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
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include "libvolume_id.h"
32 #include "libvolume_id-private.h"
34 struct lvm1_super_block {
38 struct lvm2_super_block {
46 struct lvm2_pv_header {
51 #define LVM1_SB_OFF 0x400
52 #define LVM1_MAGIC "HM"
54 int volume_id_probe_lvm1(struct volume_id *id, uint64_t off, uint64_t size)
57 struct lvm1_super_block *lvm;
59 info("probing at offset 0x%" PRIx64 "\n", off);
61 buf = volume_id_get_buffer(id, off + LVM1_SB_OFF, 0x800);
65 lvm = (struct lvm1_super_block *) buf;
67 if (memcmp(lvm->id, LVM1_MAGIC, 2) != 0)
70 volume_id_set_usage(id, VOLUME_ID_RAID);
71 id->type = "LVM1_member";
76 #define LVM2_LABEL_ID "LABELONE"
77 #define LVM2LABEL_SCAN_SECTORS 4
79 int volume_id_probe_lvm2(struct volume_id *id, uint64_t off, uint64_t size)
83 struct lvm2_super_block *lvm;
84 struct lvm2_pv_header *pvhdr;
86 dbg("probing at offset 0x%" PRIx64 "\n", off);
88 buf = volume_id_get_buffer(id, off, LVM2LABEL_SCAN_SECTORS * 0x200);
93 for (soff = 0; soff < LVM2LABEL_SCAN_SECTORS * 0x200; soff += 0x200) {
94 lvm = (struct lvm2_super_block *) &buf[soff];
96 if (memcmp(lvm->id, LVM2_LABEL_ID, 8) == 0)
103 dbg("found at offset 0x%x (pv hdr offset 0x%x)\n",
104 soff, cpu_to_le32(lvm->offset_xl));
105 soff += cpu_to_le32(lvm->offset_xl);
106 pvhdr = (struct lvm2_pv_header *) &buf[soff];
107 memcpy(id->type_version, lvm->type, 8);
108 volume_id_set_usage(id, VOLUME_ID_RAID);
109 volume_id_set_uuid(id, pvhdr->id, 0, UUID_LVM);
110 id->type = "LVM2_member";