How to find the LBA sectors used by a file

I have wanted to do this several times.
Just found this by chance in the man page, and I have tried it on xfs and ext4 partitions.


Telcontar:~ # hdparm --fibmap /home_aux/registro

/home_aux/registro:
filesystem blocksize 4096, begins at LBA 3690496; assuming 512 byte sectors.
byte_offset  begin_LBA    end_LBA    sectors
0    3690960    3691143        184
Telcontar:~ #

Telcontar:~ # hdparm --fibmap /root/hello

/root/hello:
filesystem blocksize 4096, begins at LBA 53641098; assuming 512 byte sectors.
byte_offset  begin_LBA    end_LBA    sectors
0   91762882   91762889          8
Telcontar:~ #

The reverse command would be very useful, for finding what file is affected by damage on a disk. Some filesystems have it easy, some very difficult.


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)