2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
27 #include "libvolume_id.h"
30 static struct mdp0_super_block {
32 uint32_t major_version;
33 uint32_t minor_version;
34 uint32_t patch_version;
35 uint32_t gvalid_words;
43 uint32_t not_persistent;
49 struct mdp1_super_block {
51 uint32_t major_version;
58 #define MD_RESERVED_BYTES 0x10000
59 #define MD_SB_MAGIC 0xa92b4efc
61 static int volume_id_probe_linux_raid0(struct volume_id *id, uint64_t off, uint64_t size)
69 info("probing at offset 0x%llx, size 0x%llx",
70 (unsigned long long) off, (unsigned long long) size);
74 buf = volume_id_get_buffer(id, off, 0x800);
77 mdp0 = (struct mdp0_super_block *) buf;
79 if (le32_to_cpu(mdp0->md_magic) == MD_SB_MAGIC) {
80 uuid.ints[0] = bswap_32(mdp0->set_uuid0);
81 uuid.ints[1] = bswap_32(mdp0->set_uuid1);
82 uuid.ints[2] = bswap_32(mdp0->set_uuid2);
83 uuid.ints[3] = bswap_32(mdp0->set_uuid3);
84 volume_id_set_uuid(id, uuid.bytes, UUID_DCE);
85 snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u.%u",
86 le32_to_cpu(mdp0->major_version),
87 le32_to_cpu(mdp0->minor_version),
88 le32_to_cpu(mdp0->patch_version));
89 } else if (be32_to_cpu(mdp0->md_magic) == MD_SB_MAGIC) {
90 uuid.ints[0] = mdp0->set_uuid0;
91 uuid.ints[1] = mdp0->set_uuid1;
92 uuid.ints[2] = mdp0->set_uuid2;
93 uuid.ints[3] = mdp0->set_uuid3;
94 volume_id_set_uuid(id, uuid.bytes, UUID_DCE);
95 snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u.%u",
96 be32_to_cpu(mdp0->major_version),
97 be32_to_cpu(mdp0->minor_version),
98 be32_to_cpu(mdp0->patch_version));
102 volume_id_set_usage(id, VOLUME_ID_RAID);
103 id->type = "linux_raid_member";
107 static int volume_id_probe_linux_raid1(struct volume_id *id, uint64_t off, uint64_t size)
111 info("probing at offset 0x%llx, size 0x%llx",
112 (unsigned long long) off, (unsigned long long) size);
114 buf = volume_id_get_buffer(id, off, 0x800);
117 mdp1 = (struct mdp1_super_block *) buf;
119 if (le32_to_cpu(mdp1->magic) != MD_SB_MAGIC)
122 volume_id_set_uuid(id, mdp1->set_uuid, UUID_DCE);
123 volume_id_set_label_raw(id, mdp1->set_name, 32);
124 volume_id_set_label_string(id, mdp1->set_name, 32);
125 snprintf(id->type_version, sizeof(id->type_version)-1, "%u", le32_to_cpu(mdp1->major_version));
126 volume_id_set_usage(id, VOLUME_ID_RAID);
127 id->type = "linux_raid_member";
131 int volume_id_probe_linux_raid(struct volume_id *id, uint64_t off, uint64_t size)
133 uint64_t sboff = (size & ~(MD_RESERVED_BYTES - 1)) - MD_RESERVED_BYTES;
135 /* version 0 at the end of the device */
136 if (volume_id_probe_linux_raid0(id, off + sboff, size) == 0)
139 /* version 1.0 at the end of the device */
140 if (volume_id_probe_linux_raid1(id, off + sboff, size) == 0)
143 /* version 1.1 at the start of the device */
144 if (volume_id_probe_linux_raid1(id, off, size) == 0)
147 /* version 1.2 at 4k offset from the start */
148 if (volume_id_probe_linux_raid1(id, off + 0x1000, size) == 0)