hal/hald/linux/volume_id volume_id.c, 1.27, 1.28 volume_id.h, 1.15, 1.16

Kay Sievers kay at freedesktop.org
Thu Aug 26 17:24:35 PDT 2004


Update of /cvs/hal/hal/hald/linux/volume_id
In directory gabe:/tmp/cvs-serv11674/hald/linux/volume_id

Modified Files:
	volume_id.c volume_id.h 
Log Message:
2004-08-27  Kay Sievers  <kay.sievers at vrfy.org>

        * hald/linux/volume_id/volume_id.c:
        (probe_lvm1), (probe_lvm2): Add detection of LVM physical drives
        (probe_linux_raid): add version number of raid

        * hald/linux/volume_id/volume_id.h: We are at version 021 now.
        It started as a replacement of the FAT label reading code in HAL.
        I _never_ expected that we seek over the whole disk now to search
        for raid signatures and support nearly every filesystem I've ever
        had a formatting tool for :)



Index: volume_id.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/volume_id/volume_id.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- volume_id.c	25 Aug 2004 23:56:09 -0000	1.27
+++ volume_id.c	27 Aug 2004 00:24:33 -0000	1.28
@@ -249,7 +249,71 @@
 	}
 }
 
-#define MD_RESERVED_BYTES		(64 * 1024)
+#define LVM1_SB_OFF			0x400
+#define LVM1_MAGIC			"HM"
+static int probe_lvm1(struct volume_id *id, __u64 off)
+{
+	struct lvm2_super_block {
+		__u8	id[2];
+	} __attribute__((packed)) *lvm;
+
+	const __u8 *buf;
+
+	buf = get_buffer(id, off + LVM1_SB_OFF, 0x800);
+	if (buf == NULL)
+		return -1;
+
+	lvm = (struct lvm2_super_block *) buf;
+
+	if (strncmp(lvm->id, LVM1_MAGIC, 2) != 0)
+		return -1;
+
+	id->usage_id = VOLUME_ID_RAID;
+	id->type_id = VOLUME_ID_LVM1;
+	id->type = "LVM1_member";
+
+	return 0;
+}
+
+#define LVM2_LABEL_ID			"LABELONE"
+#define LVM2LABEL_SCAN_SECTORS		4
+static int probe_lvm2(struct volume_id *id, __u64 off)
+{
+	struct lvm2_super_block {
+		__u8	id[8];
+		__u64	sector_xl;
+		__u32	crc_xl;
+		__u32	offset_xl;
+		__u8	type[8];
+	} __attribute__((packed)) *lvm;
+
+	const __u8 *buf;
+	unsigned int soff;
+
+	buf = get_buffer(id, off, LVM2LABEL_SCAN_SECTORS * 0x200);
+	if (buf == NULL)
+		return -1;
+
+
+	for (soff = 0; soff < LVM2LABEL_SCAN_SECTORS * 0x200; soff += 0x200) {
+		lvm = (struct lvm2_super_block *) &buf[soff];
+
+		if (strncmp(lvm->id, LVM2_LABEL_ID, 8) == 0)
+			goto found;
+	}
+
+	return -1;
+
+found:
+	strncpy(id->type_version, lvm->type, 8);
+	id->usage_id = VOLUME_ID_RAID;
+	id->type_id = VOLUME_ID_LVM1;
+	id->type = "LVM2_member";
+
+	return 0;
+}
+
+#define MD_RESERVED_BYTES		0x10000
 #define MD_MAGIC			0xa92b4efc
 static int probe_linux_raid(struct volume_id *id, __u64 off, __u64 size)
 {
@@ -292,6 +356,11 @@
 	memcpy(&uuid[4], &mdp->set_uuid1, 12);
 	set_uuid(id, uuid, 16);
 
+	snprintf(id->type_version, VOLUME_ID_FORMAT_SIZE-1, "%u.%u.%u",
+		 le32_to_cpu(mdp->major_version),
+		 le32_to_cpu(mdp->minor_version),
+		 le32_to_cpu(mdp->patch_version));
+
 	dbg("found raid signature");
 	id->usage_id = VOLUME_ID_RAID;
 	id->type = "linux_raid_member";
@@ -1885,6 +1954,12 @@
 	case VOLUME_ID_LINUX_RAID:
 		rc = probe_linux_raid(id, off, size);
 		break;
+	case VOLUME_ID_LVM1:
+		rc = probe_lvm1(id, off);
+		break;
+	case VOLUME_ID_LVM2:
+		rc = probe_lvm2(id, off);
+		break;
 	case VOLUME_ID_ALL:
 	default:
 		rc = probe_linux_raid(id, off, size);
@@ -1935,6 +2010,13 @@
 		rc = probe_ufs(id, off);
 		if (rc == 0)
 			break;
+		rc = probe_lvm1(id, off);
+		if (rc == 0)
+			break;
+		rc = probe_lvm2(id, off);
+		if (rc == 0)
+			break;
+
 		rc = -1;
 	}
 

Index: volume_id.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux/volume_id/volume_id.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- volume_id.h	25 Aug 2004 23:56:09 -0000	1.15
+++ volume_id.h	27 Aug 2004 00:24:33 -0000	1.16
@@ -21,7 +21,7 @@
 #ifndef _VOLUME_ID_H_
 #define _VOLUME_ID_H_
 
-#define VOLUME_ID_VERSION		020
+#define VOLUME_ID_VERSION		021
 
 #define VOLUME_ID_LABEL_SIZE		64
 #define VOLUME_ID_UUID_SIZE		16
@@ -57,7 +57,9 @@
 	VOLUME_ID_HFS,
 	VOLUME_ID_HFSPLUS,
 	VOLUME_ID_UFS,
-	VOLUME_ID_LINUX_RAID
+	VOLUME_ID_LINUX_RAID,
+	VOLUME_ID_LVM1,
+	VOLUME_ID_LVM2
 };
 
 struct volume_id_partition {




More information about the hal-commit mailing list