debugfs set_inode_field ctime(纳秒)

问题描述 投票:0回答:2

我正在使用

debugfs
更改 ext4 文件系统上文件的 ctime(程序循环附加到该特定文件的 ctime)。

因此使用的命令是:

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

但这会导致 ctime 如下:

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

不符合预期:

2013-05-03 16:52:04.000000000 +0200

原因在于,旧的 ext3 FS 仅以第二分辨率存储 ctime。 ext2/ext3 中的

inode structur size
为 128 字节。对于 ext4,此大小增加到 156 字节(i_extra_isize = 28,请参阅:https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Inode_Size),从而实现纳秒分辨率。

如何格式化 debugfs 命令以将 ctime 设置为精确的纳秒?

linux linux-kernel inode ext4 ctime
2个回答
2
投票

经过一番挖掘,我成功解决了这个问题。解决方法:阅读说明书。

debugfs 支持使用

设置 ctime/atime/mtime/crtime time_extra 字节
set_inode_field foo/bar ctime_extra 0

ctime_extra字段是一个无符号整数,因此值 0 给出了预期的设置。

dtime 未加宽,因此不支持 dtime_extra


0
投票

我正在使用较新的 debugfs(来自 ext2fsprogs 1.44.1 和 1.42.9(2014 年 2 月 4 日)的作品),它也将 inode 时间戳显示为十六进制数字(请参阅下面的

stat foo/bar
命令的输出).

请参阅下面的 debugfs 命令,将 ctime(纳秒精度)从一个 inode 复制到另一个 inode。

首先获取源inode的ctime:

stat foo/bar

stat foo/bar
的输出:

 ctime: 0xabcdef09:12345678 -- Wed May  4 02:40:09 2061
  • abcdef09 是十六进制的 ctime 数字值,
  • 12345678 是十六进制的 ctime_extra 数字值。
  • 请注意,
    Wed May...
    部分与时区相关,运行
    TZ=GMT sudo debugfs ...
    以获得跨系统一致的结果。对于复制,我们不需要这个,因为我们复制数值。

然后,将 ctime 复制到目标 inode:

set_inode_field foo/bar2 ctime @0xabcdef09
set_inode_field foo/bar2 ctime_extra 0x12345678

复制结果可以通过

stat foo/bar2
验证。

© www.soinside.com 2019 - 2024. All rights reserved.