Hi Nidhi,
You've got the function semantics wrong. It does not intend to give you
the "last byte of nth page".
Rather, the "last byte OF FILE X in nth page".
inode->i_size = file size.
Thanks,
Rajat
________________________________
From: nidhi mittal hada [mailto:[email protected]]
Sent: Wednesday, November 04, 2009 3:16 PM
To: Rajat Jain; Manish Katiyar
Cc: Kernelnewbies
Subject: Re: doubt abt a function in ext2
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
<[email protected]> 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: [email protected]
[mailto:[email protected]] 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