diff --git a/sbin/bsdlabel/bsdlabel.c b/sbin/bsdlabel/bsdlabel.c index 31e57b7c9146..56b5176dc33c 100644 --- a/sbin/bsdlabel/bsdlabel.c +++ b/sbin/bsdlabel/bsdlabel.c @@ -125,7 +125,8 @@ static int allfields; /* present all fields in edit */ static char const *xxboot; /* primary boot */ static off_t mbroffset; -static int labeloffset = LABELOFFSET + LABELSECTOR * DEV_BSIZE; +static int labelsoffset = LABELSECTOR; +static int labeloffset = LABELOFFSET; static int bbsize = BBSIZE; static int alphacksum = #if defined(__alpha__) @@ -161,14 +162,17 @@ main(int argc, char *argv[]) break; case 'm': if (!strcmp(optarg, "i386")) { - labeloffset = 512; + labelsoffset = 1; + labeloffset = 0; bbsize = 8192; alphacksum = 0; } else if (!strcmp(optarg, "pc98")) { - labeloffset = 512; + labelsoffset = 1; + labeloffset = 0; bbsize = 8192; alphacksum = 0; } else if (!strcmp(optarg, "alpha")) { + labelsoffset = 0; labeloffset = 64; bbsize = 8192; alphacksum = 1; @@ -349,7 +353,8 @@ writelabel(void) for (i = 0; i < lab.d_npartitions; i++) if (lab.d_partitions[i].p_size) lab.d_partitions[i].p_offset += mbroffset; - bsd_disklabel_le_enc(bootarea + labeloffset, lp); + bsd_disklabel_le_enc(bootarea + labeloffset + labelsoffset * secsize, + lp); if (alphacksum) { /* Generate the bootblock checksum for the SRM console. */ for (p = (uint64_t *)bootarea, i = 0, sum = 0; i < 63; i++) @@ -363,7 +368,8 @@ writelabel(void) gctl_ro_param(grq, "verb", -1, "write label"); gctl_ro_param(grq, "class", -1, "BSD"); gctl_ro_param(grq, "geom", -1, dkname); - gctl_ro_param(grq, "label", 148+16*8, bootarea + labeloffset); + gctl_ro_param(grq, "label", 148+16*8, + bootarea + labeloffset + labelsoffset * secsize); errstr = gctl_issue(grq); if (errstr != NULL) { warnx("%s", errstr); @@ -411,11 +417,18 @@ readlabel(int flag) f = open(specname, O_RDONLY); if (f < 0) err(1, specname); + /* New world order */ + if ((ioctl(f, DIOCGMEDIASIZE, &mediasize) != 0) || + (ioctl(f, DIOCGSECTORSIZE, &secsize) != 0)) { + err(4, "cannot get disk geometry"); + } (void)lseek(f, (off_t)0, SEEK_SET); if (read(f, bootarea, BBSIZE) != BBSIZE) err(4, "%s read", specname); close (f); - error = bsd_disklabel_le_dec(bootarea + labeloffset, &lab, MAXPARTITIONS); + error = bsd_disklabel_le_dec( + bootarea + (labeloffset + labelsoffset * secsize), + &lab, MAXPARTITIONS); if (flag && error) errx(1, "%s: no valid label found", specname); diff --git a/sbin/bsdlabel/runtest.sh b/sbin/bsdlabel/runtest.sh index e7f3e966b7a2..eb43b90b237a 100644 --- a/sbin/bsdlabel/runtest.sh +++ b/sbin/bsdlabel/runtest.sh @@ -3,15 +3,18 @@ TMP=/tmp/$$. set -e -for ARCH in i386 alpha pc98 +for TEST in "i386 512" "i386 4096" "alpha 512" "pc98 512" "pc98 4096" do - echo "ARCH $ARCH" - MD=`mdconfig -a -t malloc -s 2m` + set $TEST + ARCH=$1 + SEC=$2 + echo "ARCH $ARCH SEC $SEC" + MD=`mdconfig -a -t malloc -s 2m -S $SEC` trap "exec 7 /dev/null 2>&1 + dd if=/dev/$MD of=${TMP}i0 count=1 bs=8k > /dev/null 2>&1 if [ "$ARCH" = "alpha" ] ; then dd if=${TMP}i0 of=${TMP}b0 iseek=1 count=15 > /dev/null 2>&1 else @@ -24,6 +27,7 @@ do p s/c:/a:/ s/4096/1024/ + s/512/64/ } ' ${TMP}l0 > ${TMP}l1 @@ -45,30 +49,31 @@ do exit 2 fi - dd if=/dev/$MD of=${TMP}i1 count=16 > /dev/null 2>&1 + dd if=/dev/$MD of=${TMP}i1 count=1 bs=8k > /dev/null 2>&1 sed ' / c:/{ p s/c:/a:/ s/4096/2048/ + s/512/256/ } ' ${TMP}l0 > ${TMP}l2 ./bsdlabel -m ${ARCH} -R $MD ${TMP}l2 - dd if=/dev/$MD of=${TMP}i2 count=16 > /dev/null 2>&1 + dd if=/dev/$MD of=${TMP}i2 count=1 bs=8k > /dev/null 2>&1 exec 7< /dev/${MD}a for t in a c do - if dd if=${TMP}i2 of=/dev/${MD}$t 2>/dev/null ; then + if dd if=${TMP}i2 of=/dev/${MD}$t bs=8k 2>/dev/null ; then echo "PASS: Could rewrite same label to ...$t while ...a open" 1>&2 else echo "FAIL: Could not rewrite same label to ...$t while ...a open" 1>&2 exit 2 fi - if dd if=${TMP}i1 of=/dev/${MD}$t 2>/dev/null ; then + if dd if=${TMP}i1 of=/dev/${MD}$t bs=8k 2>/dev/null ; then echo "FAIL: Could label with smaller ...a to ...$t while ...a open" 1>&2 exit 2 else @@ -85,42 +90,42 @@ do exec 7< /dev/null - if dd if=${TMP}i0 of=/dev/${MD}c 2>/dev/null ; then + if dd if=${TMP}i0 of=/dev/${MD}c bs=8k 2>/dev/null ; then echo "PASS: Could write missing ...a label to ...c" 1>&2 else echo "FAIL: Could not write missing ...a label to ...c" 1>&2 exit 2 fi - if dd if=${TMP}i2 of=/dev/${MD}c 2>/dev/null ; then + if dd if=${TMP}i2 of=/dev/${MD}c bs=8k 2>/dev/null ; then echo "PASS: Could write large ...a label to ...c" 1>&2 else echo "FAIL: Could not write large ...a label to ...c" 1>&2 exit 2 fi - if dd if=${TMP}i1 of=/dev/${MD}c 2>/dev/null ; then + if dd if=${TMP}i1 of=/dev/${MD}c bs=8k 2>/dev/null ; then echo "PASS: Could write small ...a label to ...c" 1>&2 else echo "FAIL: Could not write small ...a label to ...c" 1>&2 exit 2 fi - if dd if=${TMP}i2 of=/dev/${MD}a 2>/dev/null ; then + if dd if=${TMP}i2 of=/dev/${MD}a bs=8k 2>/dev/null ; then echo "PASS: Could increase size of ...a by writing to ...a" 1>&2 else echo "FAIL: Could not increase size of ...a by writing to ...a" 1>&2 exit 2 fi - if dd if=${TMP}i1 of=/dev/${MD}a 2>/dev/null ; then + if dd if=${TMP}i1 of=/dev/${MD}a bs=8k 2>/dev/null ; then echo "FAIL: Could decrease size of ...a by writing to ...a" 1>&2 exit 2 else echo "PASS: Could not decrease size of ...a by writing to ...a" 1>&2 fi - if dd if=${TMP}i0 of=/dev/${MD}a 2>/dev/null ; then + if dd if=${TMP}i0 of=/dev/${MD}a bs=8k 2>/dev/null ; then echo "FAIL: Could delete ...a by writing to ...a" 1>&2 exit 2 else @@ -153,7 +158,7 @@ do fi exec 7> /dev/null - if dd if=${TMP}i0 of=/dev/${MD}c 2>/dev/null ; then + if dd if=${TMP}i0 of=/dev/${MD}c bs=8k 2>/dev/null ; then echo "PASS: Could delete ...a by writing to ...c" 1>&2 else echo "FAIL: Could not delete ...a by writing to ...c" 1>&2