summaryrefslogtreecommitdiffstats
path: root/sbin/bsdlabel
diff options
context:
space:
mode:
authorae <ae@FreeBSD.org>2011-11-06 18:59:42 +0000
committerae <ae@FreeBSD.org>2011-11-06 18:59:42 +0000
commit8cbc1bac70435cc703634a1f7aee6be4d7a97569 (patch)
treeed0cdbf808e43c8404cd1eb85ba3914ac89ac9fa /sbin/bsdlabel
parent50646b91e6b93cdf92d7cc88ad522c70232fa6dc (diff)
downloadFreeBSD-src-8cbc1bac70435cc703634a1f7aee6be4d7a97569.zip
FreeBSD-src-8cbc1bac70435cc703634a1f7aee6be4d7a97569.tar.gz
bsdlabel(8) could automatically fill many of disklabel's deprecated
fields, but user could specify some of those fields when edits disklabel with `bsdlabel -e`. But without -A flag these fields might be overwritten with default values from the virgin disklabel. So, don't overwrite such fields if they are not zero. Also add checks to prevent creating disklabel with less than DEFPARTITIONS and more than MAXPARTITIONS partitions. PR: bin/162332 Tested by: Eugene Grosbein MFC after: 1 week
Diffstat (limited to 'sbin/bsdlabel')
-rw-r--r--sbin/bsdlabel/bsdlabel.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/sbin/bsdlabel/bsdlabel.c b/sbin/bsdlabel/bsdlabel.c
index 83d5a4c..4f5a2c6 100644
--- a/sbin/bsdlabel/bsdlabel.c
+++ b/sbin/bsdlabel/bsdlabel.c
@@ -836,6 +836,11 @@ getasciilabel(FILE *f, struct disklabel *lp)
"line %d: bad # of partitions\n", lineno);
lp->d_npartitions = MAXPARTITIONS;
errors++;
+ } else if (v < DEFPARTITIONS) {
+ fprintf(stderr,
+ "line %d: bad # of partitions\n", lineno);
+ lp->d_npartitions = DEFPARTITIONS;
+ errors++;
} else
lp->d_npartitions = v;
continue;
@@ -1149,23 +1154,42 @@ checklabel(struct disklabel *lp)
errors++;
} else if (lp->d_bbsize % lp->d_secsize)
warnx("boot block size %% sector-size != 0");
- if (lp->d_npartitions > MAXPARTITIONS)
+ if (lp->d_npartitions > MAXPARTITIONS) {
warnx("number of partitions (%lu) > MAXPARTITIONS (%d)",
(u_long)lp->d_npartitions, MAXPARTITIONS);
+ errors++;
+ }
+ if (lp->d_npartitions < DEFPARTITIONS) {
+ warnx("number of partitions (%lu) < DEFPARTITIONS (%d)",
+ (u_long)lp->d_npartitions, DEFPARTITIONS);
+ errors++;
+ }
} else {
struct disklabel *vl;
vl = getvirginlabel();
- lp->d_secsize = vl->d_secsize;
- lp->d_nsectors = vl->d_nsectors;
- lp->d_ntracks = vl->d_ntracks;
- lp->d_ncylinders = vl->d_ncylinders;
- lp->d_rpm = vl->d_rpm;
- lp->d_interleave = vl->d_interleave;
- lp->d_secpercyl = vl->d_secpercyl;
- lp->d_secperunit = vl->d_secperunit;
- lp->d_bbsize = vl->d_bbsize;
- lp->d_npartitions = vl->d_npartitions;
+ if (lp->d_secsize == 0)
+ lp->d_secsize = vl->d_secsize;
+ if (lp->d_nsectors == 0)
+ lp->d_nsectors = vl->d_nsectors;
+ if (lp->d_ntracks == 0)
+ lp->d_ntracks = vl->d_ntracks;
+ if (lp->d_ncylinders == 0)
+ lp->d_ncylinders = vl->d_ncylinders;
+ if (lp->d_rpm == 0)
+ lp->d_rpm = vl->d_rpm;
+ if (lp->d_interleave == 0)
+ lp->d_interleave = vl->d_interleave;
+ if (lp->d_secpercyl == 0)
+ lp->d_secpercyl = vl->d_secpercyl;
+ if (lp->d_secperunit == 0)
+ lp->d_secperunit = vl->d_secperunit;
+ if (lp->d_bbsize == 0)
+ lp->d_bbsize = vl->d_bbsize;
+ if (lp->d_npartitions == 0 ||
+ lp->d_npartitions < DEFPARTITIONS ||
+ lp->d_npartitions > MAXPARTITIONS)
+ lp->d_npartitions = vl->d_npartitions;
}
OpenPOWER on IntegriCloud