From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Xin Zhao" Subject: Re: a question regarding Ext3 file truncate Date: Wed, 7 Feb 2007 13:42:14 -0500 Message-ID: <4ae3c140702071042h77f84e2iabb8eecca5eba41@mail.gmail.com> References: <4ae3c140702070916s71055311j107577421c2c366a@mail.gmail.com> <1170873473.4355.60.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: linux-fsdevel To: cmm@us.ibm.com Return-path: Received: from nz-out-0506.google.com ([64.233.162.231]:20095 "EHLO nz-out-0506.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161404AbXBGSmU (ORCPT ); Wed, 7 Feb 2007 13:42:20 -0500 Received: by nz-out-0506.google.com with SMTP id s1so257371nze for ; Wed, 07 Feb 2007 10:42:19 -0800 (PST) In-Reply-To: <1170873473.4355.60.camel@localhost.localdomain> Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org Thanks a lot! I just found it. If we need to truncate a file to 0 bytes, we have to change i_size to 0 first, then call ext3_truncate(). Then the code makes sense. Xin On 2/7/07, Mingming Cao wrote: > On Wed, 2007-02-07 at 12:16 -0500, Xin Zhao wrote: > > Hi, > > > > Please forgive me if the question is dumb. > > > > I am modifying ext3 to add some new features, but was confused by the > > implementation of ext3_truncate(). > > > > In ext3_truncate(): > > > > we first use > > n = ext3_block_to_path(inode, last_block, offsets, NULL); > > to get the path of the last block. > > > > If the number of blocks is smaller than 12, all blocks are then > > direct blocks. We then need to clear them. > > > > But the interesting thing happens: > > if (n == 1) /* direct blocks */ > > { > > ext3_free_data(handle, inode, NULL, i_data+offsets[0], > > i_data + EXT3_NDIR_BLOCKS); > > goto do_indirects; > > } > > This code seems to free data blocks right after the blocks used by the > > file. I think it should be > > ext3_free_data(handle, inode, NULL, i_data, i_data+offsets[0]); > > Last_block is the last logical block after the truncate, so > ext3_truncate() free data blocks after this point. > > Mingming > >