Debian Codegraph @

libblkid/src/superblocks/reiserfs.c

raw
1 /*
2 * Copyright (C) 1999, 2001 by Andries Brouwer
3 * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
4 * Copyright (C) 2008 Karel Zak <[email protected]>
5 *
6 * This file may be redistributed under the terms of the
7 * GNU Lesser General Public License.
8 */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <string.h>
13 #include <stdint.h>
14
15 #include "superblocks.h"
16
17 struct reiserfs_super_block {
18 uint32_t rs_blocks_count;
19 uint32_t rs_free_blocks;
20 uint32_t rs_root_block;
21 uint32_t rs_journal_block;
22 uint32_t rs_journal_dev;
23 uint32_t rs_orig_journal_size;
24 uint32_t rs_dummy2[5];
25 uint16_t rs_blocksize;
26 uint16_t rs_dummy3[3];
27 unsigned char rs_magic[12];
28 uint32_t rs_dummy4[5];
29 unsigned char rs_uuid[16];
30 char rs_label[16];
31 } __attribute__((packed));
32
33 struct reiser4_super_block {
34 unsigned char rs4_magic[16];
35 uint8_t rs4_dummy[3];
36 uint8_t rs4_blocksize;
37 unsigned char rs4_uuid[16];
38 unsigned char rs4_label[16];
39 uint64_t rs4_dummy2;
40 } __attribute__((packed));
41
42 static int probe_reiser(blkid_probe pr, const struct blkid_idmag *mag)
43 {
44 const struct reiserfs_super_block *rs;
45 unsigned int blocksize;
46
47 rs = blkid_probe_get_sb(pr, mag, struct reiserfs_super_block);
48 if (!rs)
49 return errno ? -errno : 1;
50
51 blocksize = le16_to_cpu(rs->rs_blocksize);
52
53 /* The blocksize must be at least 512B */
54 if ((blocksize >> 9) == 0)
55 return 1;
56
57 /* If the superblock is inside the journal, we have the wrong one */
58 if (mag->kboff / (blocksize >> 9) > le32_to_cpu(rs->rs_journal_block) / 2)
59 return 1;
60
61 /* LABEL/UUID are only valid for later versions of Reiserfs v3.6. */
62 if (mag->magic[6] == '2' || mag->magic[6] == '3') {
63 if (*rs->rs_label)
64 blkid_probe_set_label(pr,
65 (unsigned char *) rs->rs_label,
66 sizeof(rs->rs_label));
67 blkid_probe_set_uuid(pr, rs->rs_uuid);
68 }
69
70 if (mag->magic[6] == '3')
71 blkid_probe_set_version(pr, "JR");
72 else if (mag->magic[6] == '2')
73 blkid_probe_set_version(pr, "3.6");
74 else
75 blkid_probe_set_version(pr, "3.5");
76
77 blkid_probe_set_fsblocksize(pr, blocksize);
78 blkid_probe_set_block_size(pr, blocksize);
79
80 return 0;
81 }
82
83 static int probe_reiser4(blkid_probe pr, const struct blkid_idmag *mag)
84 {
85 const struct reiser4_super_block *rs4;
86 unsigned int blocksize;
87
88 rs4 = blkid_probe_get_sb(pr, mag, struct reiser4_super_block);
89 if (!rs4)
90 return errno ? -errno : 1;
91
92 blocksize = rs4->rs4_blocksize * 256;
93
94 /* The blocksize must be at least 512 */
95 if (blocksize < 512)
96 return BLKID_PROBE_NONE;
97
98 if (*rs4->rs4_label)
99 blkid_probe_set_label(pr, rs4->rs4_label, sizeof(rs4->rs4_label));
100 blkid_probe_set_uuid(pr, rs4->rs4_uuid);
101 blkid_probe_set_version(pr, "4");
102
103 blkid_probe_set_fsblocksize(pr, blocksize);
104 blkid_probe_set_block_size(pr, blocksize);
105
106 return 0;
107 }
108
109
110 const struct blkid_idinfo reiser_idinfo =
111 {
112 .name = "reiserfs",
113 .usage = BLKID_USAGE_FILESYSTEM,
114 .probefunc = probe_reiser,
115 .minsz = 128 * 1024,
116 .magics =
117 {
118 { .magic = "ReIsErFs", .len = 8, .kboff = 8, .sboff = 0x34 },
119 { .magic = "ReIsEr2Fs", .len = 9, .kboff = 64, .sboff = 0x34 },
120 { .magic = "ReIsEr3Fs", .len = 9, .kboff = 64, .sboff = 0x34 },
121 { .magic = "ReIsErFs", .len = 8, .kboff = 64, .sboff = 0x34 },
122 { .magic = "ReIsErFs", .len = 8, .kboff = 8, .sboff = 20 },
123 { NULL }
124 }
125 };
126
127 const struct blkid_idinfo reiser4_idinfo =
128 {
129 .name = "reiser4",
130 .usage = BLKID_USAGE_FILESYSTEM,
131 .probefunc = probe_reiser4,
132 .minsz = 128 * 1024,
133 .magics =
134 {
135 { .magic = "ReIsEr4", .len = 7, .kboff = 64 },
136 { NULL }
137 }
138 };
139
140
141
142