1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include "volume_id_internal.h"
23
24struct reiserfs_super_block {
25 uint32_t blocks_count;
26 uint32_t free_blocks;
27 uint32_t root_block;
28 uint32_t journal_block;
29 uint32_t journal_dev;
30 uint32_t orig_journal_size;
31 uint32_t dummy2[5];
32 uint16_t blocksize;
33 uint16_t dummy3[3];
34 uint8_t magic[12];
35 uint32_t dummy4[5];
36 uint8_t uuid[16];
37 uint8_t label[16];
38} PACKED;
39
40struct reiser4_super_block {
41 uint8_t magic[16];
42 uint16_t dummy[2];
43 uint8_t uuid[16];
44 uint8_t label[16];
45 uint64_t dummy2;
46} PACKED;
47
48#define REISERFS1_SUPERBLOCK_OFFSET 0x2000
49#define REISERFS_SUPERBLOCK_OFFSET 0x10000
50
51int FAST_FUNC volume_id_probe_reiserfs(struct volume_id *id )
52{
53#define off ((uint64_t)0)
54 struct reiserfs_super_block *rs;
55 struct reiser4_super_block *rs4;
56
57 dbg("reiserfs: probing at offset 0x%llx", (unsigned long long) off);
58
59 rs = volume_id_get_buffer(id, off + REISERFS_SUPERBLOCK_OFFSET, 0x200);
60 if (rs == NULL)
61 return -1;
62
63 if (memcmp(rs->magic, "ReIsErFs", 8) == 0) {
64 dbg("reiserfs: ReIsErFs, no label");
65
66 goto found;
67 }
68 if (memcmp(rs->magic, "ReIsEr2Fs", 9) == 0) {
69 dbg("reiserfs: ReIsEr2Fs");
70
71 goto found_label;
72 }
73 if (memcmp(rs->magic, "ReIsEr3Fs", 9) == 0) {
74 dbg("reiserfs: ReIsEr3Fs");
75
76 goto found_label;
77 }
78
79 rs4 = (struct reiser4_super_block *) rs;
80 if (memcmp(rs4->magic, "ReIsEr4", 7) == 0) {
81
82
83 volume_id_set_label_string(id, rs4->label, 16);
84 volume_id_set_uuid(id, rs4->uuid, UUID_DCE);
85 dbg("reiserfs: ReIsEr4, label '%s' uuid '%s'", id->label, id->uuid);
86 goto found;
87 }
88
89 rs = volume_id_get_buffer(id, off + REISERFS1_SUPERBLOCK_OFFSET, 0x200);
90 if (rs == NULL)
91 return -1;
92
93 if (memcmp(rs->magic, "ReIsErFs", 8) == 0) {
94 dbg("reiserfs: ReIsErFs, no label");
95
96 goto found;
97 }
98
99 dbg("reiserfs: no signature found");
100 return -1;
101
102 found_label:
103
104 volume_id_set_label_string(id, rs->label, 16);
105 volume_id_set_uuid(id, rs->uuid, UUID_DCE);
106 dbg("reiserfs: label '%s' uuid '%s'", id->label, id->uuid);
107
108 found:
109
110
111
112 return 0;
113}
114