when does truncate gets called

Submitted by Anonymous
on January 7, 2008 - 11:36am

I am not able to find from where and when

inode->i_ops->truncate()

gets called. Also I noticed that when we open a file in O_TRUNC mode, this call goes through do_truncate() => notify_status() and then inode->i_ops->setattr(). Same way sys_truncate() somehow goes through same path. I am not able to understand when inode->i_ipo->truncate() gets called.
Please explain.

when does truncate gets called

Dhawal Thakker (not verified)
on
January 19, 2008 - 11:06am

inode->i_ops->truncate(), truncate operation is called when the file size reduced or is been deleted.

It deletes the file blocks.

Hope this helps.

Dhawal.

grep is your friend :)

on
January 19, 2008 - 2:05pm
grep -- '->truncate' *

found

inode->i_op->truncate(inode);

in mm/memory.c:vmtruncate(), which in turn is called by fs/attr.c:inode_setattr().

opening for truncate or the explicit syscall must not truncate the file on disk right away, because it may be opened by other users. if you truncate the file on disk first, and then previously dirtied data wants to be written out or someone writes into the file via write() or implicitely via mmap(), through the page cache or with O_DIRECT, you will corrupt your filesystem, so you have to flush all references to the to-be-truncated parts of the file and make sure no new writers appear before letting the filesystem truncate the data space on disk. thus the path through mm/-code. truncate is very error prone, there have been many bug hunts in this area.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.