NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

install/50729: add "SMALLPROG"-like options to disklabel(8)



>Number:         50729
>Category:       install
>Synopsis:       add "SMALLPROG"-like options to disklabel(8)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    install-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 30 16:45:00 +0000 2016
>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



Home | Main Index | Thread Index | Old Index