Subject: Re: patch rfc: "host tools" disklabel, fdisk
To: None <tech-toolchain@NetBSD.org>
From: David Young <dyoung@pobox.com>
List: tech-toolchain
Date: 03/24/2005 01:50:03
--hUH5gZbnpyIv7Mn4
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Thu, Mar 24, 2005 at 07:54:31AM +0000, David Laight wrote:
> On Wed, Mar 23, 2005 at 10:29:26PM -0600, David Young wrote:
> > I botched the patch in a few ways. Here is a new one.
> >
> > Dave
> >
> > --
> > David Young OJC Technologies
> > dyoung@ojctech.com Urbana, IL * (217) 278-3933
>
> > [-- Attachment #2: host-fdisk-disklabel-4.gz --]
> > [-- Type: application/x-gzip, Encoding: base64, Size: 8.7K --]
>
> > [-- application/x-gzip is unsupported (use 'v' to view this part) --]
>
>
> If you want people to read patches please send them as text....
Here that is again.
Dave
--
David Young OJC Technologies
dyoung@ojctech.com Urbana, IL * (217) 278-3933
--hUH5gZbnpyIv7Mn4
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=host-fdisk-disklabel-4
? share/mk/.bsd.kinc.mk.swp
? sbin/fdisk/.fdisk.c.swp
Index: share/mk/bsd.kinc.mk
===================================================================
RCS file: /cvsroot/src/share/mk/bsd.kinc.mk,v
retrieving revision 1.35
diff -u -r1.35 bsd.kinc.mk
--- share/mk/bsd.kinc.mk 29 Jan 2004 01:48:45 -0000 1.35
+++ share/mk/bsd.kinc.mk 24 Mar 2005 04:26:11 -0000
@@ -19,9 +19,19 @@
.include <bsd.init.mk>
+.if defined(HOST_INCSDIR)
+INCS_DESTDIR?= ${HOST_INCSDIR}
+_INSTALL_DIR= ${HOST_INSTALL_DIR}
+_INSTALL_FILE= ${HOST_INSTALL_FILE}
+.else
+INCS_DESTDIR?= ${DESTDIR}${INCSDIR}
+_INSTALL_DIR= ${INSTALL_DIR} -o ${BINOWN} -g ${BINGRP}
+_INSTALL_FILE= ${INSTALL_FILE} -o ${BINOWN} -g ${BINGRP} -m ${NONBINMODE}
+.endif
+
##### Basic targets
-.PRECIOUS: ${DESTDIR}${INCSDIR}
-includes: ${DESTDIR}${INCSDIR} .WAIT ${INCS} incinstall
+.PRECIOUS: ${INCS_DESTDIR}
+includes: ${INCS_DESTDIR} .WAIT ${INCS} incinstall
##### Install rules
incinstall:: # ensure existence
@@ -29,13 +39,13 @@
# make sure the directory is OK, and install includes.
-${DESTDIR}${INCSDIR}: .EXEC
+${INCS_DESTDIR}: .EXEC
@if [ ! -d ${.TARGET} ] || [ -h ${.TARGET} ] ; then \
${_MKSHMSG_CREATE} ${.TARGET}; \
/bin/rm -rf ${.TARGET}; \
- ${_MKSHECHO} ${INSTALL_DIR} -o ${BINOWN} -g ${BINGRP} -m 755 \
+ ${_MKSHECHO} ${_INSTALL_DIR} -m 755 \
${SYSPKGTAG} ${.TARGET}; \
- ${INSTALL_DIR} -o ${BINOWN} -g ${BINGRP} -m 755 \
+ ${_INSTALL_DIR} -m 755 \
${SYSPKGTAG} ${.TARGET}; \
fi
@@ -43,13 +53,13 @@
__incinstall: .USE
@cmp -s ${.ALLSRC} ${.TARGET} > /dev/null 2>&1 || \
(${_MKSHMSG_INSTALL} ${.TARGET}; \
- ${_MKSHECHO} "${INSTALL_FILE} -c -o ${BINOWN} -g ${BINGRP} \
- -m ${NONBINMODE} ${SYSPKGTAG} ${.ALLSRC} ${.TARGET}" && \
- ${INSTALL_FILE} -c -o ${BINOWN} -g ${BINGRP} \
- -m ${NONBINMODE} ${SYSPKGTAG} ${.ALLSRC} ${.TARGET})
+ ${_MKSHECHO} "${_INSTALL_FILE} -c \
+ ${SYSPKGTAG} ${.ALLSRC} ${.TARGET}" && \
+ ${_INSTALL_FILE} -c \
+ ${SYSPKGTAG} ${.ALLSRC} ${.TARGET})
.for F in ${INCS:O:u} ${DEPINCS:O:u}
-_F:= ${DESTDIR}${INCSDIR}/${F} # installed path
+_F:= ${INCS_DESTDIR}/${F} # installed path
.if ${MKUPDATE} == "no"
${_F}! ${F} __incinstall # install rule
@@ -63,7 +73,7 @@
.undef _F
-.if defined(INCSYMLINKS) && !empty(INCSYMLINKS)
+.if defined(INCSYMLINKS) && !empty(INCSYMLINKS) && !defined(HOST_INCSDIR)
incinstall::
@(set ${INCSYMLINKS}; \
while test $$# -ge 2; do \
Index: share/mk/bsd.own.mk
===================================================================
RCS file: /cvsroot/src/share/mk/bsd.own.mk,v
retrieving revision 1.438
diff -u -r1.438 bsd.own.mk
--- share/mk/bsd.own.mk 28 Feb 2005 02:28:09 -0000 1.438
+++ share/mk/bsd.own.mk 24 Mar 2005 04:26:11 -0000
@@ -650,6 +650,7 @@
INSTALL_LINK?= ${INSTALL} ${INSTPRIV} ${HRDLINK} ${RENAME}
INSTALL_SYMLINK?= ${INSTALL} ${INSTPRIV} ${SYMLINK} ${RENAME}
HOST_INSTALL_FILE?= ${INSTALL} ${COPY} ${PRESERVE} ${RENAME}
+HOST_INSTALL_DIR?= ${INSTALL} -d
.endif
#
Index: tools/Makefile
===================================================================
RCS file: /cvsroot/src/tools/Makefile,v
retrieving revision 1.88
diff -u -r1.88 Makefile
--- tools/Makefile 27 Jan 2005 12:54:05 -0000 1.88
+++ tools/Makefile 24 Mar 2005 04:26:11 -0000
@@ -21,16 +21,16 @@
.if !defined(NOSUBDIR) # {
SUBDIR= host-mkdep .WAIT compat .WAIT \
- binstall .WAIT mktemp .WAIT \
+ binstall .WAIT nbmachine .WAIT mktemp .WAIT \
cap_mkdb crunchgen ctags gencat hexdump lint lint2 lorder \
m4 makewhatis mkdep mtree rpcgen tsort uudecode \
texinfo .WAIT \
yacc .WAIT \
lex .WAIT \
${TOOLCHAIN_BITS} \
- asn1_compile cat cksum compile_et config db file installboot \
- lint1 makefs menuc mkcsmapper mkesdb mklocale mknod msgc pax \
- pwd_mkdb stat sunlabel zic
+ asn1_compile cat cksum compile_et config db disklabel fdisk \
+ file installboot lint1 makefs menuc mkcsmapper mkesdb mklocale \
+ mknod msgc pax pwd_mkdb stat sunlabel zic
.if ${MKMAN} != "no"
SUBDIR+= groff
Index: tools/disklabel/Makefile
===================================================================
RCS file: tools/disklabel/Makefile
diff -N tools/disklabel/Makefile
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tools/disklabel/Makefile 24 Mar 2005 04:26:11 -0000
@@ -0,0 +1,7 @@
+# $NetBSD: Makefile,v 1.4 2003/11/12 02:18:27 matt Exp $
+
+HOSTPROGNAME= ${_TOOL_PREFIX}disklabel
+HOST_SRCDIR= sbin/disklabel
+HOST_CPPFLAGS= -I${TOOLDIR}/nbmachine
+
+.include "${.CURDIR}/../Makefile.host"
Index: tools/fdisk/Makefile
===================================================================
RCS file: tools/fdisk/Makefile
diff -N tools/fdisk/Makefile
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tools/fdisk/Makefile 24 Mar 2005 04:26:11 -0000
@@ -0,0 +1,10 @@
+# $NetBSD: Makefile,v 1.4 2003/11/12 02:18:27 matt Exp $
+
+HOSTPROGNAME= ${_TOOL_PREFIX}fdisk
+HOST_SRCDIR= sbin/fdisk
+HOST_CPPFLAGS= -I${TOOLDIR}/nbmachine
+HOST_SRCS= getcap.c disklabel.c
+
+.include "${.CURDIR}/../Makefile.host"
+
+.PATH: ${.CURDIR}/../../lib/libc/gen
Index: tools/nbmachine/Makefile
===================================================================
RCS file: tools/nbmachine/Makefile
diff -N tools/nbmachine/Makefile
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tools/nbmachine/Makefile 24 Mar 2005 04:26:12 -0000
@@ -0,0 +1,14 @@
+.include <bsd.own.mk>
+
+clean:
+
+depend:
+
+includes:
+
+install:
+ cd ${.CURDIR}/../../sys/arch && \
+ ${MAKE} HOST_INCSDIR=${TOOLDIR}/nbmachine/nbmachine includes
+
+obj:
+
Index: sys/sys/disklabel.h
===================================================================
RCS file: /cvsroot/src/sys/sys/disklabel.h,v
retrieving revision 1.90
diff -u -r1.90 disklabel.h
--- sys/sys/disklabel.h 7 Jan 2005 18:29:15 -0000 1.90
+++ sys/sys/disklabel.h 24 Mar 2005 04:26:12 -0000
@@ -48,7 +48,11 @@
* label can describe and the number of the "whole disk" (raw)
* paritition are machine dependent.
*/
+#if HAVE_NBTOOL_CONFIG_H
+#include <nbmachine/disklabel.h>
+#else
#include <machine/disklabel.h>
+#endif /* HAVE_NBTOOL_CONFIG_H */
/*
* The absolute maximum number of disk partitions allowed.
Index: sbin/fdisk/Makefile
===================================================================
RCS file: /cvsroot/src/sbin/fdisk/Makefile,v
retrieving revision 1.31
diff -u -r1.31 Makefile
--- sbin/fdisk/Makefile 20 Jan 2005 16:39:23 -0000 1.31
+++ sbin/fdisk/Makefile 24 Mar 2005 04:26:12 -0000
@@ -34,4 +34,6 @@
.endif
.include <bsd.prog.mk>
+.if (${HOSTPROG:Uempty} == empty)
.include <bsd.subdir.mk>
+.endif
Index: sbin/fdisk/fdisk.c
===================================================================
RCS file: /cvsroot/src/sbin/fdisk/fdisk.c,v
retrieving revision 1.88
diff -u -r1.88 fdisk.c
--- sbin/fdisk/fdisk.c 20 Jan 2005 16:01:02 -0000 1.88
+++ sbin/fdisk/fdisk.c 24 Mar 2005 04:26:13 -0000
@@ -34,21 +34,30 @@
#include <sys/cdefs.h>
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
#ifndef lint
__RCSID("$NetBSD: fdisk.c,v 1.88 2005/01/20 16:01:02 xtraeme Exp $");
#endif /* not lint */
#define MBRPTYPENAMES
#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "../../sys/sys/disklabel.h"
+#include "../../sys/sys/bootblock.h"
+#else
#include <sys/disklabel.h>
#include <sys/bootblock.h>
#include <sys/ioctl.h>
-#include <sys/param.h>
-#include <sys/stat.h>
#include <sys/sysctl.h>
+#endif /* HAVE_NBTOOL_CONFIG_H */
#include <ctype.h>
-#include <disktab.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
@@ -59,7 +68,14 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "../../include/disktab.h"
+#include "../../include/util.h"
+#else
+#include <disktab.h>
#include <util.h>
+#endif /* HAVE_NBTOOL_CONFIG_H */
#define DEFAULT_BOOTDIR "/usr/mdec"
@@ -93,7 +109,7 @@
struct disklabel disklabel; /* disk parameters */
-uint cylinders, sectors, heads;
+u_int cylinders, sectors, heads;
daddr_t disksectors;
#define cylindersectors (heads * sectors)
@@ -122,9 +138,9 @@
#define OPTIONS "0123FSafiluvs:b:c:E:r:w:"
#endif
-uint dos_cylinders;
-uint dos_heads;
-uint dos_sectors;
+u_int dos_cylinders;
+u_int dos_heads;
+u_int dos_sectors;
daddr_t dos_disksectors;
#define dos_cylindersectors (dos_heads * dos_sectors)
#define dos_totalsectors (dos_heads * dos_sectors * dos_cylinders)
@@ -132,7 +148,7 @@
#define DOSSECT(s,c) (((s) & 0x3f) | (((c) >> 2) & 0xc0))
#define DOSCYL(c) ((c) & 0xff)
#define SEC_IN_1M (1024 * 1024 / 512)
-#define SEC_TO_MB(sec) ((uint)(((sec) + SEC_IN_1M / 2) / SEC_IN_1M))
+#define SEC_TO_MB(sec) ((u_int)(((sec) + SEC_IN_1M / 2) / SEC_IN_1M))
#define SEC_TO_CYL(sec) (((sec) + dos_cylindersectors/2) / dos_cylindersectors)
#define MAXCYL 1024 /* Usual limit is 1023 */
@@ -141,7 +157,7 @@
int partition = -1;
int fd = -1, wfd = -1, *rfd = &fd;
-char *disk_file;
+char *disk_file = NULL;
char *disk_type = NULL;
int a_flag; /* set active partition */
@@ -200,7 +216,7 @@
int ptn_id(const char *, int *);
int type_match(const void *, const void *);
const char *get_type(int);
-int get_mapping(int, uint *, uint *, uint *, unsigned long *);
+int get_mapping(int, u_int *, u_int *, u_int *, unsigned long *);
#ifdef BOOTSEL
daddr_t configure_bootsel(daddr_t);
void install_bootsel(int);
@@ -208,14 +224,31 @@
void set_default_boot(daddr_t);
#endif
+#if !HAVE_NBTOOL_CONFIG_H
+static void
+initvar_disk(const char **diskp)
+{
+ int mib[2];
+ size_t len;
+ char *root_device;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_ROOT_DEVICE;
+ if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1 ||
+ (root_device = malloc(len)) == NULL ||
+ sysctl(mib, 2, root_device, &len, NULL, 0) == -1)
+ return;
+
+ *diskp = root_device;
+}
+#endif /* HAVE_NBTOOL_CONFIG_H */
int
main(int argc, char *argv[])
{
struct stat sb;
- int ch, mib[2];
+ int ch;
size_t len;
- char *root_device;
char *cp;
int n;
#ifdef BOOTSEL
@@ -225,12 +258,9 @@
int csysid, cstart, csize; /* For the b_flag. */
- mib[0] = CTL_KERN;
- mib[1] = KERN_ROOT_DEVICE;
- if (sysctl(mib, 2, NULL, &len, NULL, 0) != -1 &&
- (root_device = malloc(len)) != NULL &&
- sysctl(mib, 2, root_device, &len, NULL, 0) != -1)
- disk = root_device;
+#if !HAVE_NBTOOL_CONFIG_H
+ initvar_disk(&disk);
+#endif /* HAVE_NBTOOL_CONFIG_H */
a_flag = i_flag = u_flag = sh_flag = f_flag = s_flag = b_flag = 0;
v_flag = 0;
@@ -340,6 +370,13 @@
argc -= optind;
argv += optind;
+#if HAVE_NBTOOL_CONFIG_H
+ if (disk_file == NULL && argc > 0)
+ disk_file = argv[0];
+ else if (disk_file == NULL)
+ usage();
+#endif /* HAVE_NBTOOL_CONFIG_H */
+
if (disk_type != NULL && getdiskbyname(disk_type) == NULL)
errx(EXIT_FAILURE, "bad disktype");
@@ -371,7 +408,7 @@
/* must have been a blank disk */
init_sector0(1);
-#if defined(__i386__) || defined(__x86_64__)
+#if (defined(__i386__) || defined(__x86_64__)) && !HAVE_NBTOOL_CONFIG_H
get_geometry();
#else
intuit_translated_geometry();
@@ -455,7 +492,12 @@
"%*s[-0123 | -E num "
"[-s id/start/size[/bootmenu]]] \\\n"
"%*s[-t disktab] [-T disktype] \\\n"
- "%*s[-c bootcode] [-r|-w file] [device]\n"
+ "%*s[-c bootcode] "
+#if !HAVE_NBTOOL_CONFIG_H
+ "[-r|-w file] [device]\n"
+#else
+ "[-r|-w] file\n"
+#endif /* HAVE_NBTOOL_CONFIG_H */
"\t-a change active partition\n"
"\t-f force - not interactive\n"
"\t-i initialise MBR code\n"
@@ -586,7 +628,7 @@
static void
pr_cyls(daddr_t sector)
{
- ulong cyl, head, sect;
+ u_long cyl, head, sect;
cyl = sector / dos_cylindersectors;
sect = sector - cyl * dos_cylindersectors;
head = sect / dos_sectors;
@@ -876,6 +918,7 @@
diskname[len] = 0;
}
+#if !HAVE_NBTOOL_CONFIG_H
void
get_geometry(void)
{
@@ -923,13 +966,14 @@
/* Allright, allright, make a stupid guess.. */
intuit_translated_geometry();
}
-#endif
+#endif /* HAVE_NBTOOL_CONFIG_H */
+#endif /* defined(__i386__) || defined(__x86_64__) */
#ifdef BOOTSEL
daddr_t
get_default_boot(void)
{
- uint id;
+ u_int id;
int p;
if (le16toh(mboot.mbr_bootsel_magic) != MBR_BS_MAGIC)
@@ -1219,8 +1263,8 @@
intuit_translated_geometry(void)
{
int xcylinders = -1, xheads = -1, xsectors = -1, i, j;
- uint c1, h1, s1, c2, h2, s2;
- ulong a1, a2;
+ u_int c1, h1, s1, c2, h2, s2;
+ u_long a1, a2;
uint64_t num, denom;
/*
@@ -1316,7 +1360,7 @@
* Note: for simplicity, the returned sector is 0-based.
*/
int
-get_mapping(int i, uint *cylinder, uint *head, uint *sector,
+get_mapping(int i, u_int *cylinder, u_int *head, u_int *sector,
unsigned long *absolute)
{
struct mbr_partition *part = &mboot.mbr_parts[i / 2];
@@ -1419,7 +1463,7 @@
check_overlap(int part, int sysid, daddr_t start, daddr_t size, int fix)
{
int p;
- uint p_s, p_e;
+ u_int p_s, p_e;
if (sysid != 0) {
if (start < dos_sectors)
@@ -1538,7 +1582,7 @@
check_ext_overlap(int part, int sysid, daddr_t start, daddr_t size, int fix)
{
int p;
- uint p_s, p_e;
+ u_int p_s, p_e;
if (sysid == 0)
return 0;
@@ -2048,6 +2092,13 @@
{
static char namebuf[MAXPATHLEN + 1];
+#if HAVE_NBTOOL_CONFIG_H
+ strlcpy(namebuf, disk_file, sizeof(namebuf));
+ if ((fd = open(disk_file, update ? O_RDWR : O_RDONLY, 0)) == -1) {
+ warn("%s", disk_file);
+ return -1;
+ }
+#else
fd = opendisk(disk, update && disk_file == NULL ? O_RDWR : O_RDONLY,
namebuf, sizeof(namebuf), 0);
if (fd < 0) {
@@ -2057,6 +2108,7 @@
warn("%s", namebuf);
return (-1);
}
+#endif /* HAVE_NBTOOL_CONFIG_H */
disk = namebuf;
if (get_params() == -1) {
close(fd);
@@ -2138,6 +2190,12 @@
disklabel.d_ncylinders = dos_cylinders;
disklabel.d_ntracks = dos_heads;
disklabel.d_nsectors = dos_sectors;
+#if HAVE_NBTOOL_CONFIG_H
+ } else {
+ warnx("no disklabel specified");
+ return -1;
+ }
+#else
} else if (ioctl(fd, DIOCGDEFLABEL, &disklabel) == -1) {
warn("DIOCGDEFLABEL");
if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
@@ -2145,6 +2203,7 @@
return (-1);
}
}
+#endif /* HAVE_NBTOOL_CONFIG_H */
disksectors = disklabel.d_secperunit;
cylinders = disklabel.d_ncylinders;
heads = disklabel.d_ntracks;
@@ -2175,8 +2234,8 @@
static int
validate_bootsel(struct mbr_bootsel *mbs)
{
- uint key = mbs->mbrbs_defkey;
- uint tmo;
+ u_int key = mbs->mbrbs_defkey;
+ u_int tmo;
int i;
if (v_flag)
@@ -2290,8 +2349,10 @@
* sector 0. (e.g. empty disk)
*/
flag = 1;
+#if !HAVE_NBTOOL_CONFIG_H
if (wfd == fd && F_flag == 0 && ioctl(wfd, DIOCWLABEL, &flag) < 0)
warn("DIOCWLABEL");
+#endif /* HAVE_NBTOOL_CONFIG_H */
if (write_disk(0, &mboot) == -1) {
warn("Can't write fdisk partition table");
goto protect_label;
@@ -2311,9 +2372,11 @@
}
rval = 0;
protect_label:
+#if !HAVE_NBTOOL_CONFIG_H
flag = 0;
if (wfd == fd && F_flag == 0 && ioctl(wfd, DIOCWLABEL, &flag) < 0)
warn("DIOCWLABEL");
+#endif /* HAVE_NBTOOL_CONFIG_H */
return rval;
}
@@ -2405,7 +2468,7 @@
int
ptn_id(const char *prompt, int *extended)
{
- uint acc = 0;
+ u_int acc = 0;
char *cp;
for (;; printf("%s is not a valid partition number.\n", lbuf)) {
Index: sbin/disklabel/disklabel.c
===================================================================
RCS file: /cvsroot/src/sbin/disklabel/disklabel.c,v
retrieving revision 1.135
diff -u -r1.135 disklabel.c
--- sbin/disklabel/disklabel.c 12 Nov 2004 01:00:40 -0000 1.135
+++ sbin/disklabel/disklabel.c 24 Mar 2005 04:26:13 -0000
@@ -32,6 +32,10 @@
* SUCH DAMAGE.
*/
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\
@@ -49,16 +53,10 @@
#include <sys/param.h>
#include <sys/file.h>
-#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#define DKTYPENAMES
#define FSTYPENAMES
-#include <sys/disklabel.h>
-#include <sys/bootblock.h>
-
-#include <ufs/ufs/dinode.h>
-#include <ufs/ffs/fs.h>
#include <ctype.h>
#include <err.h>
@@ -69,9 +67,22 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
-#include <util.h>
+#include <ufs/ufs/dinode.h>
+#include <ufs/ffs/fs.h>
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "../../sys/sys/disklabel.h"
+#include "../../sys/sys/bootblock.h"
+#include "../../include/util.h"
+#include "../../include/disktab.h"
+#else
+#include <sys/ioctl.h>
+#include <sys/disklabel.h>
+#include <sys/bootblock.h>
+#include <util.h>
#include <disktab.h>
+#endif /* HAVE_NBTOOL_CONFIG_H */
#include "pathnames.h"
#include "extern.h"
@@ -175,6 +186,14 @@
#define GETNUM16(a, v) getulong(a, '\0', NULL, v, UINT16_MAX)
#define GETNUM8(a, v) getulong(a, '\0', NULL, v, UINT8_MAX)
+#if HAVE_NBTOOL_CONFIG_H
+#define GETLABELOFFSET() LABELOFFSET
+#define GETLABELSECTOR() LABELSECTOR
+#else /* HAVE_NBTOOL_CONFIG_H */
+#define GETLABELOFFSET() getlabeloffset()
+#define GETLABELSECTOR() getlabelsector()
+#endif
+
int
main(int argc, char *argv[])
{
@@ -207,16 +226,17 @@
case 'I':
++Iflag;
break;
- case 'N':
+ case 'R':
if (op != UNSPEC)
usage();
- writable = 0;
- op = SETWRITABLE;
+ op = RESTORE;
break;
- case 'R':
+#if !HAVE_NBTOOL_CONFIG_H
+ case 'N':
if (op != UNSPEC)
usage();
- op = RESTORE;
+ writable = 0;
+ op = SETWRITABLE;
break;
case 'W':
if (op != UNSPEC)
@@ -224,6 +244,7 @@
writable = 1;
op = SETWRITABLE;
break;
+#endif /* !HAVE_NBTOOL_CONFIG_H */
case 'e':
if (op != UNSPEC)
usage();
@@ -282,7 +303,12 @@
usage();
dkname = argv[0];
+#if HAVE_NBTOOL_CONFIG_H
+ f = open(dkname, op == READ ? O_RDONLY : O_RDWR, 0);
+ strlcpy(np, dkname, MAXPATHLEN);
+#else
f = opendisk(dkname, op == READ ? O_RDONLY : O_RDWR, np, MAXPATHLEN, 0);
+#endif /* HAVE_NBTOOL_CONFIG_H */
specname = np;
np += strlen(specname) + 1;
if (f < 0)
@@ -363,10 +389,12 @@
error = 1;
break;
+#if !HAVE_NBTOOL_CONFIG_H
case SETWRITABLE:
if (ioctl(f, DIOCWLABEL, (char *)&writable) < 0)
err(4, "ioctl DIOCWLABEL");
break;
+#endif /* !HAVE_NBTOOL_CONFIG_H */
case WRITE:
if (argc < 2 || argc > 3)
@@ -524,11 +552,13 @@
* may prevent us from changing the current (in-core)
* label.
*/
- if (ioctl(f, DIOCSDINFO, lp) < 0 &&
+#if !HAVE_NBTOOL_CONFIG_H
+ if (!Fflag && ioctl(f, DIOCSDINFO, lp) < 0 &&
errno != ENODEV && errno != ENOTTY) {
l_perror("ioctl DIOCSDINFO");
return (1);
}
+#endif /* HAVE_NBTOOL_CONFIG_H */
if (lseek(f, sectoffset, SEEK_SET) < 0) {
perror("lseek");
return (1);
@@ -538,8 +568,10 @@
* disable after writing.
*/
writable = 1;
+#if !HAVE_NBTOOL_CONFIG_H
if (!Fflag && ioctl(f, DIOCWLABEL, &writable) < 0)
perror("ioctl DIOCWLABEL");
+#endif /* HAVE_NBTOOL_CONFIG_H */
#ifdef __alpha__
/*
@@ -570,6 +602,7 @@
#endif /* NUMBOOT > 0 */
writable = 0;
+#if !HAVE_NBTOOL_CONFIG_H
if (!Fflag && ioctl(f, DIOCWLABEL, &writable) < 0)
perror("ioctl DIOCWLABEL");
/*
@@ -580,11 +613,16 @@
l_perror("ioctl DIOCWDINFO");
return (1);
}
+#endif /* !HAVE_NBTOOL_CONFIG_H */
} else {
+#if !HAVE_NBTOOL_CONFIG_H
if (ioctl(f, DIOCWDINFO, lp) < 0) {
l_perror("ioctl DIOCWDINFO");
return (1);
}
+#else
+ errx(1, "use -F, -r, or -I");
+#endif /* HAVE_NBTOOL_CONFIG_H */
}
#ifdef __vax__
@@ -646,7 +684,7 @@
struct mbr_partition *dp;
struct mbr_sector mbr;
int part;
- uint ext_base, next_ext, this_ext;
+ u_int ext_base, next_ext, this_ext;
static struct mbr_partition netbsd_part;
/*
@@ -920,6 +958,9 @@
}
if (msg != NULL && !Iflag)
errx(1, "%s", msg);
+#if HAVE_NBTOOL_CONFIG_H
+ goto err;
+#else
/*
* There was no label on the disk. Get the fictious one
* as a basis for initialisation.
@@ -927,13 +968,20 @@
lp = makebootarea(bootarea, &lab, f);
if (ioctl(f, DIOCGDINFO, lp) < 0 &&
ioctl(f, DIOCGDEFLABEL, lp) < 0)
- errx(1, "could not get initial label");
+ goto err;
+#endif /* HAVE_NBTOOL_CONFIG_H */
} else {
+#ifdef HAVE_NBTOOL_CONFIG_H
+ goto err;
+#else
lp = &lab;
if (ioctl(f, DIOCGDINFO, lp) < 0)
err(4, "ioctl DIOCGDINFO");
+#endif /* HAVE_NBTOOL_CONFIG_H */
}
return (lp);
+err:
+ errx(1, "could not get initial label");
}
/*
@@ -955,9 +1003,9 @@
# endif
#endif /* NUMBOOT > 0 */
- if ((lsec = getlabelsector()) < 0)
+ if ((lsec = GETLABELSECTOR()) < 0)
err(4, "getlabelsector()");
- if ((loff = getlabeloffset()) < 0)
+ if ((loff = GETLABELOFFSET()) < 0)
err(4, "getlabeloffset()");
/* XXX */
Index: sbin/disklabel/dkcksum.c
===================================================================
RCS file: /cvsroot/src/sbin/disklabel/dkcksum.c,v
retrieving revision 1.10
diff -u -r1.10 dkcksum.c
--- sbin/disklabel/dkcksum.c 7 Aug 2003 10:04:13 -0000 1.10
+++ sbin/disklabel/dkcksum.c 24 Mar 2005 04:26:14 -0000
@@ -39,7 +39,11 @@
#endif /* not lint */
#include <sys/types.h>
+#if HAVE_NBTOOL_CONFIG_H
+#include "../../sys/sys/disklabel.h"
+#else
#include <sys/disklabel.h>
+#endif /* HAVE_NBTOOL_CONFIG_H */
#include "dkcksum.h"
u_short
Index: sbin/disklabel/interact.c
===================================================================
RCS file: /cvsroot/src/sbin/disklabel/interact.c,v
retrieving revision 1.23
diff -u -r1.23 interact.c
--- sbin/disklabel/interact.c 29 Dec 2003 21:21:25 -0000 1.23
+++ sbin/disklabel/interact.c 24 Mar 2005 04:26:14 -0000
@@ -37,13 +37,19 @@
#include <sys/param.h>
#define FSTYPENAMES
#define DKTYPENAMES
-#include <sys/disklabel.h>
#include <err.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "../../include/util.h"
+#include "../../sys/sys/disklabel.h"
+#else
#include <util.h>
+#include <sys/disklabel.h>
+#endif /* HAVE_NBTOOL_CONFIG_H */
#include "extern.h"
Index: sbin/disklabel/printlabel.c
===================================================================
RCS file: /cvsroot/src/sbin/disklabel/printlabel.c,v
retrieving revision 1.11
diff -u -r1.11 printlabel.c
--- sbin/disklabel/printlabel.c 28 Feb 2004 18:19:00 -0000 1.11
+++ sbin/disklabel/printlabel.c 24 Mar 2005 04:26:14 -0000
@@ -41,7 +41,11 @@
#define DKTYPENAMES
#define FSTYPENAMES
+#if HAVE_NBTOOL_CONFIG_H
+#include "../../sys/sys/disklabel.h"
+#else
#include <sys/disklabel.h>
+#endif /* HAVE_NBTOOL_CONFIG_H */
#include <stdio.h>
--hUH5gZbnpyIv7Mn4--