Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Mar 2014 21:44:52 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r263382 - user/marcel/mkimg
Message-ID:  <201403192144.s2JLiq28054051@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Wed Mar 19 21:44:51 2014
New Revision: 263382
URL: http://svnweb.freebsd.org/changeset/base/263382

Log:
  Add mkimg.h. It contains the 'part' structure definition and the linked
  list (STAILQ) so that it can be shared and re-used in all source files.
  Replace the now unneeded scheme_add_part() with scheme_check_part() for
  posterity.
  
  Also (should have been a separate commit), remove the enforcement of
  creating a GPT table with at least 128 entries. While this is generally
  advised as the default or minimum, it's not actually a hard requirement.
  We now recreate a table that's precisely enough (rounded of course).
  
  WHile

Added:
  user/marcel/mkimg/mkimg.h   (contents, props changed)
Modified:
  user/marcel/mkimg/mkimg.c
  user/marcel/mkimg/scheme.c
  user/marcel/mkimg/scheme.h

Modified: user/marcel/mkimg/mkimg.c
==============================================================================
--- user/marcel/mkimg/mkimg.c	Wed Mar 19 21:37:44 2014	(r263381)
+++ user/marcel/mkimg/mkimg.c	Wed Mar 19 21:44:51 2014	(r263382)
@@ -40,26 +40,13 @@ __FBSDID("$FreeBSD$");
 #include <sysexits.h>
 #include <unistd.h>
 
+#include "mkimg.h"
 #include "scheme.h"
 
 #define	BUFFER_SIZE	(1024*1024)
 
-struct part {
-	STAILQ_ENTRY(part) link;
-	char	*type;		/* Partition type. */
-	char	*contents;	/* Contents/size specification. */
-	u_int	kind;		/* Content kind. */
-#define	PART_UNDEF	0
-#define	PART_KIND_FILE	1
-#define	PART_KIND_PIPE	2
-#define	PART_KIND_SIZE	3
-	u_int	index;		/* Partition index (0-based). */
-	off_t	offset;		/* Byte-offset of partition in image. */
-	off_t	size;		/* Size in bytes of partition. */
-};
-
-static STAILQ_HEAD(, part) parts = STAILQ_HEAD_INITIALIZER(parts);
-static u_int nparts = 0;
+struct partlisthead partlist = STAILQ_HEAD_INITIALIZER(partlist);
+u_int nparts = 0;
 
 static int bcfd = 0;
 static int outfd = 0;
@@ -155,7 +142,7 @@ parse_part(const char *spec)
 	}
 
 	part->index = nparts;
-	STAILQ_INSERT_TAIL(&parts, part, link);
+	STAILQ_INSERT_TAIL(&partlist, part, link);
 	nparts++;
 	return (0);
 
@@ -208,7 +195,7 @@ mkimg(void)
 		    scheme_max_parts());
 
 	offset = scheme_first_offset(nparts);
-	STAILQ_FOREACH(part, &parts, link) {
+	STAILQ_FOREACH(part, &partlist, link) {
 		part->offset = offset;
 		lseek(tmpfd, offset, SEEK_SET);
 		/* XXX check error */
@@ -237,8 +224,7 @@ mkimg(void)
 			break;
 		}
 		part->size = size;
-		scheme_add_part(part->index, part->type, part->offset,
-		    part->size);
+		scheme_check_part(part);
 		offset = scheme_next_offset(offset, size);
 	}
 

Added: user/marcel/mkimg/mkimg.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/marcel/mkimg/mkimg.h	Wed Mar 19 21:44:51 2014	(r263382)
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2014 Juniper Networks, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _MKIMG_MKIMG_H_
+#define	_MKIMG_MKIMG_H_
+
+struct part {
+	STAILQ_ENTRY(part) link;
+	char	*type;		/* Partition type. */
+	char	*contents;	/* Contents/size specification. */
+	u_int	kind;		/* Content kind. */
+#define	PART_UNDEF	0
+#define	PART_KIND_FILE	1
+#define	PART_KIND_PIPE	2
+#define	PART_KIND_SIZE	3
+	u_int	index;		/* Partition index (0-based). */
+	off_t	offset;		/* Byte-offset of partition in image. */
+	off_t	size;		/* Size in bytes of partition. */
+};
+
+extern STAILQ_HEAD(partlisthead, part) partlist;
+extern u_int nparts;
+
+#endif /* _MKIMG_MKIMG_H_ */

Modified: user/marcel/mkimg/scheme.c
==============================================================================
--- user/marcel/mkimg/scheme.c	Wed Mar 19 21:37:44 2014	(r263381)
+++ user/marcel/mkimg/scheme.c	Wed Mar 19 21:44:51 2014	(r263382)
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/types.h>
 #include <sys/diskmbr.h>
 #include <sys/diskpc98.h>
+#include <sys/queue.h>
 #include <sys/vtoc.h>
 #include <err.h>
 #include <errno.h>
@@ -37,10 +38,9 @@ __FBSDID("$FreeBSD$");
 #include <strings.h>
 #include <unistd.h>
 
+#include "mkimg.h"
 #include "scheme.h"
 
-#define	MAX(a, b)	((a < b) ? b : a)
-
 static struct scheme {
 	const char *lexeme;
 	u_int token;
@@ -57,7 +57,6 @@ static struct scheme {
 
 static u_int scheme = SCHEME_UNDEF;
 static u_int secsz = 512;
-static u_int nparts = 0;
 
 int
 scheme_select(const char *spec)
@@ -83,27 +82,12 @@ scheme_selected(void)
 }
 
 int
-scheme_add_part(u_int idx, const char *type, off_t offset, off_t size)
+scheme_check_part(struct part *p __unused)
 {
 
-	warnx("part: index=%u, type=`%s', offset=%ju, size=%ju", idx,
-	    type, (uintmax_t)offset, (uintmax_t)size);
-	switch (scheme) {
-	case SCHEME_APM:
-		break;
-	case SCHEME_BSD:
-		break;
-	case SCHEME_EBR:
-		break;
-	case SCHEME_GPT:
-		break;
-	case SCHEME_MBR:
-		break;
-	case SCHEME_PC98:
-		break;
-	case SCHEME_VTOC8:
-		break;
-	}
+	warnx("part: index=%u, type=`%s', offset=%ju, size=%ju", p->index,
+	    p->type, (uintmax_t)p->offset, (uintmax_t)p->size);
+
 	return (0);
 }
 
@@ -146,7 +130,6 @@ scheme_first_offset(u_int parts)
 {
 	off_t off;
 
-	nparts = parts;		/* Save nparts for later. */
 	switch (scheme) {
 	case SCHEME_APM:
 		off = parts + 1;
@@ -158,13 +141,13 @@ scheme_first_offset(u_int parts)
 		off = 1;
 		break;
 	case SCHEME_GPT:
-		off = 2 + (MAX(128, parts) + 3) / 4;
+		off = 2 + (parts + 3) / 4;
 		break;
 	case SCHEME_MBR:
 		off = 1;
 		break;
 	case SCHEME_PC98:
-		off = 16;
+		off = 2;
 		break;
 	case SCHEME_VTOC8:
 		off = 1;
@@ -194,7 +177,7 @@ scheme_write(int fd, off_t off)
 
 	switch (scheme) {
 	case SCHEME_GPT:
-		lim = off + secsz * (1 + (MAX(128, nparts) + 3) / 4);
+		lim = off + secsz * (1 + (nparts + 3) / 4);
 		break;
 	case SCHEME_EBR:
 		off -= secsz;

Modified: user/marcel/mkimg/scheme.h
==============================================================================
--- user/marcel/mkimg/scheme.h	Wed Mar 19 21:37:44 2014	(r263381)
+++ user/marcel/mkimg/scheme.h	Wed Mar 19 21:44:51 2014	(r263382)
@@ -41,7 +41,7 @@
 int	scheme_select(const char *);
 u_int	scheme_selected(void);
 
-int scheme_add_part(u_int, const char *, off_t, off_t);
+int scheme_check_part(struct part *);
 u_int scheme_max_parts(void);
 off_t scheme_first_offset(u_int);
 off_t scheme_next_offset(off_t, uint64_t);



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