diff options
Diffstat (limited to 'sbin')
41 files changed, 0 insertions, 6335 deletions
diff --git a/sbin/bsdlabel/disklabel.5.5 b/sbin/bsdlabel/disklabel.5.5 deleted file mode 100644 index fb6f6cd..0000000 --- a/sbin/bsdlabel/disklabel.5.5 +++ /dev/null @@ -1,384 +0,0 @@ -.\" Copyright (c) 1987, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Symmetric Computer Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)disklabel.5.5 8.1 (Berkeley) 6/5/93 -.\" -.Dd June 5, 1993 -.Dt DISKLABEL 5 -.Os -.Sh NAME -.Nm disklabel -.Nd disk pack label -.Sh SYNOPSIS -.Fd #include <sys/disklabel.h> -.Sh DESCRIPTION -Each disk or disk pack on a system may contain a disk label -which provides detailed information -about the geometry of the disk and the partitions into which the disk -is divided. -It should be initialized when the disk is formatted, -and may be changed later with the -.Xr disklabel 8 -program. -This information is used by the system disk driver and by the bootstrap -program to determine how to program the drive -and where to find the filesystems on the disk partitions. -Additional information is used by the filesystem in order -to use the disk most efficiently and to locate important filesystem information. -The description of each partition contains an identifier for the partition -type (standard filesystem, swap area, etc.). -The filesystem updates the in-core copy of the label if it contains -incomplete information about the filesystem. -.Pp -The label is located in sector number -.Dv LABELSECTOR -of the drive, usually sector 0 where it may be found -without any information about the disk geometry. -It is at an offset -.Dv LABELOFFSET -from the beginning of the sector, to allow room for the initial bootstrap. -The disk sector containing the label is normally made read-only -so that it is not accidentally overwritten by pack-to-pack copies -or swap operations; -the -.Dv DIOCWLABEL -.Xr ioctl 2 , -which is done as needed by the -.Xr disklabel -program. -.Pp -A copy of the in-core label for a disk can be obtained with the -.Dv DIOCGDINFO -.Xr ioctl ; -this works with a file descriptor for a block or character (``raw'') device -for any partition of the disk. -The in-core copy of the label is set by the -.Dv DIOCSDINFO -.Xr ioctl . -The offset of a partition cannot generally be changed while it is open, -nor can it be made smaller while it is open. -One exception is that any change is allowed if no label was found -on the disk, and the driver was able to construct only a skeletal label -without partition information. -Finally, the -.Dv DIOCWDINFO -.Xr ioctl -operation sets the in-core label and then updates the on-disk label; -there must be an existing label on the disk for this operation to succeed. -Thus, the initial label for a disk or disk pack must be installed -by writing to the raw disk. -All of these operations are normally done using -.Xr disklabel . -.Pp -The format of the disk label, as specified in -.Aw Pa sys/disklabel.h , -is -.Bd -literal -/* -* Disk description table, see disktab(5) -*/ -#define DISKTAB "/etc/disktab" - -/* -* Each disk has a label which includes information about the hardware -* disk geometry, filesystem partitions, and drive specific information. -* The label is in block 0 or 1, possibly offset from the beginning -* to leave room for a bootstrap, etc. -*/ - -#ifndef LABELSECTOR -#define LABELSECTOR 0 /* sector containing label */ -#endif - -#ifndef LABELOFFSET -#define LABELOFFSET 64 /* offset of label in sector */ -#endif - -#define DISKMAGIC ((u_long) 0x82564557) /* The disk magic number */ -#ifndef MAXPARTITIONS -#define MAXPARTITIONS 8 -#endif - -#ifndef LOCORE -struct disklabel { - u_long d_magic; /* the magic number */ - short d_type; /* drive type */ - short d_subtype; /* controller/d_type specific */ - char d_typename[16]; /* type name, e.g. "eagle" */ - /* - * d_packname contains the pack identifier and is returned when - * the disklabel is read off the disk or in-core copy. - * d_boot0 and d_boot1 are the (optional) names of the - * primary (block 0) and secondary (block 1-15) bootstraps - * as found in /usr/mdec. These are returned when using - * getdiskbyname(3) - to retrieve the values from /etc/disktab. - */ -#if defined(KERNEL) || defined(STANDALONE) - char d_packname[16]; /* pack identifier */ -#else - union { - char un_d_packname[16]; /* pack identifier */ - struct { - char *un_d_boot0; /* primary bootstrap name */ - char *un_d_boot1; /* secondary bootstrap name */ - } un_b; - } d_un; - -#define d_packname d_un.un_d_packname -#define d_boot0 d_un.un_b.un_d_boot0 -#define d_boot1 d_un.un_b.un_d_boot1 -#endif /* ! KERNEL or STANDALONE */ - - /* disk geometry: */ - u_long d_secsize; /* # of bytes per sector */ - u_long d_nsectors; /* # of data sectors per track */ - u_long d_ntracks; /* # of tracks per cylinder */ - u_long d_ncylinders; /* # of data cylinders per unit */ - u_long d_secpercyl; /* # of data sectors per cylinder */ - u_long d_secperunit; /* # of data sectors per unit */ - /* - * Spares (bad sector replacements) below - * are not counted in d_nsectors or d_secpercyl. - * Spare sectors are assumed to be physical sectors - * which occupy space at the end of each track and/or cylinder. - */ - u_short d_sparespertrack; /* # of spare sectors per track */ - u_short d_sparespercyl; /* # of spare sectors per cylinder */ - /* - * Alternate cylinders include maintenance, replacement, - * configuration description areas, etc. - */ - u_long d_acylinders; /* # of alt. cylinders per unit */ - - /* hardware characteristics: */ - /* - * d_interleave, d_trackskew and d_cylskew describe perturbations - * in the media format used to compensate for a slow controller. - * Interleave is physical sector interleave, set up by the formatter - * or controller when formatting. When interleaving is in use, - * logically adjacent sectors are not physically contiguous, - * but instead are separated by some number of sectors. - * It is specified as the ratio of physical sectors traversed - * per logical sector. Thus an interleave of 1:1 implies contiguous - * layout, while 2:1 implies that logical sector 0 is separated - * by one sector from logical sector 1. - * d_trackskew is the offset of sector 0 on track N - * relative to sector 0 on track N-1 on the same cylinder. - * Finally, d_cylskew is the offset of sector 0 on cylinder N - * relative to sector 0 on cylinder N-1. - */ - u_short d_rpm; /* rotational speed */ - u_short d_interleave; /* hardware sector interleave */ - u_short d_trackskew; /* sector 0 skew, per track */ - u_short d_cylskew; /* sector 0 skew, per cylinder */ - u_long d_headswitch; /* head switch time, usec */ - u_long d_trkseek; /* track-to-track seek, usec */ - u_long d_flags; /* generic flags */ -#define NDDATA 5 - u_long d_drivedata[NDDATA]; /* drive-type specific information */ -#define NSPARE 5 - u_long d_spare[NSPARE]; /* reserved for future use */ - u_long d_magic2; /* the magic number (again) */ - u_short d_checksum; /* xor of data incl. partitions */ - - /* filesystem and partition information: */ - u_short d_npartitions; /* number of partitions in following */ - u_long d_bbsize; /* size of boot area at sn0, bytes */ - u_long d_sbsize; /* max size of fs superblock, bytes */ - struct partition { /* the partition table */ - u_long p_size; /* number of sectors in partition */ - u_long p_offset; /* starting sector */ - u_long p_fsize; /* filesystem basic fragment size */ - u_char p_fstype; /* filesystem type, see below */ - u_char p_frag; /* filesystem fragments per block */ - union { - u_short cpg; /* UFS: FS cylinders per group */ - u_short sgs; /* LFS: FS segment shift */ - } __partition_u1; -#define p_cpg __partition_u1.cpg -#define p_sgs __partition_u1.sgs - u_short p_cpg; /* filesystem cylinders per group */ - } d_partitions[MAXPARTITIONS]; /* actually may be more */ -}; - -/* d_type values: */ -#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ -#define DTYPE_MSCP 2 /* MSCP */ -#define DTYPE_DEC 3 /* other DEC (rk, rl) */ -#define DTYPE_SCSI 4 /* SCSI */ -#define DTYPE_ESDI 5 /* ESDI interface */ -#define DTYPE_ST506 6 /* ST506 etc. */ -#define DTYPE_HPIB 7 /* CS/80 on HP-IB */ -#define DTYPE_HPFL 8 /* HP Fiber-link */ -#define DTYPE_FLOPPY 10 /* floppy */ - -#ifdef DKTYPENAMES -static char *dktypenames[] = { - "unknown", - "SMD", - "MSCP", - "old DEC", - "SCSI", - "ESDI", - "ST506", - "HP-IB", - "HP-FL", - "type 9", - "floppy", - 0 -}; -#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1) -#endif - -/* -* Filesystem type and version. -* Used to interpret other filesystem-specific -* per-partition information. -*/ -#define FS_UNUSED 0 /* unused */ -#define FS_SWAP 1 /* swap */ -#define FS_V6 2 /* Sixth Edition */ -#define FS_V7 3 /* Seventh Edition */ -#define FS_SYSV 4 /* System V */ -#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ -#define FS_V8 6 /* Eighth Edition, 4K blocks */ -#define FS_BSDFFS 7 /* 4.2BSD fast file system */ -#define FS_MSDOS 8 /* MSDOS file system */ -#define FS_BSDLFS 9 /* 4.4BSD log-structured file system */ -#define FS_OTHER 10 /* in use, but unknown/unsupported */ -#define FS_HPFS 11 /* OS/2 high-performance file system */ -#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ -#define FS_BOOT 13 /* partition contains bootstrap */ - -#ifdef DKTYPENAMES -static char *fstypenames[] = { - "unused", - "swap", - "Version 6", - "Version 7", - "System V", - "4.1BSD", - "Eighth Edition", - "4.2BSD", - "MSDOS", - "4.4LFS", - "unknown", - "HPFS", - "ISO9660", - "boot", - 0 -}; -#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1) -#endif - -/* -* flags shared by various drives: -*/ -#define D_REMOVABLE 0x01 /* removable media */ -#define D_ECC 0x02 /* supports ECC */ -#define D_BADSECT 0x04 /* supports bad sector forw. */ -#define D_RAMDISK 0x08 /* disk emulator */ -#define D_CHAIN 0x10 /* can do back-back transfers */ - -/* -* Drive data for SMD. -*/ - -#define d_smdflags d_drivedata[0] -#define D_SSE 0x1 /* supports skip sectoring */ -#define d_mindist d_drivedata[1] -#define d_maxdist d_drivedata[2] -#define d_sdist d_drivedata[3] - -/* -* Drive data for ST506. -*/ -#define d_precompcyl d_drivedata[0] -#define d_gap3 d_drivedata[1] /* used only when formatting */ - -/* - * Drive data for SCSI. - */ -#define d_blind d_drivedata[0] - -#ifndef LOCORE -/* -* Structure used to perform a format -* or other raw operation, returning data -* and/or register values. -* Register identification and format -* are device- and driver-dependent. -*/ -struct format_op { - char *df_buf; - int df_count; /* value-result */ - daddr_t df_startblk; - int df_reg[8]; /* result */ -}; - -/* -* Structure used internally to retrieve -* information about a partition on a disk. -*/ -struct partinfo { - struct disklabel *disklab; - struct partition *part; -}; - -/* -* Disk-specific ioctls. -*/ - /* get and set disklabel; DIOCGPART used internally */ -#define DIOCGDINFO _IOR('d', 101, struct disklabel) /* get */ -#define DIOCSDINFO _IOW('d', 102, struct disklabel) /* set */ -#define DIOCWDINFO _IOW('d', 103, struct disklabel) /* set, update disk */ -#define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */ - -/* do format operation, read or write */ -#define DIOCRFORMAT _IOWR('d', 105, struct format_op) -#define DIOCWFORMAT _IOWR('d', 106, struct format_op) - -#define DIOCSSTEP _IOW('d', 107, int) /* set step rate */ -#define DIOCSRETRIES _IOW('d', 108, int) /* set # of retries */ -#define DIOCWLABEL _IOW('d', 109, int) /* write en/disable label */ - -#define DIOCSBAD _IOW('d', 110, struct dkbad) /* set kernel dkbad */ - -#endif LOCORE -.Ed -.Sh SEE ALSO -.Xr disktab 5 , -.Xr disklabel 8 -.Sh HISTORY diff --git a/sbin/fastboot/Makefile b/sbin/fastboot/Makefile deleted file mode 100644 index 1bd7949..0000000 --- a/sbin/fastboot/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/5/93 - -MAN8= fastboot.8 -MLINKS= fastboot.8 fasthalt.8 - -beforeinstall: - install -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ - ${.CURDIR}/fastboot.sh ${DESTDIR}${BINDIR}/fastboot - install -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ - ${.CURDIR}/fasthalt.sh ${DESTDIR}${BINDIR}/fasthalt - -.include <bsd.prog.mk> diff --git a/sbin/fastboot/fastboot.sh b/sbin/fastboot/fastboot.sh deleted file mode 100644 index 6d36f4e..0000000 --- a/sbin/fastboot/fastboot.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh - -# -# Copyright (c) 1985, 1993 -# The Regents of the University of California. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)fastboot.sh 8.1 (Berkeley) 6/5/93 -# - -cp /dev/null /fastboot -exec /sbin/reboot $* diff --git a/sbin/fastboot/fasthalt.sh b/sbin/fastboot/fasthalt.sh deleted file mode 100644 index fce66e1..0000000 --- a/sbin/fastboot/fasthalt.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh - -# -# Copyright (c) 1988, 1993 -# The Regents of the University of California. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by the University of -# California, Berkeley and its contributors. -# 4. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# @(#)fasthalt.sh 8.1 (Berkeley) 6/5/93 -# - -cp /dev/null /fastboot -exec /sbin/halt $* diff --git a/sbin/ft/Makefile b/sbin/ft/Makefile deleted file mode 100644 index 6166c08..0000000 --- a/sbin/ft/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $Id: Makefile,v 1.2 1994/02/07 08:40:16 rgrimes Exp $ - -PROG= ft -MAN8= ft.8 -SRCS= ft.c ftecc.c -COPTS= -O2 -finline-functions -funroll-loops -fexpensive-optimizations - -.include <bsd.prog.mk> diff --git a/sbin/ft/ft.8 b/sbin/ft/ft.8 deleted file mode 100644 index 962001e..0000000 --- a/sbin/ft/ft.8 +++ /dev/null @@ -1,86 +0,0 @@ -.\" Copyright (c) 1980, 1989, 1991 The Regents of the University of California. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)ft.8 -.\" -.Dd February 7, 1994 -.Dt FT 8 -.Os BSD 4 -.Sh NAME -.Nm ft -.Nd QIC 40/80 floppy tape drive controller -.Sh SYNOPSIS -.Nm ft -.Op Fl f Ar tape -.Op Ar description -.Sh DESCRIPTION -The -.Nm ft -command allows multi-volume dump, extract, and view of tape labels, for -any pre-formatted QIC-40/80 tapes. It is totally system dependent, -and has nothing to do with the QIC standards. -.Pp -.Nm ft -is used primarily as a filter for tape i/o. -For example, to save and compress the /usr directory to tape: -.Bd -literal -offset indent -% tar cvzf - /usr | ft "/usr save" -.Ed -.Pp -To extract /usr from tape: -.Bd -literal -offset indent -% ft | tar xvzf - -.Ed -.\" .Sh SEE ALSO -.\" .Xr qtar 1 -.Sh BUGS -Formatting/Verifying is in the works. You will need to use your -existing backup program to do this for the time being. -.Sh NOTES -The floppy tape driver supports tape drives such as the Colorado -Jumbo, Mountain Summit Express, some Archive/Conner models, and -probably many others. These tape drives attach between your floppy -disk controller card and your existing floppy disks' ribbon cable. -This driver does not currently support attachments via a proprietary -tape controller card or by the parallel port. -.Pp -QIC-40/80 drives are more CPU intensive than a SCSI drive. This is -really only a factor if your machine is networked or has multiple concurrent -users. For personal use (i.e. your typical home Unix user), response time -is perfectly acceptable. The tape drives cannot detect write errors. -Instead, they make up for it by using CRC's, error correction, and bad -spot mapping. Formatting time is extremely long because of this. The -drive makes a first pass over the entire tape writing out sectors. It -then makes a second pass at a slower rate than usual (for sensitivity) -to detect bad spots on the tape. Typically it takes an hour to format -a single QIC-80 (120Mb uncompressed) tape. -.Sh AUTHOR -Steve Gerakines <steve2@genesis.nred.ma.us> diff --git a/sbin/ft/ft.c b/sbin/ft/ft.c deleted file mode 100644 index 49aadd3..0000000 --- a/sbin/ft/ft.c +++ /dev/null @@ -1,517 +0,0 @@ -/* - * Copyright (c) 1993, 1994 Steve Gerakines - * - * This is freely redistributable software. You may do anything you - * wish with it, so long as the above notice stays intact. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * ft.c - simple floppy tape filter - * - * 06/07/94 v1.0 ++sg - * Added support for tape retension. Added retries for ecc failures. - * Moved to release. - * - * 01/28/94 v0.3b (Jim Babb) - * Fixed bug when all sectors in a segment are marked bad. - * - * 10/30/93 v0.3 - * Minor revisions. Seems pretty stable. - * - * 09/02/93 v0.2 pl01 - * Initial revision. - * - * usage: ft [ -f tape ] [ description ] - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <signal.h> -#include <time.h> -#include <sys/ftape.h> - -#define DEFQIC "/dev/rft0" - -char buff[QCV_SEGSIZE]; /* scratch buffer */ -char hbuff[QCV_SEGSIZE]; /* header buffer */ -QIC_Header *hptr = (QIC_Header *)hbuff; /* header structure */ -int hsn = -1; /* segment number of header */ -int dhsn = -1; /* segment number of duplicate header */ -int tfd; /* tape file descriptor */ -QIC_Geom geo; /* tape geometry */ -int tvno = 1; /* tape volume number */ -int tvlast; /* TRUE if last volume in set */ -long tvsize = 0; /* tape volume size in bytes */ -long tvtime = NULL; /* tape change time */ -char *tvnote = ""; /* tape note */ -int doretension = 0; /* TRUE if we should retension tape */ - -/* Lookup the badmap for a given track and segment. */ -#define BADMAP(t,s) hptr->qh_badmap[(t)*geo.g_segtrk+(s)] - -/* Retrieve values from a character array. */ -#define UL_VAL(s,p) (*((ULONG *)&(s)[p])) -#define US_VAL(s,p) (*((USHORT *)&(s)[p])) - -#define equal(s1,s2) (strcmp(s1, s2) == 0) - - -/* - * Print tape usage and then leave. - */ -void -usage(void) -{ - fprintf(stderr, "usage: ft [ -r ] [ -f device ] [ \"description\" ]\n"); - exit(1); -} - - -/* - * Check status of tape drive - */ -int -check_stat(int fd, int wr) -{ - int r, s; - int sawit = 0; - - /* get tape status */ - if (ioctl(fd, QIOSTATUS, &s) < 0) { - fprintf(stderr, "could not get drive status\n"); - return(1); - } - - /* wait for the tape drive to become ready */ - while ((s & QS_READY) == 0) { - if (!sawit) { - fprintf(stderr, "waiting for drive to become ready...\n"); - sawit = 1; - } - sleep(2); - if (ioctl(fd, QIOSTATUS, &s) < 0) { - fprintf(stderr, "could not get drive status\n"); - return(1); - } - } - - if ((s & QS_FMTOK) == 0) { - fprintf(stderr, "tape is not formatted\n"); - return(2); - } - - if (wr && (s & QS_RDONLY) != 0) { - fprintf(stderr, "tape is write protected\n"); - return(3); - } - - return(0); -} - - -/* - * Convert time_t value to QIC time value. - */ -ULONG -qtimeval(time_t t) -{ - struct tm *tp; - ULONG r; - - tp = localtime(&t); - r = 2678400 * tp->tm_mon + - 86400 *(tp->tm_mday-1) + - 3600 * tp->tm_hour + - 60 * tp->tm_min + - tp->tm_sec; - r |= (tp->tm_year - 70) << 25; - return(r); -} - - -/* - * Return tm struct from QIC date format. - */ -struct tm * -qtime(UCHAR *qt) -{ - ULONG *vp = (ULONG *)qt; - struct tm t; - ULONG v; - time_t tv; - - v = *vp; - t.tm_year = ((v >> 25) & 0x7f)+70; v &= 0x1ffffff; - t.tm_mon = v / 2678400; v %= 2678400; - t.tm_mday = v / 86400 + 1; v %= 86400; - t.tm_hour = v / 3600; v %= 3600; - t.tm_min = v / 60; v %= 60; - t.tm_sec = v; - t.tm_wday = 0; /* XXX - let mktime do the real work */ - t.tm_yday = 0; - t.tm_isdst = 0; - t.tm_gmtoff = 0; - t.tm_zone = NULL; - tv = mktime(&t); - return(localtime(&tv)); -} - - -/* - * Return a string, zero terminated. - */ -char *qstr(char *str, int nchar) -{ - static char tstr[256]; - strncpy(tstr, str, nchar); - tstr[nchar] = '\0'; - return(tstr); -} - - -/* - * Read header from tape - */ -int -get_header(int fd) -{ - int r, sn, bytes; - QIC_Segment s; - int gothdr = 0; - - if (ioctl(fd, QIOGEOM, &geo) < 0) { - fprintf(stderr, "couldn't determine tape geometry\n"); - return(1); - } - - /* Get the header and duplicate */ - for (sn = 0; sn < 16; sn++) { - s.sg_trk = 0; - s.sg_seg = sn; - s.sg_badmap = 0; - s.sg_data = (UCHAR *)&buff[0]; - ioctl(fd, QIOREAD, &s); - r = check_parity(s.sg_data, 0, s.sg_crcmap); - if (s.sg_data[0] == 0x55 && s.sg_data[1] == 0xaa && - s.sg_data[2] == 0x55 && s.sg_data[3] == 0xaa) { - if (hsn >= 0) { - dhsn = sn; - if (!r && !gothdr) { - fprintf(stderr, "using secondary header\n"); - bcopy(s.sg_data, hbuff, QCV_SEGSIZE); - gothdr = 1; - } - break; - } - hsn = sn; - if (!r) { - bcopy(s.sg_data, hbuff, QCV_SEGSIZE); - gothdr = 1; - } else { - fprintf(stderr, "too many errors in primary header\n"); - } - } - } - - if (!gothdr) { - fprintf(stderr, "couldn't read header segment\n"); - ioctl(fd, QIOREWIND); - return(1); - } - - return(0); -} - - -/* - * Open /dev/tty and ask for next volume. - */ -ask_vol(int vn) -{ - FILE *inp; - int fd; - char c; - - if ((fd = open("/dev/tty", 2)) < 0) { - fprintf(stderr, "argh!! can't open /dev/tty\n"); - exit(1); - } - - fprintf(stderr, "Insert ftfilt volume %02d and press enter:", vn); - read(fd, &c, 1); - close(fd); -} - - -/* - * Return the name of the tape only. - */ -void -do_getname(void) -{ - if (check_stat(tfd, 0)) exit(1); - if (get_header(tfd)) exit(1); - fprintf(stderr, "\"%s\" - %s", - qstr(hptr->qh_tname,44), asctime(qtime(hptr->qh_chgdate))); -} - - -/* - * Extract data from tape to stdout. - */ -void -do_read(void) -{ - int sno, vno, sbytes, r, eccfails; - long curpos; - char *hname; - QIC_Segment s; - - /* Process multiple volumes if necessary */ - vno = 1; - for (;;) { - if (check_stat(tfd, 0)) { - ask_vol(vno); - continue; - } - - if (doretension) { - ioctl(tfd, QIOBOT); - ioctl(tfd, QIOEOT); - ioctl(tfd, QIOBOT); - } - - if (get_header(tfd)) { - ask_vol(vno); - continue; - } - - /* extract volume and header info from label */ - hname = hptr->qh_tname; - hname[43] = '\0'; - tvno = atoi(&hname[11]); - tvlast = (hname[10] == '*') ? 1 : 0; - tvsize = atoi(&hname[14]); - tvnote = &hname[25]; - if (vno != tvno || strncmp(hname, "ftfilt", 6) != 0) { - fprintf(stderr, "Incorrect volume inserted. This tape is:\n"); - fprintf(stderr,"\"%s\" - %s\n", hname, - asctime(qtime(hptr->qh_chgdate))); - ask_vol(vno); - continue; - } - - /* Process this volume */ - curpos = 0; - eccfails = 0; - sno = hptr->qh_first; - while (tvsize > 0) { - s.sg_trk = sno / geo.g_segtrk; - s.sg_seg = sno % geo.g_segtrk; - s.sg_badmap = BADMAP(s.sg_trk,s.sg_seg); - sbytes = sect_bytes(s.sg_badmap) - QCV_ECCSIZE; - s.sg_data = (UCHAR *)&buff[0]; - if (sbytes <= 0) { - sno++; - continue; - } - if (ioctl(tfd, QIOREAD, &s) < 0) perror("QIOREAD"); - - if (check_parity(s.sg_data, s.sg_badmap, s.sg_crcmap)) { - if (++eccfails <= 5) { - fprintf(stderr, - "ft: retry %d at segment %d byte %ld\n", - eccfails, sno, curpos); - continue; - } else - fprintf(stderr, - "ft: *** ecc failure in segment %d at byte %ld\n", - sno, curpos); - } - if (tvsize < sbytes) sbytes = tvsize; - write(1, s.sg_data, sbytes); - tvsize -= sbytes; - curpos += sbytes; - sno++; - eccfails = 0; - } - if (tvlast) break; - ioctl(tfd, QIOREWIND); - ask_vol(++vno); - } -} - - -/* - * Dump data from stdin to tape. - */ -void -do_write(void) -{ - int sno, vno, amt, sbytes; - int c, maxseg, r; - ULONG qnow; - QIC_Segment s; - char tmpstr[80]; - - qnow = qtimeval(time(NULL)); - vno = 1; - - for (;;) { - if (check_stat(tfd, 1)) { - ask_vol(vno); - continue; - } - - if (doretension) { - ioctl(tfd, QIOBOT); - ioctl(tfd, QIOEOT); - ioctl(tfd, QIOBOT); - } - - if (get_header(tfd)) { - ask_vol(vno); - continue; - } - - maxseg = geo.g_segtrk * geo.g_trktape - 1; - sno = hptr->qh_first; - tvno = vno; - tvsize = 0; - tvlast = 0; - - /* Process until end of volume or end of data */ - for (sno = hptr->qh_first; sno < maxseg && tvlast == 0; ++sno) { - /* Prepare to load the next segment */ - s.sg_trk = sno / geo.g_segtrk; - s.sg_seg = sno % geo.g_segtrk; - s.sg_badmap = BADMAP(s.sg_trk,s.sg_seg); - sbytes = sect_bytes(s.sg_badmap) - QCV_ECCSIZE; - s.sg_data = (UCHAR *)&buff[0]; - - /* Ugh. Loop to get the full amt. */ - for (amt = 0; amt < sbytes; amt += r) { - r = read(0, &s.sg_data[amt], sbytes - amt); - if (r <= 0) { - tvlast = 1; - break; - } - } - - /* skip the segment if *all* sectors are flagged as bad */ - if (amt) { - if (amt < sbytes) - bzero(&s.sg_data[amt], sbytes - amt); - r = set_parity(s.sg_data, s.sg_badmap); - if (r) fprintf(stderr, "** warning: ecc problem !!\n"); - if (ioctl(tfd, QIOWRITE, &s) < 0) { - perror("QIOWRITE"); - exit(1); - } - tvsize += amt; - } - } - - /* Build new header info */ - /* ftfilt vol*xx yyyyyyyyyy note56789012345678 */ - /* 01234567890123456789012345678901234567890123 */ - - sprintf(tmpstr, "ftfilt vol%s%02d %010d %s", - (tvlast) ? "*" : " ", tvno, tvsize, tvnote); - strncpy(hptr->qh_tname, tmpstr, 44); - UL_VAL(hptr->qh_chgdate,0) = qnow; - - /* Update the header for this volume */ - if (hsn >= 0) { - s.sg_trk = hsn / geo.g_segtrk; - s.sg_seg = hsn % geo.g_segtrk; - s.sg_badmap = 0; - s.sg_data = (UCHAR *)hbuff; - r = set_parity(s.sg_data, s.sg_badmap); - if (r) fprintf(stderr, "** warning: header ecc problem !!\n"); - if (ioctl(tfd, QIOWRITE, &s) < 0) { - perror("QIOWRITE"); - exit(1); - } - } - if (dhsn >= 0) { - s.sg_trk = dhsn / geo.g_segtrk; - s.sg_seg = dhsn % geo.g_segtrk; - s.sg_badmap = 0; - s.sg_data = (UCHAR *)hbuff; - r = set_parity(s.sg_data, s.sg_badmap); - if (r) fprintf(stderr, "** warning: duphdr ecc problem !!\n"); - if (ioctl(tfd, QIOWRITE, &s) < 0) { - perror("QIOWRITE"); - exit(1); - } - } - ioctl(tfd, QIOREWIND); - if (tvlast) break; - ask_vol(++vno); - } -} - - -/* - * Entry. - */ -void -main(int argc, char *argv[]) -{ - int r, s, i; - char *tape, *getenv(); - - - /* Get device from environment, command line will override. */ - if ((tape = getenv("TAPE")) == NULL) tape = DEFQIC; - - /* Process args. */ - for (i = 1; i < argc; i++) { - if (argv[i][0] != '-') break; - switch (argv[i][1]) { - case 'f': - case 't': - if (i == (argc - 1)) usage(); - tape = argv[++i]; - break; - case 'r': - doretension = 1; - break; - default: - usage(); - } - } - if (i < (argc - 1)) usage(); - if (i < argc) { - tvnote = argv[i]; - if (strlen(tvnote) > 18) argv[i][18] = '\0'; - } - - /* Open the tape device */ - if ((tfd = open(tape, 2)) < 0) { - perror(tape); - exit(1); - } - - if (!isatty(0)) - do_write(); - else if (!isatty(1)) - do_read(); - else - do_getname(); - - close(tfd); - exit(0); -} diff --git a/sbin/ft/ftecc.c b/sbin/ft/ftecc.c deleted file mode 100644 index fbba10f..0000000 --- a/sbin/ft/ftecc.c +++ /dev/null @@ -1,480 +0,0 @@ -/* - * Copyright (c) 1994 Steve Gerakines - * - * This is freely redistributable software. You may do anything you - * wish with it, so long as the above notice stays intact. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * ftecc.c - QIC-40/80 Reed-Solomon error correction - * 05/30/94 v1.0 ++sg - * Did some minor optimization. The multiply by 0xc0 was a dog so it - * was replaced with a table lookup. Fixed a couple of places where - * bad sectors could go unnoticed. Moved to release. - * - * 03/22/94 v0.4 - * Major re-write. It can handle everything required by QIC now. - * - * 09/14/93 v0.2 pl01 - * Modified slightly to fit with my driver. Based entirely upon David - * L. Brown's package. - */ -#include <sys/ftape.h> - -/* Inverse matrix */ -struct inv_mat { - UCHAR log_denom; /* Log of the denominator */ - UCHAR zs[3][3]; /* The matrix */ -}; - - -/* - * Powers of x, modulo 255. - */ -static UCHAR alpha_power[] = { - 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, - 0x87, 0x89, 0x95, 0xad, 0xdd, 0x3d, 0x7a, 0xf4, - 0x6f, 0xde, 0x3b, 0x76, 0xec, 0x5f, 0xbe, 0xfb, - 0x71, 0xe2, 0x43, 0x86, 0x8b, 0x91, 0xa5, 0xcd, - 0x1d, 0x3a, 0x74, 0xe8, 0x57, 0xae, 0xdb, 0x31, - 0x62, 0xc4, 0x0f, 0x1e, 0x3c, 0x78, 0xf0, 0x67, - 0xce, 0x1b, 0x36, 0x6c, 0xd8, 0x37, 0x6e, 0xdc, - 0x3f, 0x7e, 0xfc, 0x7f, 0xfe, 0x7b, 0xf6, 0x6b, - 0xd6, 0x2b, 0x56, 0xac, 0xdf, 0x39, 0x72, 0xe4, - 0x4f, 0x9e, 0xbb, 0xf1, 0x65, 0xca, 0x13, 0x26, - 0x4c, 0x98, 0xb7, 0xe9, 0x55, 0xaa, 0xd3, 0x21, - 0x42, 0x84, 0x8f, 0x99, 0xb5, 0xed, 0x5d, 0xba, - 0xf3, 0x61, 0xc2, 0x03, 0x06, 0x0c, 0x18, 0x30, - 0x60, 0xc0, 0x07, 0x0e, 0x1c, 0x38, 0x70, 0xe0, - 0x47, 0x8e, 0x9b, 0xb1, 0xe5, 0x4d, 0x9a, 0xb3, - 0xe1, 0x45, 0x8a, 0x93, 0xa1, 0xc5, 0x0d, 0x1a, - 0x34, 0x68, 0xd0, 0x27, 0x4e, 0x9c, 0xbf, 0xf9, - 0x75, 0xea, 0x53, 0xa6, 0xcb, 0x11, 0x22, 0x44, - 0x88, 0x97, 0xa9, 0xd5, 0x2d, 0x5a, 0xb4, 0xef, - 0x59, 0xb2, 0xe3, 0x41, 0x82, 0x83, 0x81, 0x85, - 0x8d, 0x9d, 0xbd, 0xfd, 0x7d, 0xfa, 0x73, 0xe6, - 0x4b, 0x96, 0xab, 0xd1, 0x25, 0x4a, 0x94, 0xaf, - 0xd9, 0x35, 0x6a, 0xd4, 0x2f, 0x5e, 0xbc, 0xff, - 0x79, 0xf2, 0x63, 0xc6, 0x0b, 0x16, 0x2c, 0x58, - 0xb0, 0xe7, 0x49, 0x92, 0xa3, 0xc1, 0x05, 0x0a, - 0x14, 0x28, 0x50, 0xa0, 0xc7, 0x09, 0x12, 0x24, - 0x48, 0x90, 0xa7, 0xc9, 0x15, 0x2a, 0x54, 0xa8, - 0xd7, 0x29, 0x52, 0xa4, 0xcf, 0x19, 0x32, 0x64, - 0xc8, 0x17, 0x2e, 0x5c, 0xb8, 0xf7, 0x69, 0xd2, - 0x23, 0x46, 0x8c, 0x9f, 0xb9, 0xf5, 0x6d, 0xda, - 0x33, 0x66, 0xcc, 0x1f, 0x3e, 0x7c, 0xf8, 0x77, - 0xee, 0x5b, 0xb6, 0xeb, 0x51, 0xa2, 0xc3, 0x01 -}; - - -/* - * Log table, modulo 255 + 1. - */ -static UCHAR alpha_log[] = { - 0xff, 0x00, 0x01, 0x63, 0x02, 0xc6, 0x64, 0x6a, - 0x03, 0xcd, 0xc7, 0xbc, 0x65, 0x7e, 0x6b, 0x2a, - 0x04, 0x8d, 0xce, 0x4e, 0xc8, 0xd4, 0xbd, 0xe1, - 0x66, 0xdd, 0x7f, 0x31, 0x6c, 0x20, 0x2b, 0xf3, - 0x05, 0x57, 0x8e, 0xe8, 0xcf, 0xac, 0x4f, 0x83, - 0xc9, 0xd9, 0xd5, 0x41, 0xbe, 0x94, 0xe2, 0xb4, - 0x67, 0x27, 0xde, 0xf0, 0x80, 0xb1, 0x32, 0x35, - 0x6d, 0x45, 0x21, 0x12, 0x2c, 0x0d, 0xf4, 0x38, - 0x06, 0x9b, 0x58, 0x1a, 0x8f, 0x79, 0xe9, 0x70, - 0xd0, 0xc2, 0xad, 0xa8, 0x50, 0x75, 0x84, 0x48, - 0xca, 0xfc, 0xda, 0x8a, 0xd6, 0x54, 0x42, 0x24, - 0xbf, 0x98, 0x95, 0xf9, 0xe3, 0x5e, 0xb5, 0x15, - 0x68, 0x61, 0x28, 0xba, 0xdf, 0x4c, 0xf1, 0x2f, - 0x81, 0xe6, 0xb2, 0x3f, 0x33, 0xee, 0x36, 0x10, - 0x6e, 0x18, 0x46, 0xa6, 0x22, 0x88, 0x13, 0xf7, - 0x2d, 0xb8, 0x0e, 0x3d, 0xf5, 0xa4, 0x39, 0x3b, - 0x07, 0x9e, 0x9c, 0x9d, 0x59, 0x9f, 0x1b, 0x08, - 0x90, 0x09, 0x7a, 0x1c, 0xea, 0xa0, 0x71, 0x5a, - 0xd1, 0x1d, 0xc3, 0x7b, 0xae, 0x0a, 0xa9, 0x91, - 0x51, 0x5b, 0x76, 0x72, 0x85, 0xa1, 0x49, 0xeb, - 0xcb, 0x7c, 0xfd, 0xc4, 0xdb, 0x1e, 0x8b, 0xd2, - 0xd7, 0x92, 0x55, 0xaa, 0x43, 0x0b, 0x25, 0xaf, - 0xc0, 0x73, 0x99, 0x77, 0x96, 0x5c, 0xfa, 0x52, - 0xe4, 0xec, 0x5f, 0x4a, 0xb6, 0xa2, 0x16, 0x86, - 0x69, 0xc5, 0x62, 0xfe, 0x29, 0x7d, 0xbb, 0xcc, - 0xe0, 0xd3, 0x4d, 0x8c, 0xf2, 0x1f, 0x30, 0xdc, - 0x82, 0xab, 0xe7, 0x56, 0xb3, 0x93, 0x40, 0xd8, - 0x34, 0xb0, 0xef, 0x26, 0x37, 0x0c, 0x11, 0x44, - 0x6f, 0x78, 0x19, 0x9a, 0x47, 0x74, 0xa7, 0xc1, - 0x23, 0x53, 0x89, 0xfb, 0x14, 0x5d, 0xf8, 0x97, - 0x2e, 0x4b, 0xb9, 0x60, 0x0f, 0xed, 0x3e, 0xe5, - 0xf6, 0x87, 0xa5, 0x17, 0x3a, 0xa3, 0x3c, 0xb7 -}; - - -/* - * Multiplication table for 0xc0. - */ -static UCHAR mult_c0[] = { - 0x00, 0xc0, 0x07, 0xc7, 0x0e, 0xce, 0x09, 0xc9, - 0x1c, 0xdc, 0x1b, 0xdb, 0x12, 0xd2, 0x15, 0xd5, - 0x38, 0xf8, 0x3f, 0xff, 0x36, 0xf6, 0x31, 0xf1, - 0x24, 0xe4, 0x23, 0xe3, 0x2a, 0xea, 0x2d, 0xed, - 0x70, 0xb0, 0x77, 0xb7, 0x7e, 0xbe, 0x79, 0xb9, - 0x6c, 0xac, 0x6b, 0xab, 0x62, 0xa2, 0x65, 0xa5, - 0x48, 0x88, 0x4f, 0x8f, 0x46, 0x86, 0x41, 0x81, - 0x54, 0x94, 0x53, 0x93, 0x5a, 0x9a, 0x5d, 0x9d, - 0xe0, 0x20, 0xe7, 0x27, 0xee, 0x2e, 0xe9, 0x29, - 0xfc, 0x3c, 0xfb, 0x3b, 0xf2, 0x32, 0xf5, 0x35, - 0xd8, 0x18, 0xdf, 0x1f, 0xd6, 0x16, 0xd1, 0x11, - 0xc4, 0x04, 0xc3, 0x03, 0xca, 0x0a, 0xcd, 0x0d, - 0x90, 0x50, 0x97, 0x57, 0x9e, 0x5e, 0x99, 0x59, - 0x8c, 0x4c, 0x8b, 0x4b, 0x82, 0x42, 0x85, 0x45, - 0xa8, 0x68, 0xaf, 0x6f, 0xa6, 0x66, 0xa1, 0x61, - 0xb4, 0x74, 0xb3, 0x73, 0xba, 0x7a, 0xbd, 0x7d, - 0x47, 0x87, 0x40, 0x80, 0x49, 0x89, 0x4e, 0x8e, - 0x5b, 0x9b, 0x5c, 0x9c, 0x55, 0x95, 0x52, 0x92, - 0x7f, 0xbf, 0x78, 0xb8, 0x71, 0xb1, 0x76, 0xb6, - 0x63, 0xa3, 0x64, 0xa4, 0x6d, 0xad, 0x6a, 0xaa, - 0x37, 0xf7, 0x30, 0xf0, 0x39, 0xf9, 0x3e, 0xfe, - 0x2b, 0xeb, 0x2c, 0xec, 0x25, 0xe5, 0x22, 0xe2, - 0x0f, 0xcf, 0x08, 0xc8, 0x01, 0xc1, 0x06, 0xc6, - 0x13, 0xd3, 0x14, 0xd4, 0x1d, 0xdd, 0x1a, 0xda, - 0xa7, 0x67, 0xa0, 0x60, 0xa9, 0x69, 0xae, 0x6e, - 0xbb, 0x7b, 0xbc, 0x7c, 0xb5, 0x75, 0xb2, 0x72, - 0x9f, 0x5f, 0x98, 0x58, 0x91, 0x51, 0x96, 0x56, - 0x83, 0x43, 0x84, 0x44, 0x8d, 0x4d, 0x8a, 0x4a, - 0xd7, 0x17, 0xd0, 0x10, 0xd9, 0x19, 0xde, 0x1e, - 0xcb, 0x0b, 0xcc, 0x0c, 0xc5, 0x05, 0xc2, 0x02, - 0xef, 0x2f, 0xe8, 0x28, 0xe1, 0x21, 0xe6, 0x26, - 0xf3, 0x33, 0xf4, 0x34, 0xfd, 0x3d, 0xfa, 0x3a -}; - - -/* - * Return number of sectors available in a segment. - */ -int -sect_count(ULONG badmap) -{ - int i, amt; - - for (amt = QCV_BLKSEG, i = 0; i < QCV_BLKSEG; i++) - if (badmap & (1 << i)) amt--; - return(amt); -} - - -/* - * Return number of bytes available in a segment. - */ -int -sect_bytes(ULONG badmap) -{ - int i, amt; - - for (amt = QCV_SEGSIZE, i = 0; i < QCV_BLKSEG; i++) - if (badmap & (1 << i)) amt -= QCV_BLKSIZE; - return(amt); -} - - -/* - * Multiply two numbers in the field. - */ -static inline UCHAR -multiply(UCHAR a, UCHAR b) -{ - int tmp; - - if (!a || !b) return(0); - tmp = alpha_log[a] + alpha_log[b]; - if (tmp > 254) tmp -= 255; - return(alpha_power[tmp]); -} - - -/* - * Multiply by an exponent. - */ -static inline UCHAR -multiply_out(UCHAR a, int b) -{ - int tmp; - - if (!a) return(0); - tmp = alpha_log[a] + b; - if (tmp > 254) tmp -= 255; - return(alpha_power[tmp]); -} - - -/* - * Divide two numbers. - */ -static inline UCHAR -divide(UCHAR a, UCHAR b) -{ - int tmp; - - if (!a || !b) return(0); - tmp = alpha_log[a] - alpha_log[b]; - if (tmp < 0) tmp += 255; - return (alpha_power[tmp]); -} - - -/* - * Divide using exponent. - */ -static inline UCHAR -divide_out(UCHAR a, UCHAR b) -{ - int tmp; - - if (!a) return 0; - tmp = alpha_log[a] - b; - if (tmp < 0) tmp += 255; - return (alpha_power[tmp]); -} - - -/* - * This returns the value z^{a-b}. - */ -static inline UCHAR -z_of_ab(UCHAR a, UCHAR b) -{ - int tmp = a - b; - - if (tmp < 0) tmp += 255; - return(alpha_power[tmp]); -} - - -/* - * Calculate the inverse matrix for two or three errors. Returns 0 - * if there is no inverse or 1 if successful. - */ -static inline int -calculate_inverse(int nerrs, int *pblk, struct inv_mat *inv) -{ - /* First some variables to remember some of the results. */ - UCHAR z20, z10, z21, z12, z01, z02; - UCHAR i0, i1, i2; - UCHAR iv0, iv1, iv2; - - if (nerrs < 2) return(1); - if (nerrs > 3) return(0); - - i0 = pblk[0]; i1 = pblk[1]; i2 = pblk[2]; - if (nerrs == 2) { - /* 2 errs */ - z01 = alpha_power[255 - i0]; - z02 = alpha_power[255 - i1]; - inv->log_denom = (z01 ^ z02); - if (!inv->log_denom) return(0); - inv->log_denom = 255 - alpha_log[inv->log_denom]; - - inv->zs[0][0] = multiply_out( 1, inv->log_denom); - inv->zs[0][1] = multiply_out(z02, inv->log_denom); - inv->zs[1][0] = multiply_out( 1, inv->log_denom); - inv->zs[1][1] = multiply_out(z01, inv->log_denom); - } else { - /* 3 errs */ - z20 = z_of_ab (i2, i0); - z10 = z_of_ab (i1, i0); - z21 = z_of_ab (i2, i1); - z12 = z_of_ab (i1, i2); - z01 = z_of_ab (i0, i1); - z02 = z_of_ab (i0, i2); - inv->log_denom = (z20 ^ z10 ^ z21 ^ z12 ^ z01 ^ z02); - if (!inv->log_denom) return(0); - inv->log_denom = 255 - alpha_log[inv->log_denom]; - - iv0 = alpha_power[255 - i0]; - iv1 = alpha_power[255 - i1]; - iv2 = alpha_power[255 - i2]; - i0 = alpha_power[i0]; - i1 = alpha_power[i1]; - i2 = alpha_power[i2]; - inv->zs[0][0] = multiply_out(i1 ^ i2, inv->log_denom); - inv->zs[0][1] = multiply_out(z21 ^ z12, inv->log_denom); - inv->zs[0][2] = multiply_out(iv1 ^ iv2, inv->log_denom); - inv->zs[1][0] = multiply_out(i0 ^ i2, inv->log_denom); - inv->zs[1][1] = multiply_out(z20 ^ z02, inv->log_denom); - inv->zs[1][2] = multiply_out(iv0 ^ iv2, inv->log_denom); - inv->zs[2][0] = multiply_out(i0 ^ i1, inv->log_denom); - inv->zs[2][1] = multiply_out(z10 ^ z01, inv->log_denom); - inv->zs[2][2] = multiply_out(iv0 ^ iv1, inv->log_denom); - } - return(1); -} - - -/* - * Determine the error magnitudes for a given matrix and syndromes. - */ -static inline void -determine(int nerrs, struct inv_mat *inv, UCHAR *ss, UCHAR *es) -{ - UCHAR tmp; - int i, j; - - for (i = 0; i < nerrs; i++) { - es[i] = 0; - for (j = 0; j < nerrs; j++) - es[i] ^= multiply(ss[j], inv->zs[i][j]); - } -} - - -/* - * Compute the 3 syndrome values. - */ -static inline int -compute_syndromes(UCHAR *data, int nblks, int col, UCHAR *ss) -{ - UCHAR r0, r1, r2, t1, t2; - UCHAR *rptr; - - rptr = data + col; - data += nblks << 10; - r0 = r1 = r2 = 0; - while (rptr < data) { - t1 = *rptr ^ r0; - t2 = mult_c0[t1]; - r0 = t2 ^ r1; - r1 = t2 ^ r2; - r2 = t1; - rptr += QCV_BLKSIZE; - } - if (r0 || r1 || r2) { - ss[0] = divide_out(r0 ^ divide_out(r1 ^ divide_out(r2, 1), 1), nblks); - ss[1] = r0 ^ r1 ^ r2; - ss[2] = multiply_out(r0 ^ multiply_out(r1 ^ multiply_out(r2, 1), 1), nblks); - return(0); - } - return(1); -} - - -/* - * Calculate the parity bytes for a segment, returns 0 on success (always). - */ -int -set_parity (UCHAR *data, ULONG badmap) -{ - UCHAR r0, r1, r2, t1, t2; - UCHAR *rptr; - int max, row, col; - - max = sect_count(badmap) - 3; - col = QCV_BLKSIZE; - while (col--) { - rptr = data; - r0 = r1 = r2 = 0; - row = max; - while (row--) { - t1 = *rptr ^ r0; - t2 = mult_c0[t1]; - r0 = t2 ^ r1; - r1 = t2 ^ r2; - r2 = t1; - rptr += QCV_BLKSIZE; - } - *rptr = r0; rptr += QCV_BLKSIZE; - *rptr = r1; rptr += QCV_BLKSIZE; - *rptr = r2; - data++; - } - return(0); -} - - -/* - * Check and correct errors in a block. Returns 0 on success, - * 1 if failed. - */ -int -check_parity(UCHAR *data, ULONG badmap, ULONG crcmap) -{ - int crcerrs, eblk[3]; - int col, row; - int i, j, nblks; - UCHAR ss[3], es[3]; - int i1, i2, saverrs; - struct inv_mat inv; - - nblks = sect_count(badmap); - - /* Count the number of CRC errors and note their locations. */ - crcerrs = 0; - if (crcmap) { - for (i = 0; i < nblks; i++) { - if (crcmap & (1 << i)) { - if (crcerrs == 3) return(1); - eblk[crcerrs++] = i; - } - } - } - - /* Calculate the inverse matrix */ - if (!calculate_inverse(crcerrs, eblk, &inv)) return(1); - - /* Scan each column for problems and attempt to correct. */ - for (col = 0; col < QCV_BLKSIZE; col++) { - if (compute_syndromes(data, nblks, col, ss)) continue; - es[0] = es[1] = es[2] = 0; - - /* Analyze the error situation. */ - switch (crcerrs) { - case 0: /* 0 errors >0 failures */ - if (!ss[0]) return(1); - eblk[crcerrs] = alpha_log[divide(ss[1], ss[0])]; - if (eblk[crcerrs] >= nblks) return(1); - es[0] = ss[1]; - if (++crcerrs > 3) return(1); - break; - - case 1: /* 1 error (+ possible failures) */ - i1 = ss[2] ^ multiply_out(ss[1], eblk[0]); - i2 = ss[1] ^ multiply_out(ss[0], eblk[0]); - if (!i1 && !i2) { /* only 1 error */ - inv.zs[0][0] = alpha_power[eblk[0]]; - inv.log_denom = 0; - } else if (!i1 || !i2) { /* too many errors */ - return(1); - } else { /* add failure */ - eblk[crcerrs] = alpha_log[divide(i1, i2)]; - if (eblk[crcerrs] >= nblks) return(1); - if (++crcerrs > 3) return(1); - if (!calculate_inverse(crcerrs, eblk, &inv)) return(1); - } - determine(crcerrs, &inv, ss, es); - break; - - case 2: /* 2 errors */ - case 3: /* 3 errors */ - determine(crcerrs, &inv, ss, es); - break; - - default: - return(1); - } - - /* Make corrections. */ - for (i = 0; i < crcerrs; i++) { - data[(eblk[i] << 10) | col] ^= es[i]; - ss[0] ^= divide_out(es[i], eblk[i]); - ss[1] ^= es[i]; - ss[2] ^= multiply_out(es[i], eblk[i]); - } - if (ss[0] || ss[1] || ss[2]) return(1); - } - return(0); -} diff --git a/sbin/ip_mroute_mod/Makefile b/sbin/ip_mroute_mod/Makefile deleted file mode 100644 index 7e78283..0000000 --- a/sbin/ip_mroute_mod/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# $Id$ - -.PATH: ${.CURDIR}/../../sys/netinet -KMOD= ip_mroute_mod -SRCS= ip_mroute.c -NOMAN= -CFLAGS+= -DMROUTE_LKM -DMROUTING - -.include <bsd.kmod.mk> diff --git a/sbin/ipfw/ipfirewall.4 b/sbin/ipfw/ipfirewall.4 deleted file mode 100644 index f11cbd54..0000000 --- a/sbin/ipfw/ipfirewall.4 +++ /dev/null @@ -1,206 +0,0 @@ -.Dd November 16, 1994 -.Dt IPFW(4)/IPACCT 4 -.Os -.Sh NAME - - ipfirewall,ipfw - IP packets filter. - ipaccounting,ipacct - IP packets/traffic accounting. - -.Sh SYNOPSIS -#include <netinet/ip_fw.h> - -setsockopt(raw_socket,IPPROTO_IP,<ipfw/ipacct option>, - <struct ip|struct ipfw>,<size>) - -Ipfw options: - IP_FW_ADD_BLK - add entry to blocking chain. - IP_FW_ADD_FWD - add entry to forwarding chain. - IP_FW_CHK_BLK - check ip packet against blocking chain. - IP_FW_CHK_FWD - check ip packet against forwarding chain. - IP_FW_DEL_BLK - delete entry from blocking chain. - IP_FW_DEL_FWD - delete entry from forwarding chain. - IP_FW_FLUSH - flush all blocking & forwarding chain entries. - IP_FW_POLICY - define default ipfw policy. - -Ipacct options: - IP_ACCT_ADD - add entry to accounting chain. - IP_ACCT_DEL - delete entry from accounting chain. - IP_ACCT_FLUSH - flush all accounting chain entries. - IP_ACCT_ZERO - zero all accounting chain entries. - -Ipfw/ipacct entry structure: - #define IP_FW_MAX_PORTS 10 - -struct ip_fw { - struct ip_fw *next; - struct in_addr src, dst; - struct in_addr src_mask, dst_mask; - u_short flags; - u_short n_src_p, n_dst_p; - u_short ports[IP_FW_MAX_PORTS]; - u_long p_cnt,b_cnt; -} - -Flags values for "flags" field: - IP_FW_F_ALL - The entry should match all IP packets. - IP_FW_F_TCP - The entry should match TCP packets. - IP_FW_F_UDP - The entry should match UDP packets. - IP_FW_F_ICMP - The entry should match ICMP packets. - IP_FW_F_KIND - Mask value to separate protocol kind. - IP_FW_F_ACCEPT - This entry is accepting ( see below ) - IP_FW_F_SRNG - Source ports are range ( see below ) - IP_FW_F_DRNG - Destination ports are range ( see below ) - IP_FW_F_PRN - Print this entry ( see below ) - IP_FW_F_BIDIR - This acct entry is bidirectional ( see below ) - IP_FW_F_MASK - Mask to match all valid flag bits. - -Kernel symbols to kvm_nlist(): - struct ip_fw *ip_fw_blk_chain - chain of forwarding entries. - struct ip_fw *ip_fw_fwd_chain - chain of blocking entries. - int ip_fw_policy - default policy. - struct ip_fw *ip_acct_chain - chain of accounting entries. - -Options in the kernel configuration file: - IPFIREWALL - enable ipfirewall. - IPFIREWALL_VERBOSE - enable firewall output ( see below ) - DEBUG_IPFIREWALL - enable extensive debugging output. - IPACCT - enable ipaccounting. - -.Sh DESCRIPTION -Ipfirewall (later ipfw) is a system facility,which allows filtering -of incoming and/or forwarding packets on the protocol+source/destination -adress/ports base. -Ipaccounting (later ipacct) is a system facility,which allows counting -of incoming,outgoing and forwarding traffic by packet/byte count. - -Basic idea is that every packet checked against number of entries -in several chains.There are 3 chains: - Blocking - this chain defines whenever packet should be accepted - ever for local delivery or for forwarding. - Forwarding - this chain defines whenever packet should be accepted - for forwarding only. - Accounting - this chain defines types of packets , which should be - counted. - -Entries added to chains by means of setsockopt() call on RAW IP socket. -Options to add/remove specific entries or to flush all entries described -above. Value passed to setsockopt() is a value of struct ip_fw for -entry. If entry added , it checked by such rules that when we start -searching chain for matching entry the first matching is the best match, -[ or at least one of them :^) ]. - That means: - * First in chain entries with specific protocol and small ranges - of src/dst adresses and ports. - * Later going entries with wider ranges of ports and adresses. - * Later entries matching every port for some adress range. - * Later universal entries matching any protocol. - -While deleting entry , every entry which equal to that passed to -setsockopt() will be removed. -Flush removes all entries. - -Every entry have several fields,by which packets matched: - struct ip_fw *next - next entry in chain.(Set internally) - - struct in_addr src - source adress to be matched. - struct in_addr src_mask - source adress mask. - To match whole networks/subnets or adress groups - mask bits should be zeroed here and also - in src_mask field. Valuable bits should be set - in src_mask field. - struct in_addr dst - destination adress to be matched. - struct in_addr dst_mask - destination adress mask. - - u_short flags - flags field.See exact description of flags meaning - in description later. - - u_short n_src_p - number of source ports in "ports" array. - u_short n_dst_p - number of destination ports in "ports" array. - u_short ports[] - ports array.Overall length currently defined - to reasonable maximum - 10,and could be changed. - The packet's src port can ever match one of - ports[0] ... ports[--n_src_p] numbers,or if - flag IP_FW_F_SRNG set take port[0] as bottom - range value and ports[1] as top one.n_src_p should - be set to 2 then.If n_src_p equal to 0 , every port - match. The same rules apply to packet's dst port, - except that it matched against ports[n_src_p] ... - ... ports[n_src_p+n_dst_p--],or if IP_FW_F_DRNG set, - range is ports[n_src_p] to ports[n_srcp++]. - - u_long p_cnt - packets count for ipacct entries. - u_long b_cnt - bytes count for ipacct entries. - -Packet matching proceeds in following way: - -a) If packet entry protocol set to ALL, see c). - -b) If entry protocol set to TCP/UDP/ICMP and packet protocol - different - no match,if packet protocol and entry protocol - same - continue. - -c) If source addres pattern does not equal to packets sources adress - masked with src_mask , or destination pattern not equal to packets - destination adress masked with dst_mask - no match. - If they does and protocol set to ALL/ICMP - got match. - If they does and protocol set to TCP/UDP - continue. - -d) If src port doesn't match or dst port doesn't match - all - packet don't match. If they does - got match. - -In ipfw packet matched consequently against every chain entry. -Search continues untill first matching entry found.If IP_FW_F_ACCEPT -flag set - packet accepted.If it is not set - packet denied. -If no matching entry found , all unmatched packets ever accepted or -denied depending on global polici value. It can be set with -IP_FW_POLICY raw socket option. Deny value is 0, other values -(default 1) is accept. - -Entries can be added with IP_FW_F_PRN flag set.If kernel compiled -with IPFIREWALL_VERBOSE option,packets matching this entries will -be printed by kernel printf's. - -If some chain is empty,every packet accepted by this chain no -matter what default policy is. - -To check whenever or not packet denied by some chain , checking -options to setsockopt() can be issued. Then the argument is -a buffer representing ip packet,thus it has to be -struct ip + struct tcphdr . -Then setsockopt() return value 0 on accept or another on deny. - -Ipaccounting entries added the same way as ipfw ones.Packet checked -against all entries in chain and values of p_cnt and b_cnt in matching -entries rised.p_cnt rises by 1 and b_cnt by ip_len value of ip packet. -Thus all traffic size counted including IP headers. - -If IP_FW_F_BIDIR flag is set in accounting entry,packets counted are -those which match entry in standart way along with packets which match -entry while their source and destination addr/port pairs swapped. - -Zero option allows all accounting to be cleared. - -.Sh DIAGNOSTICS - -[EINVAL] The IP option field was improperly formed; an option - field was shorter than the minimum value or longer than - the option buffer provided.An structural error in - ip_fw structure occured (n_src_p+n_dst_p too big, - ports set for ALL/ICMP protocols etc.) - -.Sh SEE ALSO - -ip(4), setsockopt(2), kvm_nlist(3), kvm_read(3) - -.Sh BUGS - Ipfw/ipacct facilities are new and , although serious bugs has -been tracked,some less important ones expected. - This man page also uncomplete bad styled. - -.Sh HISTORY - Ipfw facility has been intitially written as package to BSDI -by Daniel Boulet <danny@BouletFermat.ab.ca>. - It has been havily modified and ported to FreeBSD 2.0 -by Ugen J.S.Antsilevich <ugen@NetVision.net.il> - Ipacct facility written for FreeBSD 2.0 -by Ugen J.S.Antsilevich <ugen@NetVision.net.il> diff --git a/sbin/ipfw/ipfw.1 b/sbin/ipfw/ipfw.1 deleted file mode 100644 index 720b259..0000000 --- a/sbin/ipfw/ipfw.1 +++ /dev/null @@ -1,527 +0,0 @@ -.\" -.\" ipfw - a utility for manipulating the configuration of an IP firewall. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" @(#)ipfw.1 -.\" -.TH ipfw 1 "October 27, 1994" "" "FreeBSD" - -.SH NAME -ipfw - a utility for manipulating the configuration of an IP firewall. -.SH SYNOPSIS -.na -.B ipfw -.RB [options] -.SH DESCRIPTION -The -.B ipfw -command is used to configure an active IP firewall, setting masks on just -what sites are allowed to connect through it, which packets are rejected, -etc. -.SH OPTIONS -The command-line syntax of this command is rather involved, and rather than -spend a lot of time that I just don't have at the moment creating a -.B real -man page, with properly formatted sections and all, I'm just going to loosely -format the README I got. This really needs an nroff expert to go through -it with a chainsaw and do a -.N REAL -job of formatting it! This all looks rather horrible at present, and -I would actually almost recommend that you simply read the man page text -directly, rather than trying to format it. Sorry, but I do NOT speak -nroff, nor do I ever wish to learn how! :-) [-jkh]. -.PP -For a sample kernel configuration file that will enable the right kernel -features necessary for firewalling, see -.I /sys/i386/conf/IPFIREWALL -. -.PP -.B WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! -.PP -This utility can be used to put your machine into very dysfunctional state, -so if you want to test it then you should first make sure to read this man page -all the way through, and don't run it anywhere from the system console! -Using -.I ipfw -incorrectly is a really good way to kick yourself off your own machine -if you're logged in over a network! Also make sure to never set this -utility to be setuid root! It's a blatant security hole that way. -Instead, run it as root or from "/etc/rc.local" as part of the boot process. -It's also a good idea to use the checkb or checkf command options (see below) -to pass some test packets through the firewalls that you've defined before -going "live". -.PP -You may find it useful to create a file in which the first line is -.I firewall flush -to flush any existing firewalls before defining the explicit firewalls -that you wish to use. This will ensure that you're always working from a -known state. -.PP -The syntax for the -.BI ipfirewall -command option is rather complex and yet simple at the same time (if you know -what I mean). There are seven sub-commands, and probably the easiest way to -get into this is to give you a roughly BNF style grammar for the command -(curly brackets are used for precedence, alternatives are separated by |, -optional things are enclosed in square brackets, white space is required if -it appears below and must not appear if there isn't any between the tokens -below (i.e. no white space around periods, colons or slashes, whitespace -required between all other tokens)): -.PP -.nf - command ::= ipfirewall <list> | <flush> | <check> | <add> | <del> - <list> ::= list - <flush> ::= flush - <check> ::= { checkb[locking] | checkf[orwarding] } <chkparms> - <add> ::= { addb[locking] | addf[orwarding] } <add-del-parms> - <del> ::= { delb[locking] | delf[orwarding] } <add-del-parms> - <chkparms> ::= <protocol> from <ipaddr> <port> to <ipaddr> <port> - <protocol> ::= tcp | udp - <ipaddr> ::= <int>.<int>.<int>.<int> | <hostname> - <hostname> ::= a host name from /etc/hosts - <port> ::= <int> | <service> - <service> ::= a service from /etc/services - <int> ::= a non-negative integer - <add-del-parms> ::= { accept | deny } { <universal_firewall> | <protocol_firewall> } - <universal_firewall> ::= all from <masked_ipaddr> to <masked_ipaddr> - <masked_ipaddr> ::= { <ipaddr>/<bits> } | { <ipaddr>:<ipaddr> } | <ipaddr> - <bits> ::= integer in the range 0 to 32 inclusive - <protocol_firewall> ::= <protocol> from <end_firewall> to <end_firewall> - <end_firewall> ::= <masked_ipaddr> <port_list> - <port_list> ::= [ <port>:<port> ] <sub_port_list> - <sub_port_list> ::= <port> [ <sub_port_list> ] -.fi -.PP -Although I think that the above grammar is complete, it isn't exactly what -one would call easy to comprehend! Here's the basic idea along with what -each of the forms mean: -.PP -The -.I ipfirewall list -command prints a list of the firewalls on both the -forwarding and blocking chain in some more or less comprehensible format. -.PP -The -.I ipfirewall flush -command empties the two firewall chains. -.PP -The -.I ipfirewall addblocking -and -.I ipfirewall addforwarding -commands take a firewall description and add the firewall to the appropriate -firewall chain. Note that you'll probably need to add some descriptions more -then once, which will naturally take more then one entry in memory. It does -not lead to significant degradation of performance, so don't worry about it. -.PP -The -.I ipfirewall delblocking -and -.I ipfirewall delforwarding -commands take a firewall description and delete the firewall from the -appropriate firewall chain. The description must exactly match that given -to an earlier add command. One delete command removes ALL matching entries -from firewall chains. -.PP -There are two basic kinds of firewall descriptions. Universal firewall -descriptions match all IP packets between specified pairs of hosts. -Universal firewalls only check IP addresses (e.g. they match any combination -of protocol and port numbers). Protocol-specific firewalls match either -TCP/IP or UDP/IP packets between specified pairs of hosts. In addition -to host descriptions, protocol-specific firewalls optionally take a -description of which port numbers to match. -.PP -A host description consists of an IP address and a mask. The IP address -is specified as either a domain name or in the familiar -nn.nn.nn.nn format. The mask indicates how much of the IP address -should be looked at when vetting packets. There are two ways to -specify the mask. The first way is to suffix the IP address in the -firewall with a slash and an integer in the range 0 through 32 inclusive. -This integer is taken to be the number of high order bits of the IP -address which are to be checked (for example, 192.153.211.0/24 checks -the top 24 bits of the IP address, 192.153.211.17/32 checks all the -bits and 0.0.0.0/0 checks none of the bits (i.e. all IP addresses are -matched by this example)). The second way to specify a mask is to -suffix the IP address with a colon followed by another IP address. -This second address is the mask. Specifications equivalent to the -above three examples using this syntax would be -.PP -.nf -192.153.211.0:255.255.255.0 -192.153.211.17:255.255.255.255 -0.0.0.0:0.0.0.0 -.fi -.PP -The first form is taken from the syntax accepted by a Telebit NetBlazer. -The second form is more along the lines of how a netmask is specified -in /etc/netmasks. Finally, if no mask is specified then a mask of all -1's is supplied (i.e. no mask is equivalent to /32 or :255.255.255.255). -.PP -The optional description of port numbers to mask can take three forms. -The simplest form is to omit the list in which case all port numbers -match. The next form is to specify a list of port numbers (either as -positive integers or service names from /etc/services). The final form -is actually a special case of the second form in which the first pair -of port numbers is separated by a colon instead of white space. This -pair specifies a range of port numbers (i.e. x:y specifies that all -ports between x and y inclusive should match). A port description -matches a particular port number if any of the following is true: -.nf - - the port description is null - - - the first pair of port numbers is a range and the port number - is in the range (inclusive) - - - the port number is equal to any of the port numbers in the list -.fi -.PP -There is a limit of a total of 10 port numbers in the source and -destination port lists. This limit is arbitrary and easy to increase. -It is determined by the value of the IP_FIREWALL_MAX_PORTS #define -variable in ip_firewall.h. Each increase of 1 for this value adds two -bytes to the size of each firewall. Since the size of a firewall is only -slightly over 30 bytes right now, this limit of 10 could probably -be increased by quite a bit before it became a concern. I've been -thinking of increasing it to 20 which would be longer than any -reasonable firewall would need and would only consume 20 more bytes -per firewall. The counter argument to any increase is that it is -always possible to construct an equivalent set of two or more firewalls -that behaves like a single firewall with a really long port list. -.PP -This probably all sounds hopelessly complicated. It is actually not -all that tricky (I'm just not very good at explaining it yet). A few -examples will probably help a lot now: -.PP -Block all IP packets originating from the host hackers-den: -.PP -.nf - ipfirewall addb deny all from hackers-den to 0.0.0.0/0 -.fi -.PP -Block all telnet packets to our telnet server from anywhere: -.PP -.nf - ipfirewall addb deny tcp from 0.0.0.0/0 to mymachine/32 telnet -.fi -.PP -Don't forward telnet, rlogin and rsh packets onto our local -class C network: -.PP -.nf - ipfirewall addf deny tcp from 0.0.0.0/0 to ournetwork/24 telnet login shell -.fi -.PP -Don't let anyone on the local machine or any machine inside -our local network ftp access to games.com: -.PP -.nf - ipfirewall addb deny tcp from games.com ftp to 0.0.0.0/0 -.fi -.PP -This last one might look a little strange. It doesn't prevent -anyone from sending packets to the games.com ftp server. What it -does do is block any packets that the games.com ftp server sends -back! -.PP -The -.I ipfirewall checkblocking -and -.I ipfirewall checkforwarding -commands take a description of an IP packet and check to see if the blocking -or forwarding chain of firewalls respectively accept or reject the packet. -It is used to make sure that the firewalls that you've defined work as -expected. The basic syntax is probably best understood by looking at -a couple of examples: -.PP -.nf - ipfirewall checkb from bsdi.com 3001 to mymachine telnet -.fi -.PP -checks to see if the blocking firewall will block a telnet packet from -a telnet session originating on bsdi.com to the host mymachine will be -blocked or not. Note that someone connecting to our telnet server -could be using practically any port number. To be really sure, the -firewall used to prevent access should be as simple as possible and/or -you should try a variety of port numbers in addition to the rather -arbitrarily chosen port of 3001. -.PP -One final note on the check* ,add* and del* command syntax. The noise word -"to" exists in the syntax so that I can detect the end of a list of -port numbers in the from description. Since I needed a noise word to -detect this case, I added the noise word "from" in front of the from -case for consistency. -.PP -Finally, have a look at the file -.I "/usr/share/misc/ipfw.samp.filters" -. It is the set of filters that I run at home [Danny]. -.PP -Also check -.I "/usr/share/misc/ipfw.samp.scripts" -For examples of individual access restrictions. -We [NetVision] use those for our dial-in PPP/SLIP users to allow some of them -to access our internal networks, while disallowing others. -This way we open access for the user's IP when he enters the system and shut it -down when he leaves. All such changes may be applyed at any time, -and so entries added and deleted from firewall while the system is -is working have no other side effects [Ugen]. - -.SH "TECHNICAL DETAILS" -A bit of a description of how the firewalls are applied (i.e. what happens in -the kernel) may be instructive to the advanced firewall-builder: -.PP -When an IP packet is received, the ipintr() routine in ip_input.c is -called. This routine does a bit of basic error checking. If it -detects any errors in the packet it generally drops the packet on -the floor. The idea behind the ipfirewall facility is to treat packets -that we don't want to accept as bad packets (i.e. drop them on the -floor). The ipfirewall facility intercedes in the normal processing -at two points. Just after the basic sanity checks are done, we pass -any packets not targeted at the loopback network (127.0.0.0/8) to the -firewall checker along with the chain of blocking firewalls.If the firewall -checker tells us to block the packet then we branch to the "bad:" label -in ipintr() which is where all bad packets are dropped on the floor. -Otherwise, we allow normal processing of the packet to continue. The -exact point at which we intercede was chosen to be after the basic -sanity checking and before the option processing is done. We want to -be after the basic sanity checking so that we don't have to be able -to handle complete garbage. We want to be before the option processing -because option processing is done in separate rather complex routine. -Why bother doing this special processing if we might be dropping the -packet? -.PP -The second point at which we intercede is when a packet is about to be -forwarded to another host. All such packets are passed to the ip_forward -routine. The ipfirewall code is at the very top of this routine. If -the packet isn't targetted at the loopback interface (is it possible -that it could be when we reach this point? I doubt it but safety first) -then pass the packet to the firewall checker along with the forwarding -firewall chain. If the firewall checker indicates that the packet should -not be forwarded then we drop in (using code copied from a few lines -further into the routine which drops broadcast packets which are not -to be forwarded). -.PP -There are a couple of consequences of this approach: -.PP -1) Packets which are blocked are never forwarded (something to keep -in mind when designing firewalls). -.PP -2) Packets targeted at the loopback interface (127.0.0.0/8) are never -blocked. Blocking packets to the loopback interface seems pointless -and potentially quite confusing. It also makes a possibly common -case very cheap. -.PP -3) The sender of a packet which is blocked receives no indication that -the packet was dropped. The Telebit NetBlazer can be configured to -silently drop a blocked packet or to send back a "you can't get there -from here" packet to the sender. Implementing the later would have -been more work (possibly quite a bit more, I don't really know). Also, -I don't see any reason to give a potential hacker any more information -than necessary. Dropping the packet into the bit bucket seems like -the best way to keep a hacker guessing. [Danny] -.PP -(I am working on this feature, it would be made optional and -configurable by some ICMP_UNREACH_ON_DROP option, or such [Ugen]). -.PP -The firewall checker takes two parameters. The first parameter is a pointer -to the packet in question. The second parameter is a pointer to the -appropriate firewall chain. At the present time, the firewall checker passes -these parameters to a second routine which is the real firewall checker. -If the real checker says NO then an appropriate message is printed -onto the console. This is useful for debugging purposes. Whether or -not it remains in the long term depends on whether it is considered useful -for logging purposes (I'm a little reluctant to leave it in since it -provides a hacker with a way to commit a "denial of service" offense -against you by filling up your /var/log/messages file's file system -with error messages. There are ways of preventing this but ... [Danny]). -In default configuration now no information about dropped packets -printed.You may, however, define it as i do by adding -.I options IPFIREWALL_VERBOSE -to your kernel configuration file. Very useful thingy! [Ugen] - -.PP -A return value of 0 from this routine (or the real firewall checker) -indicates that the packet is to be dropped. A value of 1 indicates -that the packet is to be accepted. In the early testing stages you -might want to make the top level firewall checker always return 1 even -if the real checker returns 0 just in case the real firewall checker -screws up (or your firewalls aren't as well designed as they should be). -In fact, this might be a useful optional feature (providing a way to -leave a door unlocked doesn't seem all that wise but it has to be -balanced against the inconvenience to legitimate users who might get -screwed up by poorly designed firewalls). - -.PP -The real firewall returns 1 (accept the packet) if the chain is empty. If -efficiency is a concern (which it is in this code), this check should -be done in ip_input.c before calling the firewall checker. - -.PP -Assuming that there is a firewall chain to scan through, the real firewall -checker picks up the src and dst IP addresses from the IP packet. It -then goes through the firewall chain looking for the first firewall that -matches the packet. Once a matching firewall has been found, a value of -1 is returned if the firewall is an accept firewall and a value of 0 is -returned otherwise. -.PP -The following processing is done for each firewall on the chain: -.PP -1) check the src and dst IP addresses. If they don't match then -there isn't any point in looking any further at this firewall. -This check is done by anding the packet's IP addresses the -with appropriate masks and comparing the results to the -appropriate addresses in the firewall. Note that the mask is -NOT applied to the address in the firewall. If it has any 1 -bits that are 0 bits in the mask then the firewall will never -match (this will be checked in ipfirewall soon). If the addresses -match then we continue with the next step. -.PP -2) If the firewall is a universal firewall then we've got a match. -Return either 0 or 1 as appropriate. Otherwise, continue with -the next step. -.PP -3) Examine the IP protocol from the packet. If we havn't had to -look at it before then we get it and set a local variable to -IP_FIREWALL_TCP for TCP/IP packets, IP_FIREWALL_UDP for UDP/IP -packets, IP_FIREWALL_ICMP for ICMP packets, and IP_FIREWALL_UNIVERSAL -for all other packet types. Also, if the packet is a TCP/IP or -a UDP/IP packet, save the source and destination port numbers -at this point (taking advantage of the fact that the port numbers -are stored in the same place in either a TCP/IP or a UDP/IP -packet header). If the packet is neither a TCP/IP or a UDP/IP -packet then this firewall won't match it (on to the next firewall). -If this packet's protocol doesn't match this firewall's protocol -(which can't be universal or we wouldn't be here) then on to -the next firewall. Otherwise, continue with the next step. -.PP -4) We're checking either a TCP/IP or a UDP/IP packet. If the -firewall's source port list is empty or the packet's source -port matches something in the source port list AND if the firewall's -destination port list is empty or the packet's destination -port matches something in the destination port list then -we've got a match (return 0 or 1 as appropriate). Otherwise, -on to the next firewall. -.PP -As indicated above, if no packet on the chain matches the packet then -it is accepted if the first firewall was a deny firewall and it is rejected -if the first firewall was an accept packet. This is equivalent to the -default behaviour of a Telebit NetBlazer. They provide a way to override -this behaviour. I'm not convinced that it is necessary (I'm open to -suggestions). -.PP -That's about it for the firewall checker. The -.I ipfw -program communicates with the kernel part of the firewall facility by making -setsockopt calls on RAW IP sockets. Only root is allowed to open a RAW IP -socket. This ensures that only root uses -.I ipfw to manipulate the firewall facility. -Also, somewhere in the kernel source or on a man page, I read that the -RAW IP setsockopt calls are intended for manipulating the IP protocol layer -as opposed to manipulating any particular instance of a socket. This seems -like a reasonable description of what the firewall setsockopt command -codes do. -.PP -There are seven setsockopt command codes defined by the firewall facility -(in netinet/in.h). They are: -.PP -.nf - IP_FLUSH_FIREWALLS flush (i.e. free) both firewall chains. - - IP_ADD_FORWARDING_FIREWALL add firewall pointed at by optval parm to - the end of the forwarding firewall chain. - - IP_ADD_BLOCKING_FIREWALL add firewall pointed at by optval parm to - the end of the blocking firewall chain. - - IP_DEL_FORWARDING_FIREWALL delete firewall pointed at by optval parm - from the forwarding firewall chain. - - IP_DEL_BLOCKING_FIREWALL delete firewall pointed at by optval parm - from the blocking firewall chain. - - IP_CHECK_FORWARDING_FIREWALL pass the IP packet do the firewall checker - along with the forwarding firewall chain. - Return 0 if packet was accepted, -1 (with - errno set to EACCES) if it wasn't. - - IP_CHECK_BLOCKING_FIREWALL pass the IP packet do the firewall checker - along with the blocking firewall chain. - Return 0 if packet was accepted, -1 (with - errno set to EACCES) if it wasn't. - - The IP_ADD_* and IP_DEL_* command codes do a fair bit of validity checking. - It is quite unlikely that a garbage firewall could get past them that - would cause major problems in the firewall checker. It IS possible for - a garbage packet to get past the checks which causes major grief because - it either blocks or accepts packets according to unusual rules (the rules - will conform to the ones described above but will probably come as quite - a surprise). - - The IP_CHECK_* command codes expect the optval parameter to point - to a struct ip immediately followed by a header appropriate to the protocol - value described in the ip_p field of the ip header. The exact requirements - are as follows: - - - The length of the optval parameter must be at least - - sizeof(struct ip) + 2 * sizeof(u_short) - - since this is the amount of memory that might be referenced by - the firewall checker. - - - The ip_hl field of the ip structure must be equal to - - sizeof(struct ip) / sizeof(int) - - since this value indicates that the tcp/udp/??? header immediately - follows the ip header (appropriate for the purposes that this - interface is intended for). - - Failure to follow these rules (for either the IP_ADD_*,IP_DEL_* or the - IP_CHECK_*_FIREWALL commands) will result in a return value of -1 with - errno set to EINVAL (for now, it will also result in an appropriate - message on the console). - - To read current configuration of firewalls,the kvm_read() function used. - Symbols,which you have to find are : - struct ip_firewall * ip_firewall_blocking_chain ; - struct ip_firewall * ip_firewall_forwarding_chain ; - Both are pointers to the linked list of firewall entries. - Of course, you must at least be a member of group kmem to read kernel - symbols. -.fi -.PP -There are a couple of additional details that are worth reading about in -the ip_firewall.h file. Other than that, let the authors know how you do! -If you have any problems, you may call Danny Boulet at home (403 449-1835) -or send e-mail to <danny@BouletFermat.ab.ca>. If you call, please keep in -mind that Danny lives in the Canadian Mountain timezone (GMT-0600). -.PP -You may also reach some commercial users of this package (and also those -responsible for porting it to FreeBSD and adding several additional -commands), at 972-4-550-330, or via email at <ugen@NetVision.net.il>. -If you call, remember that Ugen lives in the Israel timezone, which is GMT+02. - -.SH FILES -/usr/share/misc/ipfw.samp.filters -/usr/share/misc/ipfw.samp.scripts -.SH "BUGS" -You can very easily hose your machine utterly if you don't know what you're -doing. Dieses Befehl ist nur fuer Experten! -.SH "SEE ALSO" -.BR reboot (1) , -.PP -.BR /sys/i386/conf/IPFIREWALL -.SH AUTHORS -Daniel Boulet <danny@BouletFermat.ab.ca> -.PP -Ugen J.S.Antsilevich <ugen@NetVision.net.il> -.PP -Jordan K. Hubbard <jkh@FreeBSD.org> [Crimes committed in this manpage] diff --git a/sbin/slattach/uucplock.c b/sbin/slattach/uucplock.c deleted file mode 100644 index fb0f7c0..0000000 --- a/sbin/slattach/uucplock.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93"; -#endif /* not lint */ - -#include <sys/types.h> -#include <sys/file.h> -#include <sys/dir.h> -#include <errno.h> -#include <syslog.h> -#include <unistd.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> - -#define _PATH_LOCKDIRNAME "/var/spool/lock/LCK..%s" - -/* Forward declarations */ -static int put_pid (int fd, pid_t pid); -static pid_t get_pid (int fd); - -/* - * uucp style locking routines - * return: 0 - success - * -1 - failure - */ - -int uu_lock (char *ttyname) -{ - int fd; - pid_t pid; - char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN]; - - (void)sprintf(tbuf, _PATH_LOCKDIRNAME, ttyname); - fd = open(tbuf, O_RDWR|O_CREAT|O_EXCL, 0660); - if (fd < 0) { - /* - * file is already locked - * check to see if the process holding the lock still exists - */ - fd = open(tbuf, O_RDWR, 0); - if (fd < 0) { - syslog(LOG_ERR, "lock open: %m"); - return(-1); - } - if ((pid = get_pid (fd)) == -1) { - syslog(LOG_ERR, "lock read: %m"); - (void)close(fd); - return(-1); - } - - if (kill(pid, 0) == 0 || errno != ESRCH) { - (void)close(fd); /* process is still running */ - return(-1); - } - /* - * The process that locked the file isn't running, so - * we'll lock it ourselves - */ - if (lseek(fd, 0L, L_SET) < 0) { - syslog(LOG_ERR, "lock lseek: %m"); - (void)close(fd); - return(-1); - } - /* fall out and finish the locking process */ - } - pid = getpid(); - if (!put_pid (fd, pid)) { - syslog(LOG_ERR, "lock write: %m"); - (void)close(fd); - (void)unlink(tbuf); - return(-1); - } - (void)close(fd); - return(0); -} - -int uu_unlock (char *ttyname) -{ - char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN]; - - (void)sprintf(tbuf, _PATH_LOCKDIRNAME, ttyname); - return(unlink(tbuf)); -} - -static int put_pid (int fd, pid_t pid) -{ - char buf [32]; - int len; - - len = sprintf (buf, "%10ld\n", pid); - return write (fd, buf, len) == len; -} - -static pid_t get_pid (int fd) -{ - int bytes_read; - char buf [32]; - pid_t pid; - - bytes_read = read (fd, buf, sizeof (buf) - 1); - if (bytes_read > 0) { - buf [bytes_read] = '\0'; - pid = strtol (buf, (char **) NULL, 10); - } - else - pid = -1; - return pid; -} - -/* end of uucplock.c */ diff --git a/sbin/startslip/example/sldown.sh b/sbin/startslip/example/sldown.sh deleted file mode 100755 index 1f342a4..0000000 --- a/sbin/startslip/example/sldown.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -/sbin/ifconfig $1 $2 -/sbin/route delete default diff --git a/sbin/startslip/example/slip.sh b/sbin/startslip/example/slip.sh deleted file mode 100755 index c2a1275..0000000 --- a/sbin/startslip/example/slip.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -startslip -b 57600 -U ./slup.sh -D ./sldown.sh \ - -s atd<phone1> -s atd<phone2> -s atd<phone3> \ - -h -t 60 -w 2 /dev/cuaa1 <login> <password> diff --git a/sbin/startslip/example/slup.sh b/sbin/startslip/example/slup.sh deleted file mode 100755 index df83c0c..0000000 --- a/sbin/startslip/example/slup.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -myname=<my.ip.address> -gateway=<gateway.ip.address> -netmask=255.255.255.248 -tune="link0 -link2" # links means force compression - -/sbin/ifconfig $1 $2 $tune -/sbin/ifconfig $1 inet $myname $gateway netmask $netmask -/sbin/route add default $gateway diff --git a/sbin/sysinstall/Makefile b/sbin/sysinstall/Makefile deleted file mode 100644 index d141faa..0000000 --- a/sbin/sysinstall/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -PROG = sysinstall -MANEXT = 1 -NOMAN= yet -CLEANFILES= makedevs.c rtermcap - -.PATH: ${.CURDIR}/../disklabel - -SRCS = exec.c dkcksum.c label.c main.c mbr.c \ - stage0.c stage1.c stage2.c stage3.c stage5.c \ - termcap.c utils.c makedevs.c ourcurses.c - -CFLAGS += -Wall -g -static -LDADD = -ldialog -lncurses -lmytinfo -DPADD = ${LIBDIALOG} ${LIBNCURSES} ${LIBMYTINFO} - -.if exists(${.CURDIR}/../../sys/i386/boot/biosboot/obj) -BOOTS=${.CURDIR}/../../sys/i386/boot/biosboot/obj -.else -BOOTS=${.CURDIR}/../../sys/i386/boot/biosboot -.endif - -makedevs.c: dev2c.sh Makefile rtermcap - mkdir -p dev - cp ${.CURDIR}/../../etc/etc.i386/MAKEDEV dev - ( cd dev; sh ./MAKEDEV all ) - sh ${.CURDIR}/dev2c.sh dev > makedevs.tmp - rm -rf dev - uudecode < ${.CURDIR}/bteasy17.uu - file2c 'const unsigned char boot0[] = {' '};' \ - < bteasy17 >> makedevs.tmp - rm -rf bteasy17 - file2c 'const unsigned char boot1[] = {' '};' \ - < ${BOOTS}/boot1 >> makedevs.tmp - file2c 'const unsigned char boot2[] = {' '};' \ - < ${BOOTS}/boot2 >> makedevs.tmp - ./rtermcap cons25 | \ - file2c 'const char termcap_cons25[] = {' ',0};' \ - >> makedevs.tmp - ./rtermcap cons25-m | \ - file2c 'const char termcap_cons25_m[] = {' ',0};' \ - >> makedevs.tmp - ./rtermcap vt100 | \ - file2c 'const char termcap_vt100[] = {' ',0};' \ - >> makedevs.tmp - mv makedevs.tmp makedevs.c - -rtermcap: ${.CURDIR}/rtermcap.c - ${CC} -o rtermcap ${.CURDIR}/rtermcap.c -ltermcap - -.include <bsd.prog.mk> - diff --git a/sbin/sysinstall/bootarea.c b/sbin/sysinstall/bootarea.c deleted file mode 100644 index 917b65e..0000000 --- a/sbin/sysinstall/bootarea.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 1994, Paul Richards. - * - * All rights reserved. - * - * This software may be used, modified, copied, distributed, and - * sold, in both source and binary form provided that the above - * copyright and these terms are retained, verbatim, as the first - * lines of this file. Under no circumstances is the author - * responsible for the proper functioning of this software, nor does - * the author assume any responsibility for damages incurred with - * its use. - */ - -#include <sys/types.h> -#include <sys/errno.h> -#include <sys/disklabel.h> -#include <sys/ioctl.h> -#include <sys/fcntl.h> -#include <sys/uio.h> -#include <unistd.h> -#include <stdio.h> -#include <string.h> -#include <dialog.h> - -#include "mbr.h" -#include "sysinstall.h" - -extern char *bootblocks; -extern struct mbr *mbr; - -int -write_bootblocks(int fd, struct disklabel *lbl) -{ - off_t of = lbl->d_partitions[OURPART].p_offset; - - Debug("Seeking to byte %ld ", of * lbl->d_secsize); - if (lseek(fd, (of * lbl->d_secsize), SEEK_SET) < 0) { - Fatal("Couldn't seek to start of partition\n"); - } - - enable_label(fd); - - if (write(fd, bootblocks, lbl->d_bbsize) != lbl->d_bbsize) { - Fatal("Failed to write bootblocks (%p,%d) %d %s\n", - bootblocks, lbl->d_bbsize, - errno, strerror(errno) - ); - } - - disable_label(fd); - - return(0); -} - -int -build_bootblocks(int dfd,struct disklabel *label,struct dos_partition *dospart) -{ - int fd; - off_t of = label->d_partitions[OURPART].p_offset; - - Debug("Loading boot code from %s", boot1); - - fd = open(boot1, O_RDONLY); - if (fd < 0) - Fatal("Couldn't open boot file %s\n", boot1); - - if (read(fd, bootblocks, MBRSIZE) < 0) - Fatal("Couldn't read from boot file %s\n", boot1); - - if (close(fd) == -1) - Fatal("Couldn't close boot file %s\n", boot1); - - Debug("Loading boot code from %s", boot2); - - fd = open(boot2, O_RDONLY); - if (fd < 0) - Fatal("Couldn't open boot file %s", boot2); - - if (read(fd, &bootblocks[MBRSIZE], (int)(label->d_bbsize - MBRSIZE)) < 0) - Fatal("Couldn't read from boot file %s\n", boot2); - - if (close(fd) == -1) - Fatal("Couldn't close boot file %s", boot2); - - bcopy(dospart, &bootblocks[DOSPARTOFF], - sizeof(struct dos_partition) * NDOSPART); - - label->d_checksum = 0; - label->d_checksum = dkcksum(label); - bcopy(label, &bootblocks[(LABELSECTOR * label->d_secsize) + LABELOFFSET], - sizeof *label); - - Debug("Seeking to byte %ld ", of * label->d_secsize); - - if (lseek(dfd, (of * label->d_secsize), SEEK_SET) < 0) { - Fatal("Couldn't seek to start of partition\n"); - } - - enable_label(dfd); - - if (write(dfd, bootblocks, label->d_bbsize) != label->d_bbsize) { - Fatal("Failed to write bootblocks (%p,%d) %d %s\n", - bootblocks, label->d_bbsize, - errno, strerror(errno) - ); - } - - disable_label(dfd); - - return(0); -} diff --git a/sbin/sysinstall/bootarea.h b/sbin/sysinstall/bootarea.h deleted file mode 100644 index 3c17eb9..0000000 --- a/sbin/sysinstall/bootarea.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 1994, Paul Richards. - * - * All rights reserved. - * - * This software may be used, modified, copied, distributed, and - * sold, in both source and binary form provided that the above - * copyright and these terms are retained, verbatim, as the first - * lines of this file. Under no circumstances is the author - * responsible for the proper functioning of this software, nor does - * the author assume any responsibility for damages incurred with - * its use. - */ - -#define BOOT1 "/stand/sdboot" -#define BOOT2 "/stand/bootsd" - -/* XXX -- calculate these, this is nasty */ -#define DEFFSIZE 1024 -#define DEFFRAG 8 - -int Mb_to_cylbdry(int, struct disklabel *); -void default_disklabel(struct disklabel *, int, int); -int disk_size(struct disklabel *); diff --git a/sbin/sysinstall/bteasy17.uu b/sbin/sysinstall/bteasy17.uu deleted file mode 100644 index 2cc05b2..0000000 --- a/sbin/sysinstall/bteasy17.uu +++ /dev/null @@ -1,15 +0,0 @@ -begin 664 bteasy17 -M,\".P([8CM"\`'S\B_2_``:Y``'RI>I@!@``B]58HD@'/#5T'+00]N0%K@26 -M]D0$_W0^Q@2`Z-H`BG0!BTP"ZPCHSP"Y`0`RT;L`?+@!`LT3<AZ!O_X!5:IU -M%NH`?```@/J!=`*R@(OJ0H#RLX@6.@>_O@>Y!`#&!BT',3+VB"V*100\`'0C -M/`5T'_[&OBH'Z'$`OD@'1D:+'`K_=`4R?01U\XVW<@?H6@"#QQ#^!BT'XLN` -M/G4$`G0+OCL'"O9U"LT8ZZR^*@?H.0#H-@`RY,T:B]J#PV"T`<T6M`!U"\T: -M.]-R\J!(!^L*S1:*Q#P<=/,$]CPQ<M8\-7?24+XH![L;!E/\K%`D?[0.S1!8 -MJ(!T\L-6N`$#NP`&N0$`,O;-$U[&!D@'/\,-B@T*1C`@+B`N("Z@9&ES:R`Q -M#0H*1&5F875L=#H@1C^@``$`!``&`P<'"@IC#F0.912`%($9@AZ3)*4GGRMU -M+U(OVS)`-_(]`&1O\TA01M-/<[)5;FGX3F]V96SL36EN:?A,:6YU^$%M;V5B -MX4)3Q$)31.E00TG80U#-5F5N:?A$;W-S9>,_OP`````````````````````` -M```````````````````````````````````````````````````````````` -1````````````````````5:H` -` -end diff --git a/sbin/sysinstall/dev2c.sh b/sbin/sysinstall/dev2c.sh deleted file mode 100644 index d395810..0000000 --- a/sbin/sysinstall/dev2c.sh +++ /dev/null @@ -1,80 +0,0 @@ -: -# -# ---------------------------------------------------------------------------- -# "THE BEER-WARE LICENSE" (Revision 42): -# <phk@login.dknet.dk> wrote this file. As long as you retain this notice you -# can do whatever you want with this stuff. If we meet some day, and you think -# this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp -# ---------------------------------------------------------------------------- -# -# $Id: stage3.c,v 1.4 1994/10/21 02:14:52 phk Exp $ -# -# During installation, we suffer badly of we have to run MAKEDEV. MAKEDEV -# need sh, ln, chown, mknod, awk, rm, test and probably emacs too when -# we come down to it. So instead this script will make a C-procedure which -# makes all the B & C nodes of a specified directory. -# -# Poul-Henning - -(cd $1; ls -li ) | sed 's/,//' | awk ' -BEGIN { - while (getline < "/etc/passwd") { - split($0,a,":") - uid[a[1]] = a[3] - } - while (getline < "/etc/group") { - split($0,a,":") - gid[a[1]] = a[3] - } - printf("/*\n"); - printf(" * This file is generated from the contents of /dev\n"); - printf(" */\n"); - printf("#define CHK(foo) {i = foo;}\n"); - printf("#include <unistd.h>\n"); - printf("#include <sys/types.h>\n"); - printf("#include <sys/stat.h>\n"); - printf("int makedevs()\n{\n\tint i=0;\n"); - } - { - printf ("/* %s */\n",$0) - $4 = uid[$4] - $5 = gid[$5] - if (substr($2,1,1) == "b") { - k="S_IFBLK" - } else if (substr($2,1,1) == "c") { - k="S_IFCHR" - } else if (substr($2,1,1) == "d") { - next - } else if (substr($2,1,1) == "-") { - next - } else { - next - } - m = 0; - if (substr($2,2,1) == "r") m += 400; - if (substr($2,3,1) == "w") m += 200; - if (substr($2,4,1) == "x") m += 100; - if (substr($2,5,1) == "r") m += 40; - if (substr($2,6,1) == "w") m += 20; - if (substr($2,7,1) == "x") m += 10; - if (substr($2,8,1) == "r") m += 4; - if (substr($2,9,1) == "w") m += 2; - if (substr($2,10,1) == "x") m += 1; - - if (a[$1] != 0) { - printf ("\tCHK(link(\"%s\",\"%s\"));\n", \ - a[$1],$11) - } else { - printf ("\tCHK(mknod(\"%s\",%s,makedev(%d,%d)));\n", \ - $11, k, $6, $7) - printf ("\tCHK(chmod(\"%s\",0%d));\n", \ - $11, m) - printf ("\tCHK(chown(\"%s\",%d,%d));\n", \ - $11, $4,$5) - a[$1] = $11 - } - } -END { - printf("\treturn i;\n}\n"); - } -' diff --git a/sbin/sysinstall/disk.h b/sbin/sysinstall/disk.h deleted file mode 100644 index 622dc0c..0000000 --- a/sbin/sysinstall/disk.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 1994, Paul Richards. - * - * All rights reserved. - * - * This software may be used, modified, copied, distributed, and - * sold, in both source and binary form provided that the above - * copyright and these terms are retained, verbatim, as the first - * lines of this file. Under no circumstances is the author - * responsible for the proper functioning of this software, nor does - * the author assume any responsibility for damages incurred with - * its use. - */ - -#define MBRSIZE 512 -#define MBR_MAGIC 0xAA55 -#define ACTIVE 0x80 - -/* XXX -- calculate these, this is nasty */ -#define DEFFSIZE 1024 -#define DEFFRAG 8 - -/* bootarea.c */ -int write_bootblocks(int); -int enable_label(int); -int disable_label(int); -/* label.c */ -char *diskname(int); - -struct mbr -{ - unsigned char padding[2]; - unsigned char bootcode[DOSPARTOFF]; - struct dos_partition dospart[4]; - unsigned short magic; -}; - -struct disk { - struct disklabel lbl; - struct mbr mbr; - struct devconf *devconf; - int selected; - int inst_part; - struct fstab mounts[MAXPARTITIONS]; -}; - -extern struct disk disk_list[]; - -struct part_type -{ - unsigned char type; - char *name; -}; - -#define PARTITION_TYPES \ -{ \ - {0x00, "Unused"} \ - ,{0x01, "Primary DOS with 12 bit FAT"} \ - ,{0x02, "XENIX / filesystem"} \ - ,{0x03, "XENIX /usr filesystem"} \ - ,{0x04, "Primary DOS with 16 bit FAT"} \ - ,{0x05, "Extended DOS"} \ - ,{0x06, "Primary 'big' DOS (> 32MB)"} \ - ,{0x07, "OS/2 HPFS, QNX or Advanced UNIX"} \ - ,{0x08, "AIX filesystem"} \ - ,{0x09, "AIX boot partition or Coherent"} \ - ,{0x0A, "OS/2 Boot Manager or OPUS"} \ - ,{0x10, "OPUS"} \ - ,{0x40, "VENIX 286"} \ - ,{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"} \ - ,{0x93, "Amoeba filesystem"} \ - ,{0x94, "Amoeba bad block table"} \ - ,{0xA5, "FreeBSD/NetBSD/386BSD"} \ - ,{0xA7, "NEXTSTEP"} \ - ,{0xB7, "BSDI BSD/386 filesystem"} \ - ,{0xB8, "BSDI BSD/386 swap"} \ - ,{0xDB, "Concurrent CPM or C.DOS or CTOS"} \ - ,{0xE1, "Speed"} \ - ,{0xE3, "Speed"} \ - ,{0xE4, "Speed"} \ - ,{0xF1, "Speed"} \ - ,{0xF2, "DOS 3.3+ Secondary"} \ - ,{0xF4, "Speed"} \ - ,{0xFF, "BBT (Bad Blocks Table)"} \ -}; diff --git a/sbin/sysinstall/editor.c b/sbin/sysinstall/editor.c deleted file mode 100644 index f4933bd..0000000 --- a/sbin/sysinstall/editor.c +++ /dev/null @@ -1,118 +0,0 @@ -#include <string.h> -#include <ncurses.h> -#include <dialog.h> - -#include "editor.h" - -int -disp_fields(WINDOW *window, struct field field[], int no_fields) -{ - int i, j; - int len; - - for (i=0; i < no_fields; i++) { - wmove(window, field[i].y, field[i].x); - switch (field[i].type) { - case F_TITLE: - case F_EDIT: - if (field[i].type == F_TITLE) - wattrset(window, title_attr); - else - wattrset(window, dialog_attr); - len=strlen(field[i].field); - for (j=0; j < field[i].width; j++) - if (j < len) - waddch(window, field[i].field[j]); - else - waddch(window, ' '); - break; - case F_BUTTON: - print_button(window, field[i].field, - field[i].y, - field[i].x, - FALSE); - break; - } - } - wrefresh(window); - return (0); -} - -int -change_field(struct field field, int key) -{ - int next; - - switch(key) { - case KEY_UP: - next = field.up; - break; - case KEY_DOWN: - next = field.down; - break; - case '\t': - next = field.right; - break; - case KEY_BTAB: - next = field.left; - break; - case '\n': - case '\r': - next = field.right; - break; - default: - next = -1; - break; - } - return (next); -} - -int -button_press(WINDOW *window, struct field field) -{ - int key; - - print_button(window, field.field, - field.y, - field.x, - TRUE); - key = wgetch(window); - - switch (key) { - case '\n': - case '\r': - return (0); - case KEY_UP: - case KEY_DOWN: - case KEY_BTAB: - case '\t': - default: - return (key); - } -} - -int -toggle_press(WINDOW *window, struct field field) -{ - int key; - - key = wgetch(window); - - switch (key) { - case ' ': - field.spare++; - if (!field.misc[field.spare]) - field.spare = 0; - sprintf(field.field, "%s", field.misc[field.spare]); - return (key); - break; - case '\n': - case '\r': - case KEY_UP: - case KEY_DOWN: - case KEY_BTAB: - case '\t': - default: - return (key); - } -} diff --git a/sbin/sysinstall/editor.h b/sbin/sysinstall/editor.h deleted file mode 100644 index 2783cc8..0000000 --- a/sbin/sysinstall/editor.h +++ /dev/null @@ -1,27 +0,0 @@ -#define ESC 27 -#define TAB 9 - -struct field { - int y; - int x; - int width; - int maxlen; - int next; - int up; - int down; - int left; - int right; - char field[80]; - int type; - int spare; - char *misc; -}; - -#define F_EDIT 0 -#define F_TITLE 1 -#define F_BUTTON 2 -#define F_TOGGLE 3 - -int disp_fields(WINDOW *, struct field *, int); -int change_field(struct field, int); -int edit_line(WINDOW *, int, int, char *, int, int); diff --git a/sbin/sysinstall/exec.c b/sbin/sysinstall/exec.c deleted file mode 100644 index 379f41d..0000000 --- a/sbin/sysinstall/exec.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: exec.c,v 1.8.2.1 1994/11/21 03:11:59 phk Exp $ - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <unistd.h> -#include <string.h> -#include <dialog.h> -#include <errno.h> -#include <fcntl.h> - -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/reboot.h> - -#include "sysinstall.h" - -int -exec(int magic, char *cmd, char *args, ...) -{ - int pid, w, status; - char *argv[EXEC_MAXARG]; - int arg = 0; - va_list ap; - struct stat dummy; - - if (stat(cmd, &dummy) == -1) { - Fatal("Executable %s does not exist", cmd); - } - - va_start(ap, args); - argv[arg++] = (char *)args; - do { - if (arg >= EXEC_MAXARG) - Fatal("Too many arguments"); - } while ((argv[arg++] = va_arg(ap, char *))); - va_end(ap); - - if ((pid = fork()) == 0) { - switch (magic) { - case 0: - close(0); dup(debug_fd); - close(1); dup(debug_fd); - close(2); dup(debug_fd); - close(debug_fd); - break; - case 1: - close(2); dup(debug_fd); - close(debug_fd); - break; - case 2: - case 3: - close(debug_fd); - break; - case 4: - close(0) ; open("/stand/sysinstall",O_RDONLY); - close(1) ; open("/mnt/stand/sysinstall", - O_WRONLY|O_CREAT|O_TRUNC,0755); - default: - break; - } - execv(cmd, argv); - exit(1); - } - - while ((w = wait(&status)) != pid && w != -1) - ; - if ((status >> 8) == 20 && magic == 3) /* special case for bininst */ - reboot(RB_AUTOBOOT); - if (w == -1) - Fatal("Child process %s terminated abnormally\n", cmd); - return(status); -} diff --git a/sbin/sysinstall/label.c b/sbin/sysinstall/label.c deleted file mode 100644 index fd0b76e..0000000 --- a/sbin/sysinstall/label.c +++ /dev/null @@ -1,379 +0,0 @@ -/* - * $Id: label.c,v 1.31 1994/12/27 23:26:51 jkh Exp $ - */ - -#include <stdlib.h> -#include <limits.h> -#define DKTYPENAMES -#include <sys/param.h> -#include <ufs/ffs/fs.h> -#include <sys/types.h> -#include <string.h> -#include <sys/disklabel.h> -#include <ufs/ffs/fs.h> - -#include <string.h> -#include <dialog.h> -#include "sysinstall.h" - -static int -AskWhichPartition(char *prompt) -{ - char buf[10]; - int i; - *buf = 0; - i = AskEm(stdscr, prompt, buf, 2); - if (i != '\n' && i != '\r') return -1; - if (!strchr("abefghABEFGH",*buf)) return -1; - return tolower(*buf) - 'a'; -} - -void -DiskLabel() -{ - int i, j, done = 0, diskno, k; - char buf[128],*p; - struct disklabel *lbl, olbl; - struct dos_partition dp[NDOSPART]; - - u_long cyl, hd, sec, tsec; - u_long l1, l2, l3, l4; - char *yip = NULL; - u_long allocated_space, ourpart_size, ourpart_offset; - - *buf = 0; - i = AskEm(stdscr, "Enter number of disk to Disklabel> ", buf, 3); - Debug("%d", i); - if (i != '\n' && i != '\r') return; - diskno = atoi(buf); - if (!(diskno >= 0 && diskno < MAX_NO_DISKS && Dname[diskno])) { - return; - } - olbl = *Dlbl[diskno]; - lbl = &olbl; - cyl = lbl->d_ncylinders; - hd = lbl->d_ntracks; - sec = lbl->d_nsectors; - tsec = lbl->d_secperunit; - for (i = lbl->d_npartitions; i < MAXPARTITIONS; i++) { - lbl->d_partitions[i].p_offset = 0; - lbl->d_partitions[i].p_size = 0; - lbl->d_partitions[i].p_fstype = 0; - } - lbl->d_npartitions = MAXPARTITIONS; - - if(Dname[diskno][0] == 's' && Dname[diskno][1] == 'd') - lbl->d_type = DTYPE_SCSI; - else - lbl->d_type = DTYPE_ST506; - - while(!done) { - clear(); standend(); - if (yip) { - standout(); - mvprintw(24, 0, yip); - standend(); - beep(); - yip = NULL; - } - j = 0; - mvprintw(j++, 0, "%s -- Diskspace editor -- DISKLABEL", TITLE); - j++; - - allocated_space = 0; - ourpart_size = lbl->d_partitions[OURPART].p_size; - ourpart_offset = lbl->d_partitions[OURPART].p_offset; - - mvprintw(j++, 0, "Part Start End Blocks MB Type Action Mountpoint"); - for (i = 0; i < MAXPARTITIONS; i++) { - refresh(); - mvprintw(j++, 0, "%c ", 'a'+i); - printw(" %8u %8u %8u %5u ", - lbl->d_partitions[i].p_offset, - lbl->d_partitions[i].p_offset+ - (lbl->d_partitions[i].p_size ? - lbl->d_partitions[i].p_size-1 : 0), - lbl->d_partitions[i].p_size, - (lbl->d_partitions[i].p_size + 1024)/2048); - - k = lbl->d_partitions[i].p_fstype; - if (k > FSMAXTYPES) - printw("%04x ", k); - else - printw("%-7.7s ", fstypenames[k]); - - if(!MP[diskno][i]) - printw(" "); - else if(!strcmp(Ftype[MP[diskno][i]],"swap")) - printw("swap "); - else if(Faction[MP[diskno][i]]) - printw("newfs "); - else - printw("mount "); - if (i == OURPART) - printw("<Entire FreeBSD slice>"); - else if (i == RAWPART) - printw("<Entire Disk>"); - else { - if (Fmount[MP[diskno][i]]) - printw(Fmount[MP[diskno][i]]); - if ((lbl->d_partitions[i].p_offset >= ourpart_offset) && - ((lbl->d_partitions[i].p_offset + - lbl->d_partitions[i].p_size) <= - (ourpart_offset + ourpart_size))) - allocated_space += lbl->d_partitions[i].p_size; - } - } - mvprintw(17, 0, "Total size: %8lu blocks %5luMb", - ourpart_size, (ourpart_size + 1024)/2048); - mvprintw(18, 0, "Space allocated: %8lu blocks %5luMb", - allocated_space, (allocated_space + 1024)/2048); - mvprintw(20, 0, "Commands available: "); - if (memcmp(lbl, Dlbl[diskno], sizeof *lbl)) { - standout(); - printw("Use (W)rite to save changes to disk"); - standend(); - } - mvprintw(21, 0, "(H)elp (T)utorial (E)dit (A)ssign (D)elete (R)eread (W)rite (Q)uit"); - mvprintw(22, 0, "(P)reserve (S)lice"); - mvprintw(23, 0, "Enter Command> "); - i=getch(); - switch(i) { - case 'h': case 'H': case '?': - clear(); - mvprintw(0, 0, -"%s -- Diskspace editor -- DISKLABEL -- Command Help - -Basic commands: - -(H)elp - This screen -(T)utorial - More detailed information on MBRs, disklabels, etc. -(E)dit - Edit an existing disklabel entry -(A)ssign - Assign a filesystem (or swap) to a partition -(D)elete - Delete an existing disklabel entry -(R)eread - Re-read disklabel from disk, discarding any changes -(W)rite - Write updated disklabel information to disk -(P)reserve - Don't newfs the filesystem (preserve old contents) -(S)lice - Import foreign slice from MBR (for example, DOS) -(Q)uit - Exit from the disklabel editor - -Press any key to return to Disklabel editor... -", TITLE); - getch(); - break; - case 't': case 'T': - ShowFile(HELPME_FILE,"Help file for disklayout"); - break; - case 'd': case 'D': - j = AskWhichPartition("Delete which partition> "); - if (j < 0) { - yip = "Invalid partition"; - break; - } - CleanMount(diskno, j); - lbl->d_partitions[j].p_fstype = FS_UNUSED; - lbl->d_partitions[j].p_size = 0; - lbl->d_partitions[j].p_offset = 0; - break; - - case 'p': case 'P': - j = AskWhichPartition("Preserve which partition> "); - if (j < 0) { - yip = "Invalid partition"; - break; - } - if (!MP[diskno][j]) { - yip = "Unmounted partitions are preserved by default"; - break; - } - if (lbl->d_partitions[j].p_fstype == FS_SWAP) { - yip = "swap partitions cannot be preserved."; - break; - } - if (lbl->d_partitions[j].p_fstype != FS_BSDFFS) { - yip = "All non-ufs partitions are preserved by default."; - break; - } - if (!fixit && !strcmp(Fmount[MP[diskno][j]],"/")) { - yip = "/ cannot be preserved."; - break; - } - if (!fixit && !strcmp(Fmount[MP[diskno][j]],"/usr")) { - yip = "/usr cannot be preserved."; - break; - } - if (!fixit && !strcmp(Fmount[MP[diskno][j]],"/var")) { - yip = "/var cannot be preserved."; - break; - } - Faction[MP[diskno][j]] = 1 - Faction[MP[diskno][j]]; - break; - - case 's': case 'S': - read_dospart(Dfd[diskno],&dp[0]); - *buf = 0; - j = AskEm(stdscr,"Import which fdisk slice> ",buf,4); - if(j != '\n' && j != '\r') - break; - i = strtoul(buf,0,0); - if (i < 1 || i > 4) { - yip = "Invalid slice, must be '1' to '4'"; - break; - } - if (!dp[i-1].dp_size) { - yip = "empty slice cannot be imported"; - break; - } - j = AskWhichPartition("Import on which partition> "); - if (j < 0) { - yip = "Invalid partition"; - break; - } - CleanMount(diskno, j); - lbl->d_partitions[j].p_offset = dp[i-1].dp_start; - lbl->d_partitions[j].p_size = dp[i-1].dp_size; - switch (dp[i-1].dp_typ) { - case 0x01: - case 0x04: - case 0x06: - lbl->d_partitions[j].p_fstype=FS_MSDOS; - break; - default: - lbl->d_partitions[j].p_fstype=FS_OTHER; - break; - } - break; - - case 'e': case 'E': - j = AskWhichPartition("Change size of which partition> "); - if (j < 0) { - yip = "Invalid partition"; - break; - } - if (lbl->d_partitions[j].p_fstype != FS_BSDFFS && - lbl->d_partitions[j].p_fstype != FS_UNUSED && - lbl->d_partitions[j].p_fstype != FS_SWAP) { - yip = "Invalid partition type"; - break; - } - if (lbl->d_partitions[OURPART].p_size == 0) { - yip = "No FreeBSD partition defined?"; - break; - } - l1=lbl->d_partitions[OURPART].p_offset; - l2=lbl->d_partitions[OURPART].p_offset + - lbl->d_partitions[OURPART].p_size; - for (i = 0; i < MAXPARTITIONS; i++) { - if (i == OURPART) continue; - if (i == RAWPART) continue; - if (i == j) continue; - if (lbl->d_partitions[i].p_size == 0) continue; - if (lbl->d_partitions[i].p_offset >= l2) continue; - if ((lbl->d_partitions[i].p_offset+ - lbl->d_partitions[i].p_size) <= l1) continue; - l3 = lbl->d_partitions[i].p_offset - l1; - l4 = l2 - (lbl->d_partitions[i].p_offset+ - lbl->d_partitions[i].p_size); - if (l3 > 0 && l3 >= l4) - l2 = l1+l3; - else if (l4 > 0 && l4 > l3) - l1 = l2-l4; - else - l2 = l1; - } - if (!(l2 - l1)) { - yip = "Sizes unchanged - couldn't find room"; - break; - } - sprintf(buf, "%lu", (l2-l1+1024L)/2048L); - i = AskEm(stdscr, "Size of partition in MB> ", buf, 10); - l3= strtol(buf, 0, 0) * 2048L; - if (!l3) { - yip = "Invalid size given"; - break; - } - if (l3 > l2 - l1) - l3 = l2 - l1; - lbl->d_partitions[j].p_size = l3; - lbl->d_partitions[j].p_offset = l1; - if (j == 1) - lbl->d_partitions[j].p_fstype = FS_SWAP; - else - lbl->d_partitions[j].p_fstype = FS_BSDFFS; - break; - - case 'r': case 'R': - olbl = *Dlbl[diskno]; - /* XXX be more selective here */ - for (i = 0; i < MAXPARTITIONS; i++) - CleanMount(diskno, i); - break; - - case 'a': case 'A': - j = AskWhichPartition("Assign which partition> "); - if (j < 0) { - yip = "Invalid partition"; - break; - } - k = lbl->d_partitions[j].p_fstype; - if (k != FS_BSDFFS && k != FS_MSDOS && k != FS_SWAP) { - yip = "Invalid partition type"; - break; - } - if (!lbl->d_partitions[j].p_size) { - yip = "Zero partition size"; - break; - } - if (k == FS_SWAP) - strcpy(buf, "swap"); - else if (Fmount[MP[diskno][j]]) - strcpy(buf, Fmount[MP[diskno][j]]); - else - *buf = 0; - if (k != FS_SWAP) { - i = AskEm(stdscr, "Directory mountpoint> ", buf, 28); - if (i != '\n' && i != '\r') - break; - p = buf + strlen(buf) - 1; - - while (isspace(*p) && p >= buf) - *p-- = '\0'; - if (*buf && *buf != '/') { - yip = "Mountpoint must start with a '/'"; - break; - } - } - CleanMount(diskno, j); - if (!*buf) - break; - p = SetMount(diskno,j,buf); - yip = p; - break; - - case 'w': case 'W': - *Dlbl[diskno] = *lbl; - Dlbl[diskno]->d_magic = DISKMAGIC; - Dlbl[diskno]->d_magic2 = DISKMAGIC; - Dlbl[diskno]->d_checksum = 0; - Dlbl[diskno]->d_checksum = dkcksum(Dlbl[diskno]); - *lbl = *Dlbl[diskno]; - enable_label(Dfd[diskno]); - if (ioctl(Dfd[diskno], DIOCSDINFO, Dlbl[diskno]) == -1) - Fatal("Couldn't set label: %s", strerror(errno)); - if (ioctl(Dfd[diskno], DIOCWDINFO, Dlbl[diskno]) == -1) - Fatal("Couldn't write label: %s", strerror(errno)); - disable_label(Dfd[diskno]); - yip = "Label written successfully."; - break; - - case 'q': case 'Q': - if (!memcmp(lbl, Dlbl[diskno], sizeof *lbl)) - return; - /* XXX be more selective here */ - for (i = 0; i < MAXPARTITIONS; i++) - CleanMount(diskno, i); - return; - break; - } - } -} diff --git a/sbin/sysinstall/label.h b/sbin/sysinstall/label.h deleted file mode 100644 index 7af153e..0000000 --- a/sbin/sysinstall/label.h +++ /dev/null @@ -1,52 +0,0 @@ -struct field label_field[] = { - { 6, 02, 10, 10, -1, -1, -1, -1, -1, "wd0a", F_TITLE, 0, 0}, - { 6, 16, 4, 4, -1, 48, 6, 49, 2, "YES", F_EDIT, 0, 0}, - { 6, 27, 7, 7, -1, 48, 7, 1, 3, "MSDOS", F_EDIT, 0, 0}, - { 6, 39, 5, 5, -1, 49, 8, 2, 4, "1000", F_EDIT, 0, 0}, - { 6, 47, 30, 79, -1, 49, 9, 3, 6, "/an/example/mountpoint", F_EDIT, 0, 0}, - { 8, 02, 4, 4, -1, -1, -1, -1, -1, "wd0b", F_TITLE, 0, 0}, - { 8, 16, 4, 4, -1, 1, 11, 4, 7, "YES", F_EDIT, 0, 0}, - { 8, 27, 7, 7, -1, 2, 12, 6, 8, "MSDOS", F_EDIT, 0, 0}, - { 8, 39, 5, 5, -1, 3, 13, 7, 9, "1000", F_EDIT, 0, 0}, - { 8, 47, 30, 79, -1, 4, 14, 8, 11, "/an/example/mountpoint", F_EDIT, 0, 0}, - {10, 02, 10, 10, -1, -1, -1, -1, -1, "wd0c", F_TITLE, 0, 0}, - {10, 16, 4, 4, -1, 6, 16, 9, 12, "YES", F_EDIT, 0, 0}, - {10, 27, 7, 7, -1, 7, 17, 11, 13, "MSDOS", F_EDIT, 0, 0}, - {10, 39, 5, 5, -1, 8, 18, 12, 14, "1000", F_EDIT, 0, 0}, - {10, 47, 30, 79, -1, 9, 19, 13, 16, "/an/example/mountpoint", F_EDIT, 0, 0}, - {12, 02, 10, 10, -1, -1, -1, -1, -1, "wd0d", F_TITLE, 0, 0}, - {12, 16, 4, 4, -1, 11, 21, 14, 17, "YES", F_EDIT, 0, 0}, - {12, 27, 7, 7, -1, 12, 22, 16, 18, "MSDOS", F_EDIT, 0, 0}, - {12, 39, 5, 5, -1, 13, 23, 17, 19, "1000", F_EDIT, 0, 0}, - {12, 47, 30, 79, -1, 14, 24, 18, 21, "/an/example/mountpoint", F_EDIT, 0, 0}, - {14, 02, 10, 10, -1, -1, -1, -1, -1, "wd0e", F_TITLE, 0, 0}, - {14, 16, 4, 4, -1, 16, 26, 19, 22, "YES", F_EDIT, 0, 0}, - {14, 27, 7, 7, -1, 17, 27, 21, 23, "MSDOS", F_EDIT, 0, 0}, - {14, 39, 5, 5, -1, 18, 28, 22, 24, "1000", F_EDIT, 0, 0}, - {14, 47, 30, 79, -1, 19, 29, 23, 26, "/an/example/mountpoint", F_EDIT, 0, 0}, - {16, 02, 10, 10, -1, -1, -1, -1, -1, "wd0f", F_TITLE, 0, 0}, - {16, 16, 4, 4, -1, 21, 31, 24, 27, "YES", F_EDIT, 0, 0}, - {16, 27, 7, 7, -1, 22, 32, 26, 28, "MSDOS", F_EDIT, 0, 0}, - {16, 39, 5, 5, -1, 23, 33, 27, 29, "1000", F_EDIT, 0, 0}, - {16, 47, 30, 79, -1, 24, 34, 28, 31, "/an/example/mountpoint", F_EDIT, 0, 0}, - {18, 02, 10, 10, -1, -1, -1, -1, -1, "wd0g", F_TITLE, 0, 0}, - {18, 16, 4, 4, -1, 26, 36, 29, 32, "YES", F_EDIT, 0, 0}, - {18, 27, 7, 7, -1, 27, 37, 31, 33, "MSDOS", F_EDIT, 0, 0}, - {18, 39, 5, 5, -1, 28, 38, 32, 34, "1000", F_EDIT, 0, 0}, - {18, 47, 30, 79, -1, 29, 39, 33, 36, "/an/example/mountpoint", F_EDIT, 0, 0}, - {20, 02, 10, 10, -1, -1, -1, -1, -1, "wd0h", F_TITLE, 0, 0}, - {20, 16, 4, 4, -1, 31, 48, 34, 37, "YES", F_EDIT, 0, 0}, - {20, 27, 7, 7, -1, 32, 48, 36, 38, "MSDOS", F_EDIT, 0, 0}, - {20, 39, 5, 5, -1, 33, 49, 37, 39, "1000", F_EDIT, 0, 0}, - {20, 47, 30, 79, 1, 34, 49, 38, 48, "/an/example/mountpoint", F_EDIT, 0, 0}, - { 0, 27, 17, 17, -1, -1, -1, -1, -1, "Disk label editor", F_TITLE, 0, 0}, - { 4, 2, 11, 11, -1, -1, -1, -1, -1, "Partition", F_TITLE, 0, 0}, - { 4, 14, 8, 8, -1, -1, -1, -1, -1, "Preserve", F_TITLE, 0, 0}, - { 4, 25, 10, 10, -1, -1, -1, -1, -1, "Filesystem", F_TITLE, 0, 0}, - { 4, 39, 5, 5, -1, -1, -1, -1, -1, "Size", F_TITLE, 0, 0}, - { 4, 47, 10, 10, -1, -1, -1, -1, -1, "Mountpoint", F_TITLE, 0, 0}, - { 2, 02, 11, 11, -1, -1, -1, -1, -1, "Free space:", F_EDIT, 0, 0}, - { 2, 15, 6, 6, -1, -1, -1, -1, -1, "000000", F_TITLE, 0, 0}, - {22, 20, 2, 2, -1, 36, 1, 39, 49, "OK", F_BUTTON, 0, 0}, - {22, 45, 2, 2, -1, 38, 3, 48, 1, "Cancel", F_BUTTON, 0, 0} -}; diff --git a/sbin/sysinstall/main.c b/sbin/sysinstall/main.c deleted file mode 100644 index d1db0e1..0000000 --- a/sbin/sysinstall/main.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: main.c,v 1.20 1995/01/30 03:19:52 phk Exp $ - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <unistd.h> -#include <fcntl.h> -#include <signal.h> - -#include <dialog.h> - -#include <sys/ioctl.h> -#include <sys/reboot.h> - -#define EXTERN /* only in main.c */ - -#include "sysinstall.h" - -void -handle_intr(int sig) -{ - dialog_clear_norefresh(); - dialog_msgbox("User Interrupt", - "User interrupted. Aborting the installation", - -1, -1, 1); - ExitSysinstall(); -} - -int -main(int argc, char **argv) -{ - signal(SIGINT, SIG_IGN); - - /* Are we running as init? */ - cpio_fd = -1; - if (getpid() == 1) { - setsid(); - if (argc > 1 && strchr(argv[1],'C')) { - /* Kernel told us that we are on a CDROM root */ - close(0); open("/bootcd/dev/console",O_RDWR); - close(1); dup(0); - close(2); dup(0); - cpio_fd = open("/floppies/cpio.flp",O_RDONLY); - on_cdrom++; - chroot("/bootcd"); - } else { - close(0); open("/dev/console",O_RDWR); - close(1); dup(0); - close(2); dup(0); - } - printf("sysinstall running as init\n\r"); - ioctl(0,TIOCSCTTY,(char *)NULL); - setlogin("root"); - setbuf(stdin,0); - setbuf(stdout,0); - setbuf(stderr,0); - } - if (set_termcap() == -1) { - Fatal("Can't find terminal entry\n"); - } - /* XXX too early to use fatal ! */ - - /* XXX - libdialog has particularly bad return value checking */ - init_dialog(); - /* If we haven't crashed I guess dialog is running ! */ - dialog_active = 1; - - signal(SIGINT, handle_intr); - - if (getpid() != 1) { - stage0(); - stage1(); - end_dialog(); - dialog_active=0; - } else if (!access("/this_is_boot_flp",R_OK)) { - while(1) { - stage0(); - if(!stage1()) - break; - } - stage2(); - end_dialog(); - dialog_active=0; - reboot(RB_AUTOBOOT); - } else { - stage3(); - stage5(); - } - return 0; -} diff --git a/sbin/sysinstall/mbr.c b/sbin/sysinstall/mbr.c deleted file mode 100644 index 03a85a7..0000000 --- a/sbin/sysinstall/mbr.c +++ /dev/null @@ -1,477 +0,0 @@ -/* - * Copyright (c) 1994, Paul Richards. - * - * All rights reserved. - * - * This software may be used, modified, copied, distributed, and - * sold, in both source and binary form provided that the above - * copyright and these terms are retained, verbatim, as the first - * lines of this file. Under no circumstances is the author - * responsible for the proper functioning of this software, nor does - * the author assume any responsibility for damages incurred with - * its use. - */ - -#include <stdio.h> -#include <unistd.h> -#include <dialog.h> -#include <fcntl.h> - -#include <sys/types.h> -#include <sys/disklabel.h> -#include <sys/uio.h> - -#include "mbr.h" -#include "sysinstall.h" - -extern struct mbr *mbr; -extern int inst_part; -extern int whole_disk; - -struct part_type part_types[] = PARTITION_TYPES - -char * -part_type(int type) -{ - int num_types = (sizeof(part_types)/sizeof(struct part_type)); - int next_type = 0; - struct part_type *ptr = part_types; - - while (next_type < num_types) { - if(ptr->type == type) - return(ptr->name); - ptr++; - next_type++; - } - return("Unknown"); -} - -void -read_dospart(int fd, struct dos_partition *dp) -{ - u_char buf[512]; - if (lseek(fd, 0, SEEK_SET) == -1) - AskAbort("Couldn't seek for master boot record read\n"); - if (read(fd, buf, 512) != 512) { - AskAbort("Failed to read master boot record\n"); - } - memcpy(dp, buf+DOSPARTOFF, sizeof(*dp)*NDOSPART); -} - -void -write_dospart(int fd, struct dos_partition *dp) -{ - u_char buf[512]; - - if (lseek(fd, 0, SEEK_SET) == -1) - AskAbort("Couldn't seek for master boot record read\n"); - if (read(fd, buf, 512) != 512) { - AskAbort("Failed to read master boot record\n"); - } - memcpy(buf+DOSPARTOFF, dp, sizeof(*dp)*NDOSPART); - buf[510] = 0x55; - buf[511] = 0xaa; - if (lseek(fd, 0, SEEK_SET) == -1) - AskAbort("Couldn't seek for master boot record write\n"); - enable_label(fd); - if (write(fd, buf, 512) != 512) - AskAbort("Failed to write master boot record\n"); - disable_label(fd); -} - -void -write_bootcode(int fd) -{ - u_char buf[512]; - - if (lseek(fd, 0, SEEK_SET) == -1) - AskAbort("Couldn't seek for master boot record read\n"); - if (read(fd, buf, 512) != 512) { - AskAbort("Failed to read master boot record\n"); - } - memcpy(buf, boot0, DOSPARTOFF); - buf[510] = 0x55; - buf[511] = 0xaa; - if (lseek(fd, 0, SEEK_SET) == -1) - AskAbort("Couldn't seek for master boot record write\n"); - enable_label(fd); - if (write(fd, buf, 512) != 512) - AskAbort("Failed to write master boot record\n"); - disable_label(fd); -} - -int -WriteBootblock(int dfd,struct disklabel *label,struct dos_partition *dospart) -{ - off_t of = label->d_partitions[OURPART].p_offset; - u_char bootblocks[BBSIZE]; - - memcpy(bootblocks, boot1, MBRSIZE); - - memcpy(&bootblocks[MBRSIZE], boot2, (int)(label->d_bbsize - MBRSIZE)); - - bcopy(dospart, &bootblocks[DOSPARTOFF], - sizeof(struct dos_partition) * NDOSPART); - - label->d_checksum = 0; - label->d_checksum = dkcksum(label); - bcopy(label, &bootblocks[(LABELSECTOR * label->d_secsize) + LABELOFFSET], - sizeof *label); - - Debug("Seeking to byte %ld ", of * label->d_secsize); - - if (lseek(dfd, (of * label->d_secsize), SEEK_SET) < 0) { - Fatal("Couldn't seek to start of partition\n"); - } - - enable_label(dfd); - - if (write(dfd, bootblocks, label->d_bbsize) != label->d_bbsize) { - Fatal("Failed to write bootblocks (%p,%d) %d %s\n", - bootblocks, label->d_bbsize, - errno, strerror(errno) - ); - } - - disable_label(dfd); - - return(0); -} - -static int -FillIn(struct dos_partition *dp, int sec, int hd) -{ - u_long l2,l3=0,sect,c,s,h; - - sect = dp->dp_start; - l2 = sect / (sec*hd); - sect -= l2*sec*hd; - if(l2>1023) l2 = 1023; - c = (l2 & 0xff); - s = (l2 >> 2) & 0xc0; - l2 = sect / sec; - h = l2; - sect -= l2*sec; - s |= (sect+1) & 0x3f; -#define NIC(a,b) if (a != b) {a = b; l3++;} - NIC(dp->dp_ssect, s); - NIC(dp->dp_scyl, c); - NIC(dp->dp_shd, h); - - sect = dp->dp_start + dp->dp_size-1; - l2 = sect / (sec*hd); - sect -= l2*sec*hd; - if(l2>1023) l2 = 1023; - c = (l2 & 0xff); - s = (l2 >> 2) & 0xc0; - l2 = sect / sec; - h = l2; - sect -= l2*sec; - s |= (sect+1) & 0x3f; - NIC(dp->dp_esect, s); - NIC(dp->dp_ecyl, c); - NIC(dp->dp_ehd, h); -#undef NIC - return l2; -} - -void -Fdisk() -{ - int i, j, done=0, diskno, flag; - char buf[128]; - struct dos_partition dp[NDOSPART]; - struct disklabel *lbl; - u_long cyl, hd, sec, tsec; - u_long l, l1, l2, l3, l4; - int changed = 0; - char *grumble = NULL; - - *buf = 0; - i = AskEm(stdscr, "Enter number of disk to Fdisk> ", buf, 2); - printf("%d", i); - if(i != '\n' && i != '\r') return; - diskno = atoi(buf); - if(!(diskno >= 0 && diskno < MAX_NO_DISKS && Dname[diskno])) return; - lbl = Dlbl[diskno]; - lbl->d_bbsize = 8192; - hd = lbl->d_ntracks; - sec = lbl->d_nsectors; - tsec = Dlbl[diskno]->d_partitions[RAWPART].p_size; - cyl = tsec/(hd*sec); - read_dospart(Dfd[diskno], dp); - while(!done) { - clear(); standend(); - j = 0; - mvprintw(j++, 0, "%s -- Diskspace editor -- FDISK", TITLE); - j++; - mvprintw(j++, 0, - "Disk: %s Geometry: %lu Cyl * %lu Hd * %lu Sect", - Dname[diskno], cyl, hd, sec); - printw(" = %luMb = %lu Sect", (tsec+1024)/2048, tsec); - j++; - for(i=0;i<NDOSPART;i++, j+=4) { - mvprintw(j, 0, "%d ", i+1); -#if 0 - printw("[%02x %02x %02x %02x %02x %02x %02x %02x %08lx %08lx]\n", - dp[i].dp_flag, dp[i].dp_shd, dp[i].dp_ssect, dp[i].dp_scyl, - dp[i].dp_typ, dp[i].dp_ehd, dp[i].dp_esect, dp[i].dp_ecyl, - dp[i].dp_start, dp[i].dp_size); -#endif - if(!dp[i].dp_size) { - printw("Unused"); - continue; - } - printw("Boot?=%s", dp[i].dp_flag == 0x80 ? "Yes" : "No "); - printw(" Type=%s\n", part_type(dp[i].dp_typ)); - printw(" Phys=(c%d/h%d/s%d..c%d/h%d/s%d)", - DPCYL(dp[i].dp_scyl, dp[i].dp_ssect), dp[i].dp_shd, - DPSECT(dp[i].dp_ssect), - DPCYL(dp[i].dp_ecyl, dp[i].dp_esect), dp[i].dp_ehd, - DPSECT(dp[i].dp_esect)); - printw(" Sector=(%lu..%lu)\n", - dp[i].dp_start, dp[i].dp_size + dp[i].dp_start-1); - printw(" Size=%lu MB, %lu Cylinders", (dp[i].dp_size+1024L)/2048L, - dp[i].dp_size/lbl->d_secpercyl); - l = dp[i].dp_size%lbl->d_secpercyl; - if(l) { - printw(" + %lu Tracks", l/lbl->d_nsectors); - l = l % lbl->d_nsectors; - if(l) { - printw(" + %lu Sectors", l); - } - } - } - mvprintw(20, 0, "Commands available: "); - mvprintw(21, 0, "(H)elp (T)utorial (D)elete (E)dit (R)eread (W)rite MBR (Q)uit"); - mvprintw(22, 0, "(U)se entire disk for FreeBSD (G)eometry use (B)oot manager"); - if (grumble) { - standout(); - mvprintw(24, 0, grumble); - standend(); - grumble = NULL; - } else if (changed) { - standout(); - mvprintw(24, 0, "Use (W)rite to save changes to disk"); - standend(); - } - mvprintw(23, 0, "Enter Command> "); - i=getch(); - switch(i) { - - case 'h': case 'H': - clear(); - mvprintw(0, 0, -"%s -- Diskspace editor -- FDISK -- Command Help - -Basic commands: - -(H)elp - This screen -(T)utorial - A more detailed discussion of MBR's, disklabels, etc. -(D)elete - Delete an existing partition -(E)dit - Edit an existing partition -(R)eread - Read fdisk information from disk again, abandoning changes -(W)rite MBR - Write modified fdisk information to disk -(Q)uit - Exit the FDISK editor - -Advanced commands: - -(U)se entire disk for FreeBSD - Assign ALL disk space on current drive -(G)eometry - Edit the default disk geometry settings -Write (B)oot manager - Install multi-OS bootmanager. - - -Press any key to return to FDISK editor... -", TITLE); - getch(); - break; - case 't': case 'T': - ShowFile(HELPME_FILE,"Help file for disklayout"); - break; - - case 'r': case 'R': - read_dospart(Dfd[diskno], dp); - changed=0; - break; - - case 'b': case 'B': - grumble = 0; - for(i=0;i<NDOSPART;i++) { - if(dp[i].dp_start == 0 && dp[i].dp_typ== MBR_PTYPE_FreeBSD) { - grumble = "Boot manager not needed."; - break; - } - } - if (!grumble) - write_bootcode(Dfd[diskno]); - grumble = "Wrote boot manager"; - break; - - case 'e': case 'E': - *buf = 0; - i = AskEm(stdscr, "Edit which Slice> ", buf, 2); - if(i != '\n' && i != '\r') break; - l = strtol(buf, 0, 0); - if(l < 1 || l > NDOSPART) break; - l1=sec; l2=tsec; - for(i=0;i<NDOSPART;i++) { - if((i+1) == l) continue; - if(!dp[i].dp_size) continue; - if(dp[i].dp_start > l2) continue; - if((dp[i].dp_start + dp[i].dp_size) <= l1) continue; - if(dp[i].dp_start > l1) - l3 = dp[i].dp_start - l1; - else - l3 = 0; - if(l2 > (dp[i].dp_start + dp[i].dp_size)) - l4 = l2 - (dp[i].dp_start + dp[i].dp_size); - else - l4 = 0; - if(l3 >= l4) - l2 = dp[i].dp_start; - else - l1 = dp[i].dp_start + dp[i].dp_size; - } - sprintf(buf, "%lu", (l2-l1+1024L)/2048L); - i = AskEm(stdscr, "Size of slice in MB> ", buf, 10); - l3=strtol(buf, 0, 0) * 2048L; - if(!l3) break; - if(l3 > l2-l1) - l3 = l2-l1; - if((l1+l3) % lbl->d_secpercyl) { /* Special for cyl==0 */ - l3 += lbl->d_secpercyl - ((l1+l3) % lbl->d_secpercyl); - } - if(l3+l1 > tsec) - l3 = tsec - l1; - changed=1; - dp[l-1].dp_start=l1; - dp[l-1].dp_size=l3; - FillIn(&dp[l-1],sec,hd); - - l4 = dp[l-1].dp_typ; - if(!l4) l4 = MBR_PTYPE_FreeBSD; - sprintf(buf, "0x%lx", l4); - i = AskEm(stdscr, "Type of slice (0xa5=FreeBSD)> ", buf, 5); - l3 = strtol(buf, 0, 0); - if(l3 == MBR_PTYPE_FreeBSD) { - for(i=0;i<NDOSPART;i++) - if(i != (l-1) && dp[i].dp_typ== MBR_PTYPE_FreeBSD) - memset(&dp[i], 0, sizeof dp[i]); - sprintf(buf, "0x80"); - } else { - sprintf(buf, "0"); - } - dp[l-1].dp_typ=l3; - i = AskEm(stdscr, "Bootflag (0x80 for YES)> ", buf, 5); - dp[l-1].dp_flag=strtol(buf, 0, 0); - if(dp[l-1].dp_flag) - for(i=0;i<NDOSPART;i++) - if(i != (l-1)) - dp[i].dp_flag = 0; - break; - - case 'u': case 'U': - memset(&dp[0], 0, sizeof dp); - changed=1; - - dp[0].dp_start = 0; - dp[0].dp_size = tsec; - FillIn(&dp[0],sec,hd); - - dp[0].dp_typ = MBR_PTYPE_FreeBSD; - dp[0].dp_flag = 0x80; - break; - - case 'g': case 'G': - sprintf(buf,"%lu",sec); - i = AskEm(stdscr, "Number of Sectors> ",buf,7); - l2 = strtoul(buf,0,0); - if(l2 != sec) - changed++; - sec=l2; - sprintf(buf,"%lu",hd); - i = AskEm(stdscr, "Number of Heads> ",buf,7); - l2 = strtoul(buf,0,0); - if(l2 != hd) - changed++; - hd=l2; - cyl = tsec/(hd*sec); - sprintf(buf,"%lu",cyl); - i = AskEm(stdscr, "Number of Cylinders> ",buf,7); - l2 = strtoul(buf,0,0); - if(l2 != cyl) - changed++; - cyl=l2; - - for (l=0;l<NDOSPART;l++) { - if (!dp[l].dp_typ || !dp[l].dp_size) - continue; - changed += FillIn(&dp[l], sec, hd); - } - - break; - - case 'd': case 'D': - *buf = 0; - i = AskEm(stdscr, "Delete which Slice> ", buf, 2); - if(i != '\n' && i != '\r') break; - l = strtol(buf, 0, 0); - if(l < 1 || l > NDOSPART) break; - memset(&dp[l-1], 0, sizeof dp[l-1]); - changed=1; - break; - - case 'w': case 'W': - write_dospart(Dfd[diskno], dp); - Dlbl[diskno]->d_partitions[OURPART].p_offset = 0; - Dlbl[diskno]->d_partitions[OURPART].p_size = 0; - for(i=0;i<NDOSPART;i++) { - if(dp[i].dp_typ == MBR_PTYPE_FreeBSD) { - Dlbl[diskno]->d_partitions[OURPART].p_offset = - dp[i].dp_start; - Dlbl[diskno]->d_partitions[OURPART].p_size = - dp[i].dp_size; - goto wok; - } - } - grumble = "No FreeBSD slice, cannot write."; - break; - - wok: - Dlbl[diskno]->d_ntracks = hd; - Dlbl[diskno]->d_nsectors = sec; - Dlbl[diskno]->d_ncylinders = cyl; - Dlbl[diskno]->d_secpercyl = hd*sec; - Dlbl[diskno]->d_magic = DISKMAGIC; - Dlbl[diskno]->d_magic2 = DISKMAGIC; - Dlbl[diskno]->d_checksum = 0; - Dlbl[diskno]->d_checksum = dkcksum(Dlbl[diskno]); - flag=1; - enable_label(Dfd[diskno]); - if(ioctl(Dfd[diskno], DIOCSDINFO, Dlbl[diskno]) == -1) - AskAbort("Couldn't set label: %s", strerror(errno)); - if(ioctl(Dfd[diskno], DIOCWDINFO, Dlbl[diskno]) == -1) - AskAbort("Couldn't write label: %s", strerror(errno)); - flag=0; - disable_label(Dfd[diskno]); - changed=0; - - if (Dlbl[diskno]->d_partitions[OURPART].p_size) { - WriteBootblock(Dfd[diskno], lbl, dp); - grumble = "Wrote MBR and disklabel to disk"; - } else { - grumble = "Wrote MBR to disk"; - } - - break; - - case 'q': case 'Q': - return; - break; - default: - beep(); - break; - } - } -} - diff --git a/sbin/sysinstall/mbr.h b/sbin/sysinstall/mbr.h deleted file mode 100644 index 9c7d190..0000000 --- a/sbin/sysinstall/mbr.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 1994, Paul Richards. - * - * All rights reserved. - * - * This software may be used, modified, copied, distributed, and - * sold, in both source and binary form provided that the above - * copyright and these terms are retained, verbatim, as the first - * lines of this file. Under no circumstances is the author - * responsible for the proper functioning of this software, nor does - * the author assume any responsibility for damages incurred with - * its use. - */ - -#define MBRSIZE 512 -#define MBR_MAGIC 0xAA55 -#define ACTIVE 0x80 - -struct mbr -{ - unsigned char bootcode[DOSPARTOFF]; - struct dos_partition dospart[4]; - unsigned short magic; -}; - -struct part_type -{ - unsigned char type; - char *name; -}; - -#define PARTITION_TYPES \ -{ \ - {0x00, "Unused"} \ - ,{0x01, "Primary DOS with 12 bit FAT"} \ - ,{0x02, "XENIX / filesystem"} \ - ,{0x03, "XENIX /usr filesystem"} \ - ,{0x04, "Primary DOS with 16 bit FAT"} \ - ,{0x05, "Extended DOS"} \ - ,{0x06, "Primary 'big' DOS (> 32MB)"} \ - ,{0x07, "OS/2 HPFS, QNX or Advanced UNIX"} \ - ,{0x08, "AIX filesystem"} \ - ,{0x09, "AIX boot partition or Coherent"} \ - ,{0x0A, "OS/2 Boot Manager or OPUS"} \ - ,{0x10, "OPUS"} \ - ,{0x40, "VENIX 286"} \ - ,{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"} \ - ,{0x83, "Linux filesystem"} \ - ,{0x93, "Amoeba filesystem"} \ - ,{0x94, "Amoeba bad block table"} \ - ,{0xA5, "FreeBSD/NetBSD/386BSD"} \ - ,{0xA7, "NEXTSTEP"} \ - ,{0xB7, "BSDI BSD/386 filesystem"} \ - ,{0xB8, "BSDI BSD/386 swap"} \ - ,{0xDB, "Concurrent CPM or C.DOS or CTOS"} \ - ,{0xE1, "Speed"} \ - ,{0xE3, "Speed"} \ - ,{0xE4, "Speed"} \ - ,{0xF1, "Speed"} \ - ,{0xF2, "DOS 3.3+ Secondary"} \ - ,{0xF4, "Speed"} \ - ,{0xFF, "BBT (Bad Blocks Table)"} \ -}; - -extern char *part_type(int); -extern int write_mbr(int, struct mbr *); -extern int read_mbr(int, struct mbr *); -extern void show_mbr(struct mbr *); -extern int clear_mbr(struct mbr *, char *); -extern void edit_mbr(struct mbr *, struct disklabel *); -extern int build_mbr(struct mbr *, char *, struct disklabel *); diff --git a/sbin/sysinstall/ourcurses.c b/sbin/sysinstall/ourcurses.c deleted file mode 100644 index 4ee3dec..0000000 --- a/sbin/sysinstall/ourcurses.c +++ /dev/null @@ -1,38 +0,0 @@ -/* Stopgap, until Paul does the right thing */ -#define ESC 27 -#define TAB 9 - -#include <stdlib.h> -#include <limits.h> -#include <sys/types.h> -#include <string.h> - -#include <string.h> -#include <dialog.h> -#include "sysinstall.h" - -int -AskEm(WINDOW *w,char *prompt, char *answer, int len) -{ - int x,y; - mvwprintw(w,23,0,prompt); - getyx(w,y,x); - wclrtoeol(w); - return line_edit(w,y,x,len,len+1,item_selected_attr,1,answer); -} - -void -ShowFile(char *filename, char *header) -{ - char buf[256]; - if (access(filename, R_OK)) { - sprintf(buf, "The %s file is not provided on the 1.2MB floppy image.", filename); - dialog_msgbox("Sorry!", buf, -1, -1, 1); - dialog_clear_norefresh(); - return; - } - dialog_clear_norefresh(); - dialog_textbox(header, filename, LINES, COLS); - dialog_clear_norefresh(); -} - diff --git a/sbin/sysinstall/rtermcap.c b/sbin/sysinstall/rtermcap.c deleted file mode 100644 index 3f18e8b..0000000 --- a/sbin/sysinstall/rtermcap.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> -#include <termcap.h> - -int -main(int argc, char **argv) -{ - char buf[4096]; - int i; - - i = tgetent(buf, argv[1]); - - printf("%s",buf); - return 0; -} diff --git a/sbin/sysinstall/stage0.c b/sbin/sysinstall/stage0.c deleted file mode 100644 index 8c5a367..0000000 --- a/sbin/sysinstall/stage0.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 1994, Jordan Hubbard, Paul Richards and Poul-Henning Kamp. - * - * All rights reserved. - * - * This software may be used, modified, copied, distributed, and - * sold, in both source and binary form provided that the above - * copyright and these terms are retained, verbatim, as the first - * lines of this file. Under no circumstances is the author - * responsible for the proper functioning of this software, nor does - * the author assume any responsibility for damages incurred with - * its use. - * - * [Note: This file bears almost no resemblance to what was here in an - * earlier incarnation]. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <sys/reboot.h> -#include <dialog.h> - -#include "sysinstall.h" - -static unsigned char *welcome[] = { - "1. README", - "READ THIS FIRST.", - "2. Release Notes", - "Read the 2.0 Release Notes (recommended).", - "3. Troubleshooting", - "Read this in case of trouble.", - "4. Partitions and MBRs", - "Verbose description of how these work.", - "5. COPYRIGHT", - "Read FreeBSD Copyright Information.", - "6. Install", - "Proceed with full installation.", - "7. Fixit", - "Repair existing installation (fixit mode).", - "8. Quit", - "Don't do anything, just reboot.", -}; - -void -stage0() -{ -evil_goto: - if (dialog_menu("Welcome to FreeBSD!", - "Use ALT-F2 and ALT-F1 to toggle between debugging\ninformation screen (ALT-F2) or this dialog screen (ALT-F1)\n\nPlease select one of the following options:", -1, -1, 8, 8, welcome, selection, NULL, NULL)) - ExitSysinstall(); - - switch (atoi(selection)) { - case 1: /* View the README */ - ShowFile(README_FILE, "Read Me First"); - goto evil_goto; - break; - - case 2: /* View the release notes */ - ShowFile(RELNOTES_FILE, "Release Notes"); - goto evil_goto; - break; - - case 3: /* View the troubleshooting file */ - ShowFile(TROUBLE_FILE, "Troubleshooting"); - goto evil_goto; - break; - - case 4: /* View DISK FAQ */ - ShowFile(HELPME_FILE, "DISK FAQ"); - goto evil_goto; - break; - - case 5: /* View copyrights */ - ShowFile(COPYRIGHT_FILE, "COPYRIGHT"); - goto evil_goto; - break; - - case 6: /* Proceed (do nothing special, really) */ - fixit = 0; - break; - - case 7: - dialog_clear(); - dialog_update(); - dialog_msgbox("WARNING!", -"The usual install procedure will be invoked, but with most of the -sanity checks disabled. The suggested course of action is to: - 1. Go to (F)disk and do a (W)rite, and possibly a (B)oot too - if your MBR has been wiped. - 2. Go into (D)isklabel and identify your root (/) and swap - partitions. - 3. Select (P)roceed to reboot and load the cpio floppy. - 4. You will now be in the stand-alone shell, where you may - conduct further repairs with the tools you'll find in - /stand. - 5. Good luck... You'll probably need it.", -1, -1, 1); - fixit = 1; - break; - - case 8: - /* Be neat.. */ - ExitSysinstall(); - break; /* hope not! :) */ - } -} diff --git a/sbin/sysinstall/stage1.c b/sbin/sysinstall/stage1.c deleted file mode 100644 index ade697b..0000000 --- a/sbin/sysinstall/stage1.c +++ /dev/null @@ -1,229 +0,0 @@ -/* -#define DEBUG - * Copyright (c) 1994, Paul Richards. - * - * All rights reserved. - * - * This software may be used, modified, copied, distributed, and - * sold, in both source and binary form provided that the above - * copyright and these terms are retained, verbatim, as the first - * lines of this file. Under no circumstances is the author - * responsible for the proper functioning of this software, nor does - * the author assume any responsibility for damages incurred with - * its use. - */ - -#include <dialog.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <stdarg.h> - -#include <sys/types.h> -#include <sys/errno.h> -#include <sys/disklabel.h> -#include <sys/ioctl.h> -#include <sys/param.h> -#include <sys/stat.h> - -#include "sysinstall.h" - -char * device_list[] = {"wd","sd",0}; - -void -query_disks() -{ - int i,j; - char disk[15]; - char diskname[5]; - struct stat st; - struct disklabel dl; - int fd; - - for(i = 0; i < MAX_NO_DISKS; i++) - if(Dname[i]) { - close(Dfd[i]); Dfd[i] = 0; - free(Dlbl[i]); Dlbl[i] = 0; - free(Dname[i]); Dname[i] = 0; - } - - Ndisk = 0; - - for (j = 0; device_list[j]; j++) { - for (i = 0; i < 10; i++) { - sprintf(diskname, "%s%d", device_list[j], i); - sprintf(disk, "/dev/r%sd", diskname); - if (stat(disk, &st) || !(st.st_mode & S_IFCHR)) - continue; - if ((fd = open(disk, O_RDWR)) == -1) - continue; - if (ioctl(fd, DIOCGDINFO, &dl) == -1) { - close(fd); - continue; - } - Dlbl[Ndisk] = Malloc(sizeof dl); - memcpy(Dlbl[Ndisk], &dl, sizeof dl); - Dname[Ndisk] = StrAlloc(diskname); - Dfd[Ndisk] = fd; - Ndisk++; - if(Ndisk == MAX_NO_DISKS) - return; - } - } -} - -int -stage1() -{ - int i,j; - int ret=1; - int ready = 0; - int foundroot=0,foundusr=0,foundswap=0; - char *complaint=0; - - query_disks(); - - while (!ready) { - clear(); standend(); - j = 2; - if (fixit) { - mvprintw(j++, 50, "|Suggested course of action:"); - mvprintw(j++, 50, "|"); - mvprintw(j++, 50, "|(F)disk, (W)rite"); - mvprintw(j++, 50, "|possibly (F)disk, (B)oot"); - mvprintw(j++, 50, "|(D)isklabel, (A)ssign <root>"); - mvprintw(j++, 50, "|(A)ssign swap"); - mvprintw(j++, 50, "|(P)roceed"); - mvprintw(j++, 50, "|Reboot"); - mvprintw(j++, 50, "|Load cpio floppy"); - mvprintw(j++, 50, "|Choose stand-alone shell"); - mvprintw(j++, 50, "|"); - mvprintw(j++, 50, "|Your old kernel, /etc/fstab"); - mvprintw(j++, 50, "|and /sbin/init files are"); - mvprintw(j++, 50, "|renamed since they will be"); - mvprintw(j++, 50, "|replaced from this floppy."); - } else { - mvprintw(j++, 50, "|You should now assign some"); - mvprintw(j++, 50, "|space to root, swap, and"); - mvprintw(j++, 50, "|(optionally) /usr partitions"); - mvprintw(j++, 50, "|Root (/) should be a minimum"); - mvprintw(j++, 50, "|of 18MB with a 30MB /usr"); - mvprintw(j++, 50, "|or 50MB without a /usr."); - mvprintw(j++, 50, "|Swap space should be a"); - mvprintw(j++, 50, "|minimum of 12MB or RAM * 2"); - mvprintw(j++, 50, "|Be sure to also (A)ssign a"); - mvprintw(j++, 50, "|mount point to each one or"); - mvprintw(j++, 50, "|it will NOT be enabled."); - mvprintw(j++, 50, "|"); - mvprintw(j++, 50, "|We suggest that you invoke"); - mvprintw(j++, 50, "|(F)disk, (W)rite bootcode"); - mvprintw(j++, 50, "|then (D)isklabel your disk."); - mvprintw(j++, 50, "|If installing on a drive"); - mvprintw(j++, 50, "|other than 0, also read the"); - mvprintw(j++, 50, "|TROUBLESHOOTING doc first"); - } - - j = 0; - mvprintw(j++, 0, "%s -- Diskspace editor", TITLE); - j++; - mvprintw(j++, 0, "Disks Total FreeBSD "); - j++; - for(i = 0; i < MAX_NO_DISKS && Dname[i]; i++) { - mvprintw(j++, 0, "%2d: %-6s %5lu MB %5lu MB", - i, - Dname[i], - PartMb(Dlbl[i],RAWPART), - PartMb(Dlbl[i],OURPART)); - } - j++; - mvprintw(j++, 0, "Filesystems Type Size Action Mountpoint"); - j++; - for(i = 0; i < MAX_NO_FS; i++) { - if(!Fname[i]) - continue; - if(!strcmp(Ftype[i],"swap")) { - mvprintw(j++, 0, "%2d: %-5s %-5s %5lu MB %-6s %-s", - i, Fname[i], Ftype[i], Fsize[i], "swap", Fmount[i]); - } else { - mvprintw(j++, 0, "%2d: %-5s %-5s %5lu MB %-6s %-s", - i, Fname[i], Ftype[i], Fsize[i], - Faction[i] ? "newfs" : "mount", Fmount[i]); - } - } - - mvprintw(20, 0, "Commands available:"); - mvprintw(21, 0, "(H)elp (T)utorial (F)disk (D)isklabel (P)roceed (Q)uit"); - if(complaint) { - standout(); - mvprintw(22, 0, complaint); - standend(); - complaint = 0; - } - mvprintw(23, 0, "Enter Command> "); - i = getch(); - switch(i) { - case 'h': case 'H': - clear(); - mvprintw(0, 0, -"%s -- Diskspace editor -- Command Help - -(T)utorial - Read a more detailed tutorial on how disklabels, MBRs, - etc. work. -(P)roceed - Proceed with system installation. -(Q)uit - Don't install anything. -(F)disk - Enter the FDISK (MBR) editor. -(D)isklabel - Enter the disklabel editor. - -Press any key to return to Diskspace editor...", TITLE); - getch(); - break; - case 't': case 'T': - ShowFile(HELPME_FILE,"Help file for disklayout"); - break; - case 'p': case 'P': - foundroot=0,foundusr=0,foundswap=0; - for (i = 1; Fmount[i]; i++) { - if(!strcmp(Fmount[i],"/")) foundroot=i; - if(!strcmp(Fmount[i],"swap")) foundswap=i; - if(!strcmp(Fmount[i],"/usr")) foundusr=i; - } - if (!foundroot) { - complaint = "Please assign mountpoint for '/'"; - break; - } - if (!foundswap) { - complaint = "Please assign mountpoint for swap"; - break; - } - if (!fixit && !foundusr && Fsize[foundroot] < 60) { - complaint = "Please assign mountpoint for /usr"; - break; - } - if (dialog_yesno("Last Chance!", - "Are you sure you want to proceed with the installation?\nLast chance before wiping your hard disk!", -1, -1)) - break; - ret = 0; - goto leave; - case 'q': case 'Q': - ret = 1; - goto leave; - case 'f': case 'F': - Fdisk(); - query_disks(); - break; - case 'd': case 'D': - DiskLabel(); - break; - default: - beep(); - } - } -leave: - clear(); - for (i = 0; Dname[i]; i++) - close(Dfd[i]); - return ret; -} - diff --git a/sbin/sysinstall/stage2.c b/sbin/sysinstall/stage2.c deleted file mode 100644 index 7d02845..0000000 --- a/sbin/sysinstall/stage2.c +++ /dev/null @@ -1,235 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: stage2.c,v 1.26 1995/03/15 06:16:10 phk Exp $ - * - */ - - -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <string.h> -#include <unistd.h> - -#include <fcntl.h> -#include <dialog.h> -#include <errno.h> - -#include <sys/stat.h> -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/wait.h> - -#include "sysinstall.h" - -void -stage2() -{ - char *p, *q; - char pbuf[90]; - char dbuf[90]; - FILE *f1; - int i, j, k; - int ffd, pfd[2]; - int zpid, cpid; - - memset(Fsize, 0, sizeof Fsize); - - /* Sort in mountpoint order */ - for (i = 1; Fname[i]; i++) - Fsize[i] = i; - Fsize[i] = 0; - - for (j = 1; j;) - for (j = 0, i = 1; Fsize[i+1]; i++) { - if (strcmp(Fmount[Fsize[i]], Fmount[Fsize[i+1]]) > 0) { - j = Fsize[i]; - Fsize[i] = Fsize[i+1]; - Fsize[i + 1] = j; - } - } - - for (j = 1; Fsize[j]; j++) { - if (strcmp(Ftype[Fsize[j]], "ufs")) - continue; - p = Fname[Fsize[j]]; - strcpy(pbuf, "/dev/r"); - strcat(pbuf, p); - if (!Faction[Fsize[j]]) { - TellEm("fsck -y /dev/r%s",p); - i = exec(0, "/stand/fsck", "/stand/fsck", "-y", pbuf, 0); - if (i) - Fatal("Exec(/stand/fsck) failed, code=%d.",i); - } else { - TellEm("newfs /dev/r%s",p); - i = exec(0, "/stand/newfs", "/stand/newfs", "-n", "1", pbuf, 0); - if (i) - Fatal("Exec(/stand/newfs) failed, code=%d.",i); - } - } - - for (j = 1; Fsize[j]; j++) { - if (!strcmp(Ftype[Fsize[j]], "swap")) - continue; - strcpy(dbuf, "/mnt"); - p = Fname[Fsize[j]]; - q = Fmount[Fsize[j]]; - if (strcmp(q, "/")) - strcat(dbuf, q); - if (!strcmp(Ftype[Fsize[j]], "ufs")) { - MountUfs(p, dbuf, 1, 0); - continue; - } else { - Mkdir(dbuf, FALSE); - } - } - - Mkdir("/mnt/etc", TRUE); - Mkdir("/mnt/dev", TRUE); - Mkdir("/mnt/mnt", TRUE); - Mkdir("/mnt/stand", TRUE); - - TellEm("unzipping /stand/sysinstall onto hard disk"); - exec(4, "/stand/gzip", "zcat", 0 ); - Link("/mnt/stand/sysinstall","/mnt/stand/cpio"); - Link("/mnt/stand/sysinstall","/mnt/stand/bad144"); - Link("/mnt/stand/sysinstall","/mnt/stand/gunzip"); - Link("/mnt/stand/sysinstall","/mnt/stand/gzip"); - Link("/mnt/stand/sysinstall","/mnt/stand/zcat"); - Link("/mnt/stand/sysinstall","/mnt/stand/newfs"); - Link("/mnt/stand/sysinstall","/mnt/stand/fsck"); - Link("/mnt/stand/sysinstall","/mnt/stand/dialog"); - - if (fixit) { - for (i=0;i<100;i++) { - sprintf(pbuf,"/mnt/etc/fstab.before.fixit.%d",i); - if (access(pbuf,R_OK)) { - rename("/mnt/etc/fstab",pbuf); - break; - } - } - for (i=0;i<100;i++) { - sprintf(pbuf,"/mnt/kernel.before.fixit.%d",i); - if (access(pbuf,R_OK)) { - rename("/mnt/kernel",pbuf); - break; - } - } - for (i=0;i<100;i++) { - sprintf(pbuf,"/mnt/sbin/init.before.fixit.%d",i); - if (access(pbuf,R_OK)) { - rename("/mnt/sbin/init",pbuf); - break; - } - } - } - - TellEm("make /dev entries"); - chdir("/mnt/dev"); - makedevs(); - chdir("/"); - - TellEm("Making /mnt/etc/fstab"); - f1 = fopen("/mnt/etc/fstab","w"); - if (!f1) - Fatal("Couldn't open /mnt/etc/fstab for writing."); - - TellEm("Writing filesystems"); - chdir("/mnt"); - for (j = 1; Fsize[j]; j++) { - if (!strcmp(Ftype[Fsize[j]],"swap")) - fprintf(f1, "/dev/%s\t\tnone\tswap sw 0 0\n", Fname[Fsize[j]]); - else { - fprintf(f1, "/dev/%s\t\t%s\t%s rw 1 1\n", - Fname[Fsize[j]], Fmount[Fsize[j]], Ftype[Fsize[j]]); - Mkdir(Fmount[Fsize[j]], FALSE); - } - } - chdir("/"); - TellEm("Writing procfs"); - fprintf(f1,"proc\t\t\t/proc\tprocfs rw 0 0\n"); - fclose(f1); - - j = fork(); - if (!j) { - chroot("/mnt"); - chdir("/"); - ffd = cpio_fd; - retry: - while (ffd < 0) { - dialog_msgbox(TITLE, - "Insert CPIO floppy in floppy drive 0", -1, -1, 1); - ffd = open("/dev/rfd0",O_RDONLY); - if (ffd > 0) - break; - Debug("problems opening /dev/rfd0: %d",errno); - } - dialog_clear_norefresh(); - TellEm("gunzip < /dev/fd0 | cpio -idum"); - pipe(pfd); - zpid = fork(); - if (!zpid) { - close(0); dup(ffd); close(ffd); - close(1); dup(pfd[1]); close(pfd[1]); - close(pfd[0]); - i = exec (1,"/stand/gunzip","/stand/gunzip", 0); - exit(i); - } - cpid = fork(); - if (!cpid) { - close(0); dup(pfd[0]); close(pfd[0]); - close(ffd); - close(pfd[1]); - close(1); open("/dev/null",O_WRONLY); - i = exec (1,"/stand/cpio","/stand/cpio","-iduvm", 0); - exit(i); - } - close(pfd[0]); - close(pfd[1]); - close(ffd); - i = wait(&j); - if (i < 0 || j) - Fatal("Pid %d, status %d, cpio=%d, gunzip=%d.\nerror:%s", - i, j, cpid, zpid, strerror(errno)); - i = wait(&j); - if (i < 0 || j) - Fatal("Pid %d, status %d, cpio=%d, gunzip=%d.\nerror:%s", - i, j, cpid, zpid, strerror(errno)); - - /* bininst.sh MUST be the last file on the floppy */ - if (access("/OK", R_OK) == -1) { - AskAbort("CPIO floppy was bad! Please check media for defects and retry."); - ffd = -1; - goto retry; - } - unlink("/OK"); - exit (0); - } - i = wait(&k); - Debug("chroot'er: %d %d %d",i,j,k); - - - sync(); - TellEm("Unmount disks"); - for (j = 1; Fsize[j]; j++) - continue; - - for (j--; j > 0; j--) { - if (!strcmp(Ftype[Fsize[j]],"swap")) - continue; - strcpy(dbuf,"/mnt"); - if (strcmp(Fmount[Fsize[j]],"/")) - strcat(dbuf, Fmount[Fsize[j]]); - TellEm("unmount %s", dbuf); - /* Don't do error-check, we reboot anyway... */ - unmount(dbuf, 0); - } - dialog_msgbox(TITLE,"Remove the floppy from the drive\n and hit return to reboot from the hard disk", -1, -1, 1); - dialog_clear(); -} diff --git a/sbin/sysinstall/stage3.c b/sbin/sysinstall/stage3.c deleted file mode 100644 index c08cccb..0000000 --- a/sbin/sysinstall/stage3.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: stage3.c,v 1.9.2.1 1994/11/21 03:12:18 phk Exp $ - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <dialog.h> -#include <string.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> -#include <fstab.h> - -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/stat.h> - -#include "sysinstall.h" - -void -stage3() -{ - char pbuf[90],*p; - int mountflags; - struct fstab *fs; - - /* - * Mount things in /etc/fstab we like. - */ - - mountflags = MNT_UPDATE; - while((fs = getfsent()) != NULL) { - p = fs->fs_spec; - if (*p++ != '/') continue; - if (*p++ != 'd') continue; - if (*p++ != 'e') continue; - if (*p++ != 'v') continue; - if (*p++ != '/') continue; - - if (!strcmp(fs->fs_type, "sw")) { - if (swapon(fs->fs_spec) == -1) - AskAbort("Unable to swap to %s - are you sure it's right?", - fs->fs_spec); - continue; - } - - if (strcmp(fs->fs_vfstype, "ufs")) continue; - - if (!strcmp(fs->fs_type, "ro")) - mountflags |= MNT_RDONLY; - else if (!strcmp(fs->fs_type, "rw")) - ; - else - continue; - strcpy(pbuf, "/dev/r"); - strcat(pbuf,p); - TellEm("fsck -y %s",pbuf); - if (exec(0, "/stand/fsck", - "/stand/fsck", "-y", pbuf, 0) == -1) - Fatal("exec(fsck) failed"); - - MountUfs(p, fs->fs_file, 0, mountflags); - mountflags = 0; - } - endfsent(); -} diff --git a/sbin/sysinstall/stage4.c b/sbin/sysinstall/stage4.c deleted file mode 100644 index 4f127ac..0000000 --- a/sbin/sysinstall/stage4.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: stage4.c,v 1.12 1995/01/28 01:13:28 jkh Exp $ - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <dialog.h> -#include <string.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> - -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/wait.h> - -#include "sysinstall.h" - -void -stage4() { /* Obsolete */ } diff --git a/sbin/sysinstall/stage5.c b/sbin/sysinstall/stage5.c deleted file mode 100644 index 218233a..0000000 --- a/sbin/sysinstall/stage5.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: stage5.c,v 1.17 1994/12/27 23:26:57 jkh Exp $ - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <dialog.h> -#include <string.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> - -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/stat.h> - -#include "sysinstall.h" - -static unsigned char msg[] = " -You are now done with the initial phase of the installation that -gets FreeBSD onto your hard disk. At this point, we need to go on -to use FTP, NFS, Tape, CD or DOS floppies to get a bindist onto your -system so that it's actually usable. Select Yes to proceed with this -phase, or No to simply drop into a shell."; - -void -stage5() -{ - int exec_sh = 1; - - setenv("PATH","/stand",1); - for(;;) { - exec_sh = dialog_yesno("End of initial installation", - msg, -1, -1); - end_dialog(); - dialog_active=0; - if (exec_sh) - exec (2, "/stand/sh", "/stand/-sh", 0); - else - exec (3, "/stand/scripts/bininst.sh", - "/stand/scripts/-bininst.sh", 0); - dialog_active=1; - } -} diff --git a/sbin/sysinstall/sysinstall.c b/sbin/sysinstall/sysinstall.c deleted file mode 100644 index 1d90daa..0000000 --- a/sbin/sysinstall/sysinstall.c +++ /dev/null @@ -1,835 +0,0 @@ -/* -#define DEBUG - * Copyright (c) 1994, Paul Richards. - * - * All rights reserved. - * - * This software may be used, modified, copied, distributed, and - * sold, in both source and binary form provided that the above - * copyright and these terms are retained, verbatim, as the first - * lines of this file. Under no circumstances is the author - * responsible for the proper functioning of this software, nor does - * the author assume any responsibility for damages incurred with - * its use. - */ - -#include <dialog.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <stdarg.h> - -#include <sys/types.h> -#include <sys/errno.h> -#include <sys/disklabel.h> -#include <sys/ioctl.h> -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/reboot.h> -#include <sys/stat.h> -#include <sys/utsname.h> -#include <sys/wait.h> -#include <ufs/ffs/fs.h> -#include <machine/console.h> - -#include "mbr.h" -#include "bootarea.h" -#include "sysinstall.h" - -struct disklabel *avail_disklabels; -int *avail_fds; -unsigned char **options; -unsigned char **avail_disknames; -unsigned char *scratch; -unsigned char *errmsg; -unsigned char *bootblocks; -struct mbr *mbr; -struct utsname utsname; -unsigned char *title = utsname.sysname; - -struct sysinstall *sysinstall; -struct sysinstall *sequence; - -int no_disks = 0; -int inst_disk = 0; -int inst_part = 0; -int custom_install; -int dialog_active = 0; - -void exit_sysinstall(); -void abort_installation(char *); -void exit_prompt(); -void fatal(char *); -extern char *part_type(int); -extern int disk_size(int); - -/* To make the binary as small as possible these should be malloc'd */ -char selection[30]; - -void -abort_installation(char *prompt) -{ - strcpy(scratch, prompt); - strcat(scratch,"\n\n Do you wish to abort the installation ?"); - if (!dialog_yesno("Abort installation ?",scratch,10,75)) - exit_prompt(); - dialog_clear(); -} - -void -exit_prompt() -{ - sprintf(scratch,"Are you sure you want to exit sysinstall?"); - if (!dialog_yesno("Exit sysinstall", scratch, 10, 75)) - exit_sysinstall(); - dialog_clear(); -} - -int -alloc_memory() -{ - int i; - - scratch = (char *)calloc(SCRATCHSIZE, sizeof(char)); - if (!scratch) - return(-1); - - errmsg = (char *)calloc(ERRMSGSIZE, sizeof(char)); - if (!errmsg) - return(-1); - - avail_disklabels = - (struct disklabel *)calloc(MAX_NO_DISKS, sizeof(struct disklabel)); - if (!avail_disklabels) - return(-1); - - avail_fds = (int *) calloc(MAX_NO_DISKS, sizeof(int)); - if (!avail_fds) - return(-1); - - avail_disknames = (unsigned char **) calloc(MAX_NO_DISKS, sizeof(char *)); - if (!avail_disknames) - return(-1); - for (i = 0; i < MAX_NO_DISKS; i++) { - avail_disknames[i] = (char *)calloc(15, sizeof(char)); - if (!avail_disknames[i]) - return(-1); - } - - options = (unsigned char **)calloc(MAX_NO_DISKS, sizeof(char *)); - if (!options) - return(-1); - for (i = 0; i < MAX_NO_DISKS; i++) { - options[i] = (char *)calloc(100, sizeof(char)); - if (!options[i]) - return(-1); - } - - mbr = (struct mbr *)malloc(sizeof(struct mbr)); - if (!mbr) - return(-1); - - bootblocks = (char *)malloc(BBSIZE); - if (!bootblocks) - return(-1); - - sysinstall = (struct sysinstall *)malloc(sizeof(struct sysinstall)); - if (!sysinstall) - return(-1); - - sequence = (struct sysinstall *)malloc(sizeof(struct sysinstall)); - if (!sequence) - return(-1); - return(0); -} - -void -free_memory() -{ - int i; - - free(scratch); - free(errmsg); - free(avail_disklabels); - free(avail_fds); - - for (i = 0; i < MAX_NO_DISKS; i++) - free(avail_disknames[i]); - free(avail_disknames); - - for (i = 0; i < MAX_NO_DISKS; i++) - free(options[i]); - free(options); - - free(mbr); - free(bootblocks); - free(sysinstall); - free(sequence); -} - -void -exit_sysinstall() -{ - if (getpid() == 1) { - if (reboot(RB_AUTOBOOT) == -1) - if (dialog_active) - while (1) - dialog_msgbox("Exit sysinstall", - "Reboot failed -- hit reset", - 10, 75, 20); - else { - fprintf(stderr, "Reboot failed -- hit reset"); - while (1); - } - } else { - free_memory(); - if (dialog_active) - end_dialog(); - exit(0); - } -} - -void -fatal(char *errmsg) -{ - if (dialog_active) - dialog_msgbox("Fatal Error -- Aborting installation", - errmsg, 10, 75, 20); - else - fprintf(stderr, "Fatal Error -- Aborting installation:\n%s\n", errmsg); - exit_sysinstall(); -} - -void -query_disks() -{ - int i; - char disk[15]; - char diskname[5]; - struct stat st; - int fd; - - no_disks = 0; - for (i = 0; i < 10; i++) { - sprintf(diskname,"wd%d",i); - sprintf(disk,"/dev/r%sd",diskname); - if ((stat(disk, &st) == 0) && (st.st_mode & S_IFCHR)) - if ((fd = open(disk, O_RDWR)) != -1) { - avail_fds[no_disks] = fd; - bcopy(diskname, avail_disknames[no_disks], strlen(diskname)); - if (ioctl(fd, DIOCGDINFO, &avail_disklabels[no_disks++]) == -1) - no_disks--; - } - } - - for (i=0;i<10;i++) { - sprintf(diskname,"sd%d",i); - sprintf(disk,"/dev/r%sd",diskname); - if ((stat(disk, &st) == 0) && (st.st_mode & S_IFCHR)) - if ((fd = open(disk, O_RDWR)) != -1) { - avail_fds[no_disks] = fd; - bcopy(diskname, avail_disknames[no_disks], strlen(diskname)); - if (ioctl(fd, DIOCGDINFO, &avail_disklabels[no_disks++]) == -1) - no_disks--; - } - } -} - -int -select_disk() -{ - int i; - int valid; - - do { - valid = 1; - sprintf(scratch,"There are %d disks available for installation: ",no_disks); - - for (i=0;i<no_disks;i++) { - sprintf(options[(i*2)], "%d",i+1); - sprintf(options[(i*2)+1], "%s, (%dMb) -> %s",avail_disklabels[i].d_typename,disk_size(i),avail_disknames[i]); - } - - if (dialog_menu("FreeBSD Installation", scratch, 10, 75, 5, no_disks, options, selection)) { - sprintf(scratch,"You did not select a valid disk"); - abort_installation(scratch); - valid = 0; - } - dialog_clear(); - } while (!valid); - return(atoi(selection) - 1); -} - -int -select_partition(int disk) -{ - int valid; - int i; - int choice; - - do { - valid = 1; - - sprintf(scratch,"Select one of the following areas to install to:"); - sprintf(options[0], "%d", 0); - sprintf(options[1], "%s, (%dMb)", "Install to entire disk", - disk_size(disk)); - for (i=0; i < NDOSPART; i++) { - sprintf(options[(i*2)+2], "%d",i+1); - sprintf(options[(i*2)+3], "%s, (%ldMb)", - part_type(mbr->dospart[i].dp_typ), - mbr->dospart[i].dp_size * 512 / (1024 * 1024)); - } - if (dialog_menu(title, - scratch, 10, 75, 5, 5, options, selection)) { - sprintf(scratch,"You did not select a valid partition"); - abort_installation(scratch); - valid = 0; - } - dialog_clear(); - choice = atoi(selection); - if (!choice) - if (dialog_yesno(title, "Installing to the whole disk will erase all its present data.\n\nAre you sure you want to do this?", 10, 75)) - valid = 0; - dialog_clear(); - } while (!valid); - - return(atoi(selection) - 1); -} - -int -exec(char *cmd, char *args, ...) -{ - int pid, w, status; - char **argv = NULL; - int arg = 0; - int no_args = 0; - va_list ap; - struct stat dummy; - - if (stat(cmd, &dummy) == -1) { - sprintf(errmsg, "Executable %s does not exist\n", cmd); - return(-1); - } - - va_start(ap, args); - do { - if (arg == no_args) { - no_args += 10; - if (!(argv = realloc(argv, no_args * sizeof(char *)))) { - sprintf(errmsg, "Failed to allocate memory during exec of %s\n", cmd); - return(-1); - } - if (arg == 0) - argv[arg++] = (char *)args; - } - } while ((argv[arg++] = va_arg(ap, char *))); - va_end(ap); - - if ((pid = fork()) == 0) { - execv(cmd, argv); - exit(1); - } - - while ((w = wait(&status)) != pid && w != -1) - ; - - free(argv); - if (w == -1) { - sprintf(errmsg, "Child process %s terminated abnormally\n", cmd); - return(-1); - } - - return(0); -} - -int -set_termcap() -{ - char *term; - - term = getenv("TERM"); - if (term == NULL) { - int color_display; - - if (setenv("TERMCAP", "/etc/termcap.small", 1) < 0) - return -1; - if (ioctl(STDERR_FILENO, GIO_COLOR, &color_display) < 0) { - char buf[64]; - int len; - - /* serial console */ - fprintf(stderr, "Enter your terminal type (must be present in /etc/termcap.small): "); - if (fgets(buf, sizeof(buf), stdin) == NULL) - return -1; - len = strlen(buf); - if (len > 0 && buf[len-1] == '\n') - buf[len-1] = '\0'; - if (setenv("TERM", buf, 1) < 0) - return -1; - } else if (color_display) { - - /* color console */ - if (setenv("TERM", "cons25", 1) < 0) - return -1; - } else { - - /* mono console */ - if (setenv("TERM", "cons25-m", 1) < 0) - return -1; - } - } - return 0; -} - -int -read_status(char *file, struct sysinstall *sysinstall) -{ - FILE *fd; - - if (!(fd = fopen(file, "r"))) { - sprintf(errmsg, "Couldn't open status file %s for reading\n", file); - return(-1); - } - if (fscanf(fd, "Root device: %s\n", sysinstall->root_dev) == -1) { - sprintf(errmsg, "Failed to read root device from file %s\n", file); - return(-1); - } - if (fscanf(fd, "Installation media: %s\n", sysinstall->media) == -1) { - sprintf(errmsg, "Failed to read installation media from file %s\n", file); - return(-1); - } - if (fscanf(fd, "Installation status: %d\n", &sysinstall->status) == -1) { - sprintf(errmsg, "Status file %s has invalid format\n", file); - return(-1); - } - if (fscanf(fd, "Sequence name: %s\n", sysinstall->seq_name) == -1) { - sprintf(errmsg, "Failed to read sequence name from file %s\n", file); - return(-1); - } - if (fscanf(fd, "Sequence number: %d of %d\n", - &sysinstall->seq_no, &sysinstall->seq_size) == -1) { - sprintf(errmsg, "Failed to read sequence information from file %s\n", file); - return(-1); - } - if (fscanf(fd, "Archive: %s\n", sysinstall->archive) == -1) { - sprintf(errmsg, "Failed to read archive name from file %s\n", file); - return(-1); - } - if (fclose(fd) != 0) { - sprintf(errmsg, "Couldn't close file %s after reading status\n", file); - return(-1); - } - return(0); -} - -int -write_status(char *file, struct sysinstall *sysinstall) -{ - FILE *fd; - - if (!(fd = fopen(file, "w"))) { - sprintf(errmsg, "Couldn't open status file %s for writing\n", file); - return(-1); - } - if (fprintf(fd, "Root device: %s\n", sysinstall->root_dev) == -1) { - sprintf(errmsg, "Failed to write root device to file %s\n", file); - return(-1); - } - if (fprintf(fd, "Installation media: %s\n", sysinstall->media) == -1) { - sprintf(errmsg, "Failed to write installation media to file %s\n", file); - return(-1); - } - if (fprintf(fd, "Installation status: %d\n", sysinstall->status) == -1) { - sprintf(errmsg, "Failed to write status information to file %s\n", file); - return(-1); - } - if (fprintf(fd, "Sequence name: %s\n", sysinstall->seq_name) == -1) { - sprintf(errmsg, "Failed to write sequence name to file %s\n", file); - return(-1); - } - if (fprintf(fd, "Sequence number: %d of %d\n", - sysinstall->seq_no, sysinstall->seq_size) == -1) { - sprintf(errmsg, "Failed to write sequence information to file %s\n", file); - return(-1); - } - if (fprintf(fd, "Archive: %s\n", sysinstall->archive) == -1) { - sprintf(errmsg, "Failed to write archive name to file %s\n", file); - return(-1); - } - if (fclose(fd) != 0) { - sprintf(errmsg, "Couldn't close status file %s after status update\n", file); - return(-1); - } - return(0); -} - -int -load_floppy(char *device, int seq_no) -{ - struct ufs_args ufsargs; - - ufsargs.fspec = device; - if (mount(MOUNT_UFS,"/mnt", 0, (caddr_t) &ufsargs) == -1) { - sprintf(errmsg, "Failed to mount floppy %s: %s\n",scratch, strerror(errno)); - return(-1); - } - - strcpy(scratch, "/mnt/"); - strcat(scratch, STATUSFILE); - if (read_status(scratch, sequence) == -1) { - if (unmount("/mnt", 0) == -1) { - strcat(errmsg, "Error unmounting floppy: "); - strcat(errmsg, strerror(errno)); - fatal(errmsg); - } - return(-1); - } - - if ((bcmp(sequence->seq_name, sysinstall->seq_name, - sizeof(sequence->seq_name)) != 0) || (sequence->seq_no != seq_no)) { - sprintf(errmsg, "Mounted floppy is not the one expected\n"); - if (unmount("/mnt", 0) == -1) { - strcat(errmsg, "Error unmounting floppy: "); - strcat(errmsg, strerror(errno)); - fatal(errmsg); - } - return(-1); - } - - return(0); -} - -void -stage1() -{ - int i; - int ok = 0; - int ready = 0; - struct ufs_args ufsargs; - - while (!ready) { - ready = 1; - - query_disks(); - inst_disk = select_disk(); - -#ifdef DEBUG - read_mbr(avail_fds[inst_disk], mbr); - show_mbr(mbr); -#endif - - if (read_mbr(avail_fds[inst_disk], mbr) == -1) { - sprintf(scratch, "The following error occured will trying to read the master boot record:\n\n%s\n\nIn order to install FreeBSD a new master boot record will have to be written which will mean all current data on the hard disk will be lost.", errmsg); - ok = 0; - while (!ok) { - abort_installation(scratch); - if (!dialog_yesno(title, "Are you sure you wish to proceed?", - 10, 75)) { - dialog_clear(); - clear_mbr(mbr); - ok = 1; - } - } - } - - if (custom_install) - if (!dialog_yesno(title, "Do you wish to edit the DOS partition table?", - 10, 75)) { - dialog_clear(); - edit_mbr(mbr, &avail_disklabels[inst_disk]); - } - - inst_part = select_partition(inst_disk); - - ok = 0; - while (!ok) { - if (build_mbr(mbr, &avail_disklabels[inst_disk])) - ok = 1; - else { - sprintf(scratch, "The DOS partition table is inconsistent.\n\n%s\n\nDo you wish to edit it by hand?", errmsg); - if (!dialog_yesno(title, scratch, 10, 75)) { - edit_mbr(mbr, &avail_disklabels[inst_disk]); - dialog_clear(); - } else { - abort_installation(""); - ok = 1; - ready = 0; - } - } - } - - default_disklabel(&avail_disklabels[inst_disk], - mbr->dospart[inst_part].dp_size, - mbr->dospart[inst_part].dp_start); - build_bootblocks(&avail_disklabels[inst_disk]); - - if (ready) { - if (dialog_yesno(title, "We are now ready to format the hard disk for FreeBSD.\n\nSome or all of the disk will be overwritten during this process.\n\nAre you sure you wish to proceed ?", 10, 75)) { - abort_installation(""); - ready = 0; - } - dialog_clear(); - } - } - - /* Write master boot record and bootblocks */ - write_mbr(avail_fds[inst_disk], mbr); - write_bootblocks(avail_fds[inst_disk], - mbr->dospart[inst_part].dp_start, - avail_disklabels[inst_disk].d_bbsize); - -#ifdef DEBUG - read_mbr(avail_fds[inst_disk], mbr); - show_mbr(mbr); -#endif - - /* close all the open disks */ - for (i=0; i < no_disks; i++) - if (close(avail_fds[i]) == -1) { - sprintf(errmsg, "Error on closing file descriptors: %s\n", - strerror(errno)); - fatal(errmsg); - } - - /* newfs the root partition */ - strcpy(scratch, avail_disknames[inst_disk]); - strcat(scratch, "a"); - if (exec("/sbin/newfs","/sbin/newfs", scratch, 0) == -1) - fatal(errmsg); - - /* newfs the /usr partition */ - strcpy(scratch, avail_disknames[inst_disk]); - strcat(scratch, "e"); - if (exec("/sbin/newfs", "/sbin/newfs", scratch, 0) == -1) - fatal(errmsg); - - strcpy(scratch, "/dev/"); - strcat(scratch, avail_disknames[inst_disk]); - strcat(scratch, "a"); - ufsargs.fspec = scratch; - if (mount(MOUNT_UFS,"/mnt", 0, (caddr_t) &ufsargs) == -1) { - sprintf(errmsg, "Error mounting %s: %s\n",scratch, strerror(errno)); - fatal(errmsg); - } - - if (mkdir("/mnt/usr",S_IRWXU) == -1) { - sprintf(errmsg, "Couldn't create directory /mnt/usr: %s\n", - strerror(errno)); - fatal(errmsg); - } - - if (mkdir("/mnt/mnt",S_IRWXU) == -1) { - sprintf(errmsg, "Couldn't create directory /mnt/mnt: %s\n", - strerror(errno)); - fatal(errmsg); - } - - strcpy(scratch, "/dev/"); - strcat(scratch, avail_disknames[inst_disk]); - strcat(scratch, "e"); - ufsargs.fspec = scratch; - if (mount(MOUNT_UFS,"/mnt/usr", 0, (caddr_t) &ufsargs) == -1) { - sprintf(errmsg, "Error mounting %s: %s\n",scratch, strerror(errno)); - fatal(errmsg); - } - - if (exec("/bin/cp","/bin/cp","/kernel","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /kernel to /mnt: %s\n",strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/cp","/bin/cp","/sysinstall","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /sysinstall to /mnt: %s\n", - strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/cp","/bin/cp","-R","/etc","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /etc to /mnt: %s\n",strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/cp","/bin/cp","-R","/sbin","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /sbin to /mnt: %s\n",strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/cp","/bin/cp","-R","/bin","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /bin to /mnt: %s\n",strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/cp","/bin/cp","-R","/dev","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /dev to /mnt: %s\n",strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/cp","/bin/cp","-R","/usr","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /usr to /mnt: %s\n",strerror(errno)); - fatal(errmsg); - } - - sysinstall->status = DISK_READY; - bcopy(avail_disknames[inst_disk], sysinstall->root_dev, - strlen(avail_disknames[inst_disk])); - sprintf(scratch, "/mnt/etc/%s", STATUSFILE); - if (write_status(scratch, sysinstall) == -1) - fatal(errmsg); - - if (unmount("/mnt/usr", 0) == -1) { - sprintf(errmsg, "Error unmounting /mnt/usr: %s\n", strerror(errno)); - fatal(errmsg); - } - - if (unmount("/mnt", 0) == -1) { - sprintf(errmsg, "Error unmounting /mnt: %s\n", strerror(errno)); - fatal(errmsg); - } -} - -void -stage2() -{ - int i; - struct ufs_args ufsargs; - - ufsargs.fspec = sysinstall->root_dev; - if (mount(MOUNT_UFS,"/", 0, (caddr_t) &ufsargs) == -1) { - sprintf(errmsg, "Failed to mount root read/write: %s\n%s", strerror(errno), ufsargs.fspec); - fatal(errmsg); - } - - sprintf(scratch, "Insert floppy %d in drive\n", sysinstall->seq_no + 1); - dialog_msgbox("Stage 2 installation", scratch, 10, 75, 1); - i = load_floppy(sysinstall->media, sysinstall->seq_no + 1); - while (i == -1) { - dialog_msgbox("Stage 2 installation",errmsg, 10, 75, 1); - sprintf(scratch, "Please insert installation floppy %d in the boot drive", sysinstall->seq_no + 1); - dialog_msgbox("Stage 2 installation",scratch, 10, 75, 1); - i = load_floppy(sysinstall->media, sysinstall->seq_no + 1); - }; - if (exec("/bin/cp","/bin/cp","/mnt/pax","/bin", 0) == -1) { - sprintf(errmsg, "Couldn't copy /mnt/pax to /bin %s\n",strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/pax", "/bin/pax", "-r", "-f", sequence->archive, 0) == -1) { - sprintf(errmsg, "Failed to extract from archive file %s\n", sequence->archive); - fatal(errmsg); - } - - sysinstall->status = INSTALLED_BASE; - sprintf(scratch, "/etc/%s", STATUSFILE); - if (write_status(scratch, sysinstall) == -1) - fatal(errmsg); - - if (unmount("/mnt", 0) == -1) { - strcat(errmsg, "Error unmounting floppy: "); - strcat(errmsg, strerror(errno)); - fatal(errmsg); - } -} - -/* - * This is the overall plan: (phk's version) - * - * If (pid == 1) - * reopen stdin, stdout, stderr, and do various other magic. - * - * If (file exists /this_is_boot.flp) - * stage0: - * present /COPYRIGHT - * present /README - * stage1: - * Ask about diskallocation and do the fdisk/disklabel stunt. - * stage2: - * Do newfs, mount and copy over a minimal world. - * make /mnt/etc/fstab. Install ourself as /mnt/sbin/init - * Else - * stage3: - * Read cpio.flp and fiddle around with the bits a bit. - * stage4: - * Read bin-tarballs: - * Using ftp - * Using NFS (?) - * Using floppy - * Using tape - * Using shell-prompt - * stage5: - * Extract bin-tarballs - * stage6: - * Ask various questions and collect answers into system-config - * files. - * stage7: - * execl("/sbin/init"); - */ - -void -main(int argc, char **argv) -{ - int i; - - /* phk's main */ - if (argc > 1 && !strcmp(argv[1],"phk")) { - return Xmain(argc,argv); - } - - /* paul's main */ - /* Are we running as init? */ - if (getpid() == 1) { - close(0); open("/dev/console", O_RDWR); - close(1); dup(0); - close(2); dup(0); - i = 1; - ioctl(0,TIOCSPGRP,&i); - setlogin("root"); - } - - if (set_termcap() == -1) - fatal("Can't find terminal entry\n"); - - if (alloc_memory() == -1) - fatal("Couldn't allocate memory\n"); - -#if 0 /* Later. Our kernels don't say the right thing at present anyway */ - if (uname(&utsname) == -1) { - /* Fake uname entry */ - bcopy("FreeBSD", utsname.sysname, strlen("FreeBSD")); - } -#else - bcopy(TITLE, utsname.sysname, strlen(TITLE)); -#endif - - /* XXX - libdialog has particularly bad return value checking */ - init_dialog(); - /* If we haven't crashed I guess dialog is running ! */ - dialog_active = 1; - - strcpy(scratch, "/etc/"); - strcat(scratch, STATUSFILE); - if (read_status(scratch, sysinstall) == -1) { - fatal(errmsg); - } - - switch(sysinstall->status) { - case NOT_INSTALLED: - stage1(); - dialog_msgbox("Stage 1 complete", - "Remove all floppy disks from the drives and hit return to reboot from the hard disk", - 10, 75, 1); - if (reboot(RB_AUTOBOOT) == -1) - fatal("Reboot failed"); - break; - - case DISK_READY: - dialog_msgbox("Stage 2 install", "Hi!", 10, 75, 1); - stage2(); - dialog_msgbox("Stage 2 complete", - "Well, this is as far as it goes so far :-)\n", - 10, 75, 1); - break; - - case INSTALLED_BASE: - break; - - default: - fatal("Unknown installation status"); - } - exit_sysinstall(); -} diff --git a/sbin/sysinstall/sysinstall.h b/sbin/sysinstall/sysinstall.h deleted file mode 100644 index e127123..0000000 --- a/sbin/sysinstall/sysinstall.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 1994, Paul Richards. - * - * All rights reserved. - * - * This software may be used, modified, copied, distributed, and - * sold, in both source and binary form provided that the above - * copyright and these terms are retained, verbatim, as the first - * lines of this file. Under no circumstances is the author - * responsible for the proper functioning of this software, nor does - * the author assume any responsibility for damages incurred with - * its use. - */ - -#define TITLE "FreeBSD 2.0-950418-SNAP Install" - -#define MAX_NO_DISKS 10 -#define MAX_NO_FS 30 -#define MAXFS MAX_NO_FS - -#define BBSIZE 8192 /* Actually in ufs/ffs/fs.h I think */ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <ncurses.h> -#include <string.h> -#include <errno.h> -#include <dialog.h> -#include <ctype.h> - -#include <sys/types.h> -#include <sys/ioctl.h> -#include <sys/dkbad.h> -#include <sys/disklabel.h> - -#define SCRATCHSIZE 1024 -#define ERRMSGSIZE 256 -#define DEFROOTSIZE 18 -#define DEFSWAPSIZE 16 -#define DEFUSRSIZE 80 -#define DEFFSIZE 1024 -#define DEFFRAG 8 - -#define BOOT_MAGIC 0xAA55 -#define ACTIVE 0x80 - -#define COPYRIGHT_FILE "/COPYRIGHT" -#define README_FILE "/README" -#define HELPME_FILE "/DISKSPACE.FAQ" -#define TROUBLE_FILE "/TROUBLESHOOTING" -#define RELNOTES_FILE "/RELNOTES.FreeBSD" - -#ifndef EXTERN -# define EXTERN extern -#endif - -extern unsigned char boot0[]; -extern unsigned char boot1[]; -extern unsigned char boot2[]; - -/* All this "disk" stuff */ -EXTERN int Ndisk; -EXTERN struct disklabel *Dlbl[MAX_NO_DISKS]; -EXTERN char *Dname[MAX_NO_DISKS]; -EXTERN int Dfd[MAX_NO_DISKS]; - -EXTERN int MP[MAX_NO_DISKS][MAXPARTITIONS]; - -/* All this "filesystem" stuff */ -EXTERN int Nfs; -EXTERN char *Fname[MAX_NO_FS+1]; -EXTERN char *Fmount[MAX_NO_FS+1]; -EXTERN char *Ftype[MAX_NO_FS+1]; -EXTERN int Faction[MAX_NO_FS+1]; -EXTERN u_long Fsize[MAX_NO_FS+1]; - -EXTERN int dialog_active; -EXTERN char selection[]; -EXTERN int debug_fd; -EXTERN int dialog_active; -EXTERN int fixit; - -EXTERN int on_serial; -EXTERN int on_cdrom; -EXTERN int cpio_fd; - -extern int no_disks; -extern int inst_disk; -extern unsigned char *scratch; -extern unsigned char *errmsg; -extern u_short dkcksum(struct disklabel *); - -/* utils.c */ -void Abort __P((void)); -void ExitSysinstall __P((void)); -void TellEm __P((char *fmt, ...)); -void Debug __P((char *fmt, ...)); -void stage0 __P((void)); -void *Malloc __P((size_t size)); -char *StrAlloc __P((char *str)); -void Fatal __P((char *fmt, ...)); -void AskAbort __P((char *fmt, ...)); -void MountUfs __P((char *device, char *mountpoint, int do_mkdir,int flags)); -void Mkdir __P((char *path, int die)); -void Link __P((char *from, char *to)); -void CopyFile __P((char *p1, char *p2)); -u_long PartMb(struct disklabel *lbl,int part); -char * SetMount __P((int disk, int part, char *path)); -void CleanMount __P((int disk, int part)); -void enable_label __P((int fd)); -void disable_label __P((int fd)); - -/* exec.c */ -int exec __P((int magic, char *cmd, char *args, ...)); -#define EXEC_MAXARG 100 - -/* stage0.c */ -void stage0 __P((void)); - -/* stage1.c */ -int stage1 __P((void)); - -/* stage2.c */ -void stage2 __P((void)); - -/* stage3.c */ -void stage3 __P((void)); - -/* stage5.c */ -void stage5 __P((void)); - -/* termcap.c */ -int set_termcap __P((void)); - -/* makedevs.c */ -int makedevs __P((void)); - -/* ourcurses.c */ -int AskEm __P((WINDOW *w,char *prompt, char *answer, int len)); -void ShowFile __P((char *filename, char *header)); - -/* mbr.c */ -int build_bootblocks __P((int dfd,struct disklabel *label,struct dos_partition *dospart)); -void Fdisk __P((void)); -void read_dospart __P((int, struct dos_partition *)); - -/* label.c */ -void DiskLabel __P((void)); diff --git a/sbin/sysinstall/termcap.c b/sbin/sysinstall/termcap.c deleted file mode 100644 index bd1e086..0000000 --- a/sbin/sysinstall/termcap.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 1994, Paul Richards. - * - * All rights reserved. - * - * This software may be used, modified, copied, distributed, and sold, in both - * source and binary form provided that the above copyright and these terms - * are retained, verbatim, as the first lines of this file. Under no - * circumstances is the author responsible for the proper functioning of this - * software, nor does the author assume any responsibility for damages - * incurred with its use. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <stdarg.h> -#include <fcntl.h> -#include <machine/console.h> - -#include "sysinstall.h" - -int -set_termcap() -{ - char *term; - extern const char termcap_vt100[]; - extern const char termcap_cons25[]; - extern const char termcap_cons25_m[]; - - term = getenv("TERM"); - if (term == NULL) { - int color_display; - - if (ioctl(STDERR_FILENO, GIO_COLOR, &color_display) < 0) { - if (setenv("TERM", "vt100", 1) < 0) - return -1; - if (setenv("TERMCAP", termcap_vt100, 1) < 0) - return -1; - debug_fd = dup(1); - on_serial++; - } else if (color_display) { - if (setenv("TERM", "cons25", 1) < 0) - return -1; - if (setenv("TERMCAP", termcap_cons25, 1) < 0) - return -1; - debug_fd = open("/dev/ttyv1",O_WRONLY); - } else { - if (setenv("TERM", "cons25-m", 1) < 0) - return -1; - if (setenv("TERMCAP", termcap_cons25_m, 1) < 0) - return -1; - debug_fd = open("/dev/ttyv1",O_WRONLY); - } - } else { - debug_fd = open("sysinstall.debug", - O_WRONLY|O_CREAT|O_TRUNC,0644); - } - return 0; -} diff --git a/sbin/sysinstall/utils.c b/sbin/sysinstall/utils.c deleted file mode 100644 index 243b191..0000000 --- a/sbin/sysinstall/utils.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: utils.c,v 1.35 1995/01/14 10:31:29 jkh Exp $ - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <unistd.h> -#include <string.h> -#include <dialog.h> -#include <errno.h> - -#include <sys/file.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/reboot.h> -#include <sys/dkbad.h> -#include <sys/disklabel.h> - -#include "sysinstall.h" - -void -strip_trailing_newlines(char *p) -{ - int len = strlen(p); - while (len > 0 && p[len-1] == '\n') - p[--len] = '\0'; -} - -void -Debug(char *fmt, ...) -{ - char *p; - va_list ap; - p = Malloc(2048); - va_start(ap,fmt); - vsnprintf(p, 2048, fmt, ap); - va_end(ap); - write(debug_fd,"Debug <",7); - write(debug_fd,p,strlen(p)); - write(debug_fd,">\n\r",3); - free(p); -} - -void -TellEm(char *fmt, ...) -{ - char *p; - va_list ap; - p = Malloc(2048); - va_start(ap,fmt); - vsnprintf(p, 2048, fmt, ap); - va_end(ap); - strip_trailing_newlines(p); - write(debug_fd,"Progress <",10); - write(debug_fd,p,strlen(p)); - write(debug_fd,">\n\r",3); - if(!on_serial) { - dialog_clear_norefresh(); - dialog_msgbox("Progress", p, -1, -1, 0); - } - free(p); -} - -void -Fatal(char *fmt, ...) -{ - char *p; - va_list ap; - p = Malloc(2048); - va_start(ap,fmt); - vsnprintf(p, 2048, fmt, ap); - va_end(ap); - strip_trailing_newlines(p); - if (dialog_active && !on_serial) - dialog_msgbox("Fatal", p, -1, -1, 1); - else - fprintf(stderr, "Fatal -- %s\n", p); - free(p); - ExitSysinstall(); -} - -void -AskAbort(char *fmt, ...) -{ - char *p; - va_list ap; - - p = Malloc(2048); - va_start(ap,fmt); - vsnprintf(p, 2048, fmt, ap); - va_end(ap); - strcat(p, "\n\nDo you wish to abort the installation?"); - if (!dialog_yesno("Abort", p, -1, -1)) { - dialog_clear_norefresh(); - Abort(); - } - dialog_clear(); - free(p); -} - -void -Abort() -{ - if (dialog_yesno("Exit sysinstall","\n\nAre you sure you want to quit?", - -1, -1)) { - dialog_clear(); - return; - } - ExitSysinstall(); -} - -void -ExitSysinstall() -{ - if (dialog_active) { - clear(); - dialog_update(); - } - if (getpid() == 1) { - if (reboot(RB_AUTOBOOT) == -1) - if (dialog_active) { - clear(); - dialog_msgbox(TITLE, "\n\nCan't reboot machine -- hit reset button", - -1,-1,0); - } else - fprintf(stderr, "Can't reboot the machine -- hit the reset button"); - while(1); - } else { - if (dialog_active) { - end_dialog(); - dialog_active = 0; - } - exit(0); - } -} - -void * -Malloc(size_t size) -{ - void *p = malloc(size); - if (!p) { - exit(7); /* XXX longjmp bad */ - } - return p; -} - -char * -StrAlloc(char *str) -{ - char *p; - - p = (char *)Malloc(strlen(str) + 1); - strcpy(p,str); - return p; -} - -void -MountUfs(char *device, char *mountpoint, int do_mkdir, int flags) -{ - struct ufs_args ufsargs; - char dbuf[90]; - - memset(&ufsargs,0,sizeof ufsargs); - - if(do_mkdir && access(mountpoint,R_OK)) { - Mkdir(mountpoint, TRUE); - } - - strcpy(dbuf,"/dev/"); - strcat(dbuf,device); - - TellEm("mount %s %s",dbuf,mountpoint); - ufsargs.fspec = dbuf; - if (mount(MOUNT_UFS, mountpoint, flags, (caddr_t) &ufsargs) == -1) { - Fatal("Error mounting %s on %s : %s\n", - dbuf, mountpoint, strerror(errno)); - } -} - -void -Mkdir(char *ipath, int die) -{ - struct stat sb; - int final=0; - char *p,*path=StrAlloc(ipath); - - Debug("mkdir(%s)",path); - p = path; - if (p[0] == '/') /* Skip leading '/'. */ - ++p; - for (;!final; ++p) { - if (p[0] == '\0' || (p[0] == '/' && p[1] == '\0')) - final++; - else if (p[0] != '/') - continue; - *p = '\0'; - if (stat(path, &sb)) { - if (errno != ENOENT && die) - Fatal("Couldn't stat directory %s: %s\n", - path,strerror(errno)); - Debug("mkdir(%s..)",path); - if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && - die) - Fatal("Couldn't create directory %s: %s\n", - path,strerror(errno)); - } - *p = '/'; - } - free(path); - return; -} - -void -Link(char *from, char *to) -{ - TellEm("ln %s %s", from, to); - if(fixit) - unlink(to); - if (link(from, to) == -1) - Fatal("Couldn't create link: %s -> %s\n", from, to); -} - -void -CopyFile(char *p1, char *p2) -{ - char buf[BUFSIZ]; - int fd1,fd2; - int i; - struct stat st; - - TellEm("Copy %s to %s",p1,p2); - fd1 = open(p1,O_RDONLY); - if (fd1 < 0) Fatal("Couldn't open %s: %s\n",p1,strerror(errno)); - fd2 = open(p2,O_TRUNC|O_CREAT|O_WRONLY,0200); - if (fd2 < 0) Fatal("Couldn't open %s: %s\n",p2,strerror(errno)); - for(;;) { - i = read(fd1,buf,sizeof buf); - if (i > 0) - if (i != write(fd2,buf,i)) { - Fatal("Write errror on %s: %s\n", - p2,strerror(errno)); - } - if (i != sizeof buf) - break; - } - fstat(fd1,&st); - fchmod(fd2,st.st_mode & 07777); - fchown(fd2,st.st_uid,st.st_gid); - close(fd1); - close(fd2); -} - -u_long -PartMb(struct disklabel *lbl,int part) -{ - u_long l; - l = 1024*1024/lbl->d_secsize; - return (lbl->d_partitions[part].p_size + l/2)/l; -} - -void -CleanMount(int disk, int part) -{ - int i = MP[disk][part]; - Faction[i] = 0; - if (Fmount[i]) { - free(Fmount[i]); - Fmount[i] = 0; - } - if (Fname[i]) { - free(Fname[i]); - Fname[i] = 0; - } - if (Ftype[i]) { - free(Ftype[i]); - Ftype[i] = 0; - } - MP[disk][part] = 0; -} - -char * -SetMount(int disk, int part, char *path) -{ - int k; - char buf[80]; - - CleanMount(disk,part); - for (k = 1; k < MAX_NO_FS; k++) - if (!Fmount[k]) - break; - - if (k >= MAX_NO_FS) - return "Maximum number of filesystems exceeded"; - - Fmount[k] = StrAlloc(path); - sprintf(buf, "%s%c", Dname[disk], part + 'a'); - Fname[k] = StrAlloc(buf); - switch (Dlbl[disk]->d_partitions[part].p_fstype) { - case FS_BSDFFS: - Ftype[k] = StrAlloc("ufs"); - if(!fixit) - Faction[k] = 1; - break; - case FS_MSDOS: - Ftype[k] = StrAlloc("msdos"); - Faction[k] = 0; - break; - case FS_SWAP: - Ftype[k] = StrAlloc("swap"); - Faction[k] = 1; - break; - default: - CleanMount(disk,part); - return "Unknown filesystem-type"; - } - Fsize[k] = (Dlbl[disk]->d_partitions[part].p_size+1024)/2048; - - MP[disk][part] = k; - return NULL; -} - -void -enable_label(int fd) -{ - int flag = 1; - if (ioctl(fd, DIOCWLABEL, &flag) < 0) - Fatal("ioctl(DIOCWLABEL,1) failed: %s",strerror(errno)); -} - -void -disable_label(int fd) -{ - int flag = 0; - if (ioctl(fd, DIOCWLABEL, &flag) < 0) - Fatal("ioctl(DIOCWLABEL,0) failed: %s",strerror(errno)); -} - |