Source-Changes-HG archive

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

[src/trunk]: src/sbin/disklabel PR/50729: Izumi Tsutsui: Add "SMALLPROG"-like...



details:   https://anonhg.NetBSD.org/src/rev/5f3d22d8ac69
branches:  trunk
changeset: 343367:5f3d22d8ac69
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jan 31 18:57:29 2016 +0000

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

diffstat:

 sbin/disklabel/Makefile   |  42 +++++++++++++++++++++++++++++++++++++++++-
 sbin/disklabel/bswap.c    |   6 +++++-
 sbin/disklabel/bswap.h    |  13 ++++++++++++-
 sbin/disklabel/interact.c |   8 ++++++--
 sbin/disklabel/main.c     |  46 ++++++++++++++++++++++++++++++++++++++++++----
 5 files changed, 106 insertions(+), 9 deletions(-)

diffs (truncated from 339 to 300 lines):

diff -r 0fbba23c9e88 -r 5f3d22d8ac69 sbin/disklabel/Makefile
--- a/sbin/disklabel/Makefile   Sun Jan 31 18:56:49 2016 +0000
+++ b/sbin/disklabel/Makefile   Sun Jan 31 18:57:29 2016 +0000
@@ -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
diff -r 0fbba23c9e88 -r 5f3d22d8ac69 sbin/disklabel/bswap.c
--- a/sbin/disklabel/bswap.c    Sun Jan 31 18:56:49 2016 +0000
+++ b/sbin/disklabel/bswap.c    Sun Jan 31 18:57:29 2016 +0000
@@ -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 @@
 
        return dkcksum_sized(lp, npartitions);
 }
+
+#endif /* !NATIVELABEL_ONLY */
diff -r 0fbba23c9e88 -r 5f3d22d8ac69 sbin/disklabel/bswap.h
--- a/sbin/disklabel/bswap.h    Sun Jan 31 18:56:49 2016 +0000
+++ b/sbin/disklabel/bswap.h    Sun Jan 31 18:57:29 2016 +0000
@@ -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 @@
 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 */
diff -r 0fbba23c9e88 -r 5f3d22d8ac69 sbin/disklabel/interact.c
--- a/sbin/disklabel/interact.c Sun Jan 31 18:56:49 2016 +0000
+++ b/sbin/disklabel/interact.c Sun Jan 31 18:57:29 2016 +0000
@@ -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 @@
                        return;
        }
 }
+
+#endif /* !NO_INTERACT */
diff -r 0fbba23c9e88 -r 5f3d22d8ac69 sbin/disklabel/main.c
--- a/sbin/disklabel/main.c     Sun Jan 31 18:56:49 2016 +0000
+++ b/sbin/disklabel/main.c     Sun Jan 31 18:57:29 2016 +0000
@@ -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 @@
 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 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 set_writable_fd = -1;
 
+#if !defined(NATIVELABEL_ONLY)
 static u_int labeloffset;
 static u_int labelsector;
 static int labelusesmbr;
@@ -347,6 +350,13 @@
 
 /* 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 @@
 }
 #endif /* HAVE_NBTOOL_CONFIG_H */
 
+#if !defined(NATIVELABEL_ONLY)
 static void
 setbyteorder(int new_byteorder)
 {
@@ -444,6 +455,7 @@
                err(EXIT_FAILURE, "DISKLABELOFFSET in environment");
        return nval;
 }
+#endif /* !NATIVELABEL_ONLY */
 
 static void
 clear_writable(void)
@@ -458,22 +470,31 @@
        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 @@
        if ((cp = getenv("MACHINE_ARCH")) != NULL) {
                getarchbyteorder(cp);
        }
+#endif
 
        mflag = labelusesmbr;
        if (mflag < 0) {
@@ -522,6 +544,7 @@
                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 @@
                case 'M':       /* machine type */
                        getmachineparams(optarg);
                        break;
+#endif
                case 'N':       /* Disallow writes to label sector */
                        op = SETREADONLY;
                        break;
@@ -547,9 +571,11 @@
                        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 @@
                        usage();
        }
 
+#if !defined(NATIVELABEL_ONLY)
        if (maxpartitions == 0) {
                errx(1, "unknown label: use -M/-B and $MACHINE/$MACHINE_ARCH");
        }
@@ -602,6 +629,7 @@
        if (!native_p)
                Fflag = rflag = 1;
 #endif
+#endif /* !NATIVELABEL_ONLY */
 
        argc -= optind;
        argv += optind;
@@ -615,7 +643,11 @@
        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];



Home | Main Index | Thread Index | Old Index