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.

Modified files:

Index: src/sbin/disklabel/Makefile
diff -u src/sbin/disklabel/Makefile:1.70 src/sbin/disklabel/Makefile:1.71
--- src/sbin/disklabel/Makefile:1.70	Fri May  3 12:05:12 2013
+++ src/sbin/disklabel/Makefile	Sun Jan 31 13:57:29 2016
@@ -1,4 +1,44 @@
-#	$NetBSD: Makefile,v 1.70 2013/05/03 16:05:12 matt Exp $
+# $NetBSD: Makefile,v 1.71 2016/01/31 18:57:29 christos Exp $
+# 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}
+#	$NetBSD: Makefile,v 1.71 2016/01/31 18:57:29 christos Exp $
 #	@(#)Makefile	8.2 (Berkeley) 3/17/94
 
 PROG=	disklabel

Index: src/sbin/disklabel/bswap.c
diff -u src/sbin/disklabel/bswap.c:1.4 src/sbin/disklabel/bswap.c:1.5
--- src/sbin/disklabel/bswap.c:1.4	Sat Jul 18 02:00:46 2015
+++ src/sbin/disklabel/bswap.c	Sun Jan 31 13:57:29 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: bswap.c,v 1.4 2015/07/18 06:00:46 htodd Exp $	*/
+/*	$NetBSD: bswap.c,v 1.5 2016/01/31 18:57:29 christos Exp $	*/
 
 /*-
  * Copyright (c) 2009 Izumi Tsutsui.  All rights reserved.
@@ -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: src/sbin/disklabel/bswap.h
diff -u src/sbin/disklabel/bswap.h:1.2 src/sbin/disklabel/bswap.h:1.3
--- src/sbin/disklabel/bswap.h:1.2	Fri May  3 12:05:12 2013
+++ src/sbin/disklabel/bswap.h	Sun Jan 31 13:57:29 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: bswap.h,v 1.2 2013/05/03 16:05:12 matt Exp $	*/
+/*	$NetBSD: bswap.h,v 1.3 2016/01/31 18:57:29 christos Exp $	*/
 
 /*-
  * Copyright (c) 2009 Izumi Tsutsui.  All rights reserved.
@@ -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: src/sbin/disklabel/interact.c
diff -u src/sbin/disklabel/interact.c:1.38 src/sbin/disklabel/interact.c:1.39
--- src/sbin/disklabel/interact.c:1.38	Fri May  3 12:05:12 2013
+++ src/sbin/disklabel/interact.c	Sun Jan 31 13:57:29 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: interact.c,v 1.38 2013/05/03 16:05:12 matt Exp $	*/
+/*	$NetBSD: interact.c,v 1.39 2016/01/31 18:57:29 christos Exp $	*/
 
 /*
  * Copyright (c) 1997 Christos Zoulas.  All rights reserved.
@@ -24,13 +24,15 @@
  * 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
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: interact.c,v 1.38 2013/05/03 16:05:12 matt Exp $");
+__RCSID("$NetBSD: interact.c,v 1.39 2016/01/31 18:57:29 christos Exp $");
 #endif /* lint */
 
 #include <sys/param.h>
@@ -810,3 +812,5 @@ interact(struct disklabel *lp, int fd)
 			return;
 	}
 }
+
+#endif /* !NO_INTERACT */

Index: src/sbin/disklabel/main.c
diff -u src/sbin/disklabel/main.c:1.45 src/sbin/disklabel/main.c:1.46
--- src/sbin/disklabel/main.c:1.45	Mon Apr 27 13:05:58 2015
+++ src/sbin/disklabel/main.c	Sun Jan 31 13:57:29 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.45 2015/04/27 17:05:58 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.46 2016/01/31 18:57:29 christos Exp $	*/
 
 /*
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 19
 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.45 2015/04/27 17:05:58 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.46 2016/01/31 18:57:29 christos Exp $");
 #endif
 #endif	/* not lint */
 
@@ -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

Reply via email to