Is there any way to find the physical address of a file if the path is provided?
Asked
Active
Viewed 2,319 times
1 Answers
2
You can do that with hdparm --fibmap
:
# hdparm --fibmap /var/log/messages
/var/log/messages:
filesystem blocksize 4096, begins at LBA 360720384; assuming 512 byte sectors.
byte_offset begin_LBA end_LBA sectors
0 413190576 413190583 8
4096 409598016 409598135 120
65536 371059584 371059711 128
131072 371060224 371060359 136
200704 360802936 360803567 632
524288 399259648 399260047 400
729088 360797952 360798207 256
860160 413419968 413420335 368
1048576 413421568 413422199 632
# echo LOL >/tmp/lol
# hdparm --fibmap /tmp/lol
/tmp/lol:
filesystem blocksize 4096, begins at LBA 360720384; assuming 512 byte sectors.
byte_offset begin_LBA end_LBA sectors
0 413374584 413374591 8
# dd if=/dev/sda skip=413374584 count=8 status=none | hexdump -C
00000000 4c 4f 4c 0a 00 00 00 00 00 00 00 00 00 00 00 00 |LOL.............|
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001000
hdparm
is making use of the FS_IOC_FIEMAP
ioctl, and falls back to FIGETBSZ
/ FIBMAP
if that's not available.
FIBMAP
ioctl (combined withFIGETBSZ
). Most filesystems support it. I know that boot loaders like lilo and grub are using it when setting up their 2nd or 3rd stage, but I'm not aware of any readily available utility making use of it. – Apr 20 '20 at 16:03