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.
26 #include "libvolume_id.h"
27 #include "libvolume_id-private.h"
30 struct lvm1_super_block {
34 struct lvm2_super_block {
42 struct lvm2_pv_header {
47 #define LVM1_SB_OFF 0x400
48 #define LVM1_MAGIC "HM"
50 int volume_id_probe_lvm1(struct volume_id *id, uint64_t off, uint64_t size)
53 struct lvm1_super_block *lvm;
55 info("probing at offset 0x%llx\n", (unsigned long long) off);
57 buf = volume_id_get_buffer(id, off + LVM1_SB_OFF, 0x800);
61 lvm = (struct lvm1_super_block *) buf;
63 if (memcmp(lvm->id, LVM1_MAGIC, 2) != 0)
66 volume_id_set_usage(id, VOLUME_ID_RAID);
67 id->type = "LVM1_member";
72 #define LVM2_LABEL_ID "LABELONE"
73 #define LVM2LABEL_SCAN_SECTORS 4
75 int volume_id_probe_lvm2(struct volume_id *id, uint64_t off, uint64_t size)
79 struct lvm2_super_block *lvm;
80 struct lvm2_pv_header *pvhdr;
82 dbg("probing at offset 0x%llx\n", (unsigned long long) off);
84 buf = volume_id_get_buffer(id, off, LVM2LABEL_SCAN_SECTORS * 0x200);
89 for (soff = 0; soff < LVM2LABEL_SCAN_SECTORS * 0x200; soff += 0x200) {
90 lvm = (struct lvm2_super_block *) &buf[soff];
92 if (memcmp(lvm->id, LVM2_LABEL_ID, 8) == 0)
99 dbg("found at offset 0x%x (pv hdr offset 0x%x)\n",
100 soff, cpu_to_le32(lvm->offset_xl));
101 soff += cpu_to_le32(lvm->offset_xl);
102 pvhdr = (struct lvm2_pv_header *) &buf[soff];
103 memcpy(id->type_version, lvm->type, 8);
104 volume_id_set_usage(id, VOLUME_ID_RAID);
105 volume_id_set_uuid(id, pvhdr->id, 0, UUID_LVM);
106 id->type = "LVM2_member";