~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to libblkid/src/superblocks/reiserfs.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <kzak@redhat.com>
 
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
        uint16_t        rs4_dummy[2];
 
36
        unsigned char   rs4_uuid[16];
 
37
        unsigned char   rs4_label[16];
 
38
        uint64_t        rs4_dummy2;
 
39
} __attribute__((packed));
 
40
 
 
41
static int probe_reiser(blkid_probe pr, const struct blkid_idmag *mag)
 
42
{
 
43
        struct reiserfs_super_block *rs;
 
44
        unsigned int blocksize;
 
45
 
 
46
        rs = blkid_probe_get_sb(pr, mag, struct reiserfs_super_block);
 
47
        if (!rs)
 
48
                return -1;
 
49
 
 
50
        blocksize = le16_to_cpu(rs->rs_blocksize);
 
51
 
 
52
        /* The blocksize must be at least 1k */
 
53
        if ((blocksize >> 10) == 0)
 
54
                return -BLKID_ERR_PARAM;
 
55
 
 
56
        /* If the superblock is inside the journal, we have the wrong one */
 
57
        if (mag->kboff / (blocksize >> 10) > le32_to_cpu(rs->rs_journal_block))
 
58
                return -BLKID_ERR_BIG;
 
59
 
 
60
        /* LABEL/UUID are only valid for later versions of Reiserfs v3.6. */
 
61
        if (mag->magic[6] == '2' || mag->magic[6] == '3') {
 
62
                if (*rs->rs_label)
 
63
                        blkid_probe_set_label(pr,
 
64
                                        (unsigned char *) rs->rs_label,
 
65
                                        sizeof(rs->rs_label));
 
66
                blkid_probe_set_uuid(pr, rs->rs_uuid);
 
67
        }
 
68
 
 
69
        if (mag->magic[6] == '3')
 
70
                blkid_probe_set_version(pr, "JR");
 
71
        else if (mag->magic[6] == '2')
 
72
                blkid_probe_set_version(pr, "3.6");
 
73
        else
 
74
                blkid_probe_set_version(pr, "3.5");
 
75
 
 
76
        return 0;
 
77
}
 
78
 
 
79
static int probe_reiser4(blkid_probe pr, const struct blkid_idmag *mag)
 
80
{
 
81
        struct reiser4_super_block *rs4;
 
82
 
 
83
        rs4 = blkid_probe_get_sb(pr, mag, struct reiser4_super_block);
 
84
        if (!rs4)
 
85
                return -1;
 
86
 
 
87
        if (*rs4->rs4_label)
 
88
                blkid_probe_set_label(pr, rs4->rs4_label, sizeof(rs4->rs4_label));
 
89
        blkid_probe_set_uuid(pr, rs4->rs4_uuid);
 
90
        blkid_probe_set_version(pr, "4");
 
91
 
 
92
        return 0;
 
93
}
 
94
 
 
95
 
 
96
const struct blkid_idinfo reiser_idinfo =
 
97
{
 
98
        .name           = "reiserfs",
 
99
        .usage          = BLKID_USAGE_FILESYSTEM,
 
100
        .probefunc      = probe_reiser,
 
101
        .minsz          = 4096 * 512,   /* not sure, this is minimal size of journal */
 
102
        .magics         =
 
103
        {
 
104
                { .magic = "ReIsErFs",  .len = 8, .kboff = 8,  .sboff = 0x34 },
 
105
                { .magic = "ReIsEr2Fs", .len = 9, .kboff = 64, .sboff = 0x34 },
 
106
                { .magic = "ReIsEr3Fs", .len = 9, .kboff = 64, .sboff = 0x34 },
 
107
                { .magic = "ReIsErFs",  .len = 8, .kboff = 64, .sboff = 0x34 },
 
108
                { .magic = "ReIsErFs",  .len = 8, .kboff =  8, .sboff = 20   },
 
109
                { NULL }
 
110
        }
 
111
};
 
112
 
 
113
const struct blkid_idinfo reiser4_idinfo =
 
114
{
 
115
        .name           = "reiser4",
 
116
        .usage          = BLKID_USAGE_FILESYSTEM,
 
117
        .probefunc      = probe_reiser4,
 
118
        .minsz          = 4096 * 512,   /* not sure, this is minimal size of journal */
 
119
        .magics         =
 
120
        {
 
121
                { .magic = "ReIsEr4", .len = 7, .kboff = 64 },
 
122
                { NULL }
 
123
        }
 
124
};
 
125
 
 
126
 
 
127
 
 
128