CVS commit: src/sbin/mbrlabel
Module Name:src Committed By: mlelstv Date: Fri Mar 30 13:14:25 UTC 2018 Modified Files: src/sbin/mbrlabel: mbrlabel.c Log Message: Handle sector sizes != 512, check partition overlaps, improve guessing of filesystem parameters. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/sbin/mbrlabel/mbrlabel.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/mbrlabel/mbrlabel.c diff -u src/sbin/mbrlabel/mbrlabel.c:1.28 src/sbin/mbrlabel/mbrlabel.c:1.29 --- src/sbin/mbrlabel/mbrlabel.c:1.28 Sat Jul 14 20:14:17 2012 +++ src/sbin/mbrlabel/mbrlabel.c Fri Mar 30 13:14:25 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: mbrlabel.c,v 1.28 2012/07/14 20:14:17 wiz Exp $ */ +/* $NetBSD: mbrlabel.c,v 1.29 2018/03/30 13:14:25 mlelstv Exp $ */ /* * Copyright (C) 1998 Wolfgang Solfrank. @@ -33,7 +33,7 @@ #include #ifndef lint -__RCSID("$NetBSD: mbrlabel.c,v 1.28 2012/07/14 20:14:17 wiz Exp $"); +__RCSID("$NetBSD: mbrlabel.c,v 1.29 2018/03/30 13:14:25 mlelstv Exp $"); #endif /* not lint */ #include @@ -116,20 +116,32 @@ getlong(void *p) static int getparts(int sd, u_int32_t off, u_int32_t extoff, int verbose) { - unsigned char buf[DEV_BSIZE]; + unsigned char *buf; struct mbr_partition parts[MBR_PART_COUNT]; struct partition npe; off_t loff; int i, j, unused, changed; + unsigned bsize = label.d_secsize; + + if (bsize < DEV_BSIZE) { + fprintf(stderr,"Invalid sector size %u\n", bsize); + exit(1); + } + + buf = malloc(bsize); + if (buf == NULL) { + perror("malloc I/O buffer"); + exit(1); + } changed = 0; - loff = (off_t)off * DEV_BSIZE; + loff = (off_t)off * bsize; if (lseek(sd, loff, SEEK_SET) != loff) { perror("seek label"); exit(1); } - if (read(sd, buf, sizeof buf) != DEV_BSIZE) { + if (read(sd, buf, bsize) != (ssize_t)bsize) { if (off != MBR_BBSECTOR) perror("read label (sector is possibly out of " "range)"); @@ -160,31 +172,50 @@ getparts(int sd, u_int32_t off, u_int32_ "Found %s partition; size %u (%u MB), offset %u\n", fstypenames[npe.p_fstype], npe.p_size, npe.p_size / 2048, npe.p_offset); + for (j = 0; j < label.d_npartitions; j++) { struct partition *lpe; if (j == RAW_PART) continue; lpe = _partitions[j]; + if (lpe->p_size == npe.p_size && - lpe->p_offset == npe.p_offset -#ifdef notyet - && (lpe->p_fstype == npe.p_fstype || - lpe->p_fstype == FS_UNUSED) */ -#endif - ) { + lpe->p_offset == npe.p_offset) { if (verbose) printf( - " skipping existing %s partition at slot %c.\n", + " skipping existing %s partition at slot %c.\n", fstypenames[lpe->p_fstype], j + 'a'); unused = -2; /* flag as existing */ break; } + if (unused == -1 && lpe->p_size == 0 && lpe->p_fstype == FS_UNUSED) unused = j; } + if (unused == -1) { + for (j = 0; j < label.d_npartitions; j++) { +struct partition *lpe; + +if (j == RAW_PART) + continue; +lpe = _partitions[j]; + +if ((npe.p_offset >= lpe->p_offset && +npe.p_offset < lpe->p_offset + lpe->p_size) || + (npe.p_offset + npe.p_size - 1 >= lpe->p_offset && +npe.p_offset + npe.p_size - 1 < lpe->p_offset + lpe->p_size)) { + printf( + " skipping overlapping %s partition at slot %c.\n", + fstypenames[lpe->p_fstype], + j + 'a'); + unused = -2; /* flag as existing */ + break; +} + } + } if (unused == -2) continue; /* entry exists, skip... */ if (unused == -1) { @@ -202,23 +233,25 @@ getparts(int sd, u_int32_t off, u_int32_ if (verbose) printf(" adding %s partition to slot %c.\n", fstypenames[npe.p_fstype], unused + 'a'); + + /* + * XXX guess some filesystem parameters, these should be + * scanned from the superblocks + */ switch (npe.p_fstype) { case FS_BSDFFS: case FS_APPLEUFS: - npe.p_size = 16384; /* XXX */ npe.p_fsize = 1024; npe.p_frag = 8; npe.p_cpg = 16; break; -#ifdef __does_not_happen__ case FS_BSDLFS: - npe.p_size = 16384; /* XXX */ npe.p_fsize = 1024; npe.p_frag = 8; - npe.p_sgs = XXX; + npe.p_sgs = 7; break; -#endif } + changed++; label.d_partitions[unused] = npe; } @@ -233,6 +266,8 @@ getparts(int sd, u_int32_t off, u_int32_ extoff ? extoff : poff, verbose); } } + + free(buf); return (changed); }
CVS commit: src/sbin/mbrlabel
Module Name:src Committed By: is Date: Wed Feb 27 20:43:00 UTC 2013 Modified Files: src/sbin/mbrlabel: mbrlabel.8 Log Message: Fix terminology issue brought up by Bug Hunting in PR 47314. The boot records in extended partitions are called Extended Boot Record (EBR); use that in the documentation where appropriate. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sbin/mbrlabel/mbrlabel.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/mbrlabel/mbrlabel.8 diff -u src/sbin/mbrlabel/mbrlabel.8:1.18 src/sbin/mbrlabel/mbrlabel.8:1.19 --- src/sbin/mbrlabel/mbrlabel.8:1.18 Sat Jul 14 20:13:30 2012 +++ src/sbin/mbrlabel/mbrlabel.8 Wed Feb 27 20:43:00 2013 @@ -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.18 2012/07/14 20:13:30 wiz Exp $ +.\ $NetBSD: mbrlabel.8,v 1.19 2013/02/27 20:43:00 is Exp $ .\ -.Dd July 13, 2012 +.Dd February 27, 2013 .Dt MBRLABEL 8 .Os .Sh NAME @@ -44,7 +44,8 @@ .Nm is used to update a .Nx -disk label from the Master Boot Record (MBR) label(s) found +disk label from the Master Boot Record (MBR) label and Extended +Boot Record (EBR) label(s) found on disks that were previously used on DOS/Windows systems (or other MBR using systems). .Pp @@ -53,11 +54,11 @@ scans the MBR contained in the very firs block specified through the .Fl s flag), then walks through every extended partition found and generates -additional partition entries for the disk from the MBRs found in +additional partition entries for the disk from the EBRs found in those extended partitions. .Pp -Each MBR partition which does not have an equivalent partition in the -disk label (equivalent in having the same size and offset) is added to +Each MBR and each EBR partition which does not have an equivalent partition +in the disk label (equivalent in having the same size and offset) is added to the first free partition slot in the disk label. A free partition slot is defined as one with an .Dv fstype @@ -105,6 +106,11 @@ See also .Xr dkctl 8 , .Xr fdisk 8 , .Xr mbr 8 +.Rs +.%A Tn Microsoft corporation +.%T Disk Concepts and Troubleshooting +.%R Tn Microsoft technical library +.Re .Sh HISTORY The .Nm
CVS commit: src/sbin/mbrlabel
Module Name:src Committed By: wiz Date: Wed Feb 27 21:21:47 UTC 2013 Modified Files: src/sbin/mbrlabel: mbrlabel.8 Log Message: Remove trailing whitespace. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sbin/mbrlabel/mbrlabel.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/mbrlabel/mbrlabel.8 diff -u src/sbin/mbrlabel/mbrlabel.8:1.19 src/sbin/mbrlabel/mbrlabel.8:1.20 --- src/sbin/mbrlabel/mbrlabel.8:1.19 Wed Feb 27 20:43:00 2013 +++ src/sbin/mbrlabel/mbrlabel.8 Wed Feb 27 21:21:47 2013 @@ -27,7 +27,7 @@ .\ 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.19 2013/02/27 20:43:00 is Exp $ +.\ $NetBSD: mbrlabel.8,v 1.20 2013/02/27 21:21:47 wiz Exp $ .\ .Dd February 27, 2013 .Dt MBRLABEL 8 @@ -44,7 +44,7 @@ .Nm is used to update a .Nx -disk label from the Master Boot Record (MBR) label and Extended +disk label from the Master Boot Record (MBR) label and Extended Boot Record (EBR) label(s) found on disks that were previously used on DOS/Windows systems (or other MBR using systems).
CVS commit: src/sbin/mbrlabel
Module Name:src Committed By: wiz Date: Sat Jul 14 20:13:31 UTC 2012 Modified Files: src/sbin/mbrlabel: mbrlabel.8 Log Message: From Bug Hunting: - use more common option list header line; - remove superfluous `.Pp' macro (fixes mandoc(1) warning); - bump date. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/sbin/mbrlabel/mbrlabel.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/mbrlabel/mbrlabel.8 diff -u src/sbin/mbrlabel/mbrlabel.8:1.17 src/sbin/mbrlabel/mbrlabel.8:1.18 --- src/sbin/mbrlabel/mbrlabel.8:1.17 Mon Apr 5 18:08:41 2010 +++ src/sbin/mbrlabel/mbrlabel.8 Sat Jul 14 20:13:30 2012 @@ -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.17 2010/04/05 18:08:41 wiz Exp $ +.\ $NetBSD: mbrlabel.8,v 1.18 2012/07/14 20:13:30 wiz Exp $ .\ -.Dd April 5, 2010 +.Dd July 13, 2012 .Dt MBRLABEL 8 .Os .Sh NAME @@ -79,8 +79,7 @@ on i386 and some other platforms) is lef By default, the proposed changed disk label will be displayed and no disk label update will occur. .Pp -Available options: -.Pp +The following options are available: .Bl -tag -width sXsectorX .It Fl f Force an update, even if there has been no change.
CVS commit: src/sbin/mbrlabel
Module Name:src Committed By: wiz Date: Sat Jul 14 20:14:17 UTC 2012 Modified Files: src/sbin/mbrlabel: mbrlabel.c Log Message: From Bug Hunting: Sync usage with man page. To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/sbin/mbrlabel/mbrlabel.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/mbrlabel/mbrlabel.c diff -u src/sbin/mbrlabel/mbrlabel.c:1.27 src/sbin/mbrlabel/mbrlabel.c:1.28 --- src/sbin/mbrlabel/mbrlabel.c:1.27 Sat Aug 27 17:45:30 2011 +++ src/sbin/mbrlabel/mbrlabel.c Sat Jul 14 20:14:17 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: mbrlabel.c,v 1.27 2011/08/27 17:45:30 joerg Exp $ */ +/* $NetBSD: mbrlabel.c,v 1.28 2012/07/14 20:14:17 wiz Exp $ */ /* * Copyright (C) 1998 Wolfgang Solfrank. @@ -33,7 +33,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: mbrlabel.c,v 1.27 2011/08/27 17:45:30 joerg Exp $); +__RCSID($NetBSD: mbrlabel.c,v 1.28 2012/07/14 20:14:17 wiz Exp $); #endif /* not lint */ #include stdio.h @@ -239,7 +239,7 @@ getparts(int sd, u_int32_t off, u_int32_ static void usage(void) { - fprintf(stderr, usage: %s [-fqrw] [-s sector] rawdisk\n, + fprintf(stderr, usage: %s [-fqrw] [-s sector] device\n, getprogname()); exit(1); }
CVS commit: src/sbin/mbrlabel
Module Name:src Committed By: joerg Date: Sat Aug 27 17:45:30 UTC 2011 Modified Files: src/sbin/mbrlabel: mbrlabel.c Log Message: Be more static. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/sbin/mbrlabel/mbrlabel.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/mbrlabel/mbrlabel.c diff -u src/sbin/mbrlabel/mbrlabel.c:1.26 src/sbin/mbrlabel/mbrlabel.c:1.27 --- src/sbin/mbrlabel/mbrlabel.c:1.26 Wed Dec 28 06:03:15 2005 +++ src/sbin/mbrlabel/mbrlabel.c Sat Aug 27 17:45:30 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mbrlabel.c,v 1.26 2005/12/28 06:03:15 christos Exp $ */ +/* $NetBSD: mbrlabel.c,v 1.27 2011/08/27 17:45:30 joerg Exp $ */ /* * Copyright (C) 1998 Wolfgang Solfrank. @@ -33,7 +33,7 @@ #include sys/cdefs.h #ifndef lint -__RCSID($NetBSD: mbrlabel.c,v 1.26 2005/12/28 06:03:15 christos Exp $); +__RCSID($NetBSD: mbrlabel.c,v 1.27 2011/08/27 17:45:30 joerg Exp $); #endif /* not lint */ #include stdio.h @@ -55,17 +55,16 @@ #include dkcksum.h #include extern.h -int main(int, char **); -void usage(void); -void getlabel(int); -void setlabel(int, int); -int getparts(int, u_int32_t, u_int32_t, int); -u_int16_t getshort(void *); -u_int32_t getlong(void *); +__dead static void usage(void); +static void getlabel(int); +static void setlabel(int, int); +static int getparts(int, u_int32_t, u_int32_t, int); +static u_int16_t getshort(void *); +static u_int32_t getlong(void *); struct disklabel label; -void +static void getlabel(int sd) { @@ -81,7 +80,7 @@ label.d_npartitions = getrawpartition() + 1; } -void +static void setlabel(int sd, int doraw) { int one = 1; @@ -98,7 +97,7 @@ } -u_int16_t +static u_int16_t getshort(void *p) { unsigned char *cp = p; @@ -106,7 +105,7 @@ return (cp[0] | (cp[1] 8)); } -u_int32_t +static u_int32_t getlong(void *p) { unsigned char *cp = p; @@ -114,7 +113,7 @@ return (cp[0] | (cp[1] 8) | (cp[2] 16) | (cp[3] 24)); } -int +static int getparts(int sd, u_int32_t off, u_int32_t extoff, int verbose) { unsigned char buf[DEV_BSIZE]; @@ -237,7 +236,7 @@ return (changed); } -void +static void usage(void) { fprintf(stderr, usage: %s [-fqrw] [-s sector] rawdisk\n,
CVS commit: src/sbin/mbrlabel
Module Name:src Committed By: wiz Date: Mon Apr 5 18:08:41 UTC 2010 Modified Files: src/sbin/mbrlabel: mbrlabel.8 Log Message: Sort option descriptions, per PR 43119 by Bug Hunting. Refer to -r from -w. Bump date. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sbin/mbrlabel/mbrlabel.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sbin/mbrlabel/mbrlabel.8 diff -u src/sbin/mbrlabel/mbrlabel.8:1.16 src/sbin/mbrlabel/mbrlabel.8:1.17 --- src/sbin/mbrlabel/mbrlabel.8:1.16 Thu Jan 12 20:37:23 2006 +++ src/sbin/mbrlabel/mbrlabel.8 Mon Apr 5 18:08:41 2010 @@ -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.16 2006/01/12 20:37:23 wiz Exp $ +.\ $NetBSD: mbrlabel.8,v 1.17 2010/04/05 18:08:41 wiz Exp $ .\ -.Dd December 27, 2005 +.Dd April 5, 2010 .Dt MBRLABEL 8 .Os .Sh NAME @@ -86,8 +86,6 @@ Force an update, even if there has been no change. .It Fl q Performs operations in a quiet fashion. -.It Fl w -Update the in-core label if it has been changed. .It Fl r In conjunction with .Fl w , @@ -98,6 +96,10 @@ Useful if the disk has remapping drivers on it and the MBR is located in a non-standard place. Defaults to 0. +.It Fl w +Update the in-core label if it has been changed. +See also +.Fl r . .El .Sh SEE ALSO .Xr disklabel 8 ,