svn commit: r263414 - user/marcel/mkimg

Marcel Moolenaar marcel at FreeBSD.org
Thu Mar 20 02:27:26 UTC 2014


Author: marcel
Date: Thu Mar 20 02:27:25 2014
New Revision: 263414
URL: http://svnweb.freebsd.org/changeset/base/263414

Log:
  Check the partition type alias as defined by the scheme.

Modified:
  user/marcel/mkimg/mkimg.c
  user/marcel/mkimg/mkimg.h
  user/marcel/mkimg/scheme.c

Modified: user/marcel/mkimg/mkimg.c
==============================================================================
--- user/marcel/mkimg/mkimg.c	Thu Mar 20 02:23:52 2014	(r263413)
+++ user/marcel/mkimg/mkimg.c	Thu Mar 20 02:27:25 2014	(r263414)
@@ -133,12 +133,12 @@ parse_part(const char *spec)
 		error = EINVAL;
 		goto errout;
 	}
-	part->type = malloc(len);
-	if (part->type == NULL) {
+	part->alias = malloc(len);
+	if (part->alias == NULL) {
 		error = ENOMEM;
 		goto errout;
 	}
-	strlcpy(part->type, spec, len);
+	strlcpy(part->alias, spec, len);
 	spec = sep + 1;
 
 	switch (*spec) {
@@ -169,8 +169,8 @@ parse_part(const char *spec)
 	return (0);
 
  errout:
-	if (part->type != NULL)
-		free(part->type);
+	if (part->alias != NULL)
+		free(part->alias);
 	free(part);
 	return (error);
 }
@@ -246,7 +246,9 @@ mkimg(void)
 			break;
 		}
 		part->size = size;
-		scheme_check_part(part);
+		error = scheme_check_part(part);
+		if (error)
+			errc(EX_DATAERR, error, "partition %d", part->index+1);
 		offset = scheme_next_offset(offset, size);
 	}
 

Modified: user/marcel/mkimg/mkimg.h
==============================================================================
--- user/marcel/mkimg/mkimg.h	Thu Mar 20 02:23:52 2014	(r263413)
+++ user/marcel/mkimg/mkimg.h	Thu Mar 20 02:27:25 2014	(r263414)
@@ -31,7 +31,7 @@
 
 struct part {
 	STAILQ_ENTRY(part) link;
-	char	*type;		/* Partition type. */
+	char	*alias;		/* Partition type alias. */
 	char	*contents;	/* Contents/size specification. */
 	u_int	kind;		/* Content kind. */
 #define	PART_UNDEF	0

Modified: user/marcel/mkimg/scheme.c
==============================================================================
--- user/marcel/mkimg/scheme.c	Thu Mar 20 02:23:52 2014	(r263413)
+++ user/marcel/mkimg/scheme.c	Thu Mar 20 02:27:25 2014	(r263414)
@@ -67,11 +67,25 @@ scheme_selected(void)
 int
 scheme_check_part(struct part *p)
 {
+	struct mkimg_alias *alias, *iter;
 
 	warnx("part(%s): index=%u, type=`%s', offset=%ju, size=%ju",
-	    scheme->name, p->index, p->type, (uintmax_t)p->offset,
+	    scheme->name, p->index, p->alias, (uintmax_t)p->offset,
 	    (uintmax_t)p->size);
 
+	/* Check the partition type alias */
+	alias = NULL;
+	iter = scheme->aliases;
+	while (iter->name != NULL) {
+		if (strcasecmp(p->alias, iter->name) == 0) {
+			alias = iter;
+			break;
+		}
+		iter++;
+	}
+	if (alias == NULL)
+		return (EINVAL);
+
 	return (0);
 }
 


More information about the svn-src-user mailing list