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

« back to all changes in this revision

Viewing changes to shlibs/blkid/src/superblocks/linux_raid.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-06-20 22:31:50 UTC
  • mfrom: (1.6.3 upstream) (4.5.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110620223150-lz8wrv0946ihcz3z
Tags: 2.19.1-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - Build for multiarch.
  - Add pre-depends on multiarch-support.
  - configure.ac: don't try to be clever about extracting a path name from
    $libdir to append to /usr in a way that's not overridable; instead,
    reuse the built-in configurable libexecdir.
  - Fix up the .pc.in files to know about libexecdir, so our substitutions
    don't leave us with unusable pkg-config files.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - Mention mountall(8) in fstab(5) manpages, along with its special
    options.
  - Since upstart is required in Ubuntu, the hwclock.sh init script is not
    called on startup and the hwclockfirst.sh init script is removed.
  - Drop depends on initscripts for the above.
  - Replace hwclock udev rule with an Upstart job.
  - For the case where mount is called with a directory to mount, look
    that directory up in mountall's /lib/init/fstab if we couldn't find
    it mentioned anywhere else.  This means "mount /proc", "mount /sys",
    etc. work.
  - mount.8 points to the cifs-utils package, not the obsolete smbfs one. 
* Dropped changes:
  - mount.preinst: lsb_release has been fixed in lucid and above to be
    usable without configuration, so we don't have to diverge from Debian
    here anymore.
* Changes merged upstream:
  - sfdisk support for '+' with '-N'
  - mount/umount.c: fix a segfault on umount with empty mtab entry
  - Fix arbitrary unmount with fuse security issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
        uint32_t        set_uuid3;
35
35
};
36
36
 
 
37
/*
 
38
 * Version-1, little-endian.
 
39
 */
37
40
struct mdp1_super_block {
38
 
        uint32_t        magic;
39
 
        uint32_t        major_version;
40
 
        uint32_t        feature_map;
41
 
        uint32_t        pad0;
42
 
        uint8_t         set_uuid[16];
43
 
        uint8_t         set_name[32];
 
41
        /* constant array information - 128 bytes */
 
42
        uint32_t        magic;          /* MD_SB_MAGIC: 0xa92b4efc - little endian */
 
43
        uint32_t        major_version;  /* 1 */
 
44
        uint32_t        feature_map;    /* 0 for now */
 
45
        uint32_t        pad0;           /* always set to 0 when writing */
 
46
 
 
47
        uint8_t         set_uuid[16];   /* user-space generated. */
 
48
        unsigned char   set_name[32];   /* set and interpreted by user-space */
 
49
 
 
50
        uint64_t        ctime;          /* lo 40 bits are seconds, top 24 are microseconds or 0*/
 
51
        uint32_t        level;          /* -4 (multipath), -1 (linear), 0,1,4,5 */
 
52
        uint32_t        layout;         /* only for raid5 currently */
 
53
        uint64_t        size;           /* used size of component devices, in 512byte sectors */
 
54
 
 
55
        uint32_t        chunksize;      /* in 512byte sectors */
 
56
        uint32_t        raid_disks;
 
57
        uint32_t        bitmap_offset;  /* sectors after start of superblock that bitmap starts
 
58
                                         * NOTE: signed, so bitmap can be before superblock
 
59
                                         * only meaningful of feature_map[0] is set.
 
60
                                         */
 
61
 
 
62
        /* These are only valid with feature bit '4' */
 
63
        uint32_t        new_level;      /* new level we are reshaping to                */
 
64
        uint64_t        reshape_position;       /* next address in array-space for reshape */
 
65
        uint32_t        delta_disks;    /* change in number of raid_disks               */
 
66
        uint32_t        new_layout;     /* new layout                                   */
 
67
        uint32_t        new_chunk;      /* new chunk size (bytes)                       */
 
68
        uint8_t         pad1[128-124];  /* set to 0 when written */
 
69
 
 
70
        /* constant this-device information - 64 bytes */
 
71
        uint64_t        data_offset;    /* sector start of data, often 0 */
 
72
        uint64_t        data_size;      /* sectors in this device that can be used for data */
 
73
        uint64_t        super_offset;   /* sector start of this superblock */
 
74
        uint64_t        recovery_offset;/* sectors before this offset (from data_offset) have been recovered */
 
75
        uint32_t        dev_number;     /* permanent identifier of this  device - not role in raid */
 
76
        uint32_t        cnt_corrected_read; /* number of read errors that were corrected by re-writing */
 
77
        uint8_t         device_uuid[16]; /* user-space setable, ignored by kernel */
 
78
        uint8_t         devflags;        /* per-device flags.  Only one defined...*/
 
79
        uint8_t         pad2[64-57];    /* set to 0 when writing */
 
80
 
 
81
        /* array state information - 64 bytes */
 
82
        uint64_t        utime;          /* 40 bits second, 24 btes microseconds */
 
83
        uint64_t        events;         /* incremented when superblock updated */
 
84
        uint64_t        resync_offset;  /* data before this offset (from data_offset) known to be in sync */
 
85
        uint32_t        sb_csum;        /* checksum upto dev_roles[max_dev] */
 
86
        uint32_t        max_dev;        /* size of dev_roles[] array to consider */
 
87
        uint8_t         pad3[64-32];    /* set to 0 when writing */
 
88
 
 
89
        /* device state information. Indexed by dev_number.
 
90
         * 2 bytes per device
 
91
         * Note there are no per-device state flags. State information is rolled
 
92
         * into the 'roles' value.  If a device is spare or faulty, then it doesn't
 
93
         * have a meaningful role.
 
94
         */
 
95
        uint16_t        dev_roles[0];   /* role in array, or 0xffff for a spare, or 0xfffe for faulty */
44
96
};
45
97
 
 
98
 
46
99
#define MD_RESERVED_BYTES               0x10000
47
100
#define MD_SB_MAGIC                     0xa92b4efc
48
101
 
49
 
static int probe_raid0(blkid_probe pr, off_t off)
 
102
static int probe_raid0(blkid_probe pr, blkid_loff_t off)
50
103
{
51
104
        struct mdp0_super_block *mdp0;
52
105
        union {
53
106
                uint32_t ints[4];
54
107
                uint8_t bytes[16];
55
108
        } uuid;
 
109
        uint32_t ma, mi, pa;
 
110
        uint64_t size;
56
111
 
57
 
        if (pr->size < 0x10000)
 
112
        if (pr->size < MD_RESERVED_BYTES)
58
113
                return -1;
59
114
        mdp0 = (struct mdp0_super_block *)
60
115
                        blkid_probe_get_buffer(pr,
67
122
 
68
123
        if (le32_to_cpu(mdp0->md_magic) == MD_SB_MAGIC) {
69
124
                uuid.ints[0] = swab32(mdp0->set_uuid0);
70
 
                if (le32_to_cpu(mdp0->minor_version >= 90)) {
 
125
                if (le32_to_cpu(mdp0->minor_version) >= 90) {
71
126
                        uuid.ints[1] = swab32(mdp0->set_uuid1);
72
127
                        uuid.ints[2] = swab32(mdp0->set_uuid2);
73
128
                        uuid.ints[3] = swab32(mdp0->set_uuid3);
74
129
                }
75
 
                if (blkid_probe_sprintf_version(pr, "%u.%u.%u",
76
 
                                le32_to_cpu(mdp0->major_version),
77
 
                                le32_to_cpu(mdp0->minor_version),
78
 
                                le32_to_cpu(mdp0->patch_version)) != 0)
79
 
                        return -1;
 
130
                ma = le32_to_cpu(mdp0->major_version);
 
131
                mi = le32_to_cpu(mdp0->minor_version);
 
132
                pa = le32_to_cpu(mdp0->patch_version);
 
133
                size = le32_to_cpu(mdp0->size);
80
134
 
81
135
        } else if (be32_to_cpu(mdp0->md_magic) == MD_SB_MAGIC) {
82
136
                uuid.ints[0] = mdp0->set_uuid0;
83
 
                if (be32_to_cpu(mdp0->minor_version >= 90)) {
 
137
                if (be32_to_cpu(mdp0->minor_version) >= 90) {
84
138
                        uuid.ints[1] = mdp0->set_uuid1;
85
139
                        uuid.ints[2] = mdp0->set_uuid2;
86
140
                        uuid.ints[3] = mdp0->set_uuid3;
87
141
                }
88
 
                if (blkid_probe_sprintf_version(pr, "%u.%u.%u",
89
 
                                be32_to_cpu(mdp0->major_version),
90
 
                                be32_to_cpu(mdp0->minor_version),
91
 
                                be32_to_cpu(mdp0->patch_version)) != 0)
92
 
                        return -1;
 
142
                ma = be32_to_cpu(mdp0->major_version);
 
143
                mi = be32_to_cpu(mdp0->minor_version);
 
144
                pa = be32_to_cpu(mdp0->patch_version);
 
145
                size = be32_to_cpu(mdp0->size);
93
146
        } else
 
147
                return 1;
 
148
 
 
149
        size <<= 10;    /* convert KiB to bytes */
 
150
 
 
151
        if (pr->size < size + MD_RESERVED_BYTES)
 
152
                /* device is too small */
 
153
                return 1;
 
154
 
 
155
        if (off < size)
 
156
                /* no space before superblock */
 
157
                return 1;
 
158
 
 
159
        /*
 
160
         * Check for collisions between RAID and partition table
 
161
         *
 
162
         * For example the superblock is at the end of the last partition, it's
 
163
         * the same possition as at the end of the disk...
 
164
         */
 
165
        if ((S_ISREG(pr->mode) || blkid_probe_is_wholedisk(pr)) &&
 
166
            blkid_probe_is_covered_by_pt(pr,
 
167
                        off - size,                             /* min. start  */
 
168
                        size + MD_RESERVED_BYTES)) {            /* min. length */
 
169
 
 
170
                /* ignore this superblock, it's within any partition and
 
171
                 * we are working with whole-disk now */
 
172
                return 1;
 
173
        }
 
174
 
 
175
        if (blkid_probe_sprintf_version(pr, "%u.%u.%u", ma, mi, pa) != 0)
94
176
                return -1;
95
 
 
96
177
        if (blkid_probe_set_uuid(pr, (unsigned char *) uuid.bytes) != 0)
97
178
                return -1;
98
 
 
 
179
        if (blkid_probe_set_magic(pr, off, sizeof(mdp0->md_magic),
 
180
                                (unsigned char *) &mdp0->md_magic))
 
181
                return -1;
99
182
        return 0;
100
183
}
101
184
 
113
196
                return -1;
114
197
        if (le32_to_cpu(mdp1->major_version) != 1)
115
198
                return -1;
 
199
        if (le64_to_cpu(mdp1->super_offset) != off >> 9)
 
200
                return -1;
116
201
        if (blkid_probe_set_uuid(pr, (unsigned char *) mdp1->set_uuid) != 0)
117
202
                return -1;
 
203
        if (blkid_probe_set_uuid_as(pr,
 
204
                        (unsigned char *) mdp1->device_uuid, "UUID_SUB") != 0)
 
205
                return -1;
118
206
        if (blkid_probe_set_label(pr, mdp1->set_name,
119
207
                                sizeof(mdp1->set_name)) != 0)
120
208
                return -1;
121
 
 
 
209
        if (blkid_probe_set_magic(pr, off, sizeof(mdp1->magic),
 
210
                                (unsigned char *) &mdp1->magic))
 
211
                return -1;
122
212
        return 0;
123
213
}
124
214