[Ocfs2-tools-devel] [PATCH 06/11] libocfs2: read/write now know inline data.
Joel Becker
Joel.Becker at oracle.com
Fri Jul 25 01:24:02 PDT 2008
On Wed, Jul 23, 2008 at 06:52:25AM +0800, Tao Ma wrote:
> +static errcode_t ocfs2_inline_data_read(struct ocfs2_dinode *di, void *buf,
> + uint32_t count, uint64_t offset,
> + uint32_t *got)
> +{
> + struct ocfs2_inline_data *id;
> + uint64_t isize;
> + uint8_t *p;
> +
> + if (!(di->i_dyn_features & OCFS2_INLINE_DATA_FL))
> + return OCFS2_ET_INVALID_ARGUMENT;
> +
> + id = &(di->id2.i_data);
> + isize = di->i_size;
You don't need isize here - you only use it once. Rather, just
use di->i_size below.
> + *got = 0;
> +
> + if (offset > id->id_count)
> + return 0;
> +
> + p = (__u8 *) &(id->id_data);
> + p += offset;
> +
> + *got = ocfs2_min((isize - offset), (uint64_t)count);
> + memcpy(buf, p, *got);
> +
> + return 0;
> +}
<snip>
> +static errcode_t ocfs2_inline_data_write(struct ocfs2_dinode *di, void *buf,
> + uint32_t count, uint64_t offset)
> +{
> + struct ocfs2_inline_data *id;
> + uint64_t isize;
> + uint8_t *p;
> +
> + if (!(di->i_dyn_features & OCFS2_INLINE_DATA_FL))
> + return OCFS2_ET_INVALID_ARGUMENT;
> +
> + id = &(di->id2.i_data);
> + isize = di->i_size;
Here you don't even use isize.
> +
> + if (offset + count > id->id_count)
> + return OCFS2_ET_NO_SPACE;
> +
> + p = (__u8 *) &(id->id_data);
> + p += offset;
> +
> + memcpy(p, buf, count);
> +
> + return 0;
> +}
Otherwise, it's looking good.
Joel
--
Life's Little Instruction Book #15
"Own a great stereo system."
Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
More information about the Ocfs2-tools-devel
mailing list