diff options
author | peter <peter@FreeBSD.org> | 1995-12-30 19:02:48 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1995-12-30 19:02:48 +0000 |
commit | c3f352d4ad515968c54d216a0e53252eff8ab3ef (patch) | |
tree | 48ddeda3c6c8d8572cc34bf52ccf9cb9bd97d488 /sbin | |
parent | ab124e78b0271ddb904b761b31e5c9a0cf24e070 (diff) | |
download | FreeBSD-src-c3f352d4ad515968c54d216a0e53252eff8ab3ef.zip FreeBSD-src-c3f352d4ad515968c54d216a0e53252eff8ab3ef.tar.gz |
This commit was generated by cvs2svn to compensate for changes in r13122,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/DISCLAIMER | 27 | ||||
-rw-r--r-- | sbin/disklabel/disklabel.5.5 | 384 | ||||
-rw-r--r-- | sbin/fastboot/fastboot.8 | 69 | ||||
-rw-r--r-- | sbin/ipfw/README | 610 | ||||
-rw-r--r-- | sbin/scsiformat/scsiformat.c | 664 |
5 files changed, 0 insertions, 1754 deletions
diff --git a/sbin/DISCLAIMER b/sbin/DISCLAIMER deleted file mode 100644 index 161e84e..0000000 --- a/sbin/DISCLAIMER +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Rdisc (this program) was developed by Sun Microsystems, Inc. and is - * provided for unrestricted use provided that this legend is included on - * all tape media and as a part of the software program in whole or part. - * Users may copy or modify Rdisc without charge, and they may freely - * distribute it. - * - * RDISC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. - * - * Rdisc is provided with no support and without any obligation on the - * part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. - * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY RDISC - * OR ANY PART THEREOF. - * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. - * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 - */ diff --git a/sbin/disklabel/disklabel.5.5 b/sbin/disklabel/disklabel.5.5 deleted file mode 100644 index fb6f6cd..0000000 --- a/sbin/disklabel/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/fastboot.8 b/sbin/fastboot/fastboot.8 deleted file mode 100644 index 2f6ac829..0000000 --- a/sbin/fastboot/fastboot.8 +++ /dev/null @@ -1,69 +0,0 @@ -.\" Copyright (c) 1983, 1991, 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.8 8.1 (Berkeley) 6/5/93 -.\" -.Dd June 5, 1993 -.Dt FASTBOOT 8 -.Os BSD 4.2 -.Sh NAME -.Nm fastboot , -.Nm fasthalt -.Nd "reboot/halt the system without checking the disks" -.Sh SYNOPSIS -.Nm fastboot -.Op Ar boot-options -.Nm fasthalt -.Op Ar halt-options -.Sh DESCRIPTION -.Nm Fastboot -and -.Nm fasthalt -are shell scripts which reboot and halt the system without -checking the file systems. This is done by creating a -file -.Pa /fastboot , -then invoking the -.Xr reboot -program. The system startup script, -.Pa /etc/rc , -looks for this file and, if present, skips the normal -invocation of -.Xr fsck 8 . -.Sh SEE ALSO -.Xr halt 8 , -.Xr reboot 8 , -.Xr rc 8 -.Sh HISTORY -The -.Nm -command appeared in -.Bx 4.2 . diff --git a/sbin/ipfw/README b/sbin/ipfw/README deleted file mode 100644 index 1cc296c..0000000 --- a/sbin/ipfw/README +++ /dev/null @@ -1,610 +0,0 @@ -***************************************************************************** -27 Oct 94 -Hi again! -So thanx to Brian McGovern , i'v took this piece of code in hands again -and made some changes: - 1) Port to FreeBSD 2.0 , so we will not go after time. - 2) Some minor changes in kernel part to improve speed and such.. - 3) Chane in behaviour: now any recently added firewall definition - preferred on other matching but older firewalls. - REMEMBER: in any case universal IP firewall has larger preference - then special TCP/UDP/ICMP firewalls. - 4) Cosmetical changes to control programm. Now it is called ipfw. - 5) Changed ip_firewall.* to ip_fw.* in kernel,and shortened some long - variable names. - 6) From now on we have user defined *policy*,which is DENY/ACCEPT for - every packet which does not matches any of firewalls.I.e.: if any - firewall defined and packet does not match them you may set it up - so it will be anyway throwed or anyway accepted. -Mostly that's all. -Bye! - --- - -= Ugen J.S.Antsilevich =- - NetVision - Commercial Internet Provider ------------------------------------------------------[C]--- -NetVision - Home of Israeli Commercial Internet - E-mail: ugen@NetVision.net.il - HTTP: http://www.NetVision.net.il/~ugen/ - Phone: +972-4-550330 Fax: +972-4-550122 - -***************************************************************************** -10 Jul 94 -Hi again...So i sitted and stared at this nice working tool and thought to -myself that it's nice but something there it needs and have not.. -So i took a piece of file and a keyboard and typed some strings. -What it was is: - -o List facility improved...Now listing of currently installed firewall - entries does not go through kernel printf's ,which is really unnice to - one who runs it NOT from console:) - -o Really important facility of deleting entries added..Yes , till this - day you had to remove all entries and then add them one by one again - to remove actually just one.Now it's over:) - -o All this changes documented in this readme,while you will see where i - added my words just by vast number of mistaces in English.Well,i hope - you will forgive one Russian guy like me:) - -So enjoy this new code and if you think it needs some additions - you -are welcome to suggest.Also i made some more warnings , while compiling -this code,i have no a clue where do they come from,however they does not -make any bad to programm.But if you will find way to remove them,feel free -to do it and post anywhere(and notify me as i also need this:) - - Bye! Ugen J.S.Antsilevich - - -########################################################################## -# Ugen J.S.Antsilevich NetVision (Israel) System Staff Member # -#------------------------------------------------------------------------# -# Email: ugen@NetVision.net.il | Phone: 972-4-550330 # -# ugen@NetManage.co.il | Fax: 972-4-550122 # -#------------------------------------------------------------------------# -# WWW HomePage: http://www.NetVision.net.il/~ugen # -# Special : Volk@Les.Tambov.SU # -########################################################################## - - -***************************************************************************** -8 Jul 94 -OK..so first of all,this is simple port to FreeBSD by Ugen J.S.Antsilevich -Actually all i had to do is to find appropriate place in kernel source files -for ipfirewall stuff..so all your thanks should go to the author... -Anyway i am porting it now to 1.1.5 (not much job though..:) so if you want -to ask something about write to me: - -ugen@NetVision.net.il - -That's it and let the --==REAL==-- author speak... -***************************************************************************** - -Here's my ipfirewall facility. I consider it to still be beta quality mostly -because the various interfaces are pretty crude. Here's some information that -you'll probably find useful (in roughly the order in which you'll need to know -it). Some of this will be absurdly simplistic. Better safe than sorry... - -This software was written for BSD/386. The current version has been ported -to BSD/386 v1.1. The context diffs are with respect to that version of -BSD/386. If you don't have access to BSD/386 v1.1 and can't make sense out of -the diffs, contact me and I'll send you the entire files (they are copyrighted -by UC-Berkeley with very 'friendly' conditions). - -Speaking of copyrights, here's mine: - -/* - * Copyright (c) 1993 Daniel Boulet - * Copyright (c) 1994 Ugen J.S.Antsilevich - * - * Redistribution and use in source forms, with and without modification, - * are permitted provided that this entire comment appears intact. - * - * Redistribution in binary form may occur without any restrictions. - * Obviously, it would be nice if you gave credit where credit is due - * but requiring it would be too onerous. - * - * This software is provided ``AS IS'' without any warranties of any kind. - */ - -Enough introductory stuff, here we go... - - 1) The file IPFIREWALL is the configuration of kernel i use with - IPFIREWALL and GATEWAY options enabled. You may not find it useful. - About the only key things are that it enables the IPFIREWALL - option and the GATEWAY option. IPFIREWALL turns on my - stuff and GATEWAY turns your machine into an IP router. - - There is nothing magical about the name of this file or the - ident name for the kernel. - - 2) The files ip_fw.c and ip_fw.h are new files that should be - placed into the /usr/src/sys/netinet directory. - - 3) The files ip_input.c and raw_ip.c are new patched versions of the - same files , they made up for version 2.0 of FreeBSD,however it was - some pre-Beta release we worked on , so to add it to other releases - just find all parts of code surrounded by: - #ifdef IPFIREWALL - .... - #endif - and place in the appropriate places in the same files. - All those files are in /usr/src/sys/netinet directory of corse. - - 4) Add the line "netinet/ip_fw.c optional ipfirewall" to the - file /usr/src/sys/conf/files. This tells the config program to - include the netinet/ip_fw.c file if the IPFIREWALL option is - defined for a kernel. - - 5) The Makefile and ipfw.c files should go into directory probably - back in your home directory tree somewhere. If this ever becomes a - part of the system then they should go into the (newly created) - directory /usr/src/sbin/ipfw. - - 6) Build yourself a kernel, make a backup of the current kernel and - and install the new one. It should behave in a completely normal - fashion since you won't have defined any firewalls yet. - - 7) Explore the ipfw program. The smartest way to do this is to - compile the program and then run it.To do it you SHOULD be root - as the programm uses setsockopt on RAW sockets to define firewalls, - and also reads kernel symbols.If any other user will run ipw - it will detect that it isn't being run by root and will just - complain and exit. - The ipfw program takes command line parameters - and (assuming they are valid) issues a single appropriate setsockopt - call. If you're defining 5 firewalls then you'll have to run the - program 5 times. See below for a description of the command syntax - of ipfirewall. - - ==================================================================== - WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! - The ipfw program can be used to put your machine into very - disfunctional state.So if you want to test it make sure you - a) Have read carifully this README till it's end. - b) First time run it from machine console,as else you can - simply shut down your own access to it. - ==================================================================== - Make sure that you never setup the program as setuid root!!! Instead, - always run it from the root command line or from "/etc/rc.local" - as part of the boot process. - - 8) Use the "ipfirewall" checkb or checkf command (see below) to pass some - test packets through the firewalls that you've defined. - - 9) You may find it useful to create a file in which the first line is - "ipfirewall flush" to flush any existing firewalls and the remaining - lines are the ipfirewall commands needed to define the firewalls that - you want to use. This will ensure that you're always working from a - known state. - - 10) If you've gotten this far then you're probably ready to let the critter - see prime time. Copy your file of ipfirewall commands into the - /etc/rc.local file and reboot the system. Once you're up, use the - ipfirewall list command to see that you've got the firewalls that you - wanted and try to test the firewall with real packets from trusted - and untrusted hosts. - -Enough of that. Here's the syntax for the ipfirewall command. It is rather -complex and yet simple at the same time (if you know what I mean). There -are seven sub-commands. 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)): - - 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> ] - -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: - - The "ipfirewall list" command prints a list of the firewalls on both the - forwarding and blocking chain in some more or less understudable format. - - The "ipfirewall flush" command empties the two firewall chains. - - The "ipfirewall addblocking" and "ipfirewall addforwarding" commands take - a firewall description and add the firewall to the appropriate firewall - chain.Take notice,that if you will add some description more then once, - it will take more then one entry in memory.It does not lead to significant - slow down of computer operation though. - - The "ipfirewall delblocking" and "ipfirewall delforwarding" commands take - a firewall description and deletes the firewall from the appropriate - firewall chain.The description must be exactly the same as it was defined - by add command.One delete command removes ALL same entries from firewall - chains. - - 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 (i.e. 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. - - 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 - - 192.153.211.0:255.255.255.0 - 192.153.211.17:255.255.255.255 - 0.0.0.0:0.0.0.0 - - 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). - - 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: - - - 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 - - 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. - - 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: - - Block all IP packets originating from the host hackers-den: - - ipfirewall addb deny all from hackers-den to 0.0.0.0/0 - - Block all telnet packets to our telnet server from anywhere: - - ipfirewall addb deny tcp from 0.0.0.0/0 to mymachine/32 telnet - - Don't forward telnet, rlogin and rsh packets onto our local - class C network: - - ipfirewall addf deny tcp from 0.0.0.0/0 to ournetwork/24 telnet login shell - - Don't let anyone on the local machine or any machine inside - our local network ftp access to games.com: - - ipfirewall addb deny tcp from games.com ftp to 0.0.0.0/0 - - 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! - - The "ipfirewall checkblocking" and "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: - - ipfirewall checkb from bsdi.com 3001 to mymachine telnet - - 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. - - 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. - - Finally, have a look at the file "filters". It is the set of filters - that I run at home.<Danny> - Also check "scripts",where individual access restrictions written. - We use those for our dial-in PPP/SLIP users,to allow some of them - to access our internal networks,while disallowing other.This way we - open access to user's IP,when he enters the system ,and shut it - down when he leaves.All those changes may be applyed at any time, - and so entries added and deleted from firewall while system is - is working.No any side effects will arise.<Ugen> - -Now for a bit of a description of how the firewalls are applied (i.e. what -happens in the kernel): - - 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? - - 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). - -There are a couple of consequences of this approach: - - 1) Packets which are blocked are never forwarded (something to keep - in mind when designing firewalls). - 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. - 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> - Well,anyway i working on this feature.It would be made optional and - configurable by some ICMP_UNREACH_ON_DROP or like this.<Ugen> - -Now for some details on how the firewall checker works: - - 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 - option IPFIREWALL_VERBOSE - to your kernel configuration file.Very useful thingy!<Ugen> - - 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). - - 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. - - 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. - - The following processing is done for each firewall on the chain: - - 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. - - 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. - - 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. - - 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. - - 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). - -That's about it for the firewall checker. The ipfirewall 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 ipfirewall 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. - -There are seven setsockopt command codes defined by the firewall facility -(in netinet/in.h). They are: - - 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 corse you have to be at least kmem group member,to read kernel symbols. - -That's about all that I can think of for now. There are a couple of details -that are worth reading about in the ip_firewall.h file. Other than that, let -me know how you do. If you have any problems, give me a call at home (403 -449-1835) or send me e-mail at "danny@BouletFermat.ab.ca". If you call, please -keep in mind that I live in the Canadian Mountain timezone (GMT-0600). - --Danny - -So that's it..if you want to say something to me-call me or mail: -Phone: 972-4-550-330 -E-mail ugen@NetVision.net.il -If you call,remember that i live in Israel timezone which is GMT+02. - --Ugen - diff --git a/sbin/scsiformat/scsiformat.c b/sbin/scsiformat/scsiformat.c deleted file mode 100644 index a185a8e..0000000 --- a/sbin/scsiformat/scsiformat.c +++ /dev/null @@ -1,664 +0,0 @@ -/*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This software was developed by the Computer Systems Engineering group - * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and - * contributed to Berkeley. - * - * 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. - * - * @(#)scsiformat.c 5.5 (Berkeley) 4/2/94 - */ - -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1992, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)scsiformat.c 5.5 (Berkeley) 4/2/94"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/ioctl.h> - -#include <dev/scsi/scsi.h> -#include <dev/scsi/disk.h> -#include <dev/scsi/disktape.h> -#include <dev/scsi/scsi_ioctl.h> - -#define COMPAT_HPSCSI - -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -int fd; -char *device; - -void scsi_str __P((char *, char *, int)); -void do_command __P((int, struct scsi_cdb *, void *, int)); -void do_format __P((void)); -void print_capacity __P((void)); -void print_inquiry __P((void)); -void prflags __P((int, const char *)); -u_char *print_mode_page __P((u_char *)); -void print_mode_sense __P((void)); -void usage __P((void)); - -#define N2(c, d) (((c) << 8) | (d)) -#define N3(b, c, d) (((b) << 16) | N2(c, d)) -#define N4(a, b, c, d) (((a) << 24) | N3(b, c, d)) - -int sense_pctl; - -int -main(argc, argv) - int argc; - char *argv[]; -{ - extern char *optarg; - int ch, readonly; - - readonly = 0; - sense_pctl = SCSI_MSENSE_PCTL_CUR; - while ((ch = getopt(argc, argv, "rp:")) != EOF) { - switch(ch) { - case 'r': - readonly = 1; - break; - case 'p': /* mode sense page control */ - switch (*optarg) { - case 'c': - sense_pctl = SCSI_MSENSE_PCTL_CUR; - break; - case 'd': - sense_pctl = SCSI_MSENSE_PCTL_DFLT; - break; - case 's': - sense_pctl = SCSI_MSENSE_PCTL_SAVED; - break; - case 'v': - (void)printf( - "*** note: for variable parameters, 1-bit means ``can write here''\n"); - sense_pctl = SCSI_MSENSE_PCTL_VAR; - break; - } - /* FALLTHROUGH */ - case '?': - default: - usage(); - } - } - argc -= optind; - argv += optind; - - if (argc != 1) - usage(); - - device = *argv; - fd = open(device, readonly ? O_RDONLY : O_RDWR, 0); - if (fd < 0) { - (void)fprintf(stderr, - "scsiformat: %s: %s\n", device, strerror(errno)); - exit(1); - } - print_inquiry(); - print_capacity(); - print_mode_sense(); - - if (!readonly) - do_format(); - exit(0); -} - -/* - * Copy a counted string, trimming trailing blanks, and turning the - * result into a C-style string. - */ -void -scsi_str(src, dst, len) - register char *src, *dst; - register int len; -{ - - while (src[len - 1] == ' ') { - if (--len == 0) { - *dst = 0; - return; - } - } - bcopy(src, dst, len); - dst[len] = 0; -} - -void -print_inquiry() -{ - register struct scsi_inq_ansi *si; - int ver; - struct scsi_inquiry inqbuf; - char vendor[10], product[17], rev[5]; - static struct scsi_cdb inq = { - CMD_INQUIRY, 0, 0, 0, sizeof(inqbuf), 0 - }; - - do_command(fd, &inq, &inqbuf, sizeof(inqbuf)); - (void)printf("%s: ", device); - - ver = (inqbuf.si_version >> VER_ANSI_SHIFT) & VER_ANSI_MASK; - if (ver != 1 && ver != 2) { - (void)printf("type 0x%x, qual 0x%x, ver 0x%x (ansi %d)\n", - inqbuf.si_type, inqbuf.si_qual, inqbuf.si_version, ver); - return; - } - si = (struct scsi_inq_ansi *)&inqbuf; - switch (si->si_type & TYPE_TYPE_MASK) { - - case TYPE_DAD: - (void)printf("(disk)"); - break; - - case TYPE_WORM: - (void)printf("(WORM)"); - break; - - case TYPE_ROM: - (void)printf("(CD-ROM)"); - break; - - case TYPE_MO: - (void)printf("(MO-DISK)"); - break; - - case TYPE_JUKEBOX: - (void)printf("(jukebox)"); - break; - - default: - (void)printf("(??)"); - break; - } - scsi_str(si->si_vendor, vendor, sizeof(si->si_vendor)); - scsi_str(si->si_product, product, sizeof(si->si_product)); - scsi_str(si->si_rev, rev, sizeof(si->si_rev)); - (void)printf(" %s %s rev %s:", vendor, product, rev); -} - -void -print_capacity() -{ - struct scsi_rc rc; /* for READ CAPACITY */ - static struct scsi_cdb cap = { CMD_READ_CAPACITY }; - - do_command(fd, &cap, &rc, sizeof(rc)); - (void)printf(" %d blocks of %d bytes each\n", - N4(rc.rc_lbah, rc.rc_lbahm, rc.rc_lbalm, rc.rc_lbal) + 1, - N4(rc.rc_blh, rc.rc_blhm, rc.rc_bllm, rc.rc_bll)); -} - -void -print_mode_sense() -{ - register u_char *cp, *ep; - register struct scsi_ms_bd *bd; - register int n, i, l, len, bdlen; -#ifdef TEN_BYTE_SENSE - struct { - struct scsi_ms10 ms; - u_char p[1023 - sizeof(struct scsi_ms10)]; - } msbuf; - static struct scsi_cdb modesense = { - CMD_MODE_SENSE10, SCSI_MSENSE_DBD, 0, 0, 0, 0, 0, - sizeof(msbuf) >> 8, sizeof (msbuf), 0 - }; - - CDB10(&modesense)->cdb_lbam = sense_pctl | SCSI_MS_PC_ALL; - do_command(fd, &modesense, &msbuf, sizeof(msbuf)); - len = N2(msbuf.ms.ms_lenh, msbuf.ms.ms_lenl); - bdlen = N2(msbuf.ms.ms_bdlh, msbuf.ms.ms_bdll); -#else - struct { - struct scsi_ms6 ms; - u_char p[255 - sizeof(struct scsi_ms6)]; - } msbuf; - static struct scsi_cdb modesense = { - CMD_MODE_SENSE6, 0, 0, 0, sizeof(msbuf), 0 - }; - - CDB6(&modesense)->cdb_lbam = sense_pctl | SCSI_MS_PC_ALL; - do_command(fd, &modesense, &msbuf, sizeof(msbuf)); - len = msbuf.ms.ms_len; - bdlen = msbuf.ms.ms_bdl; -#endif - (void)printf("\n%d bytes of mode sense data. ", len); - (void)printf("medium type 0x%x, %swrite protected\n", - msbuf.ms.ms_mt, msbuf.ms.ms_dsp & SCSI_MS_DSP_WP ? "" : "not "); - if ((n = bdlen) != 0) { - bd = (struct scsi_ms_bd *)msbuf.p; - for (n /= sizeof(*bd); --n >= 0; bd++) { - (void)printf("\tdensity code 0x%x, ", bd->bd_dc); - i = N3(bd->bd_nbh, bd->bd_nbm, bd->bd_nbl); - l = N3(bd->bd_blh, bd->bd_blm, bd->bd_bll); - if (i) - (void)printf("%d blocks of length %d\n", i, l); - else - (void)printf("all blocks of length %d\n", l); - } - } - /* - * Sense header lengths includes the sense header, while mode page - * lengths do not ... let's hear it for consistency! - */ - cp = msbuf.p + bdlen; - ep = msbuf.p + len - sizeof(msbuf.ms); - while (cp < ep) - cp = print_mode_page(cp); -} - -void -prflags(v, cp) - int v; - register const char *cp; -{ - register const char *np; - char f, sep; - - for (sep = '<'; (f = *cp++) != 0; cp = np) { - for (np = cp; *np >= ' ';) - np++; - if ((v & (1 << (f - 1))) == 0) - continue; - printf("%c%.*s", sep, np - cp, cp); - sep = ','; - } - if (sep != '<') - putchar('>'); -} - -static char * -cache_policy(x) - int x; -{ - static char rsvd[30]; - - switch (x) { - - case SCSI_CACHE_DEFAULT: - return ("default"); - - case SCSI_CACHE_KEEPPF: - return ("toss cmd data, save prefetch"); - - case SCSI_CACHE_KEEPCMD: - return ("toss prefetch data, save cmd"); - - default: - (void)sprintf(rsvd, "reserved %d", x); - return (rsvd); - } - /* NOTREACHED */ -} - -u_char * -print_mode_page(cp) - u_char *cp; -{ - register struct scsi_ms_page_hdr *mp; - int len, code, i; - u_char *tp; - const char *s; - - mp = (struct scsi_ms_page_hdr *)cp; - code = mp->mp_psc & SCSI_MS_PC_MASK; - len = mp->mp_len; - (void)printf("\npage type %d%s (%d bytes): ", - code, mp->mp_psc & SCSI_MS_MP_SAVEABLE ? " (saveable)" : "", len); - switch (code) { - - case SCSI_MS_PC_RWERRREC: -#define rw ((struct scsi_page_rwerrrec *)(mp + 1)) - (void)printf("Read/Write Error Recovery parameters.\n"); - (void)printf("\tflags = 0x%x", rw->rw_flags); - prflags(rw->rw_flags, - "\10AWRE\7ARRE\6TB\5RC\4EER\3PER\2DTE\1DCR"); - (void)printf(",\n\t%d read retries, %d correction span bits,\n", - rw->rw_read_retry, rw->rw_corr_span); - (void)printf("\t%d head offsets, %d data strobe offsets%s\n", - rw->rw_hd_off, rw->rw_ds_off, len > 6 ? "," : "."); - if (len <= 6) - break; - (void)printf("\t%d write retries, ", rw->rw_write_retry); - i = N2(rw->rw_rtlh, rw->rw_rtll); - if (i != 0xffff) - (void)printf("%d", i); - else - (void)printf("no"); - (void)printf(" recovery time limit.\n"); - break; -#undef rw - - case SCSI_MS_PC_DR: -#define dr ((struct scsi_page_dr *)(mp + 1)) - (void)printf("Disconnect/Reconnect control.\n"); - (void)printf("\tbuffer full ratio %d, buffer empty ratio %d,\n", - dr->dr_full, dr->dr_empty); - (void)printf("\ttime limits: %d bus inactivity, ", - N2(dr->dr_inacth, dr->dr_inactl)); - (void)printf("%d disconnect, %d connect.\n", - N2(dr->dr_disconh, dr->dr_disconl), - N2(dr->dr_conh, dr->dr_conl)); - (void)printf("\tmaximum burst size %d,\n", - N2(dr->dr_bursth, dr->dr_burstl)); - switch (dr->dr_dtdc & SCSI_DR_DTDC_MASK) { - case SCSI_DR_DTDC_NONE: - s = "never"; - break; - case SCSI_DR_DTDC_NOTDATA: - s = "during data transfer"; - break; - case SCSI_DR_DTDC_RSVD: - s = "???"; - break; - case SCSI_DR_DTDC_NOTD2: - s = "during and after data transfer"; - break; - } - (void)printf("\tsuppress disconnect %s.\n", s); - break; -#undef dr - - case SCSI_MS_PC_FMT: -#define fmt ((struct scsi_page_fmt *)(mp + 1)) - (void)printf("Format parameters.\n"); - (void)printf("\t%d tracks/zone, %d alt.sect./zone, ", - N2(fmt->fmt_tpzh, fmt->fmt_tpzl), - N2(fmt->fmt_aspzh, fmt->fmt_aspzl)); - (void)printf("%d alt.tracks/zone,\n\t%d alt.tracks/vol., ", - N2(fmt->fmt_atpzh, fmt->fmt_atpzl), - N2(fmt->fmt_atpvh, fmt->fmt_atpvl)); - (void)printf("%d sectors/track, %d bytes/phys.sector,\n", - N2(fmt->fmt_spth, fmt->fmt_sptl), - N2(fmt->fmt_dbppsh, fmt->fmt_dbppsl)); - (void)printf("\tinterleave %d, track skew %d, cyl.skew %d,\n", - N2(fmt->fmt_ilh, fmt->fmt_ill), - N2(fmt->fmt_tsfh, fmt->fmt_tsfl), - N2(fmt->fmt_csfh, fmt->fmt_csfl)); - (void)printf("\tdrive flags 0x%x", fmt->fmt_flags); - prflags(fmt->fmt_flags, "\10SSEC\7HSEC\6RMB\5SURF"); - (void)printf(".\n"); - break; -#undef fmt - - case SCSI_MS_PC_RDGEOM: -#define rd ((struct scsi_page_rdgeom *)(mp + 1)) - (void)printf("Disk Geometry parameters.\n"); - (void)printf("\t%d cylinders, %d heads,\n", - N3(rd->rd_ncylh, rd->rd_ncylm, rd->rd_ncyll), - rd->rd_nheads); - (void)printf("\tstart write precompensation at cyl %d,\n", - N3(rd->rd_wpcylh, rd->rd_wpcylm, rd->rd_wpcyll)); - (void)printf("\tstart reduced write current at cyl %d,\n", - N3(rd->rd_rwcylh, rd->rd_rwcylm, rd->rd_rwcyll)); - (void)printf("\tseek step rate %f us, landing zone cyl %d,\n", - N2(rd->rd_steph, rd->rd_stepl) * 0.1, - N3(rd->rd_lcylh, rd->rd_lcylm, rd->rd_lcyll)); - switch (rd->rd_rpl & SCSI_RD_RPL_MASK) { - case SCSI_RD_RPL_NONE: - s = "disabled or unsupported"; - break; - case SCSI_RD_RPL_SLAVE: - s = "slave"; - break; - case SCSI_RD_RPL_MASTER: - s = "master"; - break; - case SCSI_RD_RPL_MCONTROL: - s = "master control"; - break; - } - (void)printf("\trotational synch %s, offset %d/256%s\n", - s, rd->rd_roff, len > 18 ? "," : "."); - if (len > 18) - (void)printf("\trotation %d rpm.\n", - N2(rd->rd_rpmh, rd->rd_rpml)); - break; -#undef rd - - case SCSI_MS_PC_VERRREC: -#define v ((struct scsi_page_verrrec *)(mp + 1)) - (void)printf("Verify Error Recovery parameters.\n"); - (void)printf("\tflags = 0x%x", v->v_flags); - prflags(v->v_flags, "\4EER\3PER\2DTE\1DCR"); - (void)printf(",\n\t%d verify retries, %d %s span bits,\n\t", - v->v_verify_retry, v->v_corr_span, "correction"); - (void)printf("%d recovery time limit.\n", - N2(v->v_rtlh, v->v_rtll)); - break; -#undef v - - case SCSI_MS_PC_CACHE: -#define cache ((struct scsi_page_cache *)(mp + 1)) - (void)printf("Caching Page.\n"); - (void)printf("\tflags = 0x%x", cache->cache_flags); - prflags(cache->cache_flags, "\3WCE\2MF\1RCD"); - (void)printf( - ",\n\tread retention = %s, write retention = %s,\n", - cache_policy(SCSI_CACHE_RDPOLICY(cache->cache_reten)), - cache_policy(SCSI_CACHE_WRPOLICY(cache->cache_reten))); - (void)printf("\tdisable prefetch transfer length = %d,\n", - N2(cache->cache_dptlh, cache->cache_dptll)); - (void)printf("\tmin prefetch = %d, max prefetch = %d, ", - N2(cache->cache_minpfh, cache->cache_minpfl), - N2(cache->cache_maxpfh, cache->cache_maxpfl)); - (void)printf("max prefetch ceiling = %d.\n", - N2(cache->cache_mpch, cache->cache_mpcl)); - break; -#undef cache - - case SCSI_MS_PC_CTLMODE: -#define cm ((struct scsi_page_ctlmode *)(mp + 1)) - (void)printf("Control Mode Page.\n"); - (void)printf("\t%s report log-activity error conditions,\n", - cm->cm_rlec & SCSI_CM_RLEC ? "do" : "do not"); - (void)printf("\tqueue algorithm modifier = %d, flags = 0x%x", - SCSI_CM_QMOD(cm->cm_qctl), - cm->cm_qctl & (SCSI_CM_QERR|SCSI_CM_DQUE)); - prflags(cm->cm_qctl, "\2QERR\1DQUE"); - (void)printf(",\n\tECA/AEN flags = 0x%x", cm->cm_ecaaen); - prflags(cm->cm_ecaaen, "\10ECA\3RAENP\2UUAENP\1EAENP"); - (void)printf(", AEN holdoff period = %d ms.\n", - N2(cm->cm_aenholdh, cm->cm_aenholdl)); - break; -#undef cm - - /* - * Vendor Unique, but what the heck. - */ - case SCSI_MS_PC_CDCCACHECTL: -#define ccm ((struct scsi_page_CDCcachectlmode *)(mp + 1)) - (void)printf("CDC-specific Cache Control Mode Page.\n"); - (void)printf("\tflags = 0x%x", ccm->ccm_flags); - prflags(ccm->ccm_flags, "\7WIE\5ENABLE"); - (void)printf(", table size = %d, prefetch threshold = %d\n", - SCSI_CDC_CCM_TBLSZ(ccm->ccm_flags), - ccm->ccm_pfthresh); - (void)printf("\tmaximum %s = %d, maximum %s = %d,\n", - "threshold", ccm->ccm_maxthresh, - "prefetch multiplier", ccm->ccm_maxpfmult); - (void)printf("\tminimum %s = %d, minimum %s = %d.\n", - "threshold", ccm->ccm_minthresh, - "prefetch multiplier", ccm->ccm_minpfmult); - break; -#undef ccm - - default: - (void)printf("Unknown page type."); - for (tp = cp + sizeof(*mp), i = 0; i < len; ++i) { - if ((i & 7) == 0) - (void)printf("\n\t%2d: ", i); - (void)printf(" %02x", *tp++); - } - (void)printf(".\n"); - break; - } - return (cp + sizeof(*mp) + len); -} - -void -pr_sense(fd) - int fd; -{ - static struct scsi_fmt_sense s; - register struct scsi_sense *sn; - - if (ioctl(fd, SDIOCSENSE, &s) < 0) - (void)fprintf(stderr, - "scsiformat: SDIOCSENSE: %s\n", strerror(errno)); - - (void)printf("scsi status 0x%x", s.status); - if (s.status & STS_CHECKCOND) { - sn = (struct scsi_sense *)s.sense; - - (void)printf(" sense class %d, code %d", - SENSE_ECLASS(sn), SENSE_ECODE(sn)); - if (SENSE_ISXSENSE(sn)) { - (void)printf(", key %d", XSENSE_KEY(sn)); - if (XSENSE_IVALID(sn)) - (void)printf(", blk %d", XSENSE_INFO(sn)); - } - } - (void)printf("\n"); -} - -void -do_format() -{ - struct { - struct scsi_ms6 ms; /* mode select header */ - struct scsi_ms_bd bd; /* block descriptor */ - struct scsi_ms_page_hdr mp; /* ctl mode page hdr */ - struct scsi_page_ctlmode cm; /* ctl mode page */ - u_char pad[4]; /* ??? */ - } msel; - u_char fmtbuf[128]; - static struct scsi_cdb modeselect = { - CMD_MODE_SELECT6, - SCSI_MSEL_SCSI2_DATA | SCSI_MSEL_SAVEPAGES, 0, 0, - sizeof(msel), 0 - }; - static struct scsi_cdb format = { CMD_FORMAT_UNIT }; - - /* want mostly 0s; set them all zero here */ - bzero(&msel, sizeof(msel)); - - /* one block descriptor */ - msel.ms.ms_bdl = sizeof(struct scsi_ms_bd); - - /* block length = 512 bytes */ - msel.bd.bd_blm = 512 / 256; - msel.bd.bd_bll = 512 % 256; - - /* - * In the following, the mystery pad region is copied from - * the original driver. I have no idea what it is for. - * (Anyone got SCSI-2 documents?) - */ - - /* mode page parameters: report log-activity exception conditions */ - msel.mp.mp_psc = SCSI_MS_PC_CTLMODE; - msel.mp.mp_len = sizeof(msel.cm) + sizeof(msel.pad); - msel.cm.cm_rlec = SCSI_CM_RLEC; - - do_command(fd, &modeselect, &msel, sizeof(msel)); - - bzero(fmtbuf, sizeof(fmtbuf)); - do_command(fd, &format, fmtbuf, sizeof(fmtbuf)); -} - -void -do_command(fd, cdb, buf, len) - int fd; - struct scsi_cdb *cdb; - void *buf; - int len; -{ - static int on = 1, off = 0; - int user, ret; - - bzero(buf, len); - if (ioctl(fd, SDIOCSFORMAT, &on) < 0) { - (void)fprintf(stderr, - "scsiformat: SDIOCSFORMAT (on): %s\n", strerror(errno)); - if (ioctl(fd, SDIOCGFORMAT, &user) == 0 && user != 0) - (void)fprintf(stderr, "scsiformat: pid %d has it\n", - user); - return; - } - ret = ioctl(fd, SDIOCSCSICOMMAND, cdb); -#ifdef COMPAT_HPSCSI - if (ret < 0) { - static const char scsicmdlen[8] = { 6, 10, 0, 0, 0, 12, 0, 0 }; -#define SCSICMDLEN(cmd) scsicmdlen[(cmd) >> 5] - struct scsi_fmt_cdb { - int len; - u_char cdb[28]; - } sc; -#define OSDIOCSCSICOMMAND _IOW('S', 0x3, struct scsi_fmt_cdb) - - sc.len = SCSICMDLEN(cdb->cdb_bytes[0]); - bcopy(cdb->cdb_bytes, sc.cdb, sc.len); - ret = ioctl(fd, OSDIOCSCSICOMMAND, &sc); - } -#endif - if (ret < 0) - (void)fprintf(stderr, - "scsiformat: SDIOCSCSICOMMAND: %s\n", strerror(errno)); - else if (read(fd, buf, len) < 0) { - (void)fprintf(stderr, - "scsiformat: read: %s\n", strerror(errno)); - pr_sense(fd); - } - - if (ioctl(fd, SDIOCSFORMAT, &off) < 0) - (void)fprintf(stderr, - "scsiformat: SDIOCSFORMAT (off): %s\n", strerror(errno)); -} - -void -usage() -{ - (void)fprintf(stderr, "usage: scsiformat [-r] [-p c|d|s|v] device\n"); - exit(1); -} |