Add options to define labelsector and -offset and number of slices.

Make options to chose alternate label position for systems using MBR
more intuitive. -m now selects mode with MBR, -n selects mode without,
independent of the machine defaults.
This commit is contained in:
mlelstv 2019-07-02 16:23:47 +00:00
parent ebe30d7d2d
commit 1b979fcca7
2 changed files with 78 additions and 23 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: disklabel.8,v 1.68 2017/07/03 21:33:41 wiz Exp $
.\" $NetBSD: disklabel.8,v 1.69 2019/07/02 16:23:47 mlelstv Exp $
.\"
.\" Copyright (c) 1987, 1988, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -41,37 +41,52 @@
.Sh SYNOPSIS
.\" disklabel: read label
.Nm
.Op Fl ACDFmrtv
.Op Fl ACDFmnrtv
.Op Fl B Ar endian
.Op Fl L Ar sector
.Op Fl M Ar machine
.Op Fl O Ar offset
.Op Fl P Ar size
.Ar disk
.\" disklabel -e: read/modify/write using $EDITOR
.Nm
.Fl e
.Op Fl CDFImrv
.Op Fl CDFImnrv
.Op Fl B Ar endian
.Op Fl L Ar sector
.Op Fl M Ar machine
.Op Fl O Ar offset
.Op Fl P Ar size
.Ar disk
.\" disklabel -i: read/modify/write using builtin commands
.Nm
.Fl i
.Op Fl DFImrv
.Op Fl DFImnrv
.Op Fl B Ar endian
.Op Fl L Ar sector
.Op Fl M Ar machine
.Op Fl O Ar offset
.Op Fl P Ar size
.Ar disk
.\" disklabel -R: write from edited output
.Nm
.Fl R
.Op Fl DFmrv
.Op Fl DFmnrv
.Op Fl B Ar endian
.Op Fl L Ar sector
.Op Fl M Ar machine
.Op Fl O Ar offset
.Op Fl P Ar size
.Ar disk Ar protofile
.\" disklabel -w: write from disctab entry
.Nm
.Fl w
.Op Fl DFmrv
.Op Fl DFmnrv
.Op Fl B Ar endian
.Op Fl L Ar sector
.Op Fl M Ar machine
.Op Fl O Ar offset
.Op Fl P Ar size
.Op Fl f Ar disktab
.Ar disk Ar disktype
.Oo Ar packid Oc
@ -189,8 +204,23 @@ Specify the name of a file to use instead of
.It Fl M Ar machine
Specify the machine to generate a label for.
Defaults to the current machine it is compiled for.
Specific details can be overridden via environment
and with the options
.Fl B, L, O, p, m
and
.Fl n.
.It Fl L
num specify the relative sector number of the disklabel
similar to the environment variable DISKLABELSECTOR.
.It Fl O
num specify the relative byte offset of the disklabel.
similar to the environment variable DISKLABELOFFSET.
.It Fl P
num specify the size of the partition table.
.It Fl m
expect the label to have an MBR.
.It Fl n
expect the label not to have an MBR.
.It Fl r
Read/write the disk directly rather than using
.Xr ioctl 2
@ -368,3 +398,12 @@ flag causes
to write directly to disk, and bypass the format translation.
This will result in a disk label that the PROMs will not recognize,
and that therefore cannot be booted from.
.Pp
The
.Fl m
flag previously toggled between using an MBR and not using an MBR,
with the default being implied by the machine type.
It now always enables MBR mode, independent of the machine default.
Use the
.Fl n
flag to disable MBR mode.

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.50 2018/06/27 01:14:48 kamil Exp $ */
/* $NetBSD: main.c,v 1.51 2019/07/02 16:23:47 mlelstv Exp $ */
/*
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -76,7 +76,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 1993\
static char sccsid[] = "@(#)disklabel.c 8.4 (Berkeley) 5/4/95";
/* from static char sccsid[] = "@(#)disklabel.c 1.2 (Symmetric) 11/28/85"; */
#else
__RCSID("$NetBSD: main.c,v 1.50 2018/06/27 01:14:48 kamil Exp $");
__RCSID("$NetBSD: main.c,v 1.51 2019/07/02 16:23:47 mlelstv Exp $");
#endif
#endif /* not lint */
@ -154,7 +154,6 @@ static int tflag; /* Format output as disktab */
static int Dflag; /* Delete old labels (use with write) */
static int Iflag; /* Read/write direct, but default if absent */
static int lflag; /* List all known file system types and exit */
static int mflag; /* Expect disk to contain an MBR */
static int verbose;
static int read_all; /* set if op = READ && Aflag */
@ -481,6 +480,7 @@ main(int argc, char *argv[])
#endif
DELETE
} op = UNSPEC, old_op;
unsigned long val;
#ifndef HAVE_NBTOOL_CONFIG_H
#if !defined(NATIVELABEL_ONLY)
@ -502,22 +502,13 @@ main(int argc, char *argv[])
}
#endif
mflag = labelusesmbr;
if (mflag < 0) {
#if HAVE_NBTOOL_CONFIG_H
warn("getlabelusesmbr() failed");
#else
warn("getlabelusesmbr() failed");
mflag = LABELUSESMBR;
#endif
}
#if HAVE_NBTOOL_CONFIG_H
/* We must avoid doing any ioctl requests */
Fflag = rflag = 1;
#endif
error = 0;
while ((ch = getopt(argc, argv, "AB:CDFIM:NRWef:ilmrtvw")) != -1) {
while ((ch = getopt(argc, argv, "AB:CDFIL:M:NO:P:RWef:ilmnrtvw")) != -1) {
old_op = op;
switch (ch) {
case 'A': /* Action all labels */
@ -559,6 +550,24 @@ main(int argc, char *argv[])
case 'N': /* Disallow writes to label sector */
op = SETREADONLY;
break;
case 'L': /* Label sector */
val = strtoul(optarg, NULL, 10);
if ((val == ULONG_MAX && errno == ERANGE) || val > UINT_MAX)
err(EXIT_FAILURE, "invalid label sector: %s", optarg);
labelsector = val;
break;
case 'O': /* Label offset */
val = strtoul(optarg, NULL, 10);
if ((val == ULONG_MAX && errno == ERANGE) || val > UINT_MAX)
err(EXIT_FAILURE, "invalid label offset: %s", optarg);
labeloffset = val;
break;
case 'P': /* Max partitions */
val = strtoul(optarg, NULL, 10);
if ((val == ULONG_MAX && errno == ERANGE) || val < 1 || val > UINT_MAX)
err(EXIT_FAILURE, "invalid max partitions: %s", optarg);
maxpartitions = val;
break;
case 'W': /* Allow writes to label sector */
op = SETWRITABLE;
break;
@ -578,7 +587,10 @@ main(int argc, char *argv[])
lflag = 1;
break;
case 'm': /* Expect disk to have an MBR */
mflag ^= 1;
labelusesmbr = 1;
break;
case 'n': /* Expect disk to not have an MBR */
labelusesmbr = 0;
break;
case 'r': /* Read/write label directly from disk */
rflag = 1;
@ -600,6 +612,10 @@ main(int argc, char *argv[])
usage();
}
if (maxpartitions > MAXPARTITIONS) {
errx(1, "too large maxpartitions > %u\n", MAXPARTITIONS);
}
#if !defined(NATIVELABEL_ONLY)
if (maxpartitions == 0) {
errx(1, "unknown label: use -M/-B and $MACHINE/$MACHINE_ARCH");
@ -989,7 +1005,7 @@ readlabel_mbr(int f, u_int sector)
static int
writelabel_mbr(int f, u_int sector)
{
return update_label(f, sector, mflag ? LABELOFFSET_MBR : ~0U) ? 2 : 0;
return update_label(f, sector, labelusesmbr ? LABELOFFSET_MBR : ~0U) ? 2 : 0;
}
#endif /* !NO_MBR_SUPPORT */
@ -1369,7 +1385,7 @@ readlabel_direct(int f)
}
}
if (mflag && process_mbr(f, readlabel_mbr) == 0)
if (labelusesmbr && process_mbr(f, readlabel_mbr) == 0)
return 0;
disk_lp = find_label(f, 0);
@ -1378,7 +1394,7 @@ readlabel_direct(int f)
return 0;
}
if (!mflag && process_mbr(f, readlabel_mbr) == 0)
if (!labelusesmbr && process_mbr(f, readlabel_mbr) == 0)
return 0;
return 1;