in simple words--- simple maths --------------|----------------------------------|----------------------------------|---------------------------------| 0 page1 (1*2^12) page 2 2*2^12 page3 3*2^12 page4 4*2^12
now page_nr=3 we want last byte of page 3 inode->i_size=4*2^12 then last_byte -= page_nr << PAGE_CACHE_SHIFT; means last_byte = 4*2^12 - 3*2^12 last_byte = 1*2^12 NOT True that is isnt it --- please CMIIW but actually last_byte of page_nr=3 is 3*2^12 Nidhi On Wed, Nov 4, 2009 at 2:47 PM, Rajat Jain <rajat.j...@infogain.com> wrote: > Hi, > > The function calculates the last byte in a page OF A PARTICULAR FILE. > > static unsigned > ext2_last_byte(struct inode *inode, unsigned long page_nr) > { > unsigned last_byte = inode->i_size; > /* Currently, last_byte = file size */ > > last_byte -= page_nr << PAGE_CACHE_SHIFT; > /* Currently, last_byte = file size - no of bytes in file BEFORE this > page */ > /* implies last_byte = no of bytes in file in this page and any > subsequent pages */ > > if (last_byte > PAGE_CACHE_SIZE) > last_byte = PAGE_CACHE_SIZE; > /* Simply check if this is NOT the last page, then obviously last byte > of file in THIS page = page size */ > > return last_byte; > /* Otherwise since this is the last page, leave last_byte as is */ > } > > Thanks, > > Rajat > > > ________________________________ > > From: kernelnewbies-bou...@nl.linux.org > [mailto:kernelnewbies-bou...@nl.linux.org] On Behalf Of nidhi mittal > hada > Sent: Wednesday, November 04, 2009 2:19 PM > To: Kernelnewbies > Subject: doubt abt a function in ext2 > > > /* > * Return the offset into page `page_nr' of the last valid > * byte in that page, plus one. > */ > > static unsigned > ext2_last_byte(struct inode *inode, unsigned long page_nr) > { > unsigned last_byte = inode->i_size; > > last_byte -= page_nr << PAGE_CACHE_SHIFT; > if (last_byte > PAGE_CACHE_SIZE) > last_byte = PAGE_CACHE_SIZE; > return last_byte; > } > > > tht's a small function to get last byte of page number page_nr > but it seems to be wrong > as > last byte of page_nr if byte number start with 0 for page_nr 1 > > > last_byte should be = page_nr * (2^12 ) > > why its been subtracted from total size i_size????? > > pl tell me what i am missing ? > Nidhi > > > > > > -- > Thanks & Regards > Nidhi Mittal Hada > > > -- Thanks & Regards Nidhi Mittal Hada