I have a mapfile
produced by ddrescue
which lists 418 bad sectors where each line looks like this (the minus indicates a bad block):
Position Size
0x1CC7C68000 0x00001000 -
By converting the position in bytes to the partition relative sector number, I can use debugfs
to query the inode number and then find the path of the broken file. Doing this manually is not feasible for almost 2000 bad blocks, so I would like to automate this, is there a way to script debugfs
to execute a sequence of commands on a file system?
Here is what I am currently doing to get the file name for a broken sector:
The positions in the
ddrescue
mapfile
are in bytes relative to the start of the disk. First, I convert the position to the sector number by dividing with 512 and then I subtract the start sektor position of the partition:Partition of first sector: 91914240 Bad block position: 0x1CC7C68000 In decimal: 123610759168 Absolute sector position: 123610759168 / 512 = 241427264 Relative block position on partition: 241427264 - 91914240 = 149513024
So the bad sector is at 149513024
relative to the partition start, using debugfs
I can now find the inode:
$ debugfs
debugfs: open /dev/sdd3
debugfs: icheck 149513024
Block Inode number
149513024 1183169
debugfs: ncheck 1183169
Inode Pathname
1183169 /username/foo/bar/baz
I would like to automate this process so I can pass a list of block positions to debugfs
, resolve these blocks into inodes, filter the inodes to exclude unmapped inodes and then use ncheck
to resolve the path names for the remaining inodes. Is this possible with debugfs and some shell scripting?