是否可以找到磁盘中文件的物理地址?

是否可以找到磁盘中文件的物理地址?

如果提供了路径,有什么方法可以找到文件的物理地址吗?

答案1

你可以这样做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正在使用 ioctl ,如果不可用,FS_IOC_FIEMAP则返回到FIGETBSZ/ 。FIBMAP

相关内容