问题描述
我一直在使用来恢复硬盘,由于硬件错误而无法复制的所有设备扇区列表。
我想拿这个列表,然后写一个工具给我所有的包含这些坏扇区的文件,所以我可以删除它们。我不知道我可以使用什么API来做到这一点 - 本质上我想获得磁盘上的所有文件和每个文件的列表,它列出了它在磁盘上占用的扇区范围。
我的第一个猜测是我将遍历磁盘上的每个目录条目并检查文件是否与这些坏扇区之一重叠。如果你想将一个文件的数据位置映射到一个物理块(扇区),你可以使用这个方法来解决这个问题。使用调用F_LOG2PHYS命令。不是所有的文件系统都支持这个命令,但是HFS +。只需使用lseek选择文件偏移量,就可以从F_LOG2PHYS取回diskoffset(它在l2p_devoffset字段中的结构log2phys中返回)。有关更多详细信息,请参阅fcntl.h。
I've been recovering a hard disk using dd_rescue, which provides me a list of all of the device sectors it could not copy due to hardware errors.
I'd like to take that list, and write a tool to give me all of the files that contain these bad sectors so I can delete them. I'm not sure what APIs I can use to do this--essentially i want to get a list of all files on disk and for each file, a list of the ranges of sectors it occupies on disk.
My first guess is that I will iterate over each directory entry on the disk and check to see if the file overlaps one of these bad sectors. Maybe there's a better way.
If you want to map a file's data location to a physical block (sector), you can use the fcntl(2) call with the F_LOG2PHYS command. Not all file systems support this command, but HFS+ does. Just use lseek to pick the file offset and you can get back the diskoffset from F_LOG2PHYS (it's returned in a struct log2phys in the l2p_devoffset field). See fcntl.h for more details.
这篇关于如何将磁盘的物理扇区映射到在Mac OS X上的HFS +卷上包含它们的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!