From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anton Altaparmakov Subject: Re: truncate implementation Date: Tue, 17 Jan 2006 09:39:06 +0000 Message-ID: <1137490746.1794.7.camel@imp.csi.cam.ac.uk> References: <1137486696.3005.15.camel@laptopd505.fenrus.org> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: arjan@infradead.org, kernelnewbies@nl.linux.org, linux-fsdevel@vger.kernel.org Return-path: Received: from ppsw-7.csi.cam.ac.uk ([131.111.8.137]:25051 "EHLO ppsw-7.csi.cam.ac.uk") by vger.kernel.org with ESMTP id S932336AbWAQJjO (ORCPT ); Tue, 17 Jan 2006 04:39:14 -0500 To: Jan Koss In-Reply-To: Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org 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 (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/