[Top] [All Lists]

ftruncate() Writes Last Block of File

To: linux-xfs@xxxxxxxxxxx
Subject: ftruncate() Writes Last Block of File
From: Alan Cook <acook@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 19 Mar 2012 14:44:33 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)
I have three questions regarding the XFS implementation of ftruncate().  In the
block device driver, I can see that writes are being performed to the last block
of previously written file when ftruncate() is called.  I believe that I found
ftruncate() in the XFS sources, but all I see is the filesize being updated in
the inode.  So if ftruncate() is writing to the last block, it appears to be a
triggered event.

To test, I added printk() statements in the block device driver that outputs
jiffies for write operations.  A file is created and written (~1 MiB), and then
truncated to 8192 via ftruncate().  The original write to file happens about 20
jiffies before the call to ftruncate().  When looking at the output, there is an
additional write to what is the last block of the truncated file, which reports
the same jiffies as the call to ftruncate().

I am not reporting this as a bug, simply looking for more information, as it was
not something that I expected to happen.

Does ftruncate() actually write to the last block of the file?  If not, any
thoughts on what would be?  It only happens when ftruncate() is called.

Where in the XFS kernel code is ftruncate() implemented?  I searched around, but
have no confidence that what I see is actually the ftruncate() implementation.

If ftruncate() does write to the last block of the file, why does it do so?

<Prev in Thread] Current Thread [Next in Thread>