From cfc50733559f8f2384db972c0d95fa4ee19381b9 Mon Sep 17 00:00:00 2001 From: joerg Date: Tue, 4 May 2004 09:50:41 +0000 Subject: 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. --- sbin/sunlabel/sunlabel.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'sbin/sunlabel') 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 #include +#include #include #include #include @@ -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); } -- cgit v1.1