ext3和ext4文件系统具有日记功能。有没有机会获得有关文件的详细信息?
某种API允许User Space程序访问文件的日记条目。甚至是Journal事件(比如文件x被删除)
这似乎some kind of documentation,但我不确定它是否是正确的东西。
答案 0 :(得分:1)
debugfs
logdump
您可以使用 logdump
中的 debugfs
命令显示有关文件系统日志的信息。
例如,sudo debugfs -R 'logdump -S' /dev/sda3
收益
Journal features: journal_incompat_revoke journal_checksum_v3
Total journal size: 512M
Total journal blocks: 131072
Max transaction length: 131072
Fast commit length: 0
Journal sequence: 0x004bd0ae
Journal start: 109412
Journal checksum type: crc32c
Journal checksum: 0x157eebb7
Journal starts at block 109412, transaction 4968622
Found expected sequence 4968622, type 5 (revoke table) at block 109412
Found expected sequence 4968622, type 1 (descriptor block) at block 109413
Found expected sequence 4968622, type 2 (commit block) at block 109419
Found expected sequence 4968623, type 1 (descriptor block) at block 109420
Found expected sequence 4968623, type 2 (commit block) at block 109422
Found expected sequence 4968624, type 1 (descriptor block) at block 109423
Found expected sequence 4968624, type 2 (commit block) at block 109425
Found expected sequence 4968625, type 1 (descriptor block) at block 109426
// rest omitted
我意识到 debugfs
不是 API,但它可以访问日志。
要获取日志的原始字节,您可以再次使用 debugfs
。它的 cat
命令接受一个 inode 编号并打印 inode 指向的地址的数据。
假设日志的 inode 编号为 8:
sudo debugfs -R 'cat <8>' /dev/sda3 | hexdump -C
这将以十六进制打印日志的字节。您应该在开头看到 magic number of the journal's format,jbd2:
c0 3b 39 98
日志使用 big-endian byte order 而 ext4 使用小端。
jls
jls
还打印有关期刊的信息。
例如,sudo jls /dev/sda3
收益
JBlk Description
0: Superblock (seq: 0)
sb version: 4
sb version: 4
sb feature_compat flags 0x00000000
sb feature_incompat flags 0x00000011
JOURNAL_REVOKE
sb feature_ro_incompat flags 0x00000000
1: Unallocated Commit Block (seq: 4936768, sec: 1613471034.3277057792)
2: Unallocated Descriptor Block (seq: 4936769)
3: Unallocated FS Block 42991838
4: Unallocated FS Block 0
5: Unallocated Commit Block (seq: 4949171, sec: 1613574032.1117509120)
6: Unallocated Descriptor Block (seq: 4949172)
7: Unallocated Commit Block (seq: 4960433, sec: 1613729975.4288594432)
8: Unallocated Descriptor Block (seq: 4960434)
// rest omitted
jls
的源代码是 here。
或者,您可以查阅 ext4 wiki 以使用必须自己编写的程序来解析日志。大致步骤如下: