NetBSD Problem Report #50729

From tsutsui@ceres.dti.ne.jp  Sat Jan 30 16:41:03 2016
Return-Path: <tsutsui@ceres.dti.ne.jp>
Received: from mail.netbsd.org (mail.NetBSD.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 1673B7ACCD
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 30 Jan 2016 16:41:03 +0000 (UTC)
Message-Id: <201601301640.u0UGeuqp008428@mirage.localdomain>
Date: Sun, 31 Jan 2016 01:40:56 +0900 (JST)
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
Reply-To: tsutsui@ceres.dti.ne.jp
To: gnats-bugs@NetBSD.org
Cc: tsutsui@ceres.dti.ne.jp
Subject: add "SMALLPROG"-like options to disklabel(8)
X-Send-Pr-Version: 3.95

>Number:         50729
>Category:       install
>Synopsis:       add "SMALLPROG"-like options to disklabel(8)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    install-manager
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 30 16:45:00 +0000 2016
>Closed-Date:    Sun May 27 04:25:35 +0000 2018
>Last-Modified:  Wed May 15 12:50:01 +0000 2024
>Originator:     Izumi Tsutsui
>Release:        NetBSD 7.0
>Organization:
>Environment:
System: NetBSD -current around 20160120
Architecture: all
Machine: all
>Description:
After 7.0 disklabel(8) supports non-native label including
swapped byte-order. disklabel(8) also supports "-i" (interactive)
option.

Both these two options are not necessary on sysinst installation
(while it could still be used in rescue case), it would be worth
to options to disable these functionality to shrink install media
ramdisks etc.

>How-To-Repeat:
Code inspection.

>Fix:
The following patch adds two options:

- "NATIVELABEL_ONLY"
 Omit support of cross-platform label.
 Just replaces several parameters and functions with constants and macro.
 (shrinks ~2KB .text and ~2KB .rodata om m68k)

- "NO_INTERACT"
 Disable -i option.
 Just #ifdef'ed out the functionality.
 (shrinks ~8KB on m68k)

Note:
- no binary change is expected without the options
- distrib/utils/x_disklabel is also added for MD crunchide lists
- "minimum installtion" on sysinst works with this x_disklabel
- XXX: tools build will fail if these two options are specified
  (i.e. no explicit exclusive check)
- XXX: some Makefile stuff should be shared with distrib/utils/x_disklabel
  as src/sbin/ifconfig/Makefile.inc does?

---
? sbin/disklabel/.gitignore
Index: sbin/disklabel/bswap.c
===================================================================
RCS file: /cvsroot/src/sbin/disklabel/bswap.c,v
retrieving revision 1.4
diff -u -p -d -r1.4 bswap.c
--- sbin/disklabel/bswap.c	18 Jul 2015 06:00:46 -0000	1.4
+++ sbin/disklabel/bswap.c	30 Jan 2016 05:20:25 -0000
@@ -55,6 +55,8 @@
  *	@(#)ufs_disksubr.c	7.16 (Berkeley) 5/4/91
  */

+#if !defined(NATIVELABEL_ONLY)
+
 #if HAVE_NBTOOL_CONFIG_H
 #include "nbtool_config.h"
 #endif
@@ -179,3 +181,5 @@ dkcksum_target(struct disklabel *lp)

 	return dkcksum_sized(lp, npartitions);
 }
+
+#endif /* !NATIVELABEL_ONLY */
Index: sbin/disklabel/bswap.h
===================================================================
RCS file: /cvsroot/src/sbin/disklabel/bswap.h,v
retrieving revision 1.2
diff -u -p -d -r1.2 bswap.h
--- sbin/disklabel/bswap.h	3 May 2013 16:05:12 -0000	1.2
+++ sbin/disklabel/bswap.h	30 Jan 2016 05:20:25 -0000
@@ -38,6 +38,7 @@
 #include <sys/endian.h>
 #endif

+#if !defined(NATIVELABEL_ONLY)
 extern int bswap_p;
 extern u_int maxpartitions;

@@ -49,3 +50,13 @@ extern u_int maxpartitions;
 void htotargetlabel(struct disklabel *, const struct disklabel *);
 void targettohlabel(struct disklabel *, const struct disklabel *);
 uint16_t dkcksum_target(struct disklabel *);
+#else
+#define htotarget16(x)		(x)
+#define target16toh(x)		(x)
+#define htotarget32(x)		(x)
+#define target32toh(x)		(x)
+
+#define htotargetlabel(dl, sl)	do { *(dl) = *(sl); } while (0)
+#define targettohlabel(dl, sl)	do { *(dl) = *(sl); } while (0)
+#define dkcksum_target(label)	dkcksum(label)
+#endif /* !NATIVELABEL_ONLY */
Index: sbin/disklabel/interact.c
===================================================================
RCS file: /cvsroot/src/sbin/disklabel/interact.c,v
retrieving revision 1.38
diff -u -p -d -r1.38 interact.c
--- sbin/disklabel/interact.c	3 May 2013 16:05:12 -0000	1.38
+++ sbin/disklabel/interact.c	30 Jan 2016 05:20:25 -0000
@@ -24,6 +24,8 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */

+#if !defined(NO_INTERACT)
+
 #if HAVE_NBTOOL_CONFIG_H
 #include "nbtool_config.h"
 #endif
@@ -810,3 +812,5 @@ interact(struct disklabel *lp, int fd)
 			return;
 	}
 }
+
+#endif /* !NO_INTERACT */
Index: sbin/disklabel/main.c
===================================================================
RCS file: /cvsroot/src/sbin/disklabel/main.c,v
retrieving revision 1.45
diff -u -p -d -r1.45 main.c
--- sbin/disklabel/main.c	27 Apr 2015 17:05:58 -0000	1.45
+++ sbin/disklabel/main.c	30 Jan 2016 05:20:26 -0000
@@ -163,7 +163,9 @@ static int readlabel_direct(int);
 static void writelabel_direct(int);
 static int update_label(int, u_int, u_int);
 static struct disklabel *find_label(int, u_int);
+#if !defined(NATIVELABEL_ONLY)
 static void getmachineparams(const char *);
+#endif

 static void		 makedisktab(FILE *, struct disklabel *);
 static void		 makelabel(const char *, const char *);
@@ -184,6 +186,7 @@ static int		 getulong(const char *, char

 static int set_writable_fd = -1;

+#if !defined(NATIVELABEL_ONLY)
 static u_int labeloffset;
 static u_int labelsector;
 static int labelusesmbr;
@@ -347,6 +350,13 @@ static const struct arch_endian {

 /* Default location for label - only used if we don't find one to update */
 #define LABEL_OFFSET (dklabel_getlabelsector() * DEV_BSIZE + dklabel_getlabeloffset())
+#else
+#define labeloffset	LABELOFFSET
+#define labelsector	LABELSECTOR
+#define labelusesmbr	LABELUSESMBR
+#define maxpartitions	MAXPARTITIONS
+#define LABEL_OFFSET	LABELOFFSET
+#endif /* !NATIVELABEL_ONLY */

 /*
  * For portability it doesn't make sense to use any other value....
@@ -368,6 +378,7 @@ opendisk(const char *path, int flags, ch
 }
 #endif /* HAVE_NBTOOL_CONFIG_H */

+#if !defined(NATIVELABEL_ONLY)
 static void
 setbyteorder(int new_byteorder)
 {
@@ -444,6 +455,7 @@ dklabel_getlabeloffset(void)
 		err(EXIT_FAILURE, "DISKLABELOFFSET in environment");
 	return nval;
 }
+#endif /* !NATIVELABEL_ONLY */

 static void
 clear_writable(void)
@@ -458,22 +470,31 @@ main(int argc, char *argv[])
 	FILE	*t;
 	int	 ch, f, error;
 	char	*dkname;
+#if !defined(NATIVELABEL_ONLY)
 	char	*cp;
+#endif
 	struct stat sb;
 	int	 writable;
 	enum {
 		UNSPEC, EDIT, READ, RESTORE, SETWRITABLE, SETREADONLY,
-		WRITE, INTERACT, DELETE
+		WRITE,
+#if !defined(NO_INTERACT)
+		INTERACT,
+#endif
+		DELETE
 	} op = UNSPEC, old_op;

 #ifndef HAVE_NBTOOL_CONFIG_H
+#if !defined(NATIVELABEL_ONLY)
 	labeloffset = native_params.labeloffset = getlabeloffset();
 	labelsector = native_params.labelsector = getlabelsector();
 	labelusesmbr = native_params.labelusesmbr = getlabelusesmbr();
 	maxpartitions = native_params.maxpartitions = getmaxpartitions();
 	byteorder = native_params.byteorder = BYTE_ORDER;
 #endif
+#endif

+#if !defined(NATIVELABEL_ONLY)
 	if ((cp = getenv("MACHINE")) != NULL) {
 		getmachineparams(cp);
 	}
@@ -481,6 +502,7 @@ main(int argc, char *argv[])
 	if ((cp = getenv("MACHINE_ARCH")) != NULL) {
 		getarchbyteorder(cp);
 	}
+#endif

 	mflag = labelusesmbr;
 	if (mflag < 0) {
@@ -522,6 +544,7 @@ main(int argc, char *argv[])
 		case 'R':	/* Restore label from text file */
 			op = RESTORE;
 			break;
+#if !defined(NATIVELABEL_ONLY)
 		case 'B':	/* byteorder */
 			if (!strcmp(optarg, "be")) {
 				setbyteorder(BIG_ENDIAN);
@@ -534,6 +557,7 @@ main(int argc, char *argv[])
 		case 'M':	/* machine type */
 			getmachineparams(optarg);
 			break;
+#endif
 		case 'N':	/* Disallow writes to label sector */
 			op = SETREADONLY;
 			break;
@@ -547,9 +571,11 @@ main(int argc, char *argv[])
 			if (setdisktab(optarg) == -1)
 				usage();
 			break;
+#if !defined(NO_INTERACT)
 		case 'i':	/* Edit using built-in editor */
 			op = INTERACT;
 			break;
+#endif /* !NO_INTERACT */
 		case 'l':	/* List all known file system types and exit */
 			lflag = 1;
 			break;
@@ -576,6 +602,7 @@ main(int argc, char *argv[])
 			usage();
 	}

+#if !defined(NATIVELABEL_ONLY)
 	if (maxpartitions == 0) {
 		errx(1, "unknown label: use -M/-B and $MACHINE/$MACHINE_ARCH");
 	}
@@ -602,6 +629,7 @@ main(int argc, char *argv[])
 	if (!native_p)
 		Fflag = rflag = 1;
 #endif
+#endif /* !NATIVELABEL_ONLY */

 	argc -= optind;
 	argv += optind;
@@ -615,7 +643,11 @@ main(int argc, char *argv[])
 	if (argc < 1)
 		usage();

-	if (Iflag && op != EDIT && op != INTERACT)
+	if (Iflag && op != EDIT
+#if !defined(NO_INTERACT)
+	    && op != INTERACT
+#endif
+	    )
 		usage();

 	dkname = argv[0];
@@ -643,6 +675,7 @@ main(int argc, char *argv[])
 		error = edit(f);
 		break;

+#if !defined(NO_INTERACT)
 	case INTERACT:
 		if (argc != 1)
 			usage();
@@ -656,6 +689,7 @@ main(int argc, char *argv[])
 			lab.d_sbsize = SBLOCKSIZE;
 		interact(&lab, f);
 		break;
+#endif /* !NO_INTERACT */

 	case READ:
 		if (argc != 1)
@@ -2071,7 +2105,9 @@ usage(void)
 	{ "[-ABCFMrtv] disk", "(to read label)" },
 	{ "-w [-BDFMrv] [-f disktab] disk disktype [packid]", "(to write label)" },
 	{ "-e [-BCDFMIrv] disk", "(to edit label)" },
+#if !defined(NO_INTERACT)
 	{ "-i [-BDFMIrv] disk", "(to create a label interactively)" },
+#endif
 	{ "-D [-v] disk", "(to delete existing label(s))" },
 	{ "-R [-BDFMrv] disk protofile", "(to restore label)" },
 	{ "[-NW] disk", "(to write disable/enable label)" },
@@ -2172,10 +2208,12 @@ list_fs_types(void)
 int
 dk_ioctl(int f, u_long cmd, void *arg)
 {
+#if !defined(NATIVELABEL_ONLY)
 	if (!native_p) {
 		errno = ENOTTY;
 		return -1;
 	}
+#endif
 	return ioctl(f, cmd, arg);
 }
 #endif
Index: distrib/utils/Makefile
===================================================================
RCS file: /cvsroot/src/distrib/utils/Makefile,v
retrieving revision 1.21
diff -u -p -d -r1.21 Makefile
--- distrib/utils/Makefile	26 Jul 2014 19:35:10 -0000	1.21
+++ distrib/utils/Makefile	30 Jan 2016 05:20:42 -0000
@@ -3,7 +3,7 @@
 .if make(obj)

 SUBDIR=	libhack more ssh tls \
-	x_ed x_gzip x_ifconfig \
+	x_disklabel x_ed x_gzip x_ifconfig \
 	x_netstat x_ping x_route x_umount zcat

 .if ${MACHINE} == "acorn32"
--- /dev/null	2016-01-30 14:18:22.000000000 +0900
+++ distrib/utils/x_disklabel/Makefile	2016-01-29 10:47:31.000000000 +0900
@@ -0,0 +1,40 @@
+# $NetBSD$
+# Build a small disklabel (for tiny boot media)
+
+SRCDIR=	${.CURDIR}/../../../sbin/disklabel
+
+PROG=	disklabel
+SRCS=	main.c dkcksum.c printlabel.c
+#SRCS+=	interact.c
+NOMAN=	# defined
+
+CPPFLAGS+=	-DNO_INTERACT
+CPPFLAGS+=	-DNATIVELABEL_ONLY
+
+DPADD+= ${LIBUTIL}
+LDADD+= -lutil
+
+# these have additional requirements on the alignment of a partition
+.if (${MACHINE} == "sparc") || (${MACHINE} == "sparc64") \
+	|| (${MACHINE} == "sun3")
+CPPFLAGS+= -DSTRICT_CYLINDER_ALIGNMENT
+.endif
+
+.if (${MACHINE} == "acorn32" || ${MACHINE} == "acorn26")
+# Support FileCore boot block
+CPPFLAGS+= -DUSE_ACORN
+.endif
+
+.if (${MACHINE_ARCH} == "alpha")
+# alpha requires boot block checksum
+CPPFLAGS+= -DALPHA_BOOTBLOCK_CKSUM
+.endif
+
+.if (${MACHINE_ARCH} == "vax")
+# vax requires labels in alternative sectors on SMD disk
+CPPFLAGS+= -DVAX_ALTLABELS
+.endif
+
+.include <bsd.prog.mk>
+
+.PATH:	${SRCDIR}

---
Izumi Tsutsui

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/50729 CVS commit: src/distrib/utils
Date: Sun, 31 Jan 2016 13:56:49 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sun Jan 31 18:56:49 UTC 2016

 Modified Files:
 	src/distrib/utils: Makefile
 Added Files:
 	src/distrib/utils/x_disklabel: Makefile

 Log Message:
 PR/50729: Izumi Tsutsui: Add "small" disklabel


 To generate a diff of this commit:
 cvs rdiff -u -r1.21 -r1.22 src/distrib/utils/Makefile
 cvs rdiff -u -r0 -r1.1 src/distrib/utils/x_disklabel/Makefile

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/50729 CVS commit: src/sbin/disklabel
Date: Sun, 31 Jan 2016 13:57:29 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Sun Jan 31 18:57:29 UTC 2016

 Modified Files:
 	src/sbin/disklabel: Makefile bswap.c bswap.h interact.c main.c

 Log Message:
 PR/50729: Izumi Tsutsui: Add "SMALLPROG"-like options to disklabel(8)


 To generate a diff of this commit:
 cvs rdiff -u -r1.70 -r1.71 src/sbin/disklabel/Makefile
 cvs rdiff -u -r1.4 -r1.5 src/sbin/disklabel/bswap.c
 cvs rdiff -u -r1.2 -r1.3 src/sbin/disklabel/bswap.h
 cvs rdiff -u -r1.38 -r1.39 src/sbin/disklabel/interact.c
 cvs rdiff -u -r1.45 -r1.46 src/sbin/disklabel/main.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: tsutsui@NetBSD.org
State-Changed-When: Sun, 27 May 2018 04:25:35 +0000
State-Changed-Why:
Committed by christos back in 2016.


From: "Izumi Tsutsui" <tsutsui@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/50729 CVS commit: src/sbin/disklabel
Date: Wed, 15 May 2024 12:47:22 +0000

 Module Name:	src
 Committed By:	tsutsui
 Date:		Wed May 15 12:47:22 UTC 2024

 Modified Files:
 	src/sbin/disklabel: main.c

 Log Message:
 Fix an old bug in NATIVELABEL_ONLY case in PR/50729 by me. (sigh)

 'disklabel -r -w' writes a disklabel at a wrong sector in
 NATIVELABEL_ONLY && !LABELUSESMBR && LABELSECTOR != 0 case
 if the target disk doesn't have a valid disklabel, due to
 incorrect LABEL_OFFSET value.

 Found and investigated on NetBSD/hp300 bootable CD tests.
 Maybe this affects ports that use distrib/utils/x_disklabel
 but have no MBR support, i.e. only NetBSD/hp300 10.0 and
 NetBSD/ews4800mips 9.0 and later.

 Should be pulled up to netbsd-10 and netbsd-9.


 To generate a diff of this commit:
 cvs rdiff -u -r1.57 -r1.58 src/sbin/disklabel/main.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.