Re: truncate implementation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2006-01-17 at 12:21 +0300, Jan Koss wrote:
> Thanks for reply.
> 
> > .. which isn't in the pagetable, and then the kernel notices it's
> > outside the file and causes a SIGBUS.
>
> But if length of file after truncate is 4 byte, for example,
> and I do p[5]=.., this didn't cause any error, so I can append some garbage
> after end of file, and this is not error?

No you can't.  You only think you can.  The dirty page is written using
->writepage of the file system which will "memset()" everything between
the end of file if it is in the page and the end of the page to zero
thus your write of p[5]=... will disappear every time the page is
written.

> > .. and removes the page from the pagetable.

> I'm sorry for stupid question, but where we remove from pagetable,
> I see two places in ext2_truncate:

It is not done in the file system.  It is done by the core kernel before
the file system ->truncate is called.  The function you want is
linux/mm/memory.c::vmtruncate().  The relevant lines are:

        i_size_write(inode, offset);
        unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
        truncate_inode_pages(mapping, offset);

Best regards,

        Anton
-- 
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux