[btrfs-devel]A question about extent buffer codes

Yan Zheng yanzheng at 21cn.com
Tue Oct 16 07:36:29 PDT 2007


2007/10/16, Chris Mason <chris.mason at oracle.com>:
> On Tue, 2007-10-16 at 20:32 +0800, Yan Zheng wrote:
> > Hello
> >
> > Some xxx_extent_buffer functions have codes like:
> > --
> > offset = dst_offset & ((unsigned long)PAGE_CACHE_SIZE - 1);
> > if (i == 0)
> >         offset += start_offset;
> >
> > I can't understand why these is a test.  I feel the variable 'offset'
> > should be computed by code like:
> > --
> >  offset = (dst_offset + start_offset) & ((unsigned
> > long)PAGE_CACHE_SIZE - 1);
> It could be offset = (dst->start + dst_offset) & PAGE_CACHE_SIZE - 1,
> but start_offset is already the offset into the first page.  So, we only
> want to add it on the first page.
> -chris
>
I'm sorry , I'm still confused by these codes.  For example, when page
size is 4k,  the start_offset of a extent buffer is 2048 and we want
to access the 4096th byte in the extent buffer(parameter start is
4096). the data should be in the second page in the extent buffer and
offset from the start of the second page should be 2048.  But if
compute variable 'offset' by codes:
---  codes from read_extent_buffer  ---
offset = start & ((unsigned long)PAGE_CACHE_SIZE - 1);
if (i == 0)
	offset += start_offset;

offset is 0.   Please tell me where my mistake is,  Thanks.

YZ



More information about the Btrfs-devel mailing list