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

« back to all changes in this revision

Viewing changes to shlibs/blkid/src/superblocks/ddf_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:
18
18
/* http://www.snia.org/standards/home */
19
19
#define DDF_GUID_LENGTH                 24
20
20
#define DDF_REV_LENGTH                  8
 
21
#define DDF_MAGIC                       0xDE11DE11
 
22
 
21
23
 
22
24
struct ddf_header {
23
 
        uint8_t         signature[4];
 
25
        uint32_t        signature;
24
26
        uint32_t        crc;
25
27
        uint8_t         guid[DDF_GUID_LENGTH];
26
 
        uint8_t         ddf_rev[DDF_REV_LENGTH];
 
28
        char            ddf_rev[8];     /* 01.02.00 */
 
29
        uint32_t        seq;            /* starts at '1' */
 
30
        uint32_t        timestamp;
 
31
        uint8_t         openflag;
 
32
        uint8_t         foreignflag;
 
33
        uint8_t         enforcegroups;
 
34
        uint8_t         pad0;           /* 0xff */
 
35
        uint8_t         pad1[12];       /* 12 * 0xff */
 
36
        /* 64 bytes so far */
 
37
        uint8_t         header_ext[32]; /* reserved: fill with 0xff */
 
38
        uint64_t        primary_lba;
 
39
        uint64_t        secondary_lba;
 
40
        uint8_t         type;
 
41
        uint8_t         pad2[3];        /* 0xff */
 
42
        uint32_t        workspace_len;  /* sectors for vendor space -
 
43
                                         * at least 32768(sectors) */
 
44
        uint64_t        workspace_lba;
 
45
        uint16_t        max_pd_entries; /* one of 15, 63, 255, 1023, 4095 */
 
46
        uint16_t        max_vd_entries; /* 2^(4,6,8,10,12)-1 : i.e. as above */
 
47
        uint16_t        max_partitions; /* i.e. max num of configuration
 
48
                                           record entries per disk */
 
49
        uint16_t        config_record_len; /* 1 +ROUNDUP(max_primary_element_entries
 
50
                                           *12/512) */
 
51
        uint16_t        max_primary_element_entries; /* 16, 64, 256, 1024, or 4096 */
 
52
        uint8_t         pad3[54];       /* 0xff */
 
53
        /* 192 bytes so far */
 
54
        uint32_t        controller_section_offset;
 
55
        uint32_t        controller_section_length;
 
56
        uint32_t        phys_section_offset;
 
57
        uint32_t        phys_section_length;
 
58
        uint32_t        virt_section_offset;
 
59
        uint32_t        virt_section_length;
 
60
        uint32_t        config_section_offset;
 
61
        uint32_t        config_section_length;
 
62
        uint32_t        data_section_offset;
 
63
        uint32_t        data_section_length;
 
64
        uint32_t        bbm_section_offset;
 
65
        uint32_t        bbm_section_length;
 
66
        uint32_t        diag_space_offset;
 
67
        uint32_t        diag_space_length;
 
68
        uint32_t        vendor_offset;
 
69
        uint32_t        vendor_length;
 
70
        /* 256 bytes so far */
 
71
        uint8_t         pad4[256];      /* 0xff */
27
72
} __attribute__((packed));
28
73
 
29
74
static int probe_ddf(blkid_probe pr, const struct blkid_idmag *mag)
32
77
        int i;
33
78
        struct ddf_header *ddf = NULL;
34
79
        char version[DDF_REV_LENGTH + 1];
 
80
        uint64_t off, lba;
35
81
 
36
82
        if (pr->size < 0x30000)
37
83
                return -1;
38
84
 
39
85
        for (i = 0; i < ARRAY_SIZE(hdrs); i++) {
40
 
                uint64_t off = ((pr->size / 0x200) - hdrs[i]) * 0x200;
 
86
                off = ((pr->size / 0x200) - hdrs[i]) * 0x200;
41
87
 
42
88
                ddf = (struct ddf_header *) blkid_probe_get_buffer(pr,
43
89
                                        off,
45
91
                if (!ddf)
46
92
                        return -1;
47
93
 
48
 
                if (memcmp(ddf->signature, "\x11\xde\x11\xde", 4) == 0 ||
49
 
                    memcmp(ddf->signature, "\xde\x11\xde\x11", 4) == 0)
 
94
                if (ddf->signature == cpu_to_be32(DDF_MAGIC) ||
 
95
                    ddf->signature == cpu_to_le32(DDF_MAGIC))
50
96
                        break;
51
97
                ddf = NULL;
52
98
        }
54
100
        if (!ddf)
55
101
                return -1;
56
102
 
 
103
        lba = ddf->signature == cpu_to_be32(DDF_MAGIC) ?
 
104
                        be64_to_cpu(ddf->primary_lba) :
 
105
                        le64_to_cpu(ddf->primary_lba);
 
106
 
 
107
        if (lba > 0) {
 
108
                /* check primary header */
 
109
                unsigned char *buf;
 
110
 
 
111
                buf = blkid_probe_get_buffer(pr,
 
112
                                        lba << 9, sizeof(ddf->signature));
 
113
                if (!buf || memcmp(buf, &ddf->signature, 4))
 
114
                        return -1;
 
115
        }
 
116
 
57
117
        blkid_probe_strncpy_uuid(pr, ddf->guid, sizeof(ddf->guid));
58
118
 
59
119
        memcpy(version, ddf->ddf_rev, sizeof(ddf->ddf_rev));
61
121
 
62
122
        if (blkid_probe_set_version(pr, version) != 0)
63
123
                return -1;
 
124
        if (blkid_probe_set_magic(pr, off,
 
125
                        sizeof(ddf->signature),
 
126
                        (unsigned char *) &ddf->signature))
 
127
                return -1;
64
128
        return 0;
65
129
}
66
130