~pr0gg3d/ubuntu/oneiric/util-linux/bug-805886

« back to all changes in this revision

Viewing changes to libs/blkid/src/probers/reiserfs.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2009-07-16 15:48:23 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20090716154823-i26fshvs4v8h90qh
Tags: 2.16-1ubuntu1
* Merge from Debian, remaining changes:
  - Since udev is required in Ubuntu, the hwclock.sh init script is
    not called on startup and the hwclockfirst.sh init script is
    removed.
  - Remove /etc/adjtime on upgrade if it was not used.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - No lsb_release call in mount.preinst since we'd need Pre-Depends
    (LP: #383697).

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 "blkidP.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
 
};
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
 
};
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
 
        .magics         =
102
 
        {
103
 
                { .magic = "ReIsErFs",  .len = 8, .kboff = 8,  .sboff = 0x34 },
104
 
                { .magic = "ReIsEr2Fs", .len = 9, .kboff = 64, .sboff = 0x34 },
105
 
                { .magic = "ReIsEr3Fs", .len = 9, .kboff = 64, .sboff = 0x34 },
106
 
                { .magic = "ReIsErFs",  .len = 8, .kboff = 64, .sboff = 0x34 },
107
 
                { .magic = "ReIsErFs",  .len = 8, .kboff =  8, .sboff = 20   },
108
 
                { NULL }
109
 
        }
110
 
};
111
 
 
112
 
const struct blkid_idinfo reiser4_idinfo =
113
 
{
114
 
        .name           = "reiser4",
115
 
        .usage          = BLKID_USAGE_FILESYSTEM,
116
 
        .probefunc      = probe_reiser4,
117
 
        .magics         =
118
 
        {
119
 
                { .magic = "ReIsEr4", .len = 7, .kboff = 64 },
120
 
                { NULL }
121
 
        }
122
 
};
123
 
 
124
 
 
125
 
 
126