Date: Fri, 21 Mar 2014 05:30:27 +0000 (UTC) From: Marcel Moolenaar <marcel@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r263466 - user/marcel/mkimg Message-ID: <201403210530.s2L5URf4028314@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <err.h> #include <errno.h> #include <stdint.h> -#include <strings.h> +#include <string.h> #include <unistd.h> #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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201403210530.s2L5URf4028314>