Add an option (-s) to specify which sector to read to parse the partition

table.  Useful if the disk has remapping drivers installed into it (such as
Ontrack Disk Manager).

Added as an option instead of automatic behavior to let the user scan any
of the two partition tables at will.
This commit is contained in:
jmmv 2005-12-27 15:37:56 +00:00
parent 8e96d77b7b
commit fbb8b4076f
2 changed files with 45 additions and 12 deletions

View File

@ -27,9 +27,9 @@
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $NetBSD: mbrlabel.8,v 1.14 2003/07/13 09:56:09 lukem Exp $
.\" $NetBSD: mbrlabel.8,v 1.15 2005/12/27 15:37:56 jmmv Exp $
.\"
.Dd July 13, 2003
.Dd December 27, 2005
.Dt MBRLABEL 8
.Os
.Sh NAME
@ -38,6 +38,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl fqrw
.Op Fl s Ar sector
.Ar device
.Sh DESCRIPTION
.Nm
@ -48,8 +49,10 @@ on disks that were previously used on DOS/Windows systems (or
other MBR using systems).
.Pp
.Nm
scans the MBR contained in the very first block of the disk,
then walks through every extended partition found and generating
scans the MBR contained in the very first block of the disk (or the
block specified through the
.Fl s
flag), then walks through every extended partition found and generating
additional partition entries for the disk from the MBRs found in
those extended partitions.
.Pp
@ -78,7 +81,7 @@ disk label update will occur.
.Pp
Available options:
.Pp
.Bl -tag -width indent
.Bl -tag -width sXsectorX
.It Fl f
Force an update, even if there has been no change.
.It Fl q
@ -89,6 +92,12 @@ Update the in-core label if it has been changed.
In conjunction with
.Fl w ,
also update the on-disk label.
.It Fl s Ar sector
Specifies the logical sector number that has to be read from the disk
in order to find the MBR.
Useful if the disk has remapping drivers on it and the MBR is located
in a non-standard place.
Defaults to 0.
.El
.Sh SEE ALSO
.Xr disklabel 8 ,

View File

@ -1,4 +1,4 @@
/* $NetBSD: mbrlabel.c,v 1.24 2004/01/05 23:23:33 jmmv Exp $ */
/* $NetBSD: mbrlabel.c,v 1.25 2005/12/27 15:37:56 jmmv Exp $ */
/*
* Copyright (C) 1998 Wolfgang Solfrank.
@ -33,11 +33,14 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: mbrlabel.c,v 1.24 2004/01/05 23:23:33 jmmv Exp $");
__RCSID("$NetBSD: mbrlabel.c,v 1.25 2005/12/27 15:37:56 jmmv Exp $");
#endif /* not lint */
#include <stdio.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -128,7 +131,11 @@ getparts(int sd, u_int32_t off, u_int32_t extoff, int verbose)
exit(1);
}
if (read(sd, buf, sizeof buf) != DEV_BSIZE) {
perror("read label");
if (off != MBR_BBSECTOR)
perror("read label (sector is possibly out of "
"range)");
else
perror("read label");
exit(1);
}
if (getshort(buf + MBR_MAGIC_OFFSET) != MBR_MAGIC)
@ -233,7 +240,8 @@ getparts(int sd, u_int32_t off, u_int32_t extoff, int verbose)
void
usage(void)
{
fprintf(stderr, "usage: %s [-fqrw] rawdisk\n", getprogname());
fprintf(stderr, "usage: %s [-fqrw] [-s sector] rawdisk\n",
getprogname());
exit(1);
}
@ -242,17 +250,19 @@ int
main(int argc, char **argv)
{
int sd, ch, changed;
char name[MAXPATHLEN];
char *ep, name[MAXPATHLEN];
int force; /* force label update */
int raw; /* update on-disk label as well */
int verbose; /* verbose output */
int write_it; /* update in-core label if changed */
uint32_t sector; /* sector that contains the MBR */
force = 0;
raw = 0;
verbose = 1;
write_it = 0;
while ((ch = getopt(argc, argv, "fqrw")) != -1) {
sector = MBR_BBSECTOR;
while ((ch = getopt(argc, argv, "fqrs:w")) != -1) {
switch (ch) {
case 'f':
force = 1;
@ -262,6 +272,20 @@ main(int argc, char **argv)
break;
case 'r':
raw = 1;
break;
case 's':
errno = 0;
sector = strtoul(optarg, &ep, 10);
if (optarg[0] == '\0' || *ep != '\0')
errx(EXIT_FAILURE,
"sector number (%s) incorrectly specified",
optarg);
if ((errno == ERANGE && sector == ULONG_MAX) ||
sector > UINT32_MAX)
errx(EXIT_FAILURE,
"sector number (%s) out of range",
optarg);
break;
case 'w':
write_it = 1;
@ -281,7 +305,7 @@ main(int argc, char **argv)
exit(1);
}
getlabel(sd);
changed = getparts(sd, MBR_BBSECTOR, 0, verbose);
changed = getparts(sd, sector, 0, verbose);
if (verbose) {
putchar('\n');