linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* a question regarding Ext3 file truncate
@ 2007-02-07 17:16 Xin Zhao
  2007-02-07 18:37 ` Mingming Cao
  0 siblings, 1 reply; 3+ messages in thread
From: Xin Zhao @ 2007-02-07 17:16 UTC (permalink / raw)
  To: linux-fsdevel

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]);

Right? can some one explain this a little bit?

Thanks,
-x

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: a question regarding Ext3 file truncate
  2007-02-07 17:16 a question regarding Ext3 file truncate Xin Zhao
@ 2007-02-07 18:37 ` Mingming Cao
  2007-02-07 18:42   ` Xin Zhao
  0 siblings, 1 reply; 3+ messages in thread
From: Mingming Cao @ 2007-02-07 18:37 UTC (permalink / raw)
  To: Xin Zhao; +Cc: linux-fsdevel

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: a question regarding Ext3 file truncate
  2007-02-07 18:37 ` Mingming Cao
@ 2007-02-07 18:42   ` Xin Zhao
  0 siblings, 0 replies; 3+ messages in thread
From: Xin Zhao @ 2007-02-07 18:42 UTC (permalink / raw)
  To: cmm; +Cc: linux-fsdevel

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 <cmm@us.ibm.com> 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
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-02-07 18:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-07 17:16 a question regarding Ext3 file truncate Xin Zhao
2007-02-07 18:37 ` Mingming Cao
2007-02-07 18:42   ` Xin Zhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).