summaryrefslogtreecommitdiffstats
path: root/sbin/i386
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2001-11-03 07:31:21 +0000
committerpeter <peter@FreeBSD.org>2001-11-03 07:31:21 +0000
commit32b6e93593760bd24314cff73ac7fdd832420ac4 (patch)
tree83e3b6c9f4b11a0840196b31bdb1b2739ad8624a /sbin/i386
parent4ca131b9a6d6f29aaa503fb035a27d66620d4c3a (diff)
downloadFreeBSD-src-32b6e93593760bd24314cff73ac7fdd832420ac4.zip
FreeBSD-src-32b6e93593760bd24314cff73ac7fdd832420ac4.tar.gz
Repo copied contents of src/sbin/i386 to src/sbin and set specific
SUBDIR lists there. Some of these are used on other platforms.
Diffstat (limited to 'sbin/i386')
-rw-r--r--sbin/i386/Makefile7
-rw-r--r--sbin/i386/Makefile.inc3
-rw-r--r--sbin/i386/cxconfig/Makefile7
-rw-r--r--sbin/i386/cxconfig/cxconfig.8329
-rw-r--r--sbin/i386/cxconfig/cxconfig.c770
-rw-r--r--sbin/i386/fdisk/Makefile6
-rw-r--r--sbin/i386/fdisk/fdisk.8433
-rw-r--r--sbin/i386/fdisk/fdisk.c1509
-rw-r--r--sbin/i386/nextboot/Makefile7
-rw-r--r--sbin/i386/nextboot/nextboot.8115
-rw-r--r--sbin/i386/nextboot/nextboot.c202
11 files changed, 0 insertions, 3388 deletions
diff --git a/sbin/i386/Makefile b/sbin/i386/Makefile
deleted file mode 100644
index fcdb011..0000000
--- a/sbin/i386/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-SUBDIR= cxconfig \
- fdisk \
- nextboot
-
-.include <bsd.subdir.mk>
diff --git a/sbin/i386/Makefile.inc b/sbin/i386/Makefile.inc
deleted file mode 100644
index 265f86d..0000000
--- a/sbin/i386/Makefile.inc
+++ /dev/null
@@ -1,3 +0,0 @@
-# $FreeBSD$
-
-.include "../Makefile.inc"
diff --git a/sbin/i386/cxconfig/Makefile b/sbin/i386/cxconfig/Makefile
deleted file mode 100644
index 49c493e..0000000
--- a/sbin/i386/cxconfig/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $FreeBSD$
-
-PROG= cxconfig
-WARNS?= 2
-MAN= cxconfig.8
-
-.include <bsd.prog.mk>
diff --git a/sbin/i386/cxconfig/cxconfig.8 b/sbin/i386/cxconfig/cxconfig.8
deleted file mode 100644
index 62b06e3..0000000
--- a/sbin/i386/cxconfig/cxconfig.8
+++ /dev/null
@@ -1,329 +0,0 @@
-.\" $FreeBSD$
-.Dd December 2, 1994
-.Dt CXCONFIG 8
-.Os
-.Sh NAME
-.Nm cxconfig
-.Nd channel options management utility for Cronyx-Sigma adapter
-.Sh SYNOPSIS
-.Nm
-.Op Fl a
-.Op Ar <channel> Op Ar <option>...
-.Sh DESCRIPTION
-The
-.Nm
-utility is used for configuring the channel options of
-the Cronyx-Sigma adapter.
-.Pp
-To change channel options the channel should be free: the corresponding
-network interface in ``down'' state, the asynchronous terminal device
-.Pa /dev/tty*
-closed.
-Generally, the channel options are set up during the operating
-system startup, for example from the
-.Pa /etc/rc
-file.
-.Pp
-Note, that not all options have a sense for every particular
-case, and an attempt to set some of them can hang up the channel or
-the whole adapter.
-.Pp
-The following option is available:
-.Bl -tag -width indent
-.It Fl a
-Display full information.
-.El
-.Sh "Channel options"
-.Bl -tag -width 10n
-.It ispeed=#
-Set the receiver baud rate to the number given.
-The maximal value is 256000 bits/sec.
-In the synchronous mode the receiver baud rate is significant
-only when DPLL mode is used.
-.It ospeed=#
-Set the transmitter baud rate to the number given.
-The maximal value is 256000 bits/sec.
-In the synchronous mode the transmitter baud rate is significant
-only in the case of the internal clock source.
-If receiver and transmitter have equal data rate, then it could
-be set by specifying only the numerical argument.
-.It async
-Set the asynchronous channel mode.
-.It "hdlc, bisync, bsc, x.21, x21
-Set the synchronous channel mode: HDLC, Bisync (BSC) or X.21.
-.It ppp
-Set the link-level protocol: PpP/HDLC. The built-in simplified synchronous PPP
-implementation is used (see RFC-1548, RFC-1549).
-.It cisco
-Set the link-level protocol: Cisco/HDLC (see RFC-1547).
-This protocol is intended for compatibility with old models of Cisco routers,
-and with early versions of
-.Tn BSD/386
-drivers.
-The extensive usage of this protocol is not recommended.
-.It ext
-Use the external link-level protocol suite (for
-.Tn BSD/386
-only).
-.It "+keepalive, -keepalive"
-Enable the automatic line state control sub-protocol.
-This setting is not significant when the external link-level protocol is used.
-.It "+autorts, -autorts"
-Enable the automatic RTS signal control.
-When enabled, the RTS signal goes up only when both halves of
-the receiver ring buffer are free and ready for receive,
-and goes down when one or both buffers are busy.
-.It "port=rs232, port=rs449, port=v35
-Set the zero channel hardware interface type.
-.El
-.Sh "Common options"
-.Bl -tag -width 10n
-.It "nrz, nrzi, manchester"
-Set the data line signal encoding.
-In the case of
-.Em NRZ
-encoding the zero bit is transmitted by the zero signal
-level, the one bit - by the positive signal level.
-In the case of
-.Em NRZI
-encoding the zero bit is transmitted by the change of
-the signal level, the one bit - by the constant signal level.
-In the case of
-.Em Manchester
-encoding the zero bit is encoded as 01 value,
-the one bit - as 10 value.
-.It "+dpll, -dpll"
-Enable the digital phase locked loop mode (DPLL).
-When enabled, the receiver timing clock signal
-is derived from the received data.
-.It "+lloop, -lloop"
-Set the local loopback mode.
-.It "+extclock, -extclock"
-Set the timing clock source of synchronous channels. There are
-two possible variants:
-.Em "external clock"
-source or
-.Em "internal clock"
-generation.
-.Pp
-.Em "External clock"
-mode is the most common method for connecting
-external modem hardware. In this mode the external timing
-signal is received on TXCIN pin of the connector, and it is
-used as a synchronization clock for transmitting data (TXD).
-.Pp
-In the case of
-.Em "internal clock"
-mode the transmitted data (TXD)
-are synchronized using the internal on-board timing generator,
-the internally generated timing signal is driven on the TXCOUT
-pin, and the signal on the TXCIN pin is ignored. This mode
-is used for direct terminal-to-terminal communication,
-e.g. for connecting two computers together in a synchronous mode
-via relatively short cable. This method should also be used
-for testing channels with an external loopback connector.
-.It fifo=#
-FIFO threshold level setup for receiver and transmitter.
-.It rfifo=#
-Hardware RTS/CTS flow control FIFO threshold setup.
-.It "+ctsup, -ctsup"
-Enable/disable interrupts on CTS (Clear To Send) signal setup (0 to 1 transition).
-.It "+ctsdown, -ctsdown"
-Enable/disable interrupts on CTS (Clear To Send) signal clear (1 to 0 transition).
-.It "+cdup, -cdup"
-Enable/disable interrupts on CD (Carrier Detect) signal setup (0 to 1 transition).
-.It "+cddown, -cddown"
-Enable/disable interrupts on CD (Carrier Detect) signal clear (1 to 0 transition).
-.It "+dsrup, -dsrup"
-Enable/disable interrupts on DSR (Data Set Ready) signal setup (0 to 1 transition).
-.It "+dsrdown, -dsrdown"
-Enable/disable interrupts on DSR (Data Set Ready) signal clear (1 to 0 transition).
-.El
-.Sh "Asynchronous mode options"
-.Bl -tag -width 10n
-.It cs#
-Select character size: 5, 6, 7 or 8 bits.
-.It "parodd, pareven
-Parity mode: odd or even.
-.It "+ignpar, -ignpar
-Disable/enable parity detection.
-.It nopar
-Disable parity bit generation.
-.It forcepar
-Force parity: even - 0, odd - 1.
-.It "stopb1, stopb1.5, stopb2
-Use 1 or 1.5 or 2 stop bits per character.
-.It "+dsr, -dsr"
-Use the DSR input signal as receiver enable/disable.
-.It "+cts, -cts"
-Use the CTS input signal as transmitter enable/disable.
-.It "+rts, -rts"
-Drive the RTS output signal as transmitter ready.
-.It "+rloop, -rloop"
-Set the remote loopback mode.
-.It "+etc, -etc"
-Enable the embedded transmit commands mode.
-.It "+ixon, -ixon"
-Enable the hardware XON/XOFF flow control support.
-.It "+ixany, -ixany"
-Use the hardware IXANY mode support.
-.It "+sdt, -sdt"
-Detect the spec. characters SCHR1 and SCHR2 in the receive data.
-.It "+flowct, -flowct"
-Receive the flow control spec. characters as data.
-.It "+rdt, -rdt"
-Detect the spec. characters in range SCRL..SCRH in the receive data.
-.It "+exdt, -exdt"
-Detect the spec. characters SCHR3 and SCHR4 in the receive data.
-.It "parintr, parnull, parign, pardisc, parffnull
-Action on parity errors:
-.Pp
-.Bl -tag -width parffnullxxx -compact
-.It Mode
-Action
-.It parintr
-Generate the receiver error interrupt
-.It parnull
-Input the NUL character
-.It parign
-Ignore the error, receive as good data
-.It pardisc
-Ignore the character
-.It parffnull
-Input the sequence <0xFF, NUL, character>
-.El
-.It "brkintr, brknull, brkdisc
-Line break state action:
-.Pp
-.Bl -tag -width parffnullxxx -compact
-.It Mode
-Action
-.It brkintr
-Generate the receiver error interrupt
-.It brknull
-Input the NUL character
-.It brkdisc
-Ignore the line break state
-.El
-.It "+inlcr, -inlcr"
-Translate received NL characters to CR.
-.It "+icrnl, -icrnl"
-Translate received CR characters to NL.
-.It "+igncr, -igncr"
-Ignore received CR characters.
-.It "+ocrnl, -ocrnl"
-Translate transmitted CR characters to NL.
-.It "+onlcr, -onlcr"
-Translate transmitted NL characters to CR.
-.It "+fcerr, -fcerr"
-Process (don't process) the characters, received with errors,
-for special character/flow control matching.
-.It "+lnext, -lnext"
-Enable the LNEXT character option: the character following
-the LNEXT character is not processed for special character/flow
-control matching.
-.It "+istrip, -istrip"
-Strip input characters to seven bits.
-.It schr1=#
-The XON flow control character value.
-.It schr2=#
-The XOFF flow control character value.
-.It schr3=#
-The SCHR3 spec. character value.
-.It schr4=#
-The SCHR4 spec. character value.
-.It "scrl=#, scrh=#
-The spec. character range (inclusive).
-.It lnext=#
-The LNEXT spec. character value.
-.El
-.Sh "HDLC mode options"
-.Bl -tag -width 10n
-.It if#
-The minimum number of flags transmitted before a frame is started.
-.It noaddr
-No frame address recognition.
-.It "addrlen1, addrlen2"
-Address field length: 1 or 2 bytes.
-.It "addr1, addr2"
-Addressing mode: 4x1 bytes or 2x2 bytes.
-Registers RFAR1..RFAR4 should contain the address to be matched.
-.It "+clrdet, -clrdet"
-Enable/disable clear detect for X.21 protocol support.
-.It "+dsr, -dsr"
-Use the DSR input signal as receiver enable/disable.
-.It "+cts, -cts"
-Use the CTS input signal as transmitter enable/disable.
-.It "+rts, -rts"
-Drive the RTS output signal as transmitter ready.
-.It "+fcs, -fcs"
-Enable/disable the frame checksum generation and checking.
-.It "crc-16, crc-v.41
-Select the CRC polynomial: CRC-16 (x^16+x^15+x^2+1)
-or CRC V.41 (x^16+x^12+x^5+1).
-.It "fcs-crc-16, fcs-v.41
-Frame checksum preset: all zeros (CRC-16) or all ones (CRC V.41).
-.It "+crcinv, -crcinv"
-Invert (ie. CRC V.41) or don't invert (ie. CRC-16) the transmitted frame checksum.
-.It "+fcsapd, -fcsapd"
-Pass the received CRC to the host at the end of receiver data buffer.
-.It "idlemark, idleflag
-Idle mode: idle in mark (transmit all ones) or idle in flag (transmit flag).
-.It "+syn, -syn"
-Enable/disable sending pad characters before sending flag when coming out
-of the idle mode.
-.It pad#
-The number of synchronous characters sent (0..4).
-.It "syn=0xaa, syn=0x00
-Send sync pattern.
-.It "rfar1=#, rfar2=#, rfar3=#, rfar4=#
-Frame address registers for address recognition.
-.El
-.Sh EXAMPLES
-Set up the channel 7 of the adapter Sigma-400 under
-.Fx .
-Physical 4-wire leased line with Zelax+ M115 short-range modems.
-Synchronous mode, 128000 bits/sec, interface RS-232,
-protocol PpP/HDLC without keepalive support, NRZI encoding,
-DPLL mode, no flow control:
-.Bd -literal
-cxconfig cx7 128000 hdlc ppp -keepalive nrzi -cts +dpll -extclock
-ifconfig cx7 158.250.244.2 158.250.244.1 up
-.Ed
-.Pp
-Set up the channel 0 of the adapter Sigma-100 under
-.Fx .
-Attachment to the near computer by short cable, internal clock source.
-Synchronous mode, 256000 bits/sec, interface RS-232,
-protocol Cisco/HDLC with keepalive support:
-.Bd -literal
-cxconfig cx0 hdlc 256000 cisco +keepalive -extclock
-ifconfig cx0 200.1.1.1 200.1.1.2 up
-.Ed
-.Pp
-Set up the channel 1 of the adapter Sigma-840 under
-.Tn BSD/386 .
-Synchronous 64 kbit/sec leased line, external clock source.
-Synchronous mode, interface V.35, external protocol suite:
-.Bd -literal
-cxconfig cx1 hdlc ext
-ifconfig cx1 193.124.254.50 193.124.254.49 multicast up
-.Ed
-.Pp
-Set up the channel 0 of the adapter Sigma-840 under
-.Fx .
-Attachment to the Cisco-4000 router by null-modem cable, internal clock source.
-Synchronous mode, 64000 bits/sec, interface RS-232,
-protocol PpP/HDLC with keepalive support and flow control,
-LCP and IPCP protocols (see RFC-1548 and RFC-1332) debug tracing enabled:
-.Bd -literal
-cxconfig cx0 hdlc 64000 port=rs232 ppp +keepalive -extclock +cts
-ifconfig cx0 100.0.0.2 100.0.0.1 debug up
-.Ed
-.Sh FILES
-.Bl -tag -width /dev/cronyx -compact
-.It Pa /dev/cronyx
-the special device file for adapter options management
-.El
-.Sh SEE ALSO
-.Xr cx 4
diff --git a/sbin/i386/cxconfig/cxconfig.c b/sbin/i386/cxconfig/cxconfig.c
deleted file mode 100644
index 1a5ca48..0000000
--- a/sbin/i386/cxconfig/cxconfig.c
+++ /dev/null
@@ -1,770 +0,0 @@
-/*
- * Cronyx-Sigma adapter configuration utility for Unix.
- *
- * Copyright (C) 1994 Cronyx Ltd.
- * Author: Serge Vakulenko, <vak@zebub.msk.su>
- *
- * This software is distributed with NO WARRANTIES, not even the implied
- * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Authors grant any other persons or organisations permission to use
- * or modify this software as long as this message is kept with the software,
- * all derivative works or modified versions.
- *
- * Version 1.9, Wed Oct 4 18:58:15 MSK 1995
- *
- * Usage:
- * cxconfig [-a]
- * -- print status of all channels
- * cxconfig [-a] <channel>
- * -- print status of the channel
- * cxconfig <channel> <option>...
- * -- set channel options
- */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <machine/cronyx.h>
-
-#include <err.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#define NBRD 3
-#define CXDEV "/dev/cronyx"
-#define atoi(a) strtol((a), (char**)0, 0)
-
-cx_options_t o;
-cx_stat_t st;
-int aflag;
-int sflag;
-
-static char *
-symbol(unsigned char sym)
-{
- static char buf[40];
-
- if (sym < ' ')
- sprintf (buf, "^%c", sym+0100);
- else if (sym == '\\')
- strcat (buf, "\\\\");
- else if (sym < 127)
- sprintf (buf, "%c", sym);
- else
- sprintf (buf, "\\%03o", sym);
- return (buf);
-}
-
-static unsigned char
-atosym(char *s)
-{
- if (*s == '^')
- return (*++s & 037);
- if (*s == '\\')
- return (strtol (++s, 0, 8));
- return (*s);
-}
-
-static void
-usage(void)
-{
- fprintf (stderr,
- "Cronyx-Sigma Adapter Configuration Utility, Version 1.0\n");
- fprintf (stderr, "Copyright (C) 1994 Cronyx Ltd.\n");
- fprintf (stderr, "usage: cxconfig [-a] [<channel> [<option>...]]\n");
- exit (1);
-}
-
-static const char *
-chantype(int type)
-{
- switch (type) {
- default:
- case T_NONE: return ("none");
- case T_ASYNC: return ("RS-232");
- case T_UNIV_RS232: return ("RS-232");
- case T_UNIV_RS449: return ("RS-232/RS-449");
- case T_UNIV_V35: return ("RS-232/V.35");
- case T_SYNC_RS232: return ("RS-232");
- case T_SYNC_V35: return ("V.35");
- case T_SYNC_RS449: return ("RS-449");
- }
-}
-
-static const char *
-chanmode(int mode)
-{
- switch (mode) {
- case M_ASYNC: return ("Async");
- case M_HDLC: return ("HDLC");
- case M_BISYNC: return ("Bisync");
- case M_X21: return ("X.21");
- default: return ("???");
- }
-}
-
-static void
-getchan(int channel)
-{
- int s = open (CXDEV, 0);
- if (s < 0)
- err (1, "%s", CXDEV);
- o.board = channel/NCHAN;
- o.channel = channel%NCHAN;
- if (ioctl (s, CXIOCGETMODE, (caddr_t)&o) < 0)
- err (1, "CXIOCGETMODE");
- close (s);
- if (o.type == T_NONE)
- errx (1, "cx%d: channel %d not configured", o.board,
- o.channel);
-}
-
-static int
-printstats(int channel, int hflag)
-{
- int s, res;
-
- s = open (CXDEV, 0);
- if (s < 0)
- err (1, "%s", CXDEV);
- st.board = channel/NCHAN;
- st.channel = channel%NCHAN;
- res = ioctl (s, CXIOCGETSTAT, (caddr_t)&st);
- close (s);
- if (res < 0)
- return (-1);
-
- if (hflag)
- printf ("Chan Rintr Tintr Mintr Ibytes Ipkts Ierrs Obytes Opkts Oerrs\n");
- printf ("cx%-2d %7ld %7ld %7ld %8ld %7ld %7ld %8ld %7ld %7ld\n",
- channel, st.rintr, st.tintr, st.mintr, st.ibytes, st.ipkts,
- st.ierrs, st.obytes, st.opkts, st.oerrs);
- return (0);
-}
-
-static void
-printallstats(void)
-{
- int b, c;
-
- printf ("Chan Rintr Tintr Mintr Ibytes Ipkts Ierrs Obytes Opkts Oerrs\n");
- for (b=0; b<NBRD; ++b)
- for (c=0; c<NCHAN; ++c)
- printstats (b*NCHAN + c, 0);
-}
-
-static void
-setchan(int channel)
-{
- int s = open (CXDEV, 0);
- if (s < 0)
- err (1, "%s", CXDEV);
- o.board = channel/NCHAN;
- o.channel = channel%NCHAN;
- if (ioctl (s, CXIOCSETMODE, (caddr_t)&o) < 0)
- err (1, "CXIOCSETMODE");
- close (s);
-}
-
-static void
-printopt(void)
-{
- /* Common channel options */
- /* channel option register 4 */
- printf ("\t");
- printf ("fifo=%d ", o.opt.cor4.thr); /* FIFO threshold */
- printf ("%cctsdown ", o.opt.cor4.cts_zd ? '+' : '-'); /* detect 1 to 0 transition on the CTS */
- printf ("%ccddown ", o.opt.cor4.cd_zd ? '+' : '-'); /* detect 1 to 0 transition on the CD */
- printf ("%cdsrdown ", o.opt.cor4.dsr_zd ? '+' : '-'); /* detect 1 to 0 transition on the DSR */
- printf ("\n");
-
- /* channel option register 5 */
- printf ("\t");
- printf ("rfifo=%d ", o.opt.cor5.rx_thr); /* receive flow control FIFO threshold */
- printf ("%cctsup ", o.opt.cor5.cts_od ? '+' : '-'); /* detect 0 to 1 transition on the CTS */
- printf ("%ccdup ", o.opt.cor5.cd_od ? '+' : '-'); /* detect 0 to 1 transition on the CD */
- printf ("%cdsrup ", o.opt.cor5.dsr_od ? '+' : '-'); /* detect 0 to 1 transition on the DSR */
- printf ("\n");
-
- /* receive clock option register */
- printf ("\t");
- printf ("%s ", o.opt.rcor.encod == ENCOD_NRZ ? "nrz" : /* signal encoding */
- o.opt.rcor.encod == ENCOD_NRZI ? "nrzi" :
- o.opt.rcor.encod == ENCOD_MANCHESTER ? "manchester" : "???");
- printf ("%cdpll ", o.opt.rcor.dpll ? '+' : '-'); /* DPLL enable */
-
- /* transmit clock option register */
- printf ("%clloop ", o.opt.tcor.llm ? '+' : '-'); /* local loopback mode */
- printf ("%cextclock ", o.opt.tcor.ext1x ? '+' : '-'); /* external 1x clock mode */
- printf ("\n");
-
- switch (o.mode) {
- case M_ASYNC: /* async mode options */
- /* channel option register 1 */
- printf ("\t");
- printf ("cs%d ", o.aopt.cor1.charlen+1); /* character length, 5..8 */
- printf ("par%s ", o.aopt.cor1.parity ? "odd" : "even"); /* parity */
- printf ("%cignpar ", o.aopt.cor1.ignpar ? '+' : '-'); /* ignore parity */
- if (o.aopt.cor1.parmode != PARM_NORMAL) /* parity mode */
- printf ("%s ", o.aopt.cor1.parmode == PARM_NOPAR ? "nopar" :
- o.aopt.cor1.parmode == PARM_FORCE ? "forcepar" : "???");
- printf ("\n");
-
- /* channel option register 2 */
- printf ("\t");
- printf ("%cdsr ", o.aopt.cor2.dsrae ? '+' : '-'); /* DSR automatic enable */
- printf ("%ccts ", o.aopt.cor2.ctsae ? '+' : '-'); /* CTS automatic enable */
- printf ("%crts ", o.aopt.cor2.rtsao ? '+' : '-'); /* RTS automatic output enable */
- printf ("%crloop ", o.aopt.cor2.rlm ? '+' : '-'); /* remote loopback mode enable */
- printf ("%cetc ", o.aopt.cor2.etc ? '+' : '-'); /* embedded transmitter cmd enable */
- printf ("%cxon ", o.aopt.cor2.ixon ? '+' : '-'); /* in-band XON/XOFF enable */
- printf ("%cxany ", o.aopt.cor2.ixany ? '+' : '-'); /* XON on any character */
- printf ("\n");
-
- /* option register 3 */
- printf ("\t");
- printf ("%s ", o.aopt.cor3.stopb == STOPB_1 ? "stopb1" : /* stop bit length */
- o.aopt.cor3.stopb == STOPB_15 ? "stopb1.5" :
- o.aopt.cor3.stopb == STOPB_2 ? "stopb2" : "???");
- printf ("%csdt ", o.aopt.cor3.scde ? '+' : '-'); /* special char detection enable */
- printf ("%cflowct ", o.aopt.cor3.flowct ? '+' : '-'); /* flow control transparency mode */
- printf ("%crdt ", o.aopt.cor3.rngde ? '+' : '-'); /* range detect enable */
- printf ("%cexdt ", o.aopt.cor3.escde ? '+' : '-'); /* extended spec. char detect enable */
- printf ("\n");
-
- /* channel option register 6 */
- printf ("\t");
- printf ("%s ", o.aopt.cor6.parerr == PERR_INTR ? "parintr" : /* parity/framing error actions */
- o.aopt.cor6.parerr == PERR_NULL ? "parnull" :
- o.aopt.cor6.parerr == PERR_IGNORE ? "parign" :
- o.aopt.cor6.parerr == PERR_DISCARD ? "pardisc" :
- o.aopt.cor6.parerr == PERR_FFNULL ? "parffnull" : "???");
- printf ("%s ", o.aopt.cor6.brk == BRK_INTR ? "brkintr" : /* action on break condition */
- o.aopt.cor6.brk == BRK_NULL ? "brknull" :
- o.aopt.cor6.brk == BRK_DISCARD ? "brkdisc" : "???");
- printf ("%cinlcr ", o.aopt.cor6.inlcr ? '+' : '-'); /* translate NL to CR on input */
- printf ("%cicrnl ", o.aopt.cor6.icrnl ? '+' : '-'); /* translate CR to NL on input */
- printf ("%cigncr ", o.aopt.cor6.igncr ? '+' : '-'); /* discard CR on input */
- printf ("\n");
-
- /* channel option register 7 */
- printf ("\t");
- printf ("%cocrnl ", o.aopt.cor7.ocrnl ? '+' : '-'); /* translate CR to NL on output */
- printf ("%conlcr ", o.aopt.cor7.onlcr ? '+' : '-'); /* translate NL to CR on output */
- printf ("%cfcerr ", o.aopt.cor7.fcerr ? '+' : '-'); /* process flow ctl err chars enable */
- printf ("%clnext ", o.aopt.cor7.lnext ? '+' : '-'); /* LNext option enable */
- printf ("%cistrip ", o.aopt.cor7.istrip ? '+' : '-'); /* strip 8-bit on input */
- printf ("\n");
-
- printf ("\t");
- printf ("schr1=%s ", symbol (o.aopt.schr1)); /* special character register 1 (XON) */
- printf ("schr2=%s ", symbol (o.aopt.schr2)); /* special character register 2 (XOFF) */
- printf ("schr3=%s ", symbol (o.aopt.schr3)); /* special character register 3 */
- printf ("schr4=%s ", symbol (o.aopt.schr4)); /* special character register 4 */
- printf ("scrl=%s ", symbol (o.aopt.scrl)); /* special character range low */
- printf ("scrh=%s ", symbol (o.aopt.scrh)); /* special character range high */
- printf ("lnext=%s ", symbol (o.aopt.lnxt)); /* LNext character */
- printf ("\n");
- break;
-
- case M_HDLC: /* hdlc mode options */
- /* hdlc channel option register 1 */
- printf ("\t");
- printf ("if%d ", o.hopt.cor1.ifflags); /* number of inter-frame flags sent */
- printf ("%s ", o.hopt.cor1.admode == ADMODE_NOADDR ? "noaddr" : /* addressing mode */
- o.hopt.cor1.admode == ADMODE_4_1 ? "addr1" :
- o.hopt.cor1.admode == ADMODE_2_2 ? "addr2" : "???");
- printf ("%cclrdet ", o.hopt.cor1.clrdet ? '+' : '-'); /* clear detect for X.21 data transfer phase */
- printf ("addrlen%d ", o.hopt.cor1.aflo + 1); /* address field length option */
- printf ("\n");
-
- /* hdlc channel option register 2 */
- printf ("\t");
- printf ("%cdsr ", o.hopt.cor2.dsrae ? '+' : '-'); /* DSR automatic enable */
- printf ("%ccts ", o.hopt.cor2.ctsae ? '+' : '-'); /* CTS automatic enable */
- printf ("%crts ", o.hopt.cor2.rtsao ? '+' : '-'); /* RTS automatic output enable */
- printf ("%ccrcinv ", o.hopt.cor2.crcninv ? '-' : '+'); /* CRC invertion option */
- printf ("%cfcsapd ", o.hopt.cor2.fcsapd ? '+' : '-'); /* FCS append */
- printf ("\n");
-
- /* hdlc channel option register 3 */
- printf ("\t");
- printf ("pad%d ", o.hopt.cor3.padcnt); /* pad character count */
- printf ("idle%s ", o.hopt.cor3.idle ? "mark" : "flag"); /* idle mode */
- printf ("%cfcs ", o.hopt.cor3.nofcs ? '-' : '+'); /* FCS disable */
- printf ("fcs-%s ", o.hopt.cor3.fcspre ? "crc-16" : "v.41"); /* FCS preset */
- printf ("syn=%s ", o.hopt.cor3.syncpat ? "0xAA" : "0x00"); /* send sync pattern */
- printf ("%csyn ", o.hopt.cor3.sndpad ? '+' : '-'); /* send pad characters before flag enable */
- printf ("\n");
-
- printf ("\t");
- printf ("rfar1=0x%02x ", o.hopt.rfar1); /* receive frame address register 1 */
- printf ("rfar2=0x%02x ", o.hopt.rfar2); /* receive frame address register 2 */
- printf ("rfar3=0x%02x ", o.hopt.rfar3); /* receive frame address register 3 */
- printf ("rfar4=0x%02x ", o.hopt.rfar4); /* receive frame address register 4 */
- printf ("crc-%s ", o.hopt.cpsr ? "16" : "v.41"); /* CRC polynomial select */
- printf ("\n");
- break;
-
- case M_BISYNC: /* bisync mode options */
- /* channel option register 1 */
- printf ("\t");
- printf ("cs%d ", o.bopt.cor1.charlen+1); /* character length, 5..8 */
- printf ("par%s ", o.bopt.cor1.parity ? "odd" : "even"); /* parity */
- printf ("%cignpar ", o.bopt.cor1.ignpar ? '+' : '-'); /* ignore parity */
- if (o.bopt.cor1.parmode != PARM_NORMAL) /* parity mode */
- printf ("%s ", o.bopt.cor1.parmode == PARM_NOPAR ? "nopar" :
- o.bopt.cor1.parmode == PARM_FORCE ? "forcepar" : "???");
- printf ("\n");
-
- /* channel option register 2 */
- printf ("\t");
- printf ("syn%d ", o.bopt.cor2.syns+2); /* number of extra SYN chars before a frame */
- printf ("%ccrcinv ", o.bopt.cor2.crcninv ? '-' : '+'); /* CRC invertion option */
- printf ("%s ", o.bopt.cor2.ebcdic ? "ebcdic" : "ascii"); /* use EBCDIC as char set (instead of ASCII) */
- printf ("%cbccapd ", o.bopt.cor2.bcc ? '+' : '-'); /* BCC append enable */
- printf ("%s ", o.bopt.cor2.lrc ? "lrc" : "crc-16"); /* longitudinal redundancy check */
- printf ("\n");
-
- /* channel option register 3 */
- printf ("\t");
- printf ("pad%d ", o.bopt.cor3.padcnt); /* pad character count */
- printf ("idle%s ", o.bopt.cor3.idle ? "mark" : "syn"); /* idle mode */
- printf ("%cfcs ", o.bopt.cor3.nofcs ? '-' : '+'); /* FCS disable */
- printf ("fcs-%s ", o.bopt.cor3.fcspre ? "crc-16" : "v.41"); /* FCS preset */
- printf ("syn=%s ", o.bopt.cor3.padpat ? "0x55" : "0xAA"); /* send sync pattern */
- printf ("%csyn ", o.bopt.cor3.sndpad ? '+' : '-'); /* send pad characters before flag enable */
- printf ("\n");
-
- /* channel option register 6 */
- printf ("\t");
- printf ("specterm=%s ", symbol (o.bopt.cor6.specterm)); /* special termination character */
-
- printf ("crc-%s ", o.bopt.cpsr ? "16" : "v.41"); /* CRC polynomial select */
- printf ("\n");
- break;
-
- case M_X21: /* x.21 mode options */
- /* channel option register 1 */
- printf ("\t");
- printf ("cs%d ", o.xopt.cor1.charlen+1); /* character length, 5..8 */
- printf ("par%s ", o.xopt.cor1.parity ? "odd" : "even"); /* parity */
- printf ("%cignpar ", o.xopt.cor1.ignpar ? '+' : '-'); /* ignore parity */
- if (o.xopt.cor1.parmode != PARM_NORMAL) /* parity mode */
- printf ("%s ", o.xopt.cor1.parmode == PARM_NOPAR ? "nopar" :
- o.xopt.cor1.parmode == PARM_FORCE ? "forcepar" : "???");
- printf ("\n");
-
- /* channel option register 2 */
- printf ("\t");
- printf ("%cetc ", o.xopt.cor2.etc ? '+' : '-'); /* embedded transmitter cmd enable */
-
- /* channel option register 3 */
- printf ("%csdt ", o.xopt.cor3.scde ? '+' : '-'); /* special char detection enable */
- printf ("%cstripsyn ", o.xopt.cor3.stripsyn ? '+' : '-'); /* treat SYN chars as special condition */
- printf ("%cssdt ", o.xopt.cor3.ssde ? '+' : '-'); /* steady state detect enable */
- printf ("syn%c ", o.xopt.cor3.syn ? '1' : '2'); /* the number of SYN chars on receive */
- printf ("\n");
-
- /* channel option register 6 */
- printf ("\t");
- printf ("syn=%s ", symbol (o.xopt.cor6.synchar)); /* syn character */
-
- printf ("schr1=%s ", symbol (o.xopt.schr1)); /* special character register 1 */
- printf ("schr2=%s ", symbol (o.xopt.schr2)); /* special character register 2 */
- printf ("schr3=%s ", symbol (o.xopt.schr3)); /* special character register 3 */
- printf ("\n");
- break;
- }
-}
-
-static void
-printchan(int channel)
-{
- printf ("cx%d (%s) %s", channel, chantype (o.type), chanmode (o.mode));
- if (o.txbaud == o.rxbaud)
- printf (" %lu", o.rxbaud);
- else
- printf (" ospeed=%lu ispeed=%lu", o.txbaud, o.rxbaud);
- if ((o.channel == 0 || o.channel == 8) &&
- (o.type == T_UNIV_V35 || o.type == T_UNIV_RS449))
- printf (" port=%s", o.iftype ? (o.type == T_UNIV_V35 ?
- "v35" : "rs449") : "rs232");
- printf (o.sopt.ext ? " ext" : o.sopt.cisco ? " cisco" : " ppp");
- printf (" %ckeepalive", o.sopt.keepalive ? '+' : '-');
- printf (" %cautorts", o.sopt.norts ? '-' : '+');
- if (*o.master)
- printf (" master=%s", o.master);
- printf ("\n");
- if (aflag)
- printopt ();
-}
-
-static void
-printall(void)
-{
- struct ifconf ifc;
- struct ifreq *ifr;
- char buf[BUFSIZ], *cp;
- int s, c;
-
- s = socket (AF_INET, SOCK_DGRAM, 0);
- if (s < 0)
- err (1, "socket");
- ifc.ifc_len = sizeof (buf);
- ifc.ifc_buf = buf;
- if (ioctl (s, SIOCGIFCONF, (caddr_t)&ifc) < 0)
- err (1, "SIOCGIFCONF");
- close (s);
- s = open (CXDEV, 0);
- if (s < 0)
- err (1, "%s", CXDEV);
-
- ifr = ifc.ifc_req;
-#define max(a,b) ((a)>(b) ? (a) : (b))
-#define size(p) max((p).sa_len, sizeof(p))
- for (cp=buf; cp<buf+ifc.ifc_len; cp+=sizeof(ifr->ifr_name)+size(ifr->ifr_addr)) {
- ifr = (struct ifreq*) cp;
- if (ifr->ifr_addr.sa_family != AF_LINK)
- continue;
- if (strncmp (ifr->ifr_name, "cx", 2) != 0)
- continue;
- c = atoi (ifr->ifr_name + 2);
- o.board = c/NCHAN;
- o.channel = c%NCHAN;
- if (ioctl (s, CXIOCGETMODE, (caddr_t)&o) < 0)
- err (1, "CXIOCGETMODE");
- printchan (c);
- }
- close (s);
-}
-
-static void
-set_interface_type(char *type)
-{
- if (o.channel != 0 && o.channel != 8) {
- printf ("interface option is applicable only for channels 0 and 8\n");
- exit (1);
- }
- if (o.type != T_UNIV_V35 && o.type != T_UNIV_RS449) {
- printf ("interface option is applicable only for universal channels\n");
- exit (1);
- }
- if (! strcasecmp (type, "port=rs232"))
- o.iftype = 0;
- else
- o.iftype = 1;
-}
-
-static void
-set_master(char *ifname)
-{
- if (o.type == T_ASYNC) {
- printf ("master option is not applicable for async channels\n");
- exit (1);
- }
- strcpy (o.master, ifname);
-}
-
-static void
-set_async_opt(char *opt)
-{
- /* channel option register 1 */
- if (! strncasecmp (opt, "cs", 2)) o.aopt.cor1.charlen = atoi (opt + 2) - 1;
- else if (! strcasecmp (opt, "parodd")) o.aopt.cor1.parity = 1;
- else if (! strcasecmp (opt, "pareven")) o.aopt.cor1.parity = 0;
- else if (! strcasecmp (opt, "-ignpar")) o.aopt.cor1.ignpar = 0;
- else if (! strcasecmp (opt, "+ignpar")) o.aopt.cor1.ignpar = 1;
- else if (! strcasecmp (opt, "nopar")) o.aopt.cor1.parmode = PARM_NOPAR;
- else if (! strcasecmp (opt, "forcepar")) o.aopt.cor1.parmode = PARM_FORCE;
-
- /* channel option register 2 */
- else if (! strcasecmp (opt, "-dsr")) o.aopt.cor2.dsrae = 0;
- else if (! strcasecmp (opt, "+dsr")) o.aopt.cor2.dsrae = 1;
- else if (! strcasecmp (opt, "-cts")) o.aopt.cor2.ctsae = 0;
- else if (! strcasecmp (opt, "+cts")) o.aopt.cor2.ctsae = 1;
- else if (! strcasecmp (opt, "-rts")) o.aopt.cor2.rtsao = 0;
- else if (! strcasecmp (opt, "+rts")) o.aopt.cor2.rtsao = 1;
- else if (! strcasecmp (opt, "-rloop")) o.aopt.cor2.rlm = 0;
- else if (! strcasecmp (opt, "+rloop")) o.aopt.cor2.rlm = 1;
- else if (! strcasecmp (opt, "-etc")) o.aopt.cor2.etc = 0;
- else if (! strcasecmp (opt, "+etc")) o.aopt.cor2.etc = 1;
- else if (! strcasecmp (opt, "-ixon")) o.aopt.cor2.ixon = 0;
- else if (! strcasecmp (opt, "+ixon")) o.aopt.cor2.ixon = 1;
- else if (! strcasecmp (opt, "-ixany")) o.aopt.cor2.ixany = 0;
- else if (! strcasecmp (opt, "+ixany")) o.aopt.cor2.ixany = 1;
-
- /* option register 3 */
- else if (! strcasecmp (opt, "stopb1")) o.aopt.cor3.stopb = STOPB_1;
- else if (! strcasecmp (opt, "stopb1.5")) o.aopt.cor3.stopb = STOPB_15;
- else if (! strcasecmp (opt, "stopb2")) o.aopt.cor3.stopb = STOPB_2;
- else if (! strcasecmp (opt, "-sdt")) o.aopt.cor3.scde = 0;
- else if (! strcasecmp (opt, "+sdt")) o.aopt.cor3.scde = 1;
- else if (! strcasecmp (opt, "-flowct")) o.aopt.cor3.flowct = 0;
- else if (! strcasecmp (opt, "+flowct")) o.aopt.cor3.flowct = 1;
- else if (! strcasecmp (opt, "-rdt")) o.aopt.cor3.rngde = 0;
- else if (! strcasecmp (opt, "+rdt")) o.aopt.cor3.rngde = 1;
- else if (! strcasecmp (opt, "-exdt")) o.aopt.cor3.escde = 0;
- else if (! strcasecmp (opt, "+exdt")) o.aopt.cor3.escde = 1;
-
- /* channel option register 6 */
- else if (! strcasecmp (opt, "parintr")) o.aopt.cor6.parerr = PERR_INTR;
- else if (! strcasecmp (opt, "parnull")) o.aopt.cor6.parerr = PERR_NULL;
- else if (! strcasecmp (opt, "parign")) o.aopt.cor6.parerr = PERR_IGNORE;
- else if (! strcasecmp (opt, "pardisc")) o.aopt.cor6.parerr = PERR_DISCARD;
- else if (! strcasecmp (opt, "parffnull")) o.aopt.cor6.parerr = PERR_FFNULL;
- else if (! strcasecmp (opt, "brkintr")) o.aopt.cor6.brk = BRK_INTR;
- else if (! strcasecmp (opt, "brknull")) o.aopt.cor6.brk = BRK_NULL;
- else if (! strcasecmp (opt, "brkdisc")) o.aopt.cor6.brk = BRK_DISCARD;
- else if (! strcasecmp (opt, "-inlcr")) o.aopt.cor6.inlcr = 0;
- else if (! strcasecmp (opt, "+inlcr")) o.aopt.cor6.inlcr = 1;
- else if (! strcasecmp (opt, "-icrnl")) o.aopt.cor6.icrnl = 0;
- else if (! strcasecmp (opt, "+icrnl")) o.aopt.cor6.icrnl = 1;
- else if (! strcasecmp (opt, "-igncr")) o.aopt.cor6.igncr = 0;
- else if (! strcasecmp (opt, "+igncr")) o.aopt.cor6.igncr = 1;
-
- /* channel option register 7 */
- else if (! strcasecmp (opt, "-ocrnl")) o.aopt.cor7.ocrnl = 0;
- else if (! strcasecmp (opt, "+ocrnl")) o.aopt.cor7.ocrnl = 1;
- else if (! strcasecmp (opt, "-onlcr")) o.aopt.cor7.onlcr = 0;
- else if (! strcasecmp (opt, "+onlcr")) o.aopt.cor7.onlcr = 1;
- else if (! strcasecmp (opt, "-fcerr")) o.aopt.cor7.fcerr = 0;
- else if (! strcasecmp (opt, "+fcerr")) o.aopt.cor7.fcerr = 1;
- else if (! strcasecmp (opt, "-lnext")) o.aopt.cor7.lnext = 0;
- else if (! strcasecmp (opt, "+lnext")) o.aopt.cor7.lnext = 1;
- else if (! strcasecmp (opt, "-istrip")) o.aopt.cor7.istrip = 0;
- else if (! strcasecmp (opt, "+istrip")) o.aopt.cor7.istrip = 1;
-
- else if (! strncasecmp (opt, "schr1=", 6)) o.aopt.schr1 = atosym (opt+6);
- else if (! strncasecmp (opt, "schr2=", 6)) o.aopt.schr2 = atosym (opt+6);
- else if (! strncasecmp (opt, "schr3=", 6)) o.aopt.schr3 = atosym (opt+6);
- else if (! strncasecmp (opt, "schr4=", 6)) o.aopt.schr4 = atosym (opt+6);
- else if (! strncasecmp (opt, "scrl=", 5)) o.aopt.scrl = atosym (opt+5);
- else if (! strncasecmp (opt, "scrh=", 5)) o.aopt.scrh = atosym (opt+5);
- else if (! strncasecmp (opt, "lnext=", 6)) o.aopt.lnxt = atosym (opt+6);
- else
- usage ();
-}
-
-static void
-set_hdlc_opt(char *opt)
-{
- /* hdlc channel option register 1 */
- if (! strncasecmp (opt, "if", 2)) o.hopt.cor1.ifflags = atoi (opt + 2);
- else if (! strcasecmp (opt, "noaddr")) o.hopt.cor1.admode = ADMODE_NOADDR;
- else if (! strcasecmp (opt, "addr1")) o.hopt.cor1.admode = ADMODE_4_1;
- else if (! strcasecmp (opt, "addr2")) o.hopt.cor1.admode = ADMODE_2_2;
- else if (! strcasecmp (opt, "-clrdet")) o.hopt.cor1.clrdet = 0;
- else if (! strcasecmp (opt, "+clrdet")) o.hopt.cor1.clrdet = 1;
- else if (! strcasecmp (opt, "addrlen1")) o.hopt.cor1.aflo = 0;
- else if (! strcasecmp (opt, "addrlen2")) o.hopt.cor1.aflo = 1;
-
- /* hdlc channel option register 2 */
- else if (! strcasecmp (opt, "-dsr")) o.hopt.cor2.dsrae = 0;
- else if (! strcasecmp (opt, "+dsr")) o.hopt.cor2.dsrae = 1;
- else if (! strcasecmp (opt, "-cts")) o.hopt.cor2.ctsae = 0;
- else if (! strcasecmp (opt, "+cts")) o.hopt.cor2.ctsae = 1;
- else if (! strcasecmp (opt, "-rts")) o.hopt.cor2.rtsao = 0;
- else if (! strcasecmp (opt, "+rts")) o.hopt.cor2.rtsao = 1;
- else if (! strcasecmp (opt, "-fcsapd")) o.hopt.cor2.fcsapd = 0;
- else if (! strcasecmp (opt, "+fcsapd")) o.hopt.cor2.fcsapd = 1;
- else if (! strcasecmp (opt, "-crcinv")) o.hopt.cor2.crcninv = 1;
- else if (! strcasecmp (opt, "+crcinv")) o.hopt.cor2.crcninv = 0;
-
- /* hdlc channel option register 3 */
- else if (! strncasecmp (opt, "pad", 3)) o.hopt.cor3.padcnt = atoi (opt + 3);
- else if (! strcasecmp (opt, "idlemark")) o.hopt.cor3.idle = 1;
- else if (! strcasecmp (opt, "idleflag")) o.hopt.cor3.idle = 0;
- else if (! strcasecmp (opt, "-fcs")) o.hopt.cor3.nofcs = 1;
- else if (! strcasecmp (opt, "+fcs")) o.hopt.cor3.nofcs = 0;
- else if (! strcasecmp (opt, "fcs-crc-16")) o.hopt.cor3.fcspre = 1;
- else if (! strcasecmp (opt, "fcs-v.41")) o.hopt.cor3.fcspre = 0;
- else if (! strcasecmp (opt, "syn=0xaa")) o.hopt.cor3.syncpat = 1;
- else if (! strcasecmp (opt, "syn=0x00")) o.hopt.cor3.syncpat = 0;
- else if (! strcasecmp (opt, "-syn")) o.hopt.cor3.sndpad = 0;
- else if (! strcasecmp (opt, "+syn")) o.hopt.cor3.sndpad = 1;
-
- else if (! strncasecmp (opt, "rfar1=", 6)) o.hopt.rfar1 = atoi (opt + 6);
- else if (! strncasecmp (opt, "rfar2=", 6)) o.hopt.rfar2 = atoi (opt + 6);
- else if (! strncasecmp (opt, "rfar3=", 6)) o.hopt.rfar3 = atoi (opt + 6);
- else if (! strncasecmp (opt, "rfar4=", 6)) o.hopt.rfar4 = atoi (opt + 6);
- else if (! strcasecmp (opt, "crc-16")) o.hopt.cpsr = 1;
- else if (! strcasecmp (opt, "crc-v.41")) o.hopt.cpsr = 0;
- else usage ();
-}
-
-static void
-set_bisync_opt(char *opt __unused)
-{
- usage ();
-}
-
-static void
-set_x21_opt(char *opt __unused)
-{
- usage ();
-}
-
-int
-main(int argc, char **argv)
-{
- int channel;
-
- for (--argc, ++argv; argc>0 && **argv=='-'; --argc, ++argv)
- if (! strcasecmp (*argv, "-a"))
- ++aflag;
- else if (! strcasecmp (*argv, "-s"))
- ++sflag;
- else
- usage ();
-
- if (argc <= 0) {
- if (sflag)
- printallstats ();
- else
- printall ();
- return (0);
- }
-
- if (argv[0][0]=='c' && argv[0][1]=='x')
- *argv += 2;
- if (**argv<'0' || **argv>'9')
- usage ();
- channel = atoi (*argv);
- --argc, ++argv;
-
- if (sflag) {
- if (printstats (channel, 1) < 0)
- printf ("channel cx%d not available\n", channel);
- return (0);
- }
-
- getchan (channel);
-
- if (argc <= 0) {
- printchan (channel);
- return (0);
- }
-
- for (; argc>0; --argc, ++argv)
- if (**argv == '(')
- continue;
- else if (! strncasecmp (*argv, "ispeed=", 7))
- o.rxbaud = atoi (*argv+7);
- else if (! strncasecmp (*argv, "ospeed=", 7))
- o.txbaud = atoi (*argv+7);
- else if (! strcasecmp (*argv, "async"))
- o.mode = M_ASYNC;
- else if (! strcasecmp (*argv, "hdlc"))
- o.mode = M_HDLC;
- else if (! strcasecmp (*argv, "bisync") ||
- ! strcasecmp (*argv, "bsc"))
- o.mode = M_BISYNC;
- else if (! strcasecmp (*argv, "x.21") ||
- ! strcasecmp (*argv, "x21"))
- o.mode = M_X21;
- else if (**argv>='0' && **argv<='9')
- o.txbaud = o.rxbaud = atoi (*argv);
- else if (! strcasecmp (*argv, "cisco")) {
- o.sopt.cisco = 1;
- o.sopt.ext = 0;
- } else if (! strcasecmp (*argv, "ppp")) {
- o.sopt.cisco = 0;
- o.sopt.ext = 0;
- } else if (! strcasecmp (*argv, "ext"))
- o.sopt.ext = 1;
- else if (! strcasecmp (*argv, "+keepalive"))
- o.sopt.keepalive = 1;
- else if (! strcasecmp (*argv, "-keepalive"))
- o.sopt.keepalive = 0;
- else if (! strcasecmp (*argv, "+autorts"))
- o.sopt.norts = 0;
- else if (! strcasecmp (*argv, "-autorts"))
- o.sopt.norts = 1;
- else if (! strcasecmp (*argv, "port=rs232") ||
- ! strcasecmp (*argv, "port=rs449") ||
- ! strcasecmp (*argv, "port=v35"))
- set_interface_type (*argv);
- else if (! strncasecmp (*argv, "master=",7))
- set_master (*argv+7);
-
- /*
- * Common channel options
- */
- /* channel option register 4 */
- else if (! strcasecmp (*argv, "-ctsdown"))
- o.opt.cor4.cts_zd = 0;
- else if (! strcasecmp (*argv, "+ctsdown"))
- o.opt.cor4.cts_zd = 1;
- else if (! strcasecmp (*argv, "-cddown"))
- o.opt.cor4.cd_zd = 0;
- else if (! strcasecmp (*argv, "+cddown"))
- o.opt.cor4.cd_zd = 1;
- else if (! strcasecmp (*argv, "-dsrdown"))
- o.opt.cor4.dsr_zd = 0;
- else if (! strcasecmp (*argv, "+dsrdown"))
- o.opt.cor4.dsr_zd = 1;
- else if (! strncasecmp (*argv, "fifo=", 5))
- o.opt.cor4.thr = atoi (*argv + 5);
-
- /* channel option register 5 */
- else if (! strcasecmp (*argv, "-ctsup"))
- o.opt.cor5.cts_od = 0;
- else if (! strcasecmp (*argv, "+ctsup"))
- o.opt.cor5.cts_od = 1;
- else if (! strcasecmp (*argv, "-cdup"))
- o.opt.cor5.cd_od = 0;
- else if (! strcasecmp (*argv, "+cdup"))
- o.opt.cor5.cd_od = 1;
- else if (! strcasecmp (*argv, "-dsrup"))
- o.opt.cor5.dsr_od = 0;
- else if (! strcasecmp (*argv, "+dsrup"))
- o.opt.cor5.dsr_od = 1;
- else if (! strncasecmp (*argv, "rfifo=", 6))
- o.opt.cor5.rx_thr = atoi (*argv + 6);
-
- /* receive clock option register */
- else if (! strcasecmp (*argv, "nrz"))
- o.opt.rcor.encod = ENCOD_NRZ;
- else if (! strcasecmp (*argv, "nrzi"))
- o.opt.rcor.encod = ENCOD_NRZI;
- else if (! strcasecmp (*argv, "manchester"))
- o.opt.rcor.encod = ENCOD_MANCHESTER;
- else if (! strcasecmp (*argv, "-dpll"))
- o.opt.rcor.dpll = 0;
- else if (! strcasecmp (*argv, "+dpll"))
- o.opt.rcor.dpll = 1;
-
- /* transmit clock option register */
- else if (! strcasecmp (*argv, "-lloop"))
- o.opt.tcor.llm = 0;
- else if (! strcasecmp (*argv, "+lloop"))
- o.opt.tcor.llm = 1;
- else if (! strcasecmp (*argv, "-extclock"))
- o.opt.tcor.ext1x = 0;
- else if (! strcasecmp (*argv, "+extclock"))
- o.opt.tcor.ext1x = 1;
-
- /*
- * Mode dependent channel options
- */
- else switch (o.mode) {
- case M_ASYNC: set_async_opt (*argv); break;
- case M_HDLC: set_hdlc_opt (*argv); break;
- case M_BISYNC: set_bisync_opt (*argv); break;
- case M_X21: set_x21_opt (*argv); break;
- }
-
- setchan (channel);
- return (0);
-}
diff --git a/sbin/i386/fdisk/Makefile b/sbin/i386/fdisk/Makefile
deleted file mode 100644
index bcedf0d..0000000
--- a/sbin/i386/fdisk/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-# $FreeBSD$
-
-PROG= fdisk
-MAN= fdisk.8
-
-.include <bsd.prog.mk>
diff --git a/sbin/i386/fdisk/fdisk.8 b/sbin/i386/fdisk/fdisk.8
deleted file mode 100644
index 03e2c7a..0000000
--- a/sbin/i386/fdisk/fdisk.8
+++ /dev/null
@@ -1,433 +0,0 @@
-.\" $FreeBSD$
-.\"
-.Dd October 4, 1996
-.Dt FDISK 8
-.Os
-.Sh NAME
-.Nm fdisk
-.Nd PC partition table maintenance program
-.Sh SYNOPSIS
-.Nm
-.Op Fl BIaistu
-.Op Fl b Ar bootcode
-.Op Fl 1234
-.Op Ar disk
-.Bl -tag -width time
-.Nm
-.Fl f Ar configfile
-.Op Fl itv
-.Op Ar disk
-.Sh PROLOGUE
-In order for the BIOS to boot the kernel,
-certain conventions must be adhered to.
-Sector 0 of the disk must contain boot code,
-a partition table,
-and a magic number.
-BIOS partitions can be used to break the disk up into several pieces.
-The BIOS brings in sector 0 and verifies the magic number. The sector
-0 boot code then searches the partition table to determine which
-partition is marked
-.Em active .
-This boot code then brings in the bootstrap from the
-.Em active
-partition and, if marked bootable, runs it.
-Under DOS,
-you can have one or more partitions with one
-.Em active .
-The DOS
-.Nm
-program can be used to divide space on the disk into partitions and set one
-.Em active .
-.Sh DESCRIPTION
-The
-.Fx
-program
-.Nm
-serves a similar purpose to the DOS program. The first form is used to
-display partition information or to interactively edit the partition
-table. The second is used to write a partition table using a
-.Ar configfile
-and is designed to be used by other scripts/programs.
-.Pp
-Options are:
-.It Fl a
-Change the active partition only. Ignored if
-.Fl f
-is given.
-.It Fl b Ar bootcode
-Get the boot code from the file
-.Ar bootcode .
-Default is
-.Pa /boot/mbr .
-.It Fl B
-Reinitialize the boot code contained in sector 0 of the disk. Ignored
-if
-.Fl f
-is given.
-.It Fl f Ar configfile
-Set partition values using the file
-.Ar configfile .
-The
-.Ar configfile
-always modifies existing partitions, unless
-.Fl i
-is also given, in which case all existing partitions are deleted (marked
-as "unused") before the
-.Ar configfile
-is read. The
-.Ar configfile
-can be "-", in which case
-.Ar stdin
-is read. See
-.Sx CONFIGURATION FILE ,
-below, for file syntax.
-.Pp
-.Em WARNING :
-when
-.Fl f
-is used, you are not asked if you really want to write the partition
-table (as you are in the interactive mode). Use with caution!
-.It Fl i
-Initialize sector 0 of the disk. This implies
-.Fl u ,
-unless
-.Fl f
-is given.
-.It Fl I
-Initialize the contents of sector 0
-with one
-.Fx
-slice covering the entire disk.
-.It Fl s
-Print summary information and exit.
-.It Fl t
-Test mode; do not write partition values. Generally used with the
-.Fl f
-option to see what would be written to the partition table. Implies
-.Fl v .
-.It Fl u
-Is used for updating (editing) sector 0 of the disk. Ignored if
-.Fl f
-is given.
-.It Fl v
-Be verbose. When
-.Fl f
-is used,
-.Nm
-prints out the partition table that is written to the disk.
-.It Fl 1234
-Operate on a single fdisk entry only. Ignored if
-.Fl f
-is given.
-.El
-.Pp
-The final disk name can be provided as a
-.Sq bare
-disk name only, e.g.\&
-.Ql da0 ,
-or as a full pathname.
-If omitted,
-.Nm
-tries to figure out the default disk device name from the
-mounted root device.
-.Pp
-When called with no arguments, it prints the sector 0 partition table.
-An example follows:
-.Bd -literal
- ******* Working on device /dev/ad0 *******
- parameters extracted from in-core disklabel are:
- cylinders=769 heads=15 sectors/track=33 (495 blks/cyl)
-
- parameters to be used for BIOS calculations are:
- cylinders=769 heads=15 sectors/track=33 (495 blks/cyl)
-
- Warning: BIOS sector numbering starts with sector 1
- Information from DOS bootblock is:
- The data for partition 1 is:
- sysid 165,(FreeBSD/NetBSD/386BSD)
- start 495, size 380160 (185 Meg), flag 0
- beg: cyl 1/ sector 1/ head 0;
- end: cyl 768/ sector 33/ head 14
- The data for partition 2 is:
- sysid 164,(unknown)
- start 378180, size 2475 (1 Meg), flag 0
- beg: cyl 764/ sector 1/ head 0;
- end: cyl 768/ sector 33/ head 14
- The data for partition 3 is:
- <UNUSED>
- The data for partition 4 is:
- sysid 99,(ISC UNIX, other System V/386, GNU HURD or Mach)
- start 380656, size 224234 (109 Meg), flag 80
- beg: cyl 769/ sector 2/ head 0;
- end: cyl 197/ sector 33/ head 14
-.Ed
-.Pp
-The disk is divided into three partitions that happen to fill the disk.
-The second partition overlaps the end of the first.
-(Used for debugging purposes)
-.Bl -tag -width "cyl, sector and head"
-.It Em "sysid"
-is used to label the partition.
-.Fx
-reserves the
-magic number 165 decimal (A5 in hex).
-.It Em start No and Em size
-fields provide the start address
-and size of a partition in sectors.
-.It Em "flag 80"
-specifies that this is the active partition.
-.It Em cyl , sector No and Em head
-fields are used to specify the beginning address
-and end address for the partition.
-.It Em Note :
-these numbers are calculated using BIOS's understanding of the disk geometry
-and saved in the bootblock.
-.El
-.Pp
-The flags
-.Fl i
-or
-.Fl u
-are used to indicate that the partition data is to be updated, unless the
-.Fl f
-option is used. If the
-.Fl f
-option is not used, the
-.Nm
-program will enter a conversational mode.
-This mode is designed not to change any data unless you explicitly tell it to.
-.Nm Fdisk
-selects defaults for its questions to guarantee the above behavior.
-.Pp
-It displays each partition
-and ask if you want to edit it.
-If you say yes,
-it will step through each field showing the old value
-and asking for a new one.
-When you are done with a partition,
-.Nm
-will display it and ask if it is correct.
-.Nm Fdisk
-will then proceed to the next entry.
-.Pp
-Getting the
-.Em cyl , sector ,
-and
-.Em head
-fields correct is tricky.
-So by default,
-they will be calculated for you;
-you can specify them if you choose.
-.Pp
-After all the partitions are processed,
-you are given the option to change the
-.Em active
-partition.
-Finally,
-when the all the data for the first sector has been accumulated,
-you are asked if you really want to rewrite sector 0.
-Only if you answer yes,
-will the data be written to disk.
-.Pp
-The difference between the
-.Fl u
-flag and
-.Fl i
-flag is that
-the
-.Fl u
-flag just edits the fields as they appear on the disk.
-While the
-.Fl i
-flag is used to "initialize" sector 0;
-it will setup the last BIOS partition to use the whole disk for
-.Fx ;
-and make it active.
-.Sh NOTES
-The automatic calculation of starting cylinder etc. uses
-a set of figures that represent what the BIOS thinks is the
-geometry of the drive.
-These figures are by default taken from the incore disklabel,
-but the program initially gives you an opportunity to change them.
-This allows the user to create a bootblock that can work with drives
-that use geometry translation under the BIOS.
-.Pp
-If you hand craft your disk layout,
-please make sure that the
-.Fx
-partition starts on a cylinder boundary.
-A number of decisions made later may assume this.
-(This might not be necessary later.)
-.Pp
-Editing an existing partition will most likely cause you to
-lose all the data in that partition.
-.Pp
-You should run this program interactively once or twice to see how it
-works. This is completely safe as long as you answer the last question
-in the negative. There are subtleties that the program detects that are
-not fully explained in this manual page.
-.Sh CONFIGURATION FILE
-When the
-.Fl f
-option is given, a disk's partition table can be written using values
-from a
-.Ar configfile .
-The syntax of this file is very simple. Each line is either a comment or
-a specification, and whitespace (except for newlines) are ignored:
-.Bl -tag -width Ds
-.It Xo
-.Ic #
-.Ar comment ...
-.Xc
-Lines beginning with a "#" are comments and are ignored.
-.It Xo
-.Ic g
-.Ar spec1
-.Ar spec2
-.Ar spec3
-.Xc
-Set the BIOS geometry used in partition calculations. There must be
-three values specified, with a letter preceding each number:
-.Bl -tag -width Ds
-.Sm off
-.It Cm c Ar num
-.Sm on
-Set the number of cylinders to
-.Ar num .
-.Sm off
-.It Cm h Ar num
-.Sm on
-Set the number of heads to
-.Ar num .
-.Sm off
-.It Cm s Ar num
-.Sm on
-Set the number of sectors/track to
-.Ar num .
-.El
-.Pp
-These specs can occur in any order, as the leading letter determines
-which value is which; however, all three must be specified.
-.Pp
-This line must occur before any lines that specify partition
-information.
-.Pp
-It is an error if the following is not true:
-.Bd -literal -offset indent
-1 <= number of cylinders
-1 <= number of heads <= 256
-1 <= number of sectors/track < 64
-.Ed
-.Pp
-The number of cylinders should be less than or equal to 1024, but this
-is not enforced, although a warning will be output. Note that bootable
-.Fx
-partitions (the "/" filesystem) must lie completely within the
-first 1024 cylinders; if this is not true, booting may fail.
-Non-bootable partitions do not have this restriction.
-.Pp
-Example (all of these are equivalent), for a disk with 1019 cylinders,
-39 heads, and 63 sectors:
-.Bd -literal -offset indent
-g c1019 h39 s63
-g h39 c1019 s63
-g s63 h39 c1019
-.Ed
-.It Xo
-.Ic p
-.Ar partition
-.Ar type
-.Ar start
-.Ar length
-.Xc
-Set the partition given by
-.Ar partition
-(1-4) to type
-.Ar type ,
-starting at sector
-.Ar start
-for
-.Ar length
-sectors.
-.Pp
-Only those partitions explicitly mentioned by these lines are modified;
-any partition not referenced by a "p" line will not be modified.
-However, if an invalid partition table is present, or the
-.Fl i
-option is specified, all existing partition entries will be cleared
-(marked as unused), and these "p" lines will have to be used to
-explicitly set partition information. If multiple partitions need to be
-set, multiple "p" lines must be specified; one for each partition.
-.Pp
-These partition lines must occur after any geometry specification lines,
-if one is present.
-.Pp
-The
-.Ar type
-is 165 for
-.Fx
-partitions. Specifying a partition type of zero is
-the same as clearing the partition and marking it as unused; however,
-dummy values (such as "0") must still be specified for
-.Ar start
-and
-.Ar length .
-.Pp
-Note: the start offset will be rounded upwards to a head boundary if
-necessary, and the end offset will be rounded downwards to a cylinder
-boundary if necessary.
-.Pp
-Example: to clear partition 4 and mark it as unused:
-.Bd -literal -offset indent
-p 4 0 0 0
-.Ed
-.Pp
-Example: to set partition 1 to a
-.Fx
-partition, starting at sector 1
-for 2503871 sectors (note: these numbers will be rounded upwards and
-downwards to correspond to head and cylinder boundaries):
-.Pp
-.Bd -literal -offset indent
-p 1 165 1 2503871
-.Ed
-.Pp
-.It Xo
-.Ic a
-.Ar partition
-.Xc
-Make
-.Ar partition
-the active partition. Can occur anywhere in the config file, but only
-one must be present.
-.Pp
-Example: to make partition 1 the active partition:
-.Bd -literal -offset indent
-a 1
-.Ed
-.El
-.Sh FILES
-.Bl -tag -width /boot/mbr -compact
-.It Pa /boot/mbr
-The default boot code
-.El
-.Sh SEE ALSO
-.Xr boot0cfg 8 ,
-.Xr disklabel 8
-.Sh BUGS
-The default boot code will not necessarily handle all partition types
-correctly, in particular those introduced since MS-DOS 6.x.
-.Pp
-The entire program should be made more user-friendly.
-.Pp
-Throughout this man page, the term
-.Sq partition
-is used where it should actually be
-.Sq slice ,
-in order to conform with the terms used elsewhere.
-.Pp
-You cannot use this command to completely dedicate a disk to
-.Fx .
-The
-.Xr disklabel 8
-command must be used for this.
diff --git a/sbin/i386/fdisk/fdisk.c b/sbin/i386/fdisk/fdisk.c
deleted file mode 100644
index 35d4ee4..0000000
--- a/sbin/i386/fdisk/fdisk.c
+++ /dev/null
@@ -1,1509 +0,0 @@
-/*
- * Mach Operating System
- * Copyright (c) 1992 Carnegie Mellon University
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
- * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie Mellon
- * the rights to redistribute these changes.
- */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-#include <sys/disklabel.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/mount.h>
-#include <ctype.h>
-#include <fcntl.h>
-#include <err.h>
-#include <errno.h>
-#include <paths.h>
-#include <regex.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-int iotest;
-
-#define LBUF 100
-static char lbuf[LBUF];
-
-#define MBRSIGOFF 510
-
-/*
- *
- * Ported to 386bsd by Julian Elischer Thu Oct 15 20:26:46 PDT 1992
- *
- * 14-Dec-89 Robert Baron (rvb) at Carnegie-Mellon University
- * Copyright (c) 1989 Robert. V. Baron
- * Created.
- */
-
-#define Decimal(str, ans, tmp) if (decimal(str, &tmp, ans)) ans = tmp
-#define Hex(str, ans, tmp) if (hex(str, &tmp, ans)) ans = tmp
-#define String(str, ans, len) {char *z = ans; char **dflt = &z; if (string(str, dflt)) strncpy(ans, *dflt, len); }
-
-#define RoundCyl(x) ((((x) + cylsecs - 1) / cylsecs) * cylsecs)
-
-#define MAX_SEC_SIZE 2048 /* maximum section size that is supported */
-#define MIN_SEC_SIZE 512 /* the sector size to start sensing at */
-int secsize = 0; /* the sensed sector size */
-
-char *disk;
-
-struct disklabel disklabel; /* disk parameters */
-
-int cyls, sectors, heads, cylsecs, disksecs;
-
-struct mboot
-{
- unsigned char padding[2]; /* force the longs to be long aligned */
- unsigned char *bootinst; /* boot code */
- off_t bootinst_size;
- struct dos_partition parts[4];
-};
-struct mboot mboot = {{0}, NULL, 0};
-
-#define ACTIVE 0x80
-#define BOOT_MAGIC 0xAA55
-
-int dos_cyls;
-int dos_heads;
-int dos_sectors;
-int dos_cylsecs;
-
-#define DOSSECT(s,c) ((s & 0x3f) | ((c >> 2) & 0xc0))
-#define DOSCYL(c) (c & 0xff)
-static int partition = -1;
-
-
-#define MAX_ARGS 10
-
-static int current_line_number;
-
-static int geom_processed = 0;
-static int part_processed = 0;
-static int active_processed = 0;
-
-
-typedef struct cmd {
- char cmd;
- int n_args;
- struct arg {
- char argtype;
- int arg_val;
- } args[MAX_ARGS];
-} CMD;
-
-
-static int B_flag = 0; /* replace boot code */
-static int I_flag = 0; /* use entire disk for FreeBSD */
-static int a_flag = 0; /* set active partition */
-static char *b_flag = NULL; /* path to boot code */
-static int i_flag = 0; /* replace partition data */
-static int u_flag = 0; /* update partition data */
-static int s_flag = 0; /* Print a summary and exit */
-static int t_flag = 0; /* test only, if f_flag is given */
-static char *f_flag = NULL; /* Read config info from file */
-static int v_flag = 0; /* Be verbose */
-
-struct part_type
-{
- unsigned char type;
- char *name;
-}part_types[] =
-{
- {0x00, "unused"}
- ,{0x01, "Primary DOS with 12 bit FAT"}
- ,{0x02, "XENIX / filesystem"}
- ,{0x03, "XENIX /usr filesystem"}
- ,{0x04, "Primary DOS with 16 bit FAT (<= 32MB)"}
- ,{0x05, "Extended DOS"}
- ,{0x06, "Primary 'big' DOS (> 32MB)"}
- ,{0x07, "OS/2 HPFS, NTFS, QNX-2 (16 bit) or Advanced UNIX"}
- ,{0x08, "AIX filesystem"}
- ,{0x09, "AIX boot partition or Coherent"}
- ,{0x0A, "OS/2 Boot Manager or OPUS"}
- ,{0x0B, "DOS or Windows 95 with 32 bit FAT"}
- ,{0x0C, "DOS or Windows 95 with 32 bit FAT, LBA"}
- ,{0x0E, "Primary 'big' DOS (> 32MB, LBA)"}
- ,{0x0F, "Extended DOS, LBA"}
- ,{0x10, "OPUS"}
- ,{0x39, "plan9"}
- ,{0x40, "VENIX 286"}
- ,{0x4D, "QNX 4.2 Primary"}
- ,{0x4E, "QNX 4.2 Secondary"}
- ,{0x4F, "QNX 4.2 Tertiary"}
- ,{0x50, "DM"}
- ,{0x51, "DM"}
- ,{0x52, "CP/M or Microport SysV/AT"}
- ,{0x56, "GB"}
- ,{0x61, "Speed"}
- ,{0x63, "ISC UNIX, other System V/386, GNU HURD or Mach"}
- ,{0x64, "Novell Netware 2.xx"}
- ,{0x65, "Novell Netware 3.xx"}
- ,{0x75, "PCIX"}
- ,{0x80, "Minix 1.1 ... 1.4a"}
- ,{0x81, "Minix 1.4b ... 1.5.10"}
- ,{0x82, "Linux swap or Solaris x86"}
- ,{0x83, "Linux filesystem"}
- ,{0x93, "Amoeba filesystem"}
- ,{0x94, "Amoeba bad block table"}
- ,{0x9F, "BSD/OS"}
- ,{0xA0, "Suspend to Disk"}
- ,{0xA5, "FreeBSD/NetBSD/386BSD"}
- ,{0xA6, "OpenBSD"}
- ,{0xA7, "NEXTSTEP"}
- ,{0xA9, "NetBSD"}
- ,{0xB7, "BSDI BSD/386 filesystem"}
- ,{0xB8, "BSDI BSD/386 swap"}
- ,{0xDB, "Concurrent CPM or C.DOS or CTOS"}
- ,{0xE1, "Speed"}
- ,{0xE3, "Speed"}
- ,{0xE4, "Speed"}
- ,{0xEE, "EFI GPT"}
- ,{0xEF, "EFI System Partition"}
- ,{0xF1, "Speed"}
- ,{0xF2, "DOS 3.3+ Secondary"}
- ,{0xF4, "Speed"}
- ,{0xFF, "BBT (Bad Blocks Table)"}
-};
-
-static void print_s0(int which);
-static void print_part(int i);
-static void init_sector0(unsigned long start);
-static void init_boot(void);
-static void change_part(int i);
-static void print_params();
-static void change_active(int which);
-static void change_code();
-static void get_params_to_use();
-static char *get_rootdisk(void);
-static void dos(struct dos_partition *partp);
-static int open_disk(int u_flag);
-static ssize_t read_disk(off_t sector, void *buf);
-static ssize_t write_disk(off_t sector, void *buf);
-static int get_params();
-static int read_s0();
-static int write_s0();
-static int ok(char *str);
-static int decimal(char *str, int *num, int deflt);
-static char *get_type(int type);
-static int read_config(char *config_file);
-static void reset_boot(void);
-static int sanitize_partition(struct dos_partition *);
-static void usage(void);
-#if 0
-static int hex(char *str, int *num, int deflt);
-static int string(char *str, char **ans);
-#endif
-
-
-int
-main(int argc, char *argv[])
-{
- struct stat sb;
- int c, i;
-
- while ((c = getopt(argc, argv, "BIab:f:istuv1234")) != -1)
- switch (c) {
- case 'B':
- B_flag = 1;
- break;
- case 'I':
- I_flag = 1;
- break;
- case 'a':
- a_flag = 1;
- break;
- case 'b':
- b_flag = optarg;
- break;
- case 'f':
- f_flag = optarg;
- break;
- case 'i':
- i_flag = 1;
- break;
- case 's':
- s_flag = 1;
- break;
- case 't':
- t_flag = 1;
- break;
- case 'u':
- u_flag = 1;
- break;
- case 'v':
- v_flag = 1;
- break;
- case '1':
- case '2':
- case '3':
- case '4':
- partition = c - '0';
- break;
- default:
- usage();
- }
- if (f_flag || i_flag)
- u_flag = 1;
- if (t_flag)
- v_flag = 1;
- argc -= optind;
- argv += optind;
-
- if (argc == 0) {
- disk = get_rootdisk();
- } else {
- if (stat(argv[0], &sb) == 0) {
- /* OK, full pathname given */
- disk = argv[0];
- } else if (errno == ENOENT) {
- /* Try prepending "/dev" */
- if ((disk = malloc(strlen(argv[0]) + strlen(_PATH_DEV) +
- 1)) == NULL)
- errx(1, "out of memory");
- strcpy(disk, _PATH_DEV);
- strcat(disk, argv[0]);
- } else {
- /* other stat error, let it fail below */
- disk = argv[0];
- }
- }
- if (open_disk(u_flag) < 0)
- err(1, "cannot open disk %s", disk);
-
- /* (abu)use mboot.bootinst to probe for the sector size */
- if ((mboot.bootinst = malloc(MAX_SEC_SIZE)) == NULL)
- err(1, "cannot allocate buffer to determine disk sector size");
- read_disk(0, mboot.bootinst);
- free(mboot.bootinst);
- mboot.bootinst = NULL;
-
- if (s_flag)
- {
- int i;
- struct dos_partition *partp;
-
- if (read_s0())
- err(1, "read_s0");
- printf("%s: %d cyl %d hd %d sec\n", disk, dos_cyls, dos_heads,
- dos_sectors);
- printf("Part %11s %11s Type Flags\n", "Start", "Size");
- for (i = 0; i < NDOSPART; i++) {
- partp = ((struct dos_partition *) &mboot.parts) + i;
- if (partp->dp_start == 0 && partp->dp_size == 0)
- continue;
- printf("%4d: %11lu %11lu 0x%02x 0x%02x\n", i + 1,
- (u_long) partp->dp_start,
- (u_long) partp->dp_size, partp->dp_typ,
- partp->dp_flag);
- }
- exit(0);
- }
-
- printf("******* Working on device %s *******\n",disk);
-
- if (I_flag)
- {
- struct dos_partition *partp;
-
- read_s0();
- reset_boot();
- partp = (struct dos_partition *) (&mboot.parts[0]);
- partp->dp_typ = DOSPTYP_386BSD;
- partp->dp_flag = ACTIVE;
- partp->dp_start = dos_sectors;
- partp->dp_size = (disksecs / dos_cylsecs) * dos_cylsecs -
- dos_sectors;
-
- dos(partp);
- if (v_flag)
- print_s0(-1);
- write_s0();
- exit(0);
- }
- if (f_flag)
- {
- if (read_s0() || i_flag)
- {
- reset_boot();
- }
-
- if (!read_config(f_flag))
- {
- exit(1);
- }
- if (v_flag)
- {
- print_s0(-1);
- }
- if (!t_flag)
- {
- write_s0();
- }
- }
- else
- {
- if(u_flag)
- {
- get_params_to_use();
- }
- else
- {
- print_params();
- }
-
- if (read_s0())
- init_sector0(dos_sectors);
-
- printf("Media sector size is %d\n", secsize);
- printf("Warning: BIOS sector numbering starts with sector 1\n");
- printf("Information from DOS bootblock is:\n");
- if (partition == -1)
- for (i = 1; i <= NDOSPART; i++)
- change_part(i);
- else
- change_part(partition);
-
- if (u_flag || a_flag)
- change_active(partition);
-
- if (B_flag)
- change_code();
-
- if (u_flag || a_flag || B_flag) {
- if (!t_flag)
- {
- printf("\nWe haven't changed the partition table yet. ");
- printf("This is your last chance.\n");
- }
- print_s0(-1);
- if (!t_flag)
- {
- if (ok("Should we write new partition table?"))
- write_s0();
- }
- else
- {
- printf("\n-t flag specified -- partition table not written.\n");
- }
- }
- }
-
- exit(0);
-}
-
-static void
-usage()
-{
- fprintf(stderr, "%s%s",
- "usage: fdisk [-BIaistu] [-b bootcode] [-1234] [disk]\n",
- " fdisk -f configfile [-itv] [disk]\n");
- exit(1);
-}
-
-static void
-print_s0(int which)
-{
-int i;
-
- print_params();
- printf("Information from DOS bootblock is:\n");
- if (which == -1)
- for (i = 1; i <= NDOSPART; i++)
- printf("%d: ", i), print_part(i);
- else
- print_part(which);
-}
-
-static struct dos_partition mtpart = { 0 };
-
-static void
-print_part(int i)
-{
- struct dos_partition *partp;
- u_int64_t part_mb;
-
- partp = ((struct dos_partition *) &mboot.parts) + i - 1;
-
- if (!bcmp(partp, &mtpart, sizeof (struct dos_partition))) {
- printf("<UNUSED>\n");
- return;
- }
- /*
- * Be careful not to overflow.
- */
- part_mb = partp->dp_size;
- part_mb *= secsize;
- part_mb /= (1024 * 1024);
- printf("sysid %d,(%s)\n", partp->dp_typ, get_type(partp->dp_typ));
- printf(" start %lu, size %lu (%qd Meg), flag %x%s\n",
- (u_long)partp->dp_start,
- (u_long)partp->dp_size,
- part_mb,
- partp->dp_flag,
- partp->dp_flag == ACTIVE ? " (active)" : "");
- printf("\tbeg: cyl %d/ head %d/ sector %d;\n\tend: cyl %d/ head %d/ sector %d\n"
- ,DPCYL(partp->dp_scyl, partp->dp_ssect)
- ,partp->dp_shd
- ,DPSECT(partp->dp_ssect)
- ,DPCYL(partp->dp_ecyl, partp->dp_esect)
- ,partp->dp_ehd
- ,DPSECT(partp->dp_esect));
-}
-
-
-static void
-init_boot(void)
-{
- const char *fname;
- int fd, n;
- struct stat sb;
-
- fname = b_flag ? b_flag : "/boot/mbr";
- if ((fd = open(fname, O_RDONLY)) == -1 ||
- fstat(fd, &sb) == -1)
- err(1, "%s", fname);
- if ((mboot.bootinst_size = sb.st_size) % secsize != 0)
- errx(1, "%s: length must be a multiple of sector size", fname);
- if (mboot.bootinst != NULL)
- free(mboot.bootinst);
- if ((mboot.bootinst = malloc(mboot.bootinst_size = sb.st_size)) == NULL)
- errx(1, "%s: unable to allocate read buffer", fname);
- if ((n = read(fd, mboot.bootinst, mboot.bootinst_size)) == -1 ||
- close(fd))
- err(1, "%s", fname);
- if (n != mboot.bootinst_size)
- errx(1, "%s: short read", fname);
-}
-
-
-static void
-init_sector0(unsigned long start)
-{
-struct dos_partition *partp = (struct dos_partition *) (&mboot.parts[3]);
-
- init_boot();
-
- partp->dp_typ = DOSPTYP_386BSD;
- partp->dp_flag = ACTIVE;
- start = ((start + dos_sectors - 1) / dos_sectors) * dos_sectors;
- if(start == 0)
- start = dos_sectors;
- partp->dp_start = start;
- partp->dp_size = (disksecs / dos_cylsecs) * dos_cylsecs - start;
-
- dos(partp);
-}
-
-static void
-change_part(int i)
-{
-struct dos_partition *partp = ((struct dos_partition *) &mboot.parts) + i - 1;
-
- printf("The data for partition %d is:\n", i);
- print_part(i);
-
- if (u_flag && ok("Do you want to change it?")) {
- int tmp;
-
- if (i_flag) {
- bzero((char *)partp, sizeof (struct dos_partition));
- if (i == 4) {
- init_sector0(1);
- printf("\nThe static data for the DOS partition 4 has been reinitialized to:\n");
- print_part(i);
- }
- }
-
- do {
- Decimal("sysid (165=FreeBSD)", partp->dp_typ, tmp);
- Decimal("start", partp->dp_start, tmp);
- Decimal("size", partp->dp_size, tmp);
- if (!sanitize_partition(partp)) {
- warnx("ERROR: failed to adjust; setting sysid to 0");
- partp->dp_typ = 0;
- }
-
- if (ok("Explicitly specify beg/end address ?"))
- {
- int tsec,tcyl,thd;
- tcyl = DPCYL(partp->dp_scyl,partp->dp_ssect);
- thd = partp->dp_shd;
- tsec = DPSECT(partp->dp_ssect);
- Decimal("beginning cylinder", tcyl, tmp);
- Decimal("beginning head", thd, tmp);
- Decimal("beginning sector", tsec, tmp);
- partp->dp_scyl = DOSCYL(tcyl);
- partp->dp_ssect = DOSSECT(tsec,tcyl);
- partp->dp_shd = thd;
-
- tcyl = DPCYL(partp->dp_ecyl,partp->dp_esect);
- thd = partp->dp_ehd;
- tsec = DPSECT(partp->dp_esect);
- Decimal("ending cylinder", tcyl, tmp);
- Decimal("ending head", thd, tmp);
- Decimal("ending sector", tsec, tmp);
- partp->dp_ecyl = DOSCYL(tcyl);
- partp->dp_esect = DOSSECT(tsec,tcyl);
- partp->dp_ehd = thd;
- } else
- dos(partp);
-
- print_part(i);
- } while (!ok("Are we happy with this entry?"));
- }
-}
-
-static void
-print_params()
-{
- printf("parameters extracted from in-core disklabel are:\n");
- printf("cylinders=%d heads=%d sectors/track=%d (%d blks/cyl)\n\n"
- ,cyls,heads,sectors,cylsecs);
- if((dos_sectors > 63) || (dos_cyls > 1023) || (dos_heads > 255))
- printf("Figures below won't work with BIOS for partitions not in cyl 1\n");
- printf("parameters to be used for BIOS calculations are:\n");
- printf("cylinders=%d heads=%d sectors/track=%d (%d blks/cyl)\n\n"
- ,dos_cyls,dos_heads,dos_sectors,dos_cylsecs);
-}
-
-static void
-change_active(int which)
-{
- struct dos_partition *partp = &mboot.parts[0];
- int active, i, new, tmp;
-
- active = -1;
- for (i = 0; i < NDOSPART; i++) {
- if ((partp[i].dp_flag & ACTIVE) == 0)
- continue;
- printf("Partition %d is marked active\n", i + 1);
- if (active == -1)
- active = i + 1;
- }
- if (a_flag && which != -1)
- active = which;
- else if (active == -1)
- active = 1;
-
- if (!ok("Do you want to change the active partition?"))
- return;
-setactive:
- do {
- new = active;
- Decimal("active partition", new, tmp);
- if (new < 1 || new > 4) {
- printf("Active partition number must be in range 1-4."
- " Try again.\n");
- goto setactive;
- }
- active = new;
- } while (!ok("Are you happy with this choice"));
- for (i = 0; i < NDOSPART; i++)
- partp[i].dp_flag = 0;
- if (active > 0 && active <= NDOSPART)
- partp[active-1].dp_flag = ACTIVE;
-}
-
-static void
-change_code()
-{
- if (ok("Do you want to change the boot code?"))
- init_boot();
-}
-
-void
-get_params_to_use()
-{
- int tmp;
- print_params();
- if (ok("Do you want to change our idea of what BIOS thinks ?"))
- {
- do
- {
- Decimal("BIOS's idea of #cylinders", dos_cyls, tmp);
- Decimal("BIOS's idea of #heads", dos_heads, tmp);
- Decimal("BIOS's idea of #sectors", dos_sectors, tmp);
- dos_cylsecs = dos_heads * dos_sectors;
- print_params();
- }
- while(!ok("Are you happy with this choice"));
- }
-}
-
-
-/***********************************************\
-* Change real numbers into strange dos numbers *
-\***********************************************/
-static void
-dos(partp)
- struct dos_partition *partp;
-{
- int cy, sec;
- u_int32_t end;
-
- if (partp->dp_typ == 0 && partp->dp_start == 0 &&
- partp->dp_size == 0) {
- bcopy(partp, &mtpart, sizeof(*partp));
- return;
- }
-
- /* Start c/h/s. */
- partp->dp_shd = partp->dp_start % dos_cylsecs / dos_sectors;
- cy = partp->dp_start / dos_cylsecs;
- sec = partp->dp_start % dos_sectors + 1;
- partp->dp_scyl = DOSCYL(cy);
- partp->dp_ssect = DOSSECT(sec, cy);
-
- /* End c/h/s. */
- end = partp->dp_start + partp->dp_size - 1;
- partp->dp_ehd = end % dos_cylsecs / dos_sectors;
- cy = end / dos_cylsecs;
- sec = end % dos_sectors + 1;
- partp->dp_ecyl = DOSCYL(cy);
- partp->dp_esect = DOSSECT(sec, cy);
-}
-
-int fd;
-
- /* Getting device status */
-
-static int
-open_disk(int u_flag)
-{
- struct stat st;
-
- if (stat(disk, &st) == -1) {
- if (errno == ENOENT)
- return -2;
- warnx("can't get file status of %s", disk);
- return -1;
- }
- if ( !(st.st_mode & S_IFCHR) )
- warnx("device %s is not character special", disk);
- if ((fd = open(disk,
- a_flag || I_flag || B_flag || u_flag ? O_RDWR : O_RDONLY)) == -1) {
- if(errno == ENXIO)
- return -2;
- warnx("can't open device %s", disk);
- return -1;
- }
- if (get_params(0) == -1) {
- warnx("can't get disk parameters on %s", disk);
- return -1;
- }
- return fd;
-}
-
-static ssize_t
-read_disk(off_t sector, void *buf)
-{
- lseek(fd,(sector * 512), 0);
- if( secsize == 0 )
- for( secsize = MIN_SEC_SIZE; secsize <= MAX_SEC_SIZE; secsize *= 2 )
- {
- /* try the read */
- int size = read(fd, buf, secsize);
- if( size == secsize )
- /* it worked so return */
- return secsize;
- }
- else
- return read( fd, buf, secsize );
-
- /* we failed to read at any of the sizes */
- return -1;
-}
-
-static ssize_t
-write_disk(off_t sector, void *buf)
-{
- lseek(fd,(sector * 512), 0);
- /* write out in the size that the read_disk found worked */
- return write(fd, buf, secsize);
-}
-
-static int
-get_params()
-{
-
- if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
- warnx("can't get disk parameters on %s; supplying dummy ones", disk);
- dos_cyls = cyls = 1;
- dos_heads = heads = 1;
- dos_sectors = sectors = 1;
- dos_cylsecs = cylsecs = heads * sectors;
- disksecs = cyls * heads * sectors;
- return disksecs;
- }
-
- dos_cyls = cyls = disklabel.d_ncylinders;
- dos_heads = heads = disklabel.d_ntracks;
- dos_sectors = sectors = disklabel.d_nsectors;
- dos_cylsecs = cylsecs = heads * sectors;
- disksecs = cyls * heads * sectors;
-
- return (disksecs);
-}
-
-
-static int
-read_s0()
-{
- mboot.bootinst_size = secsize;
- if (mboot.bootinst != NULL)
- free(mboot.bootinst);
- if ((mboot.bootinst = malloc(mboot.bootinst_size)) == NULL) {
- warnx("unable to allocate buffer to read fdisk "
- "partition table");
- return -1;
- }
- if (read_disk(0, mboot.bootinst) == -1) {
- warnx("can't read fdisk partition table");
- return -1;
- }
- if (*(uint16_t *)&mboot.bootinst[MBRSIGOFF] != BOOT_MAGIC) {
- warnx("invalid fdisk partition table found");
- /* So should we initialize things */
- return -1;
- }
- memcpy(mboot.parts, &mboot.bootinst[DOSPARTOFF], sizeof(mboot.parts));
- return 0;
-}
-
-static int
-write_s0()
-{
-#ifdef NOT_NOW
- int flag;
-#endif
- int sector;
-
- if (iotest) {
- print_s0(-1);
- return 0;
- }
- memcpy(&mboot.bootinst[DOSPARTOFF], mboot.parts, sizeof(mboot.parts));
- /*
- * write enable label sector before write (if necessary),
- * disable after writing.
- * needed if the disklabel protected area also protects
- * sector 0. (e.g. empty disk)
- */
-#ifdef NOT_NOW
- flag = 1;
- if (ioctl(fd, DIOCWLABEL, &flag) < 0)
- warn("ioctl DIOCWLABEL");
-#endif
- for(sector = 0; sector < mboot.bootinst_size / secsize; sector++)
- if (write_disk(sector,
- &mboot.bootinst[sector * secsize]) == -1) {
- warn("can't write fdisk partition table");
- return -1;
-#ifdef NOT_NOW
- flag = 0;
- (void) ioctl(fd, DIOCWLABEL, &flag);
-#endif
- }
-#ifdef NOT_NOW
- flag = 0;
- (void) ioctl(fd, DIOCWLABEL, &flag);
-#endif
- return(0);
-}
-
-
-static int
-ok(str)
-char *str;
-{
- printf("%s [n] ", str);
- fflush(stdout);
- if (fgets(lbuf, LBUF, stdin) == NULL)
- exit(1);
- lbuf[strlen(lbuf)-1] = 0;
-
- if (*lbuf &&
- (!strcmp(lbuf, "yes") || !strcmp(lbuf, "YES") ||
- !strcmp(lbuf, "y") || !strcmp(lbuf, "Y")))
- return 1;
- else
- return 0;
-}
-
-static int
-decimal(char *str, int *num, int deflt)
-{
-int acc = 0, c;
-char *cp;
-
- while (1) {
- printf("Supply a decimal value for \"%s\" [%d] ", str, deflt);
- fflush(stdout);
- if (fgets(lbuf, LBUF, stdin) == NULL)
- exit(1);
- lbuf[strlen(lbuf)-1] = 0;
-
- if (!*lbuf)
- return 0;
-
- cp = lbuf;
- while ((c = *cp) && (c == ' ' || c == '\t')) cp++;
- if (!c)
- return 0;
- while ((c = *cp++)) {
- if (c <= '9' && c >= '0')
- acc = acc * 10 + c - '0';
- else
- break;
- }
- if (c == ' ' || c == '\t')
- while ((c = *cp) && (c == ' ' || c == '\t')) cp++;
- if (!c) {
- *num = acc;
- return 1;
- } else
- printf("%s is an invalid decimal number. Try again.\n",
- lbuf);
- }
-
-}
-
-#if 0
-static int
-hex(char *str, int *num, int deflt)
-{
-int acc = 0, c;
-char *cp;
-
- while (1) {
- printf("Supply a hex value for \"%s\" [%x] ", str, deflt);
- fgets(lbuf, LBUF, stdin);
- lbuf[strlen(lbuf)-1] = 0;
-
- if (!*lbuf)
- return 0;
-
- cp = lbuf;
- while ((c = *cp) && (c == ' ' || c == '\t')) cp++;
- if (!c)
- return 0;
- while ((c = *cp++)) {
- if (c <= '9' && c >= '0')
- acc = (acc << 4) + c - '0';
- else if (c <= 'f' && c >= 'a')
- acc = (acc << 4) + c - 'a' + 10;
- else if (c <= 'F' && c >= 'A')
- acc = (acc << 4) + c - 'A' + 10;
- else
- break;
- }
- if (c == ' ' || c == '\t')
- while ((c = *cp) && (c == ' ' || c == '\t')) cp++;
- if (!c) {
- *num = acc;
- return 1;
- } else
- printf("%s is an invalid hex number. Try again.\n",
- lbuf);
- }
-
-}
-
-static int
-string(char *str, char **ans)
-{
-int c;
-char *cp = lbuf;
-
- while (1) {
- printf("Supply a string value for \"%s\" [%s] ", str, *ans);
- fgets(lbuf, LBUF, stdin);
- lbuf[strlen(lbuf)-1] = 0;
-
- if (!*lbuf)
- return 0;
-
- while ((c = *cp) && (c == ' ' || c == '\t')) cp++;
- if (c == '"') {
- c = *++cp;
- *ans = cp;
- while ((c = *cp) && c != '"') cp++;
- } else {
- *ans = cp;
- while ((c = *cp) && c != ' ' && c != '\t') cp++;
- }
-
- if (c)
- *cp = 0;
- return 1;
- }
-}
-#endif
-
-static char *
-get_type(int type)
-{
- int numentries = (sizeof(part_types)/sizeof(struct part_type));
- int counter = 0;
- struct part_type *ptr = part_types;
-
-
- while(counter < numentries)
- {
- if(ptr->type == type)
- {
- return(ptr->name);
- }
- ptr++;
- counter++;
- }
- return("unknown");
-}
-
-
-static void
-parse_config_line(line, command)
- char *line;
- CMD *command;
-{
- char *cp, *end;
-
- cp = line;
- while (1) /* dirty trick used to insure one exit point for this
- function */
- {
- memset(command, 0, sizeof(*command));
-
- while (isspace(*cp)) ++cp;
- if (*cp == '\0' || *cp == '#')
- {
- break;
- }
- command->cmd = *cp++;
-
- /*
- * Parse args
- */
- while (1)
- {
- while (isspace(*cp)) ++cp;
- if (*cp == '#')
- {
- break; /* found comment */
- }
- if (isalpha(*cp))
- {
- command->args[command->n_args].argtype = *cp++;
- }
- if (!isdigit(*cp))
- {
- break; /* assume end of line */
- }
- end = NULL;
- command->args[command->n_args].arg_val = strtol(cp, &end, 0);
- if (cp == end)
- {
- break; /* couldn't parse number */
- }
- cp = end;
- command->n_args++;
- }
- break;
- }
-}
-
-
-static int
-process_geometry(command)
- CMD *command;
-{
- int status = 1, i;
-
- while (1)
- {
- geom_processed = 1;
- if (part_processed)
- {
- warnx(
- "ERROR line %d: the geometry specification line must occur before\n\
- all partition specifications",
- current_line_number);
- status = 0;
- break;
- }
- if (command->n_args != 3)
- {
- warnx("ERROR line %d: incorrect number of geometry args",
- current_line_number);
- status = 0;
- break;
- }
- dos_cyls = -1;
- dos_heads = -1;
- dos_sectors = -1;
- for (i = 0; i < 3; ++i)
- {
- switch (command->args[i].argtype)
- {
- case 'c':
- dos_cyls = command->args[i].arg_val;
- break;
- case 'h':
- dos_heads = command->args[i].arg_val;
- break;
- case 's':
- dos_sectors = command->args[i].arg_val;
- break;
- default:
- warnx(
- "ERROR line %d: unknown geometry arg type: '%c' (0x%02x)",
- current_line_number, command->args[i].argtype,
- command->args[i].argtype);
- status = 0;
- break;
- }
- }
- if (status == 0)
- {
- break;
- }
-
- dos_cylsecs = dos_heads * dos_sectors;
-
- /*
- * Do sanity checks on parameter values
- */
- if (dos_cyls < 0)
- {
- warnx("ERROR line %d: number of cylinders not specified",
- current_line_number);
- status = 0;
- }
- if (dos_cyls == 0 || dos_cyls > 1024)
- {
- warnx(
- "WARNING line %d: number of cylinders (%d) may be out-of-range\n\
- (must be within 1-1024 for normal BIOS operation, unless the entire disk\n\
- is dedicated to FreeBSD)",
- current_line_number, dos_cyls);
- }
-
- if (dos_heads < 0)
- {
- warnx("ERROR line %d: number of heads not specified",
- current_line_number);
- status = 0;
- }
- else if (dos_heads < 1 || dos_heads > 256)
- {
- warnx("ERROR line %d: number of heads must be within (1-256)",
- current_line_number);
- status = 0;
- }
-
- if (dos_sectors < 0)
- {
- warnx("ERROR line %d: number of sectors not specified",
- current_line_number);
- status = 0;
- }
- else if (dos_sectors < 1 || dos_sectors > 63)
- {
- warnx("ERROR line %d: number of sectors must be within (1-63)",
- current_line_number);
- status = 0;
- }
-
- break;
- }
- return (status);
-}
-
-
-static int
-process_partition(command)
- CMD *command;
-{
- int status = 0, partition;
- u_int32_t prev_head_boundary, prev_cyl_boundary;
- u_int32_t adj_size, max_end;
- struct dos_partition *partp;
-
- while (1)
- {
- part_processed = 1;
- if (command->n_args != 4)
- {
- warnx("ERROR line %d: incorrect number of partition args",
- current_line_number);
- break;
- }
- partition = command->args[0].arg_val;
- if (partition < 1 || partition > 4)
- {
- warnx("ERROR line %d: invalid partition number %d",
- current_line_number, partition);
- break;
- }
- partp = ((struct dos_partition *) &mboot.parts) + partition - 1;
- bzero((char *)partp, sizeof (struct dos_partition));
- partp->dp_typ = command->args[1].arg_val;
- partp->dp_start = command->args[2].arg_val;
- partp->dp_size = command->args[3].arg_val;
- max_end = partp->dp_start + partp->dp_size;
-
- if (partp->dp_typ == 0)
- {
- /*
- * Get out, the partition is marked as unused.
- */
- /*
- * Insure that it's unused.
- */
- bzero((char *)partp, sizeof (struct dos_partition));
- status = 1;
- break;
- }
-
- /*
- * Adjust start upwards, if necessary, to fall on an head boundary.
- */
- if (partp->dp_start % dos_sectors != 0)
- {
- prev_head_boundary = partp->dp_start / dos_sectors * dos_sectors;
- if (max_end < dos_sectors ||
- prev_head_boundary > max_end - dos_sectors)
- {
- /*
- * Can't go past end of partition
- */
- warnx(
- "ERROR line %d: unable to adjust start of partition %d to fall on\n\
- a head boundary",
- current_line_number, partition);
- break;
- }
- warnx(
- "WARNING: adjusting start offset of partition %d\n\
- from %u to %u, to fall on a head boundary",
- partition, (u_int)partp->dp_start,
- (u_int)(prev_head_boundary + dos_sectors));
- partp->dp_start = prev_head_boundary + dos_sectors;
- }
-
- /*
- * Adjust size downwards, if necessary, to fall on a cylinder
- * boundary.
- */
- prev_cyl_boundary =
- ((partp->dp_start + partp->dp_size) / dos_cylsecs) * dos_cylsecs;
- if (prev_cyl_boundary > partp->dp_start)
- adj_size = prev_cyl_boundary - partp->dp_start;
- else
- {
- warnx(
- "ERROR: could not adjust partition to start on a head boundary\n\
- and end on a cylinder boundary.");
- return (0);
- }
- if (adj_size != partp->dp_size)
- {
- warnx(
- "WARNING: adjusting size of partition %d from %u to %u\n\
- to end on a cylinder boundary",
- partition, (u_int)partp->dp_size, (u_int)adj_size);
- partp->dp_size = adj_size;
- }
- if (partp->dp_size == 0)
- {
- warnx("ERROR line %d: size of partition %d is zero",
- current_line_number, partition);
- break;
- }
-
- dos(partp);
- status = 1;
- break;
- }
- return (status);
-}
-
-
-static int
-process_active(command)
- CMD *command;
-{
- int status = 0, partition, i;
- struct dos_partition *partp;
-
- while (1)
- {
- active_processed = 1;
- if (command->n_args != 1)
- {
- warnx("ERROR line %d: incorrect number of active args",
- current_line_number);
- status = 0;
- break;
- }
- partition = command->args[0].arg_val;
- if (partition < 1 || partition > 4)
- {
- warnx("ERROR line %d: invalid partition number %d",
- current_line_number, partition);
- break;
- }
- /*
- * Reset active partition
- */
- partp = ((struct dos_partition *) &mboot.parts);
- for (i = 0; i < NDOSPART; i++)
- partp[i].dp_flag = 0;
- partp[partition-1].dp_flag = ACTIVE;
-
- status = 1;
- break;
- }
- return (status);
-}
-
-
-static int
-process_line(line)
- char *line;
-{
- CMD command;
- int status = 1;
-
- while (1)
- {
- parse_config_line(line, &command);
- switch (command.cmd)
- {
- case 0:
- /*
- * Comment or blank line
- */
- break;
- case 'g':
- /*
- * Set geometry
- */
- status = process_geometry(&command);
- break;
- case 'p':
- status = process_partition(&command);
- break;
- case 'a':
- status = process_active(&command);
- break;
- default:
- status = 0;
- break;
- }
- break;
- }
- return (status);
-}
-
-
-static int
-read_config(config_file)
- char *config_file;
-{
- FILE *fp = NULL;
- int status = 1;
- char buf[1010];
-
- while (1) /* dirty trick used to insure one exit point for this
- function */
- {
- if (strcmp(config_file, "-") != 0)
- {
- /*
- * We're not reading from stdin
- */
- if ((fp = fopen(config_file, "r")) == NULL)
- {
- status = 0;
- break;
- }
- }
- else
- {
- fp = stdin;
- }
- current_line_number = 0;
- while (!feof(fp))
- {
- if (fgets(buf, sizeof(buf), fp) == NULL)
- {
- break;
- }
- ++current_line_number;
- status = process_line(buf);
- if (status == 0)
- {
- break;
- }
- }
- break;
- }
- if (fp)
- {
- /*
- * It doesn't matter if we're reading from stdin, as we've reached EOF
- */
- fclose(fp);
- }
- return (status);
-}
-
-
-static void
-reset_boot(void)
-{
- int i;
- struct dos_partition *partp;
-
- init_boot();
- for (i = 0; i < 4; ++i)
- {
- partp = ((struct dos_partition *) &mboot.parts) + i;
- bzero((char *)partp, sizeof (struct dos_partition));
- }
-}
-
-static int
-sanitize_partition(partp)
- struct dos_partition *partp;
-{
- u_int32_t prev_head_boundary, prev_cyl_boundary;
- u_int32_t max_end, size, start;
-
- start = partp->dp_start;
- size = partp->dp_size;
- max_end = start + size;
- /* Only allow a zero size if the partition is being marked unused. */
- if (size == 0) {
- if (start == 0 && partp->dp_typ == 0)
- return (1);
- warnx("ERROR: size of partition is zero");
- return (0);
- }
- /* Return if no adjustment is necessary. */
- if (start % dos_sectors == 0 && (start + size) % dos_sectors == 0)
- return (1);
-
- if (start % dos_sectors != 0)
- warnx("WARNING: partition does not start on a head boundary");
- if ((start +size) % dos_sectors != 0)
- warnx("WARNING: partition does not end on a cylinder boundary");
- warnx("WARNING: this may confuse the BIOS or some operating systems");
- if (!ok("Correct this automatically?"))
- return (1);
-
- /*
- * Adjust start upwards, if necessary, to fall on an head boundary.
- */
- if (start % dos_sectors != 0) {
- prev_head_boundary = start / dos_sectors * dos_sectors;
- if (max_end < dos_sectors ||
- prev_head_boundary >= max_end - dos_sectors) {
- /*
- * Can't go past end of partition
- */
- warnx(
- "ERROR: unable to adjust start of partition to fall on a head boundary");
- return (0);
- }
- start = prev_head_boundary + dos_sectors;
- }
-
- /*
- * Adjust size downwards, if necessary, to fall on a cylinder
- * boundary.
- */
- prev_cyl_boundary = ((start + size) / dos_cylsecs) * dos_cylsecs;
- if (prev_cyl_boundary > start)
- size = prev_cyl_boundary - start;
- else {
- warnx("ERROR: could not adjust partition to start on a head boundary\n\
- and end on a cylinder boundary.");
- return (0);
- }
-
- /* Finally, commit any changes to partp and return. */
- if (start != partp->dp_start) {
- warnx("WARNING: adjusting start offset of partition to %u",
- (u_int)start);
- partp->dp_start = start;
- }
- if (size != partp->dp_size) {
- warnx("WARNING: adjusting size of partition to %u", (u_int)size);
- partp->dp_size = size;
- }
-
- return (1);
-}
-
-/*
- * Try figuring out the root device's canonical disk name.
- * The following choices are considered:
- * /dev/ad0s1a => /dev/ad0
- * /dev/da0a => /dev/da0
- * /dev/vinum/root => /dev/vinum/root
- */
-static char *
-get_rootdisk(void)
-{
- struct statfs rootfs;
- regex_t re;
-#define NMATCHES 2
- regmatch_t rm[NMATCHES];
- char *s;
- int rv;
-
- if (statfs("/", &rootfs) == -1)
- err(1, "statfs(\"/\")");
-
- if ((rv = regcomp(&re, "^(/dev/.*)(\\d+(s\\d+)?[a-h])?$",
- REG_EXTENDED)) != 0)
- errx(1, "regcomp() failed (%d)", rv);
- if ((rv = regexec(&re, rootfs.f_mntfromname, NMATCHES, rm, 0)) != 0)
- errx(1,
-"mounted root fs resource doesn't match expectations (regexec returned %d)",
- rv);
- if ((s = malloc(rm[1].rm_eo - rm[1].rm_so + 1)) == NULL)
- errx(1, "out of memory");
- memcpy(s, rootfs.f_mntfromname + rm[1].rm_so,
- rm[1].rm_eo - rm[1].rm_so);
- s[rm[1].rm_eo - rm[1].rm_so] = 0;
-
- return s;
-}
diff --git a/sbin/i386/nextboot/Makefile b/sbin/i386/nextboot/Makefile
deleted file mode 100644
index 18cfbe1..0000000
--- a/sbin/i386/nextboot/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# @(#)Makefile 1.1 (Julian Elischer) 3/28/93
-# $FreeBSD$
-
-PROG= nextboot
-MAN= nextboot.8
-
-.include <bsd.prog.mk>
diff --git a/sbin/i386/nextboot/nextboot.8 b/sbin/i386/nextboot/nextboot.8
deleted file mode 100644
index b57c4b0..0000000
--- a/sbin/i386/nextboot/nextboot.8
+++ /dev/null
@@ -1,115 +0,0 @@
-.\" $FreeBSD$
-.Dd July 9, 1996
-.Dt NEXTBOOT 8
-.Os
-.Sh NAME
-.Nm nextboot
-.Nd install a default bootstring block on the boot disk
-.Sh SYNOPSIS
-.Nm
-.Op Fl b
-.Ar filename bootstring
-.Ar
-.Nm
-.Op Fl ed
-.Ar filename
-.Sh DESCRIPTION
-The
-.Fx
-program
-.Nm
-controls the actions of the boot blocks at the time of the next boot.
-If compiled with the correct option,
-the boot blocks will check the nameblock for a magic number and a
-default name to use for booting.
-If compiled to do so they will also
-delete the name from the block, ensuring that if the boot should fail,
-then it will not be tried again.
-It is the job of
-.Pa /etc/rc
-to use
-.Nm
-to re-install the string if that boot is found to have succeeded.
-This allows a one-time only boot string to be used for such applications
-as remote debugging, and installation of new, untrusted kernels.
-The nameblock is defined at compile time to be the second physical block
-on the disk.
-.Pp
-The following options are available:
-.Bl -tag -width indent
-.It Fl b
-Is used for bootstrapping (initially configuring) the nameblock.
-Without
-this,
-.Nm
-will refuse to write to a block that does not already contain the magic
-number.
-.It Fl d
-Disable (temporarily) an existing name block by changing a bit
-in the magic number.
-.It Fl e
-Restore the good magic number on a block disabled by
-.Fl d .
-.El
-.Pp
-The
-.Fl e
-and
-.Fl d
-flags are mutually exclusive.
-.Sh DESCRIPTION
-.Nm Nextboot
-first checks that the disk has an fdisk table and checks that none of the
-partitions defined in that table include the nameblock.
-If the name block is
-shown to be unused, it will install the bootstrings given as arguments,
-one after the other, each preceded by a small magic number, and NULL
-terminated.
-The end of the list of strings is delimited by a sequence of
-0xff bytes.
-If the boot blocks are compiled to write back the nameblock
-after each boot, it will zero out the supplied names as it uses them,
-one per boot,
-until it reaches the 0xff, at which time it will revert to the compiled in
-boot string.
-At this time the nameblock will contain only zeroed out names.
-.Pp
-An example of usage might be:
-.Bd -literal
- nextboot -b /dev/rwd0 1:sd(0,a)/kernel.experimental wd(0,a)/kernel.old
-.Ed
-.Pp
-Which would instruct the boot blocks at the next boot,
-to try boot the experimental kernel off the SCSI disk.
-If for any reason this failed, the next boot attempt would
-boot the kernel
-.Pa /kernel.old
-off the IDE drive. (Assuming the write-back option were enabled) If this
-in turn failed.
-The compiled in default would be used.
-.Pp
-If the write-back feature is disabled, the nextboot program is a convenient way
-to change the default boot string.
-Note, that should the file specified in
-the nameblock be non-existent, then the name compiled into the boot blocks
-will be used for the boot rather than the next name in the nameblock.
-The
-nameblock is only consulted
-.Em once
-per boot.
-.Sh SEE ALSO
-.Xr boot 8 ,
-.Xr disklabel 8 ,
-.Xr fdisk 8
-.Sh BUGS
-This program works only in conjunction with the legacy boot code.
-.Pp
-The entire program should be made more user-friendly.
-The option of whether to write back or not should be stored on the
-disk and not a compile time option.
-I want to rethink this at some
-later stage to make it co-exist with disks that do not have
-a fdisk partitioning table (i.e. purely disklabel'd systems).
-.Pp
-Whether to write back or not should be specified at run-time in the nameblock
-so that the boot blocks need not be altered to get this feature.
diff --git a/sbin/i386/nextboot/nextboot.c b/sbin/i386/nextboot/nextboot.c
deleted file mode 100644
index 5893ca3..0000000
--- a/sbin/i386/nextboot/nextboot.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Copyright (c) 1996 Whistle Communications
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * Whistle Communications allows free use of this software in its "as is"
- * condition. Whistle Communications disclaims any liability of any kind for
- * any damages whatsoever resulting from the use of this software.
- */
-
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/disklabel.h>
-#include <fcntl.h>
-#include <err.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-struct mboot
-{
- unsigned char padding[2]; /* force the longs to be long aligned */
- unsigned char bootinst[DOSPARTOFF];
- struct dos_partition parts[4];
- unsigned short int signature;
-};
-struct mboot mboot;
-
-#define NAMEBLOCK 1 /* 2nd block */
-#define BLOCKSIZE 512
-#define ENABLE_MAGIC 0xfadefeed
-#define DISABLE_MAGIC 0xfadefade
-static int bflag;
-static int eflag;
-static int dflag;
-
-#define BOOT_MAGIC 0xAA55
-
-static void
-usage(void) {
- fprintf (stderr, "%s\n%s\n",
- "usage: nextboot [-b] device bootstring [bootstring] ...",
- " nextboot {-e,-d} device");
- exit(1);
-}
-
-int
-main (int argc, char** argv)
-{
- int fd = -1;
- char namebuf[1024], *cp = namebuf;
- int i,j;
- int ch;
- int part;
-
- bflag = 0;
- while ((ch = getopt(argc, argv, "bde")) != -1) {
- switch(ch) {
- case 'b':
- bflag = 1;
- break;
- case 'd':
- dflag = 1;
- break;
- case 'e':
- eflag = 1;
- break;
- case '?':
- default:
- usage();
- }
- }
- argc -= optind;
- argv += optind;
-
- if ( (dflag + eflag + bflag) > 1 ) {
- usage();
- }
- if (dflag + eflag){
- if(argc != 1 ) {
- usage();
- }
- } else {
- if (argc <2) {
- usage();
- }
- }
- if ((fd = open(argv[0], O_RDWR, 0)) < 0)
- errx(1, "can't open %s", argv[0]);
-
- argc--;
- argv++;
-
- /*******************************************
- * Check that we have an MBR
- */
- if (lseek(fd,0,0) == -1)
- err(1, "lseek");
- if (read (fd,&mboot.bootinst[0],BLOCKSIZE ) != BLOCKSIZE)
- err(1, "read0");
- if (mboot.signature != (unsigned short)BOOT_MAGIC)
- errx(1, "no fdisk part.. not touching block 1");
-
- /*******************************************
- * And check that none of the partitions in it cover the name block;
- */
- for ( part = 0; part < 4; part++) {
- if( mboot.parts[part].dp_size
- && (mboot.parts[part].dp_start <= NAMEBLOCK)
- && (mboot.parts[part].dp_start
- + mboot.parts[part].dp_size > NAMEBLOCK))
- errx(1,
- "name sector lies within a Bios partition: aborting write");
- }
-
-
- /*******************************************
- * Now check the name sector itself to see if it's been initialized.
- */
- if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1)
- err(1, "lseek");
- if (read(fd,namebuf,BLOCKSIZE) != BLOCKSIZE)
- err(1, "read1");
- /*******************************************
- * check if we are just enabling or disabling
- * Remember the flags are exclusive..
- */
- if(!bflag) { /* don't care what's there if bflag is set */
- switch(*(unsigned long *)cp)
- {
- case DISABLE_MAGIC:
- case ENABLE_MAGIC:
- break;
- default:
- errx(1, "namesector not initialized, use the -b flag");
- }
- }
-
-
- /*******************************************
- * If the z or r flag is set, damage or restore the magic number..
- * to disable/enable the feature
- */
- if(dflag) {
- *(unsigned long *)cp = DISABLE_MAGIC;
- } else {
- *(unsigned long *)cp = ENABLE_MAGIC;
- }
- if ((!dflag) && (!eflag)) {
- /*******************************************
- * Create a new namesector in ram
- */
- cp += 4;
- for ( i = 0 ; i < argc ; i++ ) {
- *cp++ = 'D';
- *cp++ = 'N';
- j = strlen(argv[i]);
- strncpy(cp,argv[i],j);
- cp += j;
- *cp++ = 0;
- }
- *cp++ = 0xff;
- *cp++ = 0xff;
- *cp++ = 0xff;
- namebuf[BLOCKSIZE-1] = 0; /* paranoid */
- namebuf[BLOCKSIZE] = 0xff;
- }
-
- /*******************************************
- * write it to disk.
- */
- if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1)
- err(1, "lseek");
- if(write (fd,namebuf,BLOCKSIZE ) != BLOCKSIZE)
- err(1, "write");
-
-#if 0
- /*******************************************
- * just to be safe/paranoid.. read it back..
- * and print it..
- */
- if (lseek(fd,NAMEBLOCK * BLOCKSIZE,0) == -1)
- err(1, "lseek (second)");
- read (fd,namebuf,512);
- for (i = 0;i< 16;i++) {
- for ( j = 0; j < 16; j++) {
- printf("%02x ",(unsigned char )namebuf[(i*16) + j ]);
- }
- printf("\n");
- }
-#endif
- exit(0);
-}
OpenPOWER on IntegriCloud