Re: [PATCH] fs: Fix truncate never updates m/ctime

From: Christoph Hellwig
Date: Mon Nov 15 2021 - 18:12:30 EST


On Mon, Nov 15, 2021 at 07:00:18PM +0800, Jubin Zhong wrote:
> From: zhongjubin <zhongjubin@xxxxxxxxxx>
>
> Syscall truncate() never updates m/ctime even if the file size is
> changed. However, this is incorrect according to man file:
>
> truncate (2):
> If the size changed, then the st_ctime and st_mtime fields
> (respectively, time of last status change and time of last modification;
> see stat(2)) for the file are updated, and the set-user-ID and
> set-group-ID mode bits may be cleared.
>
> Check file size before do_truncate() to fix this.

Please try to actually reproduce your alleged "bug". And maybe also
look at the actual setattr implementations. Hint: The XFS one even
has extensive comments.