如何从扇区列表生成文件列表?

Mig*_*tos 8 filesystems bad-sectors file-recovery ddrescue

我遇到了硬盘故障,并设法使用 GNU 的ddrescue. 磁盘的最后 800GB 是完美的,没有一个错误,但在前 200GB 中几乎有 14000 个错误(坏块)分布在整个区域。ddrescue创建一个描述坏块位置的日志文件。

ddrescues 命令行参数:

ddrescue /dev/sdb /dev/sdd /mnt/sdc1/sdb.log -r -1 -f -d -v
Run Code Online (Sandbox Code Playgroud)

日志文件如下所示:

#      pos        size  status
0x00000000  0x1C08CE00  +
0x1C08CE00  0x00000200  -
0x1C08D000  0x011E6800  +
0x1D273800  0x00000200  -
0x1D273A00  0x005EC000  +
0x1D85FA00  0x00000200  -
...         ...         ...
Run Code Online (Sandbox Code Playgroud)

加号 (+) 表示连续的好空格,减号 (-) 表示不可读的空格;位置和大小是十六进制的。对以“+”结尾的行进行条带化,我有一个包含坏块位置的列表,但我需要一种方法来将这些坏块与文件系统上的文件相关联,顺便说一下,就是 NTFS。

我知道我可以使用DiskExplorer 之类的工具来手动执行此操作,但是如果有 14000 个扇区,那就太糟糕了。那么,是否有一种或多或少自动和优雅的方式来做到这一点?

Mig*_*tos 6

自从这个问题取得巨大成功以来,我一直没有答案,如果有的话。但是我继续研究并发现了一个可追溯到 1999 年的 Microsoft 实用程序,称为 nfi.exe,它是Windows NT 4 和 2000OEM 支持工具 Phase 3 Service Release 2 的一部分。该实用程序完全符合我的需要,接收一个扇区并返回一个文件。但它对个别部门这样做,所以我不得不创建一个脚本来自动化这个过程。这是一个以这种方式工作的 Python (2.7+) 脚本:

它接收 ddrescue 日志文件作为输入,对其进行解析,为文件中的每个扇区调用 nfi.exe,并生成按字母顺序排列的文件列表。

>sector_correlator.py -h

usage: sector_correlator.py [-h] [-v] [-n \path\to\nfi.exe] [-V] [-L]
                        logfile nt-device-path output file

Receives a list of sectors and returns a list of files which resides in them.

positional arguments:
  logfile              path to ddrescue's logfile.
  nt-device-path       NT-style path to physical device, like
                       \device\harddisk1\dr1
  output file          filelist output file name

optional arguments:
  -h, --help           show this help message and exit
  -v, --version        show program's version number and exit
  -n \path\to\nfi.exe  nfi.exe's path, if not speciified, assumes's it is in
                       the same path as the script
  -V                   enables verbose mode
  -L                   save nfi.exe's output log to nfi_raw.log
Run Code Online (Sandbox Code Playgroud)

例子:

sector_correlator.py sdb.log \devices\harddisk0\dr0 filelist.txt
Run Code Online (Sandbox Code Playgroud)

其中:sdb.log 是 ddrescue 的日志,

\device\harddisk0\dr0 是 HD 的 NT 样式路径(您可以使用名为WinObj的 sysinternals 工具和磁盘管理实用程序来发现它)WinObj 显示物理设备列表 在此处输入图片说明

而 filelist.txt 是你想要的文件列表。它看起来像这样:

\Documents\Downloads\Evernote_4.5.1.5432.exe
\Documents\Downloads\Programs\Apophysis207SE.exe
\Documents\Downloads\Programs\GetGnuWin32-0.6.21.exe
\Documents\Downloads\Programs\mbam-setup.exe
\Documents\Downloads\Programs\msnbackup133.exe
\Documents\Downloads\Programs\x64Components_v254.exe
Run Code Online (Sandbox Code Playgroud)

脚本上的其他参数是可选的,当您使用 -h 运行它时会进行解释。默认情况下,脚本假定 nfi.exe 位于同一目录中,如果不是,请使用 -n pathtonfi.exe。

最后,这里是脚本的链接:sector_correlator.py

它非常简陋,没有错误处理,但可以完成工作。