summaryrefslogtreecommitdiff
path: root/sbin/disklabel
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2016-01-31 18:57:29 +0000
committerchristos <christos@NetBSD.org>2016-01-31 18:57:29 +0000
commit4be1db950af7788ba91d6d762bfff5990f82aae3 (patch)
tree868f405838f1850737793c0822e81b313e99d08d /sbin/disklabel
parentf57d89fb65fc42aab0eff03151b712c89745a328 (diff)
PR/50729: Izumi Tsutsui: Add "SMALLPROG"-like options to disklabel(8)
Diffstat (limited to 'sbin/disklabel')
-rw-r--r--sbin/disklabel/Makefile42
-rw-r--r--sbin/disklabel/bswap.c6
-rw-r--r--sbin/disklabel/bswap.h13
-rw-r--r--sbin/disklabel/interact.c8
-rw-r--r--sbin/disklabel/main.c46
5 files changed, 106 insertions, 9 deletions
diff --git a/sbin/disklabel/Makefile b/sbin/disklabel/Makefile
index 45e402f2f60..6320c25e7b3 100644
--- a/sbin/disklabel/Makefile
+++ b/sbin/disklabel/Makefile
@@ -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 --git a/sbin/disklabel/bswap.c b/sbin/disklabel/bswap.c
index 47b4a17f0e7..5f4ccc9637d 100644
--- a/sbin/disklabel/bswap.c
+++ b/sbin/disklabel/bswap.c
@@ -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 */
diff --git a/sbin/disklabel/bswap.h b/sbin/disklabel/bswap.h
index 4de06e0dc83..89d63c4aa2d 100644
--- a/sbin/disklabel/bswap.h
+++ b/sbin/disklabel/bswap.h
@@ -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 */
diff --git a/sbin/disklabel/interact.c b/sbin/disklabel/interact.c
index b4bad904ac0..d032e74b5ed 100644
--- a/sbin/disklabel/interact.c
+++ b/sbin/disklabel/interact.c
@@ -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 */
diff --git a/sbin/disklabel/main.c b/sbin/disklabel/main.c
index c80475dc01e..1c214636c6c 100644
--- a/sbin/disklabel/main.c
+++ b/sbin/disklabel/main.c
@@ -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, 1993\
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, 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, char *buf, int buflen, int cooked)
}
#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