svn commit: r218536 - in stable/8/sys: geom/part sys

Andrey V. Elsukov ae at FreeBSD.org
Fri Feb 11 05:37:06 UTC 2011


Author: ae
Date: Fri Feb 11 05:37:05 2011
New Revision: 218536
URL: http://svn.freebsd.org/changeset/base/218536

Log:
  MFC r218014:
    Add new user-friendly aliases for partition types for the MBR and
    EBR schemes: fat32, ebr, linux-data, linux-raid, linux-swap and
    linux-lvm. Add bios-boot GUID and alias for the GPT scheme. It used by
    GRUB 2 loader. Also do sorting definitions of types in diskmbr.h
    and in g_part.c.
  
    PR:		bin/120990, kern/147664

Modified:
  stable/8/sys/geom/part/g_part.c
  stable/8/sys/geom/part/g_part.h
  stable/8/sys/geom/part/g_part_ebr.c
  stable/8/sys/geom/part/g_part_gpt.c
  stable/8/sys/geom/part/g_part_mbr.c
  stable/8/sys/sys/diskmbr.h
  stable/8/sys/sys/gpt.h
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)

Modified: stable/8/sys/geom/part/g_part.c
==============================================================================
--- stable/8/sys/geom/part/g_part.c	Fri Feb 11 05:33:35 2011	(r218535)
+++ stable/8/sys/geom/part/g_part.c	Fri Feb 11 05:37:05 2011	(r218536)
@@ -76,7 +76,10 @@ struct g_part_alias_list {
 	{ "apple-raid-offline", G_PART_ALIAS_APPLE_RAID_OFFLINE },
 	{ "apple-tv-recovery", G_PART_ALIAS_APPLE_TV_RECOVERY },
 	{ "apple-ufs", G_PART_ALIAS_APPLE_UFS },
+	{ "bios-boot", G_PART_ALIAS_BIOS_BOOT },
+	{ "ebr", G_PART_ALIAS_EBR },
 	{ "efi", G_PART_ALIAS_EFI },
+	{ "fat32", G_PART_ALIAS_MS_FAT32 },
 	{ "freebsd", G_PART_ALIAS_FREEBSD },
 	{ "freebsd-boot", G_PART_ALIAS_FREEBSD_BOOT },
 	{ "freebsd-swap", G_PART_ALIAS_FREEBSD_SWAP },
@@ -87,6 +90,7 @@ struct g_part_alias_list {
 	{ "linux-lvm", G_PART_ALIAS_LINUX_LVM },
 	{ "linux-raid", G_PART_ALIAS_LINUX_RAID },
 	{ "linux-swap", G_PART_ALIAS_LINUX_SWAP },
+	{ "mbr", G_PART_ALIAS_MBR },
 	{ "ms-basic-data", G_PART_ALIAS_MS_BASIC_DATA },
 	{ "ms-ldm-data", G_PART_ALIAS_MS_LDM_DATA },
 	{ "ms-ldm-metadata", G_PART_ALIAS_MS_LDM_METADATA },
@@ -98,7 +102,6 @@ struct g_part_alias_list {
 	{ "netbsd-lfs", G_PART_ALIAS_NETBSD_LFS },
 	{ "netbsd-raid", G_PART_ALIAS_NETBSD_RAID },
 	{ "netbsd-swap", G_PART_ALIAS_NETBSD_SWAP },
-	{ "mbr", G_PART_ALIAS_MBR }
 };
 
 /*

Modified: stable/8/sys/geom/part/g_part.h
==============================================================================
--- stable/8/sys/geom/part/g_part.h	Fri Feb 11 05:33:35 2011	(r218535)
+++ stable/8/sys/geom/part/g_part.h	Fri Feb 11 05:37:05 2011	(r218536)
@@ -66,6 +66,9 @@ enum g_part_alias {
 	G_PART_ALIAS_NETBSD_RAID,	/* A NetBSD RAID partition entry. */
 	G_PART_ALIAS_NETBSD_SWAP,	/* A NetBSD swap partition entry. */
 	G_PART_ALIAS_NETBSD_LFS,	/* A NetBSD LFS partition entry. */
+	G_PART_ALIAS_EBR,		/* A EBR partition entry. */
+	G_PART_ALIAS_MS_FAT32,		/* A Microsoft FAT32 partition entry. */
+	G_PART_ALIAS_BIOS_BOOT,		/* A GRUB 2 boot partition entry. */
 	/* Keep the following last */
 	G_PART_ALIAS_COUNT
 };

Modified: stable/8/sys/geom/part/g_part_ebr.c
==============================================================================
--- stable/8/sys/geom/part/g_part_ebr.c	Fri Feb 11 05:33:35 2011	(r218535)
+++ stable/8/sys/geom/part/g_part_ebr.c	Fri Feb 11 05:37:05 2011	(r218536)
@@ -113,6 +113,19 @@ static struct g_part_scheme g_part_ebr_s
 };
 G_PART_SCHEME_DECLARE(g_part_ebr);
 
+static struct g_part_ebr_alias {
+	u_char		typ;
+	int		alias;
+} ebr_alias_match[] = {
+	{ DOSPTYP_386BSD,	G_PART_ALIAS_FREEBSD },
+	{ DOSPTYP_NTFS,		G_PART_ALIAS_MS_NTFS },
+	{ DOSPTYP_FAT32,	G_PART_ALIAS_MS_FAT32 },
+	{ DOSPTYP_LINSWP,	G_PART_ALIAS_LINUX_SWAP },
+	{ DOSPTYP_LINUX,	G_PART_ALIAS_LINUX_DATA },
+	{ DOSPTYP_LINLVM,	G_PART_ALIAS_LINUX_LVM },
+	{ DOSPTYP_LINRAID,	G_PART_ALIAS_LINUX_RAID },
+};
+
 static void ebr_set_chs(struct g_part_table *, uint32_t, u_char *, u_char *,
     u_char *);
 
@@ -152,6 +165,7 @@ ebr_parse_type(const char *type, u_char 
 	const char *alias;
 	char *endp;
 	long lt;
+	int i;
 
 	if (type[0] == '!') {
 		lt = strtol(type + 1, &endp, 0);
@@ -160,14 +174,18 @@ ebr_parse_type(const char *type, u_char 
 		*dp_typ = (u_char)lt;
 		return (0);
 	}
-	alias = g_part_alias_name(G_PART_ALIAS_FREEBSD);
-	if (!strcasecmp(type, alias)) {
-		*dp_typ = DOSPTYP_386BSD;
-		return (0);
+	for (i = 0;
+	    i < sizeof(ebr_alias_match) / sizeof(ebr_alias_match[0]); i++) {
+		alias = g_part_alias_name(ebr_alias_match[i].alias);
+		if (strcasecmp(type, alias) == 0) {
+			*dp_typ = ebr_alias_match[i].typ;
+			return (0);
+		}
 	}
 	return (EINVAL);
 }
 
+
 static void
 ebr_set_chs(struct g_part_table *table, uint32_t lba, u_char *cylp, u_char *hdp,
     u_char *secp)
@@ -537,13 +555,15 @@ g_part_ebr_type(struct g_part_table *bas
     char *buf, size_t bufsz)
 {
 	struct g_part_ebr_entry *entry;
-	int type;
+	int i;
 
 	entry = (struct g_part_ebr_entry *)baseentry;
-	type = entry->ent.dp_typ;
-	if (type == DOSPTYP_386BSD)
-		return (g_part_alias_name(G_PART_ALIAS_FREEBSD));
-	snprintf(buf, bufsz, "!%d", type);
+	for (i = 0;
+	    i < sizeof(ebr_alias_match) / sizeof(ebr_alias_match[0]); i++) {
+		if (ebr_alias_match[i].typ == entry->ent.dp_typ)
+			return (g_part_alias_name(ebr_alias_match[i].alias));
+	}
+	snprintf(buf, bufsz, "!%d", entry->ent.dp_typ);
 	return (buf);
 }
 

Modified: stable/8/sys/geom/part/g_part_gpt.c
==============================================================================
--- stable/8/sys/geom/part/g_part_gpt.c	Fri Feb 11 05:33:35 2011	(r218535)
+++ stable/8/sys/geom/part/g_part_gpt.c	Fri Feb 11 05:37:05 2011	(r218536)
@@ -146,6 +146,7 @@ static struct uuid gpt_uuid_apple_raid =
 static struct uuid gpt_uuid_apple_raid_offline = GPT_ENT_TYPE_APPLE_RAID_OFFLINE;
 static struct uuid gpt_uuid_apple_tv_recovery = GPT_ENT_TYPE_APPLE_TV_RECOVERY;
 static struct uuid gpt_uuid_apple_ufs = GPT_ENT_TYPE_APPLE_UFS;
+static struct uuid gpt_uuid_bios_boot = GPT_ENT_TYPE_BIOS_BOOT;
 static struct uuid gpt_uuid_efi = GPT_ENT_TYPE_EFI;
 static struct uuid gpt_uuid_freebsd = GPT_ENT_TYPE_FREEBSD;
 static struct uuid gpt_uuid_freebsd_boot = GPT_ENT_TYPE_FREEBSD_BOOT;
@@ -181,6 +182,7 @@ static struct g_part_uuid_alias {
 	{ &gpt_uuid_apple_raid_offline,	G_PART_ALIAS_APPLE_RAID_OFFLINE },
 	{ &gpt_uuid_apple_tv_recovery,	G_PART_ALIAS_APPLE_TV_RECOVERY },
 	{ &gpt_uuid_apple_ufs,		G_PART_ALIAS_APPLE_UFS },
+	{ &gpt_uuid_bios_boot,		G_PART_ALIAS_BIOS_BOOT },
 	{ &gpt_uuid_efi, 		G_PART_ALIAS_EFI },
 	{ &gpt_uuid_freebsd,		G_PART_ALIAS_FREEBSD },
 	{ &gpt_uuid_freebsd_boot, 	G_PART_ALIAS_FREEBSD_BOOT },

Modified: stable/8/sys/geom/part/g_part_mbr.c
==============================================================================
--- stable/8/sys/geom/part/g_part_mbr.c	Fri Feb 11 05:33:35 2011	(r218535)
+++ stable/8/sys/geom/part/g_part_mbr.c	Fri Feb 11 05:37:05 2011	(r218536)
@@ -108,12 +108,27 @@ static struct g_part_scheme g_part_mbr_s
 };
 G_PART_SCHEME_DECLARE(g_part_mbr);
 
+static struct g_part_mbr_alias {
+	u_char		typ;
+	int		alias;
+} mbr_alias_match[] = {
+	{ DOSPTYP_386BSD,	G_PART_ALIAS_FREEBSD },
+	{ DOSPTYP_EXT,		G_PART_ALIAS_EBR },
+	{ DOSPTYP_NTFS,		G_PART_ALIAS_MS_NTFS },
+	{ DOSPTYP_FAT32,	G_PART_ALIAS_MS_FAT32 },
+	{ DOSPTYP_LINSWP,	G_PART_ALIAS_LINUX_SWAP },
+	{ DOSPTYP_LINUX,	G_PART_ALIAS_LINUX_DATA },
+	{ DOSPTYP_LINLVM,	G_PART_ALIAS_LINUX_LVM },
+	{ DOSPTYP_LINRAID,	G_PART_ALIAS_LINUX_RAID },
+};
+
 static int
 mbr_parse_type(const char *type, u_char *dp_typ)
 {
 	const char *alias;
 	char *endp;
 	long lt;
+	int i;
 
 	if (type[0] == '!') {
 		lt = strtol(type + 1, &endp, 0);
@@ -122,15 +137,13 @@ mbr_parse_type(const char *type, u_char 
 		*dp_typ = (u_char)lt;
 		return (0);
 	}
-	alias = g_part_alias_name(G_PART_ALIAS_FREEBSD);
-	if (!strcasecmp(type, alias)) {
-		*dp_typ = DOSPTYP_386BSD;
-		return (0);
-	}
-	alias = g_part_alias_name(G_PART_ALIAS_MS_NTFS);
-	if (!strcasecmp(type, alias)) {
-		*dp_typ = DOSPTYP_NTFS;
-		return (0);
+	for (i = 0;
+	    i < sizeof(mbr_alias_match) / sizeof(mbr_alias_match[0]); i++) {
+		alias = g_part_alias_name(mbr_alias_match[i].alias);
+		if (strcasecmp(type, alias) == 0) {
+			*dp_typ = mbr_alias_match[i].typ;
+			return (0);
+		}
 	}
 	return (EINVAL);
 }
@@ -511,18 +524,15 @@ g_part_mbr_type(struct g_part_table *bas
     char *buf, size_t bufsz)
 {
 	struct g_part_mbr_entry *entry;
-	int type;
+	int i;
 
 	entry = (struct g_part_mbr_entry *)baseentry;
-	type = entry->ent.dp_typ;
-	switch (type) {
-	case DOSPTYP_386BSD:
-		return (g_part_alias_name(G_PART_ALIAS_FREEBSD));
-	case DOSPTYP_NTFS:
-		return (g_part_alias_name(G_PART_ALIAS_MS_NTFS));
-	default:
-		snprintf(buf, bufsz, "!%d", type);
+	for (i = 0;
+	    i < sizeof(mbr_alias_match) / sizeof(mbr_alias_match[0]); i++) {
+		if (mbr_alias_match[i].typ == entry->ent.dp_typ)
+			return (g_part_alias_name(mbr_alias_match[i].alias));
 	}
+	snprintf(buf, bufsz, "!%d", entry->ent.dp_typ);
 	return (buf);
 }
 

Modified: stable/8/sys/sys/diskmbr.h
==============================================================================
--- stable/8/sys/sys/diskmbr.h	Fri Feb 11 05:33:35 2011	(r218535)
+++ stable/8/sys/sys/diskmbr.h	Fri Feb 11 05:37:05 2011	(r218536)
@@ -43,13 +43,16 @@
 #define	DOSMAGICOFFSET	510
 #define	DOSMAGIC	0xAA55
 
+#define	DOSPTYP_EXT	0x05	/* DOS extended partition */
+#define	DOSPTYP_NTFS	0x07	/* NTFS partition */
+#define	DOSPTYP_FAT32	0x0b	/* FAT32 partition */
+#define	DOSPTYP_EXTLBA	0x0f	/* DOS extended partition */
 #define	DOSPTYP_386BSD	0xa5	/* 386BSD partition type */
 #define	DOSPTYP_LINSWP	0x82	/* Linux swap partition */
 #define	DOSPTYP_LINUX	0x83	/* Linux partition */
+#define	DOSPTYP_LINLVM	0x8e	/* Linux LVM partition */
 #define	DOSPTYP_PMBR	0xee	/* GPT Protective MBR */
-#define	DOSPTYP_EXT	5	/* DOS extended partition */
-#define	DOSPTYP_EXTLBA	15	/* DOS extended partition */
-#define	DOSPTYP_NTFS	0x07	/* NTFS partition */
+#define	DOSPTYP_LINRAID	0xfd	/* Linux raid partition */
 
 struct dos_partition {
 	unsigned char	dp_flag;	/* bootstrap flags */

Modified: stable/8/sys/sys/gpt.h
==============================================================================
--- stable/8/sys/sys/gpt.h	Fri Feb 11 05:33:35 2011	(r218535)
+++ stable/8/sys/sys/gpt.h	Fri Feb 11 05:37:05 2011	(r218536)
@@ -150,4 +150,10 @@ struct gpt_ent {
 #define	GPT_ENT_TYPE_NETBSD_CGD		\
 	{0x2db519ec,0xb10f,0x11dc,0xb9,0x9b,{0x00,0x19,0xd1,0x87,0x96,0x48}}
 
+/*
+ * Boot partition used by GRUB 2.
+ */
+#define	GPT_ENT_TYPE_BIOS_BOOT		\
+	{0x21686148,0x6449,0x6e6f,0x74,0x4e,{0x65,0x65,0x64,0x45,0x46,0x49}}
+
 #endif /* _SYS_GPT_H_ */


More information about the svn-src-all mailing list