aboutsummaryrefslogtreecommitdiff
path: root/sbin/sunlabel
diff options
context:
space:
mode:
authorJoerg Wunsch <joerg@FreeBSD.org>2004-05-04 09:50:41 +0000
committerJoerg Wunsch <joerg@FreeBSD.org>2004-05-04 09:50:41 +0000
commit53d4cdeb821d78172aaab965cd321a8c7f5019a3 (patch)
tree09c87064d88314bce5f6090f30273d69de8e900f /sbin/sunlabel
parent10aee7e1c4e7cca8494516582c9a2a21a5c2b01e (diff)
downloadsrc-53d4cdeb821d78172aaab965cd321a8c7f5019a3.tar.gz
src-53d4cdeb821d78172aaab965cd321a8c7f5019a3.zip
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.
Notes
Notes: svn path=/head/; revision=128916
Diffstat (limited to 'sbin/sunlabel')
-rw-r--r--sbin/sunlabel/sunlabel.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/sbin/sunlabel/sunlabel.c b/sbin/sunlabel/sunlabel.c
index 0425beeb15ff..b37c70148be2 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);
}