blob: 5dcc037ba100c220684cf058313df264439381c2 [file] [log] [blame]
Denis Vlasenkode7684a2008-02-18 21:08:49 +00001/*
2 * volume_id - reads filesystem label and uuid
3 *
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
5 * Copyright (C) 2005 Tobias Klauser <tklauser@access.unizh.ch>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
Sven-Göran Bergh3b458012013-07-31 15:45:20 +020022//kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_REISERFS) += reiserfs.o
23
Denis Vlasenkode7684a2008-02-18 21:08:49 +000024#include "volume_id_internal.h"
25
26struct reiserfs_super_block {
27 uint32_t blocks_count;
28 uint32_t free_blocks;
29 uint32_t root_block;
30 uint32_t journal_block;
31 uint32_t journal_dev;
32 uint32_t orig_journal_size;
33 uint32_t dummy2[5];
34 uint16_t blocksize;
35 uint16_t dummy3[3];
36 uint8_t magic[12];
37 uint32_t dummy4[5];
38 uint8_t uuid[16];
39 uint8_t label[16];
Denys Vlasenko8dc0e192009-09-16 00:58:11 +020040} PACKED;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000041
42struct reiser4_super_block {
43 uint8_t magic[16];
44 uint16_t dummy[2];
45 uint8_t uuid[16];
46 uint8_t label[16];
47 uint64_t dummy2;
Denys Vlasenko8dc0e192009-09-16 00:58:11 +020048} PACKED;
Denis Vlasenkode7684a2008-02-18 21:08:49 +000049
50#define REISERFS1_SUPERBLOCK_OFFSET 0x2000
51#define REISERFS_SUPERBLOCK_OFFSET 0x10000
52
Denys Vlasenko89300962009-11-01 23:07:18 +010053int FAST_FUNC volume_id_probe_reiserfs(struct volume_id *id /*,uint64_t off*/)
Denis Vlasenkode7684a2008-02-18 21:08:49 +000054{
Denis Vlasenko28ea4292009-02-15 05:51:19 +000055#define off ((uint64_t)0)
Denis Vlasenkode7684a2008-02-18 21:08:49 +000056 struct reiserfs_super_block *rs;
57 struct reiser4_super_block *rs4;
58
Denis Vlasenkoc5b73722008-03-17 09:21:26 +000059 dbg("reiserfs: probing at offset 0x%llx", (unsigned long long) off);
Denis Vlasenkode7684a2008-02-18 21:08:49 +000060
61 rs = volume_id_get_buffer(id, off + REISERFS_SUPERBLOCK_OFFSET, 0x200);
62 if (rs == NULL)
63 return -1;
64
65 if (memcmp(rs->magic, "ReIsErFs", 8) == 0) {
Denis Vlasenkoc5b73722008-03-17 09:21:26 +000066 dbg("reiserfs: ReIsErFs, no label");
67// strcpy(id->type_version, "3.5");
Denis Vlasenkode7684a2008-02-18 21:08:49 +000068 goto found;
69 }
70 if (memcmp(rs->magic, "ReIsEr2Fs", 9) == 0) {
Denis Vlasenkoc5b73722008-03-17 09:21:26 +000071 dbg("reiserfs: ReIsEr2Fs");
72// strcpy(id->type_version, "3.6");
Denis Vlasenkode7684a2008-02-18 21:08:49 +000073 goto found_label;
74 }
75 if (memcmp(rs->magic, "ReIsEr3Fs", 9) == 0) {
Denis Vlasenkoc5b73722008-03-17 09:21:26 +000076 dbg("reiserfs: ReIsEr3Fs");
77// strcpy(id->type_version, "JR");
Denis Vlasenkode7684a2008-02-18 21:08:49 +000078 goto found_label;
79 }
80
81 rs4 = (struct reiser4_super_block *) rs;
82 if (memcmp(rs4->magic, "ReIsEr4", 7) == 0) {
Denis Vlasenkoc5b73722008-03-17 09:21:26 +000083// strcpy(id->type_version, "4");
84// volume_id_set_label_raw(id, rs4->label, 16);
Denis Vlasenkode7684a2008-02-18 21:08:49 +000085 volume_id_set_label_string(id, rs4->label, 16);
86 volume_id_set_uuid(id, rs4->uuid, UUID_DCE);
Denis Vlasenkoc5b73722008-03-17 09:21:26 +000087 dbg("reiserfs: ReIsEr4, label '%s' uuid '%s'", id->label, id->uuid);
Denis Vlasenkode7684a2008-02-18 21:08:49 +000088 goto found;
89 }
90
91 rs = volume_id_get_buffer(id, off + REISERFS1_SUPERBLOCK_OFFSET, 0x200);
92 if (rs == NULL)
93 return -1;
94
95 if (memcmp(rs->magic, "ReIsErFs", 8) == 0) {
Denis Vlasenkoc5b73722008-03-17 09:21:26 +000096 dbg("reiserfs: ReIsErFs, no label");
97// strcpy(id->type_version, "3.5");
Denis Vlasenkode7684a2008-02-18 21:08:49 +000098 goto found;
99 }
100
Denis Vlasenkoc5b73722008-03-17 09:21:26 +0000101 dbg("reiserfs: no signature found");
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000102 return -1;
103
104 found_label:
Denis Vlasenkoc5b73722008-03-17 09:21:26 +0000105// volume_id_set_label_raw(id, rs->label, 16);
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000106 volume_id_set_label_string(id, rs->label, 16);
107 volume_id_set_uuid(id, rs->uuid, UUID_DCE);
Denis Vlasenkoc5b73722008-03-17 09:21:26 +0000108 dbg("reiserfs: label '%s' uuid '%s'", id->label, id->uuid);
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000109
110 found:
Denis Vlasenkoc5b73722008-03-17 09:21:26 +0000111// volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
Denys Vlasenko90615a02010-12-30 00:40:11 +0100112 IF_FEATURE_BLKID_TYPE(id->type = "reiserfs";)
Denis Vlasenkode7684a2008-02-18 21:08:49 +0000113
114 return 0;
115}