Fixed bugs in `disklabel -R...':

- nonstandard sector sizes didn't work because the sector size in the
  ASCII label was not read before a (default, wrong) sector size was used.
- the exit status was 0 after exiting early due to an invalid ASCII label.

Abort `disklabel -B...' if the secondary bootstrap doesn't fit.
This commit is contained in:
Bruce Evans 1998-07-25 16:19:10 +00:00
parent ca2be56ff9
commit 6cabb34884
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=37865
2 changed files with 42 additions and 16 deletions

View File

@ -46,7 +46,7 @@ static char sccsid[] = "@(#)disklabel.c 8.2 (Berkeley) 1/7/94";
/* from static char sccsid[] = "@(#)disklabel.c 1.2 (Symmetric) 11/28/85"; */ /* from static char sccsid[] = "@(#)disklabel.c 1.2 (Symmetric) 11/28/85"; */
#endif #endif
static const char rcsid[] = static const char rcsid[] =
"$Id: disklabel.c,v 1.15 1998/06/28 18:59:04 bde Exp $"; "$Id: disklabel.c,v 1.16 1998/07/20 11:34:06 bde Exp $";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -274,15 +274,25 @@ main(argc, argv)
if (installboot && argc == 3) { if (installboot && argc == 3) {
makelabel(argv[2], 0, &lab); makelabel(argv[2], 0, &lab);
argc--; argc--;
/*
* We only called makelabel() for its side effect
* of setting the bootstrap file names. Discard
* all changes to `lab' so that all values in the
* final label come from the ASCII label.
*/
bzero((char *)&lab, sizeof(lab));
} }
#endif #endif
if (argc != 2) if (argc != 2)
usage(); usage();
lp = makebootarea(bootarea, &lab, f);
if (!(t = fopen(argv[1], "r"))) if (!(t = fopen(argv[1], "r")))
err(4, "%s", argv[1]); err(4, "%s", argv[1]);
if (getasciilabel(t, lp)) if (!getasciilabel(t, &lab))
error = writelabel(f, bootarea, lp); exit(1);
lp = makebootarea(bootarea, &lab, f);
*lp = lab;
error = writelabel(f, bootarea, lp);
break; break;
case WRITE: case WRITE:
@ -529,9 +539,7 @@ makebootarea(boot, dp, f)
int b; int b;
#if NUMBOOT > 0 #if NUMBOOT > 0
char *dkbasename; char *dkbasename;
#if NUMBOOT == 1
struct stat sb; struct stat sb;
#endif
#ifdef __i386__ #ifdef __i386__
char *tmpbuf; char *tmpbuf;
int i, found; int i, found;
@ -646,13 +654,18 @@ makebootarea(boot, dp, f)
b = open(bootxx, O_RDONLY); b = open(bootxx, O_RDONLY);
if (b < 0) if (b < 0)
err(4, "%s", bootxx); err(4, "%s", bootxx);
if (fstat(b, &sb) != 0)
err(4, "%s", bootxx);
if (dp->d_secsize + sb.st_size > dp->d_bbsize)
errx(4, "%s too large", bootxx);
if (read(b, &boot[dp->d_secsize], if (read(b, &boot[dp->d_secsize],
(int)(dp->d_bbsize-dp->d_secsize)) < 0) (int)(dp->d_bbsize-dp->d_secsize)) < 0)
err(4, "%s", bootxx); err(4, "%s", bootxx);
#else #else
if (read(b, boot, (int)dp->d_bbsize) < 0) if (read(b, boot, (int)dp->d_bbsize) < 0)
err(4, "%s", xxboot); err(4, "%s", xxboot);
(void)fstat(b, &sb); if (fstat(b, &sb) != 0)
err(4, "%s", xxboot);
bootsize = (int)sb.st_size - dp->d_bbsize; bootsize = (int)sb.st_size - dp->d_bbsize;
if (bootsize > 0) { if (bootsize > 0) {
/* XXX assume d_secsize is a power of two */ /* XXX assume d_secsize is a power of two */
@ -991,7 +1004,7 @@ getasciilabel(f, lp)
} }
if (streq(cp, "bytes/sector")) { if (streq(cp, "bytes/sector")) {
v = atoi(tp); v = atoi(tp);
if (v <= 0 || (v % 512) != 0) { if (v <= 0 || (v % DEV_BSIZE) != 0) {
fprintf(stderr, fprintf(stderr,
"line %d: %s: bad sector size\n", "line %d: %s: bad sector size\n",
lineno, tp); lineno, tp);

View File

@ -46,7 +46,7 @@ static char sccsid[] = "@(#)disklabel.c 8.2 (Berkeley) 1/7/94";
/* from static char sccsid[] = "@(#)disklabel.c 1.2 (Symmetric) 11/28/85"; */ /* from static char sccsid[] = "@(#)disklabel.c 1.2 (Symmetric) 11/28/85"; */
#endif #endif
static const char rcsid[] = static const char rcsid[] =
"$Id: disklabel.c,v 1.15 1998/06/28 18:59:04 bde Exp $"; "$Id: disklabel.c,v 1.16 1998/07/20 11:34:06 bde Exp $";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -274,15 +274,25 @@ main(argc, argv)
if (installboot && argc == 3) { if (installboot && argc == 3) {
makelabel(argv[2], 0, &lab); makelabel(argv[2], 0, &lab);
argc--; argc--;
/*
* We only called makelabel() for its side effect
* of setting the bootstrap file names. Discard
* all changes to `lab' so that all values in the
* final label come from the ASCII label.
*/
bzero((char *)&lab, sizeof(lab));
} }
#endif #endif
if (argc != 2) if (argc != 2)
usage(); usage();
lp = makebootarea(bootarea, &lab, f);
if (!(t = fopen(argv[1], "r"))) if (!(t = fopen(argv[1], "r")))
err(4, "%s", argv[1]); err(4, "%s", argv[1]);
if (getasciilabel(t, lp)) if (!getasciilabel(t, &lab))
error = writelabel(f, bootarea, lp); exit(1);
lp = makebootarea(bootarea, &lab, f);
*lp = lab;
error = writelabel(f, bootarea, lp);
break; break;
case WRITE: case WRITE:
@ -529,9 +539,7 @@ makebootarea(boot, dp, f)
int b; int b;
#if NUMBOOT > 0 #if NUMBOOT > 0
char *dkbasename; char *dkbasename;
#if NUMBOOT == 1
struct stat sb; struct stat sb;
#endif
#ifdef __i386__ #ifdef __i386__
char *tmpbuf; char *tmpbuf;
int i, found; int i, found;
@ -646,13 +654,18 @@ makebootarea(boot, dp, f)
b = open(bootxx, O_RDONLY); b = open(bootxx, O_RDONLY);
if (b < 0) if (b < 0)
err(4, "%s", bootxx); err(4, "%s", bootxx);
if (fstat(b, &sb) != 0)
err(4, "%s", bootxx);
if (dp->d_secsize + sb.st_size > dp->d_bbsize)
errx(4, "%s too large", bootxx);
if (read(b, &boot[dp->d_secsize], if (read(b, &boot[dp->d_secsize],
(int)(dp->d_bbsize-dp->d_secsize)) < 0) (int)(dp->d_bbsize-dp->d_secsize)) < 0)
err(4, "%s", bootxx); err(4, "%s", bootxx);
#else #else
if (read(b, boot, (int)dp->d_bbsize) < 0) if (read(b, boot, (int)dp->d_bbsize) < 0)
err(4, "%s", xxboot); err(4, "%s", xxboot);
(void)fstat(b, &sb); if (fstat(b, &sb) != 0)
err(4, "%s", xxboot);
bootsize = (int)sb.st_size - dp->d_bbsize; bootsize = (int)sb.st_size - dp->d_bbsize;
if (bootsize > 0) { if (bootsize > 0) {
/* XXX assume d_secsize is a power of two */ /* XXX assume d_secsize is a power of two */
@ -991,7 +1004,7 @@ getasciilabel(f, lp)
} }
if (streq(cp, "bytes/sector")) { if (streq(cp, "bytes/sector")) {
v = atoi(tp); v = atoi(tp);
if (v <= 0 || (v % 512) != 0) { if (v <= 0 || (v % DEV_BSIZE) != 0) {
fprintf(stderr, fprintf(stderr,
"line %d: %s: bad sector size\n", "line %d: %s: bad sector size\n",
lineno, tp); lineno, tp);