Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sbin/gpt/add.c,v rcsdiff: /ftp/cvs/cvsroot/src/sbin/gpt/add.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.22 retrieving revision 1.23 diff -u -p -r1.22 -r1.23 --- src/sbin/gpt/add.c 2013/12/06 02:31:31 1.22 +++ src/sbin/gpt/add.c 2013/12/08 09:32:51 1.23 @@ -29,7 +29,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: add.c,v 1.22 2013/12/06 02:31:31 jnemeth Exp $"); +__RCSID("$NetBSD: add.c,v 1.23 2013/12/08 09:32:51 jnemeth Exp $"); #endif #include @@ -46,12 +46,12 @@ __RCSID("$NetBSD: add.c,v 1.22 2013/12/0 #include "gpt.h" static uuid_t type; -static off_t alignment, block, size; +static off_t alignment, block, sectors, size; static unsigned int entry; static uint8_t *name; const char addmsg1[] = "add [-a alignment] [-b blocknr] [-i index] [-l label]"; -const char addmsg2[] = " [-s sectors] [-t type] device ..."; +const char addmsg2[] = " [-s size] [-t type] device ..."; __dead static void usage_add(void) @@ -134,14 +134,14 @@ add(int fd) if (alignment > 0) { alignsecs = alignment / secsz; - map = map_alloc(block, size, alignsecs); + map = map_alloc(block, sectors, alignsecs); if (map == NULL) { warnx("%s: error: not enough space available on " "device for an aligned partition", device_name); return; } } else { - map = map_alloc(block, size, 0); + map = map_alloc(block, sectors, 0); if (map == NULL) { warnx("%s: error: not enough space available on " "device", device_name); @@ -226,11 +226,31 @@ cmd_add(int argc, char *argv[]) name = (uint8_t *)strdup(optarg); break; case 's': - if (size > 0) + if (sectors > 0 || size > 0) usage_add(); - size = strtoll(optarg, &p, 10); - if (*p != 0 || size < 1) + sectors = strtoll(optarg, &p, 10); + if (sectors < 1) usage_add(); + if (*p == '\0') + break; + if (*p == 's' || *p == 'S') { + if (*(p + 1) == '\0') + break; + else + usage_add(); + } + if (*p == 'b' || *p == 'B') { + if (*(p + 1) == '\0') { + size = sectors; + sectors = 0; + break; + } else + usage_add(); + } + if (dehumanize_number(optarg, &human_num) < 0) + usage_add(); + size = human_num; + sectors = 0; break; case 't': if (!uuid_is_nil(&type, NULL)) @@ -260,11 +280,21 @@ cmd_add(int argc, char *argv[]) } if (alignment % secsz != 0) { - warnx("Alignment must be a multiple of sector size; "); + warnx("Alignment must be a multiple of sector size;"); + warnx("the sector size for %s is %d bytes.", + device_name, secsz); + continue; + } + + if (size % secsz != 0) { + warnx("Size in bytes must be a multiple of sector " + "size;"); warnx("the sector size for %s is %d bytes.", device_name, secsz); continue; } + if (size > 0) + sectors = size / secsz; add(fd);