I'm trying to read the contents of a file using the file's inode.
This works fine:
echo "First line" > data.txt
sync
sudo debugfs -R "cat <$(stat -c %i data.txt)>" /dev/sda3
debugfs tells me the file contents are "First line". This part of the command gets data.txt's inode number: $(stat -c %i data.txt)
.
Things go awry when adding a second line:
echo "Second line" >> data.txt
sync
sudo debugfs -R "cat <$(stat -c %i data.txt)>" /dev/sda3
I still only get "First line" from debugfs. This doesn't change after adding more lines, running sync
again, or retrying a couple of days later.
Why doesn't debugfs show the remainder of the file contents? Am I using debugfs the wrong way?
I can reproduce this behavior reliably with other files.
I noticed that when overwriting existing file contents with echo "New content" > data.txt
, debugfs does show the new content. But adding a second line to it, will, as described above, show only the first line.
I'm on Arch Linux 5.12.3 using debugfs 1.46.2. The file system on /dev/sda3
is ext4. Calling debugfs -R "stat ..."
produces the following, which seems unsuspicious to me:
Inode: 16515371 Type: regular Mode: 0644 Flags: 0x80000
Generation: 3923658711 Version: 0x00000000:00000001
User: 1000 Group: 1000 Project: 0 Size: 34
File ACL: 0
Links: 1 Blockcount: 8
Fragment: Address: 0 Number: 0 Size: 0
ctime: 0x60b639e5:71315fa0 -- Tue Jun 1 15:45:09 2021
atime: 0x60b63988:b7c456cc -- Tue Jun 1 15:43:36 2021
mtime: 0x60b639e5:71315fa0 -- Tue Jun 1 15:45:09 2021
crtime: 0x60b63988:b7c456cc -- Tue Jun 1 15:43:36 2021
Size of extra inode fields: 32
Inode checksum: 0xbfa4390e
EXTENTS:
(0):66095479