Fix sectorsize != 512 on i386 and pc98. Add test cases for same.

This commit is contained in:
Poul-Henning Kamp 2003-06-02 14:19:31 +00:00
parent f937c268cf
commit b2bb9f9bfd
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=115696
2 changed files with 39 additions and 21 deletions

View File

@ -125,7 +125,8 @@ static int allfields; /* present all fields in edit */
static char const *xxboot; /* primary boot */ static char const *xxboot; /* primary boot */
static off_t mbroffset; 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 bbsize = BBSIZE;
static int alphacksum = static int alphacksum =
#if defined(__alpha__) #if defined(__alpha__)
@ -161,14 +162,17 @@ main(int argc, char *argv[])
break; break;
case 'm': case 'm':
if (!strcmp(optarg, "i386")) { if (!strcmp(optarg, "i386")) {
labeloffset = 512; labelsoffset = 1;
labeloffset = 0;
bbsize = 8192; bbsize = 8192;
alphacksum = 0; alphacksum = 0;
} else if (!strcmp(optarg, "pc98")) { } else if (!strcmp(optarg, "pc98")) {
labeloffset = 512; labelsoffset = 1;
labeloffset = 0;
bbsize = 8192; bbsize = 8192;
alphacksum = 0; alphacksum = 0;
} else if (!strcmp(optarg, "alpha")) { } else if (!strcmp(optarg, "alpha")) {
labelsoffset = 0;
labeloffset = 64; labeloffset = 64;
bbsize = 8192; bbsize = 8192;
alphacksum = 1; alphacksum = 1;
@ -349,7 +353,8 @@ writelabel(void)
for (i = 0; i < lab.d_npartitions; i++) for (i = 0; i < lab.d_npartitions; i++)
if (lab.d_partitions[i].p_size) if (lab.d_partitions[i].p_size)
lab.d_partitions[i].p_offset += mbroffset; 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) { if (alphacksum) {
/* Generate the bootblock checksum for the SRM console. */ /* Generate the bootblock checksum for the SRM console. */
for (p = (uint64_t *)bootarea, i = 0, sum = 0; i < 63; i++) 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, "verb", -1, "write label");
gctl_ro_param(grq, "class", -1, "BSD"); gctl_ro_param(grq, "class", -1, "BSD");
gctl_ro_param(grq, "geom", -1, dkname); 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); errstr = gctl_issue(grq);
if (errstr != NULL) { if (errstr != NULL) {
warnx("%s", errstr); warnx("%s", errstr);
@ -411,11 +417,18 @@ readlabel(int flag)
f = open(specname, O_RDONLY); f = open(specname, O_RDONLY);
if (f < 0) if (f < 0)
err(1, specname); 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); (void)lseek(f, (off_t)0, SEEK_SET);
if (read(f, bootarea, BBSIZE) != BBSIZE) if (read(f, bootarea, BBSIZE) != BBSIZE)
err(4, "%s read", specname); err(4, "%s read", specname);
close (f); 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) if (flag && error)
errx(1, "%s: no valid label found", specname); errx(1, "%s: no valid label found", specname);

View File

@ -3,15 +3,18 @@
TMP=/tmp/$$. TMP=/tmp/$$.
set -e set -e
for ARCH in i386 alpha pc98 for TEST in "i386 512" "i386 4096" "alpha 512" "pc98 512" "pc98 4096"
do do
echo "ARCH $ARCH" set $TEST
MD=`mdconfig -a -t malloc -s 2m` ARCH=$1
SEC=$2
echo "ARCH $ARCH SEC $SEC"
MD=`mdconfig -a -t malloc -s 2m -S $SEC`
trap "exec 7</dev/null; rm -f ${TMP}* ; mdconfig -d -u ${MD}" EXIT INT TERM trap "exec 7</dev/null; rm -f ${TMP}* ; mdconfig -d -u ${MD}" EXIT INT TERM
./bsdlabel -m ${ARCH} -r -w $MD auto ./bsdlabel -m ${ARCH} -r -w $MD auto
dd if=/dev/$MD of=${TMP}i0 count=16 > /dev/null 2>&1 dd if=/dev/$MD of=${TMP}i0 count=1 bs=8k > /dev/null 2>&1
if [ "$ARCH" = "alpha" ] ; then if [ "$ARCH" = "alpha" ] ; then
dd if=${TMP}i0 of=${TMP}b0 iseek=1 count=15 > /dev/null 2>&1 dd if=${TMP}i0 of=${TMP}b0 iseek=1 count=15 > /dev/null 2>&1
else else
@ -24,6 +27,7 @@ do
p p
s/c:/a:/ s/c:/a:/
s/4096/1024/ s/4096/1024/
s/512/64/
} }
' ${TMP}l0 > ${TMP}l1 ' ${TMP}l0 > ${TMP}l1
@ -45,30 +49,31 @@ do
exit 2 exit 2
fi 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 ' sed '
/ c:/{ / c:/{
p p
s/c:/a:/ s/c:/a:/
s/4096/2048/ s/4096/2048/
s/512/256/
} }
' ${TMP}l0 > ${TMP}l2 ' ${TMP}l0 > ${TMP}l2
./bsdlabel -m ${ARCH} -R $MD ${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 exec 7< /dev/${MD}a
for t in a c for t in a c
do 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 echo "PASS: Could rewrite same label to ...$t while ...a open" 1>&2
else else
echo "FAIL: Could not rewrite same label to ...$t while ...a open" 1>&2 echo "FAIL: Could not rewrite same label to ...$t while ...a open" 1>&2
exit 2 exit 2
fi 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 echo "FAIL: Could label with smaller ...a to ...$t while ...a open" 1>&2
exit 2 exit 2
else else
@ -85,42 +90,42 @@ do
exec 7< /dev/null 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 echo "PASS: Could write missing ...a label to ...c" 1>&2
else else
echo "FAIL: Could not write missing ...a label to ...c" 1>&2 echo "FAIL: Could not write missing ...a label to ...c" 1>&2
exit 2 exit 2
fi 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 echo "PASS: Could write large ...a label to ...c" 1>&2
else else
echo "FAIL: Could not write large ...a label to ...c" 1>&2 echo "FAIL: Could not write large ...a label to ...c" 1>&2
exit 2 exit 2
fi 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 echo "PASS: Could write small ...a label to ...c" 1>&2
else else
echo "FAIL: Could not write small ...a label to ...c" 1>&2 echo "FAIL: Could not write small ...a label to ...c" 1>&2
exit 2 exit 2
fi 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 echo "PASS: Could increase size of ...a by writing to ...a" 1>&2
else else
echo "FAIL: Could not increase size of ...a by writing to ...a" 1>&2 echo "FAIL: Could not increase size of ...a by writing to ...a" 1>&2
exit 2 exit 2
fi 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 echo "FAIL: Could decrease size of ...a by writing to ...a" 1>&2
exit 2 exit 2
else else
echo "PASS: Could not decrease size of ...a by writing to ...a" 1>&2 echo "PASS: Could not decrease size of ...a by writing to ...a" 1>&2
fi 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 echo "FAIL: Could delete ...a by writing to ...a" 1>&2
exit 2 exit 2
else else
@ -153,7 +158,7 @@ do
fi fi
exec 7> /dev/null 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 echo "PASS: Could delete ...a by writing to ...c" 1>&2
else else
echo "FAIL: Could not delete ...a by writing to ...c" 1>&2 echo "FAIL: Could not delete ...a by writing to ...c" 1>&2