Search code examples
linuxlinux-kernelinodeext4ctime

debugfs set_inode_field ctime with nanoseconds


I'm using debugfs to change the ctime of a file (programm rotine attached to ctime of this specific file) on an ext4 file system.

The therefor used command is:

debugfs -w -R 'set_inode_field foo/bar ctime 20130503145204' /dev/vdb1

but this is resulting in an ctime als followed:

myserver:~ # stat foo/bar 
  File: „foo/bar“
  Size: 1234        Blocks: 24         IO Block: 4096   reguläre Datei
Device: 1234h/1234d Inode: 1234567     Links: 1
Access: (0660/-rw-rw----)  Uid: (  123/ whatever)   Gid: ( 1234/ whatever)
Access: 2021-02-12 21:17:51.146954174 +0100
Modify: 2021-02-12 14:51:32.152323937 +0100
Change: 2013-05-03 16:52:04.991865222 +0200

not as expected: 2013-05-03 16:52:04.000000000 +0200

Reason, why it worked properly bevor is that the old ext3 FS stored ctime only at second resolution. the inode structur size in ext2/ext3 was 128 bytes. With ext4 this size incremented to 156 bytes (i_extra_isize = 28, see: https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Inode_Size) resulting in nanosecond resolution.

How do I format the debugfs command to set the ctime to the exact nanoseconds?


Solution

  • After a little digging I managed to solve this problem. Solution: read the manual.

    debugfs supports setting of ctime/atime/mtime/crtime time_extra bytes with

    set_inode_field foo/bar ctime_extra 0
    

    The ctime_extra field is a unsigned integer, so the value of 0 gives the expected setting.

    dtime was not widend and therefor does not support dtime_extra