From owner-svn-src-user@FreeBSD.ORG Fri Mar 21 05:30:29 2014 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 11312C73; Fri, 21 Mar 2014 05:30:29 +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 F213C912; Fri, 21 Mar 2014 05:30:28 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s2L5USw1028323; Fri, 21 Mar 2014 05:30:28 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s2L5URf4028314; Fri, 21 Mar 2014 05:30:27 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <201403210530.s2L5URf4028314@svn.freebsd.org> From: Marcel Moolenaar Date: Fri, 21 Mar 2014 05:30:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r263466 - 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: Fri, 21 Mar 2014 05:30:29 -0000 Author: marcel Date: Fri Mar 21 05:30:27 2014 New Revision: 263466 URL: http://svnweb.freebsd.org/changeset/base/263466 Log: Add support for partition labels and write them for GPT. Modified: user/marcel/mkimg/gpt.c user/marcel/mkimg/mkimg.c user/marcel/mkimg/mkimg.h user/marcel/mkimg/scheme.c user/marcel/mkimg/scheme.h Modified: user/marcel/mkimg/gpt.c ============================================================================== --- user/marcel/mkimg/gpt.c Fri Mar 21 04:52:46 2014 (r263465) +++ user/marcel/mkimg/gpt.c Fri Mar 21 05:30:27 2014 (r263466) @@ -173,6 +173,7 @@ gpt_mktbl(u_int tblsz, u_int secsz) struct gpt_ent *tbl, *ent; struct part *part; uint64_t limit; + int c, idx; tbl = calloc(tblsz, secsz); if (tbl == NULL) @@ -186,7 +187,13 @@ gpt_mktbl(u_int tblsz, u_int secsz) le64enc(&ent->ent_lba_start, part->offset / secsz); limit = (part->offset + part->size) / secsz; le64enc(&ent->ent_lba_end, limit - 1); - /* TODO add support for labels */ + if (part->label != NULL) { + idx = 0; + while ((c = part->label[idx]) != '\0') { + le16enc(ent->ent_name + idx, c); + idx++; + } + } } return (tbl); } @@ -272,7 +279,8 @@ static struct mkimg_scheme gpt_scheme = .aliases = gpt_aliases, .metadata = gpt_metadata, .write = gpt_write, - .nparts = 4096 + .nparts = 4096, + .labellen = 36 }; SCHEME_DEFINE(gpt_scheme); Modified: user/marcel/mkimg/mkimg.c ============================================================================== --- user/marcel/mkimg/mkimg.c Fri Mar 21 04:52:46 2014 (r263465) +++ user/marcel/mkimg/mkimg.c Fri Mar 21 05:30:27 2014 (r263466) @@ -163,6 +163,21 @@ parse_part(const char *spec) goto errout; } + spec = part->alias; + sep = strchr(spec, '/'); + if (sep != NULL) { + *sep++ = '\0'; + if (strlen(part->alias) == 0 || strlen(sep) == 0) { + error = EINVAL; + goto errout; + } + part->label = strdup(sep); + if (part->label == NULL) { + error = ENOMEM; + goto errout; + } + } + part->index = nparts; STAILQ_INSERT_TAIL(&partlist, part, link); nparts++; Modified: user/marcel/mkimg/mkimg.h ============================================================================== --- user/marcel/mkimg/mkimg.h Fri Mar 21 04:52:46 2014 (r263465) +++ user/marcel/mkimg/mkimg.h Fri Mar 21 05:30:27 2014 (r263466) @@ -44,6 +44,7 @@ struct part { uintptr_t type; /* Scheme-specific partition type. */ off_t offset; /* Byte-offset of partition in image. */ off_t size; /* Size in bytes of partition. */ + char *label; /* Partition label. */ }; extern STAILQ_HEAD(partlisthead, part) partlist; Modified: user/marcel/mkimg/scheme.c ============================================================================== --- user/marcel/mkimg/scheme.c Fri Mar 21 04:52:46 2014 (r263465) +++ user/marcel/mkimg/scheme.c Fri Mar 21 05:30:27 2014 (r263466) @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include #include #include "mkimg.h" @@ -86,6 +86,13 @@ scheme_check_part(struct part *p) if (alias == NULL) return (EINVAL); p->type = iter->type; + + /* Validate the optional label. */ + if (p->label != NULL) { + if (strlen(p->label) > scheme->labellen) + return (EOPNOTSUPP); + } + return (0); } Modified: user/marcel/mkimg/scheme.h ============================================================================== --- user/marcel/mkimg/scheme.h Fri Mar 21 04:52:46 2014 (r263465) +++ user/marcel/mkimg/scheme.h Fri Mar 21 05:30:27 2014 (r263466) @@ -50,7 +50,8 @@ struct mkimg_scheme { #define SCHEME_META_PART_BEFORE 3 #define SCHEME_META_PART_AFTER 4 int (*write)(int, off_t, u_int, u_int); - int nparts; + u_int nparts; + u_int labellen; }; SET_DECLARE(schemes, struct mkimg_scheme);