在全新安装期间,我不小心格式化了包含数据的磁盘。我尝试过使用一些工具:首先是testdisk,但我没有得到好的结果。(请参阅我关于超级用户的不成功帖子)。
所以我决定阅读一些关于ext2 filesystem structure的文档,我可以得到一些结果:
删除的分区有一个这样的目录树:
dev
|-scripts
|-projects
|-services
|-...
Medias
|-downloads
|-Musique
|-...
backup
...
所以,基于 ext2 目录项格式:
Directory Entry
Starting_Byte Ending_Byte Size_in_Bytes Field_Description
0 3 4 Inode
4 5 2 Total size of this entry (Including all subfields)
6 6 1 Name Length least-significant 8 bits
7 7 1 Type indicator (only if the feature bit for "directory entries have file type byte" is set, else this is the most-significant 8 bits of the Name Length)
8 8+N-1 N Name characters
我试图找到一些匹配这个结构的数据。
我使用了这个脚本:
var bindexOf = require('buffer-indexof');
var currentOffset=0;
var deviceReadStream = fs.createReadStream("/dev/sdb");
deviceReadStream.on('error',function(err){
console.log(err);
});
deviceReadStream.on('data',function(data){
var dirs = ["dev","scripts","services","projects","Medias","downloads","Musique","backup"];
dirs.forEach(function(dir){
dirOctetFormat = new Buffer(2);
dirOctetFormat.writeUInt8(dir.length,0);
dirOctetFormat.writeUInt8(2,1);// type is directory
dirOctetFormat= Buffer.concat( [dirOctetFormat, new Buffer(dir)]);
var offset = bindexOf( data, dirOctetFormat );
if( offset >= 0 ){
console.log( dir + " entry found at offset " + (currentOffset + offset) );
}
});
currentOffset += data.length;
});
}
我发现数据似乎是 dev 目录的目录条目:
===== Current offset: 233590226944 - 217.5478515625Gio ======
scripts entry found at offset 233590227030
services entry found at offset 233590227014
projects entry found at offset 233590228106
如果是这样,我得到了它的子目录的 inode 号:脚本、项目、服务,......
但我不知道该怎么办!我试图根据本指南推断这些 inode 的位置,但由于我无法找到已删除文件系统的超级块,我只需要猜测块大小、块数……以及希望获得结果对我来说似乎有点模糊。
那么,您能否为获得 inode 偏移量所需的所有值设置一些间隔,以及获得该偏移量的更正式的公式?