Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Mar 2014 16:11:49 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r263487 - user/marcel/mkimg
Message-ID:  <201403211611.s2LGBnu1088895@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Fri Mar 21 16:11:49 2014
New Revision: 263487
URL: http://svnweb.freebsd.org/changeset/base/263487

Log:
  Add more partition types (mostly just the FreeBSD ones) to GPT.
  Avoid having schemes use literal strings by introducing an enum
  as the intermediate representation (see geom_part).

Modified:
  user/marcel/mkimg/apm.c
  user/marcel/mkimg/bsd.c
  user/marcel/mkimg/ebr.c
  user/marcel/mkimg/gpt.c
  user/marcel/mkimg/mbr.c
  user/marcel/mkimg/pc98.c
  user/marcel/mkimg/scheme.c
  user/marcel/mkimg/scheme.h
  user/marcel/mkimg/vtoc8.c

Modified: user/marcel/mkimg/apm.c
==============================================================================
--- user/marcel/mkimg/apm.c	Fri Mar 21 15:46:47 2014	(r263486)
+++ user/marcel/mkimg/apm.c	Fri Mar 21 16:11:49 2014	(r263487)
@@ -36,7 +36,7 @@ __FBSDID("$FreeBSD$");
 #include "scheme.h"
 
 static struct mkimg_alias apm_aliases[] = {
-    {	NULL, 0 }
+    {	ALIAS_NONE, 0 }
 };
 
 static u_int

Modified: user/marcel/mkimg/bsd.c
==============================================================================
--- user/marcel/mkimg/bsd.c	Fri Mar 21 15:46:47 2014	(r263486)
+++ user/marcel/mkimg/bsd.c	Fri Mar 21 16:11:49 2014	(r263487)
@@ -36,7 +36,7 @@ __FBSDID("$FreeBSD$");
 #include "scheme.h"
 
 static struct mkimg_alias bsd_aliases[] = {
-    {	NULL, 0 }
+    {	ALIAS_NONE, 0 }
 };
 
 static u_int

Modified: user/marcel/mkimg/ebr.c
==============================================================================
--- user/marcel/mkimg/ebr.c	Fri Mar 21 15:46:47 2014	(r263486)
+++ user/marcel/mkimg/ebr.c	Fri Mar 21 16:11:49 2014	(r263487)
@@ -36,7 +36,7 @@ __FBSDID("$FreeBSD$");
 #include "scheme.h"
 
 static struct mkimg_alias ebr_aliases[] = {
-    {	NULL, 0 }
+    {	ALIAS_NONE, 0 }
 };
 
 static u_int

Modified: user/marcel/mkimg/gpt.c
==============================================================================
--- user/marcel/mkimg/gpt.c	Fri Mar 21 15:46:47 2014	(r263486)
+++ user/marcel/mkimg/gpt.c	Fri Mar 21 16:11:49 2014	(r263487)
@@ -43,10 +43,26 @@ __FBSDID("$FreeBSD$");
 #include "scheme.h"
 
 static uuid_t gpt_uuid_efi = GPT_ENT_TYPE_EFI;
+static uuid_t gpt_uuid_freebsd = GPT_ENT_TYPE_FREEBSD;
+static uuid_t gpt_uuid_freebsd_boot = GPT_ENT_TYPE_FREEBSD_BOOT;
+static uuid_t gpt_uuid_freebsd_nandfs = GPT_ENT_TYPE_FREEBSD_NANDFS;
+static uuid_t gpt_uuid_freebsd_swap = GPT_ENT_TYPE_FREEBSD_SWAP;
+static uuid_t gpt_uuid_freebsd_ufs = GPT_ENT_TYPE_FREEBSD_UFS;
+static uuid_t gpt_uuid_freebsd_vinum = GPT_ENT_TYPE_FREEBSD_VINUM;
+static uuid_t gpt_uuid_freebsd_zfs = GPT_ENT_TYPE_FREEBSD_ZFS;
+static uuid_t gpt_uuid_mbr = GPT_ENT_TYPE_MBR;
 
 static struct mkimg_alias gpt_aliases[] = {
-    {	"efi", ALIAS_PTR2TYPE(&gpt_uuid_efi) },
-    {	NULL, 0 }
+    {	ALIAS_EFI, ALIAS_PTR2TYPE(&gpt_uuid_efi) },
+    {	ALIAS_FREEBSD, ALIAS_PTR2TYPE(&gpt_uuid_freebsd) },
+    {	ALIAS_FREEBSD_BOOT, ALIAS_PTR2TYPE(&gpt_uuid_freebsd_boot) },
+    {	ALIAS_FREEBSD_NANDFS, ALIAS_PTR2TYPE(&gpt_uuid_freebsd_nandfs) },
+    {	ALIAS_FREEBSD_SWAP, ALIAS_PTR2TYPE(&gpt_uuid_freebsd_swap) },
+    {	ALIAS_FREEBSD_UFS, ALIAS_PTR2TYPE(&gpt_uuid_freebsd_ufs) },
+    {	ALIAS_FREEBSD_VINUM, ALIAS_PTR2TYPE(&gpt_uuid_freebsd_vinum) },
+    {	ALIAS_FREEBSD_ZFS, ALIAS_PTR2TYPE(&gpt_uuid_freebsd_zfs) },
+    {	ALIAS_MBR, ALIAS_PTR2TYPE(&gpt_uuid_mbr) },
+    {	ALIAS_NONE, 0 }		/* Keep last! */
 };
 
 /* CRC32 code derived from work by Gary S. Brown. */

Modified: user/marcel/mkimg/mbr.c
==============================================================================
--- user/marcel/mkimg/mbr.c	Fri Mar 21 15:46:47 2014	(r263486)
+++ user/marcel/mkimg/mbr.c	Fri Mar 21 16:11:49 2014	(r263487)
@@ -36,7 +36,7 @@ __FBSDID("$FreeBSD$");
 #include "scheme.h"
 
 static struct mkimg_alias mbr_aliases[] = {
-    {	NULL, 0 }
+    {	ALIAS_NONE, 0 }
 };
 
 static u_int

Modified: user/marcel/mkimg/pc98.c
==============================================================================
--- user/marcel/mkimg/pc98.c	Fri Mar 21 15:46:47 2014	(r263486)
+++ user/marcel/mkimg/pc98.c	Fri Mar 21 16:11:49 2014	(r263487)
@@ -36,7 +36,7 @@ __FBSDID("$FreeBSD$");
 #include "scheme.h"
 
 static struct mkimg_alias pc98_aliases[] = {
-    {	NULL, 0 }
+    {	ALIAS_NONE, 0 }
 };
 
 static u_int

Modified: user/marcel/mkimg/scheme.c
==============================================================================
--- user/marcel/mkimg/scheme.c	Fri Mar 21 15:46:47 2014	(r263486)
+++ user/marcel/mkimg/scheme.c	Fri Mar 21 16:11:49 2014	(r263487)
@@ -39,9 +39,39 @@ __FBSDID("$FreeBSD$");
 #include "mkimg.h"
 #include "scheme.h"
 
+static struct {
+	const char *name;
+	enum alias alias;
+} scheme_alias[] = {
+	{ "efi", ALIAS_EFI },
+	{ "freebsd", ALIAS_FREEBSD },
+	{ "freebsd-boot", ALIAS_FREEBSD_BOOT },
+	{ "freebsd-nandfs", ALIAS_FREEBSD_NANDFS },
+	{ "freebsd-swap", ALIAS_FREEBSD_SWAP },
+	{ "freebsd-ufs", ALIAS_FREEBSD_UFS },
+	{ "freebsd-vinum", ALIAS_FREEBSD_VINUM },
+	{ "freebsd-zfs", ALIAS_FREEBSD_ZFS },
+	{ "mbr", ALIAS_MBR },
+	{ NULL, ALIAS_NONE }		/* Keep last! */
+};
+
 static struct mkimg_scheme *scheme;
 static u_int secsz = 512;
 
+static enum alias
+scheme_parse_alias(const char *name)
+{
+	u_int idx;
+
+	idx = 0;
+	while (scheme_alias[idx].name != NULL) {
+		if (strcasecmp(scheme_alias[idx].name, name) == 0)
+			return (scheme_alias[idx].alias);
+		idx++;
+	}
+	return (ALIAS_NONE);
+}
+
 int
 scheme_select(const char *spec)
 {
@@ -67,30 +97,32 @@ scheme_selected(void)
 int
 scheme_check_part(struct part *p)
 {
-	struct mkimg_alias *alias, *iter;
+	struct mkimg_alias *iter;
+	enum alias alias;
 
 	warnx("part(%s): index=%u, type=`%s', offset=%ju, size=%ju",
 	    scheme->name, p->index, p->alias, (uintmax_t)p->offset,
 	    (uintmax_t)p->size);
 
 	/* Check the partition type alias */
-	alias = NULL;
+	alias = scheme_parse_alias(p->alias);
+	if (alias == ALIAS_NONE)
+		return (EINVAL);
+
 	iter = scheme->aliases;
-	while (iter->name != NULL) {
-		if (strcasecmp(p->alias, iter->name) == 0) {
-			alias = iter;
+	while (iter->alias != ALIAS_NONE) {
+		if (alias == iter->alias)
 			break;
-		}
 		iter++;
 	}
-	if (alias == NULL)
+	if (iter->alias == ALIAS_NONE)
 		return (EINVAL);
 	p->type = iter->type;
 
 	/* Validate the optional label. */
 	if (p->label != NULL) {
 		if (strlen(p->label) > scheme->labellen)
-			return (EOPNOTSUPP);
+			return (EINVAL);
 	}
 
 	return (0);

Modified: user/marcel/mkimg/scheme.h
==============================================================================
--- user/marcel/mkimg/scheme.h	Fri Mar 21 15:46:47 2014	(r263486)
+++ user/marcel/mkimg/scheme.h	Fri Mar 21 16:11:49 2014	(r263487)
@@ -31,8 +31,24 @@
 
 #include <sys/linker_set.h>
 
+enum alias {
+	ALIAS_NONE,		/* Keep first! */
+	/* start */
+	ALIAS_EFI,
+	ALIAS_FREEBSD,
+	ALIAS_FREEBSD_BOOT,
+	ALIAS_FREEBSD_NANDFS,
+	ALIAS_FREEBSD_SWAP,
+	ALIAS_FREEBSD_UFS,
+	ALIAS_FREEBSD_VINUM,
+	ALIAS_FREEBSD_ZFS,
+	ALIAS_MBR,
+	/* end */
+	ALIAS_COUNT		/* Keep last! */
+};
+
 struct mkimg_alias {
-	const char	*name;
+	u_int		alias;
 	uintptr_t	type;
 #define	ALIAS_PTR2TYPE(p)	(uintptr_t)(p)
 #define	ALIAS_INT2TYPE(i)	(i)

Modified: user/marcel/mkimg/vtoc8.c
==============================================================================
--- user/marcel/mkimg/vtoc8.c	Fri Mar 21 15:46:47 2014	(r263486)
+++ user/marcel/mkimg/vtoc8.c	Fri Mar 21 16:11:49 2014	(r263487)
@@ -36,7 +36,7 @@ __FBSDID("$FreeBSD$");
 #include "scheme.h"
 
 static struct mkimg_alias vtoc8_aliases[] = {
-    {	NULL, 0 }
+    {	ALIAS_NONE, 0 }
 };
 
 static u_int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201403211611.s2LGBnu1088895>