如何将磁盘的物理扇区映射到 HFS 上包含这些扇区的文件? Mac OS X 上的音量

发布于 2024-08-03 12:11:20 字数 317 浏览 8 评论 0原文

我一直在使用 dd_rescue 恢复硬盘,它为我提供了以下列表:由于硬件错误而无法复制的所有设备扇区。

我想获取该列表,并编写一个工具来为我提供包含这些坏扇区的所有文件,以便我可以删除它们。我不确定可以使用哪些 API 来执行此操作 - 本质上我想获取磁盘上所有文件的列表,以及每个文件在磁盘上占用的扇区范围的列表。

我的第一个猜测是,我将迭代磁盘上的每个目录条目,并检查文件是否与这些坏扇区之一重叠。也许有更好的方法。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

静谧幽蓝 2024-08-10 12:11:20

如果要将文件的数据位置映射到物理块(扇区),可以使用 fcntl(2) 使用 F_LOG2PHYS 命令调用。并非所有文件系统都支持此命令,但 HFS+ 支持。只需使用 lseek 来选择文件偏移量,您就可以从 F_LOG2PHYS 中获取磁盘偏移量(它在 l2p_devoffset 字段中的 struct log2phys 中返回)。有关更多详细信息,请参阅 fcntl.h。

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.

小兔几 2024-08-10 12:11:20

这是一个老问题,但由于它仍然是搜索该主题时的热门搜索之一,因此向所有搜索者致敬:

自 Mac OS X 10.6 fsck_hfs(8) 可以将物理扇区映射到文件(请参阅选项 -B)。使用注意事项:只有实际执行目录检查,匹配才会成功。因此,您可能必须使用选项 -l 或 -f 强制检查。

顺便说一句,hfsdebug 作为 PPC 二进制文件依赖于 Rosetta,因此无法在 Lion 或更高版本上运行。

It's an old question, but since it still is among the top hits when searching the topic, here's to all who searched:

Since Mac OS X 10.6 fsck_hfs(8) can map physical sectors to files (see option -B). A note on usage: matching will only be successful if checking of the catalog was actually performed. So you might have to force checking with options -l or -f.

BTW, hfsdebug as a PPC binary relies on Rosetta and thus will not run on Lion or later.

雾里花 2024-08-10 12:11:20

没有公开用于通过 HFS+ 文件系统进行 grubbing 的 API,但 源文件系统 可以作为 XNU 内核的一部分从 Apple 获得。另请查看 hfsdebug 工具,该工具可能有助于理解fs。

There's no API exposed for grubbing through HFS+ filesystems, but the source for the filesystem is available from Apple as part of the XNU kernel. Also check out the hfsdebug tool which might help to understand the fs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文