From owner-svn-src-user@FreeBSD.ORG Thu Mar 20 19:37:32 2014 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C025AB72; Thu, 20 Mar 2014 19:37:32 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id ACAD883F; Thu, 20 Mar 2014 19:37:32 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s2KJbW5Q088066; Thu, 20 Mar 2014 19:37:32 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s2KJbUan088057; Thu, 20 Mar 2014 19:37:30 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <201403201937.s2KJbUan088057@svn.freebsd.org> From: Marcel Moolenaar Date: Thu, 20 Mar 2014 19:37:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r263440 - user/marcel/mkimg X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Mar 2014 19:37:32 -0000 Author: marcel Date: Thu Mar 20 19:37:30 2014 New Revision: 263440 URL: http://svnweb.freebsd.org/changeset/base/263440 Log: Replace *_get_leader() and *_get_trailer() with a single *_metadata(). This single function takes a where argument to indicate the kind of metadata to "size". This way we can also get rid of the "padding" field in the scheme structure. This should make it a little more understandable what's going on. 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 Thu Mar 20 19:37:14 2014 (r263439) +++ user/marcel/mkimg/apm.c Thu Mar 20 19:37:30 2014 (r263440) @@ -40,28 +40,21 @@ static struct mkimg_alias apm_aliases[] { NULL, 0 } }; -static off_t -apm_get_leader(u_int parts) +static u_int +apm_metadata(u_int where, u_int parts, u_int secsz __unused) { + u_int secs; - return (parts + 1); -} - -static off_t -apm_get_trailer(u_int parts __unused) -{ - - return (0); + secs = (where == SCHEME_META_IMG_START) ? parts + 1 : 0; + return (secs); } static struct mkimg_scheme apm_scheme = { .name = "apm", .description = "Apple Partition Map", - .nparts = 4096, - .padding = 0, .aliases = apm_aliases, - .get_leader = apm_get_leader, - .get_trailer = apm_get_trailer + .metadata = apm_metadata, + .nparts = 4096 }; SCHEME_DEFINE(apm_scheme); Modified: user/marcel/mkimg/bsd.c ============================================================================== --- user/marcel/mkimg/bsd.c Thu Mar 20 19:37:14 2014 (r263439) +++ user/marcel/mkimg/bsd.c Thu Mar 20 19:37:30 2014 (r263440) @@ -40,28 +40,21 @@ static struct mkimg_alias bsd_aliases[] { NULL, 0 } }; -static off_t -bsd_get_leader(u_int parts __unused) +static u_int +bsd_metadata(u_int where, u_int parts __unused, u_int secsz __unused) { + u_int secs; - return (16); -} - -static off_t -bsd_get_trailer(u_int parts __unused) -{ - - return (0); + secs = (where == SCHEME_META_IMG_START) ? 16 : 0; + return (secs); } static struct mkimg_scheme bsd_scheme = { .name = "bsd", - .description = "GUID Partition Table", - .nparts = 20, - .padding = 0, + .description = "BSD disk label", .aliases = bsd_aliases, - .get_leader = bsd_get_leader, - .get_trailer = bsd_get_trailer + .metadata = bsd_metadata, + .nparts = 20 }; SCHEME_DEFINE(bsd_scheme); Modified: user/marcel/mkimg/ebr.c ============================================================================== --- user/marcel/mkimg/ebr.c Thu Mar 20 19:37:14 2014 (r263439) +++ user/marcel/mkimg/ebr.c Thu Mar 20 19:37:30 2014 (r263440) @@ -40,32 +40,21 @@ static struct mkimg_alias ebr_aliases[] { NULL, 0 } }; -static off_t -ebr_get_leader(u_int parts __unused) +static u_int +ebr_metadata(u_int where, u_int parts __unused, u_int secsz __unused) { + u_int secs; - return (1); -} - -static off_t -ebr_get_trailer(u_int parts __unused) -{ - - /* - * Compensate for having reserved a sector for the EBR after - * the last partition. - */ - return (-1); + secs = (where == SCHEME_META_PART_BEFORE) ? 1 : 0; + return (secs); } static struct mkimg_scheme ebr_scheme = { .name = "ebr", .description = "Extended Boot Record", - .nparts = 4096, - .padding = 1, /* See ebr_get_trailer() above */ .aliases = ebr_aliases, - .get_leader = ebr_get_leader, - .get_trailer = ebr_get_trailer + .metadata = ebr_metadata, + .nparts = 4096 }; SCHEME_DEFINE(ebr_scheme); Modified: user/marcel/mkimg/gpt.c ============================================================================== --- user/marcel/mkimg/gpt.c Thu Mar 20 19:37:14 2014 (r263439) +++ user/marcel/mkimg/gpt.c Thu Mar 20 19:37:30 2014 (r263440) @@ -44,28 +44,26 @@ static struct mkimg_alias gpt_aliases[] { NULL, 0 } }; -static off_t -gpt_get_leader(u_int parts) +static u_int +gpt_metadata(u_int where, u_int parts, u_int secsz) { + u_int ents, secs; - return (2 + (parts + 3) / 4); -} - -static off_t -gpt_get_trailer(u_int parts) -{ + if (where != SCHEME_META_IMG_START && where != SCHEME_META_IMG_START) + return (0); - return (1 + (parts + 3) / 4); + ents = secsz / sizeof(struct gpt_ent); + secs = (parts + ents - 1) / ents; + secs += (where == SCHEME_META_IMG_START) ? 2 : 1; + return (secs); } static struct mkimg_scheme gpt_scheme = { .name = "gpt", .description = "GUID Partition Table", - .nparts = 4096, - .padding = 0, .aliases = gpt_aliases, - .get_leader = gpt_get_leader, - .get_trailer = gpt_get_trailer + .metadata = gpt_metadata, + .nparts = 4096 }; SCHEME_DEFINE(gpt_scheme); Modified: user/marcel/mkimg/mbr.c ============================================================================== --- user/marcel/mkimg/mbr.c Thu Mar 20 19:37:14 2014 (r263439) +++ user/marcel/mkimg/mbr.c Thu Mar 20 19:37:30 2014 (r263440) @@ -41,28 +41,21 @@ static struct mkimg_alias mbr_aliases[] { NULL, 0 } }; -static off_t -mbr_get_leader(u_int parts __unused) +static u_int +mbr_metadata(u_int where, u_int parts __unused, u_int secsz __unused) { + u_int secs; - return (1); -} - -static off_t -mbr_get_trailer(u_int parts __unused) -{ - - return (0); + secs = (where == SCHEME_META_IMG_START) ? 1 : 0; + return (secs); } static struct mkimg_scheme mbr_scheme = { .name = "mbr", .description = "Master Boot Record", - .nparts = NDOSPART, - .padding = 0, .aliases = mbr_aliases, - .get_leader = mbr_get_leader, - .get_trailer = mbr_get_trailer + .metadata = mbr_metadata, + .nparts = NDOSPART }; SCHEME_DEFINE(mbr_scheme); Modified: user/marcel/mkimg/pc98.c ============================================================================== --- user/marcel/mkimg/pc98.c Thu Mar 20 19:37:14 2014 (r263439) +++ user/marcel/mkimg/pc98.c Thu Mar 20 19:37:30 2014 (r263440) @@ -41,28 +41,21 @@ static struct mkimg_alias pc98_aliases[] { NULL, 0 } }; -static off_t -pc98_get_leader(u_int parts __unused) +static u_int +pc98_metadata(u_int where, u_int parts __unused, u_int secsz __unused) { + u_int secs; - return (2); -} - -static off_t -pc98_get_trailer(u_int parts __unused) -{ - - return (0); + secs = (where == SCHEME_META_IMG_START) ? 2 : 0; + return (secs); } static struct mkimg_scheme pc98_scheme = { .name = "pc98", .description = "PC-9800 disk partitions", - .nparts = PC98_NPARTS, - .padding = 0, .aliases = pc98_aliases, - .get_leader = pc98_get_leader, - .get_trailer = pc98_get_trailer + .metadata = pc98_metadata, + .nparts = PC98_NPARTS }; SCHEME_DEFINE(pc98_scheme); Modified: user/marcel/mkimg/scheme.c ============================================================================== --- user/marcel/mkimg/scheme.c Thu Mar 20 19:37:14 2014 (r263439) +++ user/marcel/mkimg/scheme.c Thu Mar 20 19:37:30 2014 (r263440) @@ -99,27 +99,35 @@ scheme_max_parts(void) off_t scheme_first_offset(u_int parts) { - off_t off; + u_int secs; - off = scheme->get_leader(parts); - off *= secsz; - return (off); + secs = scheme->metadata(SCHEME_META_IMG_START, parts, secsz) + + scheme->metadata(SCHEME_META_PART_BEFORE, 0, secsz); + return (secs * secsz); } off_t scheme_next_offset(off_t off, uint64_t sz) { + u_int secs; sz = (sz + secsz - 1) & ~(secsz - 1); - sz += scheme->padding * secsz; + secs = scheme->metadata(SCHEME_META_PART_AFTER, 0, secsz) + + scheme->metadata(SCHEME_META_PART_BEFORE, 0, secsz); + sz += (secs * secsz); return (off + sz); } void scheme_write(int fd, off_t off) { - off_t trailer; + u_int secs; - trailer = scheme->get_trailer(nparts) * secsz; - ftruncate(fd, off + trailer); + /* Fixup offset: it has an extra metadata before the partition */ + secs = scheme->metadata(SCHEME_META_PART_BEFORE, 0, secsz); + off -= (secs * secsz); + + secs = scheme->metadata(SCHEME_META_IMG_END, nparts, secsz); + off += (secs * secsz); + ftruncate(fd, off); } Modified: user/marcel/mkimg/scheme.h ============================================================================== --- user/marcel/mkimg/scheme.h Thu Mar 20 19:37:14 2014 (r263439) +++ user/marcel/mkimg/scheme.h Thu Mar 20 19:37:30 2014 (r263440) @@ -30,20 +30,22 @@ #define _MKIMG_SCHEME_H_ struct mkimg_alias { - const char *name; - uintptr_t tp; + const char *name; + uintptr_t tp; #define ALIAS_PTR(p) (uintptr_t)(p) #define ALIAS_INT(i) (uintptr_t)(i) }; struct mkimg_scheme { - const char *name; - const char *description; - int nparts; - int padding; + const char *name; + const char *description; struct mkimg_alias *aliases; - off_t (*get_leader)(u_int); - off_t (*get_trailer)(u_int); + u_int (*metadata)(u_int, u_int, u_int); +#define SCHEME_META_IMG_START 1 +#define SCHEME_META_IMG_END 2 +#define SCHEME_META_PART_BEFORE 3 +#define SCHEME_META_PART_AFTER 4 + int nparts; }; SET_DECLARE(schemes, struct mkimg_scheme); Modified: user/marcel/mkimg/vtoc8.c ============================================================================== --- user/marcel/mkimg/vtoc8.c Thu Mar 20 19:37:14 2014 (r263439) +++ user/marcel/mkimg/vtoc8.c Thu Mar 20 19:37:30 2014 (r263440) @@ -41,28 +41,21 @@ static struct mkimg_alias vtoc8_aliases[ { NULL, 0 } }; -static off_t -vtoc8_get_leader(u_int parts __unused) +static u_int +vtoc8_metadata(u_int where, u_int parts __unused, u_int secsz __unused) { + u_int secs; - return (1); -} - -static off_t -vtoc8_get_trailer(u_int parts __unused) -{ - - return (0); + secs = (where == SCHEME_META_IMG_START) ? 1 : 0; + return (secs); } static struct mkimg_scheme vtoc8_scheme = { .name = "vtoc8", .description = "SMI VTOC8 disk labels", - .nparts = VTOC8_NPARTS, - .padding = 0, .aliases = vtoc8_aliases, - .get_leader = vtoc8_get_leader, - .get_trailer = vtoc8_get_trailer + .metadata = vtoc8_metadata, + .nparts = VTOC8_NPARTS }; SCHEME_DEFINE(vtoc8_scheme);