Skip to contentSkip to conversation

assembling a file out of debugreiserfs's map

DISCUSSION Alexy Khrabrov 2 participants 4 messages May 28, 2004 – May 31, 2004

lore
Share & tools
lore
#0 lore raw

Thanks to Vladimir, I run debugreiserfs -n with the name of the missing jpeg, p5270916.jpg, and found some data, creating a map. As Vladimir described, the map charts metadata and the data proper blocks. I attach the -f output. Since the idea to get the blocks back is to do dd on each, I wonder why do I have just a few blocks back, although the file size is correctly shown in metadata as 3563604. The -n run said, found 14 items.

To compare, the file which was recovered by rebuild-sb/rebuild-tree is the other jpeg, named p5270917.jpg. It was automatically placed in lost+found. I did a run of debugreiserfs -n to get its map, too. The -n run said, found 4 items. I attach the -f output as well. That shows just two block numbers! But the file was recovered automatically, with the correct size, 3428007. Do these block numbers imply ranges/chaining?

Just to recap, the first, long output, is for p5270916.jpg, which I need to manually assemble. The second, short output is for p5270917.jpg, which was recovered automatically.

I also attach Vladimir's explanations on running -n/-f, and dd'ing. The questions remaining are (1) where are all the blocks, i.e. why does the output shows so few, (2) is the order of the output correct, i.e. assembly should just go sequentially, (3) what size bs to give dd, probably related to the number of blocks. Feelin' almost there! :)

Signature · 2 lines
Cheers,
Alexy Khrabrov :: www.setup.org :: Age Quod Agis

Subject: Re: dd/rebuild of a small used part of a huge reiserfs on lvm?
From: Vladimir Saveliev <[email protected]>
To: Alexy Khrabrov <[email protected]>
Cc: Vitaly Fertman <[email protected]>

Hello

Quoted 6 lines · Alexy Khrabrov

Just to add, the file name in lost+found was 2572_2574. There were two large jpegs, about 4 MB each, and the recovered was one of them. They were written one after another. Can I do something based on the file name, if it represents some block numbers range or something analogous? Also, I know the names of the two original jpeg files. Can that help? Just curious...

yes
there is a way to find which blocks file is built of debugreiserfs -n file-to-look-for -a file.map /dev/hda1

this will scan reiserfs meta blocks and try to find metadata of files with this name

metadata will be stored in file.map.1

debugreiserfs -f -a file.map.1 /dev/hda1
will print information found

an example:
### is used for comments i added to output of debugreiserfs -f

tribesman:/tmp/reiserfsprogs-3.6.14/debugreiserfs # ./debugreiserfs -f /dev/hdb7 -a file.map.1
debugreiserfs 3.6.14 (2003 www.namesys.com)

block 78, item 0: 5 14 0x0 SD (0), len 44, location 2640 entry count 65535, fsck need 0, format new
(NEW SD), mode -rw-r--r--, size 33784, nlink 1, mtime 12/2002 19:28:35 blocks 72, uid 512

### stat data, found in block 78, this is block of journal

block 88, item 0: 5 14 0x0 SD (0), len 44, location 2640 entry count 65535, fsck need 0, format new
(NEW SD), mode -rw-r--r--, size 33784, nlink 1, mtime 12/2002 19:28:35 blocks 72, uid 512

### one more copy of file stat data in journal

block 9850, item 0: 5 14 0x0 SD (0), len 44, location 2640 entry count 65535, fsck need 0, format new
(NEW SD), mode -rw-r--r--, size 33784, nlink 1, mtime 12/2002 19:28:35 blocks 72, uid 512

### stat data of file

block 78, item 0: 5 14 0x1 IND (1), len 36, location 2604 entry count 0, fsck need 0, format new
9 pointers
[ 10171(9)]

### record from journal

block 88, item 0: 5 14 0x1 IND (1), len 36, location 2604 entry count 0, fsck need 0, format new
9 pointers
[ 10171(9)]

### record from journal

block 9850, item 0: 5 14 0x1 IND (1), len 36, location 2604 entry count 0, fsck need 0, format new
### this is so-called indirect item. It contains number of blocks file content is stored at. 5 is objectid of directory where file was created, 14 objectid of file itself, 0x1 - offset within the file (1 addresses 0-th possition in a file)
9 pointers
[ 10171(9)]

### take list of file blocks from here:
### 10171, 10172, 10173, 10174, 10175, 10176, 10177, 10178, 10179

tribesman:/tmp/reiserfsprogs-3.6.14/debugreiserfs #

Note, that this will only work if name of file is found. Key of file is obtained from it.
In your case it might happen that name will not be found
But you seem to know objectid? As you said that files were created one after each other and you found one of files with objectid 2574. So you might try to find metadata of files with objectid 2573 or 2575.

example:

debugreiserfs -s /dev/hda7
What key do you want to find: dirid?-1
objectid?14
looking for ([4294967295 14])
0%....20%....40%....60%....80%....100% left 0,
7302 /sec

this will create a file scan.log containing something like:
3-th item of block 9850 is item of file [4294967295 14]: 5 14 0x0 SD (0), len 44, location 2640 entry count 65535, fsck need 0, format new 4-th item of block 9850 is item of file [4294967295 14]: 5 14 0x1 IND (1), len 36, location 2604 entry count 0, fsck need 0, format new

Then you should use debugreiserfs -1 9850 /dev/hda1 to see details of 4-th item of block 9850:

It will give you information about file block map similar to the one in above.

OTOH, if there were metadata of that file without name - reiserfsck --rebuild-tree would put it into lost+found.
Well, you may try anyway. ОНОШРЙЮ - МЕ ОШРЙЮ

From: Vladimir Saveliev <[email protected]>
To: Alexy Khrabrov <[email protected]>

Hello

Quoted 5 lines · Alexy Khrabrov

Vladimir --

Almost there! Looks like it can find it by name. My debugreiserfs has no option -f, I have a version debugreiserfs 3.x.1b (2002). Should I build the latest ones?

yes, please do that urgently. ftp.namesys.com/pub/reiserfsprogs

Quoted 4 lines

The scan told me I have 14 blocks
for the other file, it preceded 2572_2574, and it said 2571. Now, given I *have* the map, how do I reassemble the blocks? Spasibo!

suppose you found that file consists of blocks:
10171, 10172, 10173, 10174, 10175, 10176, 10177, 10178, 10179

that means that bytes from 0 to 4095 are in block 10171 (blocksize 4k)
4096 - 8191: 10172
8192 - 12288: 10173
etc

so you have to do something like:

dd if=/dev/hda1 bs=4096 count=1 skip=10171 >> newfile dd if=/dev/hda1 bs=4096 count=1 skip=10172 >> newfile dd if=/dev/hda1 bs=4096 count=1 skip=10173 >> newfile .

the only problem is final filesize. It will be multiple of 4096 if that will be the problem you will have to find a way to truncate ending 0s.

block 1244, item 0: 2572 2573 0x0 SD (0), len 44, location 3448 entry count 65535, fsck need 0, format new (NEW SD), mode -r-xr--r--, size 3563604, nlink 1, mtime 27/2004 11:25:38 blocks 6968, uid 500 block 1258, item 0: 2572 2573 0x0 SD (0), len 44, location 3448 entry count 65535, fsck need 0, format new (NEW SD), mode -r-xr--r--, size 3563604, nlink 1, mtime 27/2004 11:25:38 blocks 6968, uid 500 block 1262, item 0: 2572 2573 0x0 SD (0), len 44, location 3448 entry count 65535, fsck need 0, format new (NEW SD), mode -r-xr--r--, size 3563604, nlink 1, mtime 27/2004 11:25:38 blocks 6968, uid 500 block 1266, item 0: 2572 2573 0x0 SD (0), len 44, location 3448 entry count 65535, fsck need 0, format new (NEW SD), mode -r-xr--r--, size 3563604, nlink 1, mtime 27/2004 11:25:38 blocks 6968, uid 500 block 1270, item 0: 2572 2573 0x0 SD (0), len 44, location 3448 entry count 65535, fsck need 0, format new (NEW SD), mode -r-xr--r--, size 3563604, nlink 1, mtime 27/2004 11:25:38 blocks 6968, uid 500 block 8142, item 0: 2572 2573 0x0 SD (0), len 44, location 3448 entry count 65535, fsck need 0, format new (NEW SD), mode -r-xr--r--, size 3563604, nlink 1, mtime 27/2004 11:25:38 blocks 6968, uid 500 block 1244, item 0: 2572 2573 0x1 IND (1), len 3256, location 192 entry count 0, fsck need 0, format new 814 pointers
[ 2054932(814)]
block 1258, item 0: 2572 2573 0x1 IND (1), len 3256, location 192 entry count 0, fsck need 0, format new 814 pointers
[ 2054932(814)]
block 1262, item 0: 2572 2573 0x1 IND (1), len 3256, location 192 entry count 0, fsck need 0, format new 814 pointers
[ 2054932(814)]
block 1266, item 0: 2572 2573 0x1 IND (1), len 3256, location 192 entry count 0, fsck need 0, format new 814 pointers
[ 2054932(814)]
block 1270, item 0: 2572 2573 0x1 IND (1), len 3256, location 192 entry count 0, fsck need 0, format new 814 pointers
[ 2054932(814)]
block 8142, item 0: 2572 2573 0x1 IND (1), len 3256, location 192 entry count 0, fsck need 0, format new 814 pointers
[ 2054932(814)]
block 1271, item 0: 2572 2573 0x32e001 IND (1), len 228, location 3868 entry count 0, fsck need 0, format new 57 pointers
[ 2055746(9) 2055756(48)]
block 8002, item 0: 2572 2573 0x32e001 IND (1), len 228, location 3868 entry count 0, fsck need 0, format new 57 pointers
[ 2055746(9) 2055756(48)]

block 1271, item 0: 2572 2574 0x0 SD (0), len 44, location 3824 entry count 65535, fsck need 0, format new (NEW SD), mode -r-xr--r--, size 3428007, nlink 1, mtime 27/2004 11:38:04 blocks 6696, uid 0 block 8002, item 0: 2572 2574 0x0 SD (0), len 44, location 3824 entry count 65535, fsck need 0, format new (NEW SD), mode -r-xr--r--, size 3428007, nlink 1, mtime 27/2004 11:38:04 blocks 6696, uid 0 block 1271, item 0: 2572 2574 0x1 IND (1), len 3348, location 476 entry count 0, fsck need 0, format new 837 pointers
[ 2055804(837)]
block 8002, item 0: 2572 2574 0x1 IND (1), len 3348, location 476 entry count 0, fsck need 0, format new 837 pointers
[ 2055804(837)]

#1 lore raw

I realized how IND chains lead to more blocks, so the question remaining is, whether it can be assembled automatically? Why are they repeated several times with seemingly the same block number/counts, and what does the fractioned one mean,

block 1271, item 0: 2572 2573 0x32e001 IND (1), len 228, location 3868 entry count 0, fsck need 0, format new 57 pointers
[ 2055746(9) 2055756(48)]

as compared to

block 1270, item 0: 2572 2573 0x1 IND (1), len 3256, location 192 entry count 0, fsck need 0, format new 814 pointers
[ 2054932(814)]

-- also note, that the last chain for p5270916.jpg,

block 8002, item 0: 2572 2573 0x32e001 IND (1), len 228, location 3868 entry count 0, fsck need 0, format new 57 pointers
[ 2055746(9) 2055756(48)]

mentioned the same block number 8002 which the safefly recovered p5270917.jpg mentions:

block 8002, item 0: 2572 2574 0x1 IND (1), len 3348, location 476 entry count 0, fsck need 0, format new 837 pointers
[ 2055804(837)]

Isn't there a tool/script to assemble those chains into a file by, um, a computer? :) I mean I'd hack a python script to do dd ... >> file, but I bet 1000 rubles/30 euros/40 dollars it exists somewhere!

Signature · 2 lines
Cheers,
Alexy Khrabrov :: www.setup.org :: Age Quod Agis
#2 lore raw

OK, I've restored the missing file, here's just to sum up what I've done so it may help others.

1.  debugreiserfs -n <filename> -a file.map /dev/device
2.  debugreiserfs -f -a file.map /dev/device
3.  [read around this thread for Vladimir's explanation of 

debugreiserfs output format...]

saw these lines with data blocks:

block 8142, item 0: 2572 2573 0x1 IND (1), len 3256, location 192 entry count 0, fsck need 0, format new 814 pointers
[ 2054932(814)]
block 1271, item 0: 2572 2573 0x32e001 IND (1), len 228, location 3868 entry count 0, fsck need 0, format new 57 pointers
[ 2055746(9) 2055756(48)]

and assembled like this:

dd if=/dev/lev/raid bs=4096 count=814 skip=2054932 of=new.jpg
dd if=/dev/lev/raid bs=4096 count=9 skip=2055746 >> new.jpg
dd if=/dev/lev/raid bs=4096 count=48 skip=2055756 >> new.jpg

4. Saw the size of the original in the metadata line:

(NEW SD), mode -r-xr--r--, size 3563604, nlink 1, mtime 27/2004 11:25:38 blocks 6968, uid 500

and truncated the file to that size with a wrapper script around the system truncate call (man 2 truncate), attached:

truncate new.jpg 3563604

et voila!

Thanks to Vladimir, Vitaly, the author Hans Reiser of course, and all the great team at ReiserFS. I use it since SuSE 7.1/2001 and am very happy with it!

Signature · 2 lines
Cheers,
Alexy Khrabrov :: www.setup.org :: Age Quod Agis

#include <unistd.h>
#include <stdio.h>

int main(int argc, char **argv)
{
int ex;

  if (argc !=3) {
    printf("usage: %s <file> <new size>\n", argv[0]);
    exit(1);
  }

  ex = truncate(argv[1], atol(argv[2]));

  if (!ex)
    printf("%s is now %s bytes long\n", argv[1], argv[2]);
  else
    printf("ERROR!");

return(ex);
}

#3 lore raw
In reply to Alexy Khrabrov

Hello

Quoted 21 lines · Alexy Khrabrov

I realized how IND chains lead to more blocks, so the question remaining is, whether it can be assembled automatically? Why are they repeated several times with seemingly the same block number/counts, and what does the fractioned one mean,

block 1271, item 0: 2572 2573 0x32e001 IND (1), len 228, location 3868 entry count 0, fsck need 0, format new 57 pointers
[ 2055746(9) 2055756(48)]

as compared to

block 1270, item 0: 2572 2573 0x1 IND (1), len 3256, location 192 entry count 0, fsck need 0, format new 814 pointers
[ 2054932(814)]

-- also note, that the last chain for p5270916.jpg,

block 8002, item 0: 2572 2573 0x32e001 IND (1), len 228, location 3868 entry count 0, fsck need 0, format new 57 pointers
[ 2055746(9) 2055756(48)]

Quoted 7 lines

mentioned the same block number 8002 which the safefly recovered p5270917.jpg mentions:

block 8002, item 0: 2572 2574 0x1 IND (1), len 3348, location 476 entry count 0, fsck need 0, format new 837 pointers
[ 2055804(837)]

Reiserfs does not keep metadata at the same place all the time. It keeps metadata in the tree, which rebalances whenever one changes filesystem. So, file's metadata migrates even though you did not touch that file for a long time.
So, the trick in recovering files in from metadata is to choose proper sequence of metadata given that there might by a lot of them. They may overlap also. So, it is not very easy to automate such file recovering.

Quoted 3 lines

Isn't there a tool/script to assemble those chains into a file by, um, a computer? :) I mean I'd hack a python script to do dd ... >> file, but I bet 1000 rubles/30 euros/40 dollars it exists somewhere!

I am not aware of any