use*_*366 6 data-recovery files ddrescue
不久前,我在一个垂死的 HDD 上进行了 2 次救援尝试;我首先运行(GNU)ddrescue
,然后直接dd
进行手动搜索。我想充分利用这两个图像。由于文件中的任何空段都只是 0,因此按位与应该足以合并两个文件。
是否有一个实用程序允许我创建一个文件,该文件是两个输入文件的 OR?
(我正在使用 ArchLinux,但如果它不在存储库中,我很乐意从源代码安装)
我不知道有什么实用程序可以做到这一点,但编写一个程序来做到这一点应该很容易。这是一个 Python 的骨架示例:
#!/usr/bin/env python
f=open("/path/to/image1","rb")
g=open("/path/to/image2","rb")
h=open("/path/to/imageMerge","wb") #Output file
while True:
data1=f.read(1) #Read a byte
data2=g.read(1) #Read a byte
if (data1 and data2): #Check that neither file has ended
h.write(chr(ord(data1) | ord(data2))) #Or the bytes
elif (data1): #If image1 is longer, clean up
h.write(data1)
data1=f.read()
h.write(data1)
break
elif (data2): #If image2 is longer, clean up
h.write(data2)
data2=g.read()
h.write(data2)
break
else: #No cleanup needed if images are same length
break
f.close()
g.close()
h.close()
Run Code Online (Sandbox Code Playgroud)
或者一个应该运行得更快的 C 程序(但更有可能出现未被注意到的错误):
#include <stdio.h>
#include <string.h>
#define BS 1024
int main() {
FILE *f1,*f2,*fout;
size_t bs1,bs2;
f1=fopen("image1","r");
f2=fopen("image2","r");
fout=fopen("imageMerge","w");
if(!(f1 && f2 && fout))
return 1;
char buffer1[BS];
char buffer2[BS];
char bufferout[BS];
while(1) {
bs1=fread(buffer1,1,BS,f1); //Read files to buffers, BS bytes at a time
bs2=fread(buffer2,1,BS,f2);
size_t x;
for(x=0;bs1 && bs2;--bs1,--bs2,++x) //If we have data in both,
bufferout[x]=buffer1[x] | buffer2[x]; //write OR of the two to output buffer
memcpy(bufferout+x,buffer1+x,bs1); //If bs1 is longer, copy the rest to the output buffer
memcpy(bufferout+x,buffer2+x,bs2); //If bs2 is longer, copy the rest to the output buffer
x+=bs1+bs2;
fwrite(bufferout,1,x,fout);
if(x!=BS)
break;
}
}
Run Code Online (Sandbox Code Playgroud)