Subject: Additions to `disklabel -i`
To: NetBSD tech-userlevel mailing list <tech-userlevel@netbsd.org>
From: Julian Coleman <jdc@coris.org.uk>
List: tech-userlevel
Date: 12/29/2003 18:24:48
I noticed that it was a pain to define partitions relative to each other
using `disklabel -i`, so I made a few changes:
added the ability to define a partition as starting after another partition.
if chaining is on, display all changed partitions (not just this one).
if a partition is adjusted so that it falls off the end of the disk, display
a '+' character (aka the '*').
Diffs below. OK to commit this?
J
- - 8< - - - - - - - - - - - - - Cut here - - - - - - - - - - - - - >8 - -
diff -ur /usr/src/sbin/disklabel/interact.c ./interact.c
--- /usr/src/sbin/disklabel/interact.c 2003-10-21 04:06:49.000000000 +0100
+++ ./interact.c 2003-12-29 17:59:14.000000000 +0000
@@ -474,19 +474,35 @@
}
for (;;) {
defnum(lp, def, p->p_offset);
- i = getinput(":", "Start offset", def, line);
+ i = getinput(":",
+ "Start offset ('x' to start after partition 'x)",
+ def, line);
if (i == -1)
return;
else if (i == 0)
break;
- if ((i = getnum(lp, line, 0)) == -1) {
- printf("Bad offset `%s'\n", line);
- continue;
- } else if (i > lp->d_secperunit) {
- printf("Offset `%s' out of range\n", line);
- continue;
+ if (line[1] == '\0' &&
+ line[0] >= 'a' && line[0] < 'a' + getmaxpartitions()) {
+ struct partition *cp = lp->d_partitions;
+
+ if ((cp[line[0] - 'a'].p_offset +
+ cp[line[0] - 'a'].p_size) >= lp->d_secperunit) {
+ printf("Bad offset `%s'\n", line);
+ continue;
+ } else {
+ p->p_offset = cp[line[0] - 'a'].p_offset +
+ cp[line[0] - 'a'].p_size;
+ }
+ } else {
+ if ((i = getnum(lp, line, 0)) == -1) {
+ printf("Bad offset `%s'\n", line);
+ continue;
+ } else if (i > lp->d_secperunit) {
+ printf("Offset `%s' out of range\n", line);
+ continue;
+ }
+ p->p_offset = i;
}
- p->p_offset = i;
break;
}
for (;;) {
@@ -510,19 +526,21 @@
break;
}
+ if (memcmp(&ps, p, sizeof(ps)))
+ showpartition(stdout, lp, part, Cflag);
if (chaining) {
int offs = -1;
struct partition *cp = lp->d_partitions;
for (i = 0; i < lp->d_npartitions; i++) {
if (cp[i].p_fstype != FS_UNUSED) {
- if (offs != -1)
+ if (offs != -1 && cp[i].p_offset != offs) {
cp[i].p_offset = offs;
+ showpartition(stdout, lp, i, Cflag);
+ }
offs = cp[i].p_offset + cp[i].p_size;
}
}
}
- if (memcmp(&ps, p, sizeof(ps)))
- showpartition(stdout, lp, part, Cflag);
}
diff -ur /usr/src/sbin/disklabel/printlabel.c ./printlabel.c
--- /usr/src/sbin/disklabel/printlabel.c 2003-10-21 04:06:49.000000000 +0100
+++ ./printlabel.c 2003-12-29 18:07:32.000000000 +0000
@@ -163,7 +163,9 @@
(void)fprintf(f, " # (Cyl. %6u",
pp->p_offset / lp->d_secpercyl);
- if (pp->p_offset % lp->d_secpercyl)
+ if (pp->p_offset > lp->d_secperunit)
+ putc('+', f);
+ else if (pp->p_offset % lp->d_secpercyl)
putc('*', f);
else
putc(' ', f);
@@ -173,7 +175,9 @@
pp->p_size + lp->d_secpercyl - 1) /
lp->d_secpercyl - 1);
- if ((pp->p_offset + pp->p_size) % lp->d_secpercyl)
+ if ((pp->p_offset + pp->p_size) > lp->d_secperunit)
+ putc('+', f);
+ else if ((pp->p_offset + pp->p_size) % lp->d_secpercyl)
putc('*', f);
(void)fprintf(f, ")\n");
--
My other computer also runs NetBSD / Sailing at Newbiggin
http://www.netbsd.org/ / http://www.newbigginsailingclub.org/