How can I find out where a file is physically located on the disk (block numbers)?
You can use the FIBMAP ioctl, as exemplified here, or using hdparm:
/ $ sudo /sbin/hdparm --fibmap /etc/X11/xorg.conf
/etc/X11/xorg.conf:
filesystem blocksize 4096, begins at LBA 0; assuming 512 byte sectors.
byte_offset begin_LBA end_LBA sectors
0 1579088 1579095 8
You could use debugfs
for this:
debugfs -R "stat ~/myfile" /dev/hda1
Change the hard/partition drive accordingly and make sure the drive is unmounted. You will get a list with all the blocks used:
BLOCKS:
(0):1643532
TOTAL: 1
This thread may give you some insight into ext4 file placement algorithm.
debugfs
has a bmap
function, which seems to give the data you want. You should be able to give it consecutive blocks of a file and get the physical block numbers.