diff options
author | joerg <joerg@FreeBSD.org> | 2004-05-04 09:50:41 +0000 |
---|---|---|
committer | joerg <joerg@FreeBSD.org> | 2004-05-04 09:50:41 +0000 |
commit | cfc50733559f8f2384db972c0d95fa4ee19381b9 (patch) | |
tree | 09c87064d88314bce5f6090f30273d69de8e900f /sbin/sunlabel | |
parent | c1696e146d40d8e4f3f1ef8901a4d74035ed1fab (diff) | |
download | FreeBSD-src-cfc50733559f8f2384db972c0d95fa4ee19381b9.zip FreeBSD-src-cfc50733559f8f2384db972c0d95fa4ee19381b9.tar.gz |
When editing a Sun label, make the search for a valid partition line
violate POLA a little less by not requiring exactly two spaces in front
of the entry (and silently discarding any non-matching entry). We now
recognize anything starting with a letter followed by a colon as the
first non-space chars as a partition entry.
Diffstat (limited to 'sbin/sunlabel')
-rw-r--r-- | sbin/sunlabel/sunlabel.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/sbin/sunlabel/sunlabel.c b/sbin/sunlabel/sunlabel.c index 0425bee..b37c701 100644 --- a/sbin/sunlabel/sunlabel.c +++ b/sbin/sunlabel/sunlabel.c @@ -75,6 +75,7 @@ __FBSDID("$FreeBSD$"); #include <sys/sun_disklabel.h> #include <sys/wait.h> +#include <ctype.h> #include <err.h> #include <fcntl.h> #include <inttypes.h> @@ -459,6 +460,7 @@ parse_label(struct sun_disklabel *sl, const char *file) char offset[32]; char size[32]; char buf[128]; + char *bp; uint8_t part; FILE *fp; int line; @@ -468,13 +470,28 @@ parse_label(struct sun_disklabel *sl, const char *file) err(1, "fopen"); bzero(sl->sl_part, sizeof(sl->sl_part)); while (fgets(buf, sizeof(buf), fp) != NULL) { - if (buf[0] != ' ' || buf[1] != ' ') + /* + * In order to recognize a partition entry, we search + * for lines starting with a single letter followed by + * a colon as their first non-white characters. We + * silently ignore any other lines, so any comment etc. + * lines in the label template will be ignored. + * + * XXX We should probably also recognize the geometry + * fields on top, and allow changing the geometry + * emulated by this disk. + */ + for (bp = buf; isspace(*bp); bp++) + ; + if (strlen(bp) < 2 || bp[1] != ':') { + line++; continue; - if (sscanf(buf, " %c: %s %s\n", &part, size, offset) != 3 || + } + if (sscanf(bp, "%c: %s %s\n", &part, size, offset) != 3 || parse_size(sl, part - 'a', size) || parse_offset(sl, part - 'a', offset)) { - warnx("%s: syntex error on line %d", - file, line); + warnx("%s: syntax error on line %d", + file, line + 1); fclose(fp); return (1); } |