diff options
author | cvs2svn <cvs2svn@FreeBSD.org> | 2002-06-21 19:07:22 +0000 |
---|---|---|
committer | cvs2svn <cvs2svn@FreeBSD.org> | 2002-06-21 19:07:22 +0000 |
commit | 5389693ebe81c11829a4bfa5aab9b4af89f0f0b1 (patch) | |
tree | cd032865b0b61b79fefd2da6284fd04136a050db | |
parent | be026881b1db1eb89066293625a4289fcf75d49f (diff) |
This commit was manufactured by cvs2svn to create tagvendor/NetBSD/head_20020621
'head_20020621'.
Notes
Notes:
svn path=/vendor/NetBSD/dist/; revision=98576
svn path=/vendor/NetBSD/head_20020621/; revision=98578; tag=vendor/NetBSD/head_20020621
135 files changed, 0 insertions, 36585 deletions
diff --git a/etc/mail/mailer.conf b/etc/mail/mailer.conf deleted file mode 100644 index 6d2b3c5ec3c6..000000000000 --- a/etc/mail/mailer.conf +++ /dev/null @@ -1,8 +0,0 @@ -# $NetBSD: mailer.conf,v 1.2 1999/02/05 18:11:23 perry Exp $ -# -# Execute the "real" sendmail program, named /usr/libexec/sendmail/sendmail -# -sendmail /usr/libexec/sendmail/sendmail -send-mail /usr/libexec/sendmail/sendmail -mailq /usr/libexec/sendmail/sendmail -newaliases /usr/libexec/sendmail/sendmail diff --git a/etc/mailer.conf b/etc/mailer.conf deleted file mode 100644 index 6d2b3c5ec3c6..000000000000 --- a/etc/mailer.conf +++ /dev/null @@ -1,8 +0,0 @@ -# $NetBSD: mailer.conf,v 1.2 1999/02/05 18:11:23 perry Exp $ -# -# Execute the "real" sendmail program, named /usr/libexec/sendmail/sendmail -# -sendmail /usr/libexec/sendmail/sendmail -send-mail /usr/libexec/sendmail/sendmail -mailq /usr/libexec/sendmail/sendmail -newaliases /usr/libexec/sendmail/sendmail diff --git a/etc/rc b/etc/rc deleted file mode 100644 index 19f62e74d9df..000000000000 --- a/etc/rc +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -# -# $NetBSD: rc,v 1.152 2000/04/22 03:01:22 lukem Exp $ -# -# rc.sh -- -# Run the scripts in /etc/rc.d with rcorder. - -# System startup script run by init on autoboot or after single-user. -# Output and error are redirected to console by init, and the console -# is the controlling terminal. - -export HOME=/ -export PATH=/sbin:/bin:/usr/sbin:/usr/bin - -. /etc/rc.subr -. /etc/rc.conf - -if ! checkyesno rc_configured; then - echo "/etc/rc.conf is not configured. Multiuser boot aborted." - exit 1 -fi - -if [ "$1" = autoboot ]; then - autoboot=yes - _rc_fast_run=yes # run_rc_command(): do fast booting -fi - -stty status '^T' - -# Set shell to ignore SIGINT (2), but not children; -# shell catches SIGQUIT (3) and returns to single user. -# -trap : 2 -trap "echo 'Boot interrupted.'; exit 1" 3 - -files=`rcorder -s nostart /etc/rc.d/*` - -for i in $files; do - run_rc_script $i start -done - -date -exit 0 diff --git a/etc/rc.d/NETWORK b/etc/rc.d/NETWORK deleted file mode 100755 index 92040d24bdf2..000000000000 --- a/etc/rc.d/NETWORK +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -# -# $NetBSD$ -# - -# PROVIDE: NETWORK -# REQUIRE: network dhclient - -# This is a dummy dependancy, for services which require networking -# to be operational before starting. diff --git a/etc/rc.d/gated b/etc/rc.d/gated deleted file mode 100755 index 7a11e8c22425..000000000000 --- a/etc/rc.d/gated +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh -# -# $NetBSD: gated,v 1.3 2000/05/13 08:45:06 lukem Exp $ -# - -# PROVIDE: gated -# REQUIRE: DAEMON - -. /etc/rc.subr - -name="gated" -rcvar=$name -command="/usr/sbin/${name}" -pidfile="/var/run/${name}.pid" -required_files="/etc/${name}.conf" - -load_rc_config $name -run_rc_command "$1" diff --git a/etc/rc.shutdown b/etc/rc.shutdown deleted file mode 100644 index bccf8360f485..000000000000 --- a/etc/rc.shutdown +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# -# $NetBSD: rc.shutdown,v 1.3 2000/03/10 13:17:25 lukem Exp $ -# -# rc.shutdown.sh -- -# Run the scripts in /etc/rc.d with reverse rcorder. - -export HOME=/ -export PATH=/sbin:/bin:/usr/sbin:/usr/bin - -. /etc/rc.subr -. /etc/rc.conf - -if ! checkyesno do_rcshutdown; then - echo "Skipping shutdown hooks." - exit 0 -fi - -stty status '^T' - -# Set shell to ignore SIGINT (2), but not children; -# shell catches SIGQUIT (3) and returns to single user. -# -trap : 2 -trap "echo 'Shutdown interrupted.'; exit 1" 3 - -files=`rcorder -k shutdown /etc/rc.d/*` -for i in $files; do # reverse order of files - nfiles="$i $nfiles" -done -files=$nfiles - -for i in $files; do - run_rc_script $i stop -done - -date -exit 0 diff --git a/etc/rc.subr b/etc/rc.subr deleted file mode 100644 index 5292a3271b24..000000000000 --- a/etc/rc.subr +++ /dev/null @@ -1,586 +0,0 @@ -# $NetBSD: rc.subr,v 1.28 2000/11/06 00:08:30 lukem Exp $ -# -# Copyright (c) 1997-2000 The NetBSD Foundation, Inc. -# All rights reserved. -# -# This code is derived from software contributed to The NetBSD Foundation -# by Luke Mewburn. -# -# 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 NetBSD -# Foundation, Inc. and its contributors. -# 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. -# -# rc.subr -# functions used by various rc scripts -# - -# -# functions -# --------- - -# -# checkyesno var -# Test $1 variable, and warn if not set to YES or NO. -# Return 0 if it's "yes" (et al), nonzero otherwise. -# -checkyesno() -{ - eval _value=\$${1} - case $_value in - - # "yes", "true", "on", or "1" - [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) - return 0 - ;; - - # "no", "false", "off", or "0" - [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) - return 1 - ;; - *) - warn "\$${1} is not set properly." - return 1 - ;; - esac -} - -# -# mount_critical_filesystems -# Go through the list of critical filesystems, checking each one -# to see if it is mounted, and if it is not, mounting it. -# -mount_critical_filesystems() -{ - if [ $1 = local ]; then - _fslist=$critical_filesystems_beforenet - else - _fslist=$critical_filesystems - fi - for _fs in $_fslist; do - mount | ( - _ismounted=no - while read what _on on _type type; do - if [ $on = $_fs ]; then - _ismounted=yes - fi - done - if [ $_ismounted = no ]; then - mount $_fs >/dev/null 2>&1 - fi - ) - done -} - -# -# check_pidfile pidfile procname -# Parses the first line of pidfile for a pid, and ensures -# that the process is running and matches procname. -# Prints the matching pid upon success, nothing otherwise. -# -check_pidfile() -{ - _pidfile=$1 - _procname=$2 - if [ -z "$_pidfile" -o -z "$_procname" ]; then - err 3 'USAGE: check_pidfile pidfile procname' - fi - if [ ! -f $_pidfile ]; then - return - fi - read _pid _junk < $_pidfile - if [ -z "$_pid" ]; then - return - fi - _procnamebn=${_procname##*/} - ps -p $_pid -o 'pid,command' | while read _npid _arg0 _argv; do - if [ "$_npid" = "PID" ]; then - continue - fi - if [ "$_arg0" = "$_procname" \ - -o "$_arg0" = "$_procnamebn" \ - -o "$_arg0" = "${_procnamebn}:" \ - -o "$_arg0" = "(${_procnamebn})" ]; then - echo $_npid - return - fi - done -} - -# -# check_process procname -# Ensures that a process (or processes) named procname is running. -# Prints a list of matching pids. -# -check_process() -{ - _procname=$1 - if [ -z "$_procname" ]; then - err 3 'USAGE: check_process procname' - fi - _procnamebn=${_procname##*/} - _pref= - ps -ax -o 'pid,command' | while read _npid _arg0 _argv; do - if [ "$_npid" = "PID" ]; then - continue - fi - if [ "$_arg0" = "$_procname" \ - -o "$_arg0" = "$_procnamebn" \ - -o "$_arg0" = "${_procnamebn}:" \ - -o "$_arg0" = "(${_procnamebn})" ]; then - echo -n "$_pref$_npid" - _pref=" " - fi - done -} - -# -# run_rc_command arg -# Search for arg in the list of supported commands, which is: -# "start stop restart rcvar status ${extra_commands}" -# If there's a match, run ${arg}_cmd or the default command (see below). -# -# If arg has a given prefix, then change the operation as follows: -# prefix operation -# ------ --------- -# fast Skip the pid check. -# force Set ${rcvar} to YES. -# -# The following globals are used: -# -# name needed function -# ---- ------ -------- -# name y Name of script. -# -# command n Full path to command. -# Not needed if ${arg}_cmd is set for -# each keyword. -# -# command_args n Optional args/shell directives for command. -# -# extra_commands n List of extra commands supported. -# -# pidfile n If set, use check_pidfile $pidfile, else if -# $command is set, use check_process $command. -# -# rcvar n This is checked with checkyesno to determine -# if the action should be run. -# -# ${name}_chroot n Directory to chroot to before running ${command} -# -# ${name}_chdir n Directory to cd to before running ${command} -# (if not using ${name}_chroot). -# -# ${name}_flags n Arguments to call ${command} with. -# NOTE: $flags from the parent environment -# can be used to override this. -# -# ${name}_nice n Nice level to run ${command} at. -# -# ${name}_user n User to run ${command} as, using su(1) if not -# using ${name}_chroot. -# -# ${name}_group n Group to run chrooted ${command} as. -# -# ${name}_groups n Supplementary group list to run chrooted -# ${command} with. -# -# ${_arg}_cmd n If set, use this as the action when invoked; -# $_arg is available to the action to use. -# Otherwise, use default command (see below) -# -# ${_arg}_precmd n If set, run just before performing the main -# action in the default command (i.e, after -# checking for required bits and process -# (non)existance). -# If this completes with a non-zero exit code, -# don't run ${_arg}_cmd. -# -# required_dirs n If set, check for the existence of the given -# directories before running the default -# (re)start command. -# -# required_files n If set, check for the readability of the given -# files before running the default (re)start -# command. -# -# required_vars n If set, perform checkyesno on each of the -# listed variables before running the default -# (re)start command. -# -# Default commands for a given arg: -# -# arg default -# --- ------- -# status Show if ${command} is running, etc. -# -# start if !running && checkyesno ${rcvar} -# ${command} -# -# stop if ${pidfile} -# kill $sig_stop `check_pidfile $pidfile` -# else -# kill $sig_stop `check_process $command` -# $sig_stop defaults to TERM. -# -# reload As stop, except use $sig_reload instead. -# $sig_reload defaults to HUP. -# -# restart Run `stop' then `start'. -# -# -run_rc_command() -{ - _arg=$1 - if [ -z "$name" ]; then - err 3 '$name is not set.' - fi - - case "$_arg" in - fast*) # "fast" prefix; don't check pid - _arg=${_arg#fast} - _rc_fast_run=YES - ;; - force*) # "force prefix; always start - _arg=${_arg#force} - _rc_force_run=YES - if [ -n "${rcvar}" ]; then - eval ${rcvar}=YES - fi - ;; - esac - - _keywords="start stop restart rcvar $extra_commands" - _pid= - _pidcmd= - # setup pid check command if not fast - if [ -z "$_rc_fast_run" ]; then - if [ -n "$pidfile" ]; then - _pidcmd='_pid=`check_pidfile '$pidfile' '$command'`' - elif [ -n "$command" ]; then - _pidcmd='_pid=`check_process '$command'`' - fi - if [ -n "$_pidcmd" ]; then - _keywords="${_keywords} status" - fi - fi - - if [ -z "$_arg" ]; then - rc_usage "$_keywords" - fi - - if [ -n "$flags" ]; then # allow override from environment - _flags=$flags - else - eval _flags=\$${name}_flags - fi - eval _chdir=\$${name}_chdir - eval _chroot=\$${name}_chroot - eval _nice=\$${name}_nice - eval _user=\$${name}_user - eval _group=\$${name}_group - eval _groups=\$${name}_groups - - # if ${rcvar} is set, and $1 is not - # "rcvar" or "status", then run - # checkyesno ${rcvar} - # and return if that failed - # - if [ -n "${rcvar}" -a "$_arg" != "rcvar" -a "$_arg" != "status" ]; then - if ! checkyesno ${rcvar}; then - return 0 - fi - fi - - eval $_pidcmd # determine the pid if necessary - - for _elem in $_keywords; do - if [ "$_elem" != "$_arg" ]; then - continue - fi - - # if there's a custom ${XXX_cmd}, - # run that instead of the default - # - eval _cmd=\$${_arg}_cmd - eval _precmd=\$${_arg}_precmd - if [ -n "$_cmd" ]; then - # if the precmd failed and force - # isn't set, exit - # - if ! eval $_precmd && [ -z "$_rc_force_run" ]; then - return 1 - fi - - eval $_cmd - return 0 - fi - - case "$_arg" in # default operations... - - status) - if [ -n "$_pid" ]; then - echo "${name} is running as pid $_pid." - else - echo "${name} is not running." - return 1 - fi - ;; - - start) - if [ -n "$_pid" ]; then - echo "${name} already running? (pid=$_pid)." - exit 1 - fi - - if [ ! -x $command ]; then - return 0 - fi - - # check for required variables, - # directories, and files - # - for _f in $required_vars; do - if ! checkyesno $_f; then - warn "\$${_f} is not set." - if [ -z "$_rc_force_run" ]; then - return 1 - fi - fi - done - for _f in $required_dirs; do - if [ ! -d "${_f}/." ]; then - warn "${_f} is not a directory." - if [ -z "$_rc_force_run" ]; then - return 1 - fi - fi - done - for _f in $required_files; do - if [ ! -r "${_f}" ]; then - warn "${_f} is not readable." - if [ -z "$_rc_force_run" ]; then - return 1 - fi - fi - done - - # if the precmd failed and force - # isn't set, exit - # - if ! eval $_precmd && [ -z "$_rc_force_run" ]; then - return 1 - fi - - - # setup the command to run, and run it - # - echo "Starting ${name}." - if [ -n "$_chroot" ]; then - _doit="\ -${_nice:+nice -n $_nice }\ -chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\ -$_chroot $command $_flags $command_args" - else - _doit="\ -${_user:+su -m $_user -c 'sh -c \"}\ -${_chdir:+cd $_chdir; }\ -${_nice:+nice -n $_nice }\ -$command $_flags $command_args\ -${_user:+\"'}" - fi - eval $_doit - ;; - - stop) - if [ -z "$_pid" ]; then - if [ -n "$pidfile" ]; then - echo \ - "${name} not running? (check $pidfile)." - else - echo "${name} not running?" - fi - exit 1 - fi - - if ! eval $_precmd && [ -z "$_rc_force_run" ]; then - return 1 - fi - echo "Stopping ${name}." - _doit=\ -"${_user:+su -m $_user -c '}kill -${sig_stop:-TERM} $_pid${_user:+'}" - eval $_doit - ;; - - reload) - if [ -z "$_pid" ]; then - if [ -n "$pidfile" ]; then - echo \ - "${name} not running? (check $pidfile)." - else - echo "${name} not running?" - fi - exit 1 - fi - echo "Reloading ${name} config files." - if ! eval $_precmd && [ -z "$_rc_force_run" ]; then - return 1 - fi - _doit=\ -"${_user:+su -m $_user -c '}kill -${sig_reload:-HUP} $_pid${_user:+'}" - eval $_doit - ;; - - restart) - if ! eval $_precmd && [ -z "$_rc_force_run" ]; then - return 1 - fi - # prevent restart being called more - # than once by any given script - # - if [ -n "$_rc_restart_done" ]; then - return 0 - fi - _rc_restart_done=YES - ( $0 ${_rc_force_run:+force}stop ) - sleep 1 - $0 ${_rc_force_run:+force}start - - ;; - - rcvar) - echo "# $name" - if [ -n "$rcvar" ]; then - if checkyesno ${rcvar}; then - echo "\$${rcvar}=YES" - else - echo "\$${rcvar}=NO" - fi - fi - ;; - - *) - rc_usage "$_keywords" - ;; - - esac - return 0 - done - - echo 1>&2 "$0: unknown directive '$_arg'." - rc_usage "$_keywords" - exit 1 -} - -# -# run_rc_script file arg -# Start the script `file' with `arg', and correctly handle the -# return value from the script. If `file' ends with `.sh', it's -# sourced into the current environment. Otherwise it's run as -# a child process. -# -# Note: because `.sh' files are sourced into the current environment -# run_rc_command shouldn't be used because its difficult to ensure -# that the global variable state before and after the sourcing of -# the .sh file won't adversely affect other scripts. -# -run_rc_script() -{ - _file=$1 - _arg=$2 - if [ -z "$_file" -o -z "$_arg" ]; then - err 3 'USAGE: run_rc_script file arg' - fi - - case "$_file" in - *.sh) # run in current shell - set $_arg ; . $_file - ;; - *) # run in subshell - ( set $_arg ; . $_file ) - ;; - esac -} - -# -# load_rc_config -# Source in the configuration file for a given command. -# -load_rc_config() -{ - _command=$1 - if [ -z "$_command" ]; then - err 3 'USAGE: load_rc_config command' - fi - - . /etc/rc.conf - if [ -f /etc/rc.conf.d/"$_command" ]; then - . /etc/rc.conf.d/"$_command" - fi -} - - -# -# rc_usage commands -# Print a usage string for $0, with `commands' being a list of -# valid commands. -# -rc_usage() -{ - echo -n 1>&2 "Usage: $0 [fast|force](" - - _sep= - for _elem in $*; do - echo -n 1>&2 "$_sep$_elem" - _sep="|" - done - echo 1>&2 ")" - exit 1 -} - -# -# err exitval message -# Display message to stderr and log to the syslog, and exit with exitval. -# -err() -{ - exitval=$1 - shift - - logger "$0: ERROR: $*" - echo 1>&2 "$0: ERROR: $*" - exit $exitval -} - -# -# warn message -# Display message to stderr and log to the syslog. -# -warn() -{ - logger "$0: WARNING: $*" - echo 1>&2 "$0: WARNING: $*" -} diff --git a/lib/libc/gen/lockf.3 b/lib/libc/gen/lockf.3 deleted file mode 100644 index 6094ff1055a6..000000000000 --- a/lib/libc/gen/lockf.3 +++ /dev/null @@ -1,249 +0,0 @@ -.\" $NetBSD: lockf.3,v 1.2 1998/02/05 18:47:28 perry Exp $ -.\" -.\" Copyright (c) 1997 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" -.\" This code is derived from software contributed to The NetBSD Foundation -.\" by Klaus Klein and S.P. Zeidler. -.\" -.\" 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 NetBSD -.\" Foundation, Inc. and its contributors. -.\" 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. -.\" -.Dd December 19, 1997 -.Dt LOCKF 3 -.Os NetBSD 1.4 -.Sh NAME -.Nm lockf -.Nd record locking on files -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.Fd #include <unistd.h> -.Ft int -.Fn lockf "int filedes" "int function" "off_t size" -.Sh DESCRIPTION -The -.Fn lockf -function allows sections of a file to be locked with advisory-mode locks. -Calls to -.Fn lockf -from other processes which attempt to lock the locked file section will -either return an error value or block until the section becomes unlocked. -All the locks for a process are removed when the process terminates. -.Pp -The argument -.Fa filedes -is an open file descriptor. -The file descriptor must have been opened either for write-only -.Dv ( O_WRONLY ) -or read/write -.Dv ( O_RDWR ) -operation. -.Pp -The -.Fa function -argument is a control value which specifies the action to be taken. -The permissible values for -.Fa function -are as follows: -.Bl -tag -width F_ULOCKXX -compact -offset indent -.It Sy Function -.Sy Description -.It Dv F_ULOCK -unlock locked sections -.It Dv F_LOCK -lock a section for exclusive use -.It Dv F_TLOCK -test and lock a section for exclusive use -.It Dv F_TEST -test a section for locks by other processes -.El -.Pp -.Dv F_ULOCK -removes locks from a section of the file; -.Dv F_LOCK -and -.Dv F_TLOCK -both lock a section of a file if the section is available; -.Dv F_TEST -detects if a lock by another process is present on the specified section. -.Pp -The -.Fa size -argument is the number of contiguous bytes to be locked or -unlocked. The section to be locked or unlocked starts at the current -offset in the file and extends forward for a positive size or backward -for a negative size (the preceding bytes up to but not including the -current offset). However, it is not permitted to lock a section that -starts or extends before the beginning of the file. -If -.Fa size -is 0, the section from the current offset through the largest possible -file offset is locked (that is, from the current offset through the -present or any future end-of-file). -.Pp -The sections locked with -.Dv F_LOCK -or -.Dv F_TLOCK -may, in whole or in part, contain or be contained by a previously -locked section for the same process. When this occurs, or if adjacent -locked sections would occur, the sections are combined into a single -locked section. If the request would cause the number of locks to -exceed a system-imposed limit, the request will fail. -.Pp -.Dv F_LOCK -and -.Dv F_TLOCK -requests differ only by the action taken if the section is not -available. -.Dv F_LOCK -blocks the calling process until the section is available. -.Dv F_TLOCK -makes the function fail if the section is already locked by another -process. -.Pp -File locks are released on first close by the locking process of any -file descriptor for the file. -.Pp -.Dv F_ULOCK -requests release (wholly or in part) one or more locked sections -controlled by the process. Locked sections will be unlocked starting -at the current file offset through -.Fa size -bytes or to the end of file if size is 0. When all of a locked section -is not released (that is, when the beginning or end of the area to be -unlocked falls within a locked section), the remaining portions of -that section are still locked by the process. Releasing the center -portion of a locked section will cause the remaining locked beginning -and end portions to become two separate locked sections. If the -request would cause the number of locks in the system to exceed a -system-imposed limit, the request will fail. -.Pp -An -.Dv F_ULOCK -request in which size is non-zero and the offset of the last byte of -the requested section is the maximum value for an object of type -off_t, when the process has an existing lock in which size is 0 and -which includes the last byte of the requested section, will be treated -as a request to unlock from the start of the requested section with a -size equal to 0. Otherwise an -.Dv F_ULOCK -request will attempt to unlock only the requested section. -.Pp -A potential for deadlock occurs if a process controlling a locked -region is put to sleep by attempting to lock the locked region of -another process. This implementation detects that sleeping until a -locked region is unlocked would cause a deadlock and fails with an -.Er EDEADLK -error. -.Pp -.Fn lockf , -.Xr fcntl 2 -and -.Xr flock 2 -locks may be safely used concurrently. -.Pp -Blocking on a section is interrupted by any signal. -.Sh RETURN VALUES -If successful, the -.Fn lockf -function returns 0. -Otherwise, it returns -1, sets -.Dv errno -to indicate an error, and existing locks are not changed. -.Sh ERRORS -.Fn lockf -will fail if: -.Bl -tag -width Er -.It Bq Er EAGAIN -The argument -.Fa function -is -.Dv F_TLOCK -or -.Dv F_TEST -and the section is already locked by another process. -.It Bq Er EBADF -The argument -.Fa filedes -is not a valid open file descriptor. -.Pp -The argument -.Fa function -is -.Dv F_LOCK -or -.Dv F_TLOCK , -and -.Fa filedes -is not a valid file descriptor open for writing. -.It Bq Er EDEADLK -The argument -.Fa function -is -.Dv F_LOCK -and a deadlock is detected. -.It Bq Er EINTR -The argument -.Fa function -is F_LOCK -and -.Fn lockf -was interrupted by the delivery of a signal. -.It Bq Er EINVAL -The argument -.Fa function -is not one of -.Dv F_ULOCK , -.Dv F_LOCK , -.Dv F_TLOCK -or -.Dv F_TEST . -.Pp -The argument -.Fa filedes -refers to a file that does not support locking. -.It Bq Er ENOLCK -The argument -.Fa function -is -.Dv F_ULOCK , -.Dv F_LOCK -or -.Dv F_TLOCK , -and satisfying the lock or unlock request would result in the number -of locked regions in the system exceeding a system-imposed limit. -.Sh SEE ALSO -.Xr fcntl 2 , -.Xr flock 2 -.Sh STANDARDS -The -.Fn lockf -function conforms to -.St -xpg4.2 . diff --git a/lib/libc/gen/lockf.c b/lib/libc/gen/lockf.c deleted file mode 100644 index 04193905a61d..000000000000 --- a/lib/libc/gen/lockf.c +++ /dev/null @@ -1,96 +0,0 @@ -/* $NetBSD: lockf.c,v 1.1 1997/12/20 20:23:18 kleink Exp $ */ - -/*- - * Copyright (c) 1997 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Klaus Klein. - * - * 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 NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -#include <sys/cdefs.h> -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: lockf.c,v 1.1 1997/12/20 20:23:18 kleink Exp $"); -#endif - -#include "namespace.h" -#include <errno.h> -#include <fcntl.h> -#include <unistd.h> - -#ifdef __weak_alias -__weak_alias(lockf,_lockf); -#endif - - -int -lockf(filedes, function, size) - int filedes; - int function; - off_t size; -{ - struct flock fl; - int cmd; - - fl.l_start = 0; - fl.l_len = size; - fl.l_whence = SEEK_CUR; - - switch (function) { - case F_ULOCK: - cmd = F_SETLK; - fl.l_type = F_UNLCK; - break; - case F_LOCK: - cmd = F_SETLKW; - fl.l_type = F_WRLCK; - break; - case F_TLOCK: - cmd = F_SETLK; - fl.l_type = F_WRLCK; - break; - case F_TEST: - fl.l_type = F_WRLCK; - if (fcntl(filedes, F_GETLK, &fl) == -1) - return (-1); - if (fl.l_type == F_UNLCK || fl.l_pid == getpid()) - return (0); - errno = EAGAIN; - return (-1); - /* NOTREACHED */ - default: - errno = EINVAL; - return (-1); - /* NOTREACHED */ - } - - return (fcntl(filedes, cmd, &fl)); -} diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2 deleted file mode 100644 index 69477e9796f3..000000000000 --- a/lib/libc/sys/ptrace.2 +++ /dev/null @@ -1,395 +0,0 @@ -.\" $NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $ -.\" -.\" This file is in the public domain. -.Dd November 7, 1994 -.Dt PTRACE 2 -.Os NetBSD 1.0BETA -.Sh NAME -.Nm ptrace -.Nd process tracing and debugging -.Sh SYNOPSIS -.Fd #include <sys/types.h> -.Fd #include <sys/ptrace.h> -.Ft int -.Fn ptrace "int request" "pid_t pid" "caddr_t addr" "int data" -.Sh DESCRIPTION -.Fn ptrace -provides tracing and debugging facilities. It allows one process (the -.Em tracing -process) to control another (the -.Em traced -process). Most of the time, the traced process runs normally, but when -it receives a signal -.Po -see -.Xr sigaction 2 -.Pc , -it stops. The tracing process is expected to notice this via -.Xr wait 2 -or the delivery of a -.Dv SIGCHLD -signal, examine the state of the stopped process, and cause it to -terminate or continue as appropriate. -.Fn ptrace -is the mechanism by which all this happens. -.Pp -The -.Fa request -argument specifies what operation is being performed; the meaning of -the rest of the arguments depends on the operation, but except for one -special case noted below, all -.Fn ptrace -calls are made by the tracing process, and the -.Fa pid -argument specifies the process ID of the traced process. -.Fa request -can be: -.Bl -tag -width 12n -.It Dv PT_TRACE_ME -This request is the only one used by the traced process; it declares -that the process expects to be traced by its parent. All the other -arguments are ignored. (If the parent process does not expect to trace -the child, it will probably be rather confused by the results; once the -traced process stops, it cannot be made to continue except via -.Eo \& -.Fn ptrace -.Ec \&.) -When a process has used this request and calls -.Xr execve 2 -or any of the routines built on it -.Po -such as -.Xr execv 3 -.Pc , -it will stop before executing the first instruction of the new image. -Also, any setuid or setgid bits on the executable being executed will -be ignored. -.It Dv PT_READ_I , Dv PT_READ_D -These requests read a single -.Li int -of data from the traced process' address space. Traditionally, -.Fn ptrace -has allowed for machines with distinct address spaces for instruction -and data, which is why there are two requests: conceptually, -.Dv PT_READ_I -reads from the instruction space and -.Dv PT_READ_D -reads from the data space. In the current NetBSD implementation, these -two requests are completely identical. The -.Fa addr -argument specifies the address (in the traced process' virtual address -space) at which the read is to be done. This address does not have to -meet any alignment constraints. The value read is returned as the -return value from -.Eo \& -.Fn ptrace -.Ec . -.It Dv PT_WRITE_I , Dv PT_WRITE_D -These requests parallel -.Dv PT_READ_I -and -.Dv PT_READ_D , -except that they write rather than read. The -.Fa data -argument supplies the value to be written. -.It Dv PT_READ_U -This request reads an -.Li int -from the traced process' user structure. The -.Fa addr -argument specifies the location of the int relative to the base of the -user structure; it will usually be an integer value cast to -.Li caddr_t -either explicitly or via the presence of a prototype for -.Eo \& -.Fn ptrace -.Ec . -Unlike -.Dv PT_READ_I -and -.Dv PT_READ_D , -.Fa addr -must be aligned on an -.Li int -boundary. The value read is returned as the return value from -.Eo \& -.Fn ptrace -.Ec . -.It Dv PT_WRITE_U -This request writes an -.Li int -into the traced process' user structure. -.Fa addr -specifies the offset, just as for -.Dv PT_READ_U , -and -.Fa data -specifies the value to be written, just as for -.Dv PT_WRITE_I -and -.Dv PT_WRITE_D . -.It Dv PT_CONTINUE -The traced process continues execution. -.Fa addr -is an address specifying the place where execution is to be resumed (a -new value for the program counter), or -.Li (caddr_t)1 -to indicate that execution is to pick up where it left off. -.Fa data -provides a signal number to be delivered to the traced process as it -resumes execution, or 0 if no signal is to be sent. -.It Dv PT_KILL -The traced process terminates, as if -.Dv PT_CONTINUE -had been used with -.Dv SIGKILL -given as the signal to be delivered. -.It Dv PT_ATTACH -This request allows a process to gain control of an otherwise unrelated -process and begin tracing it. It does not need any cooperation from -the to-be-traced process. In this case, -.Fa pid -specifies the process ID of the to-be-traced process, and the other two -arguments are ignored. This request requires that the target process -must have the same real UID as the tracing process, and that it must -not be executing a setuid or setgid executable. (If the tracing -process is running as root, these restrictions do not apply.) The -tracing process will see the newly-traced process stop and may then -control it as if it had been traced all along. -.It Dv PT_DETACH -This request is like PT_CONTINUE, except that it does not allow -specifying an alternate place to continue execution, and after it -succeeds, the traced process is no longer traced and continues -execution normally. -.El -.Pp -Additionally, machine-specific requests can exist. On the SPARC, these -are: -.Bl -tag -width 12n -.It Dv PT_GETREGS -This request reads the traced process' machine registers into the -.Dq Li "struct reg" -(defined in -.Aq Pa machine/reg.h ) -pointed to by -.Fa addr . -.It Dv PT_SETREGS -This request is the converse of -.Dv PT_GETREGS ; -it loads the traced process' machine registers from the -.Dq Li "struct reg" -(defined in -.Aq Pa machine/reg.h ) -pointed to by -.Fa addr . -.It Dv PT_GETFPREGS -This request reads the traced process' floating-point registers into -the -.Dq Li "struct fpreg" -(defined in -.Aq Pa machine/reg.h ) -pointed to by -.Fa addr . -.It Dv PT_SETFPREGS -This request is the converse of -.Dv PT_GETFPREGS ; -it loads the traced process' floating-point registers from the -.Dq Li "struct fpreg" -(defined in -.Aq Pa machine/reg.h ) -pointed to by -.Fa addr . -.It Dv PT_SYSCALL -This request is like -.Dv PT_CONTINUE -except that the process will stop next time it executes any system -call. Information about the system call can be examined with -.Dv PT_READ_U -and potentially modified with -.Dv PT_WRITE_U -through the -.Li u_kproc.kp_proc.p_md -element of the user structure (see below). If the process is continued -with another -.Dv PT_SYSCALL -request, it will stop again on exit from the syscall, at which point -the return values can be examined and potentially changed. The -.Li u_kproc.kp_proc.p_md -element is of type -.Dq Li "struct mdproc" , -which should be declared by including -.Aq Pa sys/param.h , -.Aq Pa sys/user.h , -and -.Aq Pa machine/proc.h , -and contains the following fields (among others): -.Bl -item -compact -offset indent -.It -.Li syscall_num -.It -.Li syscall_nargs -.It -.Li syscall_args[8] -.It -.Li syscall_err -.It -.Li syscall_rv[2] -.El -When a process stops on entry to a syscall, -.Li syscall_num -holds the number of the syscall, -.Li syscall_nargs -holds the number of arguments it expects, and -.Li syscall_args -holds the arguments themselves. (Only the first -.Li syscall_nargs -elements of -.Li syscall_args -are guaranteed to be useful.) When a process stops on exit from a -syscall, -.Li syscall_num -is -.Eo \& -.Li -1 -.Ec , -.Li syscall_err -holds the error number -.Po -see -.Xr errno 2 -.Pc , -or 0 if no error occurred, and -.Li syscall_rv -holds the return values. (If the syscall returns only one value, only -.Li syscall_rv[0] -is useful.) The tracing process can modify any of these with -.Dv PT_WRITE_U ; -only some modifications are useful. -.Pp -On entry to a syscall, -.Li syscall_num -can be changed, and the syscall actually performed will correspond to -the new number (it is the responsibility of the tracing process to fill -in -.Li syscall_args -appropriately for the new call, but there is no need to modify -.Eo \& -.Li syscall_nargs -.Ec ). -If the new syscall number is 0, no syscall is actually performed; -instead, -.Li syscall_err -and -.Li syscall_rv -are passed back to the traced process directly (and therefore should be -filled in). If the syscall number is otherwise out of range, a dummy -syscall which simply produces an -.Er ENOSYS -error is effectively performed. -.Pp -On exit from a syscall, only -.Li syscall_err -and -.Li syscall_rv -can usefully be changed; they are set to the values returned by the -syscall and will be passed back to the traced process by the normal -syscall return mechanism. -.El -.Sh ERRORS -Some requests can cause -.Fn ptrace -to return -.Li -1 -as a non-error value; to disambiguate, -.Va errno -can be set to 0 before the call and checked afterwards. The possible -errors are: -.Bl -tag -width 4n -.It Bq Er ESRCH -No process having the specified process ID exists. -.It Bq Er EINVAL -.Bl -bullet -compact -.It -A process attempted to use -.Dv PT_ATTACH -on itself. -.It -The -.Fa request -was not one of the legal requests. -.It -The -.Fa addr -to -.Dv PT_READ_U -or -.Dv PT_WRITE_U -was not -.Li int Ns \&-aligned. -.It -The signal number (in -.Fa data ) -to -.Dv PT_CONTINUE -or -.Dv PT_SYSCALL -was neither 0 nor a legal signal number. -.It -.Dv PT_GETREGS , -.Dv PT_SETREGS , -.Dv PT_GETFPREGS , -or -.Dv PT_SETFPREGS -was attempted on a process with no valid register set. (This is -normally true only of system processes.) -.El -.It Bq Er EBUSY -.Bl -bullet -compact -.It -.Dv PT_ATTACH -was attempted on a process that was already being traced. -.It -A request attempted to manipulate a process that was being traced by -some process other than the one making the request. -.It -A request (other than -.Dv PT_ATTACH ) -specified a process that wasn't stopped. -.El -.It Bq Er EPERM -.Bl -bullet -compact -.It -A request (other than -.Dv PT_ATTACH ) -attempted to manipulate a process that wasn't being traced at all. -.It -An attempt was made to use -.Dv PT_ATTACH -on a process in violation of the requirements listed under -.Dv PT_ATTACH -above. -.El -.Sh BUGS -On the SPARC, the PC is set to the provided PC value for -.Dv PT_CONTINUE -and similar calls, but the NPC is set willy-nilly to 4 greater than the -PC value. Using -.Dv PT_GETREGS -and -.Dv PT_SETREGS -to modify the PC, passing -.Li (caddr_t)1 -to -.Eo \& -.Fn ptrace -.Ec , -should be able to sidestep this. -.Pp -Single-stepping is not available. -.Pp -When using -.Dv PT_SYSCALL , -there is no easy way to tell whether the traced process stopped because -it made a syscall or because a signal was sent at a moment that it just -happened to have valid-looking garbage in its -.Dq Li "struct mdproc" . diff --git a/lib/libutil/fparseln.3 b/lib/libutil/fparseln.3 deleted file mode 100644 index a5ea8dbe1ba6..000000000000 --- a/lib/libutil/fparseln.3 +++ /dev/null @@ -1,153 +0,0 @@ -.\" $NetBSD: fparseln.3,v 1.7 1999/07/02 15:49:12 simonb Exp $ -.\" -.\" Copyright (c) 1997 Christos Zoulas. 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 Christos Zoulas. -.\" 4. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. -.\" -.Dd December 1, 1997 -.Dt FPARSELN 3 -.Os -.Sh NAME -.Nm fparseln -.Nd return the next logical line from a stream -.Sh LIBRARY -.Lb libutil -.Sh SYNOPSIS -.Fd #include <util.h> -.Ft "char *" -.Fo "fparseln" -.Fa "FILE *stream" "size_t *len" "size_t *lineno" -.Fa "const char delim[3]" "int flags" -.Fc -.Sh DESCRIPTION -The -.Fn fparseln -function -returns a pointer to the next logical line from the stream referenced by -.Fa stream . -This string is -.Dv NUL -terminated and it is dynamicaly allocated on each invocation. It is the -responsibility of the caller to free the pointer. -.Pp -By default, if a character is escaped, both it and the preceeding escape -character will be present in the returned string. -Various -.Fa flags -alter this behaviour. -.Pp -The meaning of the arguments is as follows: -.Bl -tag -width "lineno" -.It Fa stream -The stream to read from. -.It Fa len -If not -.Dv NULL , -the length of the string is stored in the memory location to which it -points. -.It Fa lineno -If not -.Dv NULL , -the value of the memory location to which is pointed to, is incremented -by the number of lines actually read from the file. -.It Fa delim -Contains the escape, continuation, and comment characters. -If a character is -.Dv NUL -then processing for that character is disabled. -If -.Dv NULL , -all characters default to values specified below. -The contents of -.Fa delim -is as follows: -.Bl -tag -width "delim[0]" -.It Fa delim[0] -The escape character, which defaults to -.Cm \e , -is used to remove any special meaning from the next character. -.It Fa delim[1] -The continuation character, which defaults to -.Cm \e , -is used to indicate that the next line should be concatenated with the -current one if this character is the last character on the current line -and is not escaped. -.It Fa delim[2] -The comment character, which defaults to -.Cm # , -if not escaped indicates the beginning of a comment that extends until the -end of the current line. -.El -.It Fa flags -If non-zero, alter the operation of -.Fn fparseln . -The various flags, which may be -.Em or Ns -ed -together, are: -.Bl -tag -width "FPARSELN_UNESCCOMM" -.It Dv FPARSELN_UNESCCOMM -Remove escape preceeding an escaped comment. -.It Dv FPARSELN_UNESCCONT -Remove escape preceeding an escaped continuation. -.It Dv FPARSELN_UNESCESC -Remove escape preceeding an escaped escape. -.It Dv FPARSELN_UNESCREST -Remove escape preceeding any other character. -.It Dv FPARSELN_UNESCALL -All of the above. -.El -.Pp -.El -.Sh RETURN VALUES -Upon successful completion a pointer to the parsed line is returned; -otherwise, -.Dv NULL -is returned. -.Pp -The -.Fn fparseln -function uses internally -.Xr fgetln 3 , -so all error conditions that apply to -.Xr fgetln 3 , -apply to -.Fn fparseln . -In addition -.Fn fparseln -may set -.Va errno -to -.Bq Er ENOMEM -and return -.Dv NULL -if it runs out of memory. -.Sh SEE ALSO -.Xr fgetln 3 -.Sh HISTORY -The -.Fn fparseln -function first appeared in -.Nx 1.4 . diff --git a/lib/libutil/fparseln.c b/lib/libutil/fparseln.c deleted file mode 100644 index cd4d3ddf3d12..000000000000 --- a/lib/libutil/fparseln.c +++ /dev/null @@ -1,230 +0,0 @@ -/* $NetBSD: fparseln.c,v 1.9 1999/09/20 04:48:06 lukem Exp $ */ - -/* - * Copyright (c) 1997 Christos Zoulas. 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 Christos Zoulas. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -#include <sys/cdefs.h> -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: fparseln.c,v 1.9 1999/09/20 04:48:06 lukem Exp $"); -#endif - -#include <assert.h> -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <util.h> - -static int isescaped __P((const char *, const char *, int)); - -/* isescaped(): - * Return true if the character in *p that belongs to a string - * that starts in *sp, is escaped by the escape character esc. - */ -static int -isescaped(sp, p, esc) - const char *sp, *p; - int esc; -{ - const char *cp; - size_t ne; - - _DIAGASSERT(sp != NULL); - _DIAGASSERT(p != NULL); - - /* No escape character */ - if (esc == '\0') - return 1; - - /* Count the number of escape characters that precede ours */ - for (ne = 0, cp = p; --cp >= sp && *cp == esc; ne++) - continue; - - /* Return true if odd number of escape characters */ - return (ne & 1) != 0; -} - - -/* fparseln(): - * Read a line from a file parsing continuations ending in \ - * and eliminating trailing newlines, or comments starting with - * the comment char. - */ -char * -fparseln(fp, size, lineno, str, flags) - FILE *fp; - size_t *size; - size_t *lineno; - const char str[3]; - int flags; -{ - static const char dstr[3] = { '\\', '\\', '#' }; - - size_t s, len; - char *buf; - char *ptr, *cp; - int cnt; - char esc, con, nl, com; - - _DIAGASSERT(fp != NULL); - - len = 0; - buf = NULL; - cnt = 1; - - if (str == NULL) - str = dstr; - - esc = str[0]; - con = str[1]; - com = str[2]; - /* - * XXX: it would be cool to be able to specify the newline character, - * but unfortunately, fgetln does not let us - */ - nl = '\n'; - - while (cnt) { - cnt = 0; - - if (lineno) - (*lineno)++; - - if ((ptr = fgetln(fp, &s)) == NULL) - break; - - if (s && com) { /* Check and eliminate comments */ - for (cp = ptr; cp < ptr + s; cp++) - if (*cp == com && !isescaped(ptr, cp, esc)) { - s = cp - ptr; - cnt = s == 0 && buf == NULL; - break; - } - } - - if (s && nl) { /* Check and eliminate newlines */ - cp = &ptr[s - 1]; - - if (*cp == nl) - s--; /* forget newline */ - } - - if (s && con) { /* Check and eliminate continuations */ - cp = &ptr[s - 1]; - - if (*cp == con && !isescaped(ptr, cp, esc)) { - s--; /* forget escape */ - cnt = 1; - } - } - - if (s == 0 && buf != NULL) - continue; - - if ((cp = realloc(buf, len + s + 1)) == NULL) { - free(buf); - return NULL; - } - buf = cp; - - (void) memcpy(buf + len, ptr, s); - len += s; - buf[len] = '\0'; - } - - if ((flags & FPARSELN_UNESCALL) != 0 && esc && buf != NULL && - strchr(buf, esc) != NULL) { - ptr = cp = buf; - while (cp[0] != '\0') { - int skipesc; - - while (cp[0] != '\0' && cp[0] != esc) - *ptr++ = *cp++; - if (cp[0] == '\0' || cp[1] == '\0') - break; - - skipesc = 0; - if (cp[1] == com) - skipesc += (flags & FPARSELN_UNESCCOMM); - if (cp[1] == con) - skipesc += (flags & FPARSELN_UNESCCONT); - if (cp[1] == esc) - skipesc += (flags & FPARSELN_UNESCESC); - if (cp[1] != com && cp[1] != con && cp[1] != esc) - skipesc = (flags & FPARSELN_UNESCREST); - - if (skipesc) - cp++; - else - *ptr++ = *cp++; - *ptr++ = *cp++; - } - *ptr = '\0'; - len = strlen(buf); - } - - if (size) - *size = len; - return buf; -} - -#ifdef TEST - -int main __P((int, char **)); - -int -main(argc, argv) - int argc; - char **argv; -{ - char *ptr; - size_t size, line; - - line = 0; - while ((ptr = fparseln(stdin, &size, &line, NULL, - FPARSELN_UNESCALL)) != NULL) - printf("line %d (%d) |%s|\n", line, size, ptr); - return 0; -} - -/* - -# This is a test -line 1 -line 2 \ -line 3 # Comment -line 4 \# Not comment \\\\ - -# And a comment \ -line 5 \\\ -line 6 - -*/ - -#endif /* TEST */ diff --git a/libexec/bootpgw/Makefile b/libexec/bootpgw/Makefile deleted file mode 100644 index a155e0e4f7c3..000000000000 --- a/libexec/bootpgw/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# Makefile -# $Id$ - -PROG= bootpgw -NOMAN= true -SRCS= bootpgw.c getif.c hwaddr.c report.c rtmsg.c - -SRCDIR= ${.CURDIR}/../bootpd -CFLAGS+=-I${SRCDIR} -.PATH: ${SRCDIR} - -.include <bsd.prog.mk> diff --git a/libexec/bootpgw/bootpgw.c b/libexec/bootpgw/bootpgw.c deleted file mode 100644 index 4e7538bb4def..000000000000 --- a/libexec/bootpgw/bootpgw.c +++ /dev/null @@ -1,675 +0,0 @@ -/* - * bootpgw.c - BOOTP GateWay - * This program forwards BOOTP Request packets to a BOOTP server. - */ - -/************************************************************************ - Copyright 1988, 1991 by Carnegie Mellon University - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, provided -that the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation, and that the name of Carnegie Mellon University not be used -in advertising or publicity pertaining to distribution of the software -without specific, written prior permission. - -CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. -IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR -PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS -ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. -************************************************************************/ - -#ifndef lint -static char rcsid[] = "$Id: bootpgw.c,v 1.1.1.1 1994/09/10 14:44:54 csgr Exp $"; -#endif - -/* - * BOOTPGW is typically used to forward BOOTP client requests from - * one subnet to a BOOTP server on a different subnet. - */ - -#include <sys/types.h> -#include <sys/param.h> -#include <sys/socket.h> -#include <sys/ioctl.h> -#include <sys/file.h> -#include <sys/time.h> -#include <sys/stat.h> - -#include <net/if.h> -#include <netinet/in.h> -#include <arpa/inet.h> /* inet_ntoa */ - -#ifndef NO_UNISTD -#include <unistd.h> -#endif -#include <stdlib.h> -#include <signal.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <ctype.h> -#include <netdb.h> -#include <syslog.h> -#include <assert.h> - -#ifdef NO_SETSID -# include <fcntl.h> /* for O_RDONLY, etc */ -#endif - -#ifndef USE_BFUNCS -# include <memory.h> -/* Yes, memcpy is OK here (no overlapped copies). */ -# define bcopy(a,b,c) memcpy(b,a,c) -# define bzero(p,l) memset(p,0,l) -# define bcmp(a,b,c) memcmp(a,b,c) -#endif - -#include "bootp.h" -#include "getif.h" -#include "hwaddr.h" -#include "report.h" -#include "patchlevel.h" - -/* Local definitions: */ -#define MAX_MSG_SIZE (3*512) /* Maximum packet size */ -#define TRUE 1 -#define FALSE 0 -#define get_network_errmsg get_errmsg - - - -/* - * Externals, forward declarations, and global variables - */ - -#ifdef __STDC__ -#define P(args) args -#else -#define P(args) () -#endif - -static void usage P((void)); -static void handle_reply P((void)); -static void handle_request P((void)); - -#undef P - -/* - * IP port numbers for client and server obtained from /etc/services - */ - -u_short bootps_port, bootpc_port; - - -/* - * Internet socket and interface config structures - */ - -struct sockaddr_in bind_addr; /* Listening */ -struct sockaddr_in recv_addr; /* Packet source */ -struct sockaddr_in send_addr; /* destination */ - - -/* - * option defaults - */ -int debug = 0; /* Debugging flag (level) */ -struct timeval actualtimeout = -{ /* fifteen minutes */ - 15 * 60L, /* tv_sec */ - 0 /* tv_usec */ -}; -u_int maxhops = 4; /* Number of hops allowed for requests. */ -u_int minwait = 3; /* Number of seconds client must wait before - its bootrequest packets are forwarded. */ - -/* - * General - */ - -int s; /* Socket file descriptor */ -char *pktbuf; /* Receive packet buffer */ -int pktlen; -char *progname; -char *servername; -int32 server_ipa; /* Real server IP address, network order. */ - -char myhostname[64]; -struct in_addr my_ip_addr; - - - - -/* - * Initialization such as command-line processing is done and then the - * main server loop is started. - */ - -void -main(argc, argv) - int argc; - char **argv; -{ - struct timeval *timeout; - struct bootp *bp; - struct servent *servp; - struct hostent *hep; - char *stmp; - int n, ba_len, ra_len; - int nfound, readfds; - int standalone; - - progname = strrchr(argv[0], '/'); - if (progname) progname++; - else progname = argv[0]; - - /* - * Initialize logging. - */ - report_init(0); /* uses progname */ - - /* - * Log startup - */ - report(LOG_INFO, "version %s.%d", VERSION, PATCHLEVEL); - - /* Debugging for compilers with struct padding. */ - assert(sizeof(struct bootp) == BP_MINPKTSZ); - - /* Get space for receiving packets and composing replies. */ - pktbuf = malloc(MAX_MSG_SIZE); - if (!pktbuf) { - report(LOG_ERR, "malloc failed"); - exit(1); - } - bp = (struct bootp *) pktbuf; - - /* - * Check to see if a socket was passed to us from inetd. - * - * Use getsockname() to determine if descriptor 0 is indeed a socket - * (and thus we are probably a child of inetd) or if it is instead - * something else and we are running standalone. - */ - s = 0; - ba_len = sizeof(bind_addr); - bzero((char *) &bind_addr, ba_len); - errno = 0; - standalone = TRUE; - if (getsockname(s, (struct sockaddr *) &bind_addr, &ba_len) == 0) { - /* - * Descriptor 0 is a socket. Assume we are a child of inetd. - */ - if (bind_addr.sin_family == AF_INET) { - standalone = FALSE; - bootps_port = ntohs(bind_addr.sin_port); - } else { - /* Some other type of socket? */ - report(LOG_INFO, "getsockname: not an INET socket"); - } - } - /* - * Set defaults that might be changed by option switches. - */ - stmp = NULL; - timeout = &actualtimeout; - gethostname(myhostname, sizeof(myhostname)); - hep = gethostbyname(myhostname); - if (!hep) { - printf("Can not get my IP address\n"); - exit(1); - } - bcopy(hep->h_addr, (char *)&my_ip_addr, sizeof(my_ip_addr)); - - /* - * Read switches. - */ - for (argc--, argv++; argc > 0; argc--, argv++) { - if (argv[0][0] != '-') - break; - switch (argv[0][1]) { - - case 'd': /* debug level */ - if (argv[0][2]) { - stmp = &(argv[0][2]); - } else if (argv[1] && argv[1][0] == '-') { - /* - * Backwards-compatible behavior: - * no parameter, so just increment the debug flag. - */ - debug++; - break; - } else { - argc--; - argv++; - stmp = argv[0]; - } - if (!stmp || (sscanf(stmp, "%d", &n) != 1) || (n < 0)) { - fprintf(stderr, - "%s: invalid debug level\n", progname); - break; - } - debug = n; - break; - - case 'h': /* hop count limit */ - if (argv[0][2]) { - stmp = &(argv[0][2]); - } else { - argc--; - argv++; - stmp = argv[0]; - } - if (!stmp || (sscanf(stmp, "%d", &n) != 1) || - (n < 0) || (n > 16)) - { - fprintf(stderr, - "bootpgw: invalid hop count limit\n"); - break; - } - maxhops = (u_int)n; - break; - - case 'i': /* inetd mode */ - standalone = FALSE; - break; - - case 's': /* standalone mode */ - standalone = TRUE; - break; - - case 't': /* timeout */ - if (argv[0][2]) { - stmp = &(argv[0][2]); - } else { - argc--; - argv++; - stmp = argv[0]; - } - if (!stmp || (sscanf(stmp, "%d", &n) != 1) || (n < 0)) { - fprintf(stderr, - "%s: invalid timeout specification\n", progname); - break; - } - actualtimeout.tv_sec = (int32) (60 * n); - /* - * If the actual timeout is zero, pass a NULL pointer - * to select so it blocks indefinitely, otherwise, - * point to the actual timeout value. - */ - timeout = (n > 0) ? &actualtimeout : NULL; - break; - - case 'w': /* wait time */ - if (argv[0][2]) { - stmp = &(argv[0][2]); - } else { - argc--; - argv++; - stmp = argv[0]; - } - if (!stmp || (sscanf(stmp, "%d", &n) != 1) || - (n < 0) || (n > 60)) - { - fprintf(stderr, - "bootpgw: invalid wait time\n"); - break; - } - minwait = (u_int)n; - break; - - default: - fprintf(stderr, "%s: unknown switch: -%c\n", - progname, argv[0][1]); - usage(); - break; - - } /* switch */ - } /* for args */ - - /* Make sure server name argument is suplied. */ - servername = argv[0]; - if (!servername) { - fprintf(stderr, "bootpgw: missing server name\n"); - usage(); - } - /* - * Get address of real bootp server. - */ - if (isdigit(servername[0])) - server_ipa = inet_addr(servername); - else { - hep = gethostbyname(servername); - if (!hep) { - fprintf(stderr, "bootpgw: can't get addr for %s\n", servername); - exit(1); - } - bcopy(hep->h_addr, (char *)&server_ipa, sizeof(server_ipa)); - } - - if (standalone) { - /* - * Go into background and disassociate from controlling terminal. - * XXX - This is not the POSIX way (Should use setsid). -gwr - */ - if (debug < 3) { - if (fork()) - exit(0); -#ifdef NO_SETSID - setpgrp(0,0); -#ifdef TIOCNOTTY - n = open("/dev/tty", O_RDWR); - if (n >= 0) { - ioctl(n, TIOCNOTTY, (char *) 0); - (void) close(n); - } -#endif /* TIOCNOTTY */ -#else /* SETSID */ - if (setsid() < 0) - perror("setsid"); -#endif /* SETSID */ - } /* if debug < 3 */ - /* - * Nuke any timeout value - */ - timeout = NULL; - - /* - * Here, bootpd would do: - * chdir - * tzone_init - * rdtab_init - * readtab - */ - - /* - * Create a socket. - */ - if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - report(LOG_ERR, "socket: %s", get_network_errmsg()); - exit(1); - } - /* - * Get server's listening port number - */ - servp = getservbyname("bootps", "udp"); - if (servp) { - bootps_port = ntohs((u_short) servp->s_port); - } else { - bootps_port = (u_short) IPPORT_BOOTPS; - report(LOG_ERR, - "udp/bootps: unknown service -- assuming port %d", - bootps_port); - } - - /* - * Bind socket to BOOTPS port. - */ - bind_addr.sin_family = AF_INET; - bind_addr.sin_port = htons(bootps_port); - bind_addr.sin_addr.s_addr = INADDR_ANY; - if (bind(s, (struct sockaddr *) &bind_addr, - sizeof(bind_addr)) < 0) - { - report(LOG_ERR, "bind: %s", get_network_errmsg()); - exit(1); - } - } /* if standalone */ - /* - * Get destination port number so we can reply to client - */ - servp = getservbyname("bootpc", "udp"); - if (servp) { - bootpc_port = ntohs(servp->s_port); - } else { - report(LOG_ERR, - "udp/bootpc: unknown service -- assuming port %d", - IPPORT_BOOTPC); - bootpc_port = (u_short) IPPORT_BOOTPC; - } - - /* no signal catchers */ - - /* - * Process incoming requests. - */ - for (;;) { - readfds = 1 << s; - nfound = select(s + 1, (fd_set *)&readfds, NULL, NULL, timeout); - if (nfound < 0) { - if (errno != EINTR) { - report(LOG_ERR, "select: %s", get_errmsg()); - } - continue; - } - if (!(readfds & (1 << s))) { - report(LOG_INFO, "exiting after %ld minutes of inactivity", - actualtimeout.tv_sec / 60); - exit(0); - } - ra_len = sizeof(recv_addr); - n = recvfrom(s, pktbuf, MAX_MSG_SIZE, 0, - (struct sockaddr *) &recv_addr, &ra_len); - if (n <= 0) { - continue; - } - if (debug > 3) { - report(LOG_INFO, "recvd pkt from IP addr %s", - inet_ntoa(recv_addr.sin_addr)); - } - if (n < sizeof(struct bootp)) { - if (debug) { - report(LOG_INFO, "received short packet"); - } - continue; - } - pktlen = n; - - switch (bp->bp_op) { - case BOOTREQUEST: - handle_request(); - break; - case BOOTREPLY: - handle_reply(); - break; - } - } -} - - - - -/* - * Print "usage" message and exit - */ - -static void -usage() -{ - fprintf(stderr, - "usage: bootpgw [-d level] [-i] [-s] [-t timeout] server\n"); - fprintf(stderr, "\t -d n\tset debug level\n"); - fprintf(stderr, "\t -h n\tset max hop count\n"); - fprintf(stderr, "\t -i\tforce inetd mode (run as child of inetd)\n"); - fprintf(stderr, "\t -s\tforce standalone mode (run without inetd)\n"); - fprintf(stderr, "\t -t n\tset inetd exit timeout to n minutes\n"); - fprintf(stderr, "\t -w n\tset min wait time (secs)\n"); - exit(1); -} - - - -/* - * Process BOOTREQUEST packet. - * - * Note, this just forwards the request to a real server. - */ -static void -handle_request() -{ - struct bootp *bp = (struct bootp *) pktbuf; - struct ifreq *ifr; - u_short secs, hops; - - /* XXX - SLIP init: Set bp_ciaddr = recv_addr here? */ - - if (debug) { - report(LOG_INFO, "request from %s", - inet_ntoa(recv_addr.sin_addr)); - } - /* Has the client been waiting long enough? */ - secs = ntohs(bp->bp_secs); - if (secs < minwait) - return; - - /* Has this packet hopped too many times? */ - hops = ntohs(bp->bp_hops); - if (++hops > maxhops) { - report(LOG_NOTICE, "reqest from %s reached hop limit", - inet_ntoa(recv_addr.sin_addr)); - return; - } - bp->bp_hops = htons(hops); - - /* - * Here one might discard a request from the same subnet as the - * real server, but we can assume that the real server will send - * a reply to the client before it waits for minwait seconds. - */ - - /* If gateway address is not set, put in local interface addr. */ - if (bp->bp_giaddr.s_addr == 0) { -#if 0 /* BUG */ - struct sockaddr_in *sip; - /* - * XXX - This picks the wrong interface when the receive addr - * is the broadcast address. There is no portable way to - * find out which interface a broadcast was received on. -gwr - * (Thanks to <walker@zk3.dec.com> for finding this bug!) - */ - ifr = getif(s, &recv_addr.sin_addr); - if (!ifr) { - report(LOG_NOTICE, "no interface for request from %s", - inet_ntoa(recv_addr.sin_addr)); - return; - } - sip = (struct sockaddr_in *) &(ifr->ifr_addr); - bp->bp_giaddr = sip->sin_addr; -#else /* BUG */ - /* - * XXX - Just set "giaddr" to our "official" IP address. - * RFC 1532 says giaddr MUST be set to the address of the - * interface on which the request was received. Setting - * it to our "default" IP address is not strictly correct, - * but is good enough to allow the real BOOTP server to - * get the reply back here. Then, before we forward the - * reply to the client, the giaddr field is corrected. - * (In case the client uses giaddr, which it should not.) - * See handle_reply() - */ - bp->bp_giaddr = my_ip_addr; -#endif /* BUG */ - - /* - * XXX - DHCP says to insert a subnet mask option into the - * options area of the request (if vendor magic == std). - */ - } - /* Set up socket address for send. */ - send_addr.sin_family = AF_INET; - send_addr.sin_port = htons(bootps_port); - send_addr.sin_addr.s_addr = server_ipa; - - /* Send reply with same size packet as request used. */ - if (sendto(s, pktbuf, pktlen, 0, - (struct sockaddr *) &send_addr, - sizeof(send_addr)) < 0) - { - report(LOG_ERR, "sendto: %s", get_network_errmsg()); - } -} - - - -/* - * Process BOOTREPLY packet. - */ -static void -handle_reply() -{ - struct bootp *bp = (struct bootp *) pktbuf; - struct ifreq *ifr; - struct sockaddr_in *sip; - u_char canon_haddr[MAXHADDRLEN]; - unsigned char *ha; - int len; - - if (debug) { - report(LOG_INFO, " reply for %s", - inet_ntoa(bp->bp_yiaddr)); - } - /* Make sure client is directly accessible. */ - ifr = getif(s, &(bp->bp_yiaddr)); - if (!ifr) { - report(LOG_NOTICE, "no interface for reply to %s", - inet_ntoa(bp->bp_yiaddr)); - return; - } -#if 1 /* Experimental (see BUG above) */ -/* #ifdef CATER_TO_OLD_CLIENTS ? */ - /* - * The giaddr field has been set to our "default" IP address - * which might not be on the same interface as the client. - * In case the client looks at giaddr, (which it should not) - * giaddr is now set to the address of the correct interface. - */ - sip = (struct sockaddr_in *) &(ifr->ifr_addr); - bp->bp_giaddr = sip->sin_addr; -#endif - - /* Set up socket address for send to client. */ - send_addr.sin_family = AF_INET; - send_addr.sin_addr = bp->bp_yiaddr; - send_addr.sin_port = htons(bootpc_port); - - /* Create an ARP cache entry for the client. */ - ha = bp->bp_chaddr; - len = bp->bp_hlen; - if (len > MAXHADDRLEN) - len = MAXHADDRLEN; - if (bp->bp_htype == HTYPE_IEEE802) { - haddr_conv802(ha, canon_haddr, len); - ha = canon_haddr; - } - if (debug > 1) - report(LOG_INFO, "setarp %s - %s", - inet_ntoa(bp->bp_yiaddr), haddrtoa(ha, len)); - setarp(s, &bp->bp_yiaddr, ha, len); - - /* Send reply with same size packet as request used. */ - if (sendto(s, pktbuf, pktlen, 0, - (struct sockaddr *) &send_addr, - sizeof(send_addr)) < 0) - { - report(LOG_ERR, "sendto: %s", get_network_errmsg()); - } -} - -/* - * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-argdecl-indent: 4 - * c-continued-statement-offset: 4 - * c-continued-brace-offset: -4 - * c-label-offset: -4 - * c-brace-offset: 0 - * End: - */ diff --git a/libexec/getty/Makefile b/libexec/getty/Makefile deleted file mode 100644 index 7f2eabe6f0d7..000000000000 --- a/libexec/getty/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/4/93 - -PROG= getty -SRCS= main.c init.c subr.c ttydefaults.c -DPADD= ${LIBUTIL} -LDADD= -lutil -MAN5= gettytab.0 ttys.0 -MAN8= getty.0 - -.include <bsd.prog.mk> diff --git a/libexec/getty/extern.h b/libexec/getty/extern.h deleted file mode 100644 index 644f93f10747..000000000000 --- a/libexec/getty/extern.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 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. - * - * @(#)extern.h 8.1 (Berkeley) 6/4/93 - */ - -struct delayval; - -int adelay __P((int, struct delayval *)); -char *autobaud __P((void)); -int delaybits __P((void)); -void edithost __P((char *)); -void gendefaults __P((void)); -int getent __P((char *, char *)); -int getflag __P((char *)); -long getnum __P((char *)); -char *getstr __P((char *, char **)); -void gettable __P((char *, char *)); -void makeenv __P((char *[])); -char *portselector __P((void)); -void set_ttydefaults __P((int)); -void setchars __P((void)); -void setdefaults __P((void)); -long setflags __P((int)); -int speed __P((int)); - -int login_tty __P((int)); /* From libutil. */ diff --git a/libexec/getty/getty.8 b/libexec/getty/getty.8 deleted file mode 100644 index ffd506064046..000000000000 --- a/libexec/getty/getty.8 +++ /dev/null @@ -1,127 +0,0 @@ -.\" Copyright (c) 1980, 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. -.\" -.\" @(#)getty.8 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt GETTY 8 -.Os BSD 4 -.Sh NAME -.Nm getty -.Nd set terminal mode -.Sh SYNOPSIS -.Nm getty -.Oo -.Ar type -.Op Ar tty -.Oc -.Sh DESCRIPTION -The -.Nm getty -program -is called by -.Xr init 8 -to open and initialize the tty line, read a login name, and invoke -.Xr login 1 . -.Pp -The argument -.Ar tty -is the special device file in -.Pa /dev -to open for the terminal (for example, ``ttyh0''). -If there is no argument or the argument is -.Ql Fl , -the tty line is assumed to be open as file descriptor 0. -.Pp -The -.Ar type -argument can be used to make -.Nm getty -treat the terminal line specially. -This argument is used as an index into the -.Nm gettytab 5 -database, to determine the characteristics of the line. -If there is no argument, or there is no such table, the -.Em default -table is used. -If there is no -.Pa /etc/gettytab -a set of system defaults is used. -If indicated by the table located, -.Nm getty -will clear the terminal screen, -print a banner heading, -and prompt for a login name. -Usually either the banner or the login prompt will include -the system hostname. -.Pp -Most of the default actions of -.Nm getty -can be circumvented, or modified, by a suitable -.Nm gettytab -table. -.Pp -The -.Nm getty -program -can be set to timeout after some interval, -which will cause dial up lines to hang up -if the login name is not entered reasonably quickly. -.Sh DIAGNOSTICS -.Bl -diag -.It "ttyxx: No such device or address." -.It "ttyxx: No such file or address." -A terminal which is turned -on in the -.Xr ttys -file cannot be opened, likely because the requisite -lines are either not configured into the system, the associated device -was not attached during boot-time system configuration, -or the special file in -.Pa /dev -does not exist. -.El -.Sh FILES -.Bl -tag -width /etc/gettytab -compact -.It Pa /etc/gettytab -.El -.Sh SEE ALSO -.Xr gettytab 5 , -.Xr init 8 , -.Xr login 1 , -.Xr ioctl 2 , -.Xr tty 4 , -.Xr ttys 5 -.Sh HISTORY -A -.Nm getty -program appeared in -.At v6 . diff --git a/libexec/getty/gettytab.5 b/libexec/getty/gettytab.5 deleted file mode 100644 index e5de06bd976b..000000000000 --- a/libexec/getty/gettytab.5 +++ /dev/null @@ -1,325 +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. -.\" -.\" @(#)gettytab.5 8.5 (Berkeley) 6/1/94 -.\" -.Dd June 1, 1994 -.Dt GETTYTAB 5 -.Os BSD 4.2 -.Sh NAME -.Nm gettytab -.Nd terminal configuration data base -.Sh SYNOPSIS -.Nm gettytab -.Sh DESCRIPTION -The -.Nm gettytab -file -is a simplified version of the -.Xr termcap 5 -data base -used to describe terminal lines. -The initial terminal login process -.Xr getty 8 -accesses the -.Nm gettytab -file each time it starts, allowing simpler -reconfiguration of terminal characteristics. -Each entry in the data base -is used to describe one class of terminals. -.Pp -There is a default terminal class, -.Em default , -that is used to set global defaults for all other classes. -(That is, the -.Em default -entry is read, then the entry for the class required -is used to override particular settings.) -.Sh CAPABILITIES -Refer to -.Xr termcap 5 -for a description of the file layout. -The -.Em default -column below lists defaults obtained if there is -no entry in the table obtained, nor one in the special -.Em default -table. -.Bl -column Namexx /usr/bin/login Default -.It Sy Name Type Default Description -.It "ap bool false terminal uses any parity" -.It "bd num 0 backspace delay" -.It "bk str 0377 alternate end of line character (input break)" -.It "cb bool false use crt backspace mode" -.It "cd num 0 carriage-return delay" -.It "ce bool false use crt erase algorithm" -.It "ck bool false use crt kill algorithm" -.It "cl str" Ta Dv NULL Ta -.No "screen clear sequence" -.It "co bool false console - add" -.Ql \en -after login prompt -.It "ds str" Ta So Li ^Y Sc Ta -.No "delayed suspend character" -.It "dx bool false set" -.Dv DECCTLQ -.It "ec bool false leave echo" -.Tn OFF -.It "ep bool false terminal uses even parity" -.It "er str" Ta So Li ^? Sc Ta -.No "erase character" -.It "et str" Ta So Li ^D Sc Ta -.No "end of text" -.Pq Dv EOF -character -.It "ev str" Ta Dv NULL Ta -.No "initial environment" -.It "f0 num unused tty mode flags to write messages" -.It "f1 num unused tty mode flags to read login name" -.It "f2 num unused tty mode flags to leave terminal as" -.It "fd num 0 form-feed (vertical motion) delay" -.It "fl str" Ta So Li ^O Sc Ta -.No "output flush character" -.It "hc bool false do" -.Tn NOT -hangup line on last close -.It "he str" Ta Dv NULL Ta -.No "hostname editing string" -.It "hn str hostname hostname" -.It "ht bool false terminal has real tabs" -.It "ig bool false ignore garbage characters in login name" -.It "im str" Ta Dv NULL Ta -.No "initial (banner) message" -.It "in str" Ta So Li ^C Sc Ta -.No "interrupt character" -.It "is num unused input speed" -.It "kl str" Ta So Li ^U Sc Ta -.No "kill character" -.It "lc bool false terminal has lower case" -.It "lm str login: login prompt" -.It "ln str" Ta So Li ^V Sc Ta -.No "``literal next'' character" -.It "lo str" Ta Pa /usr/bin/login Ta -.No "program to exec when name obtained" -.It "nd num 0 newline (line-feed) delay" -.It "nl bool false terminal has (or might have) a newline character" -.It "np bool false terminal uses no parity (i.e. 8-bit characters)" -.It "nx str default next table (for auto speed selection)" -.It "op bool false terminal uses odd parity" -.It "os num unused output speed" -.It "pc str" Ta So Li \e0 Sc Ta -.No "pad character" -.It "pe bool false use printer (hard copy) erase algorithm" -.It "pf num 0 delay" -between first prompt and following flush (seconds) -.It "ps bool false line connected to a" -.Tn MICOM -port selector -.It "qu str" Ta So Li \&^\e Sc Ta -.No "quit character" -.It "rp str" Ta So Li ^R Sc Ta -.No "line retype character" -.It "rw bool false do" -.Tn NOT -use raw for input, use cbreak -.It "sp num unused line speed (input and output)" -.It "su str" Ta So Li ^Z Sc Ta -.No "suspend character" -.It "tc str none table continuation" -.It "to num 0 timeout (seconds)" -.It "tt str" Ta Dv NULL Ta -.No "terminal type (for environment)" -.It "ub bool false do unbuffered output (of prompts etc)" -.It "uc bool false terminal is known upper case only" -.It "we str" Ta So Li ^W Sc Ta -.No "word erase character" -.It "xc bool false do -.Tn NOT -echo control chars as -.Ql ^X -.It "xf str" Ta So Li ^S Sc Ta Dv XOFF -(stop output) character -.It "xn str" Ta So Li ^Q Sc Ta Dv XON -(start output) character -.El -.Pp -If no line speed is specified, speed will not be altered -from that which prevails when getty is entered. -Specifying an input or output speed will override -line speed for stated direction only. -.Pp -Terminal modes to be used for the output of the message, -for input of the login name, -and to leave the terminal set as upon completion, -are derived from the boolean flags specified. -If the derivation should prove inadequate, -any (or all) of these three may be overridden -with one of the -.Em \&f0 , -.Em \&f1 , -or -.Em \&f2 -numeric specifications, which can be used to specify -(usually in octal, with a leading '0') -the exact values of the flags. -Local (new tty) flags are set in the top 16 bits -of this (32 bit) value. -.Pp -Should -.Xr getty -receive a null character -(presumed to indicate a line break) -it will restart using the table indicated by the -.Em nx -entry. If there is none, it will re-use its original table. -.Pp -Delays are specified in milliseconds, the nearest possible -delay available in the tty driver will be used. -Should greater certainty be desired, delays -with values 0, 1, 2, and 3 are interpreted as -choosing that particular delay algorithm from the driver. -.Pp -The -.Em \&cl -screen clear string may be preceded by a (decimal) number -of milliseconds of delay required (a la termcap). -This delay is simulated by repeated use of the pad character -.Em \&pc . -.pl -1 -.Pp -The initial message, and login message, -.Em \&im -and -.Em \&lm -may include the character sequence -.Em \&%h -or -.Em \&%t -to obtain -the hostname or tty name respectively. -.Pf ( Em %% -obtains a single '%' character.) -The hostname is normally obtained from the system, -but may be set by the -.Em \&hn -table entry. -In either case it may be edited with -.Em \&he . -The -.Em \&he -string is a sequence of characters, each character that -is neither '@' nor '#' is copied into the final hostname. -A '@' in the -.Em \&he -string, causes one character from the real hostname to -be copied to the final hostname. -A '#' in the -.Em \&he -string, causes the next character of the real hostname -to be skipped. -Surplus '@' and '#' characters are ignored. -.Pp -When getty execs the login process, given -in the -.Em \&lo -string (usually -.Dq Pa /usr/bin/login ) , -it will have set -the environment to include the terminal type, as indicated -by the -.Em \&tt -string (if it exists). -The -.Em \&ev -string, can be used to enter additional data into -the environment. -It is a list of comma separated strings, each of which -will presumably be of the form -.Em name=value . -.Pp -If a non-zero timeout is specified, with -.Em \&to , -then getty will exit within the indicated -number of seconds, either having -received a login name and passed control -to -.Xr login , -or having received an alarm signal, and exited. -This may be useful to hangup dial in lines. -.Pp -Output from -.Xr getty -is even parity unless -.Em \&op -is specified. -The -.Em \&op -string -may be specified with -.Em \&ap -to allow any parity on input, but generate odd parity output. -Note: this only applies while getty is being run, -terminal driver limitations prevent a more complete -implementation. -.Xr Getty -does not check parity of input characters in -.Dv RAW -mode. -.Sh SEE ALSO -.Xr login 1 , -.Xr termcap 5 , -.Xr getty 8 . -.Sh BUGS -The special characters (erase, kill, etc.) are reset to system defaults -by -.Xr login 1 . -In -.Em all -cases, '#' or '^H' typed in a login name will be treated as -an erase character, and '@' will be treated as a kill character. -.Pp -The delay stuff is a real crock. -Apart form its general lack of flexibility, some -of the delay algorithms are not implemented. -The terminal driver should support sane delay settings. -.Pp -The -.Em \&he -capability is stupid. -.Pp -The -.Xr termcap -format is horrid, something more rational should -have been chosen. -.Sh HISTORY -The -.Nm gettytab -file format appeared in 4.2BSD. diff --git a/libexec/getty/gettytab.h b/libexec/getty/gettytab.h deleted file mode 100644 index fb2b14f280d6..000000000000 --- a/libexec/getty/gettytab.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 1983, 1993, 1994 - * 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. - * - * @(#)gettytab.h 8.2 (Berkeley) 3/30/94 - */ - -/* - * Getty description definitions. - */ -struct gettystrs { - char *field; /* name to lookup in gettytab */ - char *defalt; /* value we find by looking in defaults */ - char *value; /* value that we find there */ -}; - -struct gettynums { - char *field; /* name to lookup */ - long defalt; /* number we find in defaults */ - long value; /* number we find there */ - int set; /* we actually got this one */ -}; - -struct gettyflags { - char *field; /* name to lookup */ - char invrt; /* name existing in gettytab --> false */ - char defalt; /* true/false in defaults */ - char value; /* true/false flag */ - char set; /* we found it */ -}; - -/* - * String values. - */ -#define NX gettystrs[0].value -#define CL gettystrs[1].value -#define IM gettystrs[2].value -#define LM gettystrs[3].value -#define ER gettystrs[4].value -#define KL gettystrs[5].value -#define ET gettystrs[6].value -#define PC gettystrs[7].value -#define TT gettystrs[8].value -#define EV gettystrs[9].value -#define LO gettystrs[10].value -#define HN gettystrs[11].value -#define HE gettystrs[12].value -#define IN gettystrs[13].value -#define QU gettystrs[14].value -#define XN gettystrs[15].value -#define XF gettystrs[16].value -#define BK gettystrs[17].value -#define SU gettystrs[18].value -#define DS gettystrs[19].value -#define RP gettystrs[20].value -#define FL gettystrs[21].value -#define WE gettystrs[22].value -#define LN gettystrs[23].value - -/* - * Numeric definitions. - */ -#define IS gettynums[0].value -#define OS gettynums[1].value -#define SP gettynums[2].value -#define ND gettynums[3].value -#define CD gettynums[4].value -#define TD gettynums[5].value -#define FD gettynums[6].value -#define BD gettynums[7].value -#define TO gettynums[8].value -#define F0 gettynums[9].value -#define F0set gettynums[9].set -#define F1 gettynums[10].value -#define F1set gettynums[10].set -#define F2 gettynums[11].value -#define F2set gettynums[11].set -#define PF gettynums[12].value - -/* - * Boolean values. - */ -#define HT gettyflags[0].value -#define NL gettyflags[1].value -#define EP gettyflags[2].value -#define EPset gettyflags[2].set -#define OP gettyflags[3].value -#define OPset gettyflags[3].set -#define AP gettyflags[4].value -#define APset gettyflags[4].set -#define EC gettyflags[5].value -#define CO gettyflags[6].value -#define CB gettyflags[7].value -#define CK gettyflags[8].value -#define CE gettyflags[9].value -#define PE gettyflags[10].value -#define RW gettyflags[11].value -#define XC gettyflags[12].value -#define LC gettyflags[13].value -#define UC gettyflags[14].value -#define IG gettyflags[15].value -#define PS gettyflags[16].value -#define HC gettyflags[17].value -#define UB gettyflags[18].value -#define AB gettyflags[19].value -#define DX gettyflags[20].value -#define NP gettyflags[21].value - -int getent __P((char *, char *)); -long getnum __P((char *)); -int getflag __P((char *)); -char *getstr __P((char *, char **)); - -extern struct gettyflags gettyflags[]; -extern struct gettynums gettynums[]; -extern struct gettystrs gettystrs[]; -extern int hopcount; diff --git a/libexec/getty/init.c b/libexec/getty/init.c deleted file mode 100644 index 835acd753b43..000000000000 --- a/libexec/getty/init.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 1983, 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[] = "@(#)init.c 8.1 (Berkeley) 6/4/93"; -#endif /* not lint */ - -/* - * Getty table initializations. - * - * Melbourne getty. - */ -#include <sgtty.h> -#include "gettytab.h" -#include "pathnames.h" - -extern struct sgttyb tmode; -extern struct tchars tc; -extern struct ltchars ltc; -extern char hostname[]; - -struct gettystrs gettystrs[] = { - { "nx" }, /* next table */ - { "cl" }, /* screen clear characters */ - { "im" }, /* initial message */ - { "lm", "login: " }, /* login message */ - { "er", &tmode.sg_erase }, /* erase character */ - { "kl", &tmode.sg_kill }, /* kill character */ - { "et", &tc.t_eofc }, /* eof chatacter (eot) */ - { "pc", "" }, /* pad character */ - { "tt" }, /* terminal type */ - { "ev" }, /* enviroment */ - { "lo", _PATH_LOGIN }, /* login program */ - { "hn", hostname }, /* host name */ - { "he" }, /* host name edit */ - { "in", &tc.t_intrc }, /* interrupt char */ - { "qu", &tc.t_quitc }, /* quit char */ - { "xn", &tc.t_startc }, /* XON (start) char */ - { "xf", &tc.t_stopc }, /* XOFF (stop) char */ - { "bk", &tc.t_brkc }, /* brk char (alt \n) */ - { "su", <c.t_suspc }, /* suspend char */ - { "ds", <c.t_dsuspc }, /* delayed suspend */ - { "rp", <c.t_rprntc }, /* reprint char */ - { "fl", <c.t_flushc }, /* flush output */ - { "we", <c.t_werasc }, /* word erase */ - { "ln", <c.t_lnextc }, /* literal next */ - { 0 } -}; - -struct gettynums gettynums[] = { - { "is" }, /* input speed */ - { "os" }, /* output speed */ - { "sp" }, /* both speeds */ - { "nd" }, /* newline delay */ - { "cd" }, /* carriage-return delay */ - { "td" }, /* tab delay */ - { "fd" }, /* form-feed delay */ - { "bd" }, /* backspace delay */ - { "to" }, /* timeout */ - { "f0" }, /* output flags */ - { "f1" }, /* input flags */ - { "f2" }, /* user mode flags */ - { "pf" }, /* delay before flush at 1st prompt */ - { 0 } -}; - -struct gettyflags gettyflags[] = { - { "ht", 0 }, /* has tabs */ - { "nl", 1 }, /* has newline char */ - { "ep", 0 }, /* even parity */ - { "op", 0 }, /* odd parity */ - { "ap", 0 }, /* any parity */ - { "ec", 1 }, /* no echo */ - { "co", 0 }, /* console special */ - { "cb", 0 }, /* crt backspace */ - { "ck", 0 }, /* crt kill */ - { "ce", 0 }, /* crt erase */ - { "pe", 0 }, /* printer erase */ - { "rw", 1 }, /* don't use raw */ - { "xc", 1 }, /* don't ^X ctl chars */ - { "lc", 0 }, /* terminal las lower case */ - { "uc", 0 }, /* terminal has no lower case */ - { "ig", 0 }, /* ignore garbage */ - { "ps", 0 }, /* do port selector speed select */ - { "hc", 1 }, /* don't set hangup on close */ - { "ub", 0 }, /* unbuffered output */ - { "ab", 0 }, /* auto-baud detect with '\r' */ - { "dx", 0 }, /* set decctlq */ - { "np", 0 }, /* no parity at all (8bit chars) */ - { 0 } -}; diff --git a/libexec/getty/main.c b/libexec/getty/main.c deleted file mode 100644 index c27ddf40a480..000000000000 --- a/libexec/getty/main.c +++ /dev/null @@ -1,549 +0,0 @@ -/*- - * Copyright (c) 1980, 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 copyright[] = -"@(#) Copyright (c) 1980, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/20/93"; -#endif /* not lint */ - -#define USE_OLD_TTY - -#include <sys/param.h> -#include <sys/stat.h> -#include <sys/resource.h> - -#include <ctype.h> -#include <ctype.h> -#include <fcntl.h> -#include <setjmp.h> -#include <sgtty.h> -#include <signal.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <time.h> -#include <unistd.h> - -#include "gettytab.h" -#include "pathnames.h" -#include "extern.h" - -/* - * Set the amount of running time that getty should accumulate - * before deciding that something is wrong and exit. - */ -#define GETTY_TIMEOUT 60 /* seconds */ - -struct sgttyb tmode = { - 0, 0, CERASE, CKILL, 0 -}; -struct tchars tc = { - CINTR, CQUIT, CSTART, - CSTOP, CEOF, CBRK, -}; -struct ltchars ltc = { - CSUSP, CDSUSP, CRPRNT, - CFLUSH, CWERASE, CLNEXT -}; - -int crmod, digit, lower, upper; - -char hostname[MAXHOSTNAMELEN]; -char name[16]; -char dev[] = _PATH_DEV; -char ttyn[32]; -char *portselector(); -char *ttyname(); - -#define OBUFSIZ 128 -#define TABBUFSIZ 512 - -char defent[TABBUFSIZ]; -char tabent[TABBUFSIZ]; - -char *env[128]; - -char partab[] = { - 0001,0201,0201,0001,0201,0001,0001,0201, - 0202,0004,0003,0205,0005,0206,0201,0001, - 0201,0001,0001,0201,0001,0201,0201,0001, - 0001,0201,0201,0001,0201,0001,0001,0201, - 0200,0000,0000,0200,0000,0200,0200,0000, - 0000,0200,0200,0000,0200,0000,0000,0200, - 0000,0200,0200,0000,0200,0000,0000,0200, - 0200,0000,0000,0200,0000,0200,0200,0000, - 0200,0000,0000,0200,0000,0200,0200,0000, - 0000,0200,0200,0000,0200,0000,0000,0200, - 0000,0200,0200,0000,0200,0000,0000,0200, - 0200,0000,0000,0200,0000,0200,0200,0000, - 0000,0200,0200,0000,0200,0000,0000,0200, - 0200,0000,0000,0200,0000,0200,0200,0000, - 0200,0000,0000,0200,0000,0200,0200,0000, - 0000,0200,0200,0000,0200,0000,0000,0201 -}; - -#define ERASE tmode.sg_erase -#define KILL tmode.sg_kill -#define EOT tc.t_eofc - -jmp_buf timeout; - -static void -dingdong() -{ - - alarm(0); - signal(SIGALRM, SIG_DFL); - longjmp(timeout, 1); -} - -jmp_buf intrupt; - -static void -interrupt() -{ - - signal(SIGINT, interrupt); - longjmp(intrupt, 1); -} - -/* - * Action to take when getty is running too long. - */ -void -timeoverrun(signo) - int signo; -{ - - syslog(LOG_ERR, "getty exiting due to excessive running time\n"); - exit(1); -} - -static int getname __P((void)); -static void oflush __P((void)); -static void prompt __P((void)); -static void putchr __P((int)); -static void putf __P((char *)); -static void putpad __P((char *)); -static void puts __P((char *)); - -int -main(argc, argv) - int argc; - char *argv[]; -{ - extern char **environ; - char *tname; - long allflags; - int repcnt = 0; - struct rlimit limit; - - signal(SIGINT, SIG_IGN); -/* - signal(SIGQUIT, SIG_DFL); -*/ - openlog("getty", LOG_ODELAY|LOG_CONS, LOG_AUTH); - gethostname(hostname, sizeof(hostname)); - if (hostname[0] == '\0') - strcpy(hostname, "Amnesiac"); - - /* - * Limit running time to deal with broken or dead lines. - */ - (void)signal(SIGXCPU, timeoverrun); - limit.rlim_max = RLIM_INFINITY; - limit.rlim_cur = GETTY_TIMEOUT; - (void)setrlimit(RLIMIT_CPU, &limit); - - /* - * The following is a work around for vhangup interactions - * which cause great problems getting window systems started. - * If the tty line is "-", we do the old style getty presuming - * that the file descriptors are already set up for us. - * J. Gettys - MIT Project Athena. - */ - if (argc <= 2 || strcmp(argv[2], "-") == 0) - strcpy(ttyn, ttyname(0)); - else { - int i; - - strcpy(ttyn, dev); - strncat(ttyn, argv[2], sizeof(ttyn)-sizeof(dev)); - if (strcmp(argv[0], "+") != 0) { - chown(ttyn, 0, 0); - chmod(ttyn, 0600); - revoke(ttyn); - /* - * Delay the open so DTR stays down long enough to be detected. - */ - sleep(2); - while ((i = open(ttyn, O_RDWR)) == -1) { - if (repcnt % 10 == 0) { - syslog(LOG_ERR, "%s: %m", ttyn); - closelog(); - } - repcnt++; - sleep(60); - } - login_tty(i); - } - } - - gettable("default", defent); - gendefaults(); - tname = "default"; - if (argc > 1) - tname = argv[1]; - for (;;) { - int off; - - gettable(tname, tabent); - if (OPset || EPset || APset) - APset++, OPset++, EPset++; - setdefaults(); - off = 0; - ioctl(0, TIOCFLUSH, &off); /* clear out the crap */ - ioctl(0, FIONBIO, &off); /* turn off non-blocking mode */ - ioctl(0, FIOASYNC, &off); /* ditto for async mode */ - if (IS) - tmode.sg_ispeed = speed(IS); - else if (SP) - tmode.sg_ispeed = speed(SP); - if (OS) - tmode.sg_ospeed = speed(OS); - else if (SP) - tmode.sg_ospeed = speed(SP); - tmode.sg_flags = setflags(0); - ioctl(0, TIOCSETP, &tmode); - setchars(); - ioctl(0, TIOCSETC, &tc); - if (HC) - ioctl(0, TIOCHPCL, 0); - if (AB) { - extern char *autobaud(); - - tname = autobaud(); - continue; - } - if (PS) { - tname = portselector(); - continue; - } - if (CL && *CL) - putpad(CL); - edithost(HE); - if (IM && *IM) - putf(IM); - if (setjmp(timeout)) { - tmode.sg_ispeed = tmode.sg_ospeed = 0; - ioctl(0, TIOCSETP, &tmode); - exit(1); - } - if (TO) { - signal(SIGALRM, dingdong); - alarm(TO); - } - if (getname()) { - register int i; - - oflush(); - alarm(0); - signal(SIGALRM, SIG_DFL); - if (name[0] == '-') { - puts("user names may not start with '-'."); - continue; - } - if (!(upper || lower || digit)) - continue; - allflags = setflags(2); - tmode.sg_flags = allflags & 0xffff; - allflags >>= 16; - if (crmod || NL) - tmode.sg_flags |= CRMOD; - if (upper || UC) - tmode.sg_flags |= LCASE; - if (lower || LC) - tmode.sg_flags &= ~LCASE; - ioctl(0, TIOCSETP, &tmode); - ioctl(0, TIOCSLTC, <c); - ioctl(0, TIOCLSET, &allflags); - signal(SIGINT, SIG_DFL); - for (i = 0; environ[i] != (char *)0; i++) - env[i] = environ[i]; - makeenv(&env[i]); - - /* - * this is what login was doing anyway. - * soon we rewrite getty completely. - */ - set_ttydefaults(0); - limit.rlim_max = RLIM_INFINITY; - limit.rlim_cur = RLIM_INFINITY; - (void)setrlimit(RLIMIT_CPU, &limit); - execle(LO, "login", "-p", name, (char *) 0, env); - syslog(LOG_ERR, "%s: %m", LO); - exit(1); - } - alarm(0); - signal(SIGALRM, SIG_DFL); - signal(SIGINT, SIG_IGN); - if (NX && *NX) - tname = NX; - } -} - -static int -getname() -{ - register int c; - register char *np; - char cs; - - /* - * Interrupt may happen if we use CBREAK mode - */ - if (setjmp(intrupt)) { - signal(SIGINT, SIG_IGN); - return (0); - } - signal(SIGINT, interrupt); - tmode.sg_flags = setflags(0); - ioctl(0, TIOCSETP, &tmode); - tmode.sg_flags = setflags(1); - prompt(); - if (PF > 0) { - oflush(); - sleep(PF); - PF = 0; - } - ioctl(0, TIOCSETP, &tmode); - crmod = digit = lower = upper = 0; - np = name; - for (;;) { - oflush(); - if (read(STDIN_FILENO, &cs, 1) <= 0) - exit(0); - if ((c = cs&0177) == 0) - return (0); - if (c == EOT) - exit(1); - if (c == '\r' || c == '\n' || np >= &name[sizeof name]) { - putf("\r\n"); - break; - } - if (islower(c)) - lower = 1; - else if (isupper(c)) - upper = 1; - else if (c == ERASE || c == '#' || c == '\b') { - if (np > name) { - np--; - if (tmode.sg_ospeed >= B1200) - puts("\b \b"); - else - putchr(cs); - } - continue; - } else if (c == KILL || c == '@') { - putchr(cs); - putchr('\r'); - if (tmode.sg_ospeed < B1200) - putchr('\n'); - /* this is the way they do it down under ... */ - else if (np > name) - puts(" \r"); - prompt(); - np = name; - continue; - } else if (isdigit(c)) - digit++; - if (IG && (c <= ' ' || c > 0176)) - continue; - *np++ = c; - putchr(cs); - } - signal(SIGINT, SIG_IGN); - *np = 0; - if (c == '\r') - crmod = 1; - if (upper && !lower && !LC || UC) - for (np = name; *np; np++) - if (isupper(*np)) - *np = tolower(*np); - return (1); -} - -static -short tmspc10[] = { - 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5, 15 -}; - -static void -putpad(s) - register char *s; -{ - register pad = 0; - register mspc10; - - if (isdigit(*s)) { - while (isdigit(*s)) { - pad *= 10; - pad += *s++ - '0'; - } - pad *= 10; - if (*s == '.' && isdigit(s[1])) { - pad += s[1] - '0'; - s += 2; - } - } - - puts(s); - /* - * If no delay needed, or output speed is - * not comprehensible, then don't try to delay. - */ - if (pad == 0) - return; - if (tmode.sg_ospeed <= 0 || - tmode.sg_ospeed >= (sizeof tmspc10 / sizeof tmspc10[0])) - return; - - /* - * Round up by a half a character frame, and then do the delay. - * Too bad there are no user program accessible programmed delays. - * Transmitting pad characters slows many terminals down and also - * loads the system. - */ - mspc10 = tmspc10[tmode.sg_ospeed]; - pad += mspc10 / 2; - for (pad /= mspc10; pad > 0; pad--) - putchr(*PC); -} - -static void -puts(s) - register char *s; -{ - while (*s) - putchr(*s++); -} - -char outbuf[OBUFSIZ]; -int obufcnt = 0; - -static void -putchr(cc) - int cc; -{ - char c; - - c = cc; - if (!NP) { - c |= partab[c&0177] & 0200; - if (OP) - c ^= 0200; - } - if (!UB) { - outbuf[obufcnt++] = c; - if (obufcnt >= OBUFSIZ) - oflush(); - } else - write(STDOUT_FILENO, &c, 1); -} - -static void -oflush() -{ - if (obufcnt) - write(STDOUT_FILENO, outbuf, obufcnt); - obufcnt = 0; -} - -static void -prompt() -{ - - putf(LM); - if (CO) - putchr('\n'); -} - -static void -putf(cp) - register char *cp; -{ - extern char editedhost[]; - time_t t; - char *slash, db[100]; - - while (*cp) { - if (*cp != '%') { - putchr(*cp++); - continue; - } - switch (*++cp) { - - case 't': - slash = strrchr(ttyn, '/'); - if (slash == (char *) 0) - puts(ttyn); - else - puts(&slash[1]); - break; - - case 'h': - puts(editedhost); - break; - - case 'd': { - static char fmt[] = "%l:% %P on %A, %d %B %Y"; - - fmt[4] = 'M'; /* I *hate* SCCS... */ - (void)time(&t); - (void)strftime(db, sizeof(db), fmt, localtime(&t)); - puts(db); - break; - } - - case '%': - putchr('%'); - break; - } - cp++; - } -} diff --git a/libexec/getty/pathnames.h b/libexec/getty/pathnames.h deleted file mode 100644 index 714a9ccc35bf..000000000000 --- a/libexec/getty/pathnames.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 1989, 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. - * - * @(#)pathnames.h 8.1 (Berkeley) 6/4/93 - */ - -#include <paths.h> - -#define _PATH_GETTYTAB "/etc/gettytab" -#define _PATH_LOGIN "/usr/bin/login" diff --git a/libexec/getty/subr.c b/libexec/getty/subr.c deleted file mode 100644 index 4a2abb3ded41..000000000000 --- a/libexec/getty/subr.c +++ /dev/null @@ -1,531 +0,0 @@ -/* - * Copyright (c) 1983, 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[] = "@(#)subr.c 8.1 (Berkeley) 6/4/93"; -#endif /* not lint */ - -/* - * Melbourne getty. - */ -#define USE_OLD_TTY -#include <stdlib.h> -#include <sgtty.h> -#include <string.h> -#include <unistd.h> - -#include "gettytab.h" -#include "extern.h" -#include "pathnames.h" - -extern struct sgttyb tmode; -extern struct tchars tc; -extern struct ltchars ltc; - -/* - * Get a table entry. - */ -void -gettable(name, buf) - char *name, *buf; -{ - register struct gettystrs *sp; - register struct gettynums *np; - register struct gettyflags *fp; - long n; - char *dba[2]; - dba[0] = _PATH_GETTYTAB; - dba[1] = 0; - - if (cgetent(&buf, dba, name) != 0) - return; - - for (sp = gettystrs; sp->field; sp++) - cgetstr(buf, sp->field, &sp->value); - for (np = gettynums; np->field; np++) { - if (cgetnum(buf, np->field, &n) == -1) - np->set = 0; - else { - np->set = 1; - np->value = n; - } - } - for (fp = gettyflags; fp->field; fp++) { - if (cgetcap(buf, fp->field, ':') == NULL) - fp->set = 0; - else { - fp->set = 1; - fp->value = 1 ^ fp->invrt; - } - } -#ifdef DEBUG - printf("name=\"%s\", buf=\"%s\"\n", name, buf); - for (sp = gettystrs; sp->field; sp++) - printf("cgetstr: %s=%s\n", sp->field, sp->value); - for (np = gettynums; np->field; np++) - printf("cgetnum: %s=%d\n", np->field, np->value); - for (fp = gettyflags; fp->field; fp++) - printf("cgetflags: %s='%c' set='%c'\n", fp->field, - fp->value + '0', fp->set + '0'); - exit(1); -#endif /* DEBUG */ -} - -void -gendefaults() -{ - register struct gettystrs *sp; - register struct gettynums *np; - register struct gettyflags *fp; - - for (sp = gettystrs; sp->field; sp++) - if (sp->value) - sp->defalt = sp->value; - for (np = gettynums; np->field; np++) - if (np->set) - np->defalt = np->value; - for (fp = gettyflags; fp->field; fp++) - if (fp->set) - fp->defalt = fp->value; - else - fp->defalt = fp->invrt; -} - -void -setdefaults() -{ - register struct gettystrs *sp; - register struct gettynums *np; - register struct gettyflags *fp; - - for (sp = gettystrs; sp->field; sp++) - if (!sp->value) - sp->value = sp->defalt; - for (np = gettynums; np->field; np++) - if (!np->set) - np->value = np->defalt; - for (fp = gettyflags; fp->field; fp++) - if (!fp->set) - fp->value = fp->defalt; -} - -static char ** -charnames[] = { - &ER, &KL, &IN, &QU, &XN, &XF, &ET, &BK, - &SU, &DS, &RP, &FL, &WE, &LN, 0 -}; - -static char * -charvars[] = { - &tmode.sg_erase, &tmode.sg_kill, &tc.t_intrc, - &tc.t_quitc, &tc.t_startc, &tc.t_stopc, - &tc.t_eofc, &tc.t_brkc, <c.t_suspc, - <c.t_dsuspc, <c.t_rprntc, <c.t_flushc, - <c.t_werasc, <c.t_lnextc, 0 -}; - -void -setchars() -{ - register int i; - register char *p; - - for (i = 0; charnames[i]; i++) { - p = *charnames[i]; - if (p && *p) - *charvars[i] = *p; - else - *charvars[i] = '\377'; - } -} - -long -setflags(n) - int n; -{ - register long f; - - switch (n) { - case 0: - if (F0set) - return(F0); - break; - case 1: - if (F1set) - return(F1); - break; - default: - if (F2set) - return(F2); - break; - } - - f = 0; - - if (AP) - f |= ANYP; - else if (OP) - f |= ODDP; - else if (EP) - f |= EVENP; - - if (UC) - f |= LCASE; - - if (NL) - f |= CRMOD; - - f |= delaybits(); - - if (n == 1) { /* read mode flags */ - if (RW) - f |= RAW; - else - f |= CBREAK; - return (f); - } - - if (!HT) - f |= XTABS; - - if (n == 0) - return (f); - - if (CB) - f |= CRTBS; - - if (CE) - f |= CRTERA; - - if (CK) - f |= CRTKIL; - - if (PE) - f |= PRTERA; - - if (EC) - f |= ECHO; - - if (XC) - f |= CTLECH; - - if (DX) - f |= DECCTQ; - - return (f); -} - -struct delayval { - unsigned delay; /* delay in ms */ - int bits; -}; - -/* - * below are random guesses, I can't be bothered checking - */ - -struct delayval crdelay[] = { - { 1, CR1 }, - { 2, CR2 }, - { 3, CR3 }, - { 83, CR1 }, - { 166, CR2 }, - { 0, CR3 }, -}; - -struct delayval nldelay[] = { - { 1, NL1 }, /* special, calculated */ - { 2, NL2 }, - { 3, NL3 }, - { 100, NL2 }, - { 0, NL3 }, -}; - -struct delayval bsdelay[] = { - { 1, BS1 }, - { 0, 0 }, -}; - -struct delayval ffdelay[] = { - { 1, FF1 }, - { 1750, FF1 }, - { 0, FF1 }, -}; - -struct delayval tbdelay[] = { - { 1, TAB1 }, - { 2, TAB2 }, - { 3, XTABS }, /* this is expand tabs */ - { 100, TAB1 }, - { 0, TAB2 }, -}; - -int -delaybits() -{ - register int f; - - f = adelay(CD, crdelay); - f |= adelay(ND, nldelay); - f |= adelay(FD, ffdelay); - f |= adelay(TD, tbdelay); - f |= adelay(BD, bsdelay); - return (f); -} - -int -adelay(ms, dp) - register ms; - register struct delayval *dp; -{ - if (ms == 0) - return (0); - while (dp->delay && ms > dp->delay) - dp++; - return (dp->bits); -} - -char editedhost[32]; - -void -edithost(pat) - register char *pat; -{ - register char *host = HN; - register char *res = editedhost; - - if (!pat) - pat = ""; - while (*pat) { - switch (*pat) { - - case '#': - if (*host) - host++; - break; - - case '@': - if (*host) - *res++ = *host++; - break; - - default: - *res++ = *pat; - break; - - } - if (res == &editedhost[sizeof editedhost - 1]) { - *res = '\0'; - return; - } - pat++; - } - if (*host) - strncpy(res, host, sizeof editedhost - (res - editedhost) - 1); - else - *res = '\0'; - editedhost[sizeof editedhost - 1] = '\0'; -} - -struct speedtab { - int speed; - int uxname; -} speedtab[] = { - { 50, B50 }, - { 75, B75 }, - { 110, B110 }, - { 134, B134 }, - { 150, B150 }, - { 200, B200 }, - { 300, B300 }, - { 600, B600 }, - { 1200, B1200 }, - { 1800, B1800 }, - { 2400, B2400 }, - { 4800, B4800 }, - { 9600, B9600 }, - { 19200, EXTA }, - { 19, EXTA }, /* for people who say 19.2K */ - { 38400, EXTB }, - { 38, EXTB }, - { 7200, EXTB }, /* alternative */ - { 0 } -}; - -int -speed(val) - int val; -{ - register struct speedtab *sp; - - if (val <= 15) - return (val); - - for (sp = speedtab; sp->speed; sp++) - if (sp->speed == val) - return (sp->uxname); - - return (B300); /* default in impossible cases */ -} - -void -makeenv(env) - char *env[]; -{ - static char termbuf[128] = "TERM="; - register char *p, *q; - register char **ep; - - ep = env; - if (TT && *TT) { - strcat(termbuf, TT); - *ep++ = termbuf; - } - if (p = EV) { - q = p; - while (q = strchr(q, ',')) { - *q++ = '\0'; - *ep++ = p; - p = q; - } - if (*p) - *ep++ = p; - } - *ep = (char *)0; -} - -/* - * This speed select mechanism is written for the Develcon DATASWITCH. - * The Develcon sends a string of the form "B{speed}\n" at a predefined - * baud rate. This string indicates the user's actual speed. - * The routine below returns the terminal type mapped from derived speed. - */ -struct portselect { - char *ps_baud; - char *ps_type; -} portspeeds[] = { - { "B110", "std.110" }, - { "B134", "std.134" }, - { "B150", "std.150" }, - { "B300", "std.300" }, - { "B600", "std.600" }, - { "B1200", "std.1200" }, - { "B2400", "std.2400" }, - { "B4800", "std.4800" }, - { "B9600", "std.9600" }, - { "B19200", "std.19200" }, - { 0 } -}; - -char * -portselector() -{ - char c, baud[20], *type = "default"; - register struct portselect *ps; - int len; - - alarm(5*60); - for (len = 0; len < sizeof (baud) - 1; len++) { - if (read(STDIN_FILENO, &c, 1) <= 0) - break; - c &= 0177; - if (c == '\n' || c == '\r') - break; - if (c == 'B') - len = 0; /* in case of leading garbage */ - baud[len] = c; - } - baud[len] = '\0'; - for (ps = portspeeds; ps->ps_baud; ps++) - if (strcmp(ps->ps_baud, baud) == 0) { - type = ps->ps_type; - break; - } - sleep(2); /* wait for connection to complete */ - return (type); -} - -/* - * This auto-baud speed select mechanism is written for the Micom 600 - * portselector. Selection is done by looking at how the character '\r' - * is garbled at the different speeds. - */ -#include <sys/time.h> - -char * -autobaud() -{ - int rfds; - struct timeval timeout; - char c, *type = "9600-baud"; - int null = 0; - - ioctl(0, TIOCFLUSH, &null); - rfds = 1 << 0; - timeout.tv_sec = 5; - timeout.tv_usec = 0; - if (select(32, (fd_set *)&rfds, (fd_set *)NULL, - (fd_set *)NULL, &timeout) <= 0) - return (type); - if (read(STDIN_FILENO, &c, sizeof(char)) != sizeof(char)) - return (type); - timeout.tv_sec = 0; - timeout.tv_usec = 20; - (void) select(32, (fd_set *)NULL, (fd_set *)NULL, - (fd_set *)NULL, &timeout); - ioctl(0, TIOCFLUSH, &null); - switch (c & 0377) { - - case 0200: /* 300-baud */ - type = "300-baud"; - break; - - case 0346: /* 1200-baud */ - type = "1200-baud"; - break; - - case 015: /* 2400-baud */ - case 0215: - type = "2400-baud"; - break; - - default: /* 4800-baud */ - type = "4800-baud"; - break; - - case 0377: /* 9600-baud */ - type = "9600-baud"; - break; - } - return (type); -} diff --git a/libexec/getty/ttys.5 b/libexec/getty/ttys.5 deleted file mode 100644 index cbbdbb67253c..000000000000 --- a/libexec/getty/ttys.5 +++ /dev/null @@ -1,139 +0,0 @@ -.\" Copyright (c) 1985, 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. -.\" -.\" @(#)ttys.5 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt TTYS 5 -.Os -.Sh NAME -.Nm ttys -.Nd terminal initialization information -.Sh DESCRIPTION -The file -.Nm ttys -contains information that is used by various routines to initialize -and control the use of terminal special files. -This information is read with the -.Xr getttyent 3 -library routines. -There is one line in the -.Nm ttys -file per special device file. -Fields are separated by tabs and/or spaces. -Fields comprised of more than one word should be enclosed in double -quotes (``"''). -Blank lines and comments may appear anywhere in the file; comments -are delimited by hash marks (``#'') and new lines. -Any unspecified fields will default to null. -.Pp -The first field is the -name of the terminal special file as it is found in -.Pa /dev . -.Pp -The second field of the file is the command to execute for the line, -usually -.Xr getty 8 , -which initializes and opens the line, setting the speed, waiting for -a user name and executing the -.Xr login 1 -program. -It can be, however, any desired command, for example -the start up for a window system terminal emulator or some other -daemon process, and can contain multiple words if quoted. -.Pp -The third field is the type of terminal usually connected to that -tty line, normally the one found in the -.Xr termcap 5 -data base file. -The environment variable -.Dv TERM -is initialized with the value by -either -.Xr getty 8 -or -.Xr login 1 . -.Pp -The remaining fields set flags in the -.Fa ty_status -entry (see -.Xr getttyent 3 ) -or specify a window system process that -.Xr init 8 -will maintain for the terminal line. -.Pp -As flag values, the strings ``on'' and ``off'' specify that -.Xr init -should (should not) execute the command given in the second field, -while ``secure'' (if ``on'' is also specified) allows users with a -uid of 0 to login on -this line. -These flag fields should not be quoted. -.Pp -The string ``window='' may be followed by a quoted command -string which -.Xr init -will execute -.Em before -starting the command specified by the second field. -.Sh EXAMPLES -.Bd -literal -# root login on console at 1200 baud -console "/usr/libexec/getty std.1200" vt100 on secure -# dialup at 1200 baud, no root logins -ttyd0 "/usr/libexec/getty d1200" dialup on # 555-1234 -# Mike's terminal: hp2621 -ttyh0 "/usr/libexec/getty std.9600" hp2621-nl on # 457 Evans -# John's terminal: vt100 -ttyh1 "/usr/libexec/getty std.9600" vt100 on # 459 Evans -# terminal emulate/window system -ttyv0 "/usr/new/xterm -L :0" vs100 on window="/usr/new/Xvs100 0" -# Network pseudo ttys -- don't enable getty -ttyp0 none network -ttyp1 none network off -.Ed -.Sh FILES -.Bl -tag -width /etc/ttys -compact -.It Pa /etc/ttys -.El -.Sh SEE ALSO -.Xr login 1 , -.Xr getttyent 3 , -.Xr ttyslot 3 , -.Xr gettytab 5 , -.Xr termcap 5 , -.Xr getty 8 , -.Xr init 8 -.Sh HISTORY -A -.Nm -file appeared in -.At v6 . diff --git a/libexec/rbootd/Makefile b/libexec/rbootd/Makefile deleted file mode 100644 index 6e377fc51d8a..000000000000 --- a/libexec/rbootd/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/4/93 - -PROG= rbootd -SRCS= bpf.c conf.c parseconf.c rbootd.c rmpproto.c utils.c -MAN8= rbootd.0 - -afterinstall: - (cd ${.CURDIR}/bootdir && install -c -o ${BINOWN} -g ${BINGRP} \ - -m 444 * ${DESTDIR}/usr/mdec/) - -.include <bsd.prog.mk> diff --git a/libexec/rbootd/bpf.c b/libexec/rbootd/bpf.c deleted file mode 100644 index 7ecd41957a32..000000000000 --- a/libexec/rbootd/bpf.c +++ /dev/null @@ -1,422 +0,0 @@ -/* - * Copyright (c) 1988, 1992 The University of Utah and the Center - * for Software Science (CSS). - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Center for Software Science of the University of Utah Computer - * Science Department. CSS requests users of this software to return - * to css-dist@cs.utah.edu any improvements that they make and grant - * CSS redistribution rights. - * - * 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. - * - * @(#)bpf.c 8.1 (Berkeley) 6/4/93 - * - * Utah $Hdr: bpf.c 3.1 92/07/06$ - * Author: Jeff Forys, University of Utah CSS - */ - -#ifndef lint -static char sccsid[] = "@(#)bpf.c 8.1 (Berkeley) 6/4/93"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/ioctl.h> -#include <sys/socket.h> - -#include <net/if.h> -#include <net/bpf.h> - -#include <ctype.h> -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <unistd.h> -#include "defs.h" -#include "pathnames.h" - -static int BpfFd = -1; -static unsigned BpfLen = 0; -static u_char *BpfPkt = NULL; - -/* -** BpfOpen -- Open and initialize a BPF device. -** -** Parameters: -** None. -** -** Returns: -** File descriptor of opened BPF device (for select() etc). -** -** Side Effects: -** If an error is encountered, the program terminates here. -*/ -int -BpfOpen() -{ - struct ifreq ifr; - char bpfdev[32]; - int n = 0; - - /* - * Open the first available BPF device. - */ - do { - (void) sprintf(bpfdev, _PATH_BPF, n++); - BpfFd = open(bpfdev, O_RDWR); - } while (BpfFd < 0 && (errno == EBUSY || errno == EPERM)); - - if (BpfFd < 0) { - syslog(LOG_ERR, "bpf: no available devices: %m"); - Exit(0); - } - - /* - * Set interface name for bpf device, get data link layer - * type and make sure it's type Ethernet. - */ - (void) strncpy(ifr.ifr_name, IntfName, sizeof(ifr.ifr_name)); - if (ioctl(BpfFd, BIOCSETIF, (caddr_t)&ifr) < 0) { - syslog(LOG_ERR, "bpf: ioctl(BIOCSETIF,%s): %m", IntfName); - Exit(0); - } - - /* - * Make sure we are dealing with an Ethernet device. - */ - if (ioctl(BpfFd, BIOCGDLT, (caddr_t)&n) < 0) { - syslog(LOG_ERR, "bpf: ioctl(BIOCGDLT): %m"); - Exit(0); - } - if (n != DLT_EN10MB) { - syslog(LOG_ERR,"bpf: %s: data-link type %d unsupported", - IntfName, n); - Exit(0); - } - - /* - * On read(), return packets immediately (do not buffer them). - */ - n = 1; - if (ioctl(BpfFd, BIOCIMMEDIATE, (caddr_t)&n) < 0) { - syslog(LOG_ERR, "bpf: ioctl(BIOCIMMEDIATE): %m"); - Exit(0); - } - - /* - * Try to enable the chip/driver's multicast address filter to - * grab our RMP address. If this fails, try promiscuous mode. - * If this fails, there's no way we are going to get any RMP - * packets so just exit here. - */ -#ifdef MSG_EOR - ifr.ifr_addr.sa_len = RMP_ADDRLEN + 2; -#endif - ifr.ifr_addr.sa_family = AF_UNSPEC; - bcopy(&RmpMcastAddr[0], (char *)&ifr.ifr_addr.sa_data[0], RMP_ADDRLEN); - if (ioctl(BpfFd, SIOCADDMULTI, (caddr_t)&ifr) < 0) { - syslog(LOG_WARNING, - "bpf: can't add mcast addr (%m), setting promiscuous mode"); - - if (ioctl(BpfFd, BIOCPROMISC, (caddr_t)0) < 0) { - syslog(LOG_ERR, "bpf: can't set promiscuous mode: %m"); - Exit(0); - } - } - - /* - * Ask BPF how much buffer space it requires and allocate one. - */ - if (ioctl(BpfFd, BIOCGBLEN, (caddr_t)&BpfLen) < 0) { - syslog(LOG_ERR, "bpf: ioctl(BIOCGBLEN): %m"); - Exit(0); - } - if (BpfPkt == NULL) - BpfPkt = (u_char *)malloc(BpfLen); - - if (BpfPkt == NULL) { - syslog(LOG_ERR, "bpf: out of memory (%u bytes for bpfpkt)", - BpfLen); - Exit(0); - } - - /* - * Write a little program to snarf RMP Boot packets and stuff - * it down BPF's throat (i.e. set up the packet filter). - */ - { -#define RMP ((struct rmp_packet *)0) - static struct bpf_insn bpf_insn[] = { - { BPF_LD|BPF_B|BPF_ABS, 0, 0, (long)&RMP->hp_llc.dsap }, - { BPF_JMP|BPF_JEQ|BPF_K, 0, 5, IEEE_DSAP_HP }, - { BPF_LD|BPF_H|BPF_ABS, 0, 0, (long)&RMP->hp_llc.cntrl }, - { BPF_JMP|BPF_JEQ|BPF_K, 0, 3, IEEE_CNTL_HP }, - { BPF_LD|BPF_H|BPF_ABS, 0, 0, (long)&RMP->hp_llc.dxsap }, - { BPF_JMP|BPF_JEQ|BPF_K, 0, 1, HPEXT_DXSAP }, - { BPF_RET|BPF_K, 0, 0, RMP_MAX_PACKET }, - { BPF_RET|BPF_K, 0, 0, 0x0 } - }; -#undef RMP - static struct bpf_program bpf_pgm = { - sizeof(bpf_insn)/sizeof(bpf_insn[0]), bpf_insn - }; - - if (ioctl(BpfFd, BIOCSETF, (caddr_t)&bpf_pgm) < 0) { - syslog(LOG_ERR, "bpf: ioctl(BIOCSETF): %m"); - Exit(0); - } - } - - return(BpfFd); -} - -/* -** BPF GetIntfName -- Return the name of a network interface attached to -** the system, or 0 if none can be found. The interface -** must be configured up; the lowest unit number is -** preferred; loopback is ignored. -** -** Parameters: -** errmsg - if no network interface found, *errmsg explains why. -** -** Returns: -** A (static) pointer to interface name, or NULL on error. -** -** Side Effects: -** None. -*/ -char * -BpfGetIntfName(errmsg) - char **errmsg; -{ - struct ifreq ibuf[8], *ifrp, *ifend, *mp; - struct ifconf ifc; - int fd; - int minunit, n; - char *cp; - static char device[sizeof(ifrp->ifr_name)]; - static char errbuf[128] = "No Error!"; - - if (errmsg != NULL) - *errmsg = errbuf; - - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - (void) strcpy(errbuf, "bpf: socket: %m"); - return(NULL); - } - ifc.ifc_len = sizeof ibuf; - ifc.ifc_buf = (caddr_t)ibuf; - -#ifdef OSIOCGIFCONF - if (ioctl(fd, OSIOCGIFCONF, (char *)&ifc) < 0 || - ifc.ifc_len < sizeof(struct ifreq)) { - (void) strcpy(errbuf, "bpf: ioctl(OSIOCGIFCONF): %m"); - return(NULL); - } -#else - if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0 || - ifc.ifc_len < sizeof(struct ifreq)) { - (void) strcpy(errbuf, "bpf: ioctl(SIOCGIFCONF): %m"); - return(NULL); - } -#endif - ifrp = ibuf; - ifend = (struct ifreq *)((char *)ibuf + ifc.ifc_len); - - mp = 0; - minunit = 666; - for (; ifrp < ifend; ++ifrp) { - if (ioctl(fd, SIOCGIFFLAGS, (char *)ifrp) < 0) { - (void) strcpy(errbuf, "bpf: ioctl(SIOCGIFFLAGS): %m"); - return(NULL); - } - - /* - * If interface is down or this is the loopback interface, - * ignore it. - */ - if ((ifrp->ifr_flags & IFF_UP) == 0 || -#ifdef IFF_LOOPBACK - (ifrp->ifr_flags & IFF_LOOPBACK)) -#else - (strcmp(ifrp->ifr_name, "lo0") == 0)) -#endif - continue; - - for (cp = ifrp->ifr_name; !isdigit(*cp); ++cp) - ; - n = atoi(cp); - if (n < minunit) { - minunit = n; - mp = ifrp; - } - } - - (void) close(fd); - if (mp == 0) { - (void) strcpy(errbuf, "bpf: no interfaces found"); - return(NULL); - } - - (void) strcpy(device, mp->ifr_name); - return(device); -} - -/* -** BpfRead -- Read packets from a BPF device and fill in `rconn'. -** -** Parameters: -** rconn - filled in with next packet. -** doread - is True if we can issue a read() syscall. -** -** Returns: -** True if `rconn' contains a new packet, False otherwise. -** -** Side Effects: -** None. -*/ -int -BpfRead(rconn, doread) - RMPCONN *rconn; - int doread; -{ - register int datlen, caplen, hdrlen; - static u_char *bp = NULL, *ep = NULL; - int cc; - - /* - * The read() may block, or it may return one or more packets. - * We let the caller decide whether or not we can issue a read(). - */ - if (doread) { - if ((cc = read(BpfFd, (char *)BpfPkt, (int)BpfLen)) < 0) { - syslog(LOG_ERR, "bpf: read: %m"); - return(0); - } else { - bp = BpfPkt; - ep = BpfPkt + cc; - } - } - -#define bhp ((struct bpf_hdr *)bp) - /* - * If there is a new packet in the buffer, stuff it into `rconn' - * and return a success indication. - */ - if (bp < ep) { - datlen = bhp->bh_datalen; - caplen = bhp->bh_caplen; - hdrlen = bhp->bh_hdrlen; - - if (caplen != datlen) - syslog(LOG_ERR, - "bpf: short packet dropped (%d of %d bytes)", - caplen, datlen); - else if (caplen > sizeof(struct rmp_packet)) - syslog(LOG_ERR, "bpf: large packet dropped (%d bytes)", - caplen); - else { - rconn->rmplen = caplen; - bcopy((char *)&bhp->bh_tstamp, (char *)&rconn->tstamp, - sizeof(struct timeval)); - bcopy((char *)bp + hdrlen, (char *)&rconn->rmp, caplen); - } - bp += BPF_WORDALIGN(caplen + hdrlen); - return(1); - } -#undef bhp - - return(0); -} - -/* -** BpfWrite -- Write packet to BPF device. -** -** Parameters: -** rconn - packet to send. -** -** Returns: -** True if write succeeded, False otherwise. -** -** Side Effects: -** None. -*/ -int -BpfWrite(rconn) - RMPCONN *rconn; -{ - if (write(BpfFd, (char *)&rconn->rmp, rconn->rmplen) < 0) { - syslog(LOG_ERR, "write: %s: %m", EnetStr(rconn)); - return(0); - } - - return(1); -} - -/* -** BpfClose -- Close a BPF device. -** -** Parameters: -** None. -** -** Returns: -** Nothing. -** -** Side Effects: -** None. -*/ -void -BpfClose() -{ - struct ifreq ifr; - - if (BpfPkt != NULL) { - free((char *)BpfPkt); - BpfPkt = NULL; - } - - if (BpfFd == -1) - return; - -#ifdef MSG_EOR - ifr.ifr_addr.sa_len = RMP_ADDRLEN + 2; -#endif - ifr.ifr_addr.sa_family = AF_UNSPEC; - bcopy(&RmpMcastAddr[0], (char *)&ifr.ifr_addr.sa_data[0], RMP_ADDRLEN); - if (ioctl(BpfFd, SIOCDELMULTI, (caddr_t)&ifr) < 0) - (void) ioctl(BpfFd, BIOCPROMISC, (caddr_t)0); - - (void) close(BpfFd); - BpfFd = -1; -} diff --git a/libexec/rbootd/conf.c b/libexec/rbootd/conf.c deleted file mode 100644 index b890eeadae7c..000000000000 --- a/libexec/rbootd/conf.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 1988, 1992 The University of Utah and the Center - * for Software Science (CSS). - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Center for Software Science of the University of Utah Computer - * Science Department. CSS requests users of this software to return - * to css-dist@cs.utah.edu any improvements that they make and grant - * CSS redistribution rights. - * - * 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. - * - * @(#)conf.c 8.1 (Berkeley) 6/4/93 - * - * Utah $Hdr: conf.c 3.1 92/07/06$ - * Author: Jeff Forys, University of Utah CSS - */ - -#ifndef lint -static char sccsid[] = "@(#)conf.c 8.1 (Berkeley) 6/4/93"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/time.h> - -#include <stdio.h> -#include "defs.h" -#include "pathnames.h" - -/* -** Define (and possibly initialize) global variables here. -** -** Caveat: -** The maximum number of bootable files (`char *BootFiles[]') is -** limited to C_MAXFILE (i.e. the maximum number of files that -** can be spec'd in the configuration file). This was done to -** simplify the boot file search code. -*/ - -char *ProgName; /* path-stripped argv[0] */ -char MyHost[MAXHOSTNAMELEN+1]; /* host name */ -int MyPid; /* process id */ -int DebugFlg = 0; /* set true if debugging */ -int BootAny = 0; /* set true if we boot anyone */ - -char *ConfigFile = NULL; /* configuration file */ -char *DfltConfig = _PATH_RBOOTDCONF; /* default configuration file */ -char *PidFile = _PATH_RBOOTDPID; /* file w/pid of server */ -char *BootDir = _PATH_RBOOTDLIB; /* directory w/boot files */ -char *DbgFile = _PATH_RBOOTDDBG; /* debug output file */ - -FILE *DbgFp = NULL; /* debug file pointer */ -char *IntfName = NULL; /* intf we are attached to */ - -u_short SessionID = 0; /* generated session ID */ - -char *BootFiles[C_MAXFILE]; /* list of boot files */ - -CLIENT *Clients = NULL; /* list of addrs we'll accept */ -RMPCONN *RmpConns = NULL; /* list of active connections */ - -char RmpMcastAddr[RMP_ADDRLEN] = RMP_ADDR; /* RMP multicast address */ diff --git a/libexec/rbootd/defs.h b/libexec/rbootd/defs.h deleted file mode 100644 index a2e0cd0616c7..000000000000 --- a/libexec/rbootd/defs.h +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 1988, 1992 The University of Utah and the Center - * for Software Science (CSS). - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Center for Software Science of the University of Utah Computer - * Science Department. CSS requests users of this software to return - * to css-dist@cs.utah.edu any improvements that they make and grant - * CSS redistribution rights. - * - * 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. - * - * @(#)defs.h 8.1 (Berkeley) 6/4/93 - * - * Utah $Hdr: defs.h 3.1 92/07/06$ - * Author: Jeff Forys, University of Utah CSS - */ - -#include "rmp.h" -#include "rmp_var.h" - -/* -** Common #define's and external variables. All other files should -** include this. -*/ - -/* - * This may be defined in <sys/param.h>, if not, it's defined here. - */ -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 64 -#endif - -/* - * SIGUSR1 and SIGUSR2 are defined in <signal.h> for 4.3BSD systems. - */ -#ifndef SIGUSR1 -#define SIGUSR1 SIGEMT -#endif -#ifndef SIGUSR2 -#define SIGUSR2 SIGFPE -#endif - -/* - * These can be faster & more efficient than strcmp()/strncmp()... - */ -#define STREQN(s1,s2) ((*s1 == *s2) && (strcmp(s1,s2) == 0)) -#define STRNEQN(s1,s2,n) ((*s1 == *s2) && (strncmp(s1,s2,n) == 0)) - -/* - * Configuration file limitations. - */ -#define C_MAXFILE 10 /* max number of boot-able files */ -#define C_LINELEN 1024 /* max length of line */ - -/* - * Direction of packet (used as argument to DispPkt). - */ -#define DIR_RCVD 0 -#define DIR_SENT 1 -#define DIR_NONE 2 - -/* - * These need not be functions, so... - */ -#define FreeStr(str) free(str) -#define FreeClient(cli) free(cli) -#define GenSessID() (++SessionID ? SessionID: ++SessionID) - -/* - * Converting an Ethernet address to a string is done in many routines. - * Using `rmp.hp_hdr.saddr' works because this field is *never* changed; - * it will *always* contain the source address of the packet. - */ -#define EnetStr(rptr) GetEtherAddr(&(rptr)->rmp.hp_hdr.saddr[0]) - -/* - * Every machine we can boot will have one of these allocated for it - * (unless there are no restrictions on who we can boot). - */ -typedef struct client_s { - u_char addr[RMP_ADDRLEN]; /* addr of machine */ - char *files[C_MAXFILE]; /* boot-able files */ - struct client_s *next; /* ptr to next */ -} CLIENT; - -/* - * Every active connection has one of these allocated for it. - */ -typedef struct rmpconn_s { - struct rmp_packet rmp; /* RMP packet */ - int rmplen; /* length of packet */ - struct timeval tstamp; /* last time active */ - int bootfd; /* open boot file */ - struct rmpconn_s *next; /* ptr to next */ -} RMPCONN; - -/* - * All these variables are defined in "conf.c". - */ -extern char *ProgName; /* path-stripped argv[0] */ -extern char MyHost[]; /* this hosts' name */ -extern int MyPid; /* this processes' ID */ -extern int DebugFlg; /* set true if debugging */ -extern int BootAny; /* set true if we can boot anyone */ - -extern char *ConfigFile; /* configuration file */ -extern char *DfltConfig; /* default configuration file */ -extern char *DbgFile; /* debug output file */ -extern char *PidFile; /* file containing pid of server */ -extern char *BootDir; /* directory w/boot files */ - -extern FILE *DbgFp; /* debug file pointer */ -extern char *IntfName; /* interface we are attached to */ - -extern u_short SessionID; /* generated session ID */ - -extern char *BootFiles[]; /* list of boot files */ - -extern CLIENT *Clients; /* list of addrs we'll accept */ -extern RMPCONN *RmpConns; /* list of active connections */ - -extern char RmpMcastAddr[]; /* RMP multicast address */ - -void AddConn __P((RMPCONN *)); -int BootDone __P((RMPCONN *)); -void BpfClose __P((void)); -char *BpfGetIntfName __P((char **)); -int BpfOpen __P((void)); -int BpfRead __P((RMPCONN *, int)); -int BpfWrite __P((RMPCONN *)); -void DebugOff __P((int)); -void DebugOn __P((int)); -void DispPkt __P((RMPCONN *, int)); -void DoTimeout __P((void)); -void DspFlnm __P((u_int, char *)); -void Exit __P((int)); -CLIENT *FindClient __P((RMPCONN *)); -RMPCONN *FindConn __P((RMPCONN *)); -void FreeClients __P((void)); -void FreeConn __P((RMPCONN *)); -void FreeConns __P((void)); -int GetBootFiles __P((void)); -char *GetEtherAddr __P((u_char *)); -CLIENT *NewClient __P((u_char *)); -RMPCONN *NewConn __P((RMPCONN *)); -char *NewStr __P((char *)); -u_char *ParseAddr __P((char *)); -int ParseConfig __P((void)); -void ProcessPacket __P((RMPCONN *, CLIENT *)); -void ReConfig __P((int)); -void RemoveConn __P((RMPCONN *)); -int SendBootRepl __P((struct rmp_packet *, RMPCONN *, char *[])); -int SendFileNo __P((struct rmp_packet *, RMPCONN *, char *[])); -int SendPacket __P((RMPCONN *)); -int SendReadRepl __P((RMPCONN *)); -int SendServerID __P((RMPCONN *)); diff --git a/libexec/rbootd/parseconf.c b/libexec/rbootd/parseconf.c deleted file mode 100644 index d00436f071c8..000000000000 --- a/libexec/rbootd/parseconf.c +++ /dev/null @@ -1,359 +0,0 @@ -/* - * Copyright (c) 1988, 1992 The University of Utah and the Center - * for Software Science (CSS). - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Center for Software Science of the University of Utah Computer - * Science Department. CSS requests users of this software to return - * to css-dist@cs.utah.edu any improvements that they make and grant - * CSS redistribution rights. - * - * 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. - * - * @(#)parseconf.c 8.1 (Berkeley) 6/4/93 - * - * Utah $Hdr: parseconf.c 3.1 92/07/06$ - * Author: Jeff Forys, University of Utah CSS - */ - -#ifndef lint -static char sccsid[] = "@(#)parseconf.c 8.1 (Berkeley) 6/4/93"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/stat.h> - -#include <ctype.h> -#include <dirent.h> -#include <fcntl.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include "defs.h" - -/* -** ParseConfig -- parse the config file into linked list of clients. -** -** Parameters: -** None. -** -** Returns: -** 1 on success, 0 otherwise. -** -** Side Effects: -** - Linked list of clients will be (re)allocated. -** -** Warnings: -** - GetBootFiles() must be called before this routine -** to create a linked list of default boot files. -*/ -int -ParseConfig() -{ - FILE *fp; - CLIENT *client; - u_char *addr; - char line[C_LINELEN]; - register char *cp, *bcp; - register int i, j; - int omask, linecnt = 0; - - if (BootAny) /* ignore config file */ - return(1); - - FreeClients(); /* delete old list of clients */ - - if ((fp = fopen(ConfigFile, "r")) == NULL) { - syslog(LOG_ERR, "ParseConfig: can't open config file (%s)", - ConfigFile); - return(0); - } - - /* - * We've got to block SIGHUP to prevent reconfiguration while - * dealing with the linked list of Clients. This can be done - * when actually linking the new client into the list, but - * this could have unexpected results if the server was HUP'd - * whilst reconfiguring. Hence, it is done here. - */ - omask = sigblock(sigmask(SIGHUP)); - - /* - * GETSTR positions `bcp' at the start of the current token, - * and null terminates it. `cp' is positioned at the start - * of the next token. spaces & commas are separators. - */ -#define GETSTR while (isspace(*cp) || *cp == ',') cp++; \ - bcp = cp; \ - while (*cp && *cp!=',' && !isspace(*cp)) cp++; \ - if (*cp) *cp++ = '\0' - - /* - * For each line, parse it into a new CLIENT struct. - */ - while (fgets(line, C_LINELEN, fp) != NULL) { - linecnt++; /* line counter */ - - if (*line == '\0' || *line == '#') /* ignore comment */ - continue; - - if ((cp = index(line,'#')) != NULL) /* trash comments */ - *cp = '\0'; - - cp = line; /* init `cp' */ - GETSTR; /* get RMP addr */ - if (bcp == cp) /* all delimiters */ - continue; - - /* - * Get an RMP address from a string. Abort on failure. - */ - if ((addr = ParseAddr(bcp)) == NULL) { - syslog(LOG_ERR, - "ParseConfig: line %d: cant parse <%s>", - linecnt, bcp); - continue; - } - - if ((client = NewClient(addr)) == NULL) /* alloc new client */ - continue; - - GETSTR; /* get first file */ - - /* - * If no boot files are spec'd, use the default list. - * Otherwise, validate each file (`bcp') against the - * list of boot-able files. - */ - i = 0; - if (bcp == cp) /* no files spec'd */ - for (; i < C_MAXFILE && BootFiles[i] != NULL; i++) - client->files[i] = BootFiles[i]; - else { - do { - /* - * For each boot file spec'd, make sure it's - * in our list. If so, include a pointer to - * it in the CLIENT's list of boot files. - */ - for (j = 0; ; j++) { - if (j==C_MAXFILE||BootFiles[j]==NULL) { - syslog(LOG_ERR, "ParseConfig: line %d: no boot file (%s)", - linecnt, bcp); - break; - } - if (STREQN(BootFiles[j], bcp)) { - if (i < C_MAXFILE) - client->files[i++] = - BootFiles[j]; - else - syslog(LOG_ERR, "ParseConfig: line %d: too many boot files (%s)", - linecnt, bcp); - break; - } - } - GETSTR; /* get next file */ - } while (bcp != cp); - - /* - * Restricted list of boot files were spec'd, - * however, none of them were found. Since we - * apparently cant let them boot "just anything", - * the entire record is invalidated. - */ - if (i == 0) { - FreeClient(client); - continue; - } - } - - /* - * Link this client into the linked list of clients. - * SIGHUP has already been blocked. - */ - if (Clients) - client->next = Clients; - Clients = client; - } - - (void) fclose(fp); /* close config file */ - - (void) sigsetmask(omask); /* reset signal mask */ - - return(1); /* return success */ -} - -/* -** ParseAddr -- Parse a string containing an RMP address. -** -** This routine is fairly liberal at parsing an RMP address. The -** address must contain 6 octets consisting of between 0 and 2 hex -** chars (upper/lower case) separated by colons. If two colons are -** together (e.g. "::", the octet between them is recorded as being -** zero. Hence, the following addrs are all valid and parse to the -** same thing: -** -** 08:00:09:00:66:ad 8::9:0:66:AD 8::9::66:aD -** -** For clarity, an RMP address is really an Ethernet address, but -** since the HP boot code uses IEEE 802.3, it's really an IEEE -** 802.3 address. Of course, all of these are identical. -** -** Parameters: -** str - string representation of an RMP address. -** -** Returns: -** pointer to a static array of RMP_ADDRLEN bytes. -** -** Side Effects: -** None. -** -** Warnings: -** - The return value points to a static buffer; it must -** be copied if it's to be saved. -** - For speed, we assume a u_char consists of 8 bits. -*/ -u_char * -ParseAddr(str) - char *str; -{ - static u_char addr[RMP_ADDRLEN]; - register char *cp; - register unsigned i; - register int part, subpart; - - bzero((char *)&addr[0], RMP_ADDRLEN); /* zero static buffer */ - - part = subpart = 0; - for (cp = str; *cp; cp++) { - /* - * A colon (`:') must be used to delimit each octet. - */ - if (*cp == ':') { - if (++part == RMP_ADDRLEN) /* too many parts */ - return(NULL); - subpart = 0; - continue; - } - - /* - * Convert hex character to an integer. - */ - if (isdigit(*cp)) - i = *cp - '0'; - else { - i = (isupper(*cp)? tolower(*cp): *cp) - 'a' + 10; - if (i < 10 || i > 15) /* not a hex char */ - return(NULL); - } - - if (subpart++) { - if (subpart > 2) /* too many hex chars */ - return(NULL); - addr[part] <<= 4; - } - addr[part] |= i; - } - - if (part != (RMP_ADDRLEN-1)) /* too few parts */ - return(NULL); - - return(&addr[0]); -} - -/* -** GetBootFiles -- record list of files in current (boot) directory. -** -** Parameters: -** None. -** -** Returns: -** Number of boot files on success, 0 on failure. -** -** Side Effects: -** Strings in `BootFiles' are freed/allocated. -** -** Warnings: -** - After this routine is called, ParseConfig() must be -** called to re-order it's list of boot file pointers. -*/ -int -GetBootFiles() -{ - DIR *dfd; - struct stat statb; - register struct dirent *dp; - register int i; - - /* - * Free the current list of boot files. - */ - for (i = 0; i < C_MAXFILE && BootFiles[i] != NULL; i++) { - FreeStr(BootFiles[i]); - BootFiles[i] = NULL; - } - - /* - * Open current directory to read boot file names. - */ - if ((dfd = opendir(".")) == NULL) { /* open BootDir */ - syslog(LOG_ERR, "GetBootFiles: can't open directory (%s)\n", - BootDir); - return(0); - } - - /* - * Read each boot file name and allocate space for it in the - * list of boot files (BootFiles). All boot files read after - * C_MAXFILE will be ignored. - */ - i = 0; - for (dp = readdir(dfd); dp != NULL; dp = readdir(dfd)) { - if (stat(dp->d_name, &statb) < 0 || - (statb.st_mode & S_IFMT) != S_IFREG) - continue; - if (i == C_MAXFILE) - syslog(LOG_ERR, - "GetBootFiles: too many boot files (%s ignored)", - dp->d_name); - else if ((BootFiles[i] = NewStr(dp->d_name)) != NULL) - i++; - } - - (void) closedir(dfd); /* close BootDir */ - - if (i == 0) /* cant find any boot files */ - syslog(LOG_ERR, "GetBootFiles: no boot files (%s)\n", BootDir); - - return(i); -} diff --git a/libexec/rbootd/pathnames.h b/libexec/rbootd/pathnames.h deleted file mode 100644 index d960dcee96ac..000000000000 --- a/libexec/rbootd/pathnames.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 1988, 1992 The University of Utah and the Center - * for Software Science (CSS). - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Center for Software Science of the University of Utah Computer - * Science Department. CSS requests users of this software to return - * to css-dist@cs.utah.edu any improvements that they make and grant - * CSS redistribution rights. - * - * 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. - * - * @(#)pathnames.h 8.1 (Berkeley) 6/4/93 - * - * Utah $Hdr: pathnames.h 3.1 92/07/06$ - * Author: Jeff Forys, University of Utah CSS - */ - -#define _PATH_BPF "/dev/bpf%d" -#define _PATH_RBOOTDCONF "/etc/rbootd.conf" -#define _PATH_RBOOTDDBG "/tmp/rbootd.dbg" -#define _PATH_RBOOTDLIB "/usr/mdec/rbootd" -#define _PATH_RBOOTDPID "/var/run/rbootd.pid" diff --git a/libexec/rbootd/rbootd.8 b/libexec/rbootd/rbootd.8 deleted file mode 100644 index f4eb36477def..000000000000 --- a/libexec/rbootd/rbootd.8 +++ /dev/null @@ -1,156 +0,0 @@ -.\" Copyright (c) 1988, 1992 The University of Utah and the Center -.\" for Software Science (CSS). -.\" Copyright (c) 1992, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" the Center for Software Science of the University of Utah Computer -.\" Science Department. CSS requests users of this software to return -.\" to css-dist@cs.utah.edu any improvements that they make and grant -.\" CSS redistribution rights. -.\" -.\" 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. -.\" -.\" @(#)rbootd.8 8.2 (Berkeley) 12/11/93 -.\" -.\" Utah $Hdr: rbootd.man 3.1 92/07/06$ -.\" Author: Jeff Forys, University of Utah CSS -.\" -.Dd "December 11, 1993" -.Dt RBOOTD 8 -.Os -.Sh NAME -.Nm rbootd -.Nd HP remote boot server -.Sh SYNOPSIS -.Nm rbootd -.Op Fl ad -.Op Fl i Ar interface -.Op config_file -.Sh DESCRIPTION -The -.Nm rbootd -utility services boot requests from Hewlett-Packard workstations over a -local area network. -All boot files must reside in the boot file directory; further, if a -client supplies path information in its boot request, it will be silently -stripped away before processing. -By default, -.Nm rbootd -only responds to requests from machines listed in its configuration file. -.Pp -The options are as follows: -.Bl -tag -width Fl -.It Fl a -Respond to boot requests from any machine. -The configuration file is ignored if this option is specified. -.It Fl d -Run -.Nm rbootd -in debug mode. -Packets sent and received are displayed to the terminal. -.It Fl i Ar interface -Service boot requests on specified interface. -If unspecified, -.Nm rbootd -searches the system interface list for the lowest numbered, configured -``up'' interface (excluding loopback). -Ties are broken by choosing the earliest match. -.El -.Pp -Specifying -.Ar config_file -on the command line causes -.Nm rbootd -to use a different configuration file from the default. -.Pp -The configuration file is a text file where each line describes a particular -machine. -A line must start with a machine's Ethernet address followed by an optional -list of boot file names. -An Ethernet address is specified in hexadecimal with each of its six octets -separated by a colon. -The boot file names come from the boot file directory. -The ethernet address and boot file(s) must be separated by white-space -and/or comma characters. -A pound sign causes the remainder of a line to be ignored. -.Pp -Here is a sample configuration file: -.Bl -column 08:00:09:0:66:ad SYSHPBSD,SYSHPUX "# vandy (anything)" -.It # -.It # ethernet addr boot file(s) comments -.It # -.It 08:00:09:0:66:ad SYSHPBSD # snake (4.3BSD) -.It 08:00:09:0:59:5b # vandy (anything) -.It 8::9:1:C6:75 SYSHPBSD,SYSHPUX # jaguar (either) -.El -.Pp -.Nm Rbootd -logs status and error messages via -.Xr syslog 3 . -A startup message is always logged, and in the case of fatal errors (or -deadly signals) a message is logged announcing the server's termination. -In general, a non-fatal error is handled by ignoring the event that caused -it (e.g. an invalid Ethernet address in the config file causes that line -to be invalidated). -.Pp -The following signals have the specified effect when sent to the server -process using the -.Xr kill 1 -command: -.Bl -tag -width SIGUSR1 -offset -compact -.It SIGHUP -Drop all active connections and reconfigure. -.It SIGUSR1 -Turn on debugging, do nothing if already on. -.It SIGUSR2 -Turn off debugging, do nothing if already off. -.El -.Sh "FILES" -.Bl -tag -width /usr/libexec/rbootd -compact -.It /dev/bpf# -packet-filter device -.It /etc/rbootd.conf -configuration file -.It /tmp/rbootd.dbg -debug output -.It /usr/mdec/rbootd -directory containing boot files -.It /var/run/rbootd.pid -process id -.El -.Sh SEE ALSO -.Xr kill 1 , -.Xr socket 2 , -.Xr signal 3 , -.Xr syslog 3 , -.Xr rmp 4 -.Sh BUGS -If multiple servers are started on the same interface, each will receive -and respond to the same boot packets. diff --git a/libexec/rbootd/rbootd.c b/libexec/rbootd/rbootd.c deleted file mode 100644 index aa01583496f2..000000000000 --- a/libexec/rbootd/rbootd.c +++ /dev/null @@ -1,508 +0,0 @@ -/* - * Copyright (c) 1988, 1992 The University of Utah and the Center - * for Software Science (CSS). - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Center for Software Science of the University of Utah Computer - * Science Department. CSS requests users of this software to return - * to css-dist@cs.utah.edu any improvements that they make and grant - * CSS redistribution rights. - * - * 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. - * - * @(#)rbootd.c 8.2 (Berkeley) 2/22/94 - * - * Utah $Hdr: rbootd.c 3.1 92/07/06$ - * Author: Jeff Forys, University of Utah CSS - */ - -#ifndef lint -static 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[] = "@(#)rbootd.c 8.2 (Berkeley) 2/22/94"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/ioctl.h> -#include <sys/time.h> - -#include <ctype.h> -#include <errno.h> -#include <fcntl.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <unistd.h> -#include "defs.h" - - -/* fd mask macros (backward compatibility with 4.2BSD) */ -#ifndef FD_SET -#ifdef notdef -typedef struct fd_set { /* this should already be in 4.2 */ - int fds_bits[1]; -} fd_set; -#endif -#define FD_ZERO(p) ((p)->fds_bits[0] = 0) -#define FD_SET(n, p) ((p)->fds_bits[0] |= (1 << (n))) -#define FD_CLR(n, p) ((p)->fds_bits[0] &= ~(1 << (n))) -#define FD_ISSET(n, p) ((p)->fds_bits[0] & (1 << (n))) -#endif - -int -main(argc, argv) - int argc; - char *argv[]; -{ - int c, fd, omask, maxfds; - fd_set rset; - - /* - * Find what name we are running under. - */ - ProgName = (ProgName = rindex(argv[0],'/')) ? ++ProgName : *argv; - - /* - * Close any open file descriptors. - * Temporarily leave stdin & stdout open for `-d', - * and stderr open for any pre-syslog error messages. - */ - { - int i, nfds = getdtablesize(); - - for (i = 0; i < nfds; i++) - if (i != fileno(stdin) && i != fileno(stdout) && - i != fileno(stderr)) - (void) close(i); - } - - /* - * Parse any arguments. - */ - while ((c = getopt(argc, argv, "adi:")) != EOF) - switch(c) { - case 'a': - BootAny++; - break; - case 'd': - DebugFlg++; - break; - case 'i': - IntfName = optarg; - break; - } - for (; optind < argc; optind++) { - if (ConfigFile == NULL) - ConfigFile = argv[optind]; - else { - fprintf(stderr, - "%s: too many config files (`%s' ignored)\n", - ProgName, argv[optind]); - } - } - - if (ConfigFile == NULL) /* use default config file */ - ConfigFile = DfltConfig; - - if (DebugFlg) { - DbgFp = stdout; /* output to stdout */ - - (void) signal(SIGUSR1, SIG_IGN); /* dont muck w/DbgFp */ - (void) signal(SIGUSR2, SIG_IGN); - } else { - (void) fclose(stdin); /* dont need these */ - (void) fclose(stdout); - - /* - * Fork off a child to do the work & exit. - */ - switch(fork()) { - case -1: /* fork failed */ - fprintf(stderr, "%s: ", ProgName); - perror("fork"); - Exit(0); - case 0: /* this is the CHILD */ - break; - default: /* this is the PARENT */ - _exit(0); - } - - /* - * Try to disassociate from the current tty. - */ - { - char *devtty = "/dev/tty"; - int i; - - if ((i = open(devtty, O_RDWR)) < 0) { - /* probably already disassociated */ - if (setpgrp(0, 0) < 0) { - fprintf(stderr, "%s: ", ProgName); - perror("setpgrp"); - } - } else { - if (ioctl(i, (u_long)TIOCNOTTY, (char *)0) < 0){ - fprintf(stderr, "%s: ", ProgName); - perror("ioctl"); - } - (void) close(i); - } - } - - (void) signal(SIGUSR1, DebugOn); - (void) signal(SIGUSR2, DebugOff); - } - - (void) fclose(stderr); /* finished with it */ - -#ifdef SYSLOG4_2 - openlog(ProgName, LOG_PID); -#else - openlog(ProgName, LOG_PID, LOG_DAEMON); -#endif - - /* - * If no interface was specified, get one now. - * - * This is convoluted because we want to get the default interface - * name for the syslog("restarted") message. If BpfGetIntfName() - * runs into an error, it will return a syslog-able error message - * (in `errmsg') which will be displayed here. - */ - if (IntfName == NULL) { - char *errmsg; - - if ((IntfName = BpfGetIntfName(&errmsg)) == NULL) { - syslog(LOG_NOTICE, "restarted (??)"); - syslog(LOG_ERR, errmsg); - Exit(0); - } - } - - syslog(LOG_NOTICE, "restarted (%s)", IntfName); - - (void) signal(SIGHUP, ReConfig); - (void) signal(SIGINT, Exit); - (void) signal(SIGTERM, Exit); - - /* - * Grab our host name and pid. - */ - if (gethostname(MyHost, MAXHOSTNAMELEN) < 0) { - syslog(LOG_ERR, "gethostname: %m"); - Exit(0); - } - MyHost[MAXHOSTNAMELEN] = '\0'; - - MyPid = getpid(); - - /* - * Write proc's pid to a file. - */ - { - FILE *fp; - - if ((fp = fopen(PidFile, "w")) != NULL) { - (void) fprintf(fp, "%d\n", MyPid); - (void) fclose(fp); - } else { - syslog(LOG_WARNING, "fopen: failed (%s)", PidFile); - } - } - - /* - * All boot files are relative to the boot directory, we might - * as well chdir() there to make life easier. - */ - if (chdir(BootDir) < 0) { - syslog(LOG_ERR, "chdir: %m (%s)", BootDir); - Exit(0); - } - - /* - * Initial configuration. - */ - omask = sigblock(sigmask(SIGHUP)); /* prevent reconfig's */ - if (GetBootFiles() == 0) /* get list of boot files */ - Exit(0); - if (ParseConfig() == 0) /* parse config file */ - Exit(0); - - /* - * Open and initialize a BPF device for the appropriate interface. - * If an error is encountered, a message is displayed and Exit() - * is called. - */ - fd = BpfOpen(); - - (void) sigsetmask(omask); /* allow reconfig's */ - - /* - * Main loop: receive a packet, determine where it came from, - * and if we service this host, call routine to handle request. - */ - maxfds = fd + 1; - FD_ZERO(&rset); - FD_SET(fd, &rset); - for (;;) { - struct timeval timeout; - fd_set r; - int nsel; - - r = rset; - - if (RmpConns == NULL) { /* timeout isnt necessary */ - nsel = select(maxfds, &r, (fd_set *)0, (fd_set *)0, - (struct timeval *)0); - } else { - timeout.tv_sec = RMP_TIMEOUT; - timeout.tv_usec = 0; - nsel = select(maxfds, &r, (fd_set *)0, (fd_set *)0, - &timeout); - } - - if (nsel < 0) { - if (errno == EINTR) - continue; - syslog(LOG_ERR, "select: %m"); - Exit(0); - } else if (nsel == 0) { /* timeout */ - DoTimeout(); /* clear stale conns */ - continue; - } - - if (FD_ISSET(fd, &r)) { - RMPCONN rconn; - CLIENT *client, *FindClient(); - int doread = 1; - - while (BpfRead(&rconn, doread)) { - doread = 0; - - if (DbgFp != NULL) /* display packet */ - DispPkt(&rconn,DIR_RCVD); - - omask = sigblock(sigmask(SIGHUP)); - - /* - * If we do not restrict service, set the - * client to NULL (ProcessPacket() handles - * this). Otherwise, check that we can - * service this host; if not, log a message - * and ignore the packet. - */ - if (BootAny) { - client = NULL; - } else if ((client=FindClient(&rconn))==NULL) { - syslog(LOG_INFO, - "%s: boot packet ignored", - EnetStr(&rconn)); - (void) sigsetmask(omask); - continue; - } - - ProcessPacket(&rconn,client); - - (void) sigsetmask(omask); - } - } - } -} - -/* -** DoTimeout -- Free any connections that have timed out. -** -** Parameters: -** None. -** -** Returns: -** Nothing. -** -** Side Effects: -** - Timed out connections in `RmpConns' will be freed. -*/ -void -DoTimeout() -{ - register RMPCONN *rtmp; - struct timeval now; - - (void) gettimeofday(&now, (struct timezone *)0); - - /* - * For each active connection, if RMP_TIMEOUT seconds have passed - * since the last packet was sent, delete the connection. - */ - for (rtmp = RmpConns; rtmp != NULL; rtmp = rtmp->next) - if ((rtmp->tstamp.tv_sec + RMP_TIMEOUT) < now.tv_sec) { - syslog(LOG_WARNING, "%s: connection timed out (%u)", - EnetStr(rtmp), rtmp->rmp.r_type); - RemoveConn(rtmp); - } -} - -/* -** FindClient -- Find client associated with a packet. -** -** Parameters: -** rconn - the new packet. -** -** Returns: -** Pointer to client info if found, NULL otherwise. -** -** Side Effects: -** None. -** -** Warnings: -** - This routine must be called with SIGHUP blocked since -** a reconfigure can invalidate the information returned. -*/ - -CLIENT * -FindClient(rconn) - register RMPCONN *rconn; -{ - register CLIENT *ctmp; - - for (ctmp = Clients; ctmp != NULL; ctmp = ctmp->next) - if (bcmp((char *)&rconn->rmp.hp_hdr.saddr[0], - (char *)&ctmp->addr[0], RMP_ADDRLEN) == 0) - break; - - return(ctmp); -} - -/* -** Exit -- Log an error message and exit. -** -** Parameters: -** sig - caught signal (or zero if not dying on a signal). -** -** Returns: -** Does not return. -** -** Side Effects: -** - This process ceases to exist. -*/ -void -Exit(sig) - int sig; -{ - if (sig > 0) - syslog(LOG_ERR, "going down on signal %d", sig); - else - syslog(LOG_ERR, "going down with fatal error"); - BpfClose(); - exit(1); -} - -/* -** ReConfig -- Get new list of boot files and reread config files. -** -** Parameters: -** None. -** -** Returns: -** Nothing. -** -** Side Effects: -** - All active connections are dropped. -** - List of boot-able files is changed. -** - List of clients is changed. -** -** Warnings: -** - This routine must be called with SIGHUP blocked. -*/ -void -ReConfig(signo) - int signo; -{ - syslog(LOG_NOTICE, "reconfiguring boot server"); - - FreeConns(); - - if (GetBootFiles() == 0) - Exit(0); - - if (ParseConfig() == 0) - Exit(0); -} - -/* -** DebugOff -- Turn off debugging. -** -** Parameters: -** None. -** -** Returns: -** Nothing. -** -** Side Effects: -** - Debug file is closed. -*/ -void -DebugOff(signo) - int signo; -{ - if (DbgFp != NULL) - (void) fclose(DbgFp); - - DbgFp = NULL; -} - -/* -** DebugOn -- Turn on debugging. -** -** Parameters: -** None. -** -** Returns: -** Nothing. -** -** Side Effects: -** - Debug file is opened/truncated if not already opened, -** otherwise do nothing. -*/ -void -DebugOn(signo) - int signo; -{ - if (DbgFp == NULL) { - if ((DbgFp = fopen(DbgFile, "w")) == NULL) - syslog(LOG_ERR, "can't open debug file (%s)", DbgFile); - } -} diff --git a/libexec/rbootd/rmp.h b/libexec/rbootd/rmp.h deleted file mode 100644 index d3b016760d35..000000000000 --- a/libexec/rbootd/rmp.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 1988, 1992 The University of Utah and the Center - * for Software Science (CSS). - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Center for Software Science of the University of Utah Computer - * Science Department. CSS requests users of this software to return - * to css-dist@cs.utah.edu any improvements that they make and grant - * CSS redistribution rights. - * - * 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. - * - * @(#)rmp.h 8.1 (Berkeley) 6/4/93 - * - * Utah $Hdr: rmp.h 3.1 92/07/06$ - * Author: Jeff Forys, University of Utah CSS - */ - -/* - * Define MIN/MAX sizes of RMP (ethernet) packet. - * For ease of computation, the 4 octet CRC field is not included. - * - * MCLBYTES is for bpfwrite(); it is adamant about using a cluster. - */ - -#define RMP_MAX_PACKET MIN(1514,MCLBYTES) -#define RMP_MIN_PACKET 60 - -/* - * Define RMP/Ethernet Multicast address (9:0:9:0:0:4) and its length. - */ -#define RMP_ADDR { 0x9, 0x0, 0x9, 0x0, 0x0, 0x4 } -#define RMP_ADDRLEN 6 - -/* - * Define IEEE802.2 (Logical Link Control) information. - */ -#define IEEE_DSAP_HP 0xF8 /* Destination Service Access Point */ -#define IEEE_SSAP_HP 0xF8 /* Source Service Access Point */ -#define IEEE_CNTL_HP 0x0300 /* Type 1 / I format control information */ - -#define HPEXT_DXSAP 0x608 /* HP Destination Service Access Point */ -#define HPEXT_SXSAP 0x609 /* HP Source Service Access Point */ - -/* - * 802.3-style "Ethernet" header. - */ - -struct hp_hdr { - u_char daddr[RMP_ADDRLEN]; - u_char saddr[RMP_ADDRLEN]; - u_short len; -}; - -/* - * HP uses 802.2 LLC with their own local extensions. This struct makes - * sence out of this data (encapsulated in the above 802.3 packet). - */ - -struct hp_llc { - u_char dsap; /* 802.2 DSAP */ - u_char ssap; /* 802.2 SSAP */ - u_short cntrl; /* 802.2 control field */ - u_short filler; /* HP filler (must be zero) */ - u_short dxsap; /* HP extended DSAP */ - u_short sxsap; /* HP extended SSAP */ -}; diff --git a/libexec/rbootd/rmp_var.h b/libexec/rbootd/rmp_var.h deleted file mode 100644 index 7df1e87465fc..000000000000 --- a/libexec/rbootd/rmp_var.h +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright (c) 1988, 1992 The University of Utah and the Center - * for Software Science (CSS). - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Center for Software Science of the University of Utah Computer - * Science Department. CSS requests users of this software to return - * to css-dist@cs.utah.edu any improvements that they make and grant - * CSS redistribution rights. - * - * 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. - * - * @(#)rmp_var.h 8.1 (Berkeley) 6/4/93 - * - * Utah $Hdr: rmp_var.h 3.1 92/07/06$ - * Author: Jeff Forys, University of Utah CSS - */ - -/* - * Possible values for "rmp_type" fields. - */ - -#define RMP_BOOT_REQ 1 /* boot request packet */ -#define RMP_BOOT_REPL 129 /* boot reply packet */ -#define RMP_READ_REQ 2 /* read request packet */ -#define RMP_READ_REPL 130 /* read reply packet */ -#define RMP_BOOT_DONE 3 /* boot complete packet */ - -/* - * Useful constants. - */ - -#define RMP_VERSION 2 /* protocol version */ -#define RMP_TIMEOUT 600 /* timeout connection after ten minutes */ -#define RMP_PROBESID 0xffff /* session ID for probes */ -#define RMP_HOSTLEN 13 /* max length of server's name */ -#define RMP_MACHLEN 20 /* length of machine type field */ - -/* - * RMP error codes - */ - -#define RMP_E_OKAY 0 -#define RMP_E_EOF 2 /* read reply: returned end of file */ -#define RMP_E_ABORT 3 /* abort operation */ -#define RMP_E_BUSY 4 /* boot reply: server busy */ -#define RMP_E_TIMEOUT 5 /* lengthen time out (not implemented) */ -#define RMP_E_NOFILE 16 /* boot reply: file does not exist */ -#define RMP_E_OPENFILE 17 /* boot reply: file open failed */ -#define RMP_E_NODFLT 18 /* boot reply: default file does not exist */ -#define RMP_E_OPENDFLT 19 /* boot reply: default file open failed */ -#define RMP_E_BADSID 25 /* read reply: bad session ID */ -#define RMP_E_BADPACKET 27 /* Bad packet detected */ - -/* - * RMPDATALEN is the maximum number of data octets that can be stuffed - * into an RMP packet. This excludes the 802.2 LLC w/HP extensions. - */ -#define RMPDATALEN (RMP_MAX_PACKET - (sizeof(struct hp_hdr) + \ - sizeof(struct hp_llc))) - -/* - * Define sizes of packets we send. Boot and Read replies are variable - * in length depending on the length of `s'. - * - * Also, define how much space `restofpkt' can take up for outgoing - * Boot and Read replies. Boot Request packets are effectively - * limited to 255 bytes due to the preceding 1-byte length field. - */ - -#define RMPBOOTSIZE(s) (sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \ - sizeof(struct rmp_boot_repl) + s - sizeof(restofpkt)) -#define RMPREADSIZE(s) (sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \ - sizeof(struct rmp_read_repl) + s - sizeof(restofpkt) \ - - sizeof(u_char)) -#define RMPDONESIZE (sizeof(struct hp_hdr) + sizeof(struct hp_llc) + \ - sizeof(struct rmp_boot_done)) -#define RMPBOOTDATA 255 -#define RMPREADDATA (RMPDATALEN - \ - (2*sizeof(u_char)+sizeof(u_short)+sizeof(u_word))) - -/* - * This protocol defines some field sizes as "rest of ethernet packet". - * There is no easy way to specify this in C, so we use a one character - * field to denote it, and index past it to the end of the packet. - */ - -typedef char restofpkt; - -/* - * Due to the RMP packet layout, we'll run into alignment problems - * on machines that cant access words on half-word boundaries. If - * you know that your machine does not suffer from this problem, - * add it to the hp300 #define below. - * - * The following macros are used to deal with this problem: - * WORDZE(w) Return True if u_word `w' is zero, False otherwise. - * ZEROWORD(w) Set u_word `w' to zero. - * COPYWORD(w1,w2) Copy u_word `w1' to `w2'. - * GETWORD(w,i) Copy u_word `w' into int `i'. - * PUTWORD(i,w) Copy int `i' into u_word `w'. - * - * N.B. We do not support little endian alignment-challenged machines. - */ -#if defined(vax) || defined(tahoe) || defined(hp300) - -typedef u_int u_word; - -#define WORDZE(w) ((w) == 0) -#define ZEROWORD(w) (w) = 0 -#define COPYWORD(w1,w2) (w2) = (w1) -#define GETWORD(w, i) (i) = (w) -#define PUTWORD(i, w) (w) = (i) - -#else - -#define _WORD_HIGHPART 0 /* XXX: assume Big Endian for now */ -#define _WORD_LOWPART 1 - -typedef struct _uword { u_short val[2]; } u_word; - -#define WORDZE(w) \ - ((w.val[_WORD_HIGHPART] == 0) && (w.val[_WORD_LOWPART] == 0)) -#define ZEROWORD(w) \ - (w).val[_WORD_HIGHPART] = (w).val[_WORD_LOWPART] = 0 -#define COPYWORD(w1, w2) \ - { (w2).val[_WORD_HIGHPART] = (w1).val[_WORD_HIGHPART]; \ - (w2).val[_WORD_LOWPART] = (w1).val[_WORD_LOWPART]; \ - } -#define GETWORD(w, i) \ - (i) = (((u_int)(w).val[_WORD_HIGHPART]) << 16) | (w).val[_WORD_LOWPART] -#define PUTWORD(i, w) \ - { (w).val[_WORD_HIGHPART] = (u_short) (((i) >> 16) & 0xffff); \ - (w).val[_WORD_LOWPART] = (u_short) (i & 0xffff); \ - } - -#endif - -/* - * Packet structures. - */ - -struct rmp_raw { /* generic RMP packet */ - u_char rmp_type; /* packet type */ - u_char rmp_rawdata[RMPDATALEN-1]; -}; - -struct rmp_boot_req { /* boot request */ - u_char rmp_type; /* packet type (RMP_BOOT_REQ) */ - u_char rmp_retcode; /* return code (0) */ - u_word rmp_seqno; /* sequence number (real time clock) */ - u_short rmp_session; /* session id (normally 0) */ - u_short rmp_version; /* protocol version (RMP_VERSION) */ - char rmp_machtype[RMP_MACHLEN]; /* machine type */ - u_char rmp_flnmsize; /* length of rmp_flnm */ - restofpkt rmp_flnm; /* name of file to be read */ -}; - -struct rmp_boot_repl { /* boot reply */ - u_char rmp_type; /* packet type (RMP_BOOT_REPL) */ - u_char rmp_retcode; /* return code (normally 0) */ - u_word rmp_seqno; /* sequence number (from boot req) */ - u_short rmp_session; /* session id (generated) */ - u_short rmp_version; /* protocol version (RMP_VERSION) */ - u_char rmp_flnmsize; /* length of rmp_flnm */ - restofpkt rmp_flnm; /* name of file (from boot req) */ -}; - -struct rmp_read_req { /* read request */ - u_char rmp_type; /* packet type (RMP_READ_REQ) */ - u_char rmp_retcode; /* return code (0) */ - u_word rmp_offset; /* file relative byte offset */ - u_short rmp_session; /* session id (from boot repl) */ - u_short rmp_size; /* max no of bytes to send */ -}; - -struct rmp_read_repl { /* read reply */ - u_char rmp_type; /* packet type (RMP_READ_REPL) */ - u_char rmp_retcode; /* return code (normally 0) */ - u_word rmp_offset; /* byte offset (from read req) */ - u_short rmp_session; /* session id (from read req) */ - restofpkt rmp_data; /* data (max size from read req) */ - u_char rmp_unused; /* padding to 16-bit boundary */ -}; - -struct rmp_boot_done { /* boot complete */ - u_char rmp_type; /* packet type (RMP_BOOT_DONE) */ - u_char rmp_retcode; /* return code (0) */ - u_word rmp_unused; /* not used (0) */ - u_short rmp_session; /* session id (from read repl) */ -}; - -struct rmp_packet { - struct hp_hdr hp_hdr; - struct hp_llc hp_llc; - union { - struct rmp_boot_req rmp_brq; /* boot request */ - struct rmp_boot_repl rmp_brpl; /* boot reply */ - struct rmp_read_req rmp_rrq; /* read request */ - struct rmp_read_repl rmp_rrpl; /* read reply */ - struct rmp_boot_done rmp_done; /* boot complete */ - struct rmp_raw rmp_raw; /* raw data */ - } rmp_proto; -}; - -/* - * Make life easier... - */ - -#define r_type rmp_proto.rmp_raw.rmp_type -#define r_data rmp_proto.rmp_raw.rmp_data -#define r_brq rmp_proto.rmp_brq -#define r_brpl rmp_proto.rmp_brpl -#define r_rrq rmp_proto.rmp_rrq -#define r_rrpl rmp_proto.rmp_rrpl -#define r_done rmp_proto.rmp_done diff --git a/libexec/rbootd/rmpproto.c b/libexec/rbootd/rmpproto.c deleted file mode 100644 index d0a8d4a8086f..000000000000 --- a/libexec/rbootd/rmpproto.c +++ /dev/null @@ -1,593 +0,0 @@ -/* - * Copyright (c) 1988, 1992 The University of Utah and the Center - * for Software Science (CSS). - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Center for Software Science of the University of Utah Computer - * Science Department. CSS requests users of this software to return - * to css-dist@cs.utah.edu any improvements that they make and grant - * CSS redistribution rights. - * - * 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. - * - * @(#)rmpproto.c 8.1 (Berkeley) 6/4/93 - * - * Utah $Hdr: rmpproto.c 3.1 92/07/06$ - * Author: Jeff Forys, University of Utah CSS - */ - -#ifndef lint -static char sccsid[] = "@(#)rmpproto.c 8.1 (Berkeley) 6/4/93"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/time.h> - -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <string.h> -#include <syslog.h> -#include <unistd.h> -#include "defs.h" - -/* -** ProcessPacket -- determine packet type and do what's required. -** -** An RMP BOOT packet has been received. Look at the type field -** and process Boot Requests, Read Requests, and Boot Complete -** packets. Any other type will be dropped with a warning msg. -** -** Parameters: -** rconn - the new connection -** client - list of files available to this host -** -** Returns: -** Nothing. -** -** Side Effects: -** - If this is a valid boot request, it will be added to -** the linked list of outstanding requests (RmpConns). -** - If this is a valid boot complete, its associated -** entry in RmpConns will be deleted. -** - Also, unless we run out of memory, a reply will be -** sent to the host that sent the packet. -*/ -void -ProcessPacket(rconn, client) - RMPCONN *rconn; - CLIENT *client; -{ - struct rmp_packet *rmp; - RMPCONN *rconnout; - - rmp = &rconn->rmp; /* cache pointer to RMP packet */ - - switch(rmp->r_type) { /* do what we came here to do */ - case RMP_BOOT_REQ: /* boot request */ - if ((rconnout = NewConn(rconn)) == NULL) - return; - - /* - * If the Session ID is 0xffff, this is a "probe" - * packet and we do not want to add the connection - * to the linked list of active connections. There - * are two types of probe packets, if the Sequence - * Number is 0 they want to know our host name, o/w - * they want the name of the file associated with - * the number spec'd by the Sequence Number. - * - * If this is an actual boot request, open the file - * and send a reply. If SendBootRepl() does not - * return 0, add the connection to the linked list - * of active connections, otherwise delete it since - * an error was encountered. - */ - if (rmp->r_brq.rmp_session == RMP_PROBESID) { - if (WORDZE(rmp->r_brq.rmp_seqno)) - (void) SendServerID(rconnout); - else - (void) SendFileNo(rmp, rconnout, - client? client->files: - BootFiles); - FreeConn(rconnout); - } else { - if (SendBootRepl(rmp, rconnout, - client? client->files: BootFiles)) - AddConn(rconnout); - else - FreeConn(rconnout); - } - break; - - case RMP_BOOT_REPL: /* boot reply (not valid) */ - syslog(LOG_WARNING, "%s: sent a boot reply", - EnetStr(rconn)); - break; - - case RMP_READ_REQ: /* read request */ - /* - * Send a portion of the boot file. - */ - (void) SendReadRepl(rconn); - break; - - case RMP_READ_REPL: /* read reply (not valid) */ - syslog(LOG_WARNING, "%s: sent a read reply", - EnetStr(rconn)); - break; - - case RMP_BOOT_DONE: /* boot complete */ - /* - * Remove the entry from the linked list of active - * connections. - */ - (void) BootDone(rconn); - break; - - default: /* unknown RMP packet type */ - syslog(LOG_WARNING, "%s: unknown packet type (%u)", - EnetStr(rconn), rmp->r_type); - } -} - -/* -** SendServerID -- send our host name to who ever requested it. -** -** Parameters: -** rconn - the reply packet to be formatted. -** -** Returns: -** 1 on success, 0 on failure. -** -** Side Effects: -** none. -*/ -int -SendServerID(rconn) - RMPCONN *rconn; -{ - register struct rmp_packet *rpl; - register char *src, *dst; - register u_char *size; - - rpl = &rconn->rmp; /* cache ptr to RMP packet */ - - /* - * Set up assorted fields in reply packet. - */ - rpl->r_brpl.rmp_type = RMP_BOOT_REPL; - rpl->r_brpl.rmp_retcode = RMP_E_OKAY; - ZEROWORD(rpl->r_brpl.rmp_seqno); - rpl->r_brpl.rmp_session = 0; - rpl->r_brpl.rmp_version = RMP_VERSION; - - size = &rpl->r_brpl.rmp_flnmsize; /* ptr to length of host name */ - - /* - * Copy our host name into the reply packet incrementing the - * length as we go. Stop at RMP_HOSTLEN or the first dot. - */ - src = MyHost; - dst = (char *) &rpl->r_brpl.rmp_flnm; - for (*size = 0; *size < RMP_HOSTLEN; (*size)++) { - if (*src == '.' || *src == '\0') - break; - *dst++ = *src++; - } - - rconn->rmplen = RMPBOOTSIZE(*size); /* set packet length */ - - return(SendPacket(rconn)); /* send packet */ -} - -/* -** SendFileNo -- send the name of a bootable file to the requester. -** -** Parameters: -** req - RMP BOOT packet containing the request. -** rconn - the reply packet to be formatted. -** filelist - list of files available to the requester. -** -** Returns: -** 1 on success, 0 on failure. -** -** Side Effects: -** none. -*/ -int -SendFileNo(req, rconn, filelist) - struct rmp_packet *req; - RMPCONN *rconn; - char *filelist[]; -{ - register struct rmp_packet *rpl; - register char *src, *dst; - register u_char *size, i; - - GETWORD(req->r_brpl.rmp_seqno, i); /* SeqNo is really FileNo */ - rpl = &rconn->rmp; /* cache ptr to RMP packet */ - - /* - * Set up assorted fields in reply packet. - */ - rpl->r_brpl.rmp_type = RMP_BOOT_REPL; - PUTWORD(i, rpl->r_brpl.rmp_seqno); - i--; - rpl->r_brpl.rmp_session = 0; - rpl->r_brpl.rmp_version = RMP_VERSION; - - size = &rpl->r_brpl.rmp_flnmsize; /* ptr to length of filename */ - *size = 0; /* init length to zero */ - - /* - * Copy the file name into the reply packet incrementing the - * length as we go. Stop at end of string or when RMPBOOTDATA - * characters have been copied. Also, set return code to - * indicate success or "no more files". - */ - if (i < C_MAXFILE && filelist[i] != NULL) { - src = filelist[i]; - dst = (char *)&rpl->r_brpl.rmp_flnm; - for (; *src && *size < RMPBOOTDATA; (*size)++) { - if (*src == '\0') - break; - *dst++ = *src++; - } - rpl->r_brpl.rmp_retcode = RMP_E_OKAY; - } else - rpl->r_brpl.rmp_retcode = RMP_E_NODFLT; - - rconn->rmplen = RMPBOOTSIZE(*size); /* set packet length */ - - return(SendPacket(rconn)); /* send packet */ -} - -/* -** SendBootRepl -- open boot file and respond to boot request. -** -** Parameters: -** req - RMP BOOT packet containing the request. -** rconn - the reply packet to be formatted. -** filelist - list of files available to the requester. -** -** Returns: -** 1 on success, 0 on failure. -** -** Side Effects: -** none. -*/ -int -SendBootRepl(req, rconn, filelist) - struct rmp_packet *req; - RMPCONN *rconn; - char *filelist[]; -{ - int retval; - char *filename, filepath[RMPBOOTDATA+1]; - RMPCONN *oldconn; - register struct rmp_packet *rpl; - register char *src, *dst1, *dst2; - register u_char i; - - /* - * If another connection already exists, delete it since we - * are obviously starting again. - */ - if ((oldconn = FindConn(rconn)) != NULL) { - syslog(LOG_WARNING, "%s: dropping existing connection", - EnetStr(oldconn)); - RemoveConn(oldconn); - } - - rpl = &rconn->rmp; /* cache ptr to RMP packet */ - - /* - * Set up assorted fields in reply packet. - */ - rpl->r_brpl.rmp_type = RMP_BOOT_REPL; - COPYWORD(req->r_brq.rmp_seqno, rpl->r_brpl.rmp_seqno); - rpl->r_brpl.rmp_session = GenSessID(); - rpl->r_brpl.rmp_version = RMP_VERSION; - rpl->r_brpl.rmp_flnmsize = req->r_brq.rmp_flnmsize; - - /* - * Copy file name to `filepath' string, and into reply packet. - */ - src = &req->r_brq.rmp_flnm; - dst1 = filepath; - dst2 = &rpl->r_brpl.rmp_flnm; - for (i = 0; i < req->r_brq.rmp_flnmsize; i++) - *dst1++ = *dst2++ = *src++; - *dst1 = '\0'; - - /* - * If we are booting HP-UX machines, their secondary loader will - * ask for files like "/hp-ux". As a security measure, we do not - * allow boot files to lay outside the boot directory (unless they - * are purposely link'd out. So, make `filename' become the path- - * stripped file name and spoof the client into thinking that it - * really got what it wanted. - */ - filename = (filename = rindex(filepath,'/'))? ++filename: filepath; - - /* - * Check that this is a valid boot file name. - */ - for (i = 0; i < C_MAXFILE && filelist[i] != NULL; i++) - if (STREQN(filename, filelist[i])) - goto match; - - /* - * Invalid boot file name, set error and send reply packet. - */ - rpl->r_brpl.rmp_retcode = RMP_E_NOFILE; - retval = 0; - goto sendpkt; - -match: - /* - * This is a valid boot file. Open the file and save the file - * descriptor associated with this connection and set success - * indication. If the file couldnt be opened, set error: - * "no such file or dir" - RMP_E_NOFILE - * "file table overflow" - RMP_E_BUSY - * "too many open files" - RMP_E_BUSY - * anything else - RMP_E_OPENFILE - */ - if ((rconn->bootfd = open(filename, O_RDONLY, 0600)) < 0) { - rpl->r_brpl.rmp_retcode = (errno == ENOENT)? RMP_E_NOFILE: - (errno == EMFILE || errno == ENFILE)? RMP_E_BUSY: - RMP_E_OPENFILE; - retval = 0; - } else { - rpl->r_brpl.rmp_retcode = RMP_E_OKAY; - retval = 1; - } - -sendpkt: - syslog(LOG_INFO, "%s: request to boot %s (%s)", - EnetStr(rconn), filename, retval? "granted": "denied"); - - rconn->rmplen = RMPBOOTSIZE(rpl->r_brpl.rmp_flnmsize); - - return (retval & SendPacket(rconn)); -} - -/* -** SendReadRepl -- send a portion of the boot file to the requester. -** -** Parameters: -** rconn - the reply packet to be formatted. -** -** Returns: -** 1 on success, 0 on failure. -** -** Side Effects: -** none. -*/ -int -SendReadRepl(rconn) - RMPCONN *rconn; -{ - int retval; - RMPCONN *oldconn; - register struct rmp_packet *rpl, *req; - register int size = 0; - int madeconn = 0; - - /* - * Find the old connection. If one doesnt exist, create one only - * to return the error code. - */ - if ((oldconn = FindConn(rconn)) == NULL) { - if ((oldconn = NewConn(rconn)) == NULL) - return(0); - syslog(LOG_ERR, "SendReadRepl: no active connection (%s)", - EnetStr(rconn)); - madeconn++; - } - - req = &rconn->rmp; /* cache ptr to request packet */ - rpl = &oldconn->rmp; /* cache ptr to reply packet */ - - if (madeconn) { /* no active connection above; abort */ - rpl->r_rrpl.rmp_retcode = RMP_E_ABORT; - retval = 1; - goto sendpkt; - } - - /* - * Make sure Session ID's match. - */ - if (req->r_rrq.rmp_session != - ((rpl->r_type == RMP_BOOT_REPL)? rpl->r_brpl.rmp_session: - rpl->r_rrpl.rmp_session)) { - syslog(LOG_ERR, "SendReadRepl: bad session id (%s)", - EnetStr(rconn)); - rpl->r_rrpl.rmp_retcode = RMP_E_BADSID; - retval = 1; - goto sendpkt; - } - - /* - * If the requester asks for more data than we can fit, - * silently clamp the request size down to RMPREADDATA. - * - * N.B. I do not know if this is "legal", however it seems - * to work. This is necessary for bpfwrite() on machines - * with MCLBYTES less than 1514. - */ - if (req->r_rrq.rmp_size > RMPREADDATA) - req->r_rrq.rmp_size = RMPREADDATA; - - /* - * Position read head on file according to info in request packet. - */ - GETWORD(req->r_rrq.rmp_offset, size); - if (lseek(oldconn->bootfd, (off_t)size, L_SET) < 0) { - syslog(LOG_ERR, "SendReadRepl: lseek: %m (%s)", - EnetStr(rconn)); - rpl->r_rrpl.rmp_retcode = RMP_E_ABORT; - retval = 1; - goto sendpkt; - } - - /* - * Read data directly into reply packet. - */ - if ((size = read(oldconn->bootfd, &rpl->r_rrpl.rmp_data, - (int) req->r_rrq.rmp_size)) <= 0) { - if (size < 0) { - syslog(LOG_ERR, "SendReadRepl: read: %m (%s)", - EnetStr(rconn)); - rpl->r_rrpl.rmp_retcode = RMP_E_ABORT; - } else { - rpl->r_rrpl.rmp_retcode = RMP_E_EOF; - } - retval = 1; - goto sendpkt; - } - - /* - * Set success indication. - */ - rpl->r_rrpl.rmp_retcode = RMP_E_OKAY; - -sendpkt: - /* - * Set up assorted fields in reply packet. - */ - rpl->r_rrpl.rmp_type = RMP_READ_REPL; - COPYWORD(req->r_rrq.rmp_offset, rpl->r_rrpl.rmp_offset); - rpl->r_rrpl.rmp_session = req->r_rrq.rmp_session; - - oldconn->rmplen = RMPREADSIZE(size); /* set size of packet */ - - retval &= SendPacket(oldconn); /* send packet */ - - if (madeconn) /* clean up after ourself */ - FreeConn(oldconn); - - return (retval); -} - -/* -** BootDone -- free up memory allocated for a connection. -** -** Parameters: -** rconn - incoming boot complete packet. -** -** Returns: -** 1 on success, 0 on failure. -** -** Side Effects: -** none. -*/ -int -BootDone(rconn) - RMPCONN *rconn; -{ - RMPCONN *oldconn; - struct rmp_packet *rpl; - - /* - * If we cant find the connection, ignore the request. - */ - if ((oldconn = FindConn(rconn)) == NULL) { - syslog(LOG_ERR, "BootDone: no existing connection (%s)", - EnetStr(rconn)); - return(0); - } - - rpl = &oldconn->rmp; /* cache ptr to RMP packet */ - - /* - * Make sure Session ID's match. - */ - if (rconn->rmp.r_rrq.rmp_session != - ((rpl->r_type == RMP_BOOT_REPL)? rpl->r_brpl.rmp_session: - rpl->r_rrpl.rmp_session)) { - syslog(LOG_ERR, "BootDone: bad session id (%s)", - EnetStr(rconn)); - return(0); - } - - RemoveConn(oldconn); /* remove connection */ - - syslog(LOG_INFO, "%s: boot complete", EnetStr(rconn)); - - return(1); -} - -/* -** SendPacket -- send an RMP packet to a remote host. -** -** Parameters: -** rconn - packet to be sent. -** -** Returns: -** 1 on success, 0 on failure. -** -** Side Effects: -** none. -*/ -int -SendPacket(rconn) - register RMPCONN *rconn; -{ - /* - * Set Ethernet Destination address to Source (BPF and the enet - * driver will take care of getting our source address set). - */ - bcopy((char *)&rconn->rmp.hp_hdr.saddr[0], - (char *)&rconn->rmp.hp_hdr.daddr[0], RMP_ADDRLEN); - rconn->rmp.hp_hdr.len = rconn->rmplen - sizeof(struct hp_hdr); - - /* - * Reverse 802.2/HP Extended Source & Destination Access Pts. - */ - rconn->rmp.hp_llc.dxsap = HPEXT_SXSAP; - rconn->rmp.hp_llc.sxsap = HPEXT_DXSAP; - - /* - * Last time this connection was active. - */ - (void) gettimeofday(&rconn->tstamp, (struct timezone *)0); - - if (DbgFp != NULL) /* display packet */ - DispPkt(rconn,DIR_SENT); - - /* - * Send RMP packet to remote host. - */ - return(BpfWrite(rconn)); -} diff --git a/libexec/rbootd/utils.c b/libexec/rbootd/utils.c deleted file mode 100644 index 58ead7c7144b..000000000000 --- a/libexec/rbootd/utils.c +++ /dev/null @@ -1,557 +0,0 @@ -/* - * Copyright (c) 1988, 1992 The University of Utah and the Center - * for Software Science (CSS). - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Center for Software Science of the University of Utah Computer - * Science Department. CSS requests users of this software to return - * to css-dist@cs.utah.edu any improvements that they make and grant - * CSS redistribution rights. - * - * 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. - * - * @(#)utils.c 8.2 (Berkeley) 2/22/94 - * - * Utah $Hdr: utils.c 3.1 92/07/06$ - * Author: Jeff Forys, University of Utah CSS - */ - -#ifndef lint -static char sccsid[] = "@(#)utils.c 8.2 (Berkeley) 2/22/94"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/time.h> - -#include <fcntl.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <time.h> -#include <unistd.h> -#include "defs.h" - -/* -** DispPkt -- Display the contents of an RMPCONN packet. -** -** Parameters: -** rconn - packet to be displayed. -** direct - direction packet is going (DIR_*). -** -** Returns: -** Nothing. -** -** Side Effects: -** None. -*/ -void -DispPkt(rconn, direct) - RMPCONN *rconn; - int direct; -{ - static char BootFmt[] = "\t\tRetCode:%u SeqNo:%lx SessID:%x Vers:%u"; - static char ReadFmt[] = "\t\tRetCode:%u Offset:%lx SessID:%x\n"; - - struct tm *tmp; - register struct rmp_packet *rmp; - int i, omask; - u_int t; - - /* - * Since we will be working with RmpConns as well as DbgFp, we - * must block signals that can affect either. - */ - omask = sigblock(sigmask(SIGHUP)|sigmask(SIGUSR1)|sigmask(SIGUSR2)); - - if (DbgFp == NULL) { /* sanity */ - (void) sigsetmask(omask); - return; - } - - /* display direction packet is going using '>>>' or '<<<' */ - fputs((direct==DIR_RCVD)?"<<< ":(direct==DIR_SENT)?">>> ":"", DbgFp); - - /* display packet timestamp */ - tmp = localtime((time_t *)&rconn->tstamp.tv_sec); - fprintf(DbgFp, "%02d:%02d:%02d.%06ld ", tmp->tm_hour, tmp->tm_min, - tmp->tm_sec, rconn->tstamp.tv_usec); - - /* display src or dst addr and information about network interface */ - fprintf(DbgFp, "Addr: %s Intf: %s\n", EnetStr(rconn), IntfName); - - rmp = &rconn->rmp; - - /* display IEEE 802.2 Logical Link Control header */ - (void) fprintf(DbgFp, "\t802.2 LLC: DSAP:%x SSAP:%x CTRL:%x\n", - rmp->hp_llc.dsap, rmp->hp_llc.ssap, rmp->hp_llc.cntrl); - - /* display HP extensions to 802.2 Logical Link Control header */ - (void) fprintf(DbgFp, "\tHP Ext: DXSAP:%x SXSAP:%x\n", - rmp->hp_llc.dxsap, rmp->hp_llc.sxsap); - - /* - * Display information about RMP packet using type field to - * determine what kind of packet this is. - */ - switch(rmp->r_type) { - case RMP_BOOT_REQ: /* boot request */ - (void) fprintf(DbgFp, "\tBoot Request:"); - GETWORD(rmp->r_brq.rmp_seqno, t); - if (rmp->r_brq.rmp_session == RMP_PROBESID) { - if (WORDZE(rmp->r_brq.rmp_seqno)) - fputs(" (Send Server ID)", DbgFp); - else - fprintf(DbgFp," (Send Filename #%u)",t); - } - (void) fputc('\n', DbgFp); - (void) fprintf(DbgFp, BootFmt, rmp->r_brq.rmp_retcode, - t, rmp->r_brq.rmp_session, - rmp->r_brq.rmp_version); - (void) fprintf(DbgFp, "\n\t\tMachine Type: "); - for (i = 0; i < RMP_MACHLEN; i++) - (void) fputc(rmp->r_brq.rmp_machtype[i], DbgFp); - DspFlnm(rmp->r_brq.rmp_flnmsize, &rmp->r_brq.rmp_flnm); - break; - case RMP_BOOT_REPL: /* boot reply */ - fprintf(DbgFp, "\tBoot Reply:\n"); - GETWORD(rmp->r_brpl.rmp_seqno, t); - (void) fprintf(DbgFp, BootFmt, rmp->r_brpl.rmp_retcode, - t, rmp->r_brpl.rmp_session, - rmp->r_brpl.rmp_version); - DspFlnm(rmp->r_brpl.rmp_flnmsize,&rmp->r_brpl.rmp_flnm); - break; - case RMP_READ_REQ: /* read request */ - (void) fprintf(DbgFp, "\tRead Request:\n"); - GETWORD(rmp->r_rrq.rmp_offset, t); - (void) fprintf(DbgFp, ReadFmt, rmp->r_rrq.rmp_retcode, - t, rmp->r_rrq.rmp_session); - (void) fprintf(DbgFp, "\t\tNoOfBytes: %u\n", - rmp->r_rrq.rmp_size); - break; - case RMP_READ_REPL: /* read reply */ - (void) fprintf(DbgFp, "\tRead Reply:\n"); - GETWORD(rmp->r_rrpl.rmp_offset, t); - (void) fprintf(DbgFp, ReadFmt, rmp->r_rrpl.rmp_retcode, - t, rmp->r_rrpl.rmp_session); - (void) fprintf(DbgFp, "\t\tNoOfBytesSent: %d\n", - rconn->rmplen - RMPREADSIZE(0)); - break; - case RMP_BOOT_DONE: /* boot complete */ - (void) fprintf(DbgFp, "\tBoot Complete:\n"); - (void) fprintf(DbgFp, "\t\tRetCode:%u SessID:%x\n", - rmp->r_done.rmp_retcode, - rmp->r_done.rmp_session); - break; - default: /* ??? */ - (void) fprintf(DbgFp, "\tUnknown Type:(%d)\n", - rmp->r_type); - } - (void) fputc('\n', DbgFp); - (void) fflush(DbgFp); - - (void) sigsetmask(omask); /* reset old signal mask */ -} - - -/* -** GetEtherAddr -- convert an RMP (Ethernet) address into a string. -** -** An RMP BOOT packet has been received. Look at the type field -** and process Boot Requests, Read Requests, and Boot Complete -** packets. Any other type will be dropped with a warning msg. -** -** Parameters: -** addr - array of RMP_ADDRLEN bytes. -** -** Returns: -** Pointer to static string representation of `addr'. -** -** Side Effects: -** None. -** -** Warnings: -** - The return value points to a static buffer; it must -** be copied if it's to be saved. -** - For speed, we assume a u_char consists of 8 bits. -*/ -char * -GetEtherAddr(addr) - u_char *addr; -{ - static char Hex[] = "0123456789abcdef"; - static char etherstr[RMP_ADDRLEN*3]; - register int i; - register char *cp1, *cp2; - - /* - * For each byte in `addr', convert it to "<hexchar><hexchar>:". - * The last byte does not get a trailing `:' appended. - */ - i = 0; - cp1 = (char *)addr; - cp2 = etherstr; - for(;;) { - *cp2++ = Hex[*cp1 >> 4 & 0xf]; - *cp2++ = Hex[*cp1++ & 0xf]; - if (++i == RMP_ADDRLEN) - break; - *cp2++ = ':'; - } - *cp2 = '\0'; - - return(etherstr); -} - - -/* -** DispFlnm -- Print a string of bytes to DbgFp (often, a file name). -** -** Parameters: -** size - number of bytes to print. -** flnm - address of first byte. -** -** Returns: -** Nothing. -** -** Side Effects: -** - Characters are sent to `DbgFp'. -*/ -void -DspFlnm(size, flnm) - register u_int size; - register char *flnm; -{ - register int i; - - (void) fprintf(DbgFp, "\n\t\tFile Name (%d): <", size); - for (i = 0; i < size; i++) - (void) fputc(*flnm++, DbgFp); - (void) fputs(">\n", DbgFp); -} - - -/* -** NewClient -- allocate memory for a new CLIENT. -** -** Parameters: -** addr - RMP (Ethernet) address of new client. -** -** Returns: -** Ptr to new CLIENT or NULL if we ran out of memory. -** -** Side Effects: -** - Memory will be malloc'd for the new CLIENT. -** - If malloc() fails, a log message will be generated. -*/ -CLIENT * -NewClient(addr) - u_char *addr; -{ - CLIENT *ctmp; - - if ((ctmp = (CLIENT *) malloc(sizeof(CLIENT))) == NULL) { - syslog(LOG_ERR, "NewClient: out of memory (%s)", - GetEtherAddr(addr)); - return(NULL); - } - - bzero(ctmp, sizeof(CLIENT)); - bcopy(addr, &ctmp->addr[0], RMP_ADDRLEN); - return(ctmp); -} - -/* -** FreeClient -- free linked list of Clients. -** -** Parameters: -** None. -** -** Returns: -** Nothing. -** -** Side Effects: -** - All malloc'd memory associated with the linked list of -** CLIENTS will be free'd; `Clients' will be set to NULL. -** -** Warnings: -** - This routine must be called with SIGHUP blocked. -*/ -void -FreeClients() -{ - register CLIENT *ctmp; - - while (Clients != NULL) { - ctmp = Clients; - Clients = Clients->next; - FreeClient(ctmp); - } -} - -/* -** NewStr -- allocate memory for a character array. -** -** Parameters: -** str - null terminated character array. -** -** Returns: -** Ptr to new character array or NULL if we ran out of memory. -** -** Side Effects: -** - Memory will be malloc'd for the new character array. -** - If malloc() fails, a log message will be generated. -*/ -char * -NewStr(str) - char *str; -{ - char *stmp; - - if ((stmp = (char *)malloc((unsigned) (strlen(str)+1))) == NULL) { - syslog(LOG_ERR, "NewStr: out of memory (%s)", str); - return(NULL); - } - - (void) strcpy(stmp, str); - return(stmp); -} - -/* -** To save time, NewConn and FreeConn maintain a cache of one RMPCONN -** in `LastFree' (defined below). -*/ - -static RMPCONN *LastFree = NULL; - -/* -** NewConn -- allocate memory for a new RMPCONN connection. -** -** Parameters: -** rconn - initialization template for new connection. -** -** Returns: -** Ptr to new RMPCONN or NULL if we ran out of memory. -** -** Side Effects: -** - Memory may be malloc'd for the new RMPCONN (if not cached). -** - If malloc() fails, a log message will be generated. -*/ -RMPCONN * -NewConn(rconn) - RMPCONN *rconn; -{ - RMPCONN *rtmp; - - if (LastFree == NULL) { /* nothing cached; make a new one */ - if ((rtmp = (RMPCONN *) malloc(sizeof(RMPCONN))) == NULL) { - syslog(LOG_ERR, "NewConn: out of memory (%s)", - EnetStr(rconn)); - return(NULL); - } - } else { /* use the cached RMPCONN */ - rtmp = LastFree; - LastFree = NULL; - } - - /* - * Copy template into `rtmp', init file descriptor to `-1' and - * set ptr to next elem NULL. - */ - bcopy((char *)rconn, (char *)rtmp, sizeof(RMPCONN)); - rtmp->bootfd = -1; - rtmp->next = NULL; - - return(rtmp); -} - -/* -** FreeConn -- Free memory associated with an RMPCONN connection. -** -** Parameters: -** rtmp - ptr to RMPCONN to be free'd. -** -** Returns: -** Nothing. -** -** Side Effects: -** - Memory associated with `rtmp' may be free'd (or cached). -** - File desc associated with `rtmp->bootfd' will be closed. -*/ -void -FreeConn(rtmp) - register RMPCONN *rtmp; -{ - /* - * If the file descriptor is in use, close the file. - */ - if (rtmp->bootfd >= 0) { - (void) close(rtmp->bootfd); - rtmp->bootfd = -1; - } - - if (LastFree == NULL) /* cache for next time */ - rtmp = LastFree; - else /* already one cached; free this one */ - free((char *)rtmp); -} - -/* -** FreeConns -- free linked list of RMPCONN connections. -** -** Parameters: -** None. -** -** Returns: -** Nothing. -** -** Side Effects: -** - All malloc'd memory associated with the linked list of -** connections will be free'd; `RmpConns' will be set to NULL. -** - If LastFree is != NULL, it too will be free'd & NULL'd. -** -** Warnings: -** - This routine must be called with SIGHUP blocked. -*/ -void -FreeConns() -{ - register RMPCONN *rtmp; - - while (RmpConns != NULL) { - rtmp = RmpConns; - RmpConns = RmpConns->next; - FreeConn(rtmp); - } - - if (LastFree != NULL) { - free((char *)LastFree); - LastFree = NULL; - } -} - -/* -** AddConn -- Add a connection to the linked list of connections. -** -** Parameters: -** rconn - connection to be added. -** -** Returns: -** Nothing. -** -** Side Effects: -** - RmpConn will point to new connection. -** -** Warnings: -** - This routine must be called with SIGHUP blocked. -*/ -void -AddConn(rconn) - register RMPCONN *rconn; -{ - if (RmpConns != NULL) - rconn->next = RmpConns; - RmpConns = rconn; -} - -/* -** FindConn -- Find a connection in the linked list of connections. -** -** We use the RMP (Ethernet) address as the basis for determining -** if this is the same connection. According to the Remote Maint -** Protocol, we can only have one connection with any machine. -** -** Parameters: -** rconn - connection to be found. -** -** Returns: -** Matching connection from linked list or NULL if not found. -** -** Side Effects: -** None. -** -** Warnings: -** - This routine must be called with SIGHUP blocked. -*/ -RMPCONN * -FindConn(rconn) - register RMPCONN *rconn; -{ - register RMPCONN *rtmp; - - for (rtmp = RmpConns; rtmp != NULL; rtmp = rtmp->next) - if (bcmp((char *)&rconn->rmp.hp_hdr.saddr[0], - (char *)&rtmp->rmp.hp_hdr.saddr[0], RMP_ADDRLEN) == 0) - break; - - return(rtmp); -} - -/* -** RemoveConn -- Remove a connection from the linked list of connections. -** -** Parameters: -** rconn - connection to be removed. -** -** Returns: -** Nothing. -** -** Side Effects: -** - If found, an RMPCONN will cease to exist and it will -** be removed from the linked list. -** -** Warnings: -** - This routine must be called with SIGHUP blocked. -*/ -void -RemoveConn(rconn) - register RMPCONN *rconn; -{ - register RMPCONN *thisrconn, *lastrconn; - - if (RmpConns == rconn) { /* easy case */ - RmpConns = RmpConns->next; - FreeConn(rconn); - } else { /* must traverse linked list */ - lastrconn = RmpConns; /* set back ptr */ - thisrconn = lastrconn->next; /* set current ptr */ - while (thisrconn != NULL) { - if (rconn == thisrconn) { /* found it */ - lastrconn->next = thisrconn->next; - FreeConn(thisrconn); - break; - } - lastrconn = thisrconn; - thisrconn = thisrconn->next; - } - } -} diff --git a/libexec/rpc.rquotad/Makefile b/libexec/rpc.rquotad/Makefile deleted file mode 100644 index 7618d98f4a48..000000000000 --- a/libexec/rpc.rquotad/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# $Id: Makefile,v 1.3 1995/04/12 00:47:27 jtc Exp $ - -PROG = rpc.rquotad -SRCS = rquotad.c -MAN8 = rpc.rquotad.8 - -DPADD= ${LIBRPCSVC} -LDADD= -lrpcsvc - -.include <bsd.prog.mk> diff --git a/libexec/rpc.rquotad/rpc.rquotad.8 b/libexec/rpc.rquotad/rpc.rquotad.8 deleted file mode 100644 index b378cc33f47d..000000000000 --- a/libexec/rpc.rquotad/rpc.rquotad.8 +++ /dev/null @@ -1,58 +0,0 @@ -.\" -.\" Copyright (c) 1994 Theo de Raadt -.\" 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 Theo de Raadt. -.\" 4. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. -.\" -.\" $Id: rpc.rquotad.8,v 1.2 1995/04/12 00:47:32 jtc Exp $ -.\" -.Dd June 22, 1994 -.Dt RPC.RQUOTAD 8 -.Os BSD 4.3 -.Sh NAME -.Nm rpc.rquotad -.Nd remote quota server -.Sh SYNOPSIS -.Nm /usr/libexec/rpc.rquotad -.Sh DESCRIPTION -.Nm rpc.rquotad -is a -.Xr rpc 3 -server which returns quotas for a user of a local filesystem -which is NFS-mounted onto a remote machine. -.Xr quota 1 -uses the results to display user quotas for remote filesystems. -.Nm rpc.rquotad -is normally invoked by -.Xr inetd 8 . -.Pp -.Nm rpc.rquotad -uses an RPC protocol defined in -.Pa /usr/include/rpcsvc/rquota.x . -.Sh BUGS -BSD 4.4 and NetBSD support group quotas but the rquota protocol does not. -.Sh SEE ALSO -.Xr quota 1 diff --git a/libexec/rpc.rquotad/rquotad.c b/libexec/rpc.rquotad/rquotad.c deleted file mode 100644 index 33fa420b17f4..000000000000 --- a/libexec/rpc.rquotad/rquotad.c +++ /dev/null @@ -1,331 +0,0 @@ -/* - * by Manuel Bouyer (bouyer@ensta.fr) - * - * There is no copyright, you can use it as you want. - */ - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/mount.h> -#include <sys/file.h> -#include <sys/stat.h> -#include <sys/socket.h> -#include <signal.h> - -#include <stdio.h> -#include <fstab.h> -#include <ctype.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <pwd.h> -#include <grp.h> -#include <errno.h> - -#include <syslog.h> -#include <varargs.h> - -#include <ufs/ufs/quota.h> -#include <rpc/rpc.h> -#include <rpc/pmap_clnt.h> -#include <rpcsvc/rquota.h> -#include <arpa/inet.h> - -void rquota_service __P((struct svc_req *request, SVCXPRT *transp)); -void sendquota __P((struct svc_req *request, SVCXPRT *transp)); -void printerr_reply __P((SVCXPRT *transp)); -void initfs __P((void)); -int getfsquota __P((long id, char *path, struct dqblk *dqblk)); -int hasquota __P((struct fstab *fs, char **qfnamep)); - -/* - * structure containing informations about ufs filesystems - * initialised by initfs() - */ -struct fs_stat { - struct fs_stat *fs_next; /* next element */ - char *fs_file; /* mount point of the filesystem */ - char *qfpathname; /* pathname of the quota file */ - dev_t st_dev; /* device of the filesystem */ -} fs_stat; -struct fs_stat *fs_begin = NULL; - -int from_inetd = 1; - -void -cleanup() -{ - (void) pmap_unset(RQUOTAPROG, RQUOTAVERS); - exit(0); -} - -int -main(argc, argv) - int argc; - char *argv[]; -{ - SVCXPRT *transp; - int sock = 0; - int proto = 0; - struct sockaddr_in from; - int fromlen; - - fromlen = sizeof(from); - if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) { - from_inetd = 0; - sock = RPC_ANYSOCK; - proto = IPPROTO_UDP; - } - - if (!from_inetd) { - daemon(0, 0); - - (void) pmap_unset(RQUOTAPROG, RQUOTAVERS); - - (void) signal(SIGINT, cleanup); - (void) signal(SIGTERM, cleanup); - (void) signal(SIGHUP, cleanup); - } - - openlog("rpc.rquotad", LOG_CONS|LOG_PID, LOG_DAEMON); - - /* create and register the service */ - transp = svcudp_create(sock); - if (transp == NULL) { - syslog(LOG_ERR, "couldn't create udp service."); - exit(1); - } - if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquota_service, proto)) { - syslog(LOG_ERR, "unable to register (RQUOTAPROG, RQUOTAVERS, %s).", proto?"udp":"(inetd)"); - exit(1); - } - - initfs(); /* init the fs_stat list */ - svc_run(); - syslog(LOG_ERR, "svc_run returned"); - exit(1); -} - -void -rquota_service(request, transp) - struct svc_req *request; - SVCXPRT *transp; -{ - switch (request->rq_proc) { - case NULLPROC: - (void)svc_sendreply(transp, xdr_void, (char *)NULL); - break; - - case RQUOTAPROC_GETQUOTA: - case RQUOTAPROC_GETACTIVEQUOTA: - sendquota(request, transp); - break; - - default: - svcerr_noproc(transp); - break; - } - if (from_inetd) - exit(0); -} - -/* read quota for the specified id, and send it */ -void -sendquota(request, transp) - struct svc_req *request; - SVCXPRT *transp; -{ - struct getquota_args getq_args; - struct getquota_rslt getq_rslt; - struct dqblk dqblk; - struct timeval timev; - - bzero((char *)&getq_args, sizeof(getq_args)); - if (!svc_getargs(transp, xdr_getquota_args, (caddr_t)&getq_args)) { - svcerr_decode(transp); - return; - } - if (request->rq_cred.oa_flavor != AUTH_UNIX) { - /* bad auth */ - getq_rslt.status = Q_EPERM; - } else if (!getfsquota(getq_args.gqa_uid, getq_args.gqa_pathp, &dqblk)) { - /* failed, return noquota */ - getq_rslt.status = Q_NOQUOTA; - } else { - gettimeofday(&timev, NULL); - getq_rslt.status = Q_OK; - getq_rslt.getquota_rslt_u.gqr_rquota.rq_active = TRUE; - getq_rslt.getquota_rslt_u.gqr_rquota.rq_bsize = DEV_BSIZE; - getq_rslt.getquota_rslt_u.gqr_rquota.rq_bhardlimit = - dqblk.dqb_bhardlimit; - getq_rslt.getquota_rslt_u.gqr_rquota.rq_bsoftlimit = - dqblk.dqb_bsoftlimit; - getq_rslt.getquota_rslt_u.gqr_rquota.rq_curblocks = - dqblk.dqb_curblocks; - getq_rslt.getquota_rslt_u.gqr_rquota.rq_fhardlimit = - dqblk.dqb_ihardlimit; - getq_rslt.getquota_rslt_u.gqr_rquota.rq_fsoftlimit = - dqblk.dqb_isoftlimit; - getq_rslt.getquota_rslt_u.gqr_rquota.rq_curfiles = - dqblk.dqb_curinodes; - getq_rslt.getquota_rslt_u.gqr_rquota.rq_btimeleft = - dqblk.dqb_btime - timev.tv_sec; - getq_rslt.getquota_rslt_u.gqr_rquota.rq_ftimeleft = - dqblk.dqb_itime - timev.tv_sec; - } - if (!svc_sendreply(transp, xdr_getquota_rslt, (char *)&getq_rslt)) { - svcerr_systemerr(transp); - } - if (!svc_freeargs(transp, xdr_getquota_args, (caddr_t)&getq_args)) { - syslog(LOG_ERR, "unable to free arguments"); - exit(1); - } -} - -void -printerr_reply(transp) /* when a reply to a request failed */ - SVCXPRT *transp; -{ - char *name; - struct sockaddr_in *caller; - int save_errno; - - save_errno = errno; - - caller = svc_getcaller(transp); - name = (char *)inet_ntoa(caller->sin_addr); - errno = save_errno; - if (errno == 0) - syslog(LOG_ERR, "couldn't send reply to %s", name); - else - syslog(LOG_ERR, "couldn't send reply to %s: %m", name); -} - -/* initialise the fs_tab list from entries in /etc/fstab */ -void -initfs() -{ - struct fs_stat *fs_current = NULL; - struct fs_stat *fs_next = NULL; - char *qfpathname; - struct fstab *fs; - struct stat st; - - setfsent(); - while ((fs = getfsent())) { - if (strcmp(fs->fs_vfstype, "ufs")) - continue; - if (!hasquota(fs, &qfpathname)) - continue; - - fs_current = (struct fs_stat *) malloc(sizeof(struct fs_stat)); - fs_current->fs_next = fs_next; /* next element */ - - fs_current->fs_file = malloc(sizeof(char) * (strlen(fs->fs_file) + 1)); - strcpy(fs_current->fs_file, fs->fs_file); - - fs_current->qfpathname = malloc(sizeof(char) * (strlen(qfpathname) + 1)); - strcpy(fs_current->qfpathname, qfpathname); - - stat(qfpathname, &st); - fs_current->st_dev = st.st_dev; - - fs_next = fs_current; - } - endfsent(); - fs_begin = fs_current; -} - -/* - * gets the quotas for id, filesystem path. - * Return 0 if fail, 1 otherwise - */ -int -getfsquota(id, path, dqblk) - long id; - char *path; - struct dqblk *dqblk; -{ - struct stat st_path; - struct fs_stat *fs; - int qcmd, fd, ret = 0; - - if (stat(path, &st_path) < 0) - return (0); - - qcmd = QCMD(Q_GETQUOTA, USRQUOTA); - - for (fs = fs_begin; fs != NULL; fs = fs->fs_next) { - /* where the devise is the same as path */ - if (fs->st_dev != st_path.st_dev) - continue; - - /* find the specified filesystem. get and return quota */ - if (quotactl(fs->fs_file, qcmd, id, dqblk) == 0) - return (1); - - if ((fd = open(fs->qfpathname, O_RDONLY)) < 0) { - syslog(LOG_ERR, "open error: %s: %m", fs->qfpathname); - return (0); - } - if (lseek(fd, (off_t)(id * sizeof(struct dqblk)), L_SET) == (off_t)-1) { - close(fd); - return (1); - } - switch (read(fd, dqblk, sizeof(struct dqblk))) { - case 0: - /* - * Convert implicit 0 quota (EOF) - * into an explicit one (zero'ed dqblk) - */ - bzero((caddr_t) dqblk, sizeof(struct dqblk)); - ret = 1; - break; - case sizeof(struct dqblk): /* OK */ - ret = 1; - break; - default: /* ERROR */ - syslog(LOG_ERR, "read error: %s: %m", fs->qfpathname); - close(fd); - return (0); - } - close(fd); - } - return (ret); -} - -/* - * Check to see if a particular quota is to be enabled. - * Comes from quota.c, NetBSD 0.9 - */ -int -hasquota(fs, qfnamep) - struct fstab *fs; - char **qfnamep; -{ - static char initname, usrname[100]; - static char buf[BUFSIZ]; - char *opt, *cp; - char *qfextension[] = INITQFNAMES; - - if (!initname) { - sprintf(usrname, "%s%s", qfextension[USRQUOTA], QUOTAFILENAME); - initname = 1; - } - strcpy(buf, fs->fs_mntops); - for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) { - if ((cp = index(opt, '='))) - *cp++ = '\0'; - if (strcmp(opt, usrname) == 0) - break; - } - if (!opt) - return (0); - if (cp) { - *qfnamep = cp; - return (1); - } - sprintf(buf, "%s/%s.%s", fs->fs_file, QUOTAFILENAME, qfextension[USRQUOTA]); - *qfnamep = buf; - return (1); -} diff --git a/libexec/rpc.sprayd/Makefile b/libexec/rpc.sprayd/Makefile deleted file mode 100644 index e497599a8451..000000000000 --- a/libexec/rpc.sprayd/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $Id: Makefile,v 1.3 1995/04/12 00:48:01 jtc Exp $ - -PROG = rpc.sprayd -SRCS = sprayd.c -MAN8 = rpc.sprayd.8 - -DPADD= ${LIBRPCSVC} -LDADD= -lrpcsvc - -.include <bsd.prog.mk> - diff --git a/libexec/rpc.sprayd/rpc.sprayd.8 b/libexec/rpc.sprayd/rpc.sprayd.8 deleted file mode 100644 index cff47264ca97..000000000000 --- a/libexec/rpc.sprayd/rpc.sprayd.8 +++ /dev/null @@ -1,54 +0,0 @@ -.\" -.\" Copyright (c) 1994 Christos Zoulas -.\" 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 Christos Zoulas. -.\" 4. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. -.\" -.\" $Id: rpc.sprayd.8,v 1.2 1995/04/12 00:48:03 jtc Exp $ -.\" -.Dd June 22, 1994 -.Dt RPC.SPRAYD 8 -.Os BSD 4.3 -.Sh NAME -.Nm rpc.sprayd -.Nd spray server -.Sh SYNOPSIS -.Nm /usr/libexec/rpc.sprayd -.Sh DESCRIPTION -.Nm rpc.sprayd -is a server which records packets sent by the -.Xr spray 1 -command and sends a traffic report to the originator of the packets. -The -.Nm rpc.sprayd -daemon is normally invoked by -.Xr inetd 8 . -.Pp -.Nm rpc.sprayd -uses an RPC protocol defined in -.Pa /usr/include/rpcsvc/spray.x . -.Sh SEE ALSO -.Xr spray 8 diff --git a/libexec/rpc.sprayd/sprayd.c b/libexec/rpc.sprayd/sprayd.c deleted file mode 100644 index 28ae295fad05..000000000000 --- a/libexec/rpc.sprayd/sprayd.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 1994 Christos Zoulas - * 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 Christos Zoulas. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - * - * $Id: sprayd.c,v 1.7 1995/03/26 23:36:44 mycroft Exp $ - */ - -#ifndef lint -static char rcsid[] = "$Id: sprayd.c,v 1.7 1995/03/26 23:36:44 mycroft Exp $"; -#endif /* not lint */ - -#include <stdio.h> -#include <stdlib.h> -#include <signal.h> -#include <unistd.h> -#include <rpc/rpc.h> -#include <rpc/pmap_clnt.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <syslog.h> -#include <rpcsvc/spray.h> - -static void spray_service __P((struct svc_req *, SVCXPRT *)); - -static int from_inetd = 1; - -#define timersub(tvp, uvp, vvp) \ - do { \ - (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ - (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ - if ((vvp)->tv_usec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_usec += 1000000; \ - } \ - } while (0) - -#define TIMEOUT 120 - -void -cleanup() -{ - (void) pmap_unset(SPRAYPROG, SPRAYVERS); - exit(0); -} - -void -die() -{ - exit(0); -} - -int -main(argc, argv) - int argc; - char *argv[]; -{ - SVCXPRT *transp; - int sock = 0; - int proto = 0; - struct sockaddr_in from; - int fromlen; - - /* - * See if inetd started us - */ - fromlen = sizeof(from); - if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) { - from_inetd = 0; - sock = RPC_ANYSOCK; - proto = IPPROTO_UDP; - } - - if (!from_inetd) { - daemon(0, 0); - - (void) pmap_unset(SPRAYPROG, SPRAYVERS); - - (void) signal(SIGINT, cleanup); - (void) signal(SIGTERM, cleanup); - (void) signal(SIGHUP, cleanup); - } else { - (void) signal(SIGALRM, die); - alarm(TIMEOUT); - } - - openlog("rpc.sprayd", LOG_CONS|LOG_PID, LOG_DAEMON); - - transp = svcudp_create(sock); - if (transp == NULL) { - syslog(LOG_ERR, "cannot create udp service."); - return 1; - } - if (!svc_register(transp, SPRAYPROG, SPRAYVERS, spray_service, proto)) { - syslog(LOG_ERR, - "unable to register (SPRAYPROG, SPRAYVERS, %s).", - proto ? "udp" : "(inetd)"); - return 1; - } - - svc_run(); - syslog(LOG_ERR, "svc_run returned"); - return 1; -} - - -static void -spray_service(rqstp, transp) - struct svc_req *rqstp; - SVCXPRT *transp; -{ - static spraycumul scum; - static struct timeval clear, get; - - switch (rqstp->rq_proc) { - case SPRAYPROC_CLEAR: - scum.counter = 0; - (void) gettimeofday(&clear, 0); - /*FALLTHROUGH*/ - - case NULLPROC: - (void)svc_sendreply(transp, xdr_void, (char *)NULL); - return; - - case SPRAYPROC_SPRAY: - scum.counter++; - return; - - case SPRAYPROC_GET: - (void) gettimeofday(&get, 0); - timersub(&get, &clear, &get); - scum.clock.sec = get.tv_sec; - scum.clock.usec = get.tv_usec; - break; - - default: - svcerr_noproc(transp); - return; - } - - if (!svc_sendreply(transp, xdr_spraycumul, (caddr_t)&scum)) { - svcerr_systemerr(transp); - syslog(LOG_ERR, "bad svc_sendreply"); - } -} diff --git a/sbin/fsdb/Makefile b/sbin/fsdb/Makefile deleted file mode 100644 index 381b81783ad4..000000000000 --- a/sbin/fsdb/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $NetBSD: Makefile,v 1.1.1.1 1995/10/08 23:08:36 thorpej Exp $ -# @(#)Makefile 8.1 (Berkeley) 6/5/93 - -PROG= fsdb -MAN= fsdb.8 -SRCS= fsdb.c fsdbutil.c \ - dir.c inode.c pass1.c pass1b.c pass2.c pass3.c pass4.c \ - pass5.c preen.c setup.c utilities.c ffs_subr.c ffs_tables.c -CFLAGS+= -I${.CURDIR}/../../sbin/fsck -LDADD+= -ledit -ltermcap -.PATH: ${.CURDIR}/../../sbin/fsck ${.CURDIR}/../../sys/ufs/ffs - -.include <bsd.prog.mk> diff --git a/sbin/fsdb/fsdb.8 b/sbin/fsdb/fsdb.8 deleted file mode 100644 index a44d191d7a83..000000000000 --- a/sbin/fsdb/fsdb.8 +++ /dev/null @@ -1,228 +0,0 @@ -.\" $NetBSD: fsdb.8,v 1.2 1995/10/08 23:18:08 thorpej Exp $ -.\" -.\" Copyright (c) 1995 John T. Kohl -.\" 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. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 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. -.\" -.Dd September 14, 1995 -.Dt FSDB 8 -.Os NetBSD -.Sh NAME -.Nm fsdb -.Nd FFS debugging/editing tool -.Sh SYNOPSIS -.Nm -.Op Fl d -.Fl f Ar fsname -.Sh DESCRIPTION -.Nm -opens -.Ar fsname -(usually a raw disk partition) and runs a command loop -allowing manipulation of the file system's inode data. You are prompted -to enter a command with -.Ic "fsdb (inum X)>" -where -.Va X -is the currently selected i-number. The initial selected inode is the -root of the filesystem (i-number 2). -The command processor uses the -.Xr libedit 3 -library, so you can use command line editing to reduce typing if desired. -When you exit the command loop, the file system superblock is marked -dirty and any buffered blocks are written to the file system. -.Pp -The -.Fl d -option enables additional debugging output (which comes primarily from -.Xr fsck 8 -derived -code). -.Sh COMMANDS -Besides the built-in -.Xr libedit 3 -commands, -.Nm -supports these commands: -.Pp -.Bl -tag -width indent -compact -.It Cm help -Print out the list of accepted commands. -.Pp -.It Cm inode Ar i-number -Select inode -.Ar i-number -as the new current inode. -.Pp -.It Cm back -Revert to the previously current inode. -.Pp -.It Cm clri -Clear the current inode. -.Pp -.It Cm lookup Ar name -.It Cm cd Ar name -Find -.Ar name -in the current directory and make its inode the current inode. -.Ar Name -may be a multi-component name or may begin with slash to indicate that -the root inode should be used to start the lookup. If some component -along the pathname is not found, the last valid directory encountered is -left as the active inode. -.br -This command is valid only if the starting inode is a directory. -.Pp -.It Cm active -.It Cm print -Print out the active inode. -.Pp -.It Cm uplink -Increment the active inode's link count. -.Pp -.It Cm downlink -Decrement the active inode's link count. -.Pp -.It Cm linkcount Ar number -Set the active inode's link count to -.Ar number . -.Pp -.It Cm ls -List the current inode's directory entries. This command is valid only -if the current inode is a directory. -.Pp -.It Cm rm Ar name -.It Cm del Ar name -Remove the entry -.Ar name -from the current directory inode. This command is valid only -if the current inode is a directory. -.Pp -.It Cm ln Ar ino Ar name -Create a link to inode -.Ar ino -under the name -.Ar name -in the current directory inode. This command is valid only -if the current inode is a directory. -.Pp -.It Cm chinum Ar dirslot Ar inum -Change the i-number in directory entry -.Ar dirslot -to -.Ar inum . -.Pp -.It Cm chname Ar dirslot Ar name -Change the name in directory entry -.Ar dirslot -to -.Ar name . -This command cannot expand a directory entry. You can only rename an -entry if the name will fit into the existing directory slot. -.Pp -.It Cm chtype Ar type -Change the type of the current inode to -.Ar type . -.Ar type -may be one of: -.Em file , -.Em dir , -.Em socket , -or -.Em fifo . -.Pp -.It Cm chmod Ar mode -Change the mode bits of the current inode to -.Ar mode . -You cannot change the file type with this subcommand; use -.Ic chtype -to do that. -.Pp -.It Cm chflags Ar flags -Change the file flags of the current inode to -.Ar flags . -.Pp -.It Cm chown Ar uid -Change the owner of the current inode to -.Ar uid . -.Pp -.It Cm chgrp Ar gid -Change the group of the current inode to -.Ar gid . -.Pp -.It Cm chgen Ar gen -Change the generation number of the current inode to -.Ar gen . -.Pp -.It Cm mtime Ar time -.It Cm ctime Ar time -.It Cm atime Ar time -Change the modification, change, or access time (respectively) on the -current inode to -.Ar time . -.Ar Time -should be in the format -.Em YYYYMMDDHHMMSS[.nsec] -where -.Em nsec -is an optional nanosecond specification. If no nanoseconds are specified, the -.Va mtimensec , -.Va ctimensec , -or -.Va atimensec -field will be set to zero. -.Pp -.It Cm quit, Cm q, Cm exit, Em <EOF> -Exit the program. -.El -.Sh SEE ALSO -.Xr libedit 3 , -.Xr fs 5 , -.Xr fsck 8 , -.Xr clri 8 . -.Sh BUGS -Manipulation of ``short'' symlinks doesn't work (in particular, don't -try changing a symlink's type). -.br -You must specify modes as numbers rather than symbolic names. -.br -There are a bunch of other things that you might want to do which -.Nm -doesn't implement. -.br -The -.Xr libedit 3 -reference page is not yet written. -.Sh HISTORY -.Nm -uses the source code for -.Xr fsck 8 -to implement most of the file system manipulation code. The remainder of -.Nm -first appeared in NetBSD. -.Sh WARNING -Use this tool with extreme caution--you can damage an FFS file system -beyond what -.Xr fsck 8 -can repair. diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c deleted file mode 100644 index 8a5ad7b3ddc2..000000000000 --- a/sbin/fsdb/fsdb.c +++ /dev/null @@ -1,865 +0,0 @@ -/* $NetBSD: fsdb.c,v 1.2 1995/10/08 23:18:10 thorpej Exp $ */ - -/* - * Copyright (c) 1995 John T. Kohl - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 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 rcsid[] = "$NetBSD: fsdb.c,v 1.2 1995/10/08 23:18:10 thorpej Exp $"; -#endif /* not lint */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/param.h> -#include <sys/time.h> -#include <sys/mount.h> -#include <ctype.h> -#include <fcntl.h> -#include <grp.h> -#include <histedit.h> -#include <limits.h> -#include <pwd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <ufs/ufs/dinode.h> -#include <ufs/ufs/dir.h> -#include <ufs/ffs/fs.h> - -#include "fsdb.h" -#include "fsck.h" - -extern char *__progname; /* from crt0.o */ - -void usage __P((void)); -int cmdloop __P((void)); - -void -usage() -{ - errx(1, "usage: %s [-d] -f <fsname>", __progname); -} - -int returntosingle = 0; - -/* - * We suck in lots of fsck code, and just pick & choose the stuff we want. - * - * fsreadfd is set up to read from the file system, fswritefd to write to - * the file system. - */ -void -main(argc, argv) - int argc; - char *argv[]; -{ - int ch, rval; - char *fsys = NULL; - struct stat stb; - - while (-1 != (ch = getopt(argc, argv, "f:d"))) { - switch (ch) { - case 'f': - fsys = optarg; - break; - case 'd': - debug++; - break; - default: - usage(); - } - } - if (fsys == NULL) - usage(); - if (!setup(fsys)) - errx(1, "cannot set up file system `%s'", fsys); - printf("Editing file system `%s'\nLast Mounted on %s\n", fsys, - sblock.fs_fsmnt); - rval = cmdloop(); - sblock.fs_clean = 0; /* mark it dirty */ - sbdirty(); - ckfini(0); - printf("*** FILE SYSTEM MARKED DIRTY\n"); - printf("*** BE SURE TO RUN FSCK TO CLEAN UP ANY DAMAGE\n"); - printf("*** IF IT WAS MOUNTED, RE-MOUNT WITH -u -o reload\n"); - exit(rval); -} - -#define CMDFUNC(func) int func __P((int argc, char *argv[])) -#define CMDFUNCSTART(func) int func(argc, argv) \ - int argc; \ - char *argv[]; - -CMDFUNC(helpfn); -CMDFUNC(focus); /* focus on inode */ -CMDFUNC(active); /* print active inode */ -CMDFUNC(focusname); /* focus by name */ -CMDFUNC(zapi); /* clear inode */ -CMDFUNC(uplink); /* incr link */ -CMDFUNC(downlink); /* decr link */ -CMDFUNC(linkcount); /* set link count */ -CMDFUNC(quit); /* quit */ -CMDFUNC(ls); /* list directory */ -CMDFUNC(rm); /* remove name */ -CMDFUNC(ln); /* add name */ -CMDFUNC(newtype); /* change type */ -CMDFUNC(chmode); /* change mode */ -CMDFUNC(chaflags); /* change flags */ -CMDFUNC(chgen); /* change generation */ -CMDFUNC(chowner); /* change owner */ -CMDFUNC(chgroup); /* Change group */ -CMDFUNC(back); /* pop back to last ino */ -CMDFUNC(chmtime); /* Change mtime */ -CMDFUNC(chctime); /* Change ctime */ -CMDFUNC(chatime); /* Change atime */ -CMDFUNC(chinum); /* Change inode # of dirent */ -CMDFUNC(chname); /* Change dirname of dirent */ - -struct cmdtable cmds[] = { - { "help", "Print out help", 1, 1, helpfn }, - { "?", "Print out help", 1, 1, helpfn }, - { "inode", "Set active inode to INUM", 2, 2, focus }, - { "clri", "Clear inode INUM", 2, 2, zapi }, - { "lookup", "Set active inode by looking up NAME", 2, 2, focusname }, - { "cd", "Set active inode by looking up NAME", 2, 2, focusname }, - { "back", "Go to previous active inode", 1, 1, back }, - { "active", "Print active inode", 1, 1, active }, - { "print", "Print active inode", 1, 1, active }, - { "uplink", "Increment link count", 1, 1, uplink }, - { "downlink", "Decrement link count", 1, 1, downlink }, - { "linkcount", "Set link count to COUNT", 2, 2, linkcount }, - { "ls", "List current inode as directory", 1, 1, ls }, - { "rm", "Remove NAME from current inode directory", 2, 2, rm }, - { "del", "Remove NAME from current inode directory", 2, 2, rm }, - { "ln", "Hardlink INO into current inode directory as NAME", 3, 3, ln }, - { "chinum", "Change dir entry number INDEX to INUM", 3, 3, chinum }, - { "chname", "Change dir entry number INDEX to NAME", 3, 3, chname }, - { "chtype", "Change type of current inode to TYPE", 2, 2, newtype }, - { "chmod", "Change mode of current inode to MODE", 2, 2, chmode }, - { "chown", "Change owner of current inode to OWNER", 2, 2, chowner }, - { "chgrp", "Change group of current inode to GROUP", 2, 2, chgroup }, - { "chflags", "Change flags of current inode to FLAGS", 2, 2, chaflags }, - { "chgen", "Change generation number of current inode to GEN", 2, 2, chgen }, - { "mtime", "Change mtime of current inode to MTIME", 2, 2, chmtime }, - { "ctime", "Change ctime of current inode to CTIME", 2, 2, chctime }, - { "atime", "Change atime of current inode to ATIME", 2, 2, chatime }, - { "quit", "Exit", 1, 1, quit }, - { "q", "Exit", 1, 1, quit }, - { "exit", "Exit", 1, 1, quit }, - { NULL, 0, 0, 0 }, -}; - -int -helpfn(argc, argv) - int argc; - char *argv[]; -{ - register struct cmdtable *cmdtp; - - printf("Commands are:\n%-10s %5s %5s %s\n", - "command", "min argc", "max argc", "what"); - - for (cmdtp = cmds; cmdtp->cmd; cmdtp++) - printf("%-10s %5u %5u %s\n", - cmdtp->cmd, cmdtp->minargc, cmdtp->maxargc, cmdtp->helptxt); - return 0; -} - -char * -prompt(el) - EditLine *el; -{ - static char pstring[64]; - snprintf(pstring, sizeof(pstring), "fsdb (inum: %d)> ", curinum); - return pstring; -} - - -int -cmdloop() -{ - char *line; - const char *elline; - int cmd_argc, rval = 0, known; -#define scratch known - char **cmd_argv; - struct cmdtable *cmdp; - History *hist; - EditLine *elptr; - - curinode = ginode(ROOTINO); - curinum = ROOTINO; - printactive(); - - hist = history_init(); - history(hist, H_EVENT, 100); /* 100 elt history buffer */ - - elptr = el_init(__progname, stdin, stdout); - el_set(elptr, EL_EDITOR, "emacs"); - el_set(elptr, EL_PROMPT, prompt); - el_set(elptr, EL_HIST, history, hist); - el_source(elptr, NULL); - - while ((elline = el_gets(elptr, &scratch)) != NULL && scratch != 0) { - if (debug) - printf("command `%s'\n", line); - - history(hist, H_ENTER, elline); - - line = strdup(elline); - cmd_argv = crack(line, &cmd_argc); - /* - * el_parse returns -1 to signal that it's not been handled - * internally. - */ - if (el_parse(elptr, cmd_argc, cmd_argv) != -1) - continue; - if (cmd_argc) { - known = 0; - for (cmdp = cmds; cmdp->cmd; cmdp++) { - if (!strcmp(cmdp->cmd, cmd_argv[0])) { - if (cmd_argc >= cmdp->minargc && - cmd_argc <= cmdp->maxargc) - rval = (*cmdp->handler)(cmd_argc, cmd_argv); - else - rval = argcount(cmdp, cmd_argc, cmd_argv); - known = 1; - break; - } - } - if (!known) - warnx("unknown command `%s'", cmd_argv[0]), rval = 1; - } else - rval = 0; - free(line); - if (rval < 0) - return rval; - if (rval) - warnx("rval was %d", rval); - } - el_end(elptr); - history_end(hist); - return rval; -} - -struct dinode *curinode; -ino_t curinum, ocurrent; - -#define GETINUM(ac,inum) inum = strtoul(argv[ac], &cp, 0); \ - if (inum < ROOTINO || inum > maxino || cp == argv[ac] || *cp != '\0' ) { \ - printf("inode %d out of range; range is [%d,%d]\n", \ - inum, ROOTINO, maxino); \ - return 1; \ - } - -/* - * Focus on given inode number - */ -CMDFUNCSTART(focus) -{ - ino_t inum; - char *cp; - - GETINUM(1,inum); - curinode = ginode(inum); - ocurrent = curinum; - curinum = inum; - printactive(); - return 0; -} - -CMDFUNCSTART(back) -{ - curinum = ocurrent; - curinode = ginode(curinum); - printactive(); - return 0; -} - -CMDFUNCSTART(zapi) -{ - ino_t inum; - struct dinode *dp; - char *cp; - - GETINUM(1,inum); - dp = ginode(inum); - clearinode(dp); - inodirty(); - if (curinode) /* re-set after potential change */ - curinode = ginode(curinum); - return 0; -} - -CMDFUNCSTART(active) -{ - printactive(); - return 0; -} - - -CMDFUNCSTART(quit) -{ - return -1; -} - -CMDFUNCSTART(uplink) -{ - if (!checkactive()) - return 1; - printf("inode %d link count now %d\n", curinum, ++curinode->di_nlink); - inodirty(); - return 0; -} - -CMDFUNCSTART(downlink) -{ - if (!checkactive()) - return 1; - printf("inode %d link count now %d\n", curinum, --curinode->di_nlink); - inodirty(); - return 0; -} - -const char *typename[] = { - "unknown", - "fifo", - "char special", - "unregistered #3", - "directory", - "unregistered #5", - "blk special", - "unregistered #7", - "regular", - "unregistered #9", - "symlink", - "unregistered #11", - "socket", - "unregistered #13", - "whiteout", -}; - -int slot; - -int -scannames(idesc) - struct inodesc *idesc; -{ - register struct direct *dirp = idesc->id_dirp; - - printf("slot %d ino %d reclen %d: %s, `%.*s'\n", - slot++, dirp->d_ino, dirp->d_reclen, typename[dirp->d_type], - dirp->d_namlen, dirp->d_name); - return (KEEPON); -} - -CMDFUNCSTART(ls) -{ - struct inodesc idesc; - checkactivedir(); /* let it go on anyway */ - - slot = 0; - idesc.id_number = curinum; - idesc.id_func = scannames; - idesc.id_type = DATA; - idesc.id_fix = IGNORE; - ckinode(curinode, &idesc); - curinode = ginode(curinum); - - return 0; -} - -int findino __P((struct inodesc *idesc)); /* from fsck */ -static int dolookup __P((char *name)); - -static int -dolookup(name) - char *name; -{ - struct inodesc idesc; - - if (!checkactivedir()) - return 0; - idesc.id_number = curinum; - idesc.id_func = findino; - idesc.id_name = name; - idesc.id_type = DATA; - idesc.id_fix = IGNORE; - if (ckinode(curinode, &idesc) & FOUND) { - curinum = idesc.id_parent; - curinode = ginode(curinum); - printactive(); - return 1; - } else { - warnx("name `%s' not found in current inode directory", name); - return 0; - } -} - -CMDFUNCSTART(focusname) -{ - char *p, *val; - - if (!checkactive()) - return 1; - - ocurrent = curinum; - - if (argv[1][0] == '/') { - curinum = ROOTINO; - curinode = ginode(ROOTINO); - } else { - if (!checkactivedir()) - return 1; - } - for (p = argv[1]; p != NULL;) { - while ((val = strsep(&p, "/")) != NULL && *val == '\0'); - if (val) { - printf("component `%s': ", val); - fflush(stdout); - if (!dolookup(val)) { - curinode = ginode(curinum); - return(1); - } - } - } - return 0; -} - -CMDFUNCSTART(ln) -{ - ino_t inum; - struct dinode *dp; - int rval; - char *cp; - - GETINUM(1,inum); - - if (!checkactivedir()) - return 1; - rval = makeentry(curinum, inum, argv[2]); - if (rval) - printf("Ino %d entered as `%s'\n", inum, argv[2]); - else - printf("could not enter name? weird.\n"); - curinode = ginode(curinum); - return rval; -} - -CMDFUNCSTART(rm) -{ - int rval; - - if (!checkactivedir()) - return 1; - rval = changeino(curinum, argv[1], 0); - if (rval & ALTERED) { - printf("Name `%s' removed\n", argv[1]); - return 0; - } else { - printf("could not remove name? weird.\n"); - return 1; - } -} - -long slotcount, desired; - -int -chinumfunc(idesc) - struct inodesc *idesc; -{ - register struct direct *dirp = idesc->id_dirp; - - if (slotcount++ == desired) { - dirp->d_ino = idesc->id_parent; - return STOP|ALTERED|FOUND; - } - return KEEPON; -} - -CMDFUNCSTART(chinum) -{ - int rval; - char *cp; - ino_t inum; - struct inodesc idesc; - - slotcount = 0; - if (!checkactivedir()) - return 1; - GETINUM(2,inum); - - desired = strtol(argv[1], &cp, 0); - if (cp == argv[1] || *cp != '\0' || desired < 0) { - printf("invalid slot number `%s'\n", argv[1]); - return 1; - } - - idesc.id_number = curinum; - idesc.id_func = chinumfunc; - idesc.id_fix = IGNORE; - idesc.id_type = DATA; - idesc.id_parent = inum; /* XXX convenient hiding place */ - - if (ckinode(curinode, &idesc) & FOUND) - return 0; - else { - warnx("no %sth slot in current directory", argv[1]); - return 1; - } -} - -int -chnamefunc(idesc) - struct inodesc *idesc; -{ - register struct direct *dirp = idesc->id_dirp; - struct direct testdir; - - if (slotcount++ == desired) { - /* will name fit? */ - testdir.d_namlen = strlen(idesc->id_name); - if (DIRSIZ(NEWDIRFMT, &testdir) <= dirp->d_reclen) { - dirp->d_namlen = testdir.d_namlen; - strcpy(dirp->d_name, idesc->id_name); - return STOP|ALTERED|FOUND; - } else - return STOP|FOUND; /* won't fit, so give up */ - } - return KEEPON; -} - -CMDFUNCSTART(chname) -{ - int rval; - char *cp; - ino_t inum; - struct inodesc idesc; - - slotcount = 0; - if (!checkactivedir()) - return 1; - - desired = strtoul(argv[1], &cp, 0); - if (cp == argv[1] || *cp != '\0') { - printf("invalid slot number `%s'\n", argv[1]); - return 1; - } - - idesc.id_number = curinum; - idesc.id_func = chnamefunc; - idesc.id_fix = IGNORE; - idesc.id_type = DATA; - idesc.id_name = argv[2]; - - rval = ckinode(curinode, &idesc); - if ((rval & (FOUND|ALTERED)) == (FOUND|ALTERED)) - return 0; - else if (rval & FOUND) { - warnx("new name `%s' does not fit in slot %s\n", argv[2], argv[1]); - return 1; - } else { - warnx("no %sth slot in current directory", argv[1]); - return 1; - } -} - -struct typemap { - const char *typename; - int typebits; -} typenamemap[] = { - {"file", IFREG}, - {"dir", IFDIR}, - {"socket", IFSOCK}, - {"fifo", IFIFO}, -}; - -CMDFUNCSTART(newtype) -{ - int rval = 1; - int type; - struct typemap *tp; - - if (!checkactive()) - return 1; - type = curinode->di_mode & IFMT; - for (tp = typenamemap; - tp < &typenamemap[sizeof(typemap)/sizeof(*typemap)]; - tp++) { - if (!strcmp(argv[1], tp->typename)) { - printf("setting type to %s\n", tp->typename); - type = tp->typebits; - break; - } - } - if (tp == &typenamemap[sizeof(typemap)/sizeof(*typemap)]) { - warnx("type `%s' not known", argv[1]); - warnx("try one of `file', `dir', `socket', `fifo'"); - return 1; - } - curinode->di_mode &= ~IFMT; - curinode->di_mode |= type; - inodirty(); - printactive(); - return 0; -} - -CMDFUNCSTART(chmode) -{ - int rval = 1; - long modebits; - char *cp; - - if (!checkactive()) - return 1; - - modebits = strtol(argv[1], &cp, 8); - if (cp == argv[1] || *cp != '\0' ) { - warnx("bad modebits `%s'", argv[1]); - return 1; - } - - curinode->di_mode &= ~07777; - curinode->di_mode |= modebits; - inodirty(); - printactive(); - return rval; -} - -CMDFUNCSTART(chaflags) -{ - int rval = 1; - u_long flags; - char *cp; - - if (!checkactive()) - return 1; - - flags = strtoul(argv[1], &cp, 0); - if (cp == argv[1] || *cp != '\0' ) { - warnx("bad flags `%s'", argv[1]); - return 1; - } - - if (flags > UINT_MAX) { - warnx("flags set beyond 32-bit range of field (%lx)\n", flags); - return(1); - } - curinode->di_flags = flags; - inodirty(); - printactive(); - return rval; -} - -CMDFUNCSTART(chgen) -{ - int rval = 1; - long gen; - char *cp; - - if (!checkactive()) - return 1; - - gen = strtol(argv[1], &cp, 0); - if (cp == argv[1] || *cp != '\0' ) { - warnx("bad gen `%s'", argv[1]); - return 1; - } - - if (gen > INT_MAX || gen < INT_MIN) { - warnx("gen set beyond 32-bit range of field (%lx)\n", gen); - return(1); - } - curinode->di_gen = gen; - inodirty(); - printactive(); - return rval; -} - -CMDFUNCSTART(linkcount) -{ - int rval = 1; - int lcnt; - char *cp; - - if (!checkactive()) - return 1; - - lcnt = strtol(argv[1], &cp, 0); - if (cp == argv[1] || *cp != '\0' ) { - warnx("bad link count `%s'", argv[1]); - return 1; - } - if (lcnt > USHRT_MAX || lcnt < 0) { - warnx("max link count is %d\n", USHRT_MAX); - return 1; - } - - curinode->di_nlink = lcnt; - inodirty(); - printactive(); - return rval; -} - -CMDFUNCSTART(chowner) -{ - int rval = 1; - unsigned long uid; - char *cp; - struct passwd *pwd; - - if (!checkactive()) - return 1; - - uid = strtoul(argv[1], &cp, 0); - if (cp == argv[1] || *cp != '\0' ) { - /* try looking up name */ - if (pwd = getpwnam(argv[1])) { - uid = pwd->pw_uid; - } else { - warnx("bad uid `%s'", argv[1]); - return 1; - } - } - - curinode->di_uid = uid; - inodirty(); - printactive(); - return rval; -} - -CMDFUNCSTART(chgroup) -{ - int rval = 1; - unsigned long gid; - char *cp; - struct group *grp; - - if (!checkactive()) - return 1; - - gid = strtoul(argv[1], &cp, 0); - if (cp == argv[1] || *cp != '\0' ) { - if (grp = getgrnam(argv[1])) { - gid = grp->gr_gid; - } else { - warnx("bad gid `%s'", argv[1]); - return 1; - } - } - - curinode->di_gid = gid; - inodirty(); - printactive(); - return rval; -} - -int -dotime(name, rsec, rnsec) - char *name; - int32_t *rsec, *rnsec; -{ - char *p, *val; - struct tm t; - int32_t sec; - int32_t nsec; - p = strchr(name, '.'); - if (p) { - *p = '\0'; - nsec = strtoul(++p, &val, 0); - if (val == p || *val != '\0' || nsec >= 1000000000 || nsec < 0) { - warnx("invalid nanoseconds"); - goto badformat; - } - } else - nsec = 0; - if (strlen(name) != 14) { -badformat: - warnx("date format: YYYYMMDDHHMMSS[.nsec]"); - return 1; - } - - for (p = name; *p; p++) - if (*p < '0' || *p > '9') - goto badformat; - - p = name; -#define VAL() ((*p++) - '0') - t.tm_year = VAL(); - t.tm_year = VAL() + t.tm_year * 10; - t.tm_year = VAL() + t.tm_year * 10; - t.tm_year = VAL() + t.tm_year * 10 - 1900; - t.tm_mon = VAL(); - t.tm_mon = VAL() + t.tm_mon * 10 - 1; - t.tm_mday = VAL(); - t.tm_mday = VAL() + t.tm_mday * 10; - t.tm_hour = VAL(); - t.tm_hour = VAL() + t.tm_hour * 10; - t.tm_min = VAL(); - t.tm_min = VAL() + t.tm_min * 10; - t.tm_sec = VAL(); - t.tm_sec = VAL() + t.tm_sec * 10; - t.tm_isdst = -1; - - sec = mktime(&t); - if (sec == -1) { - warnx("date/time out of range"); - return 1; - } - *rsec = sec; - *rnsec = nsec; - return 0; -} - -CMDFUNCSTART(chmtime) -{ - if (dotime(argv[1], &curinode->di_ctime, &curinode->di_ctimensec)) - return 1; - inodirty(); - printactive(); - return 0; -} - -CMDFUNCSTART(chatime) -{ - if (dotime(argv[1], &curinode->di_ctime, &curinode->di_ctimensec)) - return 1; - inodirty(); - printactive(); - return 0; -} - -CMDFUNCSTART(chctime) -{ - if (dotime(argv[1], &curinode->di_ctime, &curinode->di_ctimensec)) - return 1; - inodirty(); - printactive(); - return 0; -} diff --git a/sbin/fsdb/fsdb.h b/sbin/fsdb/fsdb.h deleted file mode 100644 index af51907e3521..000000000000 --- a/sbin/fsdb/fsdb.h +++ /dev/null @@ -1,56 +0,0 @@ -/* $NetBSD: fsdb.h,v 1.2 1995/10/08 23:18:11 thorpej Exp $ */ - -/* - * Copyright (c) 1995 John T. Kohl - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 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. - */ - -extern int bread __P((int fd, char *buf, daddr_t blk, long size)); -extern void bwrite __P((int fd, char *buf, daddr_t blk, long size)); -extern void rwerror __P((char *mesg, daddr_t blk)); -extern int reply __P((char *question)); - -extern long dev_bsize; -extern long secsize; -extern int fsmodified; -extern int fsfd; - -struct cmdtable { - const char *cmd; - const char *helptxt; - unsigned int minargc; - unsigned int maxargc; - int (*handler) __P((int argc, char *argv[])); -}; -extern struct dinode *curinode; -extern ino_t curinum; - -int argcount __P((struct cmdtable *cmdp, int argc, char *argv[])); -char **crack __P((char *line, int *argc)); -void printstat __P((const char *cp, ino_t inum, struct dinode *dp)); -int printactive __P((void)); -int checkactive __P((void)); -int checkactivedir __P((void)); diff --git a/sbin/fsdb/fsdbutil.c b/sbin/fsdb/fsdbutil.c deleted file mode 100644 index 1003b9d4d3e1..000000000000 --- a/sbin/fsdb/fsdbutil.c +++ /dev/null @@ -1,204 +0,0 @@ -/* $NetBSD: fsdbutil.c,v 1.2 1995/10/08 23:18:12 thorpej Exp $ */ - -/* - * Copyright (c) 1995 John T. Kohl - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 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 rcsid[] = "$NetBSD: fsdbutil.c,v 1.2 1995/10/08 23:18:12 thorpej Exp $"; -#endif /* not lint */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/param.h> -#include <sys/time.h> -#include <sys/mount.h> -#include <ctype.h> -#include <fcntl.h> -#include <grp.h> -#include <pwd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <ufs/ufs/dinode.h> -#include <ufs/ffs/fs.h> - -#include "fsdb.h" -#include "fsck.h" - -char ** -crack(line, argc) - char *line; - int *argc; -{ - static char *argv[8]; - int i; - char *p, *val; - for (p = line, i = 0; p != NULL && i < 8; i++) { - while ((val = strsep(&p, " \t\n")) != NULL && *val == '\0') - /**/; - if (val) - argv[i] = val; - else - break; - } - *argc = i; - return argv; -} - -int -argcount(cmdp, argc, argv) - struct cmdtable *cmdp; - int argc; - char *argv[]; -{ - if (cmdp->minargc == cmdp->maxargc) - warnx("command `%s' takes %u arguments", cmdp->cmd, cmdp->minargc-1); - else - warnx("command `%s' takes from %u to %u arguments", - cmdp->cmd, cmdp->minargc-1, cmdp->maxargc-1); - - warnx("usage: %s: %s", cmdp->cmd, cmdp->helptxt); - return 1; -} - -void -printstat(cp, inum, dp) - const char *cp; - ino_t inum; - struct dinode *dp; -{ - struct group *grp; - struct passwd *pw; - char *p; - - printf("%s: ", cp); - switch (dp->di_mode & IFMT) { - case IFDIR: - puts("directory"); - break; - case IFREG: - puts("regular file"); - break; - case IFBLK: - printf("block special (%d,%d)", - major(dp->di_rdev), minor(dp->di_rdev)); - break; - case IFCHR: - printf("character special (%d,%d)", - major(dp->di_rdev), minor(dp->di_rdev)); - break; - case IFLNK: - fputs("symlink",stdout); - if (dp->di_size > 0 && dp->di_size < MAXSYMLINKLEN && - dp->di_blocks == 0) - printf(" to `%.*s'\n", (int) dp->di_size, (char *)dp->di_shortlink); - else - putchar('\n'); - break; - case IFSOCK: - puts("socket"); - break; - case IFIFO: - puts("fifo"); - break; - } - printf("I=%lu MODE=%o SIZE=%qu", inum, dp->di_mode, dp->di_size); - p = ctime(&dp->di_mtime); - printf("\n\tMTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20], - dp->di_mtimensec); - p = ctime(&dp->di_ctime); - printf("\n\tCTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20], - dp->di_ctimensec); - p = ctime(&dp->di_atime); - printf("\n\tATIME=%15.15s %4.4s [%d nsec]\n", &p[4], &p[20], - dp->di_atimensec); - - if (pw = getpwuid(dp->di_uid)) - printf("OWNER=%s ", pw->pw_name); - else - printf("OWNUID=%u ", dp->di_uid); - if (grp = getgrgid(dp->di_gid)) - printf("GRP=%s ", grp->gr_name); - else - printf("GID=%u ", dp->di_gid); - - printf("LINKCNT=%hd FLAGS=%#x BLKCNT=%x GEN=%x\n", dp->di_nlink, dp->di_flags, - dp->di_blocks, dp->di_gen); -} - -int -checkactive() -{ - if (!curinode) { - warnx("no current inode\n"); - return 0; - } - return 1; -} - -int -checkactivedir() -{ - if (!curinode) { - warnx("no current inode\n"); - return 0; - } - if ((curinode->di_mode & IFMT) != IFDIR) { - warnx("inode %d not a directory", curinum); - return 0; - } - return 1; -} - -int -printactive() -{ - if (!checkactive()) - return 1; - switch (curinode->di_mode & IFMT) { - case IFDIR: - case IFREG: - case IFBLK: - case IFCHR: - case IFLNK: - case IFSOCK: - case IFIFO: - printstat("current inode", curinum, curinode); - break; - case 0: - printf("current inode %d: unallocated inode\n", curinum); - break; - default: - printf("current inode %d: screwy itype 0%o (mode 0%o)?\n", - curinum, curinode->di_mode & IFMT, curinode->di_mode); - break; - } - return 0; -} diff --git a/share/man/man4/ccd.4 b/share/man/man4/ccd.4 deleted file mode 100644 index a292bf98360f..000000000000 --- a/share/man/man4/ccd.4 +++ /dev/null @@ -1,115 +0,0 @@ -.\" $NetBSD: ccd.4,v 1.5 1995/10/09 06:09:09 thorpej Exp $ -.\" -.\" Copyright (c) 1994 Jason Downs. -.\" Copyright (c) 1994, 1995 Jason R. Thorpe. -.\" 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 for the NetBSD Project -.\" by Jason Downs and Jason R. Thorpe. -.\" 4. Neither the name of the author 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 AUTHOR ``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 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. -.\" -.Dd August 9, 1995 -.Dt CCD 4 -.Os NetBSD -.Sh NAME -.Nm ccd -.Nd Concatenated Disk Driver -.Sh SYNOPSIS -.Cd "pseudo-device ccd 4" -.Sh DESCRIPTION -The -.Nm -driver provides the capability of combining one or more disks/partitions -into one virtual disk. -.Pp -This document assumes that you're familiar with how to generate kernels, -how to properly configure disks and pseudo-devices in a kernel -configuration file, and how to partition disks. -.Pp -Note that the -.Sq raw -partitions of the disks -.Pa should not -be combined. Each component partition should be offset at least one -cylinder from the beginning of the component disk. This avoids potential -conflicts between the compoent disk's disklabel and the -.Nm ccd's -disklabel. The kernel will only allow component partitions of type FS_BSDFFS. -.Pp -In order to compile in support for the ccd, you must add a line similar -to the following to your kernel configuration file: -.Bd -unfilled -offset indent -pseudo-device ccd 4 # concatenated disk devices -.Ed -.Pp -The count argument is how many -.Nm ccds -memory is allocated for a boot time. In this example, no more than 4 -.Nm ccds -may be configured. -.Pp -A -.Nm ccd -may be either serially concatenated or interleaved. If a -.Nm ccd -is interleaved correctly, a -.Dq striping -effect is achieved, which can increase performance. The optimum interleave -factor is typically the size of a track. Since the interleave factor -is expressed in units of DEV_BSIZE, one must account for sector sizes -other than DEV_BSIZE in order to calculate the correct interleave. -The kernel will not allow an interleave factor less than the size -of the largest component sector divided by DEV_BSIZE. -.Pp -Note that best performance is achieved if all compent disks have the same -geometery and size. Optimum striping cannot occur with different -disk types. -.Pp -There is a run-time utility that is used for configuring -.Nm ccds . -See -.Xr ccdconfig 8 -for more information. -.Sh WARNINGS -If just one (or more) of the disks in a -.Nm ccd -fails, the entire -file system will be lost. -.Sh FILES -/dev/{,r}ccd* - ccd device special files. -.Pp -.Sh HISTORY -The concatenated disk driver was originally written at the University of -Utah. -.Sh SEE ALSO -.Xr MAKEDEV 8 , -.Xr ccdconfig 8 , -.Xr config 8 , -.Xr config.old 8 , -.Xr fsck 8 , -.Xr mount 8 , -.Xr newfs 8 . diff --git a/share/man/man4/tun.4 b/share/man/man4/tun.4 deleted file mode 100644 index 2f813d823f96..000000000000 --- a/share/man/man4/tun.4 +++ /dev/null @@ -1,216 +0,0 @@ -.\" $NetBSD: tun.4,v 1.1 1996/06/25 22:17:37 pk Exp $ -.\" Based on PR#2411 -.\" -.Dd March 10, 1996 -.Dt TUN 4 -.Os NetBSD 1.1 -.Sh NAME -.Nm tun -.Nd tunnel software network interface -.Sh SYNOPSIS -.Cd pseudo-device tun Op Ar count -.Sh DESCRIPTION -The -.Nm tun -interface is a software loopback mechanism that can be loosely -described as the network interface analog of the -.Xr pty 4 , -that is, -.Nm tun -does for network interfaces what the -.Nm pty -driver does for terminals. -.Pp -The -.Nm tun -driver, like the -.Nm pty -driver, provides two interfaces: an interface like the usual facility -it is simulating -.Po -a network interface in the case of -.Nm tun , -or a terminal for -.Nm pty Pc , -and a character-special device -.Dq control -interface. -.Pp -The network interfaces are named -.Sy tun Ns Ar 0 , -.Sy tun Ns Ar 1 , -etc, as many in all as the -.Ar count -figure given on the -.Sy pseudo-device -line. Each one supports the usual network-interface -.Xr ioctl 2 Ns s , -such as -.Dv SIOCSIFADDR -and -.Dv SIOCSIFNETMASK , -and thus can be used with -.Xr ifconfig 8 -like any other interface. At boot time, they are -.Dv POINTOPOINT -interfaces, but this can be changed; see the description of the control -device, below. When the system chooses to transmit a packet on the -network interface, the packet can be read from the control device -.Po -it appears as -.Dq input -there -.Pc ; -writing a packet to the control device generates an input -packet on the network interface, as if the -.Pq non-existent -hardware had just received it. -.Pp -The tunnel device, normally -.Pa /dev/tun Ns Sy N , -is exclusive-open -.Po -it cannot be opened if it is already open -.Pc -and is restricted to the super-user. A -.Fn read -call will return an error -.Pq Er EHOSTDOWN -if the interface is not -.Dq ready -.Po -which means that the control device is open and the interface's -address has been set -.Pc . -Once the interface is ready, -.Fn read -will return a packet if one is available; if not, it will either block -until one is or return -.Er EWOULDBLOCK , -depending on whether non-blocking I/O has been enabled. If the packet -is longer than is allowed for in the buffer passed to -.Fn read , -the extra data will be silently dropped. -.Pp -Packets can be optionally prepended with the destination address as presented -to the network interface output routine -.Pq Sq Li tunoutput . -The destination address is in -.Sq Li struct sockaddr -format. The actual length of the prepended address is in the member -.Sq Li sa_len . -The packet data follows immediately. -A -.Xr write 2 -call passes a packet in to be -.Dq received -on the pseudo-interface. Each -.Fn write -call supplies exactly one packet; the packet length is taken from the -amount of data provided to -.Fn write . -Writes will not block; if the packet cannot be accepted for a -transient reason -.Pq e.g., no buffer space available , -it is silently dropped; if the reason is not transient -.Pq e.g., packet too large , -an error is returned. -If -.Dq link-layer mode -is on -.Pq see Dv TUNSLMODE No below , -the actual packet data must be preceded by a -.Sq Li struct sockaddr . -The driver currently only inspects the -.Sq Li sa_family -field. -The following -.Xr ioctl 2 -calls are supported -.Pq defined in Aq Pa net/if_tun.h Ns : -.Bl -tag -width TUNSIFMODE -.It Dv TUNSDEBUG -The argument should be a pointer to an -.Va int ; -this sets the internal debugging variable to that value. What, if -anything, this variable controls is not documented here; see the source -code. -.It Dv TUNGDEBUG -The argument should be a pointer to an -.Va int ; -this stores the internal debugging variable's value into it. -.It Dv TUNSIFMODE -The argument should be a pointer to an -.Va int ; -its value must be -.Dv IFF_POINTOPOINT -or -.Dv IFF_BROADCAST . -The type of the corresponding -.Em tun Ns Sy n -interface is set to the supplied type. If the value is anything else, -an -.Er EINVAL -error occurs. The interface must be down at the time; if it is up, an -.Er EBUSY -error occurs. -.It Dv TUNSLMODE -The argument should be a pointer to an -.Va int ; -a non-zero value turns on -.Dq link-layer -mode, causing packets read from the tunnel device to be prepended with -network destination address. -.It Dv FIONBIO -Turn non-blocking I/O for reads off or on, according as the argument -.Va int Ns 's -value is or isn't zero -.Pq Writes are always nonblocking . -.It Dv FIOASYNC -Turn asynchronous I/O for reads -.Po -i.e., generation of -.Dv SIGIO -when data is available to be read -.Pc off or on, according as the argument -.Va int Ns 's -value is or isn't zero. -.It Dv FIONREAD -If any packets are queued to be read, store the size of the first one -into the argument -.Va int ; -otherwise, store zero. -.It Dv TIOCSPGRP -Set the process group to receive -.Dv SIGIO -signals, when asynchronous I/O is enabled, to the argument -.Va int -value. -.It Dv TIOCGPGRP -Retrieve the process group value for -.Dv SIGIO -signals into the argument -.Va int -value. -.El -.Pp -The control device also supports -.Xr select 2 -for read; selecting for write is pointless, and always succeeds, since -writes are always non-blocking. -.Pp -On the last close of the data device, by default, the interface is -brought down -.Po as if with -.Dq ifconfig tun Ns Sy n No down -.Pc . -All queued packets are thrown away. -.Po If the interface is up when the data device is not open -output packets are always -thrown away rather than letting them pile up -.Pc . -.Sh SEE ALSO -.Xr intro 4 , -.Xr inet 4 -.Sh BUGS -Currently is IP-only. diff --git a/share/man/man5/mailer.conf.5 b/share/man/man5/mailer.conf.5 deleted file mode 100644 index 6901cd733d19..000000000000 --- a/share/man/man5/mailer.conf.5 +++ /dev/null @@ -1,97 +0,0 @@ -.\" $NetBSD: mailer.conf.5,v 1.2 1999/05/29 18:18:30 christos Exp $ -.\" -.\" Copyright (c) 1998 -.\" Perry E. Metzger. 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 acknowledgment: -.\" This product includes software developed for the NetBSD Project -.\" by Perry E. Metzger. -.\" 4. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. -.\" -.\" The following requests are required for all man pages. -.Dd December 16, 1998 -.Dt MAILER.CONF 5 -.Os -.Sh NAME -.Nm mailer.conf -.Nd configuration file for -.Xr mailwrapper 8 . -.Sh DESCRIPTION -.Pp -The file -.Pa /etc/mailer.conf -contains a series of pairs. The first member of each pair is the name -of a program invoking -.Xr mailwrapper 8 -which is typically a symbolic link to -.Pa /usr/sbin/sendmail . -(On a typical system, -.Xr newaliases 1 -and -.Xr mailq 1 -would be set up this way.) -The second member of each pair is the name of the program to -actually execute when the first name is invoked. The file may also -contain comments, denoted by a # mark in the first column of any line. -.Sh EXAMPLES -The following is an example of how to set up an -.Nm -for traditional sendmail invocation behavior. -.Bd -literal -# Execute the "real" sendmail program, named /usr/libexec/sendmail/sendmail -sendmail /usr/libexec/sendmail/sendmail -send-mail /usr/libexec/sendmail/sendmail -mailq /usr/libexec/sendmail/sendmail -newaliases /usr/libexec/sendmail/sendmail -.Ed -.Pp -This example shows how to invoke the fictitious "newmail" program in -place of sendmail. -.Bd -literal -# Emulate sendmail using postfix -sendmail /usr/libexec/postfix/sendmail -send-mail /usr/libexec/postfix/sendmail -mailq /usr/libexec/postfix/sendmail -newaliases /usr/libexec/postfix/sendmail -.Ed -.Sh FILES -/etc/mailer.conf -.Sh SEE ALSO -.Xr mail 1 , -.Xr mailq 1 , -.Xr mailwrapper 8 , -.Xr newaliases 1 , -.Xr sendmail 8 . -.Sh HISTORY -.Nm -appeared in -.Nx 1.4 . -.Sh AUTHORS -Perry E. Metzger <perry@piermont.com> -.Sh BUGS -The entire reason this program exists is a crock. Instead, a command -for how to submit mail should be standardized, and all the "behave -differently if invoked with a different name" behavior of things like -.Xr mailq 1 -should go away. diff --git a/sys/dev/ccd/ccd.c b/sys/dev/ccd/ccd.c deleted file mode 100644 index c8d33a4b867e..000000000000 --- a/sys/dev/ccd/ccd.c +++ /dev/null @@ -1,1428 +0,0 @@ -/* $NetBSD: ccd.c,v 1.22 1995/12/08 19:13:26 thorpej Exp $ */ - -/* - * Copyright (c) 1995 Jason R. Thorpe. - * 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 for the NetBSD Project - * by Jason R. Thorpe. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -/* - * Copyright (c) 1988 University of Utah. - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * 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. - * - * from: Utah $Hdr: cd.c 1.6 90/11/28$ - * - * @(#)cd.c 8.2 (Berkeley) 11/16/93 - */ - -/* - * "Concatenated" disk driver. - * - * Dynamic configuration and disklabel support by: - * Jason R. Thorpe <thorpej@nas.nasa.gov> - * Numerical Aerodynamic Simulation Facility - * Mail Stop 258-6 - * NASA Ames Research Center - * Moffett Field, CA 94035 - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/proc.h> -#include <sys/errno.h> -#include <sys/dkstat.h> -#include <sys/buf.h> -#include <sys/malloc.h> -#include <sys/namei.h> -#include <sys/conf.h> -#include <sys/stat.h> -#include <sys/ioctl.h> -#include <sys/disklabel.h> -#include <sys/device.h> -#include <sys/disk.h> -#include <sys/syslog.h> -#include <sys/fcntl.h> -#include <sys/vnode.h> - -#include <dev/ccdvar.h> - -#if defined(CCDDEBUG) && !defined(DEBUG) -#define DEBUG -#endif - -#ifdef DEBUG -int ccddebug = 0x00; -#define CCDB_FOLLOW 0x01 -#define CCDB_INIT 0x02 -#define CCDB_IO 0x04 -#define CCDB_LABEL 0x08 -#define CCDB_VNODE 0x10 -#endif - -#define ccdunit(x) DISKUNIT(x) - -struct ccdbuf { - struct buf cb_buf; /* new I/O buf */ - struct buf *cb_obp; /* ptr. to original I/O buf */ - int cb_unit; /* target unit */ - int cb_comp; /* target component */ -}; - -#define getccdbuf() \ - ((struct ccdbuf *)malloc(sizeof(struct ccdbuf), M_DEVBUF, M_WAITOK)) -#define putccdbuf(cbp) \ - free((caddr_t)(cbp), M_DEVBUF) - -#define CCDLABELDEV(dev) \ - (MAKEDISKDEV(major((dev)), ccdunit((dev)), RAW_PART)) - -/* {b,c}devsw[] function prototypes */ -dev_type_open(ccdopen); -dev_type_close(ccdclose); -dev_type_strategy(ccdstrategy); -dev_type_ioctl(ccdioctl); -dev_type_read(ccdread); -dev_type_write(ccdwrite); - -/* called by main() at boot time */ -void ccdattach __P((int)); - -/* called by biodone() at interrupt time */ -void ccdiodone __P((struct ccdbuf *cbp)); - -static void ccdstart __P((struct ccd_softc *, struct buf *)); -static void ccdinterleave __P((struct ccd_softc *, int)); -static void ccdintr __P((struct ccd_softc *, struct buf *)); -static int ccdinit __P((struct ccddevice *, char **, struct proc *)); -static int ccdlookup __P((char *, struct proc *p, struct vnode **)); -static struct ccdbuf *ccdbuffer __P((struct ccd_softc *, struct buf *, - daddr_t, caddr_t, long)); -static void ccdgetdisklabel __P((dev_t)); -static void ccdmakedisklabel __P((struct ccd_softc *)); -static int ccdlock __P((struct ccd_softc *)); -static void ccdunlock __P((struct ccd_softc *)); - -#ifdef DEBUG -static void printiinfo __P((struct ccdiinfo *)); -#endif - -/* Non-private for the benefit of libkvm. */ -struct ccd_softc *ccd_softc; -struct ccddevice *ccddevs; -int numccd = 0; - -/* - * Called by main() during pseudo-device attachment. All we need - * to do is allocate enough space for devices to be configured later. - */ -void -ccdattach(num) - int num; -{ - int i; - - if (num <= 0) { -#ifdef DIAGNOSTIC - panic("ccdattach: count <= 0"); -#endif - return; - } - - ccd_softc = (struct ccd_softc *)malloc(num * sizeof(struct ccd_softc), - M_DEVBUF, M_NOWAIT); - ccddevs = (struct ccddevice *)malloc(num * sizeof(struct ccddevice), - M_DEVBUF, M_NOWAIT); - if ((ccd_softc == NULL) || (ccddevs == NULL)) { - printf("WARNING: no memory for concatenated disks\n"); - if (ccd_softc != NULL) - free(ccd_softc, M_DEVBUF); - if (ccddevs != NULL) - free(ccddevs, M_DEVBUF); - return; - } - numccd = num; - bzero(ccd_softc, num * sizeof(struct ccd_softc)); - bzero(ccddevs, num * sizeof(struct ccddevice)); - - /* XXX: is this necessary? */ - for (i = 0; i < numccd; ++i) - ccddevs[i].ccd_dk = -1; -} - -static int -ccdinit(ccd, cpaths, p) - struct ccddevice *ccd; - char **cpaths; - struct proc *p; -{ - register struct ccd_softc *cs = &ccd_softc[ccd->ccd_unit]; - register struct ccdcinfo *ci; - register size_t size; - register int ix; - struct vnode *vp; - struct vattr va; - size_t minsize; - int maxsecsize; - struct partinfo dpart; - struct ccdgeom *ccg = &cs->sc_geom; - char tmppath[MAXPATHLEN]; - int error; - -#ifdef DEBUG - if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) - printf("ccdinit: unit %d\n", ccd->ccd_unit); -#endif - -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - cs->sc_dk = ccd->ccd_dk; -#endif - cs->sc_size = 0; - cs->sc_ileave = ccd->ccd_interleave; - cs->sc_nccdisks = ccd->ccd_ndev; - - /* Allocate space for the component info. */ - cs->sc_cinfo = malloc(cs->sc_nccdisks * sizeof(struct ccdcinfo), - M_DEVBUF, M_WAITOK); - - /* - * Verify that each component piece exists and record - * relevant information about it. - */ - maxsecsize = 0; - minsize = 0; - for (ix = 0; ix < cs->sc_nccdisks; ix++) { - vp = ccd->ccd_vpp[ix]; - ci = &cs->sc_cinfo[ix]; - ci->ci_vp = vp; - - /* - * Copy in the pathname of the component. - */ - bzero(tmppath, sizeof(tmppath)); /* sanity */ - if (error = copyinstr(cpaths[ix], tmppath, - MAXPATHLEN, &ci->ci_pathlen)) { -#ifdef DEBUG - if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) - printf("ccd%d: can't copy path, error = %d\n", - ccd->ccd_unit, error); -#endif - free(cs->sc_cinfo, M_DEVBUF); - return (error); - } - ci->ci_path = malloc(ci->ci_pathlen, M_DEVBUF, M_WAITOK); - bcopy(tmppath, ci->ci_path, ci->ci_pathlen); - - /* - * XXX: Cache the component's dev_t. - */ - if (error = VOP_GETATTR(vp, &va, p->p_ucred, p)) { -#ifdef DEBUG - if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) - printf("ccd%d: %s: getattr failed %s = %d\n", - ccd->ccd_unit, ci->ci_path, - "error", error); -#endif - free(ci->ci_path, M_DEVBUF); - free(cs->sc_cinfo, M_DEVBUF); - return (error); - } - ci->ci_dev = va.va_rdev; - - /* - * Get partition information for the component. - */ - if (error = VOP_IOCTL(vp, DIOCGPART, (caddr_t)&dpart, - FREAD, p->p_ucred, p)) { -#ifdef DEBUG - if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) - printf("ccd%d: %s: ioctl failed, error = %d\n", - ccd->ccd_unit, ci->ci_path, error); -#endif - free(ci->ci_path, M_DEVBUF); - free(cs->sc_cinfo, M_DEVBUF); - return (error); - } - if (dpart.part->p_fstype == FS_BSDFFS) { - maxsecsize = - ((dpart.disklab->d_secsize > maxsecsize) ? - dpart.disklab->d_secsize : maxsecsize); - size = dpart.part->p_size; - } else { -#ifdef DEBUG - if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) - printf("ccd%d: %s: incorrect partition type\n", - ccd->ccd_unit, ci->ci_path); -#endif - free(ci->ci_path, M_DEVBUF); - free(cs->sc_cinfo, M_DEVBUF); - return (EFTYPE); - } - - /* - * Calculate the size, truncating to an interleave - * boundary if necessary. - */ - if (size < 0) - size = 0; - - if (cs->sc_ileave > 1) - size -= size % cs->sc_ileave; - - if (size == 0) { -#ifdef DEBUG - if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) - printf("ccd%d: %s: size == 0\n", - ccd->ccd_unit, ci->ci_path); -#endif - free(ci->ci_path, M_DEVBUF); - free(cs->sc_cinfo, M_DEVBUF); - return (ENODEV); - } - - if (minsize == 0 || size < minsize) - minsize = size; - ci->ci_size = size; - cs->sc_size += size; - } - - /* - * Don't allow the interleave to be smaller than - * the biggest component sector. - */ - if ((cs->sc_ileave > 0) && - (cs->sc_ileave < (maxsecsize / DEV_BSIZE))) { -#ifdef DEBUG - if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) - printf("ccd%d: interleave must be at least %d\n", - ccd->ccd_unit, (maxsecsize / DEV_BSIZE)); -#endif - free(ci->ci_path, M_DEVBUF); - free(cs->sc_cinfo, M_DEVBUF); - return (EINVAL); - } - - /* - * If uniform interleave is desired set all sizes to that of - * the smallest component. - */ - if (ccd->ccd_flags & CCDF_UNIFORM) { - for (ci = cs->sc_cinfo; - ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) - ci->ci_size = minsize; - cs->sc_size = cs->sc_nccdisks * minsize; - } - - /* - * Construct the interleave table. - */ - ccdinterleave(cs, ccd->ccd_unit); - - /* - * Create pseudo-geometry based on 1MB cylinders. It's - * pretty close. - */ - ccg->ccg_secsize = DEV_BSIZE; - ccg->ccg_ntracks = 1; - ccg->ccg_nsectors = 1024 * (1024 / ccg->ccg_secsize); - ccg->ccg_ncylinders = cs->sc_size / ccg->ccg_nsectors; - -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - if (ccd->ccd_dk >= 0) - dk_wpms[ccd->ccd_dk] = 32 * (60 * DEV_BSIZE / 2); /* XXX */ -#endif - - cs->sc_flags |= CCDF_INITED; - cs->sc_cflags = ccd->ccd_flags; /* So we can find out later... */ - cs->sc_unit = ccd->ccd_unit; - return (0); -} - -static void -ccdinterleave(cs, unit) - register struct ccd_softc *cs; - int unit; -{ - register struct ccdcinfo *ci, *smallci; - register struct ccdiinfo *ii; - register daddr_t bn, lbn; - register int ix; - u_long size; - -#ifdef DEBUG - if (ccddebug & CCDB_INIT) - printf("ccdinterleave(%x): ileave %d\n", cs, cs->sc_ileave); -#endif - /* - * Allocate an interleave table. - * Chances are this is too big, but we don't care. - */ - size = (cs->sc_nccdisks + 1) * sizeof(struct ccdiinfo); - cs->sc_itable = (struct ccdiinfo *)malloc(size, M_DEVBUF, M_WAITOK); - bzero((caddr_t)cs->sc_itable, size); - - /* - * Trivial case: no interleave (actually interleave of disk size). - * Each table entry represents a single component in its entirety. - */ - if (cs->sc_ileave == 0) { - bn = 0; - ii = cs->sc_itable; - - for (ix = 0; ix < cs->sc_nccdisks; ix++) { - /* Allocate space for ii_index. */ - ii->ii_index = malloc(sizeof(int), M_DEVBUF, M_WAITOK); - ii->ii_ndisk = 1; - ii->ii_startblk = bn; - ii->ii_startoff = 0; - ii->ii_index[0] = ix; - bn += cs->sc_cinfo[ix].ci_size; - ii++; - } - ii->ii_ndisk = 0; -#ifdef DEBUG - if (ccddebug & CCDB_INIT) - printiinfo(cs->sc_itable); -#endif - return; - } - - /* - * The following isn't fast or pretty; it doesn't have to be. - */ - size = 0; - bn = lbn = 0; - for (ii = cs->sc_itable; ; ii++) { - /* Allocate space for ii_index. */ - ii->ii_index = malloc((sizeof(int) * cs->sc_nccdisks), - M_DEVBUF, M_WAITOK); - - /* - * Locate the smallest of the remaining components - */ - smallci = NULL; - for (ci = cs->sc_cinfo; - ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) - if (ci->ci_size > size && - (smallci == NULL || - ci->ci_size < smallci->ci_size)) - smallci = ci; - - /* - * Nobody left, all done - */ - if (smallci == NULL) { - ii->ii_ndisk = 0; - break; - } - - /* - * Record starting logical block and component offset - */ - ii->ii_startblk = bn / cs->sc_ileave; - ii->ii_startoff = lbn; - - /* - * Determine how many disks take part in this interleave - * and record their indices. - */ - ix = 0; - for (ci = cs->sc_cinfo; - ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) - if (ci->ci_size >= smallci->ci_size) - ii->ii_index[ix++] = ci - cs->sc_cinfo; - ii->ii_ndisk = ix; - bn += ix * (smallci->ci_size - size); - lbn = smallci->ci_size / cs->sc_ileave; - size = smallci->ci_size; - } -#ifdef DEBUG - if (ccddebug & CCDB_INIT) - printiinfo(cs->sc_itable); -#endif -} - -/* ARGSUSED */ -int -ccdopen(dev, flags, fmt, p) - dev_t dev; - int flags, fmt; - struct proc *p; -{ - int unit = ccdunit(dev); - struct ccd_softc *cs; - struct disklabel *lp; - int error = 0, part, pmask; - -#ifdef DEBUG - if (ccddebug & CCDB_FOLLOW) - printf("ccdopen(%x, %x)\n", dev, flags); -#endif - if (unit >= numccd) - return (ENXIO); - cs = &ccd_softc[unit]; - - if (error = ccdlock(cs)) - return (error); - - lp = &cs->sc_dkdev.dk_label; - - part = DISKPART(dev); - pmask = (1 << part); - - /* - * If we're initialized, check to see if there are any other - * open partitions. If not, then it's safe to update - * the in-core disklabel. - */ - if ((cs->sc_flags & CCDF_INITED) && (cs->sc_dkdev.dk_openmask == 0)) - ccdgetdisklabel(dev); - - /* Check that the partition exists. */ - if (part != RAW_PART && ((part > lp->d_npartitions) || - (lp->d_partitions[part].p_fstype == FS_UNUSED))) { - error = ENXIO; - goto done; - } - - /* Prevent our unit from being unconfigured while open. */ - switch (fmt) { - case S_IFCHR: - cs->sc_dkdev.dk_copenmask |= pmask; - break; - - case S_IFBLK: - cs->sc_dkdev.dk_bopenmask |= pmask; - break; - } - cs->sc_dkdev.dk_openmask = - cs->sc_dkdev.dk_copenmask | cs->sc_dkdev.dk_bopenmask; - - done: - ccdunlock(cs); - return (0); -} - -/* ARGSUSED */ -int -ccdclose(dev, flags, fmt, p) - dev_t dev; - int flags, fmt; - struct proc *p; -{ - int unit = ccdunit(dev); - struct ccd_softc *cs; - int error = 0, part; - -#ifdef DEBUG - if (ccddebug & CCDB_FOLLOW) - printf("ccdclose(%x, %x)\n", dev, flags); -#endif - - if (unit >= numccd) - return (ENXIO); - cs = &ccd_softc[unit]; - - if (error = ccdlock(cs)) - return (error); - - part = DISKPART(dev); - - /* ...that much closer to allowing unconfiguration... */ - switch (fmt) { - case S_IFCHR: - cs->sc_dkdev.dk_copenmask &= ~(1 << part); - break; - - case S_IFBLK: - cs->sc_dkdev.dk_bopenmask &= ~(1 << part); - break; - } - cs->sc_dkdev.dk_openmask = - cs->sc_dkdev.dk_copenmask | cs->sc_dkdev.dk_bopenmask; - - ccdunlock(cs); - return (0); -} - -void -ccdstrategy(bp) - register struct buf *bp; -{ - register int unit = ccdunit(bp->b_dev); - register struct ccd_softc *cs = &ccd_softc[unit]; - register daddr_t bn; - register int sz, s; - int wlabel; - struct disklabel *lp; - -#ifdef DEBUG - if (ccddebug & CCDB_FOLLOW) - printf("ccdstrategy(%x): unit %d\n", bp, unit); -#endif - if ((cs->sc_flags & CCDF_INITED) == 0) { - bp->b_error = ENXIO; - bp->b_flags |= B_ERROR; - goto done; - } - - /* If it's a nil transfer, wake up the top half now. */ - if (bp->b_bcount == 0) - goto done; - - lp = &cs->sc_dkdev.dk_label; - - /* - * Do bounds checking and adjust transfer. If there's an - * error, the bounds check will flag that for us. - */ - wlabel = cs->sc_flags & (CCDF_WLABEL|CCDF_LABELLING); - if (DISKPART(bp->b_dev) != RAW_PART) - if (bounds_check_with_label(bp, lp, wlabel) <= 0) - goto done; - - bp->b_resid = bp->b_bcount; - - /* - * "Start" the unit. - */ - s = splbio(); - ccdstart(cs, bp); - splx(s); - return; -done: - biodone(bp); -} - -static void -ccdstart(cs, bp) - register struct ccd_softc *cs; - register struct buf *bp; -{ - register long bcount, rcount; - struct ccdbuf *cbp; - caddr_t addr; - daddr_t bn; - struct partition *pp; - -#ifdef DEBUG - if (ccddebug & CCDB_FOLLOW) - printf("ccdstart(%x, %x)\n", cs, bp); -#endif - -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - /* - * Instrumentation (not very meaningful) - */ - cs->sc_nactive++; - if (cs->sc_dk >= 0) { - dk_busy |= 1 << cs->sc_dk; - dk_xfer[cs->sc_dk]++; - dk_wds[cs->sc_dk] += bp->b_bcount >> 6; - } -#endif - - /* - * Translate the partition-relative block number to an absolute. - */ - bn = bp->b_blkno; - if (DISKPART(bp->b_dev) != RAW_PART) { - pp = &cs->sc_dkdev.dk_label.d_partitions[DISKPART(bp->b_dev)]; - bn += pp->p_offset; - } - - /* - * Allocate component buffers and fire off the requests - */ - addr = bp->b_data; - for (bcount = bp->b_bcount; bcount > 0; bcount -= rcount) { - cbp = ccdbuffer(cs, bp, bn, addr, bcount); - rcount = cbp->cb_buf.b_bcount; - if ((cbp->cb_buf.b_flags & B_READ) == 0) - cbp->cb_buf.b_vp->v_numoutput++; - VOP_STRATEGY(&cbp->cb_buf); - bn += btodb(rcount); - addr += rcount; - } -} - -/* - * Build a component buffer header. - */ -static struct ccdbuf * -ccdbuffer(cs, bp, bn, addr, bcount) - register struct ccd_softc *cs; - struct buf *bp; - daddr_t bn; - caddr_t addr; - long bcount; -{ - register struct ccdcinfo *ci; - register struct ccdbuf *cbp; - register daddr_t cbn, cboff; - -#ifdef DEBUG - if (ccddebug & CCDB_IO) - printf("ccdbuffer(%x, %x, %d, %x, %d)\n", - cs, bp, bn, addr, bcount); -#endif - /* - * Determine which component bn falls in. - */ - cbn = bn; - cboff = 0; - - /* - * Serially concatenated - */ - if (cs->sc_ileave == 0) { - register daddr_t sblk; - - sblk = 0; - for (ci = cs->sc_cinfo; cbn >= sblk + ci->ci_size; ci++) - sblk += ci->ci_size; - cbn -= sblk; - } - /* - * Interleaved - */ - else { - register struct ccdiinfo *ii; - int ccdisk, off; - - cboff = cbn % cs->sc_ileave; - cbn /= cs->sc_ileave; - for (ii = cs->sc_itable; ii->ii_ndisk; ii++) - if (ii->ii_startblk > cbn) - break; - ii--; - off = cbn - ii->ii_startblk; - if (ii->ii_ndisk == 1) { - ccdisk = ii->ii_index[0]; - cbn = ii->ii_startoff + off; - } else { - ccdisk = ii->ii_index[off % ii->ii_ndisk]; - cbn = ii->ii_startoff + off / ii->ii_ndisk; - } - cbn *= cs->sc_ileave; - ci = &cs->sc_cinfo[ccdisk]; - } - - /* - * Fill in the component buf structure. - */ - cbp = getccdbuf(); - cbp->cb_buf.b_flags = bp->b_flags | B_CALL; - cbp->cb_buf.b_iodone = (void (*)())ccdiodone; - cbp->cb_buf.b_proc = bp->b_proc; - cbp->cb_buf.b_dev = ci->ci_dev; /* XXX */ - cbp->cb_buf.b_blkno = cbn + cboff; - cbp->cb_buf.b_data = addr; - cbp->cb_buf.b_vp = ci->ci_vp; - if (cs->sc_ileave == 0) - cbp->cb_buf.b_bcount = dbtob(ci->ci_size - cbn); - else - cbp->cb_buf.b_bcount = dbtob(cs->sc_ileave - cboff); - if (cbp->cb_buf.b_bcount > bcount) - cbp->cb_buf.b_bcount = bcount; - - /* - * context for ccdiodone - */ - cbp->cb_obp = bp; - cbp->cb_unit = cs - ccd_softc; - cbp->cb_comp = ci - cs->sc_cinfo; - -#ifdef DEBUG - if (ccddebug & CCDB_IO) - printf(" dev %x(u%d): cbp %x bn %d addr %x bcnt %d\n", - ci->ci_dev, ci-cs->sc_cinfo, cbp, cbp->cb_buf.b_blkno, - cbp->cb_buf.b_data, cbp->cb_buf.b_bcount); -#endif - return (cbp); -} - -static void -ccdintr(cs, bp) - register struct ccd_softc *cs; - register struct buf *bp; -{ - -#ifdef DEBUG - if (ccddebug & CCDB_FOLLOW) - printf("ccdintr(%x, %x)\n", cs, bp); -#endif - /* - * Request is done for better or worse, wakeup the top half. - */ -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - --cs->sc_nactive; -#ifdef DIAGNOSTIC - if (cs->sc_nactive < 0) - panic("ccdintr: ccd%d: sc_nactive < 0", cs->sc_unit); -#endif - - if (cs->sc_nactive == 0 && cs->sc_dk >= 0) - dk_busy &= ~(1 << cs->sc_dk); -#endif - if (bp->b_flags & B_ERROR) - bp->b_resid = bp->b_bcount; - biodone(bp); -} - -/* - * Called at interrupt time. - * Mark the component as done and if all components are done, - * take a ccd interrupt. - */ -void -ccdiodone(cbp) - struct ccdbuf *cbp; -{ - register struct buf *bp = cbp->cb_obp; - register int unit = cbp->cb_unit; - int count, s; - - s = splbio(); -#ifdef DEBUG - if (ccddebug & CCDB_FOLLOW) - printf("ccdiodone(%x)\n", cbp); - if (ccddebug & CCDB_IO) { - printf("ccdiodone: bp %x bcount %d resid %d\n", - bp, bp->b_bcount, bp->b_resid); - printf(" dev %x(u%d), cbp %x bn %d addr %x bcnt %d\n", - cbp->cb_buf.b_dev, cbp->cb_comp, cbp, - cbp->cb_buf.b_blkno, cbp->cb_buf.b_data, - cbp->cb_buf.b_bcount); - } -#endif - - if (cbp->cb_buf.b_flags & B_ERROR) { - bp->b_flags |= B_ERROR; - bp->b_error = cbp->cb_buf.b_error ? cbp->cb_buf.b_error : EIO; -#ifdef DEBUG - printf("ccd%d: error %d on component %d\n", - unit, bp->b_error, cbp->cb_comp); -#endif - } - count = cbp->cb_buf.b_bcount; - putccdbuf(cbp); - - /* - * If all done, "interrupt". - */ - bp->b_resid -= count; - if (bp->b_resid < 0) - panic("ccdiodone: count"); - if (bp->b_resid == 0) - ccdintr(&ccd_softc[unit], bp); - splx(s); -} - -/* ARGSUSED */ -int -ccdread(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - int unit = ccdunit(dev); - struct ccd_softc *cs; - -#ifdef DEBUG - if (ccddebug & CCDB_FOLLOW) - printf("ccdread(%x, %x)\n", dev, uio); -#endif - if (unit >= numccd) - return (ENXIO); - cs = &ccd_softc[unit]; - - if ((cs->sc_flags & CCDF_INITED) == 0) - return (ENXIO); - - /* - * XXX: It's not clear that using minphys() is completely safe, - * in particular, for raw I/O. Underlying devices might have some - * non-obvious limits, because of the copy to user-space. - */ - return (physio(ccdstrategy, NULL, dev, B_READ, minphys, uio)); -} - -/* ARGSUSED */ -int -ccdwrite(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - int unit = ccdunit(dev); - struct ccd_softc *cs; - -#ifdef DEBUG - if (ccddebug & CCDB_FOLLOW) - printf("ccdwrite(%x, %x)\n", dev, uio); -#endif - if (unit >= numccd) - return (ENXIO); - cs = &ccd_softc[unit]; - - if ((cs->sc_flags & CCDF_INITED) == 0) - return (ENXIO); - - /* - * XXX: It's not clear that using minphys() is completely safe, - * in particular, for raw I/O. Underlying devices might have some - * non-obvious limits, because of the copy to user-space. - */ - return (physio(ccdstrategy, NULL, dev, B_WRITE, minphys, uio)); -} - -int -ccdioctl(dev, cmd, data, flag, p) - dev_t dev; - u_long cmd; - caddr_t data; - int flag; - struct proc *p; -{ - int unit = ccdunit(dev); - int i, j, lookedup = 0, error = 0; - int part, pmask, s; - struct ccd_softc *cs; - struct ccd_ioctl *ccio = (struct ccd_ioctl *)data; - struct ccddevice ccd; - char **cpp; - struct vnode **vpp; -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - extern int dkn; -#endif - - if (unit >= numccd) - return (ENXIO); - cs = &ccd_softc[unit]; - - bzero(&ccd, sizeof(ccd)); - - switch (cmd) { - case CCDIOCSET: - if (cs->sc_flags & CCDF_INITED) - return (EBUSY); - - if ((flag & FWRITE) == 0) - return (EBADF); - - if (error = ccdlock(cs)) - return (error); - - /* Fill in some important bits. */ - ccd.ccd_unit = unit; - ccd.ccd_interleave = ccio->ccio_ileave; - ccd.ccd_flags = ccio->ccio_flags & CCDF_USERMASK; - - /* - * Allocate space for and copy in the array of - * componet pathnames and device numbers. - */ - cpp = malloc(ccio->ccio_ndisks * sizeof(char *), - M_DEVBUF, M_WAITOK); - vpp = malloc(ccio->ccio_ndisks * sizeof(struct vnode *), - M_DEVBUF, M_WAITOK); - - error = copyin((caddr_t)ccio->ccio_disks, (caddr_t)cpp, - ccio->ccio_ndisks * sizeof(char **)); - if (error) { - free(vpp, M_DEVBUF); - free(cpp, M_DEVBUF); - ccdunlock(cs); - return (error); - } - -#ifdef DEBUG - if (ccddebug & CCDB_INIT) - for (i = 0; i < ccio->ccio_ndisks; ++i) - printf("ccdioctl: component %d: 0x%x\n", - i, cpp[i]); -#endif - - for (i = 0; i < ccio->ccio_ndisks; ++i) { -#ifdef DEBUG - if (ccddebug & CCDB_INIT) - printf("ccdioctl: lookedup = %d\n", lookedup); -#endif - if (error = ccdlookup(cpp[i], p, &vpp[i])) { - for (j = 0; j < lookedup; ++j) - (void)vn_close(vpp[j], FREAD|FWRITE, - p->p_ucred, p); - free(vpp, M_DEVBUF); - free(cpp, M_DEVBUF); - ccdunlock(cs); - return (error); - } - ++lookedup; - } - ccd.ccd_cpp = cpp; - ccd.ccd_vpp = vpp; - ccd.ccd_ndev = ccio->ccio_ndisks; - -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - /* - * Assign disk index first so that init routine - * can use it (saves having the driver drag around - * the ccddevice pointer just to set up the dk_* - * info in the open routine). - */ - if (dkn < DK_NDRIVE) - ccd.ccd_dk = dkn++; - else - ccd.ccd_dk = -1; -#endif - - /* - * Initialize the ccd. Fills in the softc for us. - */ - if (error = ccdinit(&ccd, cpp, p)) { -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - if (ccd.ccd_dk >= 0) - --dkn; -#endif - for (j = 0; j < lookedup; ++j) - (void)vn_close(vpp[j], FREAD|FWRITE, - p->p_ucred, p); - bzero(&ccd_softc[unit], sizeof(struct ccd_softc)); - free(vpp, M_DEVBUF); - free(cpp, M_DEVBUF); - ccdunlock(cs); - return (error); - } - - /* - * The ccd has been successfully initialized, so - * we can place it into the array and read the disklabel. - */ - bcopy(&ccd, &ccddevs[unit], sizeof(ccd)); - ccio->ccio_unit = unit; - ccio->ccio_size = cs->sc_size; - ccdgetdisklabel(dev); - - ccdunlock(cs); - - break; - - case CCDIOCCLR: - if ((cs->sc_flags & CCDF_INITED) == 0) - return (ENXIO); - - if ((flag & FWRITE) == 0) - return (EBADF); - - if (error = ccdlock(cs)) - return (error); - - /* - * Don't unconfigure if any other partitions are open - * or if both the character and block flavors of this - * partition are open. - */ - part = DISKPART(dev); - pmask = (1 << part); - if ((cs->sc_dkdev.dk_openmask & ~pmask) || - ((cs->sc_dkdev.dk_bopenmask & pmask) && - (cs->sc_dkdev.dk_copenmask & pmask))) { - ccdunlock(cs); - return (EBUSY); - } - - /* - * Free ccd_softc information and clear entry. - */ - - /* Close the components and free their pathnames. */ - for (i = 0; i < cs->sc_nccdisks; ++i) { - /* - * XXX: this close could potentially fail and - * cause Bad Things. Maybe we need to force - * the close to happen? - */ -#ifdef DEBUG - if (ccddebug & CCDB_VNODE) - vprint("CCDIOCCLR: vnode info", - cs->sc_cinfo[i].ci_vp); -#endif - (void)vn_close(cs->sc_cinfo[i].ci_vp, FREAD|FWRITE, - p->p_ucred, p); - free(cs->sc_cinfo[i].ci_path, M_DEVBUF); - } - - /* Free interleave index. */ - for (i = 0; cs->sc_itable[i].ii_ndisk; ++i) - free(cs->sc_itable[i].ii_index, M_DEVBUF); - - /* Free component info and interleave table. */ - free(cs->sc_cinfo, M_DEVBUF); - free(cs->sc_itable, M_DEVBUF); - cs->sc_flags &= ~CCDF_INITED; - - /* - * Free ccddevice information and clear entry. - */ - free(ccddevs[unit].ccd_cpp, M_DEVBUF); - free(ccddevs[unit].ccd_vpp, M_DEVBUF); - ccd.ccd_dk = -1; - bcopy(&ccd, &ccddevs[unit], sizeof(ccd)); - - /* This must be atomic. */ - s = splhigh(); - ccdunlock(cs); - bzero(cs, sizeof(struct ccd_softc)); - splx(s); - - break; - - case DIOCGDINFO: - if ((cs->sc_flags & CCDF_INITED) == 0) - return (ENXIO); - - *(struct disklabel *)data = cs->sc_dkdev.dk_label; - break; - - case DIOCGPART: - if ((cs->sc_flags & CCDF_INITED) == 0) - return (ENXIO); - - ((struct partinfo *)data)->disklab = &cs->sc_dkdev.dk_label; - ((struct partinfo *)data)->part = - &cs->sc_dkdev.dk_label.d_partitions[DISKPART(dev)]; - break; - - case DIOCWDINFO: - case DIOCSDINFO: - if ((cs->sc_flags & CCDF_INITED) == 0) - return (ENXIO); - - if ((flag & FWRITE) == 0) - return (EBADF); - - if (error = ccdlock(cs)) - return (error); - - cs->sc_flags |= CCDF_LABELLING; - - error = setdisklabel(&cs->sc_dkdev.dk_label, - (struct disklabel *)data, 0, &cs->sc_dkdev.dk_cpulabel); - if (error == 0) { - if (cmd == DIOCWDINFO) - error = writedisklabel(CCDLABELDEV(dev), - ccdstrategy, &cs->sc_dkdev.dk_label, - &cs->sc_dkdev.dk_cpulabel); - } - - cs->sc_flags &= ~CCDF_LABELLING; - - ccdunlock(cs); - - if (error) - return (error); - break; - - case DIOCWLABEL: - if ((cs->sc_flags & CCDF_INITED) == 0) - return (ENXIO); - - if ((flag & FWRITE) == 0) - return (EBADF); - if (*(int *)data != 0) - cs->sc_flags |= CCDF_WLABEL; - else - cs->sc_flags &= ~CCDF_WLABEL; - break; - - default: - return (ENOTTY); - } - - return (0); -} - -int -ccdsize(dev) - dev_t dev; -{ - struct ccd_softc *cs; - int part, size; - - if (ccdopen(dev, 0, S_IFBLK, curproc)) - return (-1); - - cs = &ccd_softc[ccdunit(dev)]; - part = DISKPART(dev); - - if ((cs->sc_flags & CCDF_INITED) == 0) - return (-1); - - if (cs->sc_dkdev.dk_label.d_partitions[part].p_fstype != FS_SWAP) - size = -1; - else - size = cs->sc_dkdev.dk_label.d_partitions[part].p_size; - - if (ccdclose(dev, 0, S_IFBLK, curproc)) - return (-1); - - return (size); -} - -int -ccddump(dev, blkno, va, size) - dev_t dev; - daddr_t blkno; - caddr_t va; - size_t size; -{ - - /* Not implemented. */ - return ENXIO; -} - -/* - * Lookup the provided name in the filesystem. If the file exists, - * is a valid block device, and isn't being used by anyone else, - * set *vpp to the file's vnode. - */ -static int -ccdlookup(path, p, vpp) - char *path; - struct proc *p; - struct vnode **vpp; /* result */ -{ - struct nameidata nd; - struct vnode *vp; - struct vattr va; - int error; - - NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, path, p); - if (error = vn_open(&nd, FREAD|FWRITE, 0)) { -#ifdef DEBUG - if (ccddebug & CCDB_FOLLOW|CCDB_INIT) - printf("ccdlookup: vn_open error = %d\n", error); -#endif - return (error); - } - vp = nd.ni_vp; - - if (vp->v_usecount > 1) { - VOP_UNLOCK(vp); - (void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p); - return (EBUSY); - } - - if (error = VOP_GETATTR(vp, &va, p->p_ucred, p)) { -#ifdef DEBUG - if (ccddebug & CCDB_FOLLOW|CCDB_INIT) - printf("ccdlookup: getattr error = %d\n", error); -#endif - VOP_UNLOCK(vp); - (void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p); - return (error); - } - - /* XXX: eventually we should handle VREG, too. */ - if (va.va_type != VBLK) { - VOP_UNLOCK(vp); - (void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p); - return (ENOTBLK); - } - -#ifdef DEBUG - if (ccddebug & CCDB_VNODE) - vprint("ccdlookup: vnode info", vp); -#endif - - VOP_UNLOCK(vp); - *vpp = vp; - return (0); -} - -/* - * Read the disklabel from the ccd. If one is not present, fake one - * up. - */ -static void -ccdgetdisklabel(dev) - dev_t dev; -{ - int unit = ccdunit(dev); - struct ccd_softc *cs = &ccd_softc[unit]; - char *errstring; - struct disklabel *lp = &cs->sc_dkdev.dk_label; - struct cpu_disklabel *clp = &cs->sc_dkdev.dk_cpulabel; - struct ccdgeom *ccg = &cs->sc_geom; - - bzero(lp, sizeof(*lp)); - bzero(clp, sizeof(*clp)); - - lp->d_secperunit = cs->sc_size; - lp->d_secsize = ccg->ccg_secsize; - lp->d_nsectors = ccg->ccg_nsectors; - lp->d_ntracks = ccg->ccg_ntracks; - lp->d_ncylinders = ccg->ccg_ncylinders; - lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors; - - strncpy(lp->d_typename, "ccd", sizeof(lp->d_typename)); - lp->d_type = DTYPE_CCD; - strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname)); - lp->d_rpm = 3600; - lp->d_interleave = 1; - lp->d_flags = 0; - - lp->d_partitions[RAW_PART].p_offset = 0; - lp->d_partitions[RAW_PART].p_size = cs->sc_size; - lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED; - lp->d_npartitions = RAW_PART + 1; - - lp->d_magic = DISKMAGIC; - lp->d_magic2 = DISKMAGIC; - lp->d_checksum = dkcksum(&cs->sc_dkdev.dk_label); - - /* - * Call the generic disklabel extraction routine. - */ - if (errstring = readdisklabel(CCDLABELDEV(dev), ccdstrategy, - &cs->sc_dkdev.dk_label, &cs->sc_dkdev.dk_cpulabel)) - ccdmakedisklabel(cs); - -#ifdef DEBUG - /* It's actually extremely common to have unlabeled ccds. */ - if (ccddebug & CCDB_LABEL) - if (errstring != NULL) - printf("ccd%d: %s\n", unit, errstring); -#endif -} - -/* - * Take care of things one might want to take care of in the event - * that a disklabel isn't present. - */ -static void -ccdmakedisklabel(cs) - struct ccd_softc *cs; -{ - struct disklabel *lp = &cs->sc_dkdev.dk_label; - - /* - * For historical reasons, if there's no disklabel present - * the raw partition must be marked FS_BSDFFS. - */ - lp->d_partitions[RAW_PART].p_fstype = FS_BSDFFS; - - strncpy(lp->d_packname, "default label", sizeof(lp->d_packname)); -} - -/* - * Wait interruptibly for an exclusive lock. - * - * XXX - * Several drivers do this; it should be abstracted and made MP-safe. - */ -static int -ccdlock(cs) - struct ccd_softc *cs; -{ - int error; - - while ((cs->sc_flags & CCDF_LOCKED) != 0) { - cs->sc_flags |= CCDF_WANTED; - if ((error = tsleep(cs, PRIBIO | PCATCH, "ccdlck", 0)) != 0) - return (error); - } - cs->sc_flags |= CCDF_LOCKED; - return (0); -} - -/* - * Unlock and wake up any waiters. - */ -static void -ccdunlock(cs) - struct ccd_softc *cs; -{ - - cs->sc_flags &= ~CCDF_LOCKED; - if ((cs->sc_flags & CCDF_WANTED) != 0) { - cs->sc_flags &= ~CCDF_WANTED; - wakeup(cs); - } -} - -#ifdef DEBUG -static void -printiinfo(ii) - struct ccdiinfo *ii; -{ - register int ix, i; - - for (ix = 0; ii->ii_ndisk; ix++, ii++) { - printf(" itab[%d]: #dk %d sblk %d soff %d", - ix, ii->ii_ndisk, ii->ii_startblk, ii->ii_startoff); - for (i = 0; i < ii->ii_ndisk; i++) - printf(" %d", ii->ii_index[i]); - printf("\n"); - } -} -#endif diff --git a/sys/i386/ibcs2/ibcs2_dirent.h b/sys/i386/ibcs2/ibcs2_dirent.h deleted file mode 100644 index f93e3a93c5a2..000000000000 --- a/sys/i386/ibcs2/ibcs2_dirent.h +++ /dev/null @@ -1,57 +0,0 @@ -/* $NetBSD: ibcs2_dirent.h,v 1.2 1994/10/26 02:52:51 cgd Exp $ */ - -/* - * Copyright (c) 1994 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_DIRENT_H -#define _IBCS2_DIRENT_H 1 - -#include <compat/ibcs2/ibcs2_types.h> - -#define IBCS2_MAXNAMLEN 512 -#define IBCS2_DIRBUF 1048 - -typedef struct { - int dd_fd; - int dd_loc; - int dd_size; - char *dd_buf; -} IBCS2_DIR; - -struct ibcs2_dirent { - ibcs2_ino_t d_ino; - short d_pad; - ibcs2_off_t d_off; - u_short d_reclen; - char d_name[1]; -}; - -#endif /* _IBCS2_DIRENT_H */ diff --git a/sys/i386/ibcs2/ibcs2_errno.c b/sys/i386/ibcs2/ibcs2_errno.c deleted file mode 100644 index 48cb88eb9c16..000000000000 --- a/sys/i386/ibcs2/ibcs2_errno.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * ibcs2_errno.c - * Copyright (c) 1995 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -#include <compat/ibcs2/ibcs2_errno.h> - -int bsd2ibcs_errno[] = { - 0, /* 0 */ - IBCS2_EPERM, /* 1 */ - IBCS2_ENOENT, /* 2 */ - IBCS2_ESRCH, /* 3 */ - IBCS2_EINTR, /* 4 */ - IBCS2_EIO, /* 5 */ - IBCS2_ENXIO, /* 6 */ - IBCS2_E2BIG, /* 7 */ - IBCS2_ENOEXEC, /* 8 */ - IBCS2_EBADF, /* 9 */ - IBCS2_ECHILD, /* 10 */ - IBCS2_EDEADLK, /* 11 */ - IBCS2_ENOMEM, /* 12 */ - IBCS2_EACCES, /* 13 */ - IBCS2_EFAULT, /* 14 */ - IBCS2_ENOTBLK, /* 15 */ - IBCS2_EBUSY, /* 16 */ - IBCS2_EEXIST, /* 17 */ - IBCS2_EXDEV, /* 18 */ - IBCS2_ENODEV, /* 19 */ - IBCS2_ENOTDIR, /* 20 */ - IBCS2_EISDIR, /* 21 */ - IBCS2_EINVAL, /* 22 */ - IBCS2_ENFILE, /* 23 */ - IBCS2_EMFILE, /* 24 */ - IBCS2_ENOTTY, /* 25 */ - IBCS2_ETXTBSY, /* 26 */ - IBCS2_EFBIG, /* 27 */ - IBCS2_ENOSPC, /* 28 */ - IBCS2_ESPIPE, /* 29 */ - IBCS2_EROFS, /* 30 */ - IBCS2_EMLINK, /* 31 */ - IBCS2_EPIPE, /* 32 */ - IBCS2_EDOM, /* 33 */ - IBCS2_ERANGE, /* 34 */ - IBCS2_EAGAIN, /* 35 */ - IBCS2_EINPROGRESS, /* 36 */ - IBCS2_EALREADY, /* 37 */ - IBCS2_ENOTSOCK, /* 38 */ - IBCS2_EDESTADDRREQ, /* 39 */ - IBCS2_EMSGSIZE, /* 40 */ - IBCS2_EPROTOTYPE, /* 41 */ - IBCS2_ENOPROTOOPT, /* 42 */ - IBCS2_EPROTONOSUPPORT, /* 43 */ - IBCS2_ESOCKTNOSUPPORT, /* 44 */ - IBCS2_EOPNOTSUPP, /* 45 */ - IBCS2_EPFNOSUPPORT, /* 46 */ - IBCS2_EAFNOSUPPORT, /* 47 */ - IBCS2_EADDRINUSE, /* 48 */ - IBCS2_EADDRNOTAVAIL, /* 49 */ - IBCS2_ENETDOWN, /* 50 */ - IBCS2_ENETUNREACH, /* 51 */ - IBCS2_ENETRESET, /* 52 */ - IBCS2_ECONNABORTED, /* 53 */ - IBCS2_ECONNRESET, /* 54 */ - IBCS2_ENOBUFS, /* 55 */ - IBCS2_EISCONN, /* 56 */ - IBCS2_ENOTCONN, /* 57 */ - IBCS2_ESHUTDOWN, /* 58 */ - IBCS2_ETOOMANYREFS, /* 59 */ - IBCS2_ETIMEDOUT, /* 60 */ - IBCS2_ECONNREFUSED, /* 61 */ - IBCS2_ELOOP, /* 62 */ - IBCS2_ENAMETOOLONG, /* 63 */ - IBCS2_EHOSTDOWN, /* 64 */ - IBCS2_EHOSTUNREACH, /* 65 */ - IBCS2_ENOTEMPTY, /* 66 */ - 0, /* 67 */ - 0, /* 68 */ - 0, /* 69 */ - IBCS2_ESTALE, /* 70 */ - IBCS2_EREMOTE, /* 71 */ - 0, /* 72 */ - 0, /* 73 */ - 0, /* 74 */ - 0, /* 75 */ - 0, /* 76 */ - IBCS2_ENOLCK, /* 77 */ - IBCS2_ENOSYS, /* 78 */ - 0, /* 79 */ - 0, /* 80 */ - 0, /* 81 */ -}; - diff --git a/sys/i386/ibcs2/ibcs2_errno.h b/sys/i386/ibcs2/ibcs2_errno.h deleted file mode 100644 index 30ed8241ae28..000000000000 --- a/sys/i386/ibcs2/ibcs2_errno.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * ibcs2_errno.h - * Copyright (c) 1995 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_ERRNO_H -#define _IBCS2_ERRNO_H - -#define _SCO_NET 1 - -#define IBCS2_EPERM 1 -#define IBCS2_ENOENT 2 -#define IBCS2_ESRCH 3 -#define IBCS2_EINTR 4 -#define IBCS2_EIO 5 -#define IBCS2_ENXIO 6 -#define IBCS2_E2BIG 7 -#define IBCS2_ENOEXEC 8 -#define IBCS2_EBADF 9 -#define IBCS2_ECHILD 10 -#define IBCS2_EAGAIN 11 -#define IBCS2_ENOMEM 12 -#define IBCS2_EACCES 13 -#define IBCS2_EFAULT 14 -#define IBCS2_ENOTBLK 15 -#define IBCS2_EBUSY 16 -#define IBCS2_EEXIST 17 -#define IBCS2_EXDEV 18 -#define IBCS2_ENODEV 19 -#define IBCS2_ENOTDIR 20 -#define IBCS2_EISDIR 21 -#define IBCS2_EINVAL 22 -#define IBCS2_ENFILE 23 -#define IBCS2_EMFILE 24 -#define IBCS2_ENOTTY 25 -#define IBCS2_ETXTBSY 26 -#define IBCS2_EFBIG 27 -#define IBCS2_ENOSPC 28 -#define IBCS2_ESPIPE 29 -#define IBCS2_EROFS 30 -#define IBCS2_EMLINK 31 -#define IBCS2_EPIPE 32 -#define IBCS2_EDOM 33 -#define IBCS2_ERANGE 34 -#define IBCS2_ENOMSG 35 -#define IBCS2_EIDRM 36 -#define IBCS2_ECHRNG 37 -#define IBCS2_EL2NSYNC 38 -#define IBCS2_EL3HLT 39 -#define IBCS2_EL3RST 40 -#define IBCS2_ELNRNG 41 -#define IBCS2_EUNATCH 42 -#define IBCS2_ENOCSI 43 -#define IBCS2_EL2HLT 44 -#define IBCS2_EDEADLK 45 -#define IBCS2_ENOLCK 46 -#define IBCS2_ENOSTR 60 -#define IBCS2_ENODATA 61 -#define IBCS2_ETIME 62 -#define IBCS2_ENOSR 63 -#define IBCS2_ENONET 64 -#define IBCS2_ENOPKG 65 -#define IBCS2_EREMOTE 66 -#define IBCS2_ENOLINK 67 -#define IBCS2_EADV 68 -#define IBCS2_ESRMNT 69 -#define IBCS2_ECOMM 70 -#define IBCS2_EPROTO 71 -#define IBCS2_EMULTIHOP 74 -#define IBCS2_ELBIN 75 -#define IBCS2_EDOTDOT 76 -#define IBCS2_EBADMSG 77 -#define IBCS2_ENAMETOOLONG 78 -#define IBCS2_EOVERFLOW 79 -#define IBCS2_ENOTUNIQ 80 -#define IBCS2_EBADFD 81 -#define IBCS2_EREMCHG 82 -#define IBCS2_EILSEQ 88 -#define IBCS2_ENOSYS 89 - -#if defined(_SCO_NET) /* not strict iBCS2 */ -#define IBCS2_EWOULDBLOCK 90 -#define IBCS2_EINPROGRESS 91 -#define IBCS2_EALREADY 92 -#define IBCS2_ENOTSOCK 93 -#define IBCS2_EDESTADDRREQ 94 -#define IBCS2_EMSGSIZE 95 -#define IBCS2_EPROTOTYPE 96 -#define IBCS2_EPROTONOSUPPORT 97 -#define IBCS2_ESOCKTNOSUPPORT 98 -#define IBCS2_EOPNOTSUPP 99 -#define IBCS2_EPFNOSUPPORT 100 -#define IBCS2_EAFNOSUPPORT 101 -#define IBCS2_EADDRINUSE 102 -#define IBCS2_EADDRNOTAVAIL 103 -#define IBCS2_ENETDOWN 104 -#define IBCS2_ENETUNREACH 105 -#define IBCS2_ENETRESET 106 -#define IBCS2_ECONNABORTED 107 -#define IBCS2_ECONNRESET 108 -#define IBCS2_ENOBUFS IBCS2_ENOSR -#define IBCS2_EISCONN 110 -#define IBCS2_ENOTCONN 111 -#define IBCS2_ESHUTDOWN 112 -#define IBCS2_ETOOMANYREFS 113 -#define IBCS2_ETIMEDOUT 114 -#define IBCS2_ECONNREFUSED 115 -#define IBCS2_EHOSTDOWN 116 -#define IBCS2_EHOSTUNREACH 117 -#define IBCS2_ENOPROTOOPT 118 -#define IBCS2_ENOTEMPTY 145 -#define IBCS2_ELOOP 150 -#else -#define IBCS2_ELOOP 90 -#define IBCS2_EWOULDBLOCK 90 -#define IBCS2_ERESTART 91 -#define IBCS2_ESTRPIPE 92 -#define IBCS2_ENOTEMPTY 93 -#define IBCS2_EUSERS 94 -#endif - -#define IBCS2_ESTALE 151 -#define IBCS2_EIORESID 500 - -extern int bsd2ibcs_errno[]; - -#endif /* _IBCS2_ERRNO_H */ diff --git a/sys/i386/ibcs2/ibcs2_fcntl.c b/sys/i386/ibcs2/ibcs2_fcntl.c deleted file mode 100644 index 4dede8c15b52..000000000000 --- a/sys/i386/ibcs2/ibcs2_fcntl.c +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright (c) 1995 Scott Bartram - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/namei.h> -#include <sys/proc.h> -#include <sys/file.h> -#include <sys/stat.h> -#include <sys/filedesc.h> -#include <sys/ioctl.h> -#include <sys/kernel.h> -#include <sys/mount.h> -#include <sys/malloc.h> -#include <sys/syscallargs.h> - -#include <compat/ibcs2/ibcs2_types.h> -#include <compat/ibcs2/ibcs2_fcntl.h> -#include <compat/ibcs2/ibcs2_signal.h> -#include <compat/ibcs2/ibcs2_syscallargs.h> -#include <compat/ibcs2/ibcs2_util.h> - - -static int -cvt_o_flags(flags) - int flags; -{ - int r = 0; - - /* convert mode into NetBSD mode */ - if (flags & IBCS2_O_WRONLY) r |= O_WRONLY; - if (flags & IBCS2_O_RDWR) r |= O_RDWR; - if (flags & (IBCS2_O_NDELAY | IBCS2_O_NONBLOCK)) r |= O_NONBLOCK; - if (flags & IBCS2_O_APPEND) r |= O_APPEND; - if (flags & IBCS2_O_SYNC) r |= O_FSYNC; - if (flags & IBCS2_O_CREAT) r |= O_CREAT; - if (flags & IBCS2_O_TRUNC) r |= O_TRUNC; - if (flags & IBCS2_O_EXCL) r |= O_EXCL; - return r; -} - -static void -cvt_flock2iflock(flp, iflp) - struct flock *flp; - struct ibcs2_flock *iflp; -{ - switch (flp->l_type) { - case F_RDLCK: - iflp->l_type = IBCS2_F_RDLCK; - break; - case F_WRLCK: - iflp->l_type = IBCS2_F_WRLCK; - break; - case F_UNLCK: - iflp->l_type = IBCS2_F_UNLCK; - break; - } - iflp->l_whence = (short)flp->l_whence; - iflp->l_start = (ibcs2_off_t)flp->l_start; - iflp->l_len = (ibcs2_off_t)flp->l_len; - iflp->l_sysid = 0; - iflp->l_pid = (ibcs2_pid_t)flp->l_pid; -} - -static void -cvt_iflock2flock(iflp, flp) - struct ibcs2_flock *iflp; - struct flock *flp; -{ - flp->l_start = (off_t)iflp->l_start; - flp->l_len = (off_t)iflp->l_len; - flp->l_pid = (pid_t)iflp->l_pid; - switch (iflp->l_type) { - case IBCS2_F_RDLCK: - flp->l_type = F_RDLCK; - break; - case IBCS2_F_WRLCK: - flp->l_type = F_WRLCK; - break; - case IBCS2_F_UNLCK: - flp->l_type = F_UNLCK; - break; - } - flp->l_whence = iflp->l_whence; -} - -/* convert iBCS2 mode into NetBSD mode */ -static int -ioflags2oflags(flags) - int flags; -{ - int r = 0; - - if (flags & IBCS2_O_RDONLY) r |= O_RDONLY; - if (flags & IBCS2_O_WRONLY) r |= O_WRONLY; - if (flags & IBCS2_O_RDWR) r |= O_RDWR; - if (flags & IBCS2_O_NDELAY) r |= O_NONBLOCK; - if (flags & IBCS2_O_APPEND) r |= O_APPEND; - if (flags & IBCS2_O_SYNC) r |= O_FSYNC; - if (flags & IBCS2_O_NONBLOCK) r |= O_NONBLOCK; - if (flags & IBCS2_O_CREAT) r |= O_CREAT; - if (flags & IBCS2_O_TRUNC) r |= O_TRUNC; - if (flags & IBCS2_O_EXCL) r |= O_EXCL; - if (flags & IBCS2_O_NOCTTY) r |= O_NOCTTY; - return r; -} - -/* convert NetBSD mode into iBCS2 mode */ -static int -oflags2ioflags(flags) - int flags; -{ - int r = 0; - - if (flags & O_RDONLY) r |= IBCS2_O_RDONLY; - if (flags & O_WRONLY) r |= IBCS2_O_WRONLY; - if (flags & O_RDWR) r |= IBCS2_O_RDWR; - if (flags & O_NDELAY) r |= IBCS2_O_NONBLOCK; - if (flags & O_APPEND) r |= IBCS2_O_APPEND; - if (flags & O_FSYNC) r |= IBCS2_O_SYNC; - if (flags & O_NONBLOCK) r |= IBCS2_O_NONBLOCK; - if (flags & O_CREAT) r |= IBCS2_O_CREAT; - if (flags & O_TRUNC) r |= IBCS2_O_TRUNC; - if (flags & O_EXCL) r |= IBCS2_O_EXCL; - if (flags & O_NOCTTY) r |= IBCS2_O_NOCTTY; - return r; -} - -int -ibcs2_open(p, uap, retval) - struct proc *p; - struct ibcs2_open_args *uap; - int *retval; -{ - int noctty = SCARG(uap, flags) & IBCS2_O_NOCTTY; - int ret; - caddr_t sg = stackgap_init(); - - SCARG(uap, flags) = cvt_o_flags(SCARG(uap, flags)); - if (SCARG(uap, flags) & O_CREAT) - CHECKALTCREAT(p, &sg, SCARG(uap, path)); - else - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - ret = open(p, uap, retval); - - if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) { - struct filedesc *fdp = p->p_fd; - struct file *fp = fdp->fd_ofiles[*retval]; - - /* ignore any error, just give it a try */ - if (fp->f_type == DTYPE_VNODE) - (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p); - } - return ret; -} - -int -ibcs2_creat(p, uap, retval) - struct proc *p; - struct ibcs2_creat_args *uap; - int *retval; -{ - struct open_args cup; - caddr_t sg = stackgap_init(); - - CHECKALTCREAT(p, &sg, SCARG(uap, path)); - SCARG(&cup, path) = SCARG(uap, path); - SCARG(&cup, mode) = SCARG(uap, mode); - SCARG(&cup, flags) = O_WRONLY | O_CREAT | O_TRUNC; - return open(p, &cup, retval); -} - -int -ibcs2_access(p, uap, retval) - struct proc *p; - struct ibcs2_access_args *uap; - int *retval; -{ - struct access_args cup; - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - SCARG(&cup, path) = SCARG(uap, path); - SCARG(&cup, flags) = SCARG(uap, flags); - return access(p, &cup, retval); -} - -int -ibcs2_fcntl(p, uap, retval) - struct proc *p; - struct ibcs2_fcntl_args *uap; - int *retval; -{ - int error; - struct fcntl_args fa; - struct flock *flp; - struct ibcs2_flock ifl; - - switch(SCARG(uap, cmd)) { - case IBCS2_F_DUPFD: - SCARG(&fa, fd) = SCARG(uap, fd); - SCARG(&fa, cmd) = F_DUPFD; - SCARG(&fa, arg) = SCARG(uap, arg); - return fcntl(p, &fa, retval); - case IBCS2_F_GETFD: - SCARG(&fa, fd) = SCARG(uap, fd); - SCARG(&fa, cmd) = F_GETFD; - SCARG(&fa, arg) = SCARG(uap, arg); - return fcntl(p, &fa, retval); - case IBCS2_F_SETFD: - SCARG(&fa, fd) = SCARG(uap, fd); - SCARG(&fa, cmd) = F_SETFD; - SCARG(&fa, arg) = SCARG(uap, arg); - return fcntl(p, &fa, retval); - case IBCS2_F_GETFL: - SCARG(&fa, fd) = SCARG(uap, fd); - SCARG(&fa, cmd) = F_GETFL; - SCARG(&fa, arg) = SCARG(uap, arg); - error = fcntl(p, &fa, retval); - if (error) - return error; - *retval = oflags2ioflags(*retval); - return error; - case IBCS2_F_SETFL: - SCARG(&fa, fd) = SCARG(uap, fd); - SCARG(&fa, cmd) = F_SETFL; - SCARG(&fa, arg) = (void *)ioflags2oflags(SCARG(uap, arg)); - return fcntl(p, &fa, retval); - - case IBCS2_F_GETLK: - { - caddr_t sg = stackgap_init(); - flp = stackgap_alloc(&sg, sizeof(*flp)); - error = copyin((caddr_t)SCARG(uap, arg), (caddr_t)&ifl, - ibcs2_flock_len); - if (error) - return error; - cvt_iflock2flock(&ifl, flp); - SCARG(&fa, fd) = SCARG(uap, fd); - SCARG(&fa, cmd) = F_GETLK; - SCARG(&fa, arg) = (void *)flp; - error = fcntl(p, &fa, retval); - if (error) - return error; - cvt_flock2iflock(flp, &ifl); - return copyout((caddr_t)&ifl, (caddr_t)SCARG(uap, arg), - ibcs2_flock_len); - } - - case IBCS2_F_SETLK: - { - caddr_t sg = stackgap_init(); - flp = stackgap_alloc(&sg, sizeof(*flp)); - error = copyin((caddr_t)SCARG(uap, arg), (caddr_t)&ifl, - ibcs2_flock_len); - if (error) - return error; - cvt_iflock2flock(&ifl, flp); - SCARG(&fa, fd) = SCARG(uap, fd); - SCARG(&fa, cmd) = F_SETLK; - SCARG(&fa, arg) = (void *)flp; - return fcntl(p, &fa, retval); - } - - case IBCS2_F_SETLKW: - { - caddr_t sg = stackgap_init(); - flp = stackgap_alloc(&sg, sizeof(*flp)); - error = copyin((caddr_t)SCARG(uap, arg), (caddr_t)&ifl, - ibcs2_flock_len); - if (error) - return error; - cvt_iflock2flock(&ifl, flp); - SCARG(&fa, fd) = SCARG(uap, fd); - SCARG(&fa, cmd) = F_SETLKW; - SCARG(&fa, arg) = (void *)flp; - return fcntl(p, &fa, retval); - } - } - return ENOSYS; -} diff --git a/sys/i386/ibcs2/ibcs2_fcntl.h b/sys/i386/ibcs2/ibcs2_fcntl.h deleted file mode 100644 index b75537cb66f5..000000000000 --- a/sys/i386/ibcs2/ibcs2_fcntl.h +++ /dev/null @@ -1,76 +0,0 @@ -/* $NetBSD: ibcs2_fcntl.h,v 1.2 1994/10/26 02:52:54 cgd Exp $ */ - -/* - * Copyright (c) 1994 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_FCNTL_H -#define _IBCS2_FCNTL_H 1 - -#include <compat/ibcs2/ibcs2_types.h> - -#define IBCS2_O_RDONLY 0x0000 -#define IBCS2_O_WRONLY 0x0001 -#define IBCS2_O_RDWR 0x0002 -#define IBCS2_O_NDELAY 0x0004 -#define IBCS2_O_APPEND 0x0008 -#define IBCS2_O_SYNC 0x0010 -#define IBCS2_O_NONBLOCK 0x0080 -#define IBCS2_O_CREAT 0x0100 -#define IBCS2_O_TRUNC 0x0200 -#define IBCS2_O_EXCL 0x0400 -#define IBCS2_O_NOCTTY 0x0800 - -#define IBCS2_F_DUPFD 0 -#define IBCS2_F_GETFD 1 -#define IBCS2_F_SETFD 2 -#define IBCS2_F_GETFL 3 -#define IBCS2_F_SETFL 4 -#define IBCS2_F_GETLK 5 -#define IBCS2_F_SETLK 6 -#define IBCS2_F_SETLKW 7 - -struct ibcs2_flock { - short l_type; - short l_whence; - ibcs2_off_t l_start; - ibcs2_off_t l_len; - short l_sysid; - ibcs2_pid_t l_pid; -}; -#define ibcs2_flock_len (sizeof(struct ibcs2_flock)) - -#define IBCS2_F_RDLCK 1 -#define IBCS2_F_WRLCK 2 -#define IBCS2_F_UNLCK 3 - -#define IBCS2_O_ACCMODE 3 -#define IBCS2_FD_CLOEXEC 1 - -#endif /* _IBCS2_FCNTL_H */ diff --git a/sys/i386/ibcs2/ibcs2_ioctl.c b/sys/i386/ibcs2/ibcs2_ioctl.c deleted file mode 100644 index 9b45f50527cc..000000000000 --- a/sys/i386/ibcs2/ibcs2_ioctl.c +++ /dev/null @@ -1,487 +0,0 @@ -/* $NetBSD: ibcs2_ioctl.c,v 1.6 1995/03/14 15:12:28 scottb Exp $ */ - -/* - * Copyright (c) 1994, 1995 Scott Bartram - * All rights reserved. - * - * based on compat/sunos/sun_ioctl.c - * - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/namei.h> -#include <sys/dir.h> -#include <sys/proc.h> -#include <sys/file.h> -#include <sys/stat.h> -#include <sys/filedesc.h> -#include <sys/ioctl.h> -#include <sys/kernel.h> -#include <sys/malloc.h> -#include <sys/mbuf.h> -#include <sys/mman.h> -#include <sys/mount.h> -#include <sys/reboot.h> -#include <sys/resource.h> -#include <sys/resourcevar.h> -#include <sys/signal.h> -#include <sys/signalvar.h> -#include <sys/socket.h> -#include <sys/termios.h> -#include <sys/time.h> -#include <sys/times.h> -#include <sys/tty.h> -#include <sys/vnode.h> -#include <sys/uio.h> -#include <sys/wait.h> -#include <sys/utsname.h> -#include <sys/unistd.h> - -#include <net/if.h> -#include <sys/syscallargs.h> - -#include <compat/ibcs2/ibcs2_types.h> -#include <compat/ibcs2/ibcs2_signal.h> -#include <compat/ibcs2/ibcs2_socksys.h> -#include <compat/ibcs2/ibcs2_stropts.h> -#include <compat/ibcs2/ibcs2_syscallargs.h> -#include <compat/ibcs2/ibcs2_termios.h> -#include <compat/ibcs2/ibcs2_util.h> - -/* - * iBCS2 ioctl calls. - */ - -static struct speedtab sptab[] = { - { 0, 0 }, - { 50, 1 }, - { 75, 2 }, - { 110, 3 }, - { 134, 4 }, - { 135, 4 }, - { 150, 5 }, - { 200, 6 }, - { 300, 7 }, - { 600, 8 }, - { 1200, 9 }, - { 1800, 10 }, - { 2400, 11 }, - { 4800, 12 }, - { 9600, 13 }, - { 19200, 14 }, - { 38400, 15 }, - { -1, -1 } -}; - -static u_long s2btab[] = { - 0, - 50, - 75, - 110, - 134, - 150, - 200, - 300, - 600, - 1200, - 1800, - 2400, - 4800, - 9600, - 19200, - 38400, -}; - -static void -stios2btios(st, bt) - struct ibcs2_termios *st; - struct termios *bt; -{ - register u_long l, r; - - l = st->c_iflag; r = 0; - if (l & IBCS2_IGNBRK) r |= IGNBRK; - if (l & IBCS2_BRKINT) r |= BRKINT; - if (l & IBCS2_IGNPAR) r |= IGNPAR; - if (l & IBCS2_PARMRK) r |= PARMRK; - if (l & IBCS2_INPCK) r |= INPCK; - if (l & IBCS2_ISTRIP) r |= ISTRIP; - if (l & IBCS2_INLCR) r |= INLCR; - if (l & IBCS2_IGNCR) r |= IGNCR; - if (l & IBCS2_ICRNL) r |= ICRNL; - if (l & IBCS2_IXON) r |= IXON; - if (l & IBCS2_IXANY) r |= IXANY; - if (l & IBCS2_IXOFF) r |= IXOFF; - if (l & IBCS2_IMAXBEL) r |= IMAXBEL; - bt->c_iflag = r; - - l = st->c_oflag; r = 0; - if (l & IBCS2_OPOST) r |= OPOST; - if (l & IBCS2_ONLCR) r |= ONLCR; - if (l & IBCS2_TAB3) r |= OXTABS; - bt->c_oflag = r; - - l = st->c_cflag; r = 0; - switch (l & IBCS2_CSIZE) { - case IBCS2_CS5: r |= CS5; break; - case IBCS2_CS6: r |= CS6; break; - case IBCS2_CS7: r |= CS7; break; - case IBCS2_CS8: r |= CS8; break; - } - if (l & IBCS2_CSTOPB) r |= CSTOPB; - if (l & IBCS2_CREAD) r |= CREAD; - if (l & IBCS2_PARENB) r |= PARENB; - if (l & IBCS2_PARODD) r |= PARODD; - if (l & IBCS2_HUPCL) r |= HUPCL; - if (l & IBCS2_CLOCAL) r |= CLOCAL; - bt->c_cflag = r; - - l = st->c_lflag; r = 0; - if (l & IBCS2_ISIG) r |= ISIG; - if (l & IBCS2_ICANON) r |= ICANON; - if (l & IBCS2_ECHO) r |= ECHO; - if (l & IBCS2_ECHOE) r |= ECHOE; - if (l & IBCS2_ECHOK) r |= ECHOK; - if (l & IBCS2_ECHONL) r |= ECHONL; - if (l & IBCS2_NOFLSH) r |= NOFLSH; - if (l & IBCS2_TOSTOP) r |= TOSTOP; - bt->c_lflag = r; - - bt->c_ispeed = bt->c_ospeed = s2btab[l & 0x0000000f]; - - bt->c_cc[VINTR] = - st->c_cc[IBCS2_VINTR] ? st->c_cc[IBCS2_VINTR] : _POSIX_VDISABLE; - bt->c_cc[VQUIT] = - st->c_cc[IBCS2_VQUIT] ? st->c_cc[IBCS2_VQUIT] : _POSIX_VDISABLE; - bt->c_cc[VERASE] = - st->c_cc[IBCS2_VERASE] ? st->c_cc[IBCS2_VERASE] : _POSIX_VDISABLE; - bt->c_cc[VKILL] = - st->c_cc[IBCS2_VKILL] ? st->c_cc[IBCS2_VKILL] : _POSIX_VDISABLE; - bt->c_cc[VEOF] = - st->c_cc[IBCS2_VEOF] ? st->c_cc[IBCS2_VEOF] : _POSIX_VDISABLE; - bt->c_cc[VEOL] = - st->c_cc[IBCS2_VEOL] ? st->c_cc[IBCS2_VEOL] : _POSIX_VDISABLE; - bt->c_cc[VEOL2] = - st->c_cc[IBCS2_VEOL2] ? st->c_cc[IBCS2_VEOL2] : _POSIX_VDISABLE; -#if 0 - bt->c_cc[VSWTCH] = - st->c_cc[IBCS2_VSWTCH] ? st->c_cc[IBCS2_VSWTCH] : _POSIX_VDISABLE; -#endif - bt->c_cc[VSTART] = - st->c_cc[IBCS2_VSTART] ? st->c_cc[IBCS2_VSTART] : _POSIX_VDISABLE; - bt->c_cc[VSTOP] = - st->c_cc[IBCS2_VSTOP] ? st->c_cc[IBCS2_VSTOP] : _POSIX_VDISABLE; - bt->c_cc[VSUSP] = - st->c_cc[IBCS2_VSUSP] ? st->c_cc[IBCS2_VSUSP] : _POSIX_VDISABLE; - bt->c_cc[VDSUSP] = _POSIX_VDISABLE; - bt->c_cc[VREPRINT] = _POSIX_VDISABLE; - bt->c_cc[VDISCARD] = _POSIX_VDISABLE; - bt->c_cc[VWERASE] = _POSIX_VDISABLE; - bt->c_cc[VLNEXT] = _POSIX_VDISABLE; - bt->c_cc[VSTATUS] = _POSIX_VDISABLE; -} - -static void -btios2stios(bt, st) - struct termios *bt; - struct ibcs2_termios *st; -{ - register u_long l, r; - - l = bt->c_iflag; r = 0; - if (l & IGNBRK) r |= IBCS2_IGNBRK; - if (l & BRKINT) r |= IBCS2_BRKINT; - if (l & IGNPAR) r |= IBCS2_IGNPAR; - if (l & PARMRK) r |= IBCS2_PARMRK; - if (l & INPCK) r |= IBCS2_INPCK; - if (l & ISTRIP) r |= IBCS2_ISTRIP; - if (l & INLCR) r |= IBCS2_INLCR; - if (l & IGNCR) r |= IBCS2_IGNCR; - if (l & ICRNL) r |= IBCS2_ICRNL; - if (l & IXON) r |= IBCS2_IXON; - if (l & IXANY) r |= IBCS2_IXANY; - if (l & IXOFF) r |= IBCS2_IXOFF; - if (l & IMAXBEL) r |= IBCS2_IMAXBEL; - st->c_iflag = r; - - l = bt->c_oflag; r = 0; - if (l & OPOST) r |= IBCS2_OPOST; - if (l & ONLCR) r |= IBCS2_ONLCR; - if (l & OXTABS) r |= IBCS2_TAB3; - st->c_oflag = r; - - l = bt->c_cflag; r = 0; - switch (l & CSIZE) { - case CS5: r |= IBCS2_CS5; break; - case CS6: r |= IBCS2_CS6; break; - case CS7: r |= IBCS2_CS7; break; - case CS8: r |= IBCS2_CS8; break; - } - if (l & CSTOPB) r |= IBCS2_CSTOPB; - if (l & CREAD) r |= IBCS2_CREAD; - if (l & PARENB) r |= IBCS2_PARENB; - if (l & PARODD) r |= IBCS2_PARODD; - if (l & HUPCL) r |= IBCS2_HUPCL; - if (l & CLOCAL) r |= IBCS2_CLOCAL; - st->c_cflag = r; - - l = bt->c_lflag; r = 0; - if (l & ISIG) r |= IBCS2_ISIG; - if (l & ICANON) r |= IBCS2_ICANON; - if (l & ECHO) r |= IBCS2_ECHO; - if (l & ECHOE) r |= IBCS2_ECHOE; - if (l & ECHOK) r |= IBCS2_ECHOK; - if (l & ECHONL) r |= IBCS2_ECHONL; - if (l & NOFLSH) r |= IBCS2_NOFLSH; - if (l & TOSTOP) r |= IBCS2_TOSTOP; - st->c_lflag = r; - - l = ttspeedtab(bt->c_ospeed, sptab); - if (l >= 0) - st->c_cflag |= l; - - st->c_cc[IBCS2_VINTR] = - bt->c_cc[VINTR] != _POSIX_VDISABLE ? bt->c_cc[VINTR] : 0; - st->c_cc[IBCS2_VQUIT] = - bt->c_cc[VQUIT] != _POSIX_VDISABLE ? bt->c_cc[VQUIT] : 0; - st->c_cc[IBCS2_VERASE] = - bt->c_cc[VERASE] != _POSIX_VDISABLE ? bt->c_cc[VERASE] : 0; - st->c_cc[IBCS2_VKILL] = - bt->c_cc[VKILL] != _POSIX_VDISABLE ? bt->c_cc[VKILL] : 0; - st->c_cc[IBCS2_VEOF] = - bt->c_cc[VEOF] != _POSIX_VDISABLE ? bt->c_cc[VEOF] : 0; - st->c_cc[IBCS2_VEOL] = - bt->c_cc[VEOL] != _POSIX_VDISABLE ? bt->c_cc[VEOL] : 0; - st->c_cc[IBCS2_VEOL2] = - bt->c_cc[VEOL2] != _POSIX_VDISABLE ? bt->c_cc[VEOL2] : 0; - st->c_cc[IBCS2_VSWTCH] = - 0; - st->c_cc[IBCS2_VSUSP] = - bt->c_cc[VSUSP] != _POSIX_VDISABLE ? bt->c_cc[VSUSP] : 0; - st->c_cc[IBCS2_VSTART] = - bt->c_cc[VSTART] != _POSIX_VDISABLE ? bt->c_cc[VSTART] : 0; - st->c_cc[IBCS2_VSTOP] = - bt->c_cc[VSTOP] != _POSIX_VDISABLE ? bt->c_cc[VSTOP] : 0; - - st->c_line = 0; -} - -static void -stios2stio(ts, t) - struct ibcs2_termios *ts; - struct ibcs2_termio *t; -{ - t->c_iflag = ts->c_iflag; - t->c_oflag = ts->c_oflag; - t->c_cflag = ts->c_cflag; - t->c_lflag = ts->c_lflag; - t->c_line = ts->c_line; - bcopy(ts->c_cc, t->c_cc, IBCS2_NCC); -} - -static void -stio2stios(t, ts) - struct ibcs2_termio *t; - struct ibcs2_termios *ts; -{ - ts->c_iflag = t->c_iflag; - ts->c_oflag = t->c_oflag; - ts->c_cflag = t->c_cflag; - ts->c_lflag = t->c_lflag; - ts->c_line = t->c_line; - bcopy(t->c_cc, ts->c_cc, IBCS2_NCC); -} - -int -ibcs2_ioctl(p, uap, retval) - struct proc *p; - struct ibcs2_ioctl_args *uap; - int *retval; -{ - struct filedesc *fdp = p->p_fd; - struct file *fp; - int (*ctl)(); - int error; - - if (SCARG(uap, fd) < 0 || SCARG(uap, fd) >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) { - DPRINTF(("ibcs2_ioctl(%d): bad fd %d ", p->p_pid, - SCARG(uap, fd))); - return EBADF; - } - - if ((fp->f_flag & (FREAD|FWRITE)) == 0) { - DPRINTF(("ibcs2_ioctl(%d): bad fp flag ", p->p_pid)); - return EBADF; - } - - ctl = fp->f_ops->fo_ioctl; - - switch (SCARG(uap, cmd)) { - case IBCS2_TCGETA: - case IBCS2_XCGETA: - case IBCS2_OXCGETA: - { - struct termios bts; - struct ibcs2_termios sts; - struct ibcs2_termio st; - - if ((error = (*ctl)(fp, TIOCGETA, (caddr_t)&bts, p)) != 0) - return error; - - btios2stios (&bts, &sts); - if (SCARG(uap, cmd) == IBCS2_TCGETA) { - stios2stio (&sts, &st); - error = copyout((caddr_t)&st, SCARG(uap, data), - sizeof (st)); - if (error) - DPRINTF(("ibcs2_ioctl(%d): copyout failed ", - p->p_pid)); - return error; - } else - return copyout((caddr_t)&sts, SCARG(uap, data), - sizeof (sts)); - /*NOTREACHED*/ - } - - case IBCS2_TCSETA: - case IBCS2_TCSETAW: - case IBCS2_TCSETAF: - { - struct termios bts; - struct ibcs2_termios sts; - struct ibcs2_termio st; - - if ((error = copyin(SCARG(uap, data), (caddr_t)&st, - sizeof(st))) != 0) { - DPRINTF(("ibcs2_ioctl(%d): TCSET copyin failed ", - p->p_pid)); - return error; - } - - /* get full BSD termios so we don't lose information */ - if ((error = (*ctl)(fp, TIOCGETA, (caddr_t)&bts, p)) != 0) { - DPRINTF(("ibcs2_ioctl(%d): TCSET ctl failed fd %d ", - p->p_pid, SCARG(uap, fd))); - return error; - } - - /* - * convert to iBCS2 termios, copy in information from - * termio, and convert back, then set new values. - */ - btios2stios(&bts, &sts); - stio2stios(&st, &sts); - stios2btios(&sts, &bts); - - return (*ctl)(fp, SCARG(uap, cmd) - IBCS2_TCSETA + TIOCSETA, - (caddr_t)&bts, p); - } - - case IBCS2_XCSETA: - case IBCS2_XCSETAW: - case IBCS2_XCSETAF: - { - struct termios bts; - struct ibcs2_termios sts; - - if ((error = copyin(SCARG(uap, data), (caddr_t)&sts, - sizeof (sts))) != 0) { - return error; - } - stios2btios (&sts, &bts); - return (*ctl)(fp, SCARG(uap, cmd) - IBCS2_XCSETA + TIOCSETA, - (caddr_t)&bts, p); - } - - case IBCS2_OXCSETA: - case IBCS2_OXCSETAW: - case IBCS2_OXCSETAF: - { - struct termios bts; - struct ibcs2_termios sts; - - if ((error = copyin(SCARG(uap, data), (caddr_t)&sts, - sizeof (sts))) != 0) { - return error; - } - stios2btios (&sts, &bts); - return (*ctl)(fp, SCARG(uap, cmd) - IBCS2_OXCSETA + TIOCSETA, - (caddr_t)&bts, p); - } - - case IBCS2_TCSBRK: - DPRINTF(("ibcs2_ioctl(%d): TCSBRK ", p->p_pid)); - return ENOSYS; - - case IBCS2_TCXONC: - DPRINTF(("ibcs2_ioctl(%d): TCXONC ", p->p_pid)); - return ENOSYS; - - case IBCS2_TCFLSH: - DPRINTF(("ibcs2_ioctl(%d): TCFLSH ", p->p_pid)); - return ENOSYS; - - case IBCS2_TIOCGWINSZ: - SCARG(uap, cmd) = TIOCGWINSZ; - return ioctl(p, uap, retval); - - case IBCS2_TIOCSWINSZ: - SCARG(uap, cmd) = TIOCSWINSZ; - return ioctl(p, uap, retval); - - case IBCS2_TIOCGPGRP: - return copyout((caddr_t)&p->p_pgrp->pg_id, SCARG(uap, data), - sizeof(p->p_pgrp->pg_id)); - - case IBCS2_TIOCSPGRP: /* XXX - is uap->data a pointer to pgid? */ - { - struct setpgid_args sa; - - SCARG(&sa, pid) = 0; - SCARG(&sa, pgid) = (int)SCARG(uap, data); - if (error = setpgid(p, &sa, retval)) - return error; - return 0; - } - - case IBCS2_TCGETSC: /* SCO console - get scancode flags */ - return ENOSYS; - - case IBCS2_TCSETSC: /* SCO console - set scancode flags */ - return ENOSYS; - - case IBCS2_SIOCSOCKSYS: - return ibcs2_socksys(p, uap, retval); - - case IBCS2_I_NREAD: /* STREAMS */ - SCARG(uap, cmd) = FIONREAD; - return ioctl(p, uap, retval); - - default: - DPRINTF(("ibcs2_ioctl(%d): unknown cmd 0x%lx ", - p->p_pid, SCARG(uap, cmd))); - return ENOSYS; - } - return ENOSYS; -} - diff --git a/sys/i386/ibcs2/ibcs2_ipc.c b/sys/i386/ibcs2/ibcs2_ipc.c deleted file mode 100644 index 6dc171417d8f..000000000000 --- a/sys/i386/ibcs2/ibcs2_ipc.c +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Copyright (c) 1995 Scott Bartram - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/namei.h> -#include <sys/proc.h> -#include <sys/file.h> -#include <sys/stat.h> -#include <sys/filedesc.h> -#include <sys/ioctl.h> -#include <sys/ipc.h> -#include <sys/kernel.h> -#include <sys/malloc.h> -#include <sys/mbuf.h> -#include <sys/mman.h> -#include <sys/mount.h> -#include <sys/reboot.h> -#include <sys/resource.h> -#include <sys/resourcevar.h> -#include <sys/signal.h> -#include <sys/signalvar.h> -#include <sys/socket.h> -#include <sys/time.h> -#include <sys/times.h> -#include <sys/vnode.h> -#include <sys/uio.h> -#include <sys/wait.h> -#include <sys/utsname.h> -#include <sys/unistd.h> -#include <sys/msg.h> -#include <sys/sem.h> -#include <sys/shm.h> -#include <sys/syscallargs.h> - -#include <vm/vm.h> - -#include <compat/ibcs2/ibcs2_types.h> -#include <compat/ibcs2/ibcs2_signal.h> -#include <compat/ibcs2/ibcs2_syscallargs.h> -#include <compat/ibcs2/ibcs2_util.h> - -#define IBCS2_IPC_RMID 0 -#define IBCS2_IPC_SET 1 -#define IBCS2_IPC_STAT 2 - -/* - * iBCS2 msgsys call - */ - -struct ibcs2_msqid_ds { - struct ipc_perm msg_perm; - struct msg *msg_first; - struct msg *msg_last; - u_short msg_cbytes; - u_short msg_qnum; - u_short msg_qbytes; - u_short msg_lspid; - u_short msg_lrpid; - ibcs2_time_t msg_stime; - ibcs2_time_t msg_rtime; - ibcs2_time_t msg_ctime; -}; - -static void -cvt_msqid2imsqid(bp, ibp) -struct msqid_ds *bp; -struct ibcs2_msqid_ds *ibp; -{ - ibp->msg_perm = bp->msg_perm; - ibp->msg_first = bp->msg_first; - ibp->msg_last = bp->msg_last; - ibp->msg_cbytes = (u_short)bp->msg_cbytes; - ibp->msg_qnum = (u_short)bp->msg_qnum; - ibp->msg_qbytes = (u_short)bp->msg_qbytes; - ibp->msg_lspid = (u_short)bp->msg_lspid; - ibp->msg_lrpid = (u_short)bp->msg_lrpid; - ibp->msg_stime = bp->msg_stime; - ibp->msg_rtime = bp->msg_rtime; - ibp->msg_ctime = bp->msg_ctime; - return; -} - -static void -cvt_imsqid2msqid(ibp, bp) -struct ibcs2_msqid_ds *ibp; -struct msqid_ds *bp; -{ - bp->msg_perm = ibp->msg_perm; - bp->msg_first = ibp->msg_first; - bp->msg_last = ibp->msg_last; - bp->msg_cbytes = ibp->msg_cbytes; - bp->msg_qnum = ibp->msg_qnum; - bp->msg_qbytes = ibp->msg_qbytes; - bp->msg_lspid = ibp->msg_lspid; - bp->msg_lrpid = ibp->msg_lrpid; - bp->msg_stime = ibp->msg_stime; - bp->msg_rtime = ibp->msg_rtime; - bp->msg_ctime = ibp->msg_ctime; - return; -} - -int -ibcs2_msgsys(p, uap, retval) - struct proc *p; - struct ibcs2_msgsys_args *uap; - int *retval; -{ - switch (SCARG(uap, which)) { - case 0: /* msgget */ - SCARG(uap, which) = 1; - return compat_10_msgsys(p, uap, retval); - case 1: { /* msgctl */ - int error; - struct compat_10_msgsys_args margs; - caddr_t sg = stackgap_init(); - - SCARG(&margs, which) = 0; - SCARG(&margs, a2) = SCARG(uap, a2); - SCARG(&margs, a4) = - (int)stackgap_alloc(&sg, sizeof(struct msqid_ds)); - SCARG(&margs, a3) = SCARG(uap, a3); - switch (SCARG(&margs, a3)) { - case IBCS2_IPC_STAT: - error = compat_10_msgsys(p, &margs, retval); - if (!error) - cvt_msqid2imsqid(SCARG(&margs, a4), - (struct ibcs2_msqid_ds *)SCARG(uap, a4)); - return error; - case IBCS2_IPC_SET: - cvt_imsqid2msqid((struct ibcs2_msqid_ds *)SCARG(uap, - a4), - SCARG(&margs, a4)); - return compat_10_msgsys(p, &margs, retval); - case IBCS2_IPC_RMID: - return compat_10_msgsys(p, &margs, retval); - } - return EINVAL; - } - case 2: /* msgrcv */ - SCARG(uap, which) = 3; - return compat_10_msgsys(p, uap, retval); - case 3: /* msgsnd */ - SCARG(uap, which) = 2; - return compat_10_msgsys(p, uap, retval); - default: - return EINVAL; - } -} - - -/* - * iBCS2 semsys call - */ - -struct ibcs2_semid_ds { - struct ipc_perm sem_perm; - struct ibcs2_sem *sem_base; - u_short sem_nsems; - int pad1; - ibcs2_time_t sem_otime; - ibcs2_time_t sem_ctime; -}; - -struct ibcs2_sem { - u_short semval; - ibcs2_pid_t sempid; - u_short semncnt; - u_short semzcnt; -}; - -static void -cvt_sem2isem(bp, ibp) -struct sem *bp; -struct ibcs2_sem *ibp; -{ - ibp->semval = bp->semval; - ibp->sempid = bp->sempid; - ibp->semncnt = bp->semncnt; - ibp->semzcnt = bp->semzcnt; - return; -} - -static void -cvt_isem2sem(ibp, bp) -struct ibcs2_sem *ibp; -struct sem *bp; -{ - bp->semval = ibp->semval; - bp->sempid = ibp->sempid; - bp->semncnt = ibp->semncnt; - bp->semzcnt = ibp->semzcnt; - return; -} - -static void -cvt_semid2isemid(bp, ibp) -struct semid_ds *bp; -struct ibcs2_semid_ds *ibp; -{ - ibp->sem_perm = bp->sem_perm; - ibp->sem_base = (struct ibcs2_sem *)bp->sem_base; - ibp->sem_nsems = bp->sem_nsems; - ibp->sem_otime = bp->sem_otime; - ibp->sem_ctime = bp->sem_ctime; - return; -} - -static void -cvt_isemid2semid(ibp, bp) -struct ibcs2_semid_ds *ibp; -struct semid_ds *bp; -{ - bp->sem_perm = ibp->sem_perm; - bp->sem_base = (struct sem *)ibp->sem_base; - bp->sem_nsems = ibp->sem_nsems; - bp->sem_otime = ibp->sem_otime; - bp->sem_ctime = ibp->sem_ctime; - return; -} - -int -ibcs2_semsys(p, uap, retval) - struct proc *p; - struct ibcs2_semsys_args *uap; - int *retval; -{ - int error; - - switch (SCARG(uap, which)) { - case 0: /* semctl */ - switch(SCARG(uap, a4)) { - case IBCS2_IPC_STAT: - { - struct ibcs2_semid_ds *isp; - struct semid_ds *sp; - caddr_t sg = stackgap_init(); - - isp = (struct ibcs2_semid_ds *)SCARG(uap, a5); - sp = stackgap_alloc(&sg, sizeof(struct semid_ds)); - SCARG(uap, a5) = (int)sp; - error = compat_10_semsys(p, uap, retval); - if (!error) { - SCARG(uap, a5) = (int)isp; - isp = stackgap_alloc(&sg, sizeof(*isp)); - cvt_semid2isemid(sp, isp); - error = copyout((caddr_t)isp, - (caddr_t)SCARG(uap, a5), - sizeof(*isp)); - } - return error; - } - case IBCS2_IPC_SET: - { - struct ibcs2_semid_ds *isp; - struct semid_ds *sp; - caddr_t sg = stackgap_init(); - - isp = stackgap_alloc(&sg, sizeof(*isp)); - sp = stackgap_alloc(&sg, sizeof(*sp)); - error = copyin((caddr_t)SCARG(uap, a5), (caddr_t)isp, - sizeof(*isp)); - if (error) - return error; - cvt_isemid2semid(isp, sp); - SCARG(uap, a5) = (int)sp; - return compat_10_semsys(p, uap, retval); - } - } - return compat_10_semsys(p, uap, retval); - - case 1: /* semget */ - return compat_10_semsys(p, uap, retval); - - case 2: /* semop */ - return compat_10_semsys(p, uap, retval); - } - return EINVAL; -} - - -/* - * iBCS2 shmsys call - */ - -struct ibcs2_shmid_ds { - struct ipc_perm shm_perm; - int shm_segsz; - int pad1; - char pad2[4]; - u_short shm_lpid; - u_short shm_cpid; - u_short shm_nattch; - u_short shm_cnattch; - ibcs2_time_t shm_atime; - ibcs2_time_t shm_dtime; - ibcs2_time_t shm_ctime; -}; - -static void -cvt_shmid2ishmid(bp, ibp) -struct shmid_ds *bp; -struct ibcs2_shmid_ds *ibp; -{ - ibp->shm_perm = bp->shm_perm; - ibp->shm_segsz = bp->shm_segsz; - ibp->shm_lpid = bp->shm_lpid; - ibp->shm_cpid = bp->shm_cpid; - ibp->shm_nattch = bp->shm_nattch; - ibp->shm_cnattch = 0; /* ignored anyway */ - ibp->shm_atime = bp->shm_atime; - ibp->shm_dtime = bp->shm_dtime; - ibp->shm_ctime = bp->shm_ctime; - return; -} - -static void -cvt_ishmid2shmid(ibp, bp) -struct ibcs2_shmid_ds *ibp; -struct shmid_ds *bp; -{ - bp->shm_perm = ibp->shm_perm; - bp->shm_segsz = ibp->shm_segsz; - bp->shm_lpid = ibp->shm_lpid; - bp->shm_cpid = ibp->shm_cpid; - bp->shm_nattch = ibp->shm_nattch; - bp->shm_atime = ibp->shm_atime; - bp->shm_dtime = ibp->shm_dtime; - bp->shm_ctime = ibp->shm_ctime; - bp->shm_internal = (void *)0; /* ignored anyway */ - return; -} - -int -ibcs2_shmsys(p, uap, retval) - struct proc *p; - struct ibcs2_shmsys_args *uap; - int *retval; -{ - int error; - - switch (SCARG(uap, which)) { - case 0: /* shmat */ - return compat_10_shmsys(p, uap, retval); - - case 1: /* shmctl */ - switch(SCARG(uap, a3)) { - case IBCS2_IPC_STAT: - { - struct ibcs2_shmid_ds *isp; - struct shmid_ds *sp; - caddr_t sg = stackgap_init(); - - isp = (struct ibcs2_shmid_ds *)SCARG(uap, a4); - sp = stackgap_alloc(&sg, sizeof(*sp)); - SCARG(uap, a4) = (int)sp; - error = compat_10_shmsys(p, uap, retval); - if (!error) { - SCARG(uap, a4) = (int)isp; - isp = stackgap_alloc(&sg, sizeof(*isp)); - cvt_shmid2ishmid(sp, isp); - error = copyout((caddr_t)isp, - (caddr_t)SCARG(uap, a4), - sizeof(*isp)); - } - return error; - } - case IBCS2_IPC_SET: - { - struct ibcs2_shmid_ds *isp; - struct shmid_ds *sp; - caddr_t sg = stackgap_init(); - - isp = stackgap_alloc(&sg, sizeof(*isp)); - sp = stackgap_alloc(&sg, sizeof(*sp)); - error = copyin((caddr_t)SCARG(uap, a4), (caddr_t)isp, - sizeof(*isp)); - if (error) - return error; - cvt_ishmid2shmid(isp, sp); - SCARG(uap, a4) = (int)sp; - return compat_10_shmsys(p, uap, retval); - } - } - return compat_10_shmsys(p, uap, retval); - - case 2: /* shmdt */ - return compat_10_shmsys(p, uap, retval); - - case 3: /* shmget */ - return compat_10_shmsys(p, uap, retval); - } - return EINVAL; -} diff --git a/sys/i386/ibcs2/ibcs2_misc.c b/sys/i386/ibcs2/ibcs2_misc.c deleted file mode 100644 index cc1da262bbc0..000000000000 --- a/sys/i386/ibcs2/ibcs2_misc.c +++ /dev/null @@ -1,1200 +0,0 @@ -/* $NetBSD: ibcs2_misc.c,v 1.6 1995/05/01 19:33:17 mycroft Exp $ */ - -/* - * Copyright (c) 1994, 1995 Scott Bartram - * 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. - * - * 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, Lawrence Berkeley Laboratory. - * - * 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. - * - * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp - * - * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93 - */ - -/* - * IBCS2 compatibility module. - * - * IBCS2 system calls that are implemented differently in BSD are - * handled here. - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/namei.h> -#include <sys/proc.h> -#include <sys/file.h> -#include <sys/filedesc.h> -#include <sys/ioctl.h> -#include <sys/kernel.h> -#include <sys/malloc.h> -#include <sys/mbuf.h> -#include <sys/mman.h> -#include <sys/mount.h> -#include <sys/reboot.h> -#include <sys/resource.h> -#include <sys/resourcevar.h> -#include <sys/socket.h> -#include <sys/stat.h> -#include <sys/time.h> -#include <sys/times.h> -#include <sys/vnode.h> -#include <sys/uio.h> -#include <sys/wait.h> -#include <sys/utsname.h> -#include <sys/unistd.h> - -#include <ufs/ufs/dir.h> - -#include <netinet/in.h> -#include <sys/syscallargs.h> - -#include <miscfs/specfs/specdev.h> - -#include <vm/vm.h> -#include <sys/sysctl.h> /* must be included after vm.h */ - -#include <i386/include/reg.h> - -#include <compat/ibcs2/ibcs2_types.h> -#include <compat/ibcs2/ibcs2_dirent.h> -#include <compat/ibcs2/ibcs2_fcntl.h> -#include <compat/ibcs2/ibcs2_time.h> -#include <compat/ibcs2/ibcs2_signal.h> -#include <compat/ibcs2/ibcs2_timeb.h> -#include <compat/ibcs2/ibcs2_unistd.h> -#include <compat/ibcs2/ibcs2_utsname.h> -#include <compat/ibcs2/ibcs2_util.h> -#include <compat/ibcs2/ibcs2_utime.h> -#include <compat/ibcs2/ibcs2_syscallargs.h> - - -int -ibcs2_ulimit(p, uap, retval) - struct proc *p; - struct ibcs2_ulimit_args *uap; - int *retval; -{ - int error; - struct rlimit rl; - struct setrlimit_args { - int resource; - struct rlimit *rlp; - } sra; -#define IBCS2_GETFSIZE 1 -#define IBCS2_SETFSIZE 2 -#define IBCS2_GETPSIZE 3 -#define IBCS2_GETDTABLESIZE 4 - - switch (SCARG(uap, cmd)) { - case IBCS2_GETFSIZE: - *retval = p->p_rlimit[RLIMIT_FSIZE].rlim_cur; - return 0; - case IBCS2_SETFSIZE: /* XXX - fix this */ -#ifdef notyet - rl.rlim_cur = SCARG(uap, newlimit); - sra.resource = RLIMIT_FSIZE; - sra.rlp = &rl; - error = setrlimit(p, &sra, retval); - if (!error) - *retval = p->p_rlimit[RLIMIT_FSIZE].rlim_cur; - else - DPRINTF(("failed ")); - return error; -#else - *retval = SCARG(uap, newlimit); - return 0; -#endif - case IBCS2_GETPSIZE: - *retval = p->p_rlimit[RLIMIT_RSS].rlim_cur; /* XXX */ - return 0; - case IBCS2_GETDTABLESIZE: - uap->cmd = IBCS2_SC_OPEN_MAX; - return ibcs2_sysconf(p, uap, retval); - default: - return ENOSYS; - } -} - -int -ibcs2_waitsys(p, uap, retval) - struct proc *p; - struct ibcs2_waitsys_args *uap; - int *retval; -{ - int error, status; - struct wait4_args w4; -#define WAITPID_EFLAGS 0x8c4 /* OF, SF, ZF, PF */ - - SCARG(&w4, rusage) = NULL; - if ((p->p_md.md_regs->tf_eflags & WAITPID_EFLAGS) == WAITPID_EFLAGS) { - /* waitpid */ - SCARG(&w4, pid) = SCARG(uap, a1); - SCARG(&w4, status) = (int *)SCARG(uap, a2); - SCARG(&w4, options) = SCARG(uap, a3); - } else { - /* wait */ - SCARG(&w4, pid) = WAIT_ANY; - SCARG(&w4, status) = (int *)SCARG(uap, a1); - SCARG(&w4, options) = 0; - } - if ((error = wait4(p, &w4, retval)) != 0) - return error; - if (SCARG(&w4, status)) /* this is real iBCS brain-damage */ - return copyin((caddr_t)SCARG(&w4, status), (caddr_t)&retval[1], - sizeof(SCARG(&w4, status))); - return 0; -} - -int -ibcs2_execv(p, uap, retval) - struct proc *p; - struct ibcs2_execv_args *uap; - int *retval; -{ - struct execve_args ea; - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - SCARG(&ea, path) = SCARG(uap, path); - SCARG(&ea, argp) = SCARG(uap, argp); - SCARG(&ea, envp) = NULL; - return execve(p, &ea, retval); -} - -int -ibcs2_execve(p, uap, retval) - struct proc *p; - struct execve_args *uap; - int *retval; -{ - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - return execve(p, uap, retval); -} - -int -ibcs2_umount(p, uap, retval) - struct proc *p; - struct ibcs2_umount_args *uap; - int *retval; -{ - struct unmount_args um; - - SCARG(&um, path) = SCARG(uap, name); - SCARG(&um, flags) = 0; - return unmount(p, &um, retval); -} - -int -ibcs2_mount(p, uap, retval) - struct proc *p; - struct ibcs2_mount_args *uap; - int *retval; -{ -#ifdef notyet - int oflags = SCARG(uap, flags), nflags, error; - char fsname[MFSNAMELEN]; - - if (oflags & (IBCS2_MS_NOSUB | IBCS2_MS_SYS5)) - return (EINVAL); - if ((oflags & IBCS2_MS_NEWTYPE) == 0) - return (EINVAL); - nflags = 0; - if (oflags & IBCS2_MS_RDONLY) - nflags |= MNT_RDONLY; - if (oflags & IBCS2_MS_NOSUID) - nflags |= MNT_NOSUID; - if (oflags & IBCS2_MS_REMOUNT) - nflags |= MNT_UPDATE; - SCARG(uap, flags) = nflags; - - if (error = copyinstr((caddr_t)SCARG(uap, type), fsname, sizeof fsname, - (u_int *)0)) - return (error); - - if (strcmp(fsname, "4.2") == 0) { - SCARG(uap, type) = (caddr_t)STACK_ALLOC(); - if (error = copyout("ufs", SCARG(uap, type), sizeof("ufs"))) - return (error); - } else if (strcmp(fsname, "nfs") == 0) { - struct ibcs2_nfs_args sna; - struct sockaddr_in sain; - struct nfs_args na; - struct sockaddr sa; - - if (error = copyin(SCARG(uap, data), &sna, sizeof sna)) - return (error); - if (error = copyin(sna.addr, &sain, sizeof sain)) - return (error); - bcopy(&sain, &sa, sizeof sa); - sa.sa_len = sizeof(sain); - SCARG(uap, data) = (caddr_t)STACK_ALLOC(); - na.addr = (struct sockaddr *)((int)SCARG(uap, data) + sizeof na); - na.sotype = SOCK_DGRAM; - na.proto = IPPROTO_UDP; - na.fh = (nfsv2fh_t *)sna.fh; - na.flags = sna.flags; - na.wsize = sna.wsize; - na.rsize = sna.rsize; - na.timeo = sna.timeo; - na.retrans = sna.retrans; - na.hostname = sna.hostname; - - if (error = copyout(&sa, na.addr, sizeof sa)) - return (error); - if (error = copyout(&na, SCARG(uap, data), sizeof na)) - return (error); - } - return (mount(p, uap, retval)); -#else - return EINVAL; -#endif -} - -/* - * Read iBCS2-style directory entries. We suck them into kernel space so - * that they can be massaged before being copied out to user code. Like - * SunOS, we squish out `empty' entries. - * - * This is quite ugly, but what do you expect from compatibility code? - */ - -int -ibcs2_getdents(p, uap, retval) - struct proc *p; - register struct ibcs2_getdents_args *uap; - int *retval; -{ - register struct vnode *vp; - register caddr_t inp, buf; /* BSD-format */ - register int len, reclen; /* BSD-format */ - register caddr_t outp; /* iBCS2-format */ - register int resid; /* iBCS2-format */ - struct file *fp; - struct uio auio; - struct iovec aiov; - struct ibcs2_dirent idb; - off_t off; /* true file offset */ - int buflen, error, eofflag; -#define BSD_DIRENT(cp) ((struct direct *)(cp)) -#define IBCS2_RECLEN(reclen) (reclen + sizeof(u_short)) - - if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) - return (error); - if ((fp->f_flag & FREAD) == 0) - return (EBADF); - vp = (struct vnode *)fp->f_data; - if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */ - return (EINVAL); - buflen = min(MAXBSIZE, SCARG(uap, nbytes)); - buf = malloc(buflen, M_TEMP, M_WAITOK); - VOP_LOCK(vp); - off = fp->f_offset; -again: - aiov.iov_base = buf; - aiov.iov_len = buflen; - auio.uio_iov = &aiov; - auio.uio_iovcnt = 1; - auio.uio_rw = UIO_READ; - auio.uio_segflg = UIO_SYSSPACE; - auio.uio_procp = p; - auio.uio_resid = buflen; - auio.uio_offset = off; - /* - * First we read into the malloc'ed buffer, then - * we massage it into user space, one record at a time. - */ - if (error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, (u_long *)0, - 0)) - goto out; - inp = buf; - outp = SCARG(uap, buf); - resid = SCARG(uap, nbytes); - if ((len = buflen - auio.uio_resid) == 0) - goto eof; - for (; len > 0; len -= reclen) { - reclen = BSD_DIRENT(inp)->d_reclen; - if (reclen & 3) - panic("ibcs2_getdents"); - off += reclen; /* each entry points to next */ - if (BSD_DIRENT(inp)->d_ino == 0) { - inp += reclen; /* it is a hole; squish it out */ - continue; - } - if (reclen > len || resid < IBCS2_RECLEN(reclen)) { - /* entry too big for buffer, so just stop */ - outp++; - break; - } - /* - * Massage in place to make a iBCS2-shaped dirent (otherwise - * we have to worry about touching user memory outside of - * the copyout() call). - */ - idb.d_ino = (ibcs2_ino_t)BSD_DIRENT(inp)->d_ino; - idb.d_off = (ibcs2_off_t)off; - idb.d_reclen = (u_short)IBCS2_RECLEN(reclen); - if ((error = copyout((caddr_t)&idb, outp, 10)) != 0 || - (error = copyout(BSD_DIRENT(inp)->d_name, outp + 10, - BSD_DIRENT(inp)->d_namlen + 1)) != 0) - goto out; - /* advance past this real entry */ - inp += reclen; - /* advance output past iBCS2-shaped entry */ - outp += IBCS2_RECLEN(reclen); - resid -= IBCS2_RECLEN(reclen); - } - /* if we squished out the whole block, try again */ - if (outp == SCARG(uap, buf)) - goto again; - fp->f_offset = off; /* update the vnode offset */ -eof: - *retval = SCARG(uap, nbytes) - resid; -out: - VOP_UNLOCK(vp); - free(buf, M_TEMP); - return (error); -} - -int -ibcs2_read(p, uap, retval) - struct proc *p; - struct ibcs2_read_args *uap; - int *retval; -{ - register struct vnode *vp; - register caddr_t inp, buf; /* BSD-format */ - register int len, reclen; /* BSD-format */ - register caddr_t outp; /* iBCS2-format */ - register int resid; /* iBCS2-format */ - struct file *fp; - struct uio auio; - struct iovec aiov; - struct ibcs2_direct { - ibcs2_ino_t ino; - char name[14]; - } idb; - off_t off; /* true file offset */ - int buflen, error, eofflag, size; - - if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) { - if (error == EINVAL) - return read(p, uap, retval); - else - return error; - } - if ((fp->f_flag & FREAD) == 0) - return (EBADF); - vp = (struct vnode *)fp->f_data; - if (vp->v_type != VDIR) - return read(p, uap, retval); - DPRINTF(("ibcs2_read: read directory\n")); - buflen = max(MAXBSIZE, SCARG(uap, nbytes)); - buf = malloc(buflen, M_TEMP, M_WAITOK); - VOP_LOCK(vp); - off = fp->f_offset; -again: - aiov.iov_base = buf; - aiov.iov_len = buflen; - auio.uio_iov = &aiov; - auio.uio_iovcnt = 1; - auio.uio_rw = UIO_READ; - auio.uio_segflg = UIO_SYSSPACE; - auio.uio_procp = p; - auio.uio_resid = buflen; - auio.uio_offset = off & ~(DIRBLKSIZ - 1); - /* - * First we read into the malloc'ed buffer, then - * we massage it into user space, one record at a time. - */ - if (error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, - (u_long *)0, 0)) { - DPRINTF(("VOP_READDIR failed: %d\n", error)); - goto out; - } - inp = buf + (off & (DIRBLKSIZ - 1)); - buflen -= off & (DIRBLKSIZ - 1); - outp = SCARG(uap, buf); - resid = SCARG(uap, nbytes); - if ((len = buflen - auio.uio_resid) == 0) - goto eof; - for (; len > 0 && resid > 0; len -= reclen) { - reclen = BSD_DIRENT(inp)->d_reclen; - if (reclen & 3) - panic("ibcs2_read"); - if (BSD_DIRENT(inp)->d_ino == 0) { - inp += reclen; /* it is a hole; squish it out */ - off += reclen; - continue; - } - if (reclen > len || resid < sizeof(struct ibcs2_direct)) { - /* entry too big for buffer, so just stop */ - outp++; - break; - } - /* - * Massage in place to make a iBCS2-shaped dirent (otherwise - * we have to worry about touching user memory outside of - * the copyout() call). - * - * TODO: if length(filename) > 14, then break filename into - * multiple entries and set inode = 0xffff except last - */ - idb.ino = (BSD_DIRENT(inp)->d_ino > 0xfffe) ? 0xfffe : - BSD_DIRENT(inp)->d_ino; - (void)copystr(BSD_DIRENT(inp)->d_name, idb.name, 14, &size); - bzero(idb.name + size, 14 - size); - if (error = copyout(&idb, outp, sizeof(struct ibcs2_direct))) - goto out; - /* advance past this real entry */ - off += reclen; - inp += reclen; - /* advance output past iBCS2-shaped entry */ - outp += sizeof(struct ibcs2_direct); - resid -= sizeof(struct ibcs2_direct); - } - /* if we squished out the whole block, try again */ - if (outp == SCARG(uap, buf)) - goto again; - fp->f_offset = off; /* update the vnode offset */ -eof: - *retval = SCARG(uap, nbytes) - resid; -out: - VOP_UNLOCK(vp); - free(buf, M_TEMP); - return (error); -} - -int -ibcs2_mknod(p, uap, retval) - struct proc *p; - struct ibcs2_mknod_args *uap; - int *retval; -{ - caddr_t sg = stackgap_init(); - - CHECKALTCREAT(p, &sg, SCARG(uap, path)); - if (S_ISFIFO(SCARG(uap, mode))) { - struct mkfifo_args ap; - SCARG(&ap, path) = SCARG(uap, path); - SCARG(&ap, mode) = SCARG(uap, mode); - return mkfifo(p, uap, retval); - } else { - struct mknod_args ap; - SCARG(&ap, path) = SCARG(uap, path); - SCARG(&ap, mode) = SCARG(uap, mode); - SCARG(&ap, dev) = SCARG(uap, dev); - return mknod(p, &ap, retval); - } -} - -int -ibcs2_getgroups(p, uap, retval) - struct proc *p; - struct ibcs2_getgroups_args *uap; - int *retval; -{ - int error, i; - ibcs2_gid_t igid, *iset; - struct getgroups_args sa; - gid_t *gp; - caddr_t sg = stackgap_init(); - - SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize); - if (SCARG(uap, gidsetsize)) { - SCARG(&sa, gidset) = stackgap_alloc(&sg, NGROUPS_MAX * - sizeof(gid_t *)); - iset = stackgap_alloc(&sg, SCARG(uap, gidsetsize) * - sizeof(ibcs2_gid_t)); - } - if (error = getgroups(p, &sa, retval)) - return error; - for (i = 0, gp = SCARG(&sa, gidset); i < retval[0]; i++) - iset[i] = (ibcs2_gid_t)*gp++; - if (retval[0] && (error = copyout((caddr_t)iset, - (caddr_t)SCARG(uap, gidset), - sizeof(ibcs2_gid_t) * retval[0]))) - return error; - return 0; -} - -int -ibcs2_setgroups(p, uap, retval) - struct proc *p; - struct ibcs2_setgroups_args *uap; - int *retval; -{ - int error, i; - ibcs2_gid_t igid, *iset; - struct setgroups_args sa; - gid_t *gp; - caddr_t sg = stackgap_init(); - - SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize); - SCARG(&sa, gidset) = stackgap_alloc(&sg, SCARG(&sa, gidsetsize) * - sizeof(gid_t *)); - iset = stackgap_alloc(&sg, SCARG(&sa, gidsetsize) * - sizeof(ibcs2_gid_t *)); - if (SCARG(&sa, gidsetsize)) { - if (error = copyin((caddr_t)SCARG(uap, gidset), (caddr_t)iset, - sizeof(ibcs2_gid_t *) * - SCARG(uap, gidsetsize))) - return error; - } - for (i = 0, gp = SCARG(&sa, gidset); i < SCARG(&sa, gidsetsize); i++) - *gp++ = (gid_t)iset[i]; - return setgroups(p, &sa, retval); -} - -int -ibcs2_setuid(p, uap, retval) - struct proc *p; - struct ibcs2_setuid_args *uap; - int *retval; -{ - struct setuid_args sa; - - SCARG(&sa, uid) = (uid_t)SCARG(uap, uid); - return setuid(p, &sa, retval); -} - -int -ibcs2_setgid(p, uap, retval) - struct proc *p; - struct ibcs2_setgid_args *uap; - int *retval; -{ - struct setgid_args sa; - - SCARG(&sa, gid) = (gid_t)SCARG(uap, gid); - return setgid(p, &sa, retval); -} - -int -xenix_ftime(p, uap, retval) - struct proc *p; - struct xenix_ftime_args *uap; - int *retval; -{ - struct timeval tv; - extern struct timezone tz; - struct xenix_timeb itb; - - microtime(&tv); - itb.time = tv.tv_sec; - itb.millitm = (tv.tv_usec / 1000); - itb.timezone = tz.tz_minuteswest; - itb.dstflag = tz.tz_dsttime; - return copyout((caddr_t)&itb, (caddr_t)SCARG(uap, tp), xenix_timeb_len); -} - -int -ibcs2_time(p, uap, retval) - struct proc *p; - struct ibcs2_time_args *uap; - int *retval; -{ - struct timeval tv; - - microtime(&tv); - *retval = tv.tv_sec; - if (SCARG(uap, tp)) - return copyout((caddr_t)&tv.tv_sec, (caddr_t)SCARG(uap, tp), - sizeof(ibcs2_time_t)); - else - return 0; -} - -int -ibcs2_pathconf(p, uap, retval) - struct proc *p; - struct ibcs2_pathconf_args *uap; - int *retval; -{ - SCARG(uap, name)++; /* iBCS2 _PC_* defines are offset by one */ - return pathconf(p, uap, retval); -} - -int -ibcs2_fpathconf(p, uap, retval) - struct proc *p; - struct ibcs2_fpathconf_args *uap; - int *retval; -{ - SCARG(uap, name)++; /* iBCS2 _PC_* defines are offset by one */ - return fpathconf(p, uap, retval); -} - -int -ibcs2_sysconf(p, uap, retval) - struct proc *p; - struct ibcs2_sysconf_args *uap; - int *retval; -{ - int mib[2], value, len, error; - struct __sysctl_args sa; - struct getrlimit_args ga; - - switch(SCARG(uap, name)) { - case IBCS2_SC_ARG_MAX: - mib[1] = KERN_ARGMAX; - break; - - case IBCS2_SC_CHILD_MAX: - { - caddr_t sg = stackgap_init(); - - SCARG(&ga, which) = RLIMIT_NPROC; - SCARG(&ga, rlp) = stackgap_alloc(&sg, sizeof(struct rlimit *)); - if (error = getrlimit(p, &ga, retval)) - return error; - *retval = SCARG(&ga, rlp)->rlim_cur; - return 0; - } - - case IBCS2_SC_CLK_TCK: - *retval = hz; - return 0; - - case IBCS2_SC_NGROUPS_MAX: - mib[1] = KERN_NGROUPS; - break; - - case IBCS2_SC_OPEN_MAX: - { - caddr_t sg = stackgap_init(); - - SCARG(&ga, which) = RLIMIT_NOFILE; - SCARG(&ga, rlp) = stackgap_alloc(&sg, sizeof(struct rlimit *)); - if (error = getrlimit(p, &ga, retval)) - return error; - *retval = SCARG(&ga, rlp)->rlim_cur; - return 0; - } - - case IBCS2_SC_JOB_CONTROL: - mib[1] = KERN_JOB_CONTROL; - break; - - case IBCS2_SC_SAVED_IDS: - mib[1] = KERN_SAVED_IDS; - break; - - case IBCS2_SC_VERSION: - mib[1] = KERN_POSIX1; - break; - - case IBCS2_SC_PASS_MAX: - *retval = 128; /* XXX - should we create PASS_MAX ? */ - return 0; - - case IBCS2_SC_XOPEN_VERSION: - *retval = 2; /* XXX: What should that be? */ - return 0; - - default: - return EINVAL; - } - - mib[0] = CTL_KERN; - len = sizeof(value); - SCARG(&sa, name) = mib; - SCARG(&sa, namelen) = 2; - SCARG(&sa, old) = &value; - SCARG(&sa, oldlenp) = &len; - SCARG(&sa, new) = NULL; - SCARG(&sa, newlen) = 0; - if (error = __sysctl(p, &sa, retval)) - return error; - *retval = value; - return 0; -} - -int -ibcs2_alarm(p, uap, retval) - struct proc *p; - struct ibcs2_alarm_args *uap; - int *retval; -{ - int error; - struct itimerval *itp, *oitp; - struct setitimer_args sa; - caddr_t sg = stackgap_init(); - - itp = stackgap_alloc(&sg, sizeof(*itp)); - oitp = stackgap_alloc(&sg, sizeof(*oitp)); - timerclear(&itp->it_interval); - itp->it_value.tv_sec = SCARG(uap, sec); - itp->it_value.tv_usec = 0; - - SCARG(&sa, which) = ITIMER_REAL; - SCARG(&sa, itv) = itp; - SCARG(&sa, oitv) = oitp; - error = setitimer(p, &sa, retval); - if (error) - return error; - if (oitp->it_value.tv_usec) - oitp->it_value.tv_sec++; - *retval = oitp->it_value.tv_sec; - return 0; -} - -int -ibcs2_getmsg(p, uap, retval) - struct proc *p; - struct ibcs2_getmsg_args *uap; - int *retval; -{ - return 0; -} - -int -ibcs2_putmsg(p, uap, retval) - struct proc *p; - struct ibcs2_putmsg_args *uap; - int *retval; -{ - return 0; -} - -int -ibcs2_times(p, uap, retval) - struct proc *p; - struct ibcs2_times_args *uap; - int *retval; -{ - int error; - struct getrusage_args ga; - struct tms tms; - struct timeval t; - caddr_t sg = stackgap_init(); - struct rusage *ru = stackgap_alloc(&sg, sizeof(*ru)); -#define CONVTCK(r) (r.tv_sec * hz + r.tv_usec / (1000000 / hz)) - - SCARG(&ga, who) = RUSAGE_SELF; - SCARG(&ga, rusage) = ru; - error = getrusage(p, &ga, retval); - if (error) - return error; - tms.tms_utime = CONVTCK(ru->ru_utime); - tms.tms_stime = CONVTCK(ru->ru_stime); - - SCARG(&ga, who) = RUSAGE_CHILDREN; - error = getrusage(p, &ga, retval); - if (error) - return error; - tms.tms_cutime = CONVTCK(ru->ru_utime); - tms.tms_cstime = CONVTCK(ru->ru_stime); - - microtime(&t); - *retval = CONVTCK(t); - - return copyout((caddr_t)&tms, (caddr_t)SCARG(uap, tp), - sizeof(struct tms)); -} - -int -ibcs2_stime(p, uap, retval) - struct proc *p; - struct ibcs2_stime_args *uap; - int *retval; -{ - int error; - struct settimeofday_args sa; - caddr_t sg = stackgap_init(); - - SCARG(&sa, tv) = stackgap_alloc(&sg, sizeof(*SCARG(&sa, tv))); - SCARG(&sa, tzp) = NULL; - if (error = copyin((caddr_t)SCARG(uap, timep), - &(SCARG(&sa, tv)->tv_sec), sizeof(long))) - return error; - SCARG(&sa, tv)->tv_usec = 0; - if (error = settimeofday(p, &sa, retval)) - return EPERM; - return 0; -} - -int -ibcs2_utime(p, uap, retval) - struct proc *p; - struct ibcs2_utime_args *uap; - int *retval; -{ - int error; - struct utimes_args sa; - struct timeval *tp; - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - SCARG(&sa, path) = SCARG(uap, path); - if (SCARG(uap, buf)) { - struct ibcs2_utimbuf ubuf; - - if (error = copyin((caddr_t)SCARG(uap, buf), (caddr_t)&ubuf, - sizeof(ubuf))) - return error; - SCARG(&sa, tptr) = stackgap_alloc(&sg, - 2 * sizeof(struct timeval *)); - tp = (struct timeval *)SCARG(&sa, tptr); - tp->tv_sec = ubuf.actime; - tp->tv_usec = 0; - tp++; - tp->tv_sec = ubuf.modtime; - tp->tv_usec = 0; - } else - SCARG(&sa, tptr) = NULL; - return utimes(p, &sa, retval); -} - -int -ibcs2_nice(p, uap, retval) - struct proc *p; - struct ibcs2_nice_args *uap; - int *retval; -{ - int error, cur_nice = p->p_nice; - struct setpriority_args sa; - - SCARG(&sa, which) = PRIO_PROCESS; - SCARG(&sa, who) = 0; - SCARG(&sa, prio) = p->p_nice + SCARG(uap, incr); - if (error = setpriority(p, &sa, retval)) - return EPERM; - *retval = p->p_nice; - return 0; -} - -/* - * iBCS2 getpgrp, setpgrp, setsid, and setpgid - */ - -int -ibcs2_pgrpsys(p, uap, retval) - struct proc *p; - struct ibcs2_pgrpsys_args *uap; - int *retval; -{ - switch (SCARG(uap, type)) { - case 0: /* getpgrp */ - *retval = p->p_pgrp->pg_id; - return 0; - - case 1: /* setpgrp */ - { - struct setpgid_args sa; - - SCARG(&sa, pid) = 0; - SCARG(&sa, pgid) = 0; - setpgid(p, &sa, retval); - *retval = p->p_pgrp->pg_id; - return 0; - } - - case 2: /* setpgid */ - { - struct setpgid_args sa; - - SCARG(&sa, pid) = SCARG(uap, pid); - SCARG(&sa, pgid) = SCARG(uap, pgid); - return setpgid(p, &sa, retval); - } - - case 3: /* setsid */ - return setsid(p, NULL, retval); - - default: - return EINVAL; - } -} - -/* - * XXX - need to check for nested calls - */ - -int -ibcs2_plock(p, uap, retval) - struct proc *p; - struct ibcs2_plock_args *uap; - int *retval; -{ - int error; -#define IBCS2_UNLOCK 0 -#define IBCS2_PROCLOCK 1 -#define IBCS2_TEXTLOCK 2 -#define IBCS2_DATALOCK 4 - - - if (error = suser(p->p_ucred, &p->p_acflag)) - return EPERM; - switch(SCARG(uap, cmd)) { - case IBCS2_UNLOCK: - case IBCS2_PROCLOCK: - case IBCS2_TEXTLOCK: - case IBCS2_DATALOCK: - return 0; /* XXX - TODO */ - } - return EINVAL; -} - -int -ibcs2_uadmin(p, uap, retval) - struct proc *p; - struct ibcs2_uadmin_args *uap; - int *retval; -{ -#define SCO_A_REBOOT 1 -#define SCO_A_SHUTDOWN 2 -#define SCO_A_REMOUNT 4 -#define SCO_A_CLOCK 8 -#define SCO_A_SETCONFIG 128 -#define SCO_A_GETDEV 130 - -#define SCO_AD_HALT 0 -#define SCO_AD_BOOT 1 -#define SCO_AD_IBOOT 2 -#define SCO_AD_PWRDOWN 3 -#define SCO_AD_PWRNAP 4 - -#define SCO_AD_PANICBOOT 1 - -#define SCO_AD_GETBMAJ 0 -#define SCO_AD_GETCMAJ 1 - - switch(SCARG(uap, cmd)) { - case SCO_A_REBOOT: - case SCO_A_SHUTDOWN: - switch(SCARG(uap, func)) { - case SCO_AD_HALT: - case SCO_AD_PWRDOWN: - case SCO_AD_PWRNAP: - reboot(RB_HALT); - case SCO_AD_BOOT: - case SCO_AD_IBOOT: - reboot(RB_AUTOBOOT); - } - return EINVAL; - case SCO_A_REMOUNT: - case SCO_A_CLOCK: - case SCO_A_SETCONFIG: - return 0; - case SCO_A_GETDEV: - return EINVAL; /* XXX - TODO */ - } - return EINVAL; -} - -int -ibcs2_sysfs(p, uap, retval) - struct proc *p; - struct ibcs2_sysfs_args *uap; - int *retval; -{ -#define IBCS2_GETFSIND 1 -#define IBCS2_GETFSTYP 2 -#define IBCS2_GETNFSTYP 3 - - switch(SCARG(uap, cmd)) { - case IBCS2_GETFSIND: - case IBCS2_GETFSTYP: - case IBCS2_GETNFSTYP: - } - return EINVAL; /* XXX - TODO */ -} - -int -ibcs2_poll(p, uap, retval) - struct proc *p; - struct ibcs2_poll_args *uap; - int *retval; -{ - return EINVAL; /* XXX - TODO */ -} - -int -xenix_rdchk(p, uap, retval) - struct proc *p; - struct xenix_rdchk_args *uap; - int *retval; -{ - int error; - struct ioctl_args sa; - caddr_t sg = stackgap_init(); - - SCARG(&sa, fd) = SCARG(uap, fd); - SCARG(&sa, com) = FIONREAD; - SCARG(&sa, data) = stackgap_alloc(&sg, sizeof(int)); - if (error = ioctl(p, &sa, retval)) - return error; - *retval = (*((int*)SCARG(&sa, data))) ? 1 : 0; - return 0; -} - -int -xenix_chsize(p, uap, retval) - struct proc *p; - struct xenix_chsize_args *uap; - int *retval; -{ - struct ftruncate_args sa; - - SCARG(&sa, fd) = SCARG(uap, fd); - SCARG(&sa, pad) = 0; - SCARG(&sa, length) = SCARG(uap, size); - return ftruncate(p, &sa, retval); -} - -int -xenix_nap(p, uap, retval) - struct proc *p; - struct xenix_nap_args *uap; - int *retval; -{ - return ENOSYS; -} - -int -ibcs2_unlink(p, uap, retval) - struct proc *p; - struct ibcs2_unlink_args *uap; - int *retval; -{ - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - return unlink(p, uap, retval); -} - -int -ibcs2_chdir(p, uap, retval) - struct proc *p; - struct ibcs2_chdir_args *uap; - int *retval; -{ - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - return chdir(p, uap, retval); -} - -int -ibcs2_chmod(p, uap, retval) - struct proc *p; - struct ibcs2_chmod_args *uap; - int *retval; -{ - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - return chmod(p, uap, retval); -} - -int -ibcs2_chown(p, uap, retval) - struct proc *p; - struct ibcs2_chown_args *uap; - int *retval; -{ - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - return chown(p, uap, retval); -} - -int -ibcs2_rmdir(p, uap, retval) - struct proc *p; - struct ibcs2_rmdir_args *uap; - int *retval; -{ - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - return rmdir(p, uap, retval); -} - -int -ibcs2_mkdir(p, uap, retval) - struct proc *p; - struct ibcs2_mkdir_args *uap; - int *retval; -{ - caddr_t sg = stackgap_init(); - - CHECKALTCREAT(p, &sg, SCARG(uap, path)); - return mkdir(p, uap, retval); -} - -int -ibcs2_symlink(p, uap, retval) - struct proc *p; - struct ibcs2_symlink_args *uap; - int *retval; -{ - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - CHECKALTCREAT(p, &sg, SCARG(uap, link)); - return symlink(p, uap, retval); -} - -int -ibcs2_rename(p, uap, retval) - struct proc *p; - struct ibcs2_rename_args *uap; - int *retval; -{ - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, from)); - CHECKALTCREAT(p, &sg, SCARG(uap, to)); - return rename(p, uap, retval); -} - -int -ibcs2_readlink(p, uap, retval) - struct proc *p; - struct ibcs2_readlink_args *uap; - int *retval; -{ - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - return readlink(p, uap, retval); -} diff --git a/sys/i386/ibcs2/ibcs2_mount.h b/sys/i386/ibcs2/ibcs2_mount.h deleted file mode 100644 index d1b9aaaedc24..000000000000 --- a/sys/i386/ibcs2/ibcs2_mount.h +++ /dev/null @@ -1,41 +0,0 @@ -/* $NetBSD: ibcs2_mount.h,v 1.2 1994/10/26 02:53:00 cgd Exp $ */ - -/* - * Copyright (c) 1994 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_MOUNT_H -#define _IBCS2_MOUNT_H - -#define IBCS2_MS_RDONLY 0x01 -#define IBCS2_MS_FSS 0x02 -#define IBCS2_MS_DATA 0x04 -#define IBCS2_MS_CACHE 0x08 - -#endif /* _IBCS2_MOUNT_H */ diff --git a/sys/i386/ibcs2/ibcs2_signal.c b/sys/i386/ibcs2/ibcs2_signal.c deleted file mode 100644 index ba768b0966ac..000000000000 --- a/sys/i386/ibcs2/ibcs2_signal.c +++ /dev/null @@ -1,492 +0,0 @@ -/* $NetBSD: ibcs2_signal.c,v 1.6 1995/09/19 22:19:07 thorpej Exp $ */ - -/* - * Copyright (c) 1995 Scott Bartram - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/namei.h> -#include <sys/proc.h> -#include <sys/filedesc.h> -#include <sys/ioctl.h> -#include <sys/mount.h> -#include <sys/kernel.h> -#include <sys/signal.h> -#include <sys/signalvar.h> -#include <sys/malloc.h> - -#include <sys/syscallargs.h> - -#include <compat/ibcs2/ibcs2_types.h> -#include <compat/ibcs2/ibcs2_signal.h> -#include <compat/ibcs2/ibcs2_syscallargs.h> -#include <compat/ibcs2/ibcs2_util.h> - -#define sigemptyset(s) bzero((s), sizeof(*(s))) -#define sigismember(s, n) (*(s) & sigmask(n)) -#define sigaddset(s, n) (*(s) |= sigmask(n)) - -#define ibcs2_sigmask(n) (1 << ((n) - 1)) -#define ibcs2_sigemptyset(s) bzero((s), sizeof(*(s))) -#define ibcs2_sigismember(s, n) (*(s) & ibcs2_sigmask(n)) -#define ibcs2_sigaddset(s, n) (*(s) |= ibcs2_sigmask(n)) - -int bsd_to_ibcs2_sig[] = { - 0, /* 0 */ - IBCS2_SIGHUP, /* 1 */ - IBCS2_SIGINT, /* 2 */ - IBCS2_SIGQUIT, /* 3 */ - IBCS2_SIGILL, /* 4 */ - IBCS2_SIGTRAP, /* 5 */ - IBCS2_SIGABRT, /* 6 */ - IBCS2_SIGEMT, /* 7 */ - IBCS2_SIGFPE, /* 8 */ - IBCS2_SIGKILL, /* 9 */ - IBCS2_SIGBUS, /* 10 */ - IBCS2_SIGSEGV, /* 11 */ - IBCS2_SIGSYS, /* 12 */ - IBCS2_SIGPIPE, /* 13 */ - IBCS2_SIGALRM, /* 14 */ - IBCS2_SIGTERM, /* 15 */ - 0, /* 16 - SIGURG */ - IBCS2_SIGSTOP, /* 17 */ - IBCS2_SIGTSTP, /* 18 */ - IBCS2_SIGCONT, /* 19 */ - IBCS2_SIGCLD, /* 20 */ - IBCS2_SIGTTIN, /* 21 */ - IBCS2_SIGTTOU, /* 22 */ - IBCS2_SIGPOLL, /* 23 */ - 0, /* 24 - SIGXCPU */ - 0, /* 25 - SIGXFSZ */ - IBCS2_SIGVTALRM, /* 26 */ - IBCS2_SIGPROF, /* 27 */ - IBCS2_SIGWINCH, /* 28 */ - 0, /* 29 */ - IBCS2_SIGUSR1, /* 30 */ - IBCS2_SIGUSR2, /* 31 */ -}; - -int ibcs2_to_bsd_sig[] = { - 0, /* 0 */ - SIGHUP, /* 1 */ - SIGINT, /* 2 */ - SIGQUIT, /* 3 */ - SIGILL, /* 4 */ - SIGTRAP, /* 5 */ - SIGABRT, /* 6 */ - SIGEMT, /* 7 */ - SIGFPE, /* 8 */ - SIGKILL, /* 9 */ - SIGBUS, /* 10 */ - SIGSEGV, /* 11 */ - SIGSYS, /* 12 */ - SIGPIPE, /* 13 */ - SIGALRM, /* 14 */ - SIGTERM, /* 15 */ - SIGUSR1, /* 16 */ - SIGUSR2, /* 17 */ - SIGCHLD, /* 18 */ - 0, /* 19 - SIGPWR */ - SIGWINCH, /* 20 */ - 0, /* 21 */ - SIGIO, /* 22 */ - SIGSTOP, /* 23 */ - SIGTSTP, /* 24 */ - SIGCONT, /* 25 */ - SIGTTIN, /* 26 */ - SIGTTOU, /* 27 */ - SIGVTALRM, /* 28 */ - SIGPROF, /* 29 */ - 0, /* 30 */ - 0, /* 31 */ -}; - -void -ibcs2_to_bsd_sigset(iss, bss) - const ibcs2_sigset_t *iss; - sigset_t *bss; -{ - int i, newsig; - - sigemptyset(bss); - for (i = 1; i < IBCS2_NSIG; i++) { - if (ibcs2_sigismember(iss, i)) { - newsig = ibcs2_to_bsd_sig[i]; - if (newsig) - sigaddset(bss, newsig); - } - } -} - -void -bsd_to_ibcs2_sigset(bss, iss) - const sigset_t *bss; - ibcs2_sigset_t *iss; -{ - int i, newsig; - - ibcs2_sigemptyset(iss); - for (i = 1; i < NSIG; i++) { - if (sigismember(bss, i)) { - newsig = bsd_to_ibcs2_sig[i]; - if (newsig) - ibcs2_sigaddset(iss, newsig); - } - } -} - -void -ibcs2_to_bsd_sigaction(isa, bsa) - struct ibcs2_sigaction *isa; - struct sigaction *bsa; -{ - - bsa->sa_handler = isa->sa_handler; - ibcs2_to_bsd_sigset(&isa->sa_mask, &bsa->sa_mask); - bsa->sa_flags = 0; - if ((isa->sa_flags & IBCS2_SA_NOCLDSTOP) != 0) - bsa->sa_flags |= SA_NOCLDSTOP; -} - -void -bsd_to_ibcs2_sigaction(bsa, isa) - struct sigaction *bsa; - struct ibcs2_sigaction *isa; -{ - - isa->sa_handler = bsa->sa_handler; - bsd_to_ibcs2_sigset(&bsa->sa_mask, &isa->sa_mask); - isa->sa_flags = 0; - if ((bsa->sa_flags & SA_NOCLDSTOP) != 0) - isa->sa_flags |= SA_NOCLDSTOP; -} - -int -ibcs2_sigaction(p, v, retval) - register struct proc *p; - void *v; - register_t *retval; -{ - struct ibcs2_sigaction_args /* { - syscallarg(int) sig; - syscallarg(struct ibcs2_sigaction *) act; - syscallarg(struct ibcs2_sigaction *) oact; - } */ *uap = v; - struct ibcs2_sigaction *nisa, *oisa, tmpisa; - struct sigaction *nbsa, *obsa, tmpbsa; - struct sigaction_args sa; - caddr_t sg; - int error; - - sg = stackgap_init(p->p_emul); - nisa = SCARG(uap, act); - oisa = SCARG(uap, oact); - - if (oisa != NULL) - obsa = stackgap_alloc(&sg, sizeof(struct sigaction)); - else - obsa = NULL; - - if (nisa != NULL) { - nbsa = stackgap_alloc(&sg, sizeof(struct sigaction)); - if ((error = copyin(nisa, &tmpisa, sizeof(tmpisa))) != 0) - return error; - ibcs2_to_bsd_sigaction(&tmpisa, &tmpbsa); - if ((error = copyout(&tmpbsa, nbsa, sizeof(tmpbsa))) != 0) - return error; - } else - nbsa = NULL; - - SCARG(&sa, signum) = ibcs2_to_bsd_sig[SCARG(uap, sig)]; - SCARG(&sa, nsa) = nbsa; - SCARG(&sa, osa) = obsa; - - if ((error = sigaction(p, &sa, retval)) != 0) - return error; - - if (oisa != NULL) { - if ((error = copyin(obsa, &tmpbsa, sizeof(tmpbsa))) != 0) - return error; - bsd_to_ibcs2_sigaction(&tmpbsa, &tmpisa); - if ((error = copyout(&tmpisa, oisa, sizeof(tmpisa))) != 0) - return error; - } - - return 0; -} - -int -ibcs2_sigsys(p, v, retval) - register struct proc *p; - void *v; - register_t *retval; -{ - struct ibcs2_sigsys_args /* { - syscallarg(int) sig; - syscallarg(ibcs2_sig_t) fp; - } */ *uap = v; - int signum = ibcs2_to_bsd_sig[IBCS2_SIGNO(SCARG(uap, sig))]; - int error; - caddr_t sg = stackgap_init(p->p_emul); - - if (signum <= 0 || signum >= IBCS2_NSIG) { - if (IBCS2_SIGCALL(SCARG(uap, sig)) == IBCS2_SIGNAL_MASK || - IBCS2_SIGCALL(SCARG(uap, sig)) == IBCS2_SIGSET_MASK) - *retval = (int)IBCS2_SIG_ERR; - return EINVAL; - } - - switch (IBCS2_SIGCALL(SCARG(uap, sig))) { - /* - * sigset is identical to signal() except that SIG_HOLD is allowed as - * an action. - */ - case IBCS2_SIGSET_MASK: - /* - * sigset is identical to signal() except - * that SIG_HOLD is allowed as - * an action. - */ - if (SCARG(uap, fp) == IBCS2_SIG_HOLD) { - struct sigprocmask_args sa; - - SCARG(&sa, how) = SIG_BLOCK; - SCARG(&sa, mask) = sigmask(signum); - return sigprocmask(p, &sa, retval); - } - /* FALLTHROUGH */ - - case IBCS2_SIGNAL_MASK: - { - struct sigaction_args sa_args; - struct sigaction *nbsa, *obsa, sa; - - nbsa = stackgap_alloc(&sg, sizeof(struct sigaction)); - obsa = stackgap_alloc(&sg, sizeof(struct sigaction)); - SCARG(&sa_args, signum) = signum; - SCARG(&sa_args, nsa) = nbsa; - SCARG(&sa_args, osa) = obsa; - - sa.sa_handler = SCARG(uap, fp); - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; -#if 0 - if (signum != SIGALRM) - sa.sa_flags = SA_RESTART; -#endif - if ((error = copyout(&sa, nbsa, sizeof(sa))) != 0) - return error; - if ((error = sigaction(p, &sa_args, retval)) != 0) { - DPRINTF(("signal: sigaction failed: %d\n", - error)); - *retval = (int)IBCS2_SIG_ERR; - return error; - } - if ((error = copyin(obsa, &sa, sizeof(sa))) != 0) - return error; - *retval = (int)sa.sa_handler; - return 0; - } - - case IBCS2_SIGHOLD_MASK: - { - struct sigprocmask_args sa; - - SCARG(&sa, how) = SIG_BLOCK; - SCARG(&sa, mask) = sigmask(signum); - return sigprocmask(p, &sa, retval); - } - - case IBCS2_SIGRELSE_MASK: - { - struct sigprocmask_args sa; - - SCARG(&sa, how) = SIG_UNBLOCK; - SCARG(&sa, mask) = sigmask(signum); - return sigprocmask(p, &sa, retval); - } - - case IBCS2_SIGIGNORE_MASK: - { - struct sigaction_args sa_args; - struct sigaction *bsa, sa; - - bsa = stackgap_alloc(&sg, sizeof(struct sigaction)); - SCARG(&sa_args, signum) = signum; - SCARG(&sa_args, nsa) = bsa; - SCARG(&sa_args, osa) = NULL; - - sa.sa_handler = SIG_IGN; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - if ((error = copyout(&sa, bsa, sizeof(sa))) != 0) - return error; - if ((error = sigaction(p, &sa_args, retval)) != 0) { - DPRINTF(("sigignore: sigaction failed\n")); - return error; - } - return 0; - } - - case IBCS2_SIGPAUSE_MASK: - { - struct sigsuspend_args sa; - - SCARG(&sa, mask) = p->p_sigmask &~ sigmask(signum); - return sigsuspend(p, &sa, retval); - } - - default: - return ENOSYS; - } -} - -int -ibcs2_sigprocmask(p, v, retval) - register struct proc *p; - void *v; - register_t *retval; -{ - struct ibcs2_sigprocmask_args /* { - syscallarg(int) how; - syscallarg(ibcs2_sigset_t *) set; - syscallarg(ibcs2_sigset_t *) oset; - } */ *uap = v; - ibcs2_sigset_t iss; - sigset_t bss; - int error = 0; - - if (SCARG(uap, oset) != NULL) { - /* Fix the return value first if needed */ - bsd_to_ibcs2_sigset(&p->p_sigmask, &iss); - if ((error = copyout(&iss, SCARG(uap, oset), sizeof(iss))) != 0) - return error; - } - - if (SCARG(uap, set) == NULL) - /* Just examine */ - return 0; - - if ((error = copyin(SCARG(uap, set), &iss, sizeof(iss))) != 0) - return error; - - ibcs2_to_bsd_sigset(&iss, &bss); - - (void) splhigh(); - - switch (SCARG(uap, how)) { - case IBCS2_SIG_BLOCK: - p->p_sigmask |= bss & ~sigcantmask; - break; - - case IBCS2_SIG_UNBLOCK: - p->p_sigmask &= ~bss; - break; - - case IBCS2_SIG_SETMASK: - p->p_sigmask = bss & ~sigcantmask; - break; - - default: - error = EINVAL; - break; - } - - (void) spl0(); - - return error; -} - -int -ibcs2_sigpending(p, v, retval) - register struct proc *p; - void *v; - register_t *retval; -{ - struct ibcs2_sigpending_args /* { - syscallarg(ibcs2_sigset_t *) mask; - } */ *uap = v; - sigset_t bss; - ibcs2_sigset_t iss; - - bss = p->p_siglist & p->p_sigmask; - bsd_to_ibcs2_sigset(&bss, &iss); - - return copyout(&iss, SCARG(uap, mask), sizeof(iss)); -} - -int -ibcs2_sigsuspend(p, v, retval) - register struct proc *p; - void *v; - register_t *retval; -{ - struct ibcs2_sigsuspend_args /* { - syscallarg(ibcs2_sigset_t *) mask; - } */ *uap = v; - ibcs2_sigset_t sss; - sigset_t bss; - struct sigsuspend_args sa; - int error; - - if ((error = copyin(SCARG(uap, mask), &sss, sizeof(sss))) != 0) - return error; - - ibcs2_to_bsd_sigset(&sss, &bss); - - SCARG(&sa, mask) = bss; - return sigsuspend(p, &sa, retval); -} - -int -ibcs2_pause(p, uap, retval) - register struct proc *p; - void *uap; - register_t *retval; -{ - struct sigsuspend_args bsa; - - SCARG(&bsa, mask) = p->p_sigmask; - return sigsuspend(p, &bsa, retval); -} - -int -ibcs2_kill(p, v, retval) - register struct proc *p; - void *v; - register_t *retval; -{ - struct ibcs2_kill_args /* { - syscallarg(int) pid; - syscallarg(int) signo; - } */ *uap = v; - struct kill_args ka; - - SCARG(&ka, pid) = SCARG(uap, pid); - SCARG(&ka, signum) = ibcs2_to_bsd_sig[SCARG(uap, signo)]; - return kill(p, &ka, retval); -} diff --git a/sys/i386/ibcs2/ibcs2_signal.h b/sys/i386/ibcs2/ibcs2_signal.h deleted file mode 100644 index 2858688d79d8..000000000000 --- a/sys/i386/ibcs2/ibcs2_signal.h +++ /dev/null @@ -1,105 +0,0 @@ -/* $NetBSD: ibcs2_signal.h,v 1.7 1995/08/14 02:26:01 mycroft Exp $ */ - -/* - * Copyright (c) 1994, 1995 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_SIGNAL_H -#define _IBCS2_SIGNAL_H - -#define IBCS2_SIGHUP 1 -#define IBCS2_SIGINT 2 -#define IBCS2_SIGQUIT 3 -#define IBCS2_SIGILL 4 -#define IBCS2_SIGTRAP 5 -#define IBCS2_SIGIOT 6 -#define IBCS2_SIGABRT 6 -#define IBCS2_SIGEMT 7 -#define IBCS2_SIGFPE 8 -#define IBCS2_SIGKILL 9 -#define IBCS2_SIGBUS 10 -#define IBCS2_SIGSEGV 11 -#define IBCS2_SIGSYS 12 -#define IBCS2_SIGPIPE 13 -#define IBCS2_SIGALRM 14 -#define IBCS2_SIGTERM 15 -#define IBCS2_SIGUSR1 16 -#define IBCS2_SIGUSR2 17 -#define IBCS2_SIGCLD 18 -#define IBCS2_SIGPWR 19 -#define IBCS2_SIGWINCH 20 -#define IBCS2_SIGPOLL 22 -#define IBCS2_NSIG 32 - -/* - * SCO-specific - */ -#define IBCS2_SIGSTOP 23 -#define IBCS2_SIGTSTP 24 -#define IBCS2_SIGCONT 25 -#define IBCS2_SIGTTIN 26 -#define IBCS2_SIGTTOU 27 -#define IBCS2_SIGVTALRM 28 -#define IBCS2_SIGPROF 29 - -#define IBCS2_SIGNO_MASK 0x00FF -#define IBCS2_SIGNAL_MASK 0x0000 -#define IBCS2_SIGSET_MASK 0x0100 -#define IBCS2_SIGHOLD_MASK 0x0200 -#define IBCS2_SIGRELSE_MASK 0x0400 -#define IBCS2_SIGIGNORE_MASK 0x0800 -#define IBCS2_SIGPAUSE_MASK 0x1000 - -#define IBCS2_SIGNO(x) ((x) & IBCS2_SIGNO_MASK) -#define IBCS2_SIGCALL(x) ((x) & ~IBCS2_SIGNO_MASK) - -#define IBCS2_SIG_DFL (void(*)())0 -#define IBCS2_SIG_ERR (void(*)())-1 -#define IBCS2_SIG_IGN (void(*)())1 -#define IBCS2_SIG_HOLD (void(*)())2 - -#define IBCS2_SIG_SETMASK 0 -#define IBCS2_SIG_BLOCK 1 -#define IBCS2_SIG_UNBLOCK 2 - -typedef long ibcs2_sigset_t; -typedef void (*ibcs2_sig_t) __P((int)); - -struct ibcs2_sigaction { - ibcs2_sig_t sa_handler; - ibcs2_sigset_t sa_mask; - int sa_flags; -}; - -/* sa_flags */ -#define IBCS2_SA_NOCLDSTOP 1 - -extern int bsd_to_ibcs2_sig[]; - -#endif /* _IBCS2_SIGNAL_H */ diff --git a/sys/i386/ibcs2/ibcs2_socksys.c b/sys/i386/ibcs2/ibcs2_socksys.c deleted file mode 100644 index 6cf0a8f0d6a9..000000000000 --- a/sys/i386/ibcs2/ibcs2_socksys.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 1994, 1995 Scott Bartram - * Copyright (c) 1994 Arne H Juul - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -#include <sys/param.h> -#include <sys/proc.h> -#include <sys/file.h> -#include <sys/filedesc.h> -#include <sys/ioctl.h> -#include <sys/termios.h> -#include <sys/tty.h> -#include <sys/socket.h> -#include <sys/ioctl.h> -#include <net/if.h> - -#include <compat/ibcs2/ibcs2_socksys.h> -#include <compat/ibcs2/ibcs2_util.h> - -/* - * iBCS2 socksys calls. - */ - -struct ibcs2_socksys_args { - int fd; - int magic; - caddr_t argsp; -}; - -int -ibcs2_socksys(p, uap, retval) - register struct proc *p; - register struct ibcs2_socksys_args *uap; - int *retval; -{ - register struct filedesc *fdp = p->p_fd; - register struct file *fp; - int error; - int realargs[7]; /* 1 for command, 6 for recvfrom */ - - /* - * SOCKET should only be legal on /dev/socksys. - * GETIPDOMAINNAME should only be legal on /dev/socksys ? - * The others are (and should be) only legal on sockets. - */ - - if (error = copyin(uap->argsp, (caddr_t)realargs, sizeof(realargs))) - return error; - DPRINTF(("ibcs2_socksys: %08x %08x %08x %08x %08x %08x %08x\n", - realargs[0], realargs[1], realargs[2], realargs[3], - realargs[4], realargs[5], realargs[6])); - switch (realargs[0]) { - case SOCKSYS_ACCEPT: - return accept(p, realargs+1, retval); - case SOCKSYS_BIND: - return bind(p, realargs+1, retval); - case SOCKSYS_CONNECT: - return connect(p, realargs+1, retval); - case SOCKSYS_GETPEERNAME: - return getpeername(p, realargs+1, retval); - case SOCKSYS_GETSOCKNAME: - return getsockname(p, realargs+1, retval); - case SOCKSYS_GETSOCKOPT: - return getsockopt(p, realargs+1, retval); - case SOCKSYS_LISTEN: - return listen(p, realargs+1, retval); - case SOCKSYS_RECV: - realargs[5] = realargs[6] = 0; - /* FALLTHROUGH */ - case SOCKSYS_RECVFROM: - return recvfrom(p, realargs+1, retval); - case SOCKSYS_SEND: - realargs[5] = realargs[6] = 0; - /* FALLTHROUGH */ - case SOCKSYS_SENDTO: - return sendto(p, realargs+1, retval); - case SOCKSYS_SETSOCKOPT: - return setsockopt(p, realargs+1, retval); - case SOCKSYS_SHUTDOWN: - return shutdown(p, realargs+1, retval); - case SOCKSYS_SOCKET: - return socket(p, realargs+1, retval); - case SOCKSYS_SELECT: - return select(p, realargs+1, retval); - case SOCKSYS_GETIPDOMAIN: - return compat_09_getdomainname(p, realargs + 1, retval); - case SOCKSYS_SETIPDOMAIN: - return compat_09_setdomainname(p, realargs + 1, retval); - case SOCKSYS_ADJTIME: - return adjtime(p, realargs + 1, retval); - case SOCKSYS_SETREUID: - return compat_43_setreuid(p, realargs + 1, retval); - case SOCKSYS_SETREGID: - return compat_43_setregid(p, realargs + 1, retval); - case SOCKSYS_GETTIME: - return gettimeofday(p, realargs + 1, retval); - case SOCKSYS_SETTIME: - return settimeofday(p, realargs + 1, retval); - case SOCKSYS_GETITIMER: - return getitimer(p, realargs + 1, retval); - case SOCKSYS_SETITIMER: - return setitimer(p, realargs + 1, retval); - - default: - printf("socksys unknown %08x %08x %08x %08x %08x %08x %08x\n", - realargs[0], realargs[1], realargs[2], realargs[3], - realargs[4], realargs[5], realargs[6]); - return EINVAL; - } - /* NOTREACHED */ -} diff --git a/sys/i386/ibcs2/ibcs2_socksys.h b/sys/i386/ibcs2/ibcs2_socksys.h deleted file mode 100644 index bc89180b44b4..000000000000 --- a/sys/i386/ibcs2/ibcs2_socksys.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 1994, 1995 Scott Bartram - * Copyright (c) 1994 Arne H Juul - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_SOCKSYS_H -#define _IBCS2_SOCKSYS_H 1 - -#include <sys/ioccom.h> -#include <compat/ibcs2/ibcs2_types.h> - -#define SOCKSYS_ACCEPT 1 -#define SOCKSYS_BIND 2 -#define SOCKSYS_CONNECT 3 -#define SOCKSYS_GETPEERNAME 4 -#define SOCKSYS_GETSOCKNAME 5 -#define SOCKSYS_GETSOCKOPT 6 -#define SOCKSYS_LISTEN 7 -#define SOCKSYS_RECV 8 -#define SOCKSYS_RECVFROM 9 -#define SOCKSYS_SEND 10 -#define SOCKSYS_SENDTO 11 -#define SOCKSYS_SETSOCKOPT 12 -#define SOCKSYS_SHUTDOWN 13 -#define SOCKSYS_SOCKET 14 -#define SOCKSYS_SELECT 15 -#define SOCKSYS_GETIPDOMAIN 16 -#define SOCKSYS_SETIPDOMAIN 17 -#define SOCKSYS_ADJTIME 18 -#define SOCKSYS_SETREUID 19 -#define SOCKSYS_SETREGID 20 -#define SOCKSYS_GETTIME 21 -#define SOCKSYS_SETTIME 22 -#define SOCKSYS_GETITIMER 23 -#define SOCKSYS_SETITIMER 24 - -#define IBCS2_SIOCSHIWAT _IOW('S', 1, int) -#define IBCS2_SIOCGHIWAT _IOR('S', 2, int) -#define IBCS2_SIOCSLOWAT _IOW('S', 3, int) -#define IBCS2_SIOCGLOWAT _IOR('S', 4, int) -#define IBCS2_SIOCATMARK _IOR('S', 5, int) -#define IBCS2_SIOCSPGRP _IOW('S', 6, int) -#define IBCS2_SIOCGPGRP _IOR('S', 7, int) -#define IBCS2_FIONREAD _IOR('S', 8, int) -#define IBCS2_FIONBIO _IOW('S', 9, int) -#define IBCS2_FIOASYNC _IOW('S', 10, int) -#define IBCS2_SIOCPROTO _IOW('S', 11, struct socknewproto) -#define IBCS2_SIOCGETNAME _IOR('S', 12, struct sockaddr) -#define IBCS2_SIOCGETPEER _IOR('S', 13, struct sockaddr) -#define IBCS2_IF_UNITSEL _IOW('S', 14, int) -#define IBCS2_SIOCXPROTO _IO('S', 15) - -#define IBCS2_SIOCADDRT _IOW('R', 9, struct rtentry) -#define IBCS2_SIOCDELRT _IOW('R', 10, struct rtentry) - -#define IBCS2_SIOCSIFADDR _IOW('I', 11, struct ifreq) -#define IBCS2_SIOCGIFADDR _IOWR('I', 12, struct ifreq) -#define IBCS2_SIOCSIFDSTADDR _IOW('I', 13, struct ifreq) -#define IBCS2_SIOCGIFDSTADDR _IOWR('I', 14, struct ifreq) -#define IBCS2_SIOCSIFFLAGS _IOW('I', 15, struct ifreq) -#define IBCS2_SIOCGIFFLAGS _IOWR('I', 16, struct ifreq) -#define IBCS2_SIOCGIFCONF _IOWR('I', 17, struct ifconf) -#define IBCS2_SIOCSIFMTU _IOW('I', 21, struct ifreq) -#define IBCS2_SIOCGIFMTU _IOWR('I', 22, struct ifreq) -#define IBCS2_SIOCIFDETACH _IOW('I', 26, struct ifreq) -#define IBCS2_SIOCGENPSTATS _IOWR('I', 27, struct ifreq) -#define IBCS2_SIOCX25XMT _IOWR('I', 29, struct ifreq) -#define IBCS2_SIOCX25RCV _IOWR('I', 30, struct ifreq) -#define IBCS2_SIOCX25TBL _IOWR('I', 31, struct ifreq) -#define IBCS2_SIOCGIFBRDADDR _IOWR('I', 32, struct ifreq) -#define IBCS2_SIOCSIFBRDADDR _IOW('I', 33, struct ifreq) -#define IBCS2_SIOCGIFNETMASK _IOWR('I', 34, struct ifreq) -#define IBCS2_SIOCSIFNETMASK _IOW('I', 35, struct ifreq) -#define IBCS2_SIOCGIFMETRIC _IOWR('I', 36, struct ifreq) -#define IBCS2_SIOCSIFMETRIC _IOW('I', 37, struct ifreq) -#define IBCS2_SIOCSARP _IOW('I', 38, struct arpreq) -#define IBCS2_SIOCGARP _IOWR('I', 39, struct arpreq) -#define IBCS2_SIOCDARP _IOW('I', 40, struct arpreq) -#define IBCS2_SIOCSIFNAME _IOW('I', 41, struct ifreq) -#define IBCS2_SIOCGIFONEP _IOWR('I', 42, struct ifreq) -#define IBCS2_SIOCSIFONEP _IOW('I', 43, struct ifreq) -#define IBCS2_SIOCGENADDR _IOWR('I', 65, struct ifreq) -#define IBCS2_SIOCSOCKSYS _IOW('I', 66, struct socksysreq) - -struct socksysreq { - int realargs[7]; -}; - -struct socknewproto { - int family; - int type; - int proto; - ibcs2_dev_t dev; - int flags; -}; - -#endif /* _IBCS2_SOCKSYS_H */ diff --git a/sys/i386/ibcs2/ibcs2_stat.c b/sys/i386/ibcs2/ibcs2_stat.c deleted file mode 100644 index a9d5c4bb0f9f..000000000000 --- a/sys/i386/ibcs2/ibcs2_stat.c +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright (c) 1995 Scott Bartram - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/namei.h> -#include <sys/proc.h> -#include <sys/file.h> -#include <sys/stat.h> -#include <sys/filedesc.h> -#include <sys/ioctl.h> -#include <sys/kernel.h> -#include <sys/mount.h> -#include <sys/malloc.h> -#include <sys/vnode.h> -#include <sys/syscallargs.h> - -#include <vm/vm.h> - -#include <compat/ibcs2/ibcs2_types.h> -#include <compat/ibcs2/ibcs2_fcntl.h> -#include <compat/ibcs2/ibcs2_signal.h> -#include <compat/ibcs2/ibcs2_stat.h> -#include <compat/ibcs2/ibcs2_statfs.h> -#include <compat/ibcs2/ibcs2_syscallargs.h> -#include <compat/ibcs2/ibcs2_ustat.h> -#include <compat/ibcs2/ibcs2_util.h> -#include <compat/ibcs2/ibcs2_utsname.h> - - -static void -bsd_stat2ibcs_stat(st, st4) - struct ostat *st; - struct ibcs2_stat *st4; -{ - bzero(st4, sizeof(*st4)); - st4->st_dev = (ibcs2_dev_t)st->st_dev; - st4->st_ino = (ibcs2_ino_t)st->st_ino; - st4->st_mode = (ibcs2_mode_t)st->st_mode; - st4->st_nlink = (ibcs2_nlink_t)st->st_nlink; - st4->st_uid = (ibcs2_uid_t)st->st_uid; - st4->st_gid = (ibcs2_gid_t)st->st_gid; - st4->st_rdev = (ibcs2_dev_t)st->st_rdev; - st4->st_size = (ibcs2_off_t)st->st_size; - st4->st_atim = (ibcs2_time_t)st->st_atime; - st4->st_mtim = (ibcs2_time_t)st->st_mtime; - st4->st_ctim = (ibcs2_time_t)st->st_ctime; -} - -static int -cvt_statfs(sp, buf, len) - struct statfs *sp; - caddr_t buf; - int len; -{ - struct ibcs2_statfs ssfs; - - bzero(&ssfs, sizeof ssfs); - ssfs.f_fstyp = 0; - ssfs.f_bsize = sp->f_bsize; - ssfs.f_frsize = 0; - ssfs.f_blocks = sp->f_blocks; - ssfs.f_bfree = sp->f_bfree; - ssfs.f_files = sp->f_files; - ssfs.f_ffree = sp->f_ffree; - ssfs.f_fname[0] = 0; - ssfs.f_fpack[0] = 0; - return copyout((caddr_t)&ssfs, buf, len); -} - -int -ibcs2_statfs(p, uap, retval) - struct proc *p; - struct ibcs2_statfs_args *uap; - int *retval; -{ - register struct mount *mp; - register struct statfs *sp; - int error; - struct nameidata nd; - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p); - if (error = namei(&nd)) - return (error); - mp = nd.ni_vp->v_mount; - sp = &mp->mnt_stat; - vrele(nd.ni_vp); - if (error = VFS_STATFS(mp, sp, p)) - return (error); - sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; - return cvt_statfs(sp, (caddr_t)SCARG(uap, buf), SCARG(uap, len)); -} - -int -ibcs2_fstatfs(p, uap, retval) - struct proc *p; - struct ibcs2_fstatfs_args *uap; - int *retval; -{ - struct file *fp; - struct mount *mp; - register struct statfs *sp; - int error; - - if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) - return (error); - mp = ((struct vnode *)fp->f_data)->v_mount; - sp = &mp->mnt_stat; - if (error = VFS_STATFS(mp, sp, p)) - return (error); - sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; - return cvt_statfs(sp, (caddr_t)SCARG(uap, buf), SCARG(uap, len)); -} - -int -ibcs2_stat(p, uap, retval) - struct proc *p; - struct ibcs2_stat_args *uap; - int *retval; -{ - struct ostat st; - struct ibcs2_stat ibcs2_st; - struct compat_43_stat_args cup; - int error; - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - SCARG(&cup, path) = SCARG(uap, path); - SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st)); - if (error = compat_43_stat(p, &cup, retval)) - return error; - if (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) - return error; - bsd_stat2ibcs_stat(&st, &ibcs2_st); - return copyout((caddr_t)&ibcs2_st, (caddr_t)SCARG(uap, st), - ibcs2_stat_len); -} - -int -ibcs2_lstat(p, uap, retval) - struct proc *p; - struct ibcs2_lstat_args *uap; - int *retval; -{ - struct ostat st; - struct ibcs2_stat ibcs2_st; - struct compat_43_lstat_args cup; - int error; - caddr_t sg = stackgap_init(); - - CHECKALTEXIST(p, &sg, SCARG(uap, path)); - SCARG(&cup, path) = SCARG(uap, path); - SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st)); - if (error = compat_43_lstat(p, &cup, retval)) - return error; - if (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) - return error; - bsd_stat2ibcs_stat(&st, &ibcs2_st); - return copyout((caddr_t)&ibcs2_st, (caddr_t)SCARG(uap, st), - ibcs2_stat_len); -} - -int -ibcs2_fstat(p, uap, retval) - struct proc *p; - struct ibcs2_fstat_args *uap; - int *retval; -{ - struct ostat st; - struct ibcs2_stat ibcs2_st; - struct compat_43_fstat_args cup; - int error; - caddr_t sg = stackgap_init(); - - SCARG(&cup, fd) = SCARG(uap, fd); - SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(st)); - if (error = compat_43_fstat(p, &cup, retval)) - return error; - if (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) - return error; - bsd_stat2ibcs_stat(&st, &ibcs2_st); - return copyout((caddr_t)&ibcs2_st, (caddr_t)SCARG(uap, st), - ibcs2_stat_len); -} - -int -ibcs2_utssys(p, uap, retval) - struct proc *p; - struct ibcs2_utssys_args *uap; - int *retval; -{ - switch (SCARG(uap, flag)) { - case 0: /* uname(2) */ - { - struct ibcs2_utsname sut; - extern char ostype[], machine[], osrelease[]; - - bzero(&sut, ibcs2_utsname_len); - bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1); - bcopy(hostname, sut.nodename, sizeof(sut.nodename)); - sut.nodename[sizeof(sut.nodename)-1] = '\0'; - bcopy(osrelease, sut.release, sizeof(sut.release) - 1); - bcopy("1", sut.version, sizeof(sut.version) - 1); - bcopy(machine, sut.machine, sizeof(sut.machine) - 1); - - return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, a1), - ibcs2_utsname_len); - } - - case 2: /* ustat(2) */ - { - return ENOSYS; /* XXX - TODO */ - } - - default: - return ENOSYS; - } -} diff --git a/sys/i386/ibcs2/ibcs2_stat.h b/sys/i386/ibcs2/ibcs2_stat.h deleted file mode 100644 index 2eb01027e0cc..000000000000 --- a/sys/i386/ibcs2/ibcs2_stat.h +++ /dev/null @@ -1,89 +0,0 @@ -/* $NetBSD: ibcs2_stat.h,v 1.2 1994/10/26 02:53:03 cgd Exp $ */ - -/* - * Copyright (c) 1994 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_STAT_H -#define _IBCS2_STAT_H - -#include <compat/ibcs2/ibcs2_types.h> - -struct ibcs2_stat { - ibcs2_dev_t st_dev; - ibcs2_ino_t st_ino; - ibcs2_mode_t st_mode; - ibcs2_nlink_t st_nlink; - ibcs2_uid_t st_uid; - ibcs2_gid_t st_gid; - ibcs2_dev_t st_rdev; - ibcs2_off_t st_size; - ibcs2_time_t st_atim; - ibcs2_time_t st_mtim; - ibcs2_time_t st_ctim; -}; - -#define ibcs2_stat_len (sizeof(struct ibcs2_stat)) - -#define IBCS2_S_IFMT 0xf000 -#define IBCS2_S_IFIFO 0x1000 -#define IBCS2_S_IFCHR 0x2000 -#define IBCS2_S_IFDIR 0x4000 -#define IBCS2_S_IFBLK 0x6000 -#define IBCS2_S_IFREG 0x8000 -#define IBCS2_S_IFSOCK 0xc000 - -#define IBCS2_S_IFNAM 0x5000 -#define IBCS2_S_IFLNK 0xa000 - -#define IBCS2_S_ISUID 0x0800 -#define IBCS2_S_ISGID 0x0400 -#define IBCS2_S_ISVTX 0x0200 - -#define IBCS2_S_IRWXU 0x01c0 -#define IBCS2_S_IRUSR 0x0100 -#define IBCS2_S_IWUSR 0x0080 -#define IBCS2_S_IXUSR 0x0040 -#define IBCS2_S_IRWXG 0x0038 -#define IBCS2_S_IRGRP 0x0020 -#define IBCS2_S_IWGRP 0x000f -#define IBCS2_S_IXGRP 0x0008 -#define IBCS2_S_IRWXO 0x0007 -#define IBCS2_S_IROTH 0x0004 -#define IBCS2_S_IWOTH 0x0002 -#define IBCS2_S_IXOTH 0x0001 - -#define IBCS2_S_ISFIFO(mode) (((mode) & IBCS2_S_IFMT) == IBCS2_S_IFIFO) -#define IBCS2_S_ISCHR(mode) (((mode) & IBCS2_S_IFMT) == IBCS2_S_IFCHR) -#define IBCS2_S_ISDIR(mode) (((mode) & IBCS2_S_IFMT) == IBCS2_S_IFDIR) -#define IBCS2_S_ISBLK(mode) (((mode) & IBCS2_S_IFMT) == IBCS2_S_IFBLK) -#define IBCS2_S_ISREG(mode) (((mode) & IBCS2_S_IFMT) == IBCS2_S_IFREG) -#define IBCS2_S_ISSOCK(mode) (((mode) & IBCS2_S_IFMT) == IBCS2_S_IFSOCK) - -#endif /* _IBCS2_STAT_H */ diff --git a/sys/i386/ibcs2/ibcs2_statfs.h b/sys/i386/ibcs2/ibcs2_statfs.h deleted file mode 100644 index d6e0100c1eb9..000000000000 --- a/sys/i386/ibcs2/ibcs2_statfs.h +++ /dev/null @@ -1,48 +0,0 @@ -/* $NetBSD: ibcs2_statfs.h,v 1.2 1994/10/26 02:53:06 cgd Exp $ */ - -/* - * Copyright (c) 1994 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_STATFS_H -#define _IBCS2_STATFS_H - -struct ibcs2_statfs { - short f_fstyp; - long f_bsize; - long f_frsize; - long f_blocks; - long f_bfree; - long f_files; - long f_ffree; - char f_fname[6]; - char f_fpack[6]; -}; - -#endif /* _IBCS2_STATFS_H */ diff --git a/sys/i386/ibcs2/ibcs2_stropts.h b/sys/i386/ibcs2/ibcs2_stropts.h deleted file mode 100644 index 4d26e7358265..000000000000 --- a/sys/i386/ibcs2/ibcs2_stropts.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * ibcs2_stropts.h - * Copyright (c) 1995 Scott Bartram - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_STROPTS_H -#define _IBCS2_STROPTS_H - -#define IBCS2_STR ('S'<<8) -#define IBCS2_I_NREAD (IBCS2_STR|01) -#define IBCS2_I_PUSH (IBCS2_STR|02) -#define IBCS2_I_POP (IBCS2_STR|03) -#define IBCS2_I_LOOK (IBCS2_STR|04) -#define IBCS2_I_FLUSH (IBCS2_STR|05) -#define IBCS2_I_SRDOPT (IBCS2_STR|06) -#define IBCS2_I_GRDOPT (IBCS2_STR|07) -#define IBCS2_I_STR (IBCS2_STR|010) -#define IBCS2_I_SETSIG (IBCS2_STR|011) -#define IBCS2_I_GETSIG (IBCS2_STR|012) -#define IBCS2_I_FIND (IBCS2_STR|013) -#define IBCS2_I_LINK (IBCS2_STR|014) -#define IBCS2_I_UNLINK (IBCS2_STR|015) -#define IBCS2_I_PEEK (IBCS2_STR|017) -#define IBCS2_I_FDINSERT (IBCS2_STR|020) -#define IBCS2_I_SENDFD (IBCS2_STR|021) -#define IBCS2_I_RECVFD (IBCS2_STR|022) - -#endif /* _IBCS2_STROPTS_H */ diff --git a/sys/i386/ibcs2/ibcs2_syscall.h b/sys/i386/ibcs2/ibcs2_syscall.h deleted file mode 100644 index f02ad4242204..000000000000 --- a/sys/i386/ibcs2/ibcs2_syscall.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * System call numbers. - * - * DO NOT EDIT-- this file is automatically generated. - * created from NetBSD: syscalls.master,v 1.4 1995/03/14 15:12:52 scottb Exp - */ - -#define IBCS2_SYS_syscall 0 -#define IBCS2_SYS_exit 1 -#define IBCS2_SYS_fork 2 -#define IBCS2_SYS_ibcs2_read 3 -#define IBCS2_SYS_write 4 -#define IBCS2_SYS_ibcs2_open 5 -#define IBCS2_SYS_close 6 -#define IBCS2_SYS_ibcs2_waitsys 7 -#define IBCS2_SYS_ibcs2_creat 8 -#define IBCS2_SYS_link 9 -#define IBCS2_SYS_ibcs2_unlink 10 -#define IBCS2_SYS_ibcs2_execv 11 -#define IBCS2_SYS_ibcs2_chdir 12 -#define IBCS2_SYS_ibcs2_time 13 -#define IBCS2_SYS_ibcs2_mknod 14 -#define IBCS2_SYS_ibcs2_chmod 15 -#define IBCS2_SYS_ibcs2_chown 16 -#define IBCS2_SYS_obreak 17 -#define IBCS2_SYS_ibcs2_stat 18 -#define IBCS2_SYS_compat_43_lseek 19 -#define IBCS2_SYS_getpid 20 -#define IBCS2_SYS_ibcs2_mount 21 -#define IBCS2_SYS_ibcs2_umount 22 -#define IBCS2_SYS_ibcs2_setuid 23 -#define IBCS2_SYS_getuid 24 -#define IBCS2_SYS_ibcs2_stime 25 -#define IBCS2_SYS_ibcs2_alarm 27 -#define IBCS2_SYS_ibcs2_fstat 28 -#define IBCS2_SYS_ibcs2_pause 29 -#define IBCS2_SYS_ibcs2_utime 30 -#define IBCS2_SYS_ibcs2_access 33 -#define IBCS2_SYS_ibcs2_nice 34 -#define IBCS2_SYS_ibcs2_statfs 35 -#define IBCS2_SYS_sync 36 -#define IBCS2_SYS_ibcs2_kill 37 -#define IBCS2_SYS_ibcs2_fstatfs 38 -#define IBCS2_SYS_ibcs2_pgrpsys 39 -#define IBCS2_SYS_dup 41 -#define IBCS2_SYS_pipe 42 -#define IBCS2_SYS_ibcs2_times 43 -#define IBCS2_SYS_ibcs2_plock 45 -#define IBCS2_SYS_ibcs2_setgid 46 -#define IBCS2_SYS_getgid 47 -#define IBCS2_SYS_ibcs2_sigsys 48 -#define IBCS2_SYS_ibcs2_msgsys 49 -#define IBCS2_SYS_ibcs2_shmsys 52 -#define IBCS2_SYS_ibcs2_semsys 53 -#define IBCS2_SYS_ibcs2_ioctl 54 -#define IBCS2_SYS_ibcs2_uadmin 55 -#define IBCS2_SYS_ibcs2_utssys 57 -#define IBCS2_SYS_ibcs2_execve 59 -#define IBCS2_SYS_umask 60 -#define IBCS2_SYS_chroot 61 -#define IBCS2_SYS_ibcs2_fcntl 62 -#define IBCS2_SYS_ibcs2_ulimit 63 - /* 70 is obsolete rfs_advfs */ - /* 71 is obsolete rfs_unadvfs */ - /* 72 is obsolete rfs_rmount */ - /* 73 is obsolete rfs_rumount */ - /* 74 is obsolete rfs_rfstart */ - /* 75 is obsolete rfs_sigret */ - /* 76 is obsolete rfs_rdebug */ - /* 77 is obsolete rfs_rfstop */ -#define IBCS2_SYS_ibcs2_rmdir 79 -#define IBCS2_SYS_ibcs2_mkdir 80 -#define IBCS2_SYS_ibcs2_getdents 81 -#define IBCS2_SYS_ibcs2_sysfs 84 -#define IBCS2_SYS_ibcs2_getmsg 85 -#define IBCS2_SYS_ibcs2_putmsg 86 -#define IBCS2_SYS_ibcs2_poll 87 -#define IBCS2_SYS_ibcs2_symlink 90 -#define IBCS2_SYS_ibcs2_lstat 91 -#define IBCS2_SYS_ibcs2_readlink 92 -#define IBCS2_SYS_sigreturn 103 -#define IBCS2_SYS_xenix_rdchk 135 -#define IBCS2_SYS_xenix_chsize 138 -#define IBCS2_SYS_xenix_ftime 139 -#define IBCS2_SYS_xenix_nap 140 -#define IBCS2_SYS_select 164 -#define IBCS2_SYS_ibcs2_sigaction 167 -#define IBCS2_SYS_ibcs2_sigprocmask 168 -#define IBCS2_SYS_ibcs2_sigpending 169 -#define IBCS2_SYS_ibcs2_sigsuspend 170 -#define IBCS2_SYS_ibcs2_getgroups 171 -#define IBCS2_SYS_ibcs2_setgroups 172 -#define IBCS2_SYS_ibcs2_sysconf 173 -#define IBCS2_SYS_ibcs2_pathconf 174 -#define IBCS2_SYS_ibcs2_fpathconf 175 -#define IBCS2_SYS_ibcs2_rename 176 -#define IBCS2_SYS_MAXSYSCALL 177 diff --git a/sys/i386/ibcs2/ibcs2_sysent.c b/sys/i386/ibcs2/ibcs2_sysent.c deleted file mode 100644 index c7e9fb338214..000000000000 --- a/sys/i386/ibcs2/ibcs2_sysent.c +++ /dev/null @@ -1,534 +0,0 @@ -/* - * System call switch table. - * - * DO NOT EDIT-- this file is automatically generated. - * created from NetBSD: syscalls.master,v 1.4 1995/03/14 15:12:52 scottb Exp - */ - -#include <sys/param.h> -#include <compat/ibcs2/ibcs2_types.h> -#include <compat/ibcs2/ibcs2_signal.h> -#include <compat/ibcs2/ibcs2_statfs.h> -#include <sys/systm.h> -#include <sys/signal.h> -#include <sys/mount.h> -#include <sys/syscallargs.h> -#include <compat/ibcs2/ibcs2_syscallargs.h> -int nosys(); -int exit(); -int fork(); -int ibcs2_read(); -int write(); -int ibcs2_open(); -int close(); -int ibcs2_waitsys(); -int ibcs2_creat(); -int link(); -int ibcs2_unlink(); -int ibcs2_execv(); -int ibcs2_chdir(); -int ibcs2_time(); -int ibcs2_mknod(); -int ibcs2_chmod(); -int ibcs2_chown(); -int obreak(); -int ibcs2_stat(); -int compat_43_lseek(); -int getpid(); -int ibcs2_mount(); -int ibcs2_umount(); -int ibcs2_setuid(); -int getuid(); -int ibcs2_stime(); -int ibcs2_alarm(); -int ibcs2_fstat(); -int ibcs2_pause(); -int ibcs2_utime(); -int ibcs2_access(); -int ibcs2_nice(); -int ibcs2_statfs(); -int sync(); -int ibcs2_kill(); -int ibcs2_fstatfs(); -int ibcs2_pgrpsys(); -int dup(); -int pipe(); -int ibcs2_times(); -int ibcs2_plock(); -int ibcs2_setgid(); -int getgid(); -int ibcs2_sigsys(); -#ifdef SYSVMSG -int ibcs2_msgsys(); -#else -#endif -#ifdef SYSVSHM -int ibcs2_shmsys(); -#else -#endif -#ifdef SYSVSEM -int ibcs2_semsys(); -#else -#endif -int ibcs2_ioctl(); -int ibcs2_uadmin(); -int ibcs2_utssys(); -int ibcs2_execve(); -int umask(); -int chroot(); -int ibcs2_fcntl(); -int ibcs2_ulimit(); -int ibcs2_rmdir(); -int ibcs2_mkdir(); -int ibcs2_getdents(); -int ibcs2_sysfs(); -int ibcs2_getmsg(); -int ibcs2_putmsg(); -int ibcs2_poll(); -int ibcs2_symlink(); -int ibcs2_lstat(); -int ibcs2_readlink(); -int sigreturn(); -int xenix_rdchk(); -int xenix_chsize(); -int xenix_ftime(); -int xenix_nap(); -int select(); -int ibcs2_sigaction(); -int ibcs2_sigprocmask(); -int ibcs2_sigpending(); -int ibcs2_sigsuspend(); -int ibcs2_getgroups(); -int ibcs2_setgroups(); -int ibcs2_sysconf(); -int ibcs2_pathconf(); -int ibcs2_fpathconf(); -int ibcs2_rename(); - -#ifdef COMPAT_43 -#define compat_43(func) __CONCAT(compat_43_,func) - -#ifdef SYSVMSG -#else -#endif -#ifdef SYSVSHM -#else -#endif -#ifdef SYSVSEM -#else -#endif - -#else /* COMPAT_43 */ -#define compat_43(func) nosys -#endif /* COMPAT_43 */ - - -#ifdef COMPAT_09 -#define compat_09(func) __CONCAT(compat_09_,func) - -#ifdef SYSVMSG -#else -#endif -#ifdef SYSVSHM -#else -#endif -#ifdef SYSVSEM -#else -#endif - -#else /* COMPAT_09 */ -#define compat_09(func) nosys -#endif /* COMPAT_09 */ - - -#ifdef COMPAT_10 -#define compat_10(func) __CONCAT(compat_10_,func) - -#ifdef SYSVMSG -#else -#endif -#ifdef SYSVSHM -#else -#endif -#ifdef SYSVSEM -#else -#endif - -#else /* COMPAT_10 */ -#define compat_10(func) nosys -#endif /* COMPAT_10 */ - -#define s(type) sizeof(type) - -struct sysent ibcs2_sysent[] = { - { 0, 0, - nosys }, /* 0 = syscall */ - { 1, s(struct exit_args), - exit }, /* 1 = exit */ - { 0, 0, - fork }, /* 2 = fork */ - { 3, s(struct ibcs2_read_args), - ibcs2_read }, /* 3 = ibcs2_read */ - { 3, s(struct write_args), - write }, /* 4 = write */ - { 3, s(struct ibcs2_open_args), - ibcs2_open }, /* 5 = ibcs2_open */ - { 1, s(struct close_args), - close }, /* 6 = close */ - { 3, s(struct ibcs2_waitsys_args), - ibcs2_waitsys }, /* 7 = ibcs2_waitsys */ - { 2, s(struct ibcs2_creat_args), - ibcs2_creat }, /* 8 = ibcs2_creat */ - { 2, s(struct link_args), - link }, /* 9 = link */ - { 1, s(struct ibcs2_unlink_args), - ibcs2_unlink }, /* 10 = ibcs2_unlink */ - { 2, s(struct ibcs2_execv_args), - ibcs2_execv }, /* 11 = ibcs2_execv */ - { 1, s(struct ibcs2_chdir_args), - ibcs2_chdir }, /* 12 = ibcs2_chdir */ - { 1, s(struct ibcs2_time_args), - ibcs2_time }, /* 13 = ibcs2_time */ - { 3, s(struct ibcs2_mknod_args), - ibcs2_mknod }, /* 14 = ibcs2_mknod */ - { 2, s(struct ibcs2_chmod_args), - ibcs2_chmod }, /* 15 = ibcs2_chmod */ - { 3, s(struct ibcs2_chown_args), - ibcs2_chown }, /* 16 = ibcs2_chown */ - { 1, s(struct obreak_args), - obreak }, /* 17 = obreak */ - { 2, s(struct ibcs2_stat_args), - ibcs2_stat }, /* 18 = ibcs2_stat */ - { 3, s(struct compat_43_lseek_args), - compat_43_lseek }, /* 19 = compat_43_lseek */ - { 0, 0, - getpid }, /* 20 = getpid */ - { 6, s(struct ibcs2_mount_args), - ibcs2_mount }, /* 21 = ibcs2_mount */ - { 1, s(struct ibcs2_umount_args), - ibcs2_umount }, /* 22 = ibcs2_umount */ - { 1, s(struct ibcs2_setuid_args), - ibcs2_setuid }, /* 23 = ibcs2_setuid */ - { 0, 0, - getuid }, /* 24 = getuid */ - { 1, s(struct ibcs2_stime_args), - ibcs2_stime }, /* 25 = ibcs2_stime */ - { 0, 0, - nosys }, /* 26 = unimplemented ibcs2_ptrace */ - { 1, s(struct ibcs2_alarm_args), - ibcs2_alarm }, /* 27 = ibcs2_alarm */ - { 2, s(struct ibcs2_fstat_args), - ibcs2_fstat }, /* 28 = ibcs2_fstat */ - { 0, 0, - ibcs2_pause }, /* 29 = ibcs2_pause */ - { 2, s(struct ibcs2_utime_args), - ibcs2_utime }, /* 30 = ibcs2_utime */ - { 0, 0, - nosys }, /* 31 = unimplemented was stty */ - { 0, 0, - nosys }, /* 32 = unimplemented was gtty */ - { 2, s(struct ibcs2_access_args), - ibcs2_access }, /* 33 = ibcs2_access */ - { 1, s(struct ibcs2_nice_args), - ibcs2_nice }, /* 34 = ibcs2_nice */ - { 4, s(struct ibcs2_statfs_args), - ibcs2_statfs }, /* 35 = ibcs2_statfs */ - { 0, 0, - sync }, /* 36 = sync */ - { 2, s(struct ibcs2_kill_args), - ibcs2_kill }, /* 37 = ibcs2_kill */ - { 4, s(struct ibcs2_fstatfs_args), - ibcs2_fstatfs }, /* 38 = ibcs2_fstatfs */ - { 4, s(struct ibcs2_pgrpsys_args), - ibcs2_pgrpsys }, /* 39 = ibcs2_pgrpsys */ - { 0, 0, - nosys }, /* 40 = unimplemented ibcs2_xenix */ - { 1, s(struct dup_args), - dup }, /* 41 = dup */ - { 0, 0, - pipe }, /* 42 = pipe */ - { 1, s(struct ibcs2_times_args), - ibcs2_times }, /* 43 = ibcs2_times */ - { 0, 0, - nosys }, /* 44 = unimplemented profil */ - { 1, s(struct ibcs2_plock_args), - ibcs2_plock }, /* 45 = ibcs2_plock */ - { 1, s(struct ibcs2_setgid_args), - ibcs2_setgid }, /* 46 = ibcs2_setgid */ - { 0, 0, - getgid }, /* 47 = getgid */ - { 2, s(struct ibcs2_sigsys_args), - ibcs2_sigsys }, /* 48 = ibcs2_sigsys */ -#ifdef SYSVMSG - { 6, s(struct ibcs2_msgsys_args), - ibcs2_msgsys }, /* 49 = ibcs2_msgsys */ -#else - { 0, 0, - nosys }, /* 49 = unimplemented nosys */ -#endif - { 0, 0, - nosys }, /* 50 = unimplemented ibcs2_sys3b */ - { 0, 0, - nosys }, /* 51 = unimplemented ibcs2_acct */ -#ifdef SYSVSHM - { 4, s(struct ibcs2_shmsys_args), - ibcs2_shmsys }, /* 52 = ibcs2_shmsys */ -#else - { 0, 0, - nosys }, /* 52 = unimplemented nosys */ -#endif -#ifdef SYSVSEM - { 5, s(struct ibcs2_semsys_args), - ibcs2_semsys }, /* 53 = ibcs2_semsys */ -#else - { 0, 0, - nosys }, /* 53 = unimplemented nosys */ -#endif - { 3, s(struct ibcs2_ioctl_args), - ibcs2_ioctl }, /* 54 = ibcs2_ioctl */ - { 3, s(struct ibcs2_uadmin_args), - ibcs2_uadmin }, /* 55 = ibcs2_uadmin */ - { 0, 0, - nosys }, /* 56 = unimplemented nosys */ - { 3, s(struct ibcs2_utssys_args), - ibcs2_utssys }, /* 57 = ibcs2_utssys */ - { 0, 0, - nosys }, /* 58 = unimplemented nosys */ - { 3, s(struct ibcs2_execve_args), - ibcs2_execve }, /* 59 = ibcs2_execve */ - { 1, s(struct umask_args), - umask }, /* 60 = umask */ - { 1, s(struct chroot_args), - chroot }, /* 61 = chroot */ - { 3, s(struct ibcs2_fcntl_args), - ibcs2_fcntl }, /* 62 = ibcs2_fcntl */ - { 2, s(struct ibcs2_ulimit_args), - ibcs2_ulimit }, /* 63 = ibcs2_ulimit */ - { 0, 0, - nosys }, /* 64 = unimplemented reserved for unix/pc */ - { 0, 0, - nosys }, /* 65 = unimplemented reserved for unix/pc */ - { 0, 0, - nosys }, /* 66 = unimplemented reserved for unix/pc */ - { 0, 0, - nosys }, /* 67 = unimplemented reserved for unix/pc */ - { 0, 0, - nosys }, /* 68 = unimplemented reserved for unix/pc */ - { 0, 0, - nosys }, /* 69 = unimplemented reserved for unix/pc */ - { 0, 0, - nosys }, /* 70 = obsolete rfs_advfs */ - { 0, 0, - nosys }, /* 71 = obsolete rfs_unadvfs */ - { 0, 0, - nosys }, /* 72 = obsolete rfs_rmount */ - { 0, 0, - nosys }, /* 73 = obsolete rfs_rumount */ - { 0, 0, - nosys }, /* 74 = obsolete rfs_rfstart */ - { 0, 0, - nosys }, /* 75 = obsolete rfs_sigret */ - { 0, 0, - nosys }, /* 76 = obsolete rfs_rdebug */ - { 0, 0, - nosys }, /* 77 = obsolete rfs_rfstop */ - { 0, 0, - nosys }, /* 78 = unimplemented rfs_rfsys */ - { 1, s(struct ibcs2_rmdir_args), - ibcs2_rmdir }, /* 79 = ibcs2_rmdir */ - { 2, s(struct ibcs2_mkdir_args), - ibcs2_mkdir }, /* 80 = ibcs2_mkdir */ - { 3, s(struct ibcs2_getdents_args), - ibcs2_getdents }, /* 81 = ibcs2_getdents */ - { 0, 0, - nosys }, /* 82 = unimplemented nosys */ - { 0, 0, - nosys }, /* 83 = unimplemented nosys */ - { 3, s(struct ibcs2_sysfs_args), - ibcs2_sysfs }, /* 84 = ibcs2_sysfs */ - { 4, s(struct ibcs2_getmsg_args), - ibcs2_getmsg }, /* 85 = ibcs2_getmsg */ - { 4, s(struct ibcs2_putmsg_args), - ibcs2_putmsg }, /* 86 = ibcs2_putmsg */ - { 3, s(struct ibcs2_poll_args), - ibcs2_poll }, /* 87 = ibcs2_poll */ - { 0, 0, - nosys }, /* 88 = unimplemented nosys */ - { 0, 0, - nosys }, /* 89 = unimplemented nosys */ - { 2, s(struct ibcs2_symlink_args), - ibcs2_symlink }, /* 90 = ibcs2_symlink */ - { 2, s(struct ibcs2_lstat_args), - ibcs2_lstat }, /* 91 = ibcs2_lstat */ - { 3, s(struct ibcs2_readlink_args), - ibcs2_readlink }, /* 92 = ibcs2_readlink */ - { 0, 0, - nosys }, /* 93 = unimplemented nosys */ - { 0, 0, - nosys }, /* 94 = unimplemented nosys */ - { 0, 0, - nosys }, /* 95 = unimplemented nosys */ - { 0, 0, - nosys }, /* 96 = unimplemented nosys */ - { 0, 0, - nosys }, /* 97 = unimplemented nosys */ - { 0, 0, - nosys }, /* 98 = unimplemented nosys */ - { 0, 0, - nosys }, /* 99 = unimplemented nosys */ - { 0, 0, - nosys }, /* 100 = unimplemented nosys */ - { 0, 0, - nosys }, /* 101 = unimplemented nosys */ - { 0, 0, - nosys }, /* 102 = unimplemented nosys */ - { 1, s(struct sigreturn_args), - sigreturn }, /* 103 = sigreturn */ - { 0, 0, - nosys }, /* 104 = unimplemented nosys */ - { 0, 0, - nosys }, /* 105 = unimplemented nosys */ - { 0, 0, - nosys }, /* 106 = unimplemented nosys */ - { 0, 0, - nosys }, /* 107 = unimplemented nosys */ - { 0, 0, - nosys }, /* 108 = unimplemented nosys */ - { 0, 0, - nosys }, /* 109 = unimplemented nosys */ - { 0, 0, - nosys }, /* 110 = unimplemented nosys */ - { 0, 0, - nosys }, /* 111 = unimplemented nosys */ - { 0, 0, - nosys }, /* 112 = unimplemented nosys */ - { 0, 0, - nosys }, /* 113 = unimplemented nosys */ - { 0, 0, - nosys }, /* 114 = unimplemented nosys */ - { 0, 0, - nosys }, /* 115 = unimplemented nosys */ - { 0, 0, - nosys }, /* 116 = unimplemented nosys */ - { 0, 0, - nosys }, /* 117 = unimplemented nosys */ - { 0, 0, - nosys }, /* 118 = unimplemented nosys */ - { 0, 0, - nosys }, /* 119 = unimplemented nosys */ - { 0, 0, - nosys }, /* 120 = unimplemented nosys */ - { 0, 0, - nosys }, /* 121 = unimplemented nosys */ - { 0, 0, - nosys }, /* 122 = unimplemented nosys */ - { 0, 0, - nosys }, /* 123 = unimplemented nosys */ - { 0, 0, - nosys }, /* 124 = unimplemented nosys */ - { 0, 0, - nosys }, /* 125 = unimplemented nosys */ - { 0, 0, - nosys }, /* 126 = unimplemented nosys */ - { 0, 0, - nosys }, /* 127 = unimplemented nosys */ - { 0, 0, - nosys }, /* 128 = unimplemented nosys */ - { 0, 0, - nosys }, /* 129 = unimplemented xenix_xlocking */ - { 0, 0, - nosys }, /* 130 = unimplemented xenix_creatsem */ - { 0, 0, - nosys }, /* 131 = unimplemented xenix_opensem */ - { 0, 0, - nosys }, /* 132 = unimplemented xenix_sigsem */ - { 0, 0, - nosys }, /* 133 = unimplemented xenix_waitsem */ - { 0, 0, - nosys }, /* 134 = unimplemented xenix_nbwaitsem */ - { 1, s(struct xenix_rdchk_args), - xenix_rdchk }, /* 135 = xenix_rdchk */ - { 0, 0, - nosys }, /* 136 = unimplemented nosys */ - { 0, 0, - nosys }, /* 137 = unimplemented nosys */ - { 2, s(struct xenix_chsize_args), - xenix_chsize }, /* 138 = xenix_chsize */ - { 1, s(struct xenix_ftime_args), - xenix_ftime }, /* 139 = xenix_ftime */ - { 1, s(struct xenix_nap_args), - xenix_nap }, /* 140 = xenix_nap */ - { 0, 0, - nosys }, /* 141 = unimplemented xenix_sdget */ - { 0, 0, - nosys }, /* 142 = unimplemented xenix_sdfree */ - { 0, 0, - nosys }, /* 143 = unimplemented xenix_sdenter */ - { 0, 0, - nosys }, /* 144 = unimplemented xenix_sdleave */ - { 0, 0, - nosys }, /* 145 = unimplemented xenix_sdgetv */ - { 0, 0, - nosys }, /* 146 = unimplemented xenix_sdwaitv */ - { 0, 0, - nosys }, /* 147 = unimplemented nosys */ - { 0, 0, - nosys }, /* 148 = unimplemented nosys */ - { 0, 0, - nosys }, /* 149 = unimplemented nosys */ - { 0, 0, - nosys }, /* 150 = unimplemented nosys */ - { 0, 0, - nosys }, /* 151 = unimplemented nosys */ - { 0, 0, - nosys }, /* 152 = unimplemented nosys */ - { 0, 0, - nosys }, /* 153 = unimplemented nosys */ - { 0, 0, - nosys }, /* 154 = unimplemented nosys */ - { 0, 0, - nosys }, /* 155 = unimplemented nosys */ - { 0, 0, - nosys }, /* 156 = unimplemented nosys */ - { 0, 0, - nosys }, /* 157 = unimplemented nosys */ - { 0, 0, - nosys }, /* 158 = unimplemented nosys */ - { 0, 0, - nosys }, /* 159 = unimplemented nosys */ - { 0, 0, - nosys }, /* 160 = unimplemented xenix_proctl */ - { 0, 0, - nosys }, /* 161 = unimplemented xenix_execseg */ - { 0, 0, - nosys }, /* 162 = unimplemented xenix_unexecseg */ - { 0, 0, - nosys }, /* 163 = unimplemented nosys */ - { 5, s(struct select_args), - select }, /* 164 = select */ - { 0, 0, - nosys }, /* 165 = unimplemented xenix_eaccess */ - { 0, 0, - nosys }, /* 166 = unimplemented xenix_paccess */ - { 3, s(struct ibcs2_sigaction_args), - ibcs2_sigaction }, /* 167 = ibcs2_sigaction */ - { 3, s(struct ibcs2_sigprocmask_args), - ibcs2_sigprocmask }, /* 168 = ibcs2_sigprocmask */ - { 1, s(struct ibcs2_sigpending_args), - ibcs2_sigpending }, /* 169 = ibcs2_sigpending */ - { 1, s(struct ibcs2_sigsuspend_args), - ibcs2_sigsuspend }, /* 170 = ibcs2_sigsuspend */ - { 2, s(struct ibcs2_getgroups_args), - ibcs2_getgroups }, /* 171 = ibcs2_getgroups */ - { 2, s(struct ibcs2_setgroups_args), - ibcs2_setgroups }, /* 172 = ibcs2_setgroups */ - { 1, s(struct ibcs2_sysconf_args), - ibcs2_sysconf }, /* 173 = ibcs2_sysconf */ - { 2, s(struct ibcs2_pathconf_args), - ibcs2_pathconf }, /* 174 = ibcs2_pathconf */ - { 2, s(struct ibcs2_fpathconf_args), - ibcs2_fpathconf }, /* 175 = ibcs2_fpathconf */ - { 2, s(struct ibcs2_rename_args), - ibcs2_rename }, /* 176 = ibcs2_rename */ -}; - diff --git a/sys/i386/ibcs2/ibcs2_termios.h b/sys/i386/ibcs2/ibcs2_termios.h deleted file mode 100644 index 35602cf999d9..000000000000 --- a/sys/i386/ibcs2/ibcs2_termios.h +++ /dev/null @@ -1,235 +0,0 @@ -/* $NetBSD: ibcs2_termios.h,v 1.3 1994/10/26 02:53:07 cgd Exp $ */ - -/* - * Copyright (c) 1994 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_TERMIOS_H -#define _IBCS2_TERMIOS_H 1 - -#include <compat/ibcs2/ibcs2_types.h> - -#define IBCS2_NCC 8 -#define IBCS2_NCCS 13 - -typedef u_short ibcs2_tcflag_t; -typedef u_char ibcs2_cc_t; -typedef u_long ibcs2_speed_t; - -struct ibcs2_termio { - u_short c_iflag; - u_short c_oflag; - u_short c_cflag; - u_short c_lflag; - char c_line; - u_char c_cc[IBCS2_NCC]; -}; - -struct ibcs2_termios { - ibcs2_tcflag_t c_iflag; - ibcs2_tcflag_t c_oflag; - ibcs2_tcflag_t c_cflag; - ibcs2_tcflag_t c_lflag; - char c_line; - ibcs2_cc_t c_cc[IBCS2_NCCS]; - char c_ispeed; - char c_ospeed; -}; - -#define IBCS2_VINTR 0 -#define IBCS2_VQUIT 1 -#define IBCS2_VERASE 2 -#define IBCS2_VKILL 3 -#define IBCS2_VEOF 4 -#define IBCS2_VEOL 5 -#define IBCS2_VEOL2 6 -#define IBCS2_VMIN 4 -#define IBCS2_VTIME 5 -#define IBCS2_VSWTCH 7 -#define IBCS2_VSUSP 10 -#define IBCS2_VSTART 11 -#define IBCS2_VSTOP 12 - -#define IBCS2_CNUL 0 -#define IBCS2_CDEL 0377 -#define IBCS2_CESC '\\' -#define IBCS2_CINTR 0177 -#define IBCS2_CQUIT 034 -#define IBCS2_CERASE '#' -#define IBCS2_CKILL '@' -#define IBCS2_CSTART 021 -#define IBCS2_CSTOP 023 -#define IBCS2_CSWTCH 032 -#define IBCS2_CNSWTCH 0 -#define IBCS2_CSUSP 032 - -#define IBCS2_IGNBRK 0000001 -#define IBCS2_BRKINT 0000002 -#define IBCS2_IGNPAR 0000004 -#define IBCS2_PARMRK 0000010 -#define IBCS2_INPCK 0000020 -#define IBCS2_ISTRIP 0000040 -#define IBCS2_INLCR 0000100 -#define IBCS2_IGNCR 0000200 -#define IBCS2_ICRNL 0000400 -#define IBCS2_IUCLC 0001000 -#define IBCS2_IXON 0002000 -#define IBCS2_IXANY 0004000 -#define IBCS2_IXOFF 0010000 -#define IBCS2_IMAXBEL 0020000 -#define IBCS2_DOSMODE 0100000 - -#define IBCS2_OPOST 0000001 -#define IBCS2_OLCUC 0000002 -#define IBCS2_ONLCR 0000004 -#define IBCS2_OCRNL 0000010 -#define IBCS2_ONOCR 0000020 -#define IBCS2_ONLRET 0000040 -#define IBCS2_OFILL 0000100 -#define IBCS2_OFDEL 0000200 -#define IBCS2_NLDLY 0000400 -#define IBCS2_NL0 0000000 -#define IBCS2_NL1 0000400 -#define IBCS2_CRDLY 0003000 -#define IBCS2_CR0 0000000 -#define IBCS2_CR1 0001000 -#define IBCS2_CR2 0002000 -#define IBCS2_CR3 0003000 -#define IBCS2_TABDLY 0014000 -#define IBCS2_TAB0 0000000 -#define IBCS2_TAB1 0004000 -#define IBCS2_TAB2 0010000 -#define IBCS2_TAB3 0014000 -#define IBCS2_BSDLY 0020000 -#define IBCS2_BS0 0000000 -#define IBCS2_BS1 0020000 -#define IBCS2_VTDLY 0040000 -#define IBCS2_VT0 0000000 -#define IBCS2_VT1 0040000 -#define IBCS2_FFDLY 0100000 -#define IBCS2_FF0 0000000 -#define IBCS2_FF1 0100000 - -#define IBCS2_CBAUD 0000017 -#define IBCS2_CSIZE 0000060 -#define IBCS2_CS5 0000000 -#define IBCS2_CS6 0000020 -#define IBCS2_CS7 0000040 -#define IBCS2_CS8 0000060 -#define IBCS2_CSTOPB 0000100 -#define IBCS2_CREAD 0000200 -#define IBCS2_PARENB 0000400 -#define IBCS2_PARODD 0001000 -#define IBCS2_HUPCL 0002000 -#define IBCS2_CLOCAL 0004000 -#define IBCS2_RCV1EN 0010000 -#define IBCS2_XMT1EN 0020000 -#define IBCS2_LOBLK 0040000 -#define IBCS2_XCLUDE 0100000 - -#define IBCS2_ISIG 0000001 -#define IBCS2_ICANON 0000002 -#define IBCS2_XCASE 0000004 -#define IBCS2_ECHO 0000010 -#define IBCS2_ECHOE 0000020 -#define IBCS2_ECHOK 0000040 -#define IBCS2_ECHONL 0000100 -#define IBCS2_NOFLSH 0000200 -#define IBCS2_IEXTEN 0000400 -#define IBCS2_TOSTOP 0001000 - -#define IBCS2_XIOC (('i'<<24)|('X'<<16)) -#define IBCS2_XCGETA (IBCS2_XIOC|1) -#define IBCS2_XCSETA (IBCS2_XIOC|2) -#define IBCS2_XCSETAW (IBCS2_XIOC|3) -#define IBCS2_XCSETAF (IBCS2_XIOC|4) - -#define IBCS2_OXIOC ('x'<<8) -#define IBCS2_OXCGETA (IBCS2_OXIOC|1) -#define IBCS2_OXCSETA (IBCS2_OXIOC|2) -#define IBCS2_OXCSETAW (IBCS2_OXIOC|3) -#define IBCS2_OXCSETAF (IBCS2_OXIOC|4) - -#define IBCS2_TIOC ('T'<<8) -#define IBCS2_TCGETA (IBCS2_TIOC|1) -#define IBCS2_TCSETA (IBCS2_TIOC|2) -#define IBCS2_TCSETAW (IBCS2_TIOC|3) -#define IBCS2_TCSETAF (IBCS2_TIOC|4) -#define IBCS2_TCSBRK (IBCS2_TIOC|5) -#define IBCS2_TCXONC (IBCS2_TIOC|6) -#define IBCS2_TCFLSH (IBCS2_TIOC|7) - -#define IBCS2_TCGETSC (IBCS2_TIOC|34) -#define IBCS2_TCSETSC (IBCS2_TIOC|35) - -#define IBCS2_TIOCSWINSZ (IBCS2_TIOC|103) -#define IBCS2_TIOCGWINSZ (IBCS2_TIOC|104) -#define IBCS2_TIOCSPGRP (IBCS2_TIOC|118) -#define IBCS2_TIOCGPGRP (IBCS2_TIOC|119) - -#define IBCS2_TCSANOW IBCS2_XCSETA -#define IBCS2_TCSADRAIN IBCS2_XCSETAW -#define IBCS2_TCSAFLUSH IBCS2_XCSETAF -#define IBCS2_TCSADFLUSH IBCS2_XCSETAF - -#define IBCS2_TCIFLUSH 0 -#define IBCS2_TCOFLUSH 1 -#define IBCS2_TCIOFLUSH 2 - -#define IBCS2_TCOOFF 0 -#define IBCS2_TCOON 1 -#define IBCS2_TCIOFF 2 -#define IBCS2_TCION 3 - -#define IBCS2_B0 0 -#define IBCS2_B50 1 -#define IBCS2_B75 2 -#define IBCS2_B110 3 -#define IBCS2_B134 4 -#define IBCS2_B150 5 -#define IBCS2_B200 6 -#define IBCS2_B300 7 -#define IBCS2_B600 8 -#define IBCS2_B1200 9 -#define IBCS2_B1800 10 -#define IBCS2_B2400 11 -#define IBCS2_B4800 12 -#define IBCS2_B9600 13 -#define IBCS2_B19200 14 -#define IBCS2_B38400 15 - -struct ibcs2_winsize { - u_short ws_row; - u_short ws_col; - u_short ws_xpixel; - u_short ws_ypixel; -}; - -#endif /* _IBCS2_H_ */ - diff --git a/sys/i386/ibcs2/ibcs2_time.h b/sys/i386/ibcs2/ibcs2_time.h deleted file mode 100644 index a3b669b6ae3f..000000000000 --- a/sys/i386/ibcs2/ibcs2_time.h +++ /dev/null @@ -1,50 +0,0 @@ -/* $NetBSD: ibcs2_time.h,v 1.2 1994/10/26 02:53:08 cgd Exp $ */ - -/* - * Copyright (c) 1994 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_TIME_H -#define _IBCS2_TIME_H - -#include <compat/ibcs2/ibcs2_types.h> - -struct ibcs2_tm { - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; -}; - -#endif /* _IBCS2_TIME_H */ diff --git a/sys/i386/ibcs2/ibcs2_types.h b/sys/i386/ibcs2/ibcs2_types.h deleted file mode 100644 index 305a1fc6f440..000000000000 --- a/sys/i386/ibcs2/ibcs2_types.h +++ /dev/null @@ -1,54 +0,0 @@ -/* $NetBSD: ibcs2_types.h,v 1.5 1995/08/14 01:11:54 mycroft Exp $ */ - -/* - * Copyright (c) 1994 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_TYPES_H -#define _IBCS2_TYPES_H - -typedef unsigned char ibcs2_uchar_t; -typedef unsigned long ibcs2_ulong_t; - -typedef char * ibcs2_caddr_t; -typedef long ibcs2_daddr_t; -typedef long ibcs2_off_t; -typedef long ibcs2_key_t; -typedef unsigned short ibcs2_uid_t; -typedef unsigned short ibcs2_gid_t; -typedef short ibcs2_nlink_t; -typedef short ibcs2_dev_t; -typedef unsigned short ibcs2_ino_t; -typedef unsigned int ibcs2_size_t; -typedef long ibcs2_time_t; -typedef long ibcs2_clock_t; -typedef unsigned short ibcs2_mode_t; -typedef short ibcs2_pid_t; - -#endif /* _IBCS2_TYPES_H */ diff --git a/sys/i386/ibcs2/ibcs2_unistd.h b/sys/i386/ibcs2/ibcs2_unistd.h deleted file mode 100644 index 1a0dd6694128..000000000000 --- a/sys/i386/ibcs2/ibcs2_unistd.h +++ /dev/null @@ -1,75 +0,0 @@ -/* $NetBSD: ibcs2_unistd.h,v 1.2 1994/10/26 02:53:11 cgd Exp $ */ - -/* - * Copyright (c) 1994 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_UNISTD_H -#define _IBCS2_UNISTD_H - -#define IBCS2_R_OK 4 -#define IBCS2_W_OK 2 -#define IBCS2_X_OK 1 -#define IBCS2_F_OK 0 - -#define IBCS2_F_ULOCK 0 -#define IBCS2_F_LOCK 1 -#define IBCS2_F_TLOCK 2 -#define IBCS2_F_TEST 3 - -#define IBCS2_SEEK_SET 0 -#define IBCS2_SEEK_CUR 1 -#define IBCS2_SEEK_END 2 - -#define IBCS2_SC_ARG_MAX 0 -#define IBCS2_SC_CHILD_MAX 1 -#define IBCS2_SC_CLK_TCK 2 -#define IBCS2_SC_NGROUPS_MAX 3 -#define IBCS2_SC_OPEN_MAX 4 -#define IBCS2_SC_JOB_CONTROL 5 -#define IBCS2_SC_SAVED_IDS 6 -#define IBCS2_SC_VERSION 7 -#define IBCS2_SC_PASS_MAX 8 -#define IBCS2_SC_XOPEN_VERSION 9 - -#define IBCS2_PC_LINK_MAX 0 -#define IBCS2_PC_MAX_CANON 1 -#define IBCS2_PC_MAX_INPUT 2 -#define IBCS2_PC_NAME_MAX 3 -#define IBCS2_PC_PATH_MAX 4 -#define IBCS2_PC_PIPE_BUF 5 -#define IBCS2_PC_CHOWN_RESTRICTED 6 -#define IBCS2_PC_NO_TRUNC 7 -#define IBCS2_PC_VDISABLE 8 - -#define IBCS2_STDIN_FILENO 0 -#define IBCS2_STDOUT_FILENO 1 -#define IBCS2_STDERR_FILENO 2 - -#endif /* _IBCS2_UNISTD_H */ diff --git a/sys/i386/ibcs2/ibcs2_ustat.h b/sys/i386/ibcs2/ibcs2_ustat.h deleted file mode 100644 index 03c714635918..000000000000 --- a/sys/i386/ibcs2/ibcs2_ustat.h +++ /dev/null @@ -1,46 +0,0 @@ -/* $NetBSD: ibcs2_ustat.h,v 1.2 1994/10/26 02:53:13 cgd Exp $ */ - -/* - * Copyright (c) 1994 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_USTAT_H -#define _IBCS2_USTAT_H 1 - -#include <compat/ibcs2/ibcs2_types.h> - -struct ibcs2_ustat { - long f_tfree; - ibcs2_ino_t f_tinode; - char f_fname[6]; - char f_fpack[6]; -}; -#define ibcs2_ustat_len (sizeof(struct ibcs2_ustat)) - -#endif /* _IBCS2_USTAT_H */ diff --git a/sys/i386/ibcs2/ibcs2_util.c b/sys/i386/ibcs2/ibcs2_util.c deleted file mode 100644 index 69937acda294..000000000000 --- a/sys/i386/ibcs2/ibcs2_util.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 1994 Christos Zoulas - * Copyright (c) 1995 Frank van der Linden - * Copyright (c) 1995 Scott Bartram - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - * - * from: svr4_util.c,v 1.5 1995/01/22 23:44:50 christos Exp - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/namei.h> -#include <sys/proc.h> -#include <sys/file.h> -#include <sys/stat.h> -#include <sys/filedesc.h> -#include <sys/ioctl.h> -#include <sys/kernel.h> -#include <sys/malloc.h> -#include <sys/vnode.h> - -#include <compat/ibcs2/ibcs2_util.h> - -const char ibcs2_emul_path[] = "/emul/ibcs2"; - -/* - * Search an alternate path before passing pathname arguments on - * to system calls. Useful for keeping a seperate 'emulation tree'. - * - * If cflag is set, we check if an attempt can be made to create - * the named file, i.e. we check if the directory it should - * be in exists. - */ -int -ibcs2_emul_find(p, sgp, prefix, path, pbuf, cflag) - struct proc *p; - caddr_t *sgp; /* Pointer to stackgap memory */ - const char *prefix; - char *path; - char **pbuf; - int cflag; -{ - struct nameidata nd; - struct nameidata ndroot; - struct vattr vat; - struct vattr vatroot; - int error; - char *ptr, *buf, *cp; - size_t sz, len; - - buf = (char *) malloc(MAXPATHLEN, M_TEMP, M_WAITOK); - *pbuf = path; - - for (ptr = buf; (*ptr = *prefix) != '\0'; ptr++, prefix++) - continue; - - sz = MAXPATHLEN - (ptr - buf); - - /* - * If sgp is not given then the path is already in kernel space - */ - if (sgp == NULL) - error = copystr(path, ptr, sz, &len); - else - error = copyinstr(path, ptr, sz, &len); - - if (error) { - free(buf, M_TEMP); - return error; - } - - if (*ptr != '/') { - free(buf, M_TEMP); - return EINVAL; - } - - /* - * We know that there is a / somewhere in this pathname. - * Search backwards for it, to find the file's parent dir - * to see if it exists in the alternate tree. If it does, - * and we want to create a file (cflag is set). We don't - * need to worry about the root comparison in this case. - */ - - if (cflag) { - for (cp = &ptr[len] - 1; *cp != '/'; cp--); - *cp = '\0'; - - NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, p); - - if ((error = namei(&nd)) != 0) { - free(buf, M_TEMP); - return error; - } - - *cp = '/'; - } - else { - NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, p); - - if ((error = namei(&nd)) != 0) { - free(buf, M_TEMP); - return error; - } - - /* - * We now compare the vnode of the ibcs2_root to the one - * vnode asked. If they resolve to be the same, then we - * ignore the match so that the real root gets used. - * This avoids the problem of traversing "../.." to find the - * root directory and never finding it, because "/" resolves - * to the emulation root directory. This is expensive :-( - */ - /* XXX: prototype should have const here for NDINIT */ - NDINIT(&ndroot, LOOKUP, FOLLOW, UIO_SYSSPACE, - (char *) ibcs2_emul_path, p); - - if ((error = namei(&ndroot)) != 0) { - /* Cannot happen! */ - free(buf, M_TEMP); - vrele(nd.ni_vp); - return error; - } - - if ((error = VOP_GETATTR(nd.ni_vp, &vat, p->p_ucred, p)) != 0) { - goto done; - } - - if ((error = VOP_GETATTR(ndroot.ni_vp, &vatroot, p->p_ucred, p)) - != 0) { - goto done; - } - - if (vat.va_fsid == vatroot.va_fsid && - vat.va_fileid == vatroot.va_fileid) { - error = ENOENT; - goto done; - } - - } - if (sgp == NULL) - *pbuf = buf; - else { - sz = &ptr[len] - buf; - *pbuf = stackgap_alloc(sgp, sz + 1); - error = copyout(buf, *pbuf, sz); - free(buf, M_TEMP); - } - - -done: - vrele(nd.ni_vp); - if (!cflag) - vrele(ndroot.ni_vp); - return error; -} diff --git a/sys/i386/ibcs2/ibcs2_util.h b/sys/i386/ibcs2/ibcs2_util.h deleted file mode 100644 index 6aa4e8c9a503..000000000000 --- a/sys/i386/ibcs2/ibcs2_util.h +++ /dev/null @@ -1,82 +0,0 @@ - -/* - * Copyright (c) 1994 Christos Zoulas - * Copyright (c) 1995 Frank van der Linden - * Copyright (c) 1995 Scott Bartram - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - * - * from: svr4_util.h,v 1.5 1994/11/18 02:54:31 christos Exp - * from: linux_util.h,v 1.2 1995/03/05 23:23:50 fvdl Exp - */ - -/* - * This file is pretty much the same as Christos' svr4_util.h - * (for now). - */ - -#ifndef _IBCS2_UTIL_H_ -#define _IBCS2_UTIL_H_ - -#include <machine/vmparam.h> -#include <sys/exec.h> -#include <sys/cdefs.h> - -static __inline caddr_t -stackgap_init() -{ - extern char sigcode[], esigcode[]; -#define szsigcode ((caddr_t)(esigcode - sigcode)) - return STACKGAPBASE; -} - - -static __inline void * -stackgap_alloc(sgp, sz) - caddr_t *sgp; - size_t sz; -{ - void *p = (void *) *sgp; - *sgp += ALIGN(sz); - return p; -} - -#ifdef DEBUG_IBCS2 -#define DPRINTF(a) printf a; -#else -#define DPRINTF(a) -#endif - -extern const char ibcs2_emul_path[]; - -int ibcs2_emul_find __P((struct proc *, caddr_t *, const char *, char *, - char **, int)); - -#define CHECKALTEXIST(p, sgp, path) \ - ibcs2_emul_find(p, sgp, ibcs2_emul_path, path, &(path), 0) - -#define CHECKALTCREAT(p, sgp, path) \ - ibcs2_emul_find(p, sgp, ibcs2_emul_path, path, &(path), 1) - -#endif /* !_IBCS2_UTIL_H_ */ diff --git a/sys/i386/ibcs2/ibcs2_utime.h b/sys/i386/ibcs2/ibcs2_utime.h deleted file mode 100644 index 02d83150a27a..000000000000 --- a/sys/i386/ibcs2/ibcs2_utime.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 1995 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_UTIME_H -#define _IBCS2_UTIME_H - -#include <compat/ibcs2/ibcs2_types.h> - -struct ibcs2_utimbuf { - ibcs2_time_t actime; - ibcs2_time_t modtime; -}; - -#endif /* _IBCS2_UTIME_H */ diff --git a/sys/i386/ibcs2/ibcs2_utsname.h b/sys/i386/ibcs2/ibcs2_utsname.h deleted file mode 100644 index 4f2ee68f7a9b..000000000000 --- a/sys/i386/ibcs2/ibcs2_utsname.h +++ /dev/null @@ -1,45 +0,0 @@ -/* $NetBSD: ibcs2_utsname.h,v 1.2 1994/10/26 02:53:14 cgd Exp $ */ - -/* - * Copyright (c) 1994 Scott Bartram - * 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 Scott Bartram. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 _IBCS2_UTSNAME_H -#define _IBCS2_UTSNAME_H - -struct ibcs2_utsname { - char sysname[9]; - char nodename[9]; - char release[9]; - char version[9]; - char machine[9]; -}; -#define ibcs2_utsname_len (sizeof(struct ibcs2_utsname)) - -#endif /* _IBCS2_UTSNAME_H */ diff --git a/sys/i386/ibcs2/syscalls.conf b/sys/i386/ibcs2/syscalls.conf deleted file mode 100644 index 7f46f4433407..000000000000 --- a/sys/i386/ibcs2/syscalls.conf +++ /dev/null @@ -1,12 +0,0 @@ -# syscalls.conf - -sysnames="ibcs2_syscalls.c" -sysnumhdr="ibcs2_syscall.h" -syssw="ibcs2_sysent.c" -sysarghdr="ibcs2_syscallargs.h" -compatopts="compat_43 compat_09 compat_10" -libcompatopts="" - -switchname="ibcs2_sysent" -namesname="ibcs2_syscallnames" -constprefix="IBCS2_SYS_" diff --git a/sys/i386/ibcs2/syscalls.master b/sys/i386/ibcs2/syscalls.master deleted file mode 100644 index db907d72e555..000000000000 --- a/sys/i386/ibcs2/syscalls.master +++ /dev/null @@ -1,243 +0,0 @@ - $NetBSD: syscalls.master,v 1.4 1995/03/14 15:12:52 scottb Exp $ - -; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 -; System call name/number master file (or rather, slave, from IBCS2). -; Processed to created ibcs2_sysent.c, ibcs2_syscalls.c and ibcs2_syscall.h. - -; Columns: number type nargs name altname/comments -; number system call number, must be in order -; type one of STD, OBSOL, UNIMPL, STD -; nargs number of arguments -; name name of syscall routine -; altname name of system call if different -; for UNIMPL/OBSOL, name continues with comments - -#include <sys/param.h> -#include <compat/ibcs2/ibcs2_types.h> -#include <compat/ibcs2/ibcs2_signal.h> -#include <compat/ibcs2/ibcs2_statfs.h> -#include <sys/systm.h> -#include <sys/signal.h> -#include <sys/mount.h> -#include <sys/syscallargs.h> -#include <compat/ibcs2/ibcs2_syscallargs.h> - -; types: -; STD always included -; STD included on COMPAT #ifdef -; LIBSTD included on COMPAT #ifdef, and placed in syscall.h -; OBSOL obsolete, not included in system, only specifies name -; UNIMPL not implemented, placeholder only - -; #ifdef's, etc. may be included, and are copied to the output files. - -0 NOARGS { int nosys(void); } syscall -1 NOARGS { int exit(int rval); } -2 NOARGS { int fork(void); } -3 STD { int ibcs2_read(int fd, char *buf, u_int nbytes); } -4 NOARGS { int write(int fd, char *buf, u_int nbytes); } -5 STD { int ibcs2_open(char *path, int flags, int mode); } -6 NOARGS { int close(int fd); } -7 STD { int ibcs2_waitsys(int a1, int a2, int a3); } -8 STD { int ibcs2_creat(char *path, int mode); } -9 NOARGS { int link(char *path, char *link); } -10 STD { int ibcs2_unlink(char *path); } -11 STD { int ibcs2_execv(char *path, char **argp); } -12 STD { int ibcs2_chdir(char *path); } -13 STD { int ibcs2_time(ibcs2_time_t *tp); } -14 STD { int ibcs2_mknod(char* path, int mode, int dev); } -15 STD { int ibcs2_chmod(char *path, int mode); } -16 STD { int ibcs2_chown(char *path, int uid, int gid); } -17 NOARGS { int obreak(caddr_t nsize); } -18 STD { int ibcs2_stat(char* path, struct ibcs2_stat *st); } -19 NOARGS { long compat_43_lseek(int fd, long offset, \ - int whence); } -20 NOARGS { pid_t getpid(void); } -21 STD { int ibcs2_mount(char *special, char *dir, int flags, \ - int fstype, char *data, int len); } -22 STD { int ibcs2_umount(char *name); } -23 STD { int ibcs2_setuid(int uid); } -24 NOARGS { uid_t getuid(void); } -25 STD { int ibcs2_stime(long *timep); } -26 UNIMPL ibcs2_ptrace -27 STD { int ibcs2_alarm(unsigned sec); } -28 STD { int ibcs2_fstat(int fd, struct ibcs2_stat *st); } -29 STD { int ibcs2_pause(void); } -30 STD { int ibcs2_utime(char *path, \ - struct ibcs2_utimbuf *buf); } -31 UNIMPL was stty -32 UNIMPL was gtty -33 STD { int ibcs2_access(char *path, int flags); } -34 STD { int ibcs2_nice(int incr); } -35 STD { int ibcs2_statfs(char *path, \ - struct ibcs2_statfs *buf, \ - int len, int fstype); } -36 NOARGS { int sync(void); } -37 STD { int ibcs2_kill(int pid, int signo); } -38 STD { int ibcs2_fstatfs(int fd, struct ibcs2_statfs *buf, \ - int len, int fstype); } -39 STD { int ibcs2_pgrpsys(int type, caddr_t dummy, int pid, \ - int pgid); } -40 UNIMPL ibcs2_xenix -41 NOARGS { int dup(u_int fd); } -42 NOARGS { int pipe(void); } -43 STD { int ibcs2_times(struct tms *tp); } -44 UNIMPL profil -45 STD { int ibcs2_plock(int cmd); } -46 STD { int ibcs2_setgid(int gid); } -47 NOARGS { gid_t getgid(void); } -48 STD { int ibcs2_sigsys(int sig, ibcs2_sig_t fp); } -#ifdef SYSVMSG -49 STD { int ibcs2_msgsys(int which, int a2, int a3, int a4, \ - int a5, int a6); } -#else -49 UNIMPL nosys -#endif -50 UNIMPL ibcs2_sys3b -51 UNIMPL ibcs2_acct -#ifdef SYSVSHM -52 STD { int ibcs2_shmsys(int which, int a2, int a3, int a4); } -#else -52 UNIMPL nosys -#endif -#ifdef SYSVSEM -53 STD { int ibcs2_semsys(int which, int a2, int a3, int a4, \ - int a5); } -#else -53 UNIMPL nosys -#endif -54 STD { int ibcs2_ioctl(int fd, int cmd, caddr_t data); } -55 STD { int ibcs2_uadmin(int cmd, int func, caddr_t data); } -56 UNIMPL nosys -57 STD { int ibcs2_utssys(int a1, int a2, int flag); } -58 UNIMPL nosys -59 STD { int ibcs2_execve(char *path, char **argp, \ - char **envp); } -60 NOARGS { int umask(int newmask); } -61 NOARGS { int chroot(char *path); } -62 STD { int ibcs2_fcntl(int fd, int cmd, char *arg); } -63 STD { long ibcs2_ulimit(int cmd, int newlimit); } -64 UNIMPL reserved for unix/pc -65 UNIMPL reserved for unix/pc -66 UNIMPL reserved for unix/pc -67 UNIMPL reserved for unix/pc -68 UNIMPL reserved for unix/pc -69 UNIMPL reserved for unix/pc -70 OBSOL rfs_advfs -71 OBSOL rfs_unadvfs -72 OBSOL rfs_rmount -73 OBSOL rfs_rumount -74 OBSOL rfs_rfstart -75 OBSOL rfs_sigret -76 OBSOL rfs_rdebug -77 OBSOL rfs_rfstop -78 UNIMPL rfs_rfsys -79 STD { int ibcs2_rmdir(char *path); } -80 STD { int ibcs2_mkdir(char *path, int mode); } -81 STD { int ibcs2_getdents(int fd, char *buf, int nbytes); } -82 UNIMPL nosys -83 UNIMPL nosys -84 STD { int ibcs2_sysfs(int cmd, caddr_t d1, char *buf); } -85 STD { int ibcs2_getmsg(int fd, struct ibcs2_stropts *ctl, \ - struct ibcs2_stropts *dat, \ - int *flags); } -86 STD { int ibcs2_putmsg(int fd, struct ibcs2_stropts *ctl, \ - struct ibcs2_stropts *dat, \ - int flags); } -87 STD { int ibcs2_poll(struct ibcs2_pollfd *fds, long nfds, \ - int timeout); } -88 UNIMPL nosys -89 UNIMPL nosys -90 STD { int ibcs2_symlink(char *path, char *link); } -91 STD { int ibcs2_lstat(char *path, struct ibcs2_stat *st); } -92 STD { int ibcs2_readlink(char *path, char *buf, int count); } -93 UNIMPL nosys -94 UNIMPL nosys -95 UNIMPL nosys -96 UNIMPL nosys -97 UNIMPL nosys -98 UNIMPL nosys -99 UNIMPL nosys -100 UNIMPL nosys -101 UNIMPL nosys -102 UNIMPL nosys -103 NOARGS { int sigreturn(struct sigcontext *sigcntxp); } -104 UNIMPL nosys -105 UNIMPL nosys -106 UNIMPL nosys -107 UNIMPL nosys -108 UNIMPL nosys -109 UNIMPL nosys -110 UNIMPL nosys -111 UNIMPL nosys -112 UNIMPL nosys -113 UNIMPL nosys -114 UNIMPL nosys -115 UNIMPL nosys -116 UNIMPL nosys -117 UNIMPL nosys -118 UNIMPL nosys -119 UNIMPL nosys -120 UNIMPL nosys -121 UNIMPL nosys -122 UNIMPL nosys -123 UNIMPL nosys -124 UNIMPL nosys -125 UNIMPL nosys -126 UNIMPL nosys -127 UNIMPL nosys -128 UNIMPL nosys -129 UNIMPL xenix_xlocking -130 UNIMPL xenix_creatsem -131 UNIMPL xenix_opensem -132 UNIMPL xenix_sigsem -133 UNIMPL xenix_waitsem -134 UNIMPL xenix_nbwaitsem -135 STD { int xenix_rdchk(int fd); } -136 UNIMPL nosys -137 UNIMPL nosys -138 STD { int xenix_chsize(int fd, long size); } -139 STD { int xenix_ftime(struct xenix_timeb *tp); } -140 STD { int xenix_nap(int millisec); } -141 UNIMPL xenix_sdget -142 UNIMPL xenix_sdfree -143 UNIMPL xenix_sdenter -144 UNIMPL xenix_sdleave -145 UNIMPL xenix_sdgetv -146 UNIMPL xenix_sdwaitv -147 UNIMPL nosys -148 UNIMPL nosys -149 UNIMPL nosys -150 UNIMPL nosys -151 UNIMPL nosys -152 UNIMPL nosys -153 UNIMPL nosys -154 UNIMPL nosys -155 UNIMPL nosys -156 UNIMPL nosys -157 UNIMPL nosys -158 UNIMPL nosys -159 UNIMPL nosys -160 UNIMPL xenix_proctl -161 UNIMPL xenix_execseg -162 UNIMPL xenix_unexecseg -163 UNIMPL nosys -164 NOARGS { int select(u_int nd, fd_set *in, fd_set *ou, \ - fd_set *ex, struct timeval *tv); } -165 UNIMPL xenix_eaccess -166 UNIMPL xenix_paccess -167 STD { int ibcs2_sigaction(int sig, \ - struct ibcs2_sigaction *act, \ - struct ibcs2_sigaction *oact); } -168 STD { int ibcs2_sigprocmask(int how, ibcs2_sigset_t *set, \ - ibcs2_sigset_t *oset); } -169 STD { int ibcs2_sigpending(ibcs2_sigset_t *mask); } -170 STD { int ibcs2_sigsuspend(ibcs2_sigset_t *mask); } -171 STD { int ibcs2_getgroups(int gidsetsize, \ - ibcs2_gid_t *gidset); } -172 STD { int ibcs2_setgroups(int gidsetsize, \ - ibcs2_gid_t *gidset); } -173 STD { int ibcs2_sysconf(int name); } -174 STD { int ibcs2_pathconf(char *path, int name); } -175 STD { int ibcs2_fpathconf(int fd, int name); } -176 STD { int ibcs2_rename(char *from, char *to); } diff --git a/sys/net/if_media.c b/sys/net/if_media.c deleted file mode 100644 index 1dcf18fd0556..000000000000 --- a/sys/net/if_media.c +++ /dev/null @@ -1,475 +0,0 @@ -/* $NetBSD: if_media.c,v 1.1 1997/03/17 02:55:15 thorpej Exp $ */ - -/* - * Copyright (c) 1997 - * Jonathan Stone and Jason R. Thorpe. All rights reserved. - * - * This software is derived from information provided by Matt Thomas. - * - * 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 Jonathan Stone - * and Jason R. Thorpe for the NetBSD Project. - * 4. The names of the authors may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 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. - */ - -/* - * BSD/OS-compatible network interface media selection. - * - * Where it is safe to do so, this code strays slightly from the BSD/OS - * design. Software which uses the API (device drivers, basically) - * shouldn't notice any difference. - * - * Many thanks to Matt Thomas for providing the information necessary - * to implement this interface. - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/errno.h> -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <sys/malloc.h> - -#include <net/if.h> -#include <net/if_media.h> -#include <net/netisr.h> - -/* - * Compile-time options: - * IFMEDIA_DEBUG: - * turn on implementation-level debug printfs. - * Useful for debugging newly-ported drivers. - */ - -struct ifmedia_entry *ifmedia_match __P((struct ifmedia *ifm, - int flags, int mask)); - -#ifdef IFMEDIA_DEBUG -int ifmedia_debug = 0; -static void ifmedia_printword __P((int)); -#endif - -/* - * Initialize if_media struct for a specific interface instance. - */ -void -ifmedia_init(ifm, dontcare_mask, change_callback, status_callback) - struct ifmedia *ifm; - int dontcare_mask; - ifm_change_cb_t change_callback; - ifm_stat_cb_t status_callback; -{ - - LIST_INIT(&ifm->ifm_list); - ifm->ifm_cur = NULL; - ifm->ifm_media = 0; - ifm->ifm_mask = dontcare_mask; /* IF don't-care bits */ - ifm->ifm_change = change_callback; - ifm->ifm_status = status_callback; -} - -/* - * Add a media configuration to the list of supported media - * for a specific interface instance. - */ -void -ifmedia_add(ifm, mword, data, aux) - struct ifmedia *ifm; - int mword; - int data; - void *aux; -{ - register struct ifmedia_entry *entry; - -#ifdef IFMEDIA_DEBUG - if (ifmedia_debug) { - if (ifm == NULL) { - printf("ifmedia_add: null ifm\n"); - return; - } - printf("Adding entry for "); - ifmedia_printword(mword); - } -#endif - - entry = malloc(sizeof(*entry), M_IFADDR, M_NOWAIT); - if (entry == NULL) - panic("ifmedia_add: can't malloc entry"); - - entry->ifm_media = mword; - entry->ifm_data = data; - entry->ifm_aux = aux; - - LIST_INSERT_HEAD(&ifm->ifm_list, entry, ifm_list); -} - -/* - * Add an array of media configurations to the list of - * supported media for a specific interface instance. - */ -void -ifmedia_list_add(ifm, lp, count) - struct ifmedia *ifm; - struct ifmedia_entry *lp; - int count; -{ - int i; - - for (i = 0; i < count; i++) - ifmedia_add(ifm, lp[i].ifm_media, lp[i].ifm_data, - lp[i].ifm_aux); -} - -/* - * Set the default active media. - * - * Called by device-specific code which is assumed to have already - * selected the default media in hardware. We do _not_ call the - * media-change callback. - */ -void -ifmedia_set(ifm, target) - struct ifmedia *ifm; - int target; - -{ - struct ifmedia_entry *match; - - match = ifmedia_match(ifm, target, ifm->ifm_mask); - - if (match == NULL) { - printf("ifmedia_set: no match for 0x%x/0x%x\n", - target, ~ifm->ifm_mask); - panic("ifmedia_set"); - } - ifm->ifm_cur = match; - -#ifdef IFMEDIA_DEBUG - if (ifmedia_debug) { - printf("ifmedia_set: target "); - ifmedia_printword(target); - printf("ifmedia_set: setting to "); - ifmedia_printword(ifm->ifm_cur->ifm_media); - } -#endif -} - -/* - * Device-independent media ioctl support function. - */ -int -ifmedia_ioctl(ifp, ifr, ifm, cmd) - struct ifnet *ifp; - struct ifreq *ifr; - struct ifmedia *ifm; - u_long cmd; -{ - struct ifmedia_entry *match; - struct ifmediareq *ifmr = (struct ifmediareq *) ifr; - int error = 0, sticky; - - if (ifp == NULL || ifr == NULL || ifm == NULL) - return(EINVAL); - - switch (cmd) { - - /* - * Set the current media. - */ - case SIOCSIFMEDIA: - { - struct ifmedia_entry *oldentry; - int oldmedia; - int newmedia = ifr->ifr_media; - - match = ifmedia_match(ifm, newmedia, ifm->ifm_mask); - if (match == NULL) { -#ifdef IFMEDIA_DEBUG - if (ifmedia_debug) { - printf( - "ifmedia_ioctl: no media found for 0x%x\n", - newmedia); - } -#endif - return (ENXIO); - } - - /* - * If no change, we're done. - * XXX Automedia may invole software intervention. - * Keep going in case the the connected media changed. - * Similarly, if best match changed (kernel debugger?). - */ - if ((IFM_SUBTYPE(newmedia) != IFM_AUTO) && - (newmedia == ifm->ifm_media) && - (match == ifm->ifm_cur)) - return 0; - - /* - * We found a match, now make the driver switch to it. - * Make sure to preserve our old media type in case the - * driver can't switch. - */ -#ifdef IFMEDIA_DEBUG - if (ifmedia_debug) { - printf("ifmedia_ioctl: switching %s to ", - ifp->if_xname); - ifmedia_printword(match->ifm_media); - } -#endif - oldentry = ifm->ifm_cur; - oldmedia = ifm->ifm_media; - ifm->ifm_cur = match; - ifm->ifm_media = newmedia; - error = (*ifm->ifm_change)(ifp); - if (error) { - ifm->ifm_cur = oldentry; - ifm->ifm_media = oldmedia; - } - break; - } - - /* - * Get list of available media and current media on interface. - */ - case SIOCGIFMEDIA: - { - struct ifmedia_entry *ep; - int *kptr, count; - - kptr = NULL; /* XXX gcc */ - - ifmr->ifm_active = ifmr->ifm_current = ifm->ifm_cur ? - ifm->ifm_cur->ifm_media : IFM_NONE; - ifmr->ifm_mask = ifm->ifm_mask; - ifmr->ifm_status = 0; - (*ifm->ifm_status)(ifp, ifmr); - - count = 0; - ep = ifm->ifm_list.lh_first; - - if (ifmr->ifm_count != 0) { - kptr = (int *)malloc(ifmr->ifm_count * sizeof(int), - M_TEMP, M_WAITOK); - - /* - * Get the media words from the interface's list. - */ - for (; ep != NULL && count < ifmr->ifm_count; - ep = ep->ifm_list.le_next, count++) - kptr[count] = ep->ifm_media; - - if (ep != NULL) - error = E2BIG; /* oops! */ - } - - /* - * If there are more interfaces on the list, count - * them. This allows the caller to set ifmr->ifm_count - * to 0 on the first call to know how much space to - * callocate. - */ - for (; ep != NULL; ep = ep->ifm_list.le_next) - count++; - - /* - * We do the copyout on E2BIG, because that's - * just our way of telling userland that there - * are more. This is the behavior I've observed - * under BSD/OS 3.0 - */ - sticky = error; - if ((error == 0 || error == E2BIG) && ifmr->ifm_count != 0) { - error = copyout((caddr_t)kptr, - (caddr_t)ifmr->ifm_ulist, - ifmr->ifm_count * sizeof(int)); - } - - if (error == 0) - error = sticky; - - if (ifmr->ifm_count != 0) - free(kptr, M_TEMP); - - ifmr->ifm_count = count; - break; - } - - default: - return (EINVAL); - } - - return (error); -} - -/* - * Find media entry matching a given ifm word. - * - */ -struct ifmedia_entry * -ifmedia_match(ifm, target, mask) - struct ifmedia *ifm; - int target; - int mask; -{ - struct ifmedia_entry *match, *next; - - match = NULL; - mask = ~mask; - - for (next = ifm->ifm_list.lh_first; next != NULL; - next = next->ifm_list.le_next) { - if ((next->ifm_media & mask) == (target & mask)) { -#if defined(IFMEDIA_DEBUG) || defined(DIAGNOSTIC) - if (match) { - printf("ifmedia_match: multiple match for " - "0x%x/0x%x\n", target, mask); - } -#endif - match = next; - } - } - - return match; -} - -#ifdef IFMEDIA_DEBUG -struct ifmedia_description ifm_type_descriptions[] = - IFM_TYPE_DESCRIPTIONS; - -struct ifmedia_description ifm_subtype_ethernet_descriptions[] = - IFM_SUBTYPE_ETHERNET_DESCRIPTIONS; - -struct ifmedia_description ifm_subtype_ethernet_option_descriptions[] = - IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS; - -struct ifmedia_description ifm_subtype_tokenring_descriptions[] = - IFM_SUBTYPE_TOKENRING_DESCRIPTIONS; - -struct ifmedia_description ifm_subtype_tokenring_option_descriptions[] = - IFM_SUBTYPE_TOKENRING_OPTION_DESCRIPTIONS; - -struct ifmedia_description ifm_subtype_fddi_descriptions[] = - IFM_SUBTYPE_FDDI_DESCRIPTIONS; - -struct ifmedia_description ifm_subtype_fddi_option_descriptions[] = - IFM_SUBTYPE_FDDI_OPTION_DESCRIPTIONS; - -struct ifmedia_description ifm_subtype_shared_descriptions[] = - IFM_SUBTYPE_SHARED_DESCRIPTIONS; - -struct ifmedia_description ifm_shared_option_descriptions[] = - IFM_SHARED_OPTION_DESCRIPTIONS; - -struct ifmedia_type_to_subtype { - struct ifmedia_description *subtypes; - struct ifmedia_description *options; -}; - -/* must be in the same order as IFM_TYPE_DESCRIPTIONS */ -struct ifmedia_type_to_subtype ifmedia_types_to_subtypes[] = { - { - &ifm_subtype_ethernet_descriptions[0], - &ifm_subtype_ethernet_option_descriptions[0] - }, - { - &ifm_subtype_tokenring_descriptions[0], - &ifm_subtype_tokenring_option_descriptions[0] - }, - { - &ifm_subtype_fddi_descriptions[0], - &ifm_subtype_fddi_option_descriptions[0] - }, -}; - -/* - * print a media word. - */ -static void -ifmedia_printword(ifmw) - int ifmw; -{ - struct ifmedia_description *desc; - struct ifmedia_type_to_subtype *ttos; - int seen_option = 0; - - /* Find the top-level interface type. */ - for (desc = ifm_type_descriptions, ttos = ifmedia_types_to_subtypes; - desc->ifmt_string != NULL; desc++, ttos++) - if (IFM_TYPE(ifmw) == desc->ifmt_word) - break; - if (desc->ifmt_string == NULL) { - printf("<unknown type>\n"); - return; - } - printf(desc->ifmt_string); - - /* - * Check for the shared subtype descriptions first, then the - * type-specific ones. - */ - for (desc = ifm_subtype_shared_descriptions; - desc->ifmt_string != NULL; desc++) - if (IFM_SUBTYPE(ifmw) == desc->ifmt_word) - goto got_subtype; - - for (desc = ttos->subtypes; desc->ifmt_string != NULL; desc++) - if (IFM_SUBTYPE(ifmw) == desc->ifmt_word) - break; - if (desc->ifmt_string == NULL) { - printf(" <unknown subtype>\n"); - return; - } - - got_subtype: - printf(" %s", desc->ifmt_string); - - /* - * Look for shared options. - */ - for (desc = ifm_shared_option_descriptions; - desc->ifmt_string != NULL; desc++) { - if (ifmw & desc->ifmt_word) { - if (seen_option == 0) - printf(" <"); - printf("%s%s", seen_option++ ? "," : "", - desc->ifmt_string); - } - } - - /* - * Look for subtype-specific options. - */ - for (desc = ttos->options; desc->ifmt_string != NULL; desc++) { - if (ifmw & desc->ifmt_word) { - if (seen_option == 0) - printf(" <"); - printf("%s%s", seen_option++ ? "," : "", - desc->ifmt_string); - } - } - printf("%s\n", seen_option ? ">" : ""); -} -#endif /* IFMEDIA_DEBUG */ diff --git a/sys/net/if_media.h b/sys/net/if_media.h deleted file mode 100644 index 08d056133b50..000000000000 --- a/sys/net/if_media.h +++ /dev/null @@ -1,306 +0,0 @@ -/* $NetBSD: if_media.h,v 1.3 1997/03/26 01:19:27 thorpej Exp $ */ - -/* - * Copyright (c) 1997 - * Jonathan Stone and Jason R. Thorpe. All rights reserved. - * - * This software is derived from information provided by Matt Thomas. - * - * 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 Jonathan Stone - * and Jason R. Thorpe for the NetBSD Project. - * 4. The names of the authors may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 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 _NET_IF_MEDIA_H_ -#define _NET_IF_MEDIA_H_ - -/* - * Prototypes and definitions for BSD/OS-compatible network interface - * media selection. - * - * Where it is safe to do so, this code strays slightly from the BSD/OS - * design. Software which uses the API (device drivers, basically) - * shouldn't notice any difference. - * - * Many thanks to Matt Thomas for providing the information necessary - * to implement this interface. - */ - -#ifdef _KERNEL - -#include <sys/queue.h> - -/* - * Driver callbacks for media status and change requests. - */ -typedef int (*ifm_change_cb_t) __P((struct ifnet *ifp)); -typedef void (*ifm_stat_cb_t) __P((struct ifnet *ifp, struct ifmediareq *req)); - -/* - * In-kernel representation of a single supported media type. - */ -struct ifmedia_entry { - LIST_ENTRY(ifmedia_entry) ifm_list; - int ifm_media; /* description of this media attachment */ - int ifm_data; /* for driver-specific use */ - void *ifm_aux; /* for driver-specific use */ -}; - -/* - * One of these goes into a network interface's softc structure. - * It is used to keep general media state. - */ -struct ifmedia { - int ifm_mask; /* mask of changes we don't care about */ - int ifm_media; /* current user-set media word */ - struct ifmedia_entry *ifm_cur; /* currently selected media */ - LIST_HEAD(, ifmedia_entry) ifm_list; /* list of all supported media */ - ifm_change_cb_t ifm_change; /* media change driver callback */ - ifm_stat_cb_t ifm_status; /* media status driver callback */ -}; - -/* Initialize an interface's struct if_media field. */ -void ifmedia_init __P((struct ifmedia *ifm, int dontcare_mask, - ifm_change_cb_t change_callback, ifm_stat_cb_t status_callback)); - -/* Add one supported medium to a struct ifmedia. */ -void ifmedia_add __P((struct ifmedia *ifm, int mword, int data, void *aux)); - -/* Add an array (of ifmedia_entry) media to a struct ifmedia. */ -void ifmedia_list_add(struct ifmedia *mp, struct ifmedia_entry *lp, - int count); - -/* Set default media type on initialization. */ -void ifmedia_set __P((struct ifmedia *ifm, int mword)); - -/* Common ioctl function for getting/setting media, called by driver. */ -int ifmedia_ioctl __P((struct ifnet *ifp, struct ifreq *ifr, - struct ifmedia *ifm, u_long cmd)); - -#endif /*_KERNEL */ - -/* - * if_media Options word: - * Bits Use - * ---- ------- - * 0-3 Media variant - * 4 RFU - * 5-7 Media type - * 8-15 Type specific options - * 16-19 RFU - * 20-27 Shared (global) options - * 28-31 Instance - */ - -/* - * Ethernet - */ -#define IFM_ETHER 0x00000020 -#define IFM_10_T 3 /* 10BaseT - RJ45 */ -#define IFM_10_2 4 /* 10Base2 - Thinnet */ -#define IFM_10_5 5 /* 10Base5 - AUI */ -#define IFM_100_TX 6 /* 100BaseTX - RJ45 */ -#define IFM_100_FX 7 /* 100BaseFX - Fiber */ -#define IFM_100_T4 8 /* 100BaseT4 - 4 pair cat 3 */ -#define IFM_100_VG 9 /* 100VG-AnyLAN */ -#define IFM_100_T2 10 /* 100BaseT2 */ - -/* - * Token ring - */ -#define IFM_TOKEN 0x00000040 -#define IFM_TOK_STP4 3 /* Shielded twisted pair 4m - DB9 */ -#define IFM_TOK_STP16 4 /* Shielded twisted pair 16m - DB9 */ -#define IFM_TOK_UTP4 5 /* Unshielded twisted pair 4m - RJ45 */ -#define IFM_TOK_UTP16 6 /* Unshielded twisted pair 16m - RJ45 */ -#define IFM_TOK_ETR 0x00000200 /* Early token release */ -#define IFM_TOK_SRCRT 0x00000400 /* Enable source routing features */ -#define IFM_TOK_ALLR 0x00000800 /* All routes / Single route bcast */ - -/* - * FDDI - */ -#define IFM_FDDI 0x00000060 -#define IFM_FDDI_SMF 3 /* Single-mode fiber */ -#define IFM_FDDI_MMF 4 /* Multi-mode fiber */ -#define IFM_FDDI_UTP 5 /* CDDI / UTP */ -#define IFM_FDDI_DA 0x00000100 /* Dual attach / single attach */ - -/* - * Shared media sub-types - */ -#define IFM_AUTO 0 /* Autoselect best media */ -#define IFM_MANUAL 1 /* Jumper/dipswitch selects media */ -#define IFM_NONE 2 /* Deselect all media */ - -/* - * Shared options - */ -#define IFM_FDX 0x00100000 /* Force full duplex */ -#define IFM_HDX 0x00200000 /* Force half duplex */ -#define IFM_FLAG0 0x01000000 /* Driver defined flag */ -#define IFM_FLAG1 0x02000000 /* Driver defined flag */ -#define IFM_FLAG2 0x04000000 /* Driver defined flag */ -#define IFM_LOOP 0x08000000 /* Put hardware in loopback */ - -/* - * Masks - */ -#define IFM_NMASK 0x000000e0 /* Network type */ -#define IFM_TMASK 0x0000000f /* Media sub-type */ -#define IFM_IMASK 0xf0000000 /* Instance */ -#define IFM_ISHIFT 28 /* Instance shift */ -#define IFM_OMASK 0x0000ff00 /* Type specific options */ -#define IFM_GMASK 0x0ff00000 /* Global options */ - -/* - * Status bits - */ -#define IFM_AVALID 0x00000001 /* Active bit valid */ -#define IFM_ACTIVE 0x00000002 /* Interface attached to working net */ - -/* - * Macros to extract various bits of information from the media word. - */ -#define IFM_TYPE(x) ((x) & IFM_NMASK) -#define IFM_SUBTYPE(x) ((x) & IFM_TMASK) -#define IFM_INST(x) (((x) & IFM_IMASK) >> IFM_ISHIFT) - -/* - * NetBSD extension not defined in the BSDI API. This is used in various - * places to get the canonical description for a given type/subtype. - * - * NOTE: all but the top-level type descriptions must contain NO whitespace! - * Otherwise, parsing these in ifconfig(8) would be a nightmare. - */ -struct ifmedia_description { - int ifmt_word; /* word value; may be masked */ - const char *ifmt_string; /* description */ -}; - -#define IFM_TYPE_DESCRIPTIONS { \ - { IFM_ETHER, "Ethernet" }, \ - { IFM_TOKEN, "Token ring" }, \ - { IFM_FDDI, "FDDI" }, \ - { 0, NULL }, \ -} - -#define IFM_SUBTYPE_ETHERNET_DESCRIPTIONS { \ - { IFM_10_T, "10baseT/UTP" }, \ - { IFM_10_2, "10base2/BNC" }, \ - { IFM_10_5, "10base5/AUI" }, \ - { IFM_100_TX, "100baseTX" }, \ - { IFM_100_FX, "100baseFX" }, \ - { IFM_100_T4, "100baseT4" }, \ - { IFM_100_VG, "100baseVG" }, \ - { IFM_100_T2, "100baseT2" }, \ - { 0, NULL }, \ -} - -#define IFM_SUBTYPE_ETHERNET_ALIASES { \ - { IFM_10_T, "UTP" }, \ - { IFM_10_T, "10UTP" }, \ - { IFM_10_2, "BNC" }, \ - { IFM_10_2, "10BNC" }, \ - { IFM_10_5, "AUI" }, \ - { IFM_10_5, "10AUI" }, \ - { IFM_100_TX, "100TX" }, \ - { IFM_100_FX, "100FX" }, \ - { IFM_100_T4, "100T4" }, \ - { IFM_100_VG, "100VG" }, \ - { IFM_100_T2, "100T2" }, \ - { 0, NULL }, \ -} - -#define IFM_SUBTYPE_ETHERNET_OPTION_DESCRIPTIONS { \ - { 0, NULL }, \ -} - -#define IFM_SUBTYPE_TOKENRING_DESCRIPTIONS { \ - { IFM_TOK_STP4, "DB9/4Mbit" }, \ - { IFM_TOK_STP16, "DB9/16Mbit" }, \ - { IFM_TOK_UTP4, "UTP/4Mbit" }, \ - { IFM_TOK_UTP16, "UTP/16Mbit" }, \ - { 0, NULL }, \ -} - -#define IFM_SUBTYPE_TOKENRING_ALIASES { \ - { IFM_TOK_STP4, "4STP" }, \ - { IFM_TOK_STP16, "16STP" }, \ - { IFM_TOK_UTP4, "4UTP" }, \ - { IFM_TOK_UTP16, "16UTP" }, \ - { 0, NULL }, \ -} - -#define IFM_SUBTYPE_TOKENRING_OPTION_DESCRIPTIONS { \ - { IFM_TOK_ETR, "EarlyTokenRelease" }, \ - { IFM_TOK_SRCRT, "SourceRouting" }, \ - { IFM_TOK_ALLR, "AllRoutes" }, \ - { 0, NULL }, \ -} - -#define IFM_SUBTYPE_FDDI_DESCRIPTIONS { \ - { IFM_FDDI_SMF, "Single-mode" }, \ - { IFM_FDDI_MMF, "Multi-mode" }, \ - { IFM_FDDI_UTP, "UTP" }, \ - { 0, NULL }, \ -} - -#define IFM_SUBTYPE_FDDI_ALIASES { \ - { IFM_FDDI_SMF, "SMF" }, \ - { IFM_FDDI_MMF, "MMF" }, \ - { IFM_FDDI_UTP, "CDDI" }, \ - { 0, NULL }, \ -} - -#define IFM_SUBTYPE_FDDI_OPTION_DESCRIPTIONS { \ - { IFM_FDDI_DA, "Dual-attach" }, \ - { 0, NULL }, \ -} - -#define IFM_SUBTYPE_SHARED_DESCRIPTIONS { \ - { IFM_AUTO, "autoselect" }, \ - { IFM_MANUAL, "manual" }, \ - { IFM_NONE, "none" }, \ - { 0, NULL }, \ -} - -#define IFM_SUBTYPE_SHARED_ALIASES { \ - { IFM_AUTO, "auto" }, \ - { 0, NULL }, \ -} - -#define IFM_SHARED_OPTION_DESCRIPTIONS { \ - { IFM_FDX, "full-duplex" }, \ - { IFM_HDX, "half-duplex" }, \ - { IFM_FLAG0, "flag0" }, \ - { IFM_FLAG1, "flag1" }, \ - { IFM_FLAG2, "flag2" }, \ - { IFM_LOOP, "hw-loopback" }, \ - { 0, NULL }, \ -} - -#endif /* _NET_IF_MEDIA_H_ */ diff --git a/sys/pci/dc21040reg.h b/sys/pci/dc21040reg.h deleted file mode 100644 index 4b477261ab67..000000000000 --- a/sys/pci/dc21040reg.h +++ /dev/null @@ -1,607 +0,0 @@ -/* $NetBSD: dc21040reg.h,v 1.15 1998/05/22 18:50:59 matt Exp $ */ - -/*- - * Copyright (c) 1994, 1995, 1996 Matt Thomas <matt@3am-software.com> - * 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. The name of the author may not be used to endorse or promote products - * derived from this software withough specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - * - * Id: dc21040reg.h,v 1.24 1997/05/16 19:47:09 thomas Exp - */ - -#if !defined(_DC21040_H) -#define _DC21040_H - -#if defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN -#define TULIP_BITFIELD2(a, b) b, a -#define TULIP_BITFIELD3(a, b, c) c, b, a -#define TULIP_BITFIELD4(a, b, c, d) d, c, b, a -#else -#define TULIP_BITFIELD2(a, b) a, b -#define TULIP_BITFIELD3(a, b, c) a, b, c -#define TULIP_BITFIELD4(a, b, c, d) a, b, c, d -#endif - -typedef struct { - u_int32_t d_status; - u_int32_t TULIP_BITFIELD3(d_length1 : 11, - d_length2 : 11, - d_flag : 10); - u_int32_t d_addr1; - u_int32_t d_addr2; -} tulip_desc_t; - -#define TULIP_DSTS_OWNER 0x80000000 /* Owner (1 = 21040) */ -#define TULIP_DSTS_ERRSUM 0x00008000 /* Error Summary */ -/* - * Transmit Status - */ -#define TULIP_DSTS_TxBABBLE 0x00004000 /* Transmitter Babbled */ -#define TULIP_DSTS_TxCARRLOSS 0x00000800 /* Carrier Loss */ -#define TULIP_DSTS_TxNOCARR 0x00000400 /* No Carrier */ -#define TULIP_DSTS_TxLATECOLL 0x00000200 /* Late Collision */ -#define TULIP_DSTS_TxEXCCOLL 0x00000100 /* Excessive Collisions */ -#define TULIP_DSTS_TxNOHRTBT 0x00000080 /* No Heartbeat */ -#define TULIP_DSTS_TxCOLLMASK 0x00000078 /* Collision Count (mask) */ -#define TULIP_DSTS_V_TxCOLLCNT 0x00000003 /* Collision Count (bit) */ -#define TULIP_DSTS_TxLINKFAIL 0x00000004 /* Link Failure */ -#define TULIP_DSTS_TxUNDERFLOW 0x00000002 /* Underflow Error */ -#define TULIP_DSTS_TxDEFERRED 0x00000001 /* Initially Deferred */ -/* - * Receive Status - */ -#define TULIP_DSTS_RxBADLENGTH 0x00004000 /* Length Error */ -#define TULIP_DSTS_RxDATATYPE 0x00003000 /* Data Type */ -#define TULIP_DSTS_RxRUNT 0x00000800 /* Runt Frame */ -#define TULIP_DSTS_RxMULTICAST 0x00000400 /* Multicast Frame */ -#define TULIP_DSTS_RxFIRSTDESC 0x00000200 /* First Descriptor */ -#define TULIP_DSTS_RxLASTDESC 0x00000100 /* Last Descriptor */ -#define TULIP_DSTS_RxTOOLONG 0x00000080 /* Frame Too Long */ -#define TULIP_DSTS_RxCOLLSEEN 0x00000040 /* Collision Seen */ -#define TULIP_DSTS_RxFRAMETYPE 0x00000020 /* Frame Type */ -#define TULIP_DSTS_RxWATCHDOG 0x00000010 /* Receive Watchdog */ -#define TULIP_DSTS_RxDRBBLBIT 0x00000004 /* Dribble Bit */ -#define TULIP_DSTS_RxBADCRC 0x00000002 /* CRC Error */ -#define TULIP_DSTS_RxOVERFLOW 0x00000001 /* Overflow */ - - -#define TULIP_DFLAG_ENDRING 0x0008 /* End of Transmit Ring */ -#define TULIP_DFLAG_CHAIN 0x0004 /* Chain using d_addr2 */ - -#define TULIP_DFLAG_TxWANTINTR 0x0200 /* Signal Interrupt on Completion */ -#define TULIP_DFLAG_TxLASTSEG 0x0100 /* Last Segment */ -#define TULIP_DFLAG_TxFIRSTSEG 0x0080 /* First Segment */ -#define TULIP_DFLAG_TxINVRSFILT 0x0040 /* Inverse Filtering */ -#define TULIP_DFLAG_TxSETUPPKT 0x0020 /* Setup Packet */ -#define TULIP_DFLAG_TxHASCRC 0x0010 /* Don't Append the CRC */ -#define TULIP_DFLAG_TxNOPADDING 0x0002 /* Don't AutoPad */ -#define TULIP_DFLAG_TxHASHFILT 0x0001 /* Hash/Perfect Filtering */ - -/* - * The 21040 Registers (IO Space Addresses) - */ -#define TULIP_REG_BUSMODE 0x00 /* CSR0 -- Bus Mode */ -#define TULIP_REG_TXPOLL 0x08 /* CSR1 -- Transmit Poll Demand */ -#define TULIP_REG_RXPOLL 0x10 /* CSR2 -- Receive Poll Demand */ -#define TULIP_REG_RXLIST 0x18 /* CSR3 -- Receive List Base Addr */ -#define TULIP_REG_TXLIST 0x20 /* CSR4 -- Transmit List Base Addr */ -#define TULIP_REG_STATUS 0x28 /* CSR5 -- Status */ -#define TULIP_REG_CMD 0x30 /* CSR6 -- Command */ -#define TULIP_REG_INTR 0x38 /* CSR7 -- Interrupt Control */ -#define TULIP_REG_MISSES 0x40 /* CSR8 -- Missed Frame Counter */ -#define TULIP_REG_ADDRROM 0x48 /* CSR9 -- ENET ROM Register */ -#define TULIP_REG_RSRVD 0x50 /* CSR10 -- Reserved */ -#define TULIP_REG_FULL_DUPLEX 0x58 /* CSR11 -- Full Duplex */ -#define TULIP_REG_SIA_STATUS 0x60 /* CSR12 -- SIA Status */ -#define TULIP_REG_SIA_CONN 0x68 /* CSR13 -- SIA Connectivity */ -#define TULIP_REG_SIA_TXRX 0x70 /* CSR14 -- SIA Tx Rx */ -#define TULIP_REG_SIA_GEN 0x78 /* CSR15 -- SIA General */ - -/* - * CSR5 -- Status Register - * CSR7 -- Interrupt Control - */ -#define TULIP_STS_ERRORMASK 0x03800000L /* ( R) Error Bits (Valid when SYSERROR is set) */ -#define TULIP_STS_ERR_PARITY 0x00000000L /* 000 - Parity Error (Perform Reset) */ -#define TULIP_STS_ERR_MASTER 0x00800000L /* 001 - Master Abort */ -#define TULIP_STS_ERR_TARGET 0x01000000L /* 010 - Target Abort */ -#define TULIP_STS_ERR_SHIFT 23 -#define TULIP_STS_TXSTATEMASK 0x00700000L /* ( R) Transmission Process State */ -#define TULIP_STS_TXS_RESET 0x00000000L /* 000 - Rset or transmit jabber expired */ -#define TULIP_STS_TXS_FETCH 0x00100000L /* 001 - Fetching transmit descriptor */ -#define TULIP_STS_TXS_WAITEND 0x00200000L /* 010 - Wait for end of transmission */ -#define TULIP_STS_TXS_READING 0x00300000L /* 011 - Read buffer and enqueue data */ -#define TULIP_STS_TXS_RSRVD 0x00400000L /* 100 - Reserved */ -#define TULIP_STS_TXS_SETUP 0x00500000L /* 101 - Setup Packet */ -#define TULIP_STS_TXS_SUSPEND 0x00600000L /* 110 - Transmit FIFO underflow or an - unavailable transmit descriptor */ -#define TULIP_STS_TXS_CLOSE 0x00700000L /* 111 - Close transmit descriptor */ -#define TULIP_STS_RXSTATEMASK 0x000E0000L /* ( R) Receive Process State*/ -#define TULIP_STS_RXS_STOPPED 0x00000000L /* 000 - Stopped */ -#define TULIP_STS_RXS_FETCH 0x00020000L /* 001 - Running -- Fetch receive descriptor */ -#define TULIP_STS_RXS_ENDCHECK 0x00040000L /* 010 - Running -- Check for end of receive - packet before prefetch of next descriptor */ -#define TULIP_STS_RXS_WAIT 0x00060000L /* 011 - Running -- Wait for receive packet */ -#define TULIP_STS_RXS_SUSPEND 0x00080000L /* 100 - Suspended -- As a result of - unavailable receive buffers */ -#define TULIP_STS_RXS_CLOSE 0x000A0000L /* 101 - Running -- Close receive descriptor */ -#define TULIP_STS_RXS_FLUSH 0x000C0000L /* 110 - Running -- Flush the current frame - from the receive FIFO as a result of - an unavailable receive buffer */ -#define TULIP_STS_RXS_DEQUEUE 0x000E0000L /* 111 - Running -- Dequeue the receive frame - from the receive FIFO into the receive - buffer. */ -#define TULIP_STS_NORMALINTR 0x00010000L /* (RW) Normal Interrupt */ -#define TULIP_STS_ABNRMLINTR 0x00008000L /* (RW) Abnormal Interrupt */ -#define TULIP_STS_SYSERROR 0x00002000L /* (RW) System Error */ -#define TULIP_STS_LINKFAIL 0x00001000L /* (RW) Link Failure (21040) */ -#define TULIP_STS_FULDPLXSHRT 0x00000800L /* (RW) Full Duplex Short Fram Rcvd (21040) */ -#define TULIP_STS_GPTIMEOUT 0x00000800L /* (RW) General Purpose Timeout (21140) */ -#define TULIP_STS_AUI 0x00000400L /* (RW) AUI/TP Switch (21040) */ -#define TULIP_STS_RXTIMEOUT 0x00000200L /* (RW) Receive Watchbog Timeout */ -#define TULIP_STS_RXSTOPPED 0x00000100L /* (RW) Receive Process Stopped */ -#define TULIP_STS_RXNOBUF 0x00000080L /* (RW) Receive Buffer Unavailable */ -#define TULIP_STS_RXINTR 0x00000040L /* (RW) Receive Interrupt */ -#define TULIP_STS_TXUNDERFLOW 0x00000020L /* (RW) Transmit Underflow */ -#define TULIP_STS_LINKPASS 0x00000010L /* (RW) LinkPass (21041) */ -#define TULIP_STS_TXBABBLE 0x00000008L /* (RW) Transmit Jabber Timeout */ -#define TULIP_STS_TXNOBUF 0x00000004L /* (RW) Transmit Buffer Unavailable */ -#define TULIP_STS_TXSTOPPED 0x00000002L /* (RW) Transmit Process Stopped */ -#define TULIP_STS_TXINTR 0x00000001L /* (RW) Transmit Interrupt */ - -/* - * CSR6 -- Command (Operation Mode) Register - */ -#define TULIP_CMD_MUSTBEONE 0x02000000L /* (RW) Must Be One (21140) */ -#define TULIP_CMD_SCRAMBLER 0x01000000L /* (RW) Scrambler Mode (21140) */ -#define TULIP_CMD_PCSFUNCTION 0x00800000L /* (RW) PCS Function (21140) */ -#define TULIP_CMD_TXTHRSHLDCTL 0x00400000L /* (RW) Transmit Threshold Mode (21140) */ -#define TULIP_CMD_STOREFWD 0x00200000L /* (RW) Store and Foward (21140) */ -#define TULIP_CMD_NOHEARTBEAT 0x00080000L /* (RW) No Heartbeat (21140) */ -#define TULIP_CMD_PORTSELECT 0x00040000L /* (RW) Post Select (100Mb) (21140) */ -#define TULIP_CMD_ENHCAPTEFFCT 0x00040000L /* (RW) Enhanced Capture Effecty (21041) */ -#define TULIP_CMD_CAPTREFFCT 0x00020000L /* (RW) Capture Effect (!802.3) */ -#define TULIP_CMD_BACKPRESSURE 0x00010000L /* (RW) Back Pressure (!802.3) (21040) */ -#define TULIP_CMD_THRESHOLDCTL 0x0000C000L /* (RW) Threshold Control */ -#define TULIP_CMD_THRSHLD72 0x00000000L /* 00 - 72 Bytes */ -#define TULIP_CMD_THRSHLD96 0x00004000L /* 01 - 96 Bytes */ -#define TULIP_CMD_THRSHLD128 0x00008000L /* 10 - 128 bytes */ -#define TULIP_CMD_THRSHLD160 0x0000C000L /* 11 - 160 Bytes */ -#define TULIP_CMD_TXRUN 0x00002000L /* (RW) Start/Stop Transmitter */ -#define TULIP_CMD_FORCECOLL 0x00001000L /* (RW) Force Collisions */ -#define TULIP_CMD_OPERMODE 0x00000C00L /* (RW) Operating Mode */ -#define TULIP_CMD_FULLDUPLEX 0x00000200L /* (RW) Full Duplex Mode */ -#define TULIP_CMD_FLAKYOSCDIS 0x00000100L /* (RW) Flakey Oscillator Disable */ -#define TULIP_CMD_ALLMULTI 0x00000080L /* (RW) Pass All Multicasts */ -#define TULIP_CMD_PROMISCUOUS 0x00000040L /* (RW) Promiscuous Mode */ -#define TULIP_CMD_BACKOFFCTR 0x00000020L /* (RW) Start/Stop Backoff Counter (!802.3) */ -#define TULIP_CMD_INVFILTER 0x00000010L /* (R ) Inverse Filtering */ -#define TULIP_CMD_PASSBADPKT 0x00000008L /* (RW) Pass Bad Frames */ -#define TULIP_CMD_HASHONLYFLTR 0x00000004L /* (R ) Hash Only Filtering */ -#define TULIP_CMD_RXRUN 0x00000002L /* (RW) Start/Stop Receive Filtering */ -#define TULIP_CMD_HASHPRFCTFLTR 0x00000001L /* (R ) Hash/Perfect Receive Filtering */ - -#define TULIP_SIASTS_OTHERRXACTIVITY 0x00000200L -#define TULIP_SIASTS_RXACTIVITY 0x00000100L -#define TULIP_SIASTS_LINKFAIL 0x00000004L -#define TULIP_SIASTS_LINK100FAIL 0x00000002L -#define TULIP_SIACONN_RESET 0x00000000L - -/* - * 21040 SIA definitions - */ -#define TULIP_21040_PROBE_10BASET_TIMEOUT 2500 -#define TULIP_21040_PROBE_AUIBNC_TIMEOUT 300 -#define TULIP_21040_PROBE_EXTSIA_TIMEOUT 300 - -#define TULIP_21040_SIACONN_10BASET 0x0000EF01L -#define TULIP_21040_SIATXRX_10BASET 0x0000FFFFL -#define TULIP_21040_SIAGEN_10BASET 0x00000000L - -#define TULIP_21040_SIACONN_10BASET_FD 0x0000EF01L -#define TULIP_21040_SIATXRX_10BASET_FD 0x0000FFFDL -#define TULIP_21040_SIAGEN_10BASET_FD 0x00000000L - -#define TULIP_21040_SIACONN_AUIBNC 0x0000EF09L -#define TULIP_21040_SIATXRX_AUIBNC 0x00000705L -#define TULIP_21040_SIAGEN_AUIBNC 0x00000006L - -#define TULIP_21040_SIACONN_EXTSIA 0x00003041L -#define TULIP_21040_SIATXRX_EXTSIA 0x00000000L -#define TULIP_21040_SIAGEN_EXTSIA 0x00000006L - -/* - * 21041 SIA definitions - */ - -#define TULIP_21041_PROBE_10BASET_TIMEOUT 2500 -#define TULIP_21041_PROBE_AUIBNC_TIMEOUT 300 - -#define TULIP_21041_SIACONN_10BASET 0x0000EF01L -#define TULIP_21041_SIATXRX_10BASET 0x0000FF3FL -#define TULIP_21041_SIAGEN_10BASET 0x00000000L - -#define TULIP_21041P2_SIACONN_10BASET 0x0000EF01L -#define TULIP_21041P2_SIATXRX_10BASET 0x0000FFFFL -#define TULIP_21041P2_SIAGEN_10BASET 0x00000000L - -#define TULIP_21041_SIACONN_10BASET_FD 0x0000EF01L -#define TULIP_21041_SIATXRX_10BASET_FD 0x0000FF3DL -#define TULIP_21041_SIAGEN_10BASET_FD 0x00000000L - -#define TULIP_21041P2_SIACONN_10BASET_FD 0x0000EF01L -#define TULIP_21041P2_SIATXRX_10BASET_FD 0x0000FFFFL -#define TULIP_21041P2_SIAGEN_10BASET_FD 0x00000000L - -#define TULIP_21041_SIACONN_AUI 0x0000EF09L -#define TULIP_21041_SIATXRX_AUI 0x0000F73DL -#define TULIP_21041_SIAGEN_AUI 0x0000000EL - -#define TULIP_21041P2_SIACONN_AUI 0x0000EF09L -#define TULIP_21041P2_SIATXRX_AUI 0x0000F7FDL -#define TULIP_21041P2_SIAGEN_AUI 0x0000000EL - -#define TULIP_21041_SIACONN_BNC 0x0000EF09L -#define TULIP_21041_SIATXRX_BNC 0x0000F73DL -#define TULIP_21041_SIAGEN_BNC 0x00000006L - -#define TULIP_21041P2_SIACONN_BNC 0x0000EF09L -#define TULIP_21041P2_SIATXRX_BNC 0x0000F7FDL -#define TULIP_21041P2_SIAGEN_BNC 0x00000006L - -/* - * 21142 SIA definitions - */ - -#define TULIP_21142_PROBE_10BASET_TIMEOUT 2500 -#define TULIP_21142_PROBE_AUIBNC_TIMEOUT 300 - -#define TULIP_21142_SIACONN_10BASET 0x00000001L -#define TULIP_21142_SIATXRX_10BASET 0x00007F3FL -#define TULIP_21142_SIAGEN_10BASET 0x00000008L - -#define TULIP_21142_SIACONN_10BASET_FD 0x00000001L -#define TULIP_21142_SIATXRX_10BASET_FD 0x00007F3DL -#define TULIP_21142_SIAGEN_10BASET_FD 0x00000008L - -#define TULIP_21142_SIACONN_AUI 0x00000009L -#define TULIP_21142_SIATXRX_AUI 0x00000705L -#define TULIP_21142_SIAGEN_AUI 0x0000000EL - -#define TULIP_21142_SIACONN_BNC 0x00000009L -#define TULIP_21142_SIATXRX_BNC 0x00000705L -#define TULIP_21142_SIAGEN_BNC 0x00000006L - - - - -#define TULIP_WATCHDOG_TXDISABLE 0x00000001L -#define TULIP_WATCHDOG_RXDISABLE 0x00000010L - -#define TULIP_BUSMODE_SWRESET 0x00000001L -#define TULIP_BUSMODE_DESCSKIPLEN_MASK 0x0000007CL -#define TULIP_BUSMODE_BIGENDIAN 0x00000080L -#define TULIP_BUSMODE_BURSTLEN_MASK 0x00003F00L -#define TULIP_BUSMODE_BURSTLEN_DEFAULT 0x00000000L -#define TULIP_BUSMODE_BURSTLEN_1LW 0x00000100L -#define TULIP_BUSMODE_BURSTLEN_2LW 0x00000200L -#define TULIP_BUSMODE_BURSTLEN_4LW 0x00000400L -#define TULIP_BUSMODE_BURSTLEN_8LW 0x00000800L -#define TULIP_BUSMODE_BURSTLEN_16LW 0x00001000L -#define TULIP_BUSMODE_BURSTLEN_32LW 0x00002000L -#define TULIP_BUSMODE_CACHE_NOALIGN 0x00000000L -#define TULIP_BUSMODE_CACHE_ALIGN8 0x00004000L -#define TULIP_BUSMODE_CACHE_ALIGN16 0x00008000L -#define TULIP_BUSMODE_CACHE_ALIGN32 0x0000C000L -#define TULIP_BUSMODE_TXPOLL_NEVER 0x00000000L -#define TULIP_BUSMODE_TXPOLL_200000ns 0x00020000L -#define TULIP_BUSMODE_TXPOLL_800000ns 0x00040000L -#define TULIP_BUSMODE_TXPOLL_1600000ns 0x00060000L -#define TULIP_BUSMODE_TXPOLL_12800ns 0x00080000L /* 21041 only */ -#define TULIP_BUSMODE_TXPOLL_25600ns 0x000A0000L /* 21041 only */ -#define TULIP_BUSMODE_TXPOLL_51200ns 0x000C0000L /* 21041 only */ -#define TULIP_BUSMODE_TXPOLL_102400ns 0x000E0000L /* 21041 only */ -#define TULIP_BUSMODE_DESC_BIGENDIAN 0x00100000L /* 21041 only */ -#define TULIP_BUSMODE_READMULTIPLE 0x00200000L /* */ - -#define TULIP_REG_CFDA 0x40 -#define TULIP_CFDA_SLEEP 0x80000000L -#define TULIP_CFDA_SNOOZE 0x40000000L - -#define TULIP_GP_PINSET 0x00000100L -/* - * These are the defintitions used for the DEC 21140 - * evaluation board. - */ -#define TULIP_GP_EB_PINS 0x0000001F /* General Purpose Pin directions */ -#define TULIP_GP_EB_OK10 0x00000080 /* 10 Mb/sec Signal Detect gep<7> */ -#define TULIP_GP_EB_OK100 0x00000040 /* 100 Mb/sec Signal Detect gep<6> */ -#define TULIP_GP_EB_INIT 0x0000000B /* No loopback --- point-to-point */ - -/* - * These are the defintitions used for the SMC9332 (21140) board. - */ -#define TULIP_GP_SMC_9332_PINS 0x0000003F /* General Purpose Pin directions */ -#define TULIP_GP_SMC_9332_OK10 0x00000080 /* 10 Mb/sec Signal Detect gep<7> */ -#define TULIP_GP_SMC_9332_OK100 0x00000040 /* 100 Mb/sec Signal Detect gep<6> */ -#define TULIP_GP_SMC_9332_INIT 0x00000009 /* No loopback --- point-to-point */ - -#define TULIP_OUI_SMC_0 0x00 -#define TULIP_OUI_SMC_1 0x00 -#define TULIP_OUI_SMC_2 0xC0 - -/* - * There are the definitions used for the DEC DE500 - * 10/100 family of boards - */ -#define TULIP_GP_DE500_PINS 0x0000001FL -#define TULIP_GP_DE500_LINK_PASS 0x00000080L -#define TULIP_GP_DE500_SYM_LINK 0x00000040L -#define TULIP_GP_DE500_SIGNAL_DETECT 0x00000020L -#define TULIP_GP_DE500_PHY_RESET 0x00000010L -#define TULIP_GP_DE500_HALFDUPLEX 0x00000008L -#define TULIP_GP_DE500_PHY_LOOPBACK 0x00000004L -#define TULIP_GP_DE500_FORCE_LED 0x00000002L -#define TULIP_GP_DE500_FORCE_100 0x00000001L - -/* - * These are the defintitions used for the Cogent EM100 - * 21140 board. - */ -#define TULIP_GP_EM100_PINS 0x0000003F /* General Purpose Pin directions */ -#define TULIP_GP_EM100_INIT 0x00000009 /* No loopback --- point-to-point */ -#define TULIP_OUI_COGENT_0 0x00 -#define TULIP_OUI_COGENT_1 0x00 -#define TULIP_OUI_COGENT_2 0x92 -#define TULIP_COGENT_EM100TX_ID 0x12 -#define TULIP_COGENT_EM100FX_ID 0x15 - - -/* - * These are the defintitions used for the Znyx ZX342 - * 10/100 board - */ -#define TULIP_OUI_ZNYX_0 0x00 -#define TULIP_OUI_ZNYX_1 0xC0 -#define TULIP_OUI_ZNYX_2 0x95 - -#define TULIP_ZNYX_ID_ZX312 0x0602 -#define TULIP_ZNYX_ID_ZX312T 0x0622 -#define TULIP_ZNYX_ID_ZX314_INTA 0x0701 -#define TULIP_ZNYX_ID_ZX314 0x0711 -#define TULIP_ZNYX_ID_ZX315_INTA 0x0801 -#define TULIP_ZNYX_ID_ZX315 0x0811 -#define TULIP_ZNYX_ID_ZX342 0x0901 -#define TULIP_ZNYX_ID_ZX342B 0x0921 -#define TULIP_ZNYX_ID_ZX342_X3 0x0902 -#define TULIP_ZNYX_ID_ZX342_X4 0x0903 -#define TULIP_ZNYX_ID_ZX344 0x0A01 -#define TULIP_ZNYX_ID_ZX351 0x0B01 -#define TULIP_ZNYX_ID_ZX345 0x0C01 -#define TULIP_ZNYX_ID_ZX311 0x0D01 -#define TULIP_ZNYX_ID_ZX346 0x0E01 - -#define TULIP_GP_ZX34X_PINS 0x0000001F /* General Purpose Pin directions */ -#define TULIP_GP_ZX344_PINS 0x0000000B /* General Purpose Pin directions */ -#define TULIP_GP_ZX345_PINS 0x00000003 /* General Purpose Pin directions */ -#define TULIP_GP_ZX346_PINS 0x00000043 /* General Purpose Pin directions */ -#define TULIP_GP_ZX34X_LNKFAIL 0x00000080 /* 10Mb/s Link Failure */ -#define TULIP_GP_ZX34X_SYMDET 0x00000040 /* 100Mb/s Symbol Detect */ -#define TULIP_GP_ZX345_PHYACT 0x00000040 /* PHY Activity */ -#define TULIP_GP_ZX34X_SIGDET 0x00000020 /* 100Mb/s Signal Detect */ -#define TULIP_GP_ZX346_AUTONEG_ENABLED 0x00000020 /* 802.3u autoneg enabled */ -#define TULIP_GP_ZX342_COLENA 0x00000008 /* 10t Ext LB */ -#define TULIP_GP_ZX344_ROTINT 0x00000008 /* PPB IRQ rotation */ -#define TULIP_GP_ZX345_SPEED10 0x00000008 /* 10Mb speed detect */ -#define TULIP_GP_ZX346_SPEED100 0x00000008 /* 100Mb speed detect */ -#define TULIP_GP_ZX34X_NCOLENA 0x00000004 /* 10t Int LB */ -#define TULIP_GP_ZX34X_RXMATCH 0x00000004 /* RX Match */ -#define TULIP_GP_ZX346_FULLDUPLEX 0x00000004 /* Full Duplex Sensed */ -#define TULIP_GP_ZX34X_LB102 0x00000002 /* 100tx twister LB */ -#define TULIP_GP_ZX34X_NLB101 0x00000001 /* PDT/PDR LB */ -#define TULIP_GP_ZX34X_INIT 0x00000009 - -/* - * Compex's OUI. We need to twiddle a bit on their 21041 card. - */ -#define TULIP_OUI_COMPEX_0 0x00 -#define TULIP_OUI_COMPEX_1 0x80 -#define TULIP_OUI_COMPEX_2 0x48 -#define TULIP_21041_COMPEX_XREGDATA 1 - -/* - * Asante's OUI and stuff... - */ -#define TULIP_OUI_ASANTE_0 0x00 -#define TULIP_OUI_ASANTE_1 0x00 -#define TULIP_OUI_ASANTE_2 0x94 -#define TULIP_GP_ASANTE_PINS 0x000000bf /* GP pin config */ -#define TULIP_GP_ASANTE_PHYRESET 0x00000008 /* Reset PHY */ - -/* - * ACCTON EN1207 specialties - */ - -#define TULIP_OUI_EN1207_0 0x00 -#define TULIP_OUI_EN1207_1 0x00 -#define TULIP_OUI_EN1207_2 0xE8 - -#define TULIP_CSR8_EN1207 0x08 -#define TULIP_CSR9_EN1207 0x00 -#define TULIP_CSR10_EN1207 0x03 -#define TULIP_CSR11_EN1207 0x1F - -#define TULIP_GP_EN1207_BNC_INIT 0x0000011B -#define TULIP_GP_EN1207_UTP_INIT 0x9E00000B -#define TULIP_GP_EN1207_100_INIT 0x6D00031B - -/* - * SROM definitions for the 21140 and 21041. - */ -#define SROMXREG 0x0400 -#define SROMSEL 0x0800 -#define SROMRD 0x4000 -#define SROMWR 0x2000 -#define SROMDIN 0x0008 -#define SROMDOUT 0x0004 -#define SROMDOUTON 0x0004 -#define SROMDOUTOFF 0x0004 -#define SROMCLKON 0x0002 -#define SROMCLKOFF 0x0002 -#define SROMCSON 0x0001 -#define SROMCSOFF 0x0001 -#define SROMCS 0x0001 - -#define SROMCMD_MODE 4 -#define SROMCMD_WR 5 -#define SROMCMD_RD 6 - -#define SROM_BITWIDTH 6 - -/* - * MII Definitions for the 21041 and 21140/21140A/21142 - */ -#define MII_PREAMBLE (~0) -#define MII_TEST 0xAAAAAAAA -#define MII_RDCMD 0xF6 /* 1111.0110 */ -#define MII_WRCMD 0xF5 /* 1111.0101 */ -#define MII_DIN 0x00080000 -#define MII_RD 0x00040000 -#define MII_WR 0x00000000 -#define MII_DOUT 0x00020000 -#define MII_CLK 0x00010000 -#define MII_CLKON MII_CLK -#define MII_CLKOFF MII_CLK - -#define PHYREG_CONTROL 0 -#define PHYREG_STATUS 1 -#define PHYREG_IDLOW 2 -#define PHYREG_IDHIGH 3 -#define PHYREG_AUTONEG_ADVERTISEMENT 4 -#define PHYREG_AUTONEG_ABILITIES 5 -#define PHYREG_AUTONEG_EXPANSION 6 -#define PHYREG_AUTONEG_NEXTPAGE 7 - -#define PHYSTS_100BASET4 0x8000 -#define PHYSTS_100BASETX_FD 0x4000 -#define PHYSTS_100BASETX 0x2000 -#define PHYSTS_10BASET_FD 0x1000 -#define PHYSTS_10BASET 0x0800 -#define PHYSTS_AUTONEG_DONE 0x0020 -#define PHYSTS_REMOTE_FAULT 0x0010 -#define PHYSTS_CAN_AUTONEG 0x0008 -#define PHYSTS_LINK_UP 0x0004 -#define PHYSTS_JABBER_DETECT 0x0002 -#define PHYSTS_EXTENDED_REGS 0x0001 - -#define PHYCTL_RESET 0x8000 -#define PHYCTL_SELECT_100MB 0x2000 -#define PHYCTL_AUTONEG_ENABLE 0x1000 -#define PHYCTL_ISOLATE 0x0400 -#define PHYCTL_AUTONEG_RESTART 0x0200 -#define PHYCTL_FULL_DUPLEX 0x0100 - -/* - * Definitions for the DE425. - */ -#define DE425_CFID 0x08 /* Configuration Id */ -#define DE425_CFCS 0x0C /* Configuration Command-Status */ -#define DE425_CFRV 0x18 /* Configuration Revision */ -#define DE425_CFLT 0x1C /* Configuration Latency Timer */ -#define DE425_CBIO 0x28 /* Configuration Base IO Address */ -#define DE425_CFDA 0x2C /* Configuration Driver Area */ -#define DE425_ENETROM_OFFSET 0xC90 /* Offset in I/O space for ENETROM */ -#define DE425_CFG0 0xC88 /* IRQ register */ -#define DE425_EISAID 0x10a34250 /* EISA device id */ -#define DE425_EISA_IOSIZE 0x100 - -#define DEC_VENDORID 0x1011 -#define CHIPID_21040 0x0002 -#define CHIPID_21140 0x0009 -#define CHIPID_21041 0x0014 -#define CHIPID_21142 0x0019 -#define PCI_VENDORID(x) ((x) & 0xFFFF) -#define PCI_CHIPID(x) (((x) >> 16) & 0xFFFF) - -/* - * Generic SROM Format - * - * - */ - -typedef struct { - u_int8_t sh_idbuf[18]; - u_int8_t sh_version; - u_int8_t sh_adapter_count; - u_int8_t sh_ieee802_address[6]; -} tulip_srom_header_t; - -typedef struct { - u_int8_t sai_device; - u_int8_t sai_leaf_offset_lowbyte; - u_int8_t sai_leaf_offset_highbyte; -} tulip_srom_adapter_info_t; - -typedef enum { - TULIP_SROM_CONNTYPE_10BASET =0x0000, - TULIP_SROM_CONNTYPE_BNC =0x0001, - TULIP_SROM_CONNTYPE_AUI =0x0002, - TULIP_SROM_CONNTYPE_100BASETX =0x0003, - TULIP_SROM_CONNTYPE_100BASET4 =0x0006, - TULIP_SROM_CONNTYPE_100BASEFX =0x0007, - TULIP_SROM_CONNTYPE_MII_10BASET =0x0009, - TULIP_SROM_CONNTYPE_MII_100BASETX =0x000D, - TULIP_SROM_CONNTYPE_MII_100BASET4 =0x000F, - TULIP_SROM_CONNTYPE_MII_100BASEFX =0x0010, - TULIP_SROM_CONNTYPE_10BASET_NWAY =0x0100, - TULIP_SROM_CONNTYPE_10BASET_FD =0x0204, - TULIP_SROM_CONNTYPE_MII_10BASET_FD =0x020A, - TULIP_SROM_CONNTYPE_100BASETX_FD =0x020E, - TULIP_SROM_CONNTYPE_MII_100BASETX_FD =0x0211, - TULIP_SROM_CONNTYPE_10BASET_NOLINKPASS =0x0400, - TULIP_SROM_CONNTYPE_AUTOSENSE =0x0800, - TULIP_SROM_CONNTYPE_AUTOSENSE_POWERUP =0x8800, - TULIP_SROM_CONNTYPE_AUTOSENSE_NWAY =0x9000, - TULIP_SROM_CONNTYPE_NOT_USED =0xFFFF -} tulip_srom_connection_t; - -typedef enum { - TULIP_SROM_MEDIA_10BASET =0x0000, - TULIP_SROM_MEDIA_BNC =0x0001, - TULIP_SROM_MEDIA_AUI =0x0002, - TULIP_SROM_MEDIA_100BASETX =0x0003, - TULIP_SROM_MEDIA_10BASET_FD =0x0004, - TULIP_SROM_MEDIA_100BASETX_FD =0x0005, - TULIP_SROM_MEDIA_100BASET4 =0x0006, - TULIP_SROM_MEDIA_100BASEFX =0x0007, - TULIP_SROM_MEDIA_100BASEFX_FD =0x0008 -} tulip_srom_media_t; - -#define TULIP_SROM_21041_EXTENDED 0x40 - -#define TULIP_SROM_2114X_NOINDICATOR 0x8000 -#define TULIP_SROM_2114X_DEFAULT 0x4000 -#define TULIP_SROM_2114X_POLARITY 0x0080 -#define TULIP_SROM_2114X_CMDBITS(n) (((n) & 0x0071) << 18) -#define TULIP_SROM_2114X_BITPOS(b) (1 << (((b) & 0x0E) >> 1)) - - - -#endif /* !defined(_DC21040_H) */ diff --git a/sys/pci/if_de.c b/sys/pci/if_de.c deleted file mode 100644 index 5ad8dfad5567..000000000000 --- a/sys/pci/if_de.c +++ /dev/null @@ -1,5883 +0,0 @@ -/* $NetBSD: if_de.c,v 1.86 1999/06/01 19:17:59 thorpej Exp $ */ - -/*- - * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com) - * 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. The name of the author may not be used to endorse or promote products - * derived from this software withough specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - * - * Id: if_de.c,v 1.94 1997/07/03 16:55:07 thomas Exp - * - */ - -/* - * DEC 21040 PCI Ethernet Controller - * - * Written by Matt Thomas - * BPF support code stolen directly from if_ec.c - * - * This driver supports the DEC DE435 or any other PCI - * board which support 21040, 21041, or 21140 (mostly). - */ -#define TULIP_HDR_DATA - -#ifdef __NetBSD__ -#include "opt_inet.h" -#include "opt_ns.h" -#endif - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/mbuf.h> -#include <sys/protosw.h> -#include <sys/socket.h> -#include <sys/ioctl.h> -#include <sys/errno.h> -#include <sys/malloc.h> -#include <sys/kernel.h> -#include <sys/proc.h> /* only for declaration of wakeup() used by vm.h */ -#if defined(__FreeBSD__) -#include <machine/clock.h> -#elif defined(__bsdi__) || defined(__NetBSD__) -#include <sys/device.h> -#endif - -#if defined(__NetBSD__) -#include "rnd.h" -#if NRND > 0 -#include <sys/rnd.h> -#endif -#endif - -#include <net/if.h> -#if defined(SIOCSIFMEDIA) && !defined(TULIP_NOIFMEDIA) -#include <net/if_media.h> -#endif -#include <net/if_types.h> -#include <net/if_dl.h> -#include <net/route.h> -#include <net/netisr.h> - -#if defined(__bsdi__) && _BSDI_VERSION >= 199701 -#include <dev/mii/mii.h> -#include <dev/mii/miivar.h> -#endif - -#include "bpfilter.h" -#if NBPFILTER > 0 -#include <net/bpf.h> -#include <net/bpfdesc.h> -#endif - -#ifdef INET -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/in_var.h> -#include <netinet/ip.h> -#endif - -#ifdef NS -#include <netns/ns.h> -#include <netns/ns_if.h> -#endif - -#include <vm/vm.h> -#include <vm/vm_param.h> -#include <vm/vm_kern.h> - -#if defined(__FreeBSD__) -#include <vm/pmap.h> -#include <pci.h> -#include <netinet/if_ether.h> -#if NPCI > 0 -#include <pci/pcivar.h> -#include <pci/dc21040reg.h> -#define DEVAR_INCLUDE "pci/if_devar.h" -#endif -#endif /* __FreeBSD__ */ - -#if defined(__bsdi__) -#include <netinet/if_ether.h> -#include <i386/pci/ic/dc21040reg.h> -#include <i386/isa/isa.h> -#include <i386/isa/icu.h> -#include <i386/isa/dma.h> -#include <i386/isa/isavar.h> -#include <i386/pci/pci.h> -#if _BSDI_VERSION < 199510 -#include <eisa.h> -#else -#define NEISA 0 -#endif -#if NEISA > 0 && _BSDI_VERSION >= 199401 -#include <i386/eisa/eisa.h> -#define TULIP_EISA -#endif -#define DEVAR_INCLUDE "i386/pci/if_devar.h" -#endif /* __bsdi__ */ - -#if defined(__NetBSD__) -#include <net/if_ether.h> -#if defined(INET) -#include <netinet/if_inarp.h> -#endif -#include <machine/bus.h> -#include <machine/intr.h> -#include <dev/pci/pcireg.h> -#include <dev/pci/pcivar.h> -#include <dev/ic/dc21040reg.h> -#define DEVAR_INCLUDE "dev/pci/if_devar.h" -#endif /* __NetBSD__ */ - -/* - * Intel CPUs should use I/O mapped access. - */ -#if defined(__i386__) || defined(TULIP_EISA) -#define TULIP_IOMAPPED -#endif - -#if 0 -/* - * This turns on all sort of debugging stuff and make the - * driver much larger. - */ -#define TULIP_DEBUG -#endif - -#if 0 -#define TULIP_PERFSTATS -#endif - -#if 0 -#define TULIP_USE_SOFTINTR -#endif - -#define TULIP_HZ 10 - -#include DEVAR_INCLUDE -/* - * This module supports - * the DEC 21040 PCI Ethernet Controller. - * the DEC 21041 PCI Ethernet Controller. - * the DEC 21140 PCI Fast Ethernet Controller. - */ -static void tulip_mii_autonegotiate(tulip_softc_t * const sc, const unsigned phyaddr); -static tulip_intrfunc_t tulip_intr_shared(void *arg); -static tulip_intrfunc_t tulip_intr_normal(void *arg); -static void tulip_init(tulip_softc_t * const sc); -static void tulip_reset(tulip_softc_t * const sc); -static ifnet_ret_t tulip_ifstart_one(struct ifnet *ifp); -static ifnet_ret_t tulip_ifstart(struct ifnet *ifp); -static struct mbuf *tulip_txput(tulip_softc_t * const sc, struct mbuf *m); -static void tulip_txput_setup(tulip_softc_t * const sc); -static void tulip_rx_intr(tulip_softc_t * const sc); -static void tulip_addr_filter(tulip_softc_t * const sc); -static unsigned tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno); -static void tulip_mii_writereg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data); -static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities); -static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t * const sc); -static int tulip_srom_decode(tulip_softc_t * const sc); -#if defined(IFM_ETHER) -static int tulip_ifmedia_change(struct ifnet * const ifp); -static void tulip_ifmedia_status(struct ifnet * const ifp, struct ifmediareq *req); -#endif -/* static void tulip_21140_map_media(tulip_softc_t *sc); */ - -static void -tulip_timeout_callback( - void *arg) -{ - tulip_softc_t * const sc = arg; - tulip_spl_t s = TULIP_RAISESPL(); - - TULIP_PERFSTART(timeout) - - sc->tulip_flags &= ~TULIP_TIMEOUTPENDING; - sc->tulip_probe_timeout -= 1000 / TULIP_HZ; - (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER); - - TULIP_PERFEND(timeout); - TULIP_RESTORESPL(s); -} - -static void -tulip_timeout( - tulip_softc_t * const sc) -{ - if (sc->tulip_flags & TULIP_TIMEOUTPENDING) - return; - sc->tulip_flags |= TULIP_TIMEOUTPENDING; - timeout(tulip_timeout_callback, sc, (hz + TULIP_HZ / 2) / TULIP_HZ); -} - -#if defined(TULIP_NEED_FASTTIMEOUT) -static void -tulip_fasttimeout_callback( - void *arg) -{ - tulip_softc_t * const sc = arg; - tulip_spl_t s = TULIP_RAISESPL(); - - sc->tulip_flags &= ~TULIP_FASTTIMEOUTPENDING; - (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_FASTTIMER); - TULIP_RESTORESPL(s); -} - -static void -tulip_fasttimeout( - tulip_softc_t * const sc) -{ - if (sc->tulip_flags & TULIP_FASTTIMEOUTPENDING) - return; - sc->tulip_flags |= TULIP_FASTTIMEOUTPENDING; - timeout(tulip_fasttimeout_callback, sc, 1); -} -#endif - -static int -tulip_txprobe( - tulip_softc_t * const sc) -{ - struct mbuf *m; - /* - * Before we are sure this is the right media we need - * to send a small packet to make sure there's carrier. - * Strangely, BNC and AUI will "see" receive data if - * either is connected so the transmit is the only way - * to verify the connectivity. - */ - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m == NULL) - return 0; - /* - * Construct a LLC TEST message which will point to ourselves. - */ - bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6); - bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6); - mtod(m, struct ether_header *)->ether_type = htons(3); - mtod(m, unsigned char *)[14] = 0; - mtod(m, unsigned char *)[15] = 0; - mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */ - m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3; - /* - * send it! - */ - sc->tulip_cmdmode |= TULIP_CMD_TXRUN; - sc->tulip_intrmask |= TULIP_STS_TXINTR; - sc->tulip_flags |= TULIP_TXPROBE_ACTIVE; - TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); - TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); - if ((m = tulip_txput(sc, m)) != NULL) - m_freem(m); - sc->tulip_probe.probe_txprobes++; - return 1; -} - -#ifdef BIG_PACKET -#define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0) -#else -#define TULIP_SIAGEN_WATCHDOG 0 -#endif - -static void -tulip_media_set( - tulip_softc_t * const sc, - tulip_media_t media) -{ - const tulip_media_info_t *mi = sc->tulip_mediums[media]; - - if (mi == NULL) - return; - - /* - * If we are switching media, make sure we don't think there's - * any stale RX activity - */ - sc->tulip_flags &= ~TULIP_RXACT; - if (mi->mi_type == TULIP_MEDIAINFO_SIA) { - TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); - TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx); - if (sc->tulip_features & TULIP_HAVE_SIAGP) { - TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG); - DELAY(50); - TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG); - } else { - TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG); - } - TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity); - } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) { -#define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL) - /* - * If the cmdmode bits don't match the currently operating mode, - * set the cmdmode appropriately and reset the chip. - */ - if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) { - sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS; - sc->tulip_cmdmode |= mi->mi_cmdmode; - tulip_reset(sc); - } - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit); - DELAY(10); - TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata); - } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) { - /* - * If the cmdmode bits don't match the currently operating mode, - * set the cmdmode appropriately and reset the chip. - */ - if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) { - sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS; - sc->tulip_cmdmode |= mi->mi_cmdmode; - tulip_reset(sc); - } - TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol); - TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata); - } else if (mi->mi_type == TULIP_MEDIAINFO_MII - && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) { - int idx; - if (sc->tulip_features & TULIP_HAVE_SIAGP) { - const u_int8_t *dp; - dp = &sc->tulip_rombuf[mi->mi_reset_offset]; - for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) { - DELAY(10); - TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16); - } - sc->tulip_phyaddr = mi->mi_phyaddr; - dp = &sc->tulip_rombuf[mi->mi_gpr_offset]; - for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) { - DELAY(10); - TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16); - } - } else { - for (idx = 0; idx < mi->mi_reset_length; idx++) { - DELAY(10); - TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]); - } - sc->tulip_phyaddr = mi->mi_phyaddr; - for (idx = 0; idx < mi->mi_gpr_length; idx++) { - DELAY(10); - TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]); - } - } - if (sc->tulip_flags & TULIP_TRYNWAY) { - tulip_mii_autonegotiate(sc, sc->tulip_phyaddr); - } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) { - u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL); - data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE); - sc->tulip_flags &= ~TULIP_DIDNWAY; - if (TULIP_IS_MEDIA_FD(media)) - data |= PHYCTL_FULL_DUPLEX; - if (TULIP_IS_MEDIA_100MB(media)) - data |= PHYCTL_SELECT_100MB; - tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data); - } - } -} - -static void -tulip_linkup( - tulip_softc_t * const sc, - tulip_media_t media) -{ - if ((sc->tulip_flags & TULIP_LINKUP) == 0) - sc->tulip_flags |= TULIP_PRINTLINKUP; - sc->tulip_flags |= TULIP_LINKUP; - sc->tulip_if.if_flags &= ~IFF_OACTIVE; -#if 0 /* XXX how does with work with ifmedia? */ - if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) { - if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) { - if (TULIP_CAN_MEDIA_FD(media) - && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL) - media = TULIP_FD_MEDIA_OF(media); - } else { - if (TULIP_IS_MEDIA_FD(media) - && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL) - media = TULIP_HD_MEDIA_OF(media); - } - } -#endif - if (sc->tulip_media != media) { -#ifdef TULIP_DEBUG - sc->tulip_dbg.dbg_last_media = sc->tulip_media; -#endif - sc->tulip_media = media; - sc->tulip_flags |= TULIP_PRINTMEDIA; - if (TULIP_IS_MEDIA_FD(sc->tulip_media)) { - sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX; - } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) { - sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; - } - } - /* - * We could set probe_timeout to 0 but setting to 3000 puts this - * in one central place and the only matters is tulip_link is - * followed by a tulip_timeout. Therefore setting it should not - * result in aberrant behavour. - */ - sc->tulip_probe_timeout = 3000; - sc->tulip_probe_state = TULIP_PROBE_INACTIVE; - sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY); - if (sc->tulip_flags & TULIP_INRESET) { - tulip_media_set(sc, sc->tulip_media); - } else if (sc->tulip_probe_media != sc->tulip_media) { - /* - * No reason to change media if we have the right media. - */ - tulip_reset(sc); - } - tulip_init(sc); -} - -static void -tulip_media_print( - tulip_softc_t * const sc) -{ - if ((sc->tulip_flags & TULIP_LINKUP) == 0) - return; - if (sc->tulip_flags & TULIP_PRINTMEDIA) { - printf(TULIP_PRINTF_FMT ": enabling %s port\n", - TULIP_PRINTF_ARGS, - tulip_mediums[sc->tulip_media]); - sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP); - } else if (sc->tulip_flags & TULIP_PRINTLINKUP) { - printf(TULIP_PRINTF_FMT ": link up\n", TULIP_PRINTF_ARGS); - sc->tulip_flags &= ~TULIP_PRINTLINKUP; - } -} - -#if defined(TULIP_DO_GPR_SENSE) -static tulip_media_t -tulip_21140_gpr_media_sense( - tulip_softc_t * const sc) -{ - tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN; - tulip_media_t last_media = TULIP_MEDIA_UNKNOWN; - tulip_media_t media; - - /* - * If one of the media blocks contained a default media flag, - * use that. - */ - for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) { - const tulip_media_info_t *mi; - /* - * Media is not supported (or is full-duplex). - */ - if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media)) - continue; - if (mi->mi_type != TULIP_MEDIAINFO_GPR) - continue; - - /* - * Remember the media is this is the "default" media. - */ - if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN) - maybe_media = media; - - /* - * No activity mask? Can't see if it is active if there's no mask. - */ - if (mi->mi_actmask == 0) - continue; - - /* - * Does the activity data match? - */ - if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata) - continue; - -#if defined(TULIP_DEBUG) - printf(TULIP_PRINTF_FMT ": gpr_media_sense: %s: 0x%02x & 0x%02x == 0x%02x\n", - TULIP_PRINTF_ARGS, tulip_mediums[media], - TULIP_CSR_READ(sc, csr_gp) & 0xFF, - mi->mi_actmask, mi->mi_actdata); -#endif - /* - * It does! If this is the first media we detected, then - * remember this media. If isn't the first, then there were - * multiple matches which we equate to no match (since we don't - * which to select (if any). - */ - if (last_media == TULIP_MEDIA_UNKNOWN) { - last_media = media; - } else if (last_media != media) { - last_media = TULIP_MEDIA_UNKNOWN; - } - } - return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media; -} -#endif /* TULIP_DO_GPR_SENSE */ - -static tulip_link_status_t -tulip_media_link_monitor( - tulip_softc_t * const sc) -{ - const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media]; - tulip_link_status_t linkup = TULIP_LINK_DOWN; - - if (mi == NULL) { -#if defined(DIAGNOSTIC) || defined(TULIP_DEBUG) - panic("tulip_media_link_monitor: %s: botch at line %d\n", - tulip_mediums[sc->tulip_media],__LINE__); -#endif - return TULIP_LINK_UNKNOWN; - } - - - /* - * Have we seen some packets? If so, the link must be good. - */ - if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) { - sc->tulip_flags &= ~TULIP_RXACT; - sc->tulip_probe_timeout = 3000; - return TULIP_LINK_UP; - } - - sc->tulip_flags &= ~TULIP_RXACT; - if (mi->mi_type == TULIP_MEDIAINFO_MII) { - u_int32_t status; - /* - * Read the PHY status register. - */ - status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS); - if (status & PHYSTS_AUTONEG_DONE) { - /* - * If the PHY has completed autonegotiation, see the if the - * remote systems abilities have changed. If so, upgrade or - * downgrade as appropriate. - */ - u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES); - abilities = (abilities << 6) & status; - if (abilities != sc->tulip_abilities) { -#if defined(TULIP_DEBUG) - loudprintf(TULIP_PRINTF_FMT "(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n", - TULIP_PRINTF_ARGS, sc->tulip_phyaddr, - sc->tulip_abilities, abilities); -#endif - if (tulip_mii_map_abilities(sc, abilities)) { - tulip_linkup(sc, sc->tulip_probe_media); - return TULIP_LINK_UP; - } - /* - * if we had selected media because of autonegotiation, - * we need to probe for the new media. - */ - sc->tulip_probe_state = TULIP_PROBE_INACTIVE; - if (sc->tulip_flags & TULIP_DIDNWAY) - return TULIP_LINK_DOWN; - } - } - /* - * The link is now up. If was down, say its back up. - */ - if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP) - linkup = TULIP_LINK_UP; - } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) { - /* - * No activity sensor? Assume all's well. - */ - if (mi->mi_actmask == 0) - return TULIP_LINK_UNKNOWN; - /* - * Does the activity data match? - */ - if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata) - linkup = TULIP_LINK_UP; - } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) { - /* - * Assume non TP ok for now. - */ - if (!TULIP_IS_MEDIA_TP(sc->tulip_media)) - return TULIP_LINK_UNKNOWN; - if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0) - linkup = TULIP_LINK_UP; -#if defined(TULIP_DEBUG) - if (sc->tulip_probe_timeout <= 0) - printf(TULIP_PRINTF_FMT ": sia status = 0x%08x\n", TULIP_PRINTF_ARGS, TULIP_CSR_READ(sc, csr_sia_status)); -#endif - } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) { - return TULIP_LINK_UNKNOWN; - } - /* - * We will wait for 3 seconds until the link goes into suspect mode. - */ - if (sc->tulip_flags & TULIP_LINKUP) { - if (linkup == TULIP_LINK_UP) - sc->tulip_probe_timeout = 3000; - if (sc->tulip_probe_timeout > 0) - return TULIP_LINK_UP; - - sc->tulip_flags &= ~TULIP_LINKUP; - printf(TULIP_PRINTF_FMT ": link down: cable problem?\n", TULIP_PRINTF_ARGS); - } -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_link_downed++; -#endif - return TULIP_LINK_DOWN; -} - -static void -tulip_media_poll( - tulip_softc_t * const sc, - tulip_mediapoll_event_t event) -{ -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_events[event]++; -#endif - if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE - && event == TULIP_MEDIAPOLL_TIMER) { - switch (tulip_media_link_monitor(sc)) { - case TULIP_LINK_DOWN: { - /* - * Link Monitor failed. Probe for new media. - */ - event = TULIP_MEDIAPOLL_LINKFAIL; - break; - } - case TULIP_LINK_UP: { - /* - * Check again soon. - */ - tulip_timeout(sc); - return; - } - case TULIP_LINK_UNKNOWN: { - /* - * We can't tell so don't bother. - */ - return; - } - } - } - - if (event == TULIP_MEDIAPOLL_LINKFAIL) { - if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) { - if (TULIP_DO_AUTOSENSE(sc)) { -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_link_failures++; -#endif - sc->tulip_media = TULIP_MEDIA_UNKNOWN; - if (sc->tulip_if.if_flags & IFF_UP) - tulip_reset(sc); /* restart probe */ - } - return; - } -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_link_pollintrs++; -#endif - } - - if (event == TULIP_MEDIAPOLL_START) { - sc->tulip_if.if_flags |= IFF_OACTIVE; - if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE) - return; - sc->tulip_probe_mediamask = 0; - sc->tulip_probe_passes = 0; -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_media_probes++; -#endif - /* - * If the SROM contained an explicit media to use, use it. - */ - sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX); - sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS; - sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP); - /* - * connidx is defaulted to a media_unknown type. - */ - sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media; - if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) { - tulip_linkup(sc, sc->tulip_probe_media); - tulip_timeout(sc); - return; - } - - if (sc->tulip_features & TULIP_HAVE_GPR) { - sc->tulip_probe_state = TULIP_PROBE_GPRTEST; - sc->tulip_probe_timeout = 2000; - } else { - sc->tulip_probe_media = TULIP_MEDIA_MAX; - sc->tulip_probe_timeout = 0; - sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; - } - } - - /* - * Ignore txprobe failures or spurious callbacks. - */ - if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED - && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) { - sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; - return; - } - - /* - * If we really transmitted a packet, then that's the media we'll use. - */ - if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) { - if (event == TULIP_MEDIAPOLL_LINKPASS) { - /* XXX Check media status just to be sure */ - sc->tulip_probe_media = TULIP_MEDIA_10BASET; -#if defined(TULIP_DEBUG) - } else { - sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++; -#endif - } - tulip_linkup(sc, sc->tulip_probe_media); - tulip_timeout(sc); - return; - } - - if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) { -#if defined(TULIP_DO_GPR_SENSE) - /* - * Check for media via the general purpose register. - * - * Try to sense the media via the GPR. If the same value - * occurs 3 times in a row then just use that. - */ - if (sc->tulip_probe_timeout > 0) { - tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc); -#if defined(TULIP_DEBUG) - printf(TULIP_PRINTF_FMT ": media_poll: gpr sensing = %s\n", - TULIP_PRINTF_ARGS, tulip_mediums[new_probe_media]); -#endif - if (new_probe_media != TULIP_MEDIA_UNKNOWN) { - if (new_probe_media == sc->tulip_probe_media) { - if (--sc->tulip_probe_count == 0) - tulip_linkup(sc, sc->tulip_probe_media); - } else { - sc->tulip_probe_count = 10; - } - } - sc->tulip_probe_media = new_probe_media; - tulip_timeout(sc); - return; - } -#endif /* TULIP_DO_GPR_SENSE */ - /* - * Brute force. We cycle through each of the media types - * and try to transmit a packet. - */ - sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; - sc->tulip_probe_media = TULIP_MEDIA_MAX; - sc->tulip_probe_timeout = 0; - tulip_timeout(sc); - return; - } - - if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST - && (sc->tulip_features & TULIP_HAVE_MII)) { - tulip_media_t old_media = sc->tulip_probe_media; - tulip_mii_autonegotiate(sc, sc->tulip_phyaddr); - switch (sc->tulip_probe_state) { - case TULIP_PROBE_FAILED: - case TULIP_PROBE_MEDIATEST: { - /* - * Try the next media. - */ - sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask; - sc->tulip_probe_timeout = 0; -#ifdef notyet - if (sc->tulip_probe_state == TULIP_PROBE_FAILED) - break; - if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc)) - break; - sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300; -#endif - break; - } - case TULIP_PROBE_PHYAUTONEG: { - return; - } - case TULIP_PROBE_INACTIVE: { - /* - * Only probe if we autonegotiated a media that hasn't failed. - */ - sc->tulip_probe_timeout = 0; - if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) { - sc->tulip_probe_media = old_media; - break; - } - tulip_linkup(sc, sc->tulip_probe_media); - tulip_timeout(sc); - return; - } - default: { -#if defined(DIAGNOSTIC) || defined(TULIP_DEBUG) - panic("tulip_media_poll: botch at line %d\n", __LINE__); -#endif - break; - } - } - } - - if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) { -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++; -#endif - sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; - return; - } - - /* - * switch to another media if we tried this one enough. - */ - if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) { -#if defined(TULIP_DEBUG) - if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) { - printf(TULIP_PRINTF_FMT ": poll media unknown!\n", - TULIP_PRINTF_ARGS); - sc->tulip_probe_media = TULIP_MEDIA_MAX; - } -#endif - /* - * Find the next media type to check for. Full Duplex - * types are not allowed. - */ - do { - sc->tulip_probe_media -= 1; - if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) { - if (++sc->tulip_probe_passes == 3) { - printf(TULIP_PRINTF_FMT ": autosense failed: cable problem?\n", - TULIP_PRINTF_ARGS); - if ((sc->tulip_if.if_flags & IFF_UP) == 0) { - sc->tulip_if.if_flags &= ~IFF_RUNNING; - sc->tulip_probe_state = TULIP_PROBE_INACTIVE; - return; - } - } - sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */ - sc->tulip_probe_mediamask = 0; - sc->tulip_probe_media = TULIP_MEDIA_MAX - 1; - } - } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL - || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) - || TULIP_IS_MEDIA_FD(sc->tulip_probe_media)); - -#if defined(TULIP_DEBUG) - printf(TULIP_PRINTF_FMT ": %s: probing %s\n", TULIP_PRINTF_ARGS, - event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout", - tulip_mediums[sc->tulip_probe_media]); -#endif - sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000; - sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; - sc->tulip_probe.probe_txprobes = 0; - tulip_reset(sc); - tulip_media_set(sc, sc->tulip_probe_media); - sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; - } - tulip_timeout(sc); - - /* - * If this is hanging off a phy, we know are doing NWAY and we have - * forced the phy to a specific speed. Wait for link up before - * before sending a packet. - */ - switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) { - case TULIP_MEDIAINFO_MII: { - if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc)) - return; - break; - } - case TULIP_MEDIAINFO_SIA: { - if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) { - if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) - return; - tulip_linkup(sc, sc->tulip_probe_media); -#ifdef notyet - if (sc->tulip_features & TULIP_HAVE_MII) - tulip_timeout(sc); -#endif - return; - } - break; - } - case TULIP_MEDIAINFO_RESET: - case TULIP_MEDIAINFO_SYM: - case TULIP_MEDIAINFO_NONE: - case TULIP_MEDIAINFO_GPR: { - break; - } - } - /* - * Try to send a packet. - */ - tulip_txprobe(sc); -} - -static void -tulip_media_select( - tulip_softc_t * const sc) -{ - if (sc->tulip_features & TULIP_HAVE_GPR) { - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit); - DELAY(10); - TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata); - } - /* - * If this board has no media, just return - */ - if (sc->tulip_features & TULIP_HAVE_NOMEDIA) - return; - - if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) { - TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); - (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START); - } else { - tulip_media_set(sc, sc->tulip_media); - } -} - -static void -tulip_21040_mediainfo_init( - tulip_softc_t * const sc, - tulip_media_t media) -{ - sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160 - |TULIP_CMD_BACKOFFCTR; - sc->tulip_if.if_baudrate = 10000000; - - if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) { - TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET); - TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD); - sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; - } - - if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) { - TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC); - } - - if (media == TULIP_MEDIA_UNKNOWN) { - TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA); - } -} - -static void -tulip_21040_media_probe( - tulip_softc_t * const sc) -{ - tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN); - return; -} - -static void -tulip_21040_10baset_only_media_probe( - tulip_softc_t * const sc) -{ - tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET); - tulip_media_set(sc, TULIP_MEDIA_10BASET); - sc->tulip_media = TULIP_MEDIA_10BASET; -} - -static void -tulip_21040_10baset_only_media_select( - tulip_softc_t * const sc) -{ - sc->tulip_flags |= TULIP_LINKUP; - if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) { - sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX; - sc->tulip_flags &= ~TULIP_SQETEST; - } else { - sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; - sc->tulip_flags |= TULIP_SQETEST; - } - tulip_media_set(sc, sc->tulip_media); -} - -static void -tulip_21040_auibnc_only_media_probe( - tulip_softc_t * const sc) -{ - tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC); - sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP; - tulip_media_set(sc, TULIP_MEDIA_AUIBNC); - sc->tulip_media = TULIP_MEDIA_AUIBNC; -} - -static void -tulip_21040_auibnc_only_media_select( - tulip_softc_t * const sc) -{ - tulip_media_set(sc, TULIP_MEDIA_AUIBNC); - sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; -} - -static const tulip_boardsw_t tulip_21040_boardsw = { - TULIP_21040_GENERIC, - tulip_21040_media_probe, - tulip_media_select, - tulip_media_poll, -}; - -static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = { - TULIP_21040_GENERIC, - tulip_21040_10baset_only_media_probe, - tulip_21040_10baset_only_media_select, - NULL, -}; - -static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = { - TULIP_21040_GENERIC, - tulip_21040_auibnc_only_media_probe, - tulip_21040_auibnc_only_media_select, - NULL, -}; - -static void -tulip_21041_mediainfo_init( - tulip_softc_t * const sc) -{ - tulip_media_info_t * const mi = sc->tulip_mediainfo; - -#ifdef notyet - if (sc->tulip_revinfo >= 0x20) { - TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET); - TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD); - TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI); - TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC); - return; - } -#endif - TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET); - TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD); - TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI); - TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC); -} - -static void -tulip_21041_media_probe( - tulip_softc_t * const sc) -{ - sc->tulip_if.if_baudrate = 10000000; - sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT - |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR; - sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; - tulip_21041_mediainfo_init(sc); -} - -static void -tulip_21041_media_poll( - tulip_softc_t * const sc, - const tulip_mediapoll_event_t event) -{ - u_int32_t sia_status; - -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_events[event]++; -#endif - - if (event == TULIP_MEDIAPOLL_LINKFAIL) { - if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE - || !TULIP_DO_AUTOSENSE(sc)) - return; - sc->tulip_media = TULIP_MEDIA_UNKNOWN; - tulip_reset(sc); /* start probe */ - return; - } - - /* - * If we've been been asked to start a poll or link change interrupt - * restart the probe (and reset the tulip to a known state). - */ - if (event == TULIP_MEDIAPOLL_START) { - sc->tulip_if.if_flags |= IFF_OACTIVE; - sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN); -#ifdef notyet - if (sc->tulip_revinfo >= 0x20) { - sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX; - sc->tulip_flags |= TULIP_DIDNWAY; - } -#endif - TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); - sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; - sc->tulip_probe_media = TULIP_MEDIA_10BASET; - sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT; - tulip_media_set(sc, TULIP_MEDIA_10BASET); - tulip_timeout(sc); - return; - } - - if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) - return; - - if (event == TULIP_MEDIAPOLL_TXPROBE_OK) { -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++; -#endif - tulip_linkup(sc, sc->tulip_probe_media); - return; - } - - sia_status = TULIP_CSR_READ(sc, csr_sia_status); - TULIP_CSR_WRITE(sc, csr_sia_status, sia_status); - if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) { - if (sc->tulip_revinfo >= 0x20) { - if (sia_status & (PHYSTS_10BASET_FD << (16 - 6))) - sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD; - } - /* - * If the link has passed LinkPass, 10baseT is the - * proper media to use. - */ - tulip_linkup(sc, sc->tulip_probe_media); - return; - } - - /* - * wait for up to 2.4 seconds for the link to reach pass state. - * Only then start scanning the other media for activity. - * choose media with receive activity over those without. - */ - if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) { - if (event != TULIP_MEDIAPOLL_TIMER) - return; - if (sc->tulip_probe_timeout > 0 - && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) { - tulip_timeout(sc); - return; - } - sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; - sc->tulip_flags |= TULIP_WANTRXACT; - if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) { - sc->tulip_probe_media = TULIP_MEDIA_BNC; - } else { - sc->tulip_probe_media = TULIP_MEDIA_AUI; - } - tulip_media_set(sc, sc->tulip_probe_media); - tulip_timeout(sc); - return; - } - - /* - * If we failed, clear the txprobe active flag. - */ - if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) - sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; - - - if (event == TULIP_MEDIAPOLL_TIMER) { - /* - * If we've received something, then that's our link! - */ - if (sc->tulip_flags & TULIP_RXACT) { - tulip_linkup(sc, sc->tulip_probe_media); - return; - } - /* - * if no txprobe active - */ - if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0 - && ((sc->tulip_flags & TULIP_WANTRXACT) == 0 - || (sia_status & TULIP_SIASTS_RXACTIVITY))) { - sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; - tulip_txprobe(sc); - tulip_timeout(sc); - return; - } - /* - * Take 2 passes through before deciding to not - * wait for receive activity. Then take another - * two passes before spitting out a warning. - */ - if (sc->tulip_probe_timeout <= 0) { - if (sc->tulip_flags & TULIP_WANTRXACT) { - sc->tulip_flags &= ~TULIP_WANTRXACT; - sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; - } else { - printf(TULIP_PRINTF_FMT ": autosense failed: cable problem?\n", - TULIP_PRINTF_ARGS); - if ((sc->tulip_if.if_flags & IFF_UP) == 0) { - sc->tulip_if.if_flags &= ~IFF_RUNNING; - sc->tulip_probe_state = TULIP_PROBE_INACTIVE; - return; - } - } - } - } - - /* - * Since this media failed to probe, try the other one. - */ - sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT; - if (sc->tulip_probe_media == TULIP_MEDIA_AUI) { - sc->tulip_probe_media = TULIP_MEDIA_BNC; - } else { - sc->tulip_probe_media = TULIP_MEDIA_AUI; - } - tulip_media_set(sc, sc->tulip_probe_media); - sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; - tulip_timeout(sc); -} - -static const tulip_boardsw_t tulip_21041_boardsw = { - TULIP_21041_GENERIC, - tulip_21041_media_probe, - tulip_media_select, - tulip_21041_media_poll -}; - -static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = { - { 0x20005c00, 0, /* 08-00-17 */ - { - { 0x19, 0x0040, 0x0040 }, /* 10TX */ - { 0x19, 0x0040, 0x0000 }, /* 100TX */ - }, -#if defined(TULIP_DEBUG) - "NS DP83840", -#endif - }, - { 0x0281F400, 0, /* 00-A0-7D */ - { - { 0x12, 0x0010, 0x0000 }, /* 10T */ - { }, /* 100TX */ - { 0x12, 0x0010, 0x0010 }, /* 100T4 */ - { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */ - }, -#if defined(TULIP_DEBUG) - "Seeq 80C240" -#endif - }, -#if 0 - { 0x0015F420, 0, /* 00-A0-7D */ - { - { 0x12, 0x0010, 0x0000 }, /* 10T */ - { }, /* 100TX */ - { 0x12, 0x0010, 0x0010 }, /* 100T4 */ - { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */ - }, -#if defined(TULIP_DEBUG) - "Broadcom BCM5000" -#endif - }, -#endif - { 0x0281F400, 0, /* 00-A0-BE */ - { - { 0x11, 0x8000, 0x0000 }, /* 10T */ - { 0x11, 0x8000, 0x8000 }, /* 100TX */ - { }, /* 100T4 */ - { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */ - }, -#if defined(TULIP_DEBUG) - "ICS 1890" -#endif - }, - { 0 } -}; - -static tulip_media_t -tulip_mii_phy_readspecific( - tulip_softc_t * const sc) -{ - const tulip_phy_attr_t *attr; - u_int16_t data; - u_int32_t id; - unsigned idx = 0; - static const tulip_media_t table[] = { - TULIP_MEDIA_UNKNOWN, - TULIP_MEDIA_10BASET, - TULIP_MEDIA_100BASETX, - TULIP_MEDIA_100BASET4, - TULIP_MEDIA_UNKNOWN, - TULIP_MEDIA_10BASET_FD, - TULIP_MEDIA_100BASETX_FD, - TULIP_MEDIA_UNKNOWN - }; - - /* - * Don't read phy specific registers if link is not up. - */ - data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS); - if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) - return TULIP_MEDIA_UNKNOWN; - - id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) | - tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH); - for (attr = tulip_mii_phy_attrlist;; attr++) { - if (attr->attr_id == 0) - return TULIP_MEDIA_UNKNOWN; - if ((id & ~0x0F) == attr->attr_id) - break; - } - - if (attr->attr_modes[PHY_MODE_100TX].pm_regno) { - const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX]; - data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); - if ((data & pm->pm_mask) == pm->pm_value) - idx = 2; - } - if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) { - const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4]; - data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); - if ((data & pm->pm_mask) == pm->pm_value) - idx = 3; - } - if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) { - const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T]; - data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); - if ((data & pm->pm_mask) == pm->pm_value) - idx = 1; - } - if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) { - const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX]; - data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno); - idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0); - } - return table[idx]; -} - -static unsigned -tulip_mii_get_phyaddr( - tulip_softc_t * const sc, - unsigned offset) -{ - unsigned phyaddr; - - for (phyaddr = 1; phyaddr < 32; phyaddr++) { - unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS); - if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET) - continue; - if (offset == 0) - return phyaddr; - offset--; - } - if (offset == 0) { - unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS); - if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET) - return TULIP_MII_NOPHY; - return 0; - } - return TULIP_MII_NOPHY; -} - -static int -tulip_mii_map_abilities( - tulip_softc_t * const sc, - unsigned abilities) -{ - sc->tulip_abilities = abilities; - if (abilities & PHYSTS_100BASETX_FD) { - sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD; - } else if (abilities & PHYSTS_100BASET4) { - sc->tulip_probe_media = TULIP_MEDIA_100BASET4; - } else if (abilities & PHYSTS_100BASETX) { - sc->tulip_probe_media = TULIP_MEDIA_100BASETX; - } else if (abilities & PHYSTS_10BASET_FD) { - sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD; - } else if (abilities & PHYSTS_10BASET) { - sc->tulip_probe_media = TULIP_MEDIA_10BASET; - } else { - sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; - return 0; - } - sc->tulip_probe_state = TULIP_PROBE_INACTIVE; - return 1; -} - -static void -tulip_mii_autonegotiate( - tulip_softc_t * const sc, - const unsigned phyaddr) -{ - switch (sc->tulip_probe_state) { - case TULIP_PROBE_MEDIATEST: - case TULIP_PROBE_INACTIVE: { - sc->tulip_flags |= TULIP_DIDNWAY; - tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET); - sc->tulip_probe_timeout = 3000; - sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR; - sc->tulip_probe_state = TULIP_PROBE_PHYRESET; - /* FALL THROUGH */ - } - case TULIP_PROBE_PHYRESET: { - u_int32_t status; - u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL); - if (data & PHYCTL_RESET) { - if (sc->tulip_probe_timeout > 0) { - tulip_timeout(sc); - return; - } - printf(TULIP_PRINTF_FMT "(phy%d): error: reset of PHY never completed!\n", - TULIP_PRINTF_ARGS, phyaddr); - sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE; - sc->tulip_probe_state = TULIP_PROBE_FAILED; - sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING); - return; - } - status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS); - if ((status & PHYSTS_CAN_AUTONEG) == 0) { -#if defined(TULIP_DEBUG) - loudprintf(TULIP_PRINTF_FMT "(phy%d): autonegotiation disabled\n", - TULIP_PRINTF_ARGS, phyaddr); -#endif - sc->tulip_flags &= ~TULIP_DIDNWAY; - sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; - return; - } - if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01)) - tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01); - tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE); - data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL); -#if defined(TULIP_DEBUG) - if ((data & PHYCTL_AUTONEG_ENABLE) == 0) - loudprintf(TULIP_PRINTF_FMT "(phy%d): oops: enable autonegotiation failed: 0x%04x\n", - TULIP_PRINTF_ARGS, phyaddr, data); - else - loudprintf(TULIP_PRINTF_FMT "(phy%d): autonegotiation restarted: 0x%04x\n", - TULIP_PRINTF_ARGS, phyaddr, data); - sc->tulip_dbg.dbg_nway_starts++; -#endif - sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG; - sc->tulip_probe_timeout = 3000; - /* FALL THROUGH */ - } - case TULIP_PROBE_PHYAUTONEG: { - u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS); - u_int32_t data; - if ((status & PHYSTS_AUTONEG_DONE) == 0) { - if (sc->tulip_probe_timeout > 0) { - tulip_timeout(sc); - return; - } -#if defined(TULIP_DEBUG) - loudprintf(TULIP_PRINTF_FMT "(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n", - TULIP_PRINTF_ARGS, phyaddr, status, - tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL)); -#endif - sc->tulip_flags &= ~TULIP_DIDNWAY; - sc->tulip_probe_state = TULIP_PROBE_MEDIATEST; - return; - } - data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES); -#if defined(TULIP_DEBUG) - loudprintf(TULIP_PRINTF_FMT "(phy%d): autonegotiation complete: 0x%04x\n", - TULIP_PRINTF_ARGS, phyaddr, data); -#endif - data = (data << 6) & status; - if (!tulip_mii_map_abilities(sc, data)) - sc->tulip_flags &= ~TULIP_DIDNWAY; - return; - } - default: { -#if defined(DIAGNOSTIC) - panic("tulip_media_poll: botch at line %d\n", __LINE__); -#endif - break; - } - } -#if defined(TULIP_DEBUG) - loudprintf(TULIP_PRINTF_FMT "(phy%d): autonegotiation failure: state = %d\n", - TULIP_PRINTF_ARGS, phyaddr, sc->tulip_probe_state); - sc->tulip_dbg.dbg_nway_failures++; -#endif -} - -static void -tulip_2114x_media_preset( - tulip_softc_t * const sc) -{ - const tulip_media_info_t *mi = NULL; - tulip_media_t media = sc->tulip_media; - - if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) - media = sc->tulip_media; - else - media = sc->tulip_probe_media; - - sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT; - sc->tulip_flags &= ~TULIP_SQETEST; - if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) { -#if defined(TULIP_DEBUG) - if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) { -#endif - mi = sc->tulip_mediums[media]; - if (mi->mi_type == TULIP_MEDIAINFO_MII) { - sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT; - } else if (mi->mi_type == TULIP_MEDIAINFO_GPR - || mi->mi_type == TULIP_MEDIAINFO_SYM) { - sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS; - sc->tulip_cmdmode |= mi->mi_cmdmode; - } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) { - TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET); - } -#if defined(TULIP_DEBUG) - } else { - printf(TULIP_PRINTF_FMT ": preset: bad media %d!\n", - TULIP_PRINTF_ARGS, media); - } -#endif - } - switch (media) { - case TULIP_MEDIA_BNC: - case TULIP_MEDIA_AUI: - case TULIP_MEDIA_10BASET: { - sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX; - sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL; - sc->tulip_if.if_baudrate = 10000000; - sc->tulip_flags |= TULIP_SQETEST; - break; - } - case TULIP_MEDIA_10BASET_FD: { - sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL; - sc->tulip_if.if_baudrate = 10000000; - break; - } - case TULIP_MEDIA_100BASEFX: - case TULIP_MEDIA_100BASET4: - case TULIP_MEDIA_100BASETX: { - sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL); - sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT; - sc->tulip_if.if_baudrate = 100000000; - break; - } - case TULIP_MEDIA_100BASEFX_FD: - case TULIP_MEDIA_100BASETX_FD: { - sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT; - sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL; - sc->tulip_if.if_baudrate = 100000000; - break; - } - default: { - break; - } - } - TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); -} - -/* - ******************************************************************** - * Start of 21140/21140A support which does not use the MII interface - */ - -static void -tulip_null_media_poll( - tulip_softc_t * const sc, - tulip_mediapoll_event_t event) -{ -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_events[event]++; -#endif -#if defined(DIAGNOSTIC) - printf(TULIP_PRINTF_FMT ": botch(media_poll) at line %d\n", - TULIP_PRINTF_ARGS, __LINE__); -#endif -} - -__inline__ static void -tulip_21140_mediainit( - tulip_softc_t * const sc, - tulip_media_info_t * const mip, - tulip_media_t const media, - unsigned gpdata, - unsigned cmdmode) -{ - sc->tulip_mediums[media] = mip; - mip->mi_type = TULIP_MEDIAINFO_GPR; - mip->mi_cmdmode = cmdmode; - mip->mi_gpdata = gpdata; -} - -static void -tulip_21140_evalboard_media_probe( - tulip_softc_t * const sc) -{ - tulip_media_info_t *mip = sc->tulip_mediainfo; - - sc->tulip_gpinit = TULIP_GP_EB_PINS; - sc->tulip_gpdata = TULIP_GP_EB_INIT; - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS); - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT); - TULIP_CSR_WRITE(sc, csr_command, - TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT | - TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); - TULIP_CSR_WRITE(sc, csr_command, - TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); - DELAY(1000000); - if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) { - sc->tulip_media = TULIP_MEDIA_10BASET; - } else { - sc->tulip_media = TULIP_MEDIA_100BASETX; - } - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, - TULIP_GP_EB_INIT, - TULIP_CMD_TXTHRSHLDCTL); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, - TULIP_GP_EB_INIT, - TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, - TULIP_GP_EB_INIT, - TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION - |TULIP_CMD_SCRAMBLER); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, - TULIP_GP_EB_INIT, - TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION - |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); -} - -static const tulip_boardsw_t tulip_21140_eb_boardsw = { - TULIP_21140_DEC_EB, - tulip_21140_evalboard_media_probe, - tulip_media_select, - tulip_null_media_poll, - tulip_2114x_media_preset, -}; - -static void -tulip_21140_accton_media_probe( - tulip_softc_t * const sc) -{ - tulip_media_info_t *mip = sc->tulip_mediainfo; - unsigned gpdata; - - sc->tulip_gpinit = TULIP_GP_EB_PINS; - sc->tulip_gpdata = TULIP_GP_EB_INIT; - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS); - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT); - TULIP_CSR_WRITE(sc, csr_command, - TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT | - TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); - TULIP_CSR_WRITE(sc, csr_command, - TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); - DELAY(1000000); - gpdata = TULIP_CSR_READ(sc, csr_gp); - if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) { - sc->tulip_media = TULIP_MEDIA_10BASET; - } else { - if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) { - sc->tulip_media = TULIP_MEDIA_BNC; - } else { - sc->tulip_media = TULIP_MEDIA_100BASETX; - } - } - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC, - TULIP_GP_EN1207_BNC_INIT, - TULIP_CMD_TXTHRSHLDCTL); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, - TULIP_GP_EN1207_UTP_INIT, - TULIP_CMD_TXTHRSHLDCTL); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, - TULIP_GP_EN1207_UTP_INIT, - TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, - TULIP_GP_EN1207_100_INIT, - TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION - |TULIP_CMD_SCRAMBLER); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, - TULIP_GP_EN1207_100_INIT, - TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION - |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); -} - -static const tulip_boardsw_t tulip_21140_accton_boardsw = { - TULIP_21140_EN1207, - tulip_21140_accton_media_probe, - tulip_media_select, - tulip_null_media_poll, - tulip_2114x_media_preset, -}; - -static void -tulip_21140_smc9332_media_probe( - tulip_softc_t * const sc) -{ - tulip_media_info_t *mip = sc->tulip_mediainfo; - int idx, cnt = 0; - - TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE); - TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); - DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at - 33MHz that comes to two microseconds but wait a - bit longer anyways) */ - TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT | - TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); - sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS; - sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT; - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET); - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT); - DELAY(200000); - for (idx = 1000; idx > 0; idx--) { - u_int32_t csr = TULIP_CSR_READ(sc, csr_gp); - if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) { - if (++cnt > 100) - break; - } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) { - break; - } else { - cnt = 0; - } - DELAY(1000); - } - sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET; - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, - TULIP_GP_SMC_9332_INIT, - TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION - |TULIP_CMD_SCRAMBLER); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, - TULIP_GP_SMC_9332_INIT, - TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION - |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, - TULIP_GP_SMC_9332_INIT, - TULIP_CMD_TXTHRSHLDCTL); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, - TULIP_GP_SMC_9332_INIT, - TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); -} - -static const tulip_boardsw_t tulip_21140_smc9332_boardsw = { - TULIP_21140_SMC_9332, - tulip_21140_smc9332_media_probe, - tulip_media_select, - tulip_null_media_poll, - tulip_2114x_media_preset, -}; - -static void -tulip_21140_cogent_em100_media_probe( - tulip_softc_t * const sc) -{ - tulip_media_info_t *mip = sc->tulip_mediainfo; - u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command); - - sc->tulip_gpinit = TULIP_GP_EM100_PINS; - sc->tulip_gpdata = TULIP_GP_EM100_INIT; - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS); - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT); - - cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE; - cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER); - if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) { - TULIP_CSR_WRITE(sc, csr_command, cmdmode); - sc->tulip_media = TULIP_MEDIA_100BASEFX; - - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX, - TULIP_GP_EM100_INIT, - TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD, - TULIP_GP_EM100_INIT, - TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION - |TULIP_CMD_FULLDUPLEX); - } else { - TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER); - sc->tulip_media = TULIP_MEDIA_100BASETX; - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, - TULIP_GP_EM100_INIT, - TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION - |TULIP_CMD_SCRAMBLER); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, - TULIP_GP_EM100_INIT, - TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION - |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); - } -} - -static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = { - TULIP_21140_COGENT_EM100, - tulip_21140_cogent_em100_media_probe, - tulip_media_select, - tulip_null_media_poll, - tulip_2114x_media_preset -}; - -static void -tulip_21140_znyx_zx34x_media_probe( - tulip_softc_t * const sc) -{ - tulip_media_info_t *mip = sc->tulip_mediainfo; - int cnt10 = 0, cnt100 = 0, idx; - - sc->tulip_gpinit = TULIP_GP_ZX34X_PINS; - sc->tulip_gpdata = TULIP_GP_ZX34X_INIT; - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS); - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT); - TULIP_CSR_WRITE(sc, csr_command, - TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT | - TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE); - TULIP_CSR_WRITE(sc, csr_command, - TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL); - - DELAY(200000); - for (idx = 1000; idx > 0; idx--) { - u_int32_t csr = TULIP_CSR_READ(sc, csr_gp); - if ((csr & (TULIP_GP_ZX34X_LNKFAIL|TULIP_GP_ZX34X_SYMDET|TULIP_GP_ZX34X_SIGDET)) == (TULIP_GP_ZX34X_LNKFAIL|TULIP_GP_ZX34X_SYMDET|TULIP_GP_ZX34X_SIGDET)) { - if (++cnt100 > 100) - break; - } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) { - if (++cnt10 > 100) - break; - } else { - cnt10 = 0; - cnt100 = 0; - } - DELAY(1000); - } - sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET; - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET, - TULIP_GP_ZX34X_INIT, - TULIP_CMD_TXTHRSHLDCTL); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD, - TULIP_GP_ZX34X_INIT, - TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX, - TULIP_GP_ZX34X_INIT, - TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION - |TULIP_CMD_SCRAMBLER); - tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD, - TULIP_GP_ZX34X_INIT, - TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION - |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX); -} - -static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = { - TULIP_21140_ZNYX_ZX34X, - tulip_21140_znyx_zx34x_media_probe, - tulip_media_select, - tulip_null_media_poll, - tulip_2114x_media_preset, -}; - -static void -tulip_2114x_media_probe( - tulip_softc_t * const sc) -{ - sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE - |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72; -} - -static const tulip_boardsw_t tulip_2114x_isv_boardsw = { - TULIP_21140_ISV, - tulip_2114x_media_probe, - tulip_media_select, - tulip_media_poll, - tulip_2114x_media_preset, -}; - -/* - * ******** END of chip-specific handlers. *********** - */ - -/* - * Code the read the SROM and MII bit streams (I2C) - */ -static void -tulip_delay_300ns( - tulip_softc_t * const sc) -{ - int idx; - for (idx = (300 / 33) + 1; idx > 0; idx--) - (void) TULIP_CSR_READ(sc, csr_busmode); -} - -#define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); tulip_delay_300ns(sc); } while (0) - -static void -tulip_srom_idle( - tulip_softc_t * const sc) -{ - unsigned bit, csr; - - csr = SROMSEL ; EMIT; - csr = SROMSEL | SROMRD; EMIT; - csr ^= SROMCS; EMIT; - csr ^= SROMCLKON; EMIT; - - /* - * Write 25 cycles of 0 which will force the SROM to be idle. - */ - for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) { - csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ - csr ^= SROMCLKON; EMIT; /* clock high; data valid */ - } - csr ^= SROMCLKOFF; EMIT; - csr ^= SROMCS; EMIT; - csr = 0; EMIT; -} - - -static void -tulip_srom_read( - tulip_softc_t * const sc) -{ - unsigned idx; - const unsigned bitwidth = SROM_BITWIDTH; - const unsigned cmdmask = (SROMCMD_RD << bitwidth); - const unsigned msb = 1 << (bitwidth + 3 - 1); - unsigned lastidx = (1 << bitwidth) - 1; - - tulip_srom_idle(sc); - - for (idx = 0; idx <= lastidx; idx++) { - unsigned lastbit, data, bits, bit, csr; - csr = SROMSEL ; EMIT; - csr = SROMSEL | SROMRD; EMIT; - csr ^= SROMCSON; EMIT; - csr ^= SROMCLKON; EMIT; - - lastbit = 0; - for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) { - const unsigned thisbit = bits & msb; - csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ - if (thisbit != lastbit) { - csr ^= SROMDOUT; EMIT; /* clock low; invert data */ - } else { - EMIT; - } - csr ^= SROMCLKON; EMIT; /* clock high; data valid */ - lastbit = thisbit; - } - csr ^= SROMCLKOFF; EMIT; - - for (data = 0, bits = 0; bits < 16; bits++) { - data <<= 1; - csr ^= SROMCLKON; EMIT; /* clock high; data valid */ - data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0; - csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */ - } - sc->tulip_rombuf[idx*2] = data & 0xFF; - sc->tulip_rombuf[idx*2+1] = data >> 8; - csr = SROMSEL | SROMRD; EMIT; - csr = 0; EMIT; - } - tulip_srom_idle(sc); -} - -#define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); tulip_delay_300ns(sc); } while (0) - -static void -tulip_mii_writebits( - tulip_softc_t * const sc, - unsigned data, - unsigned bits) -{ - unsigned msb = 1 << (bits - 1); - unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); - unsigned lastbit = (csr & MII_DOUT) ? msb : 0; - - csr |= MII_WR; MII_EMIT; /* clock low; assert write */ - - for (; bits > 0; bits--, data <<= 1) { - const unsigned thisbit = data & msb; - if (thisbit != lastbit) { - csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */ - } - csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ - lastbit = thisbit; - csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ - } -} - -static void -tulip_mii_turnaround( - tulip_softc_t * const sc, - unsigned cmd) -{ - unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); - - if (cmd == MII_WRCMD) { - csr |= MII_DOUT; MII_EMIT; /* clock low; change data */ - csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ - csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ - csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */ - } else { - csr |= MII_RD; MII_EMIT; /* clock low; switch to read */ - } - csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ - csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ -} - -static unsigned -tulip_mii_readbits( - tulip_softc_t * const sc) -{ - unsigned data; - unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); - int idx; - - for (idx = 0, data = 0; idx < 16; idx++) { - data <<= 1; /* this is NOOP on the first pass through */ - csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */ - if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN) - data |= 1; - csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */ - } - csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */ - - return data; -} - -static unsigned -tulip_mii_readreg( - tulip_softc_t * const sc, - unsigned devaddr, - unsigned regno) -{ - unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); - unsigned data; - - csr &= ~(MII_RD|MII_CLK); MII_EMIT; - tulip_mii_writebits(sc, MII_PREAMBLE, 32); - tulip_mii_writebits(sc, MII_RDCMD, 8); - tulip_mii_writebits(sc, devaddr, 5); - tulip_mii_writebits(sc, regno, 5); - tulip_mii_turnaround(sc, MII_RDCMD); - - data = tulip_mii_readbits(sc); -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_phyregs[regno][0] = data; - sc->tulip_dbg.dbg_phyregs[regno][1]++; -#endif - return data; -} - -static void -tulip_mii_writereg( - tulip_softc_t * const sc, - unsigned devaddr, - unsigned regno, - unsigned data) -{ - unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK); - csr &= ~(MII_RD|MII_CLK); MII_EMIT; - tulip_mii_writebits(sc, MII_PREAMBLE, 32); - tulip_mii_writebits(sc, MII_WRCMD, 8); - tulip_mii_writebits(sc, devaddr, 5); - tulip_mii_writebits(sc, regno, 5); - tulip_mii_turnaround(sc, MII_WRCMD); - tulip_mii_writebits(sc, data, 16); -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_phyregs[regno][2] = data; - sc->tulip_dbg.dbg_phyregs[regno][3]++; -#endif -} - -#define tulip_mchash(mca) (tulip_crc32(mca, 6) & 0x1FF) -#define tulip_srom_crcok(databuf) ( \ - ((tulip_crc32(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \ - ((databuf)[126] | ((databuf)[127] << 8))) - -static unsigned -tulip_crc32( - const unsigned char *databuf, - size_t datalen) -{ - u_int idx, crc = 0xFFFFFFFFUL; - static const u_int crctab[] = { - 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, - 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, - 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, - 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c - }; - - for (idx = 0; idx < datalen; idx++) { - crc ^= *databuf++; - crc = (crc >> 4) ^ crctab[crc & 0xf]; - crc = (crc >> 4) ^ crctab[crc & 0xf]; - } - return crc; -} - -static void -tulip_identify_dec_nic( - tulip_softc_t * const sc) -{ - strcpy(sc->tulip_boardid, "DEC "); -#define D0 4 - if (sc->tulip_chipid <= TULIP_DE425) - return; - if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0 - || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) { - bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8); - sc->tulip_boardid[D0+8] = ' '; - } -#undef D0 -} - -static void -tulip_identify_znyx_nic( - tulip_softc_t * const sc) -{ - unsigned id = 0; - strcpy(sc->tulip_boardid, "ZNYX ZX3XX "); - if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) { - unsigned znyx_ptr; - sc->tulip_boardid[8] = '4'; - znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125]; - if (znyx_ptr < 26 || znyx_ptr > 116) { - sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; - return; - } - /* ZX344 = 0010 .. 0013FF - */ - if (sc->tulip_rombuf[znyx_ptr] == 0x4A - && sc->tulip_rombuf[znyx_ptr + 1] == 0x52 - && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) { - id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4]; - if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) { - sc->tulip_boardid[9] = '2'; - if (id == TULIP_ZNYX_ID_ZX342B) { - sc->tulip_boardid[10] = 'B'; - sc->tulip_boardid[11] = ' '; - } - sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; - } else if (id == TULIP_ZNYX_ID_ZX344) { - sc->tulip_boardid[10] = '4'; - sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; - } else if (id == TULIP_ZNYX_ID_ZX345) { - sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5'; - } else if (id == TULIP_ZNYX_ID_ZX346) { - sc->tulip_boardid[9] = '6'; - } else if (id == TULIP_ZNYX_ID_ZX351) { - sc->tulip_boardid[8] = '5'; - sc->tulip_boardid[9] = '1'; - } - } - if (id == 0) { - /* - * Assume it's a ZX342... - */ - sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw; - } - return; - } - sc->tulip_boardid[8] = '1'; - if (sc->tulip_chipid == TULIP_21041) { - sc->tulip_boardid[10] = '1'; - return; - } - if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) { - id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36]; - if (id == TULIP_ZNYX_ID_ZX312T) { - sc->tulip_boardid[9] = '2'; - sc->tulip_boardid[10] = 'T'; - sc->tulip_boardid[11] = ' '; - sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; - } else if (id == TULIP_ZNYX_ID_ZX314_INTA) { - sc->tulip_boardid[9] = '4'; - sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; - sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; - } else if (id == TULIP_ZNYX_ID_ZX314) { - sc->tulip_boardid[9] = '4'; - sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; - sc->tulip_features |= TULIP_HAVE_BASEROM; - } else if (id == TULIP_ZNYX_ID_ZX315_INTA) { - sc->tulip_boardid[9] = '5'; - sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; - } else if (id == TULIP_ZNYX_ID_ZX315) { - sc->tulip_boardid[9] = '5'; - sc->tulip_features |= TULIP_HAVE_BASEROM; - } else { - id = 0; - } - } - if (id == 0) { - if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 3) == 0) { - sc->tulip_boardid[9] = '4'; - sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; - sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; - } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) { - sc->tulip_boardid[9] = '5'; - sc->tulip_boardsw = &tulip_21040_boardsw; - sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; - } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) { - sc->tulip_boardid[9] = '2'; - sc->tulip_boardsw = &tulip_21040_boardsw; - } - } -} - -static void -tulip_identify_smc_nic( - tulip_softc_t * const sc) -{ - u_int32_t id1, id2, ei; - int auibnc = 0, utp = 0; - char *cp; - - strcpy(sc->tulip_boardid, "SMC "); - if (sc->tulip_chipid == TULIP_21041) - return; - if (sc->tulip_chipid != TULIP_21040) { - if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) { - strcpy(&sc->tulip_boardid[4], "9332DST "); - sc->tulip_boardsw = &tulip_21140_smc9332_boardsw; - } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) { - strcpy(&sc->tulip_boardid[4], "9334BDT "); - } else { - strcpy(&sc->tulip_boardid[4], "9332BDT "); - } - return; - } - id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8); - id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8); - ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8); - - strcpy(&sc->tulip_boardid[4], "8432"); - cp = &sc->tulip_boardid[8]; - if ((id1 & 1) == 0) - *cp++ = 'B', auibnc = 1; - if ((id1 & 0xFF) > 0x32) - *cp++ = 'T', utp = 1; - if ((id1 & 0x4000) == 0) - *cp++ = 'A', auibnc = 1; - if (id2 == 0x15) { - sc->tulip_boardid[7] = '4'; - *cp++ = '-'; - *cp++ = 'C'; - *cp++ = 'H'; - *cp++ = (ei ? '2' : '1'); - } - *cp++ = ' '; - *cp = '\0'; - if (utp && !auibnc) - sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw; - else if (!utp && auibnc) - sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw; -} - -static void -tulip_identify_cogent_nic( - tulip_softc_t * const sc) -{ - strcpy(sc->tulip_boardid, "Cogent "); - if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) { - if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) { - strcat(sc->tulip_boardid, "EM100TX "); - sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; -#if defined(TULIP_COGENT_EM110TX_ID) - } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) { - strcat(sc->tulip_boardid, "EM110TX "); - sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; -#endif - } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) { - strcat(sc->tulip_boardid, "EM100FX "); - sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw; - } - /* - * Magic number (0x24001109U) is the SubVendor (0x2400) and - * SubDevId (0x1109) for the ANA6944TX (EM440TX). - */ - if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U - && (sc->tulip_features & TULIP_HAVE_BASEROM)) { - /* - * Cogent (Adaptec) is still mapping all INTs to INTA of - * first 21140. Dumb! Dumb! - */ - strcat(sc->tulip_boardid, "EM440TX "); - sc->tulip_features |= TULIP_HAVE_SHAREDINTR; - } - } else if (sc->tulip_chipid == TULIP_21040) { - sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM; - } -} - -static void -tulip_identify_accton_nic( - tulip_softc_t * const sc) -{ - strcpy(sc->tulip_boardid, "ACCTON "); - switch (sc->tulip_chipid) { - case TULIP_21140A: - strcat(sc->tulip_boardid, "EN1207 "); - if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) - sc->tulip_boardsw = &tulip_21140_accton_boardsw; - break; - case TULIP_21140: - strcat(sc->tulip_boardid, "EN1207TX "); - if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) - sc->tulip_boardsw = &tulip_21140_eb_boardsw; - break; - case TULIP_21040: - strcat(sc->tulip_boardid, "EN1203 "); - sc->tulip_boardsw = &tulip_21040_boardsw; - break; - case TULIP_21041: - strcat(sc->tulip_boardid, "EN1203 "); - sc->tulip_boardsw = &tulip_21041_boardsw; - break; - default: - sc->tulip_boardsw = &tulip_2114x_isv_boardsw; - break; - } -} - -static void -tulip_identify_asante_nic( - tulip_softc_t * const sc) -{ - strcpy(sc->tulip_boardid, "Asante "); - if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) - && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) { - tulip_media_info_t *mi = sc->tulip_mediainfo; - int idx; - /* - * The Asante Fast Ethernet doesn't always ship with a valid - * new format SROM. So if isn't in the new format, we cheat - * set it up as if we had. - */ - - sc->tulip_gpinit = TULIP_GP_ASANTE_PINS; - sc->tulip_gpdata = 0; - - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET); - TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET); - DELAY(100); - TULIP_CSR_WRITE(sc, csr_gp, 0); - - mi->mi_type = TULIP_MEDIAINFO_MII; - mi->mi_gpr_length = 0; - mi->mi_gpr_offset = 0; - mi->mi_reset_length = 0; - mi->mi_reset_offset = 0;; - - mi->mi_phyaddr = TULIP_MII_NOPHY; - for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) { - DELAY(10000); - mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0); - } - if (mi->mi_phyaddr == TULIP_MII_NOPHY) { - printf(TULIP_PRINTF_FMT ": can't find phy 0\n", TULIP_PRINTF_ARGS); - return; - } - - sc->tulip_features |= TULIP_HAVE_MII; - mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD; - mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD; - mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD; - mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD; - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD); - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX); - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4); - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD); - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET); - mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) | - tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH); - - sc->tulip_boardsw = &tulip_2114x_isv_boardsw; - } -} - -static void -tulip_identify_compex_nic( - tulip_softc_t * const sc) -{ - strcpy(sc->tulip_boardid, "COMPEX "); - if (sc->tulip_chipid == TULIP_21140A) { - int root_unit; - tulip_softc_t *root_sc = NULL; - - strcat(sc->tulip_boardid, "400TX/PCI "); - /* - * All 4 chips on these boards share an interrupt. This code - * copied from tulip_read_macaddr. - */ - sc->tulip_features |= TULIP_HAVE_SHAREDINTR; - for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) { - root_sc = TULIP_UNIT_TO_SOFTC(root_unit); - if (root_sc == NULL - || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR)) - break; - root_sc = NULL; - } - if (root_sc != NULL - && root_sc->tulip_chipid == sc->tulip_chipid - && root_sc->tulip_pci_busno == sc->tulip_pci_busno) { - sc->tulip_features |= TULIP_HAVE_SLAVEDINTR; - sc->tulip_slaves = root_sc->tulip_slaves; - root_sc->tulip_slaves = sc; - } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) { - printf("\nCannot find master device for de%d interrupts", - sc->tulip_unit); - } - } else { - strcat(sc->tulip_boardid, "unknown "); - } - /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */ - return; -} - -static int -tulip_srom_decode( - tulip_softc_t * const sc) -{ - unsigned idx1, idx2, idx3; - - const tulip_srom_header_t *shp = (tulip_srom_header_t *) &sc->tulip_rombuf[0]; - const tulip_srom_adapter_info_t *saip = (tulip_srom_adapter_info_t *) (shp + 1); - tulip_srom_media_t srom_media; - tulip_media_info_t *mi = sc->tulip_mediainfo; - const u_int8_t *dp; - u_int32_t leaf_offset, blocks, data; - - for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) { - if (shp->sh_adapter_count == 1) - break; - if (saip->sai_device == sc->tulip_pci_devno) - break; - } - /* - * Didn't find the right media block for this card. - */ - if (idx1 == shp->sh_adapter_count) - return 0; - - /* - * Save the hardware address. - */ - bcopy((caddr_t) shp->sh_ieee802_address, (caddr_t) sc->tulip_enaddr, 6); - /* - * If this is a multiple port card, add the adapter index to the last - * byte of the hardware address. (if it isn't multiport, adding 0 - * won't hurt. - */ - sc->tulip_enaddr[5] += idx1; - - leaf_offset = saip->sai_leaf_offset_lowbyte - + saip->sai_leaf_offset_highbyte * 256; - dp = sc->tulip_rombuf + leaf_offset; - - sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2; - - for (idx2 = 0;; idx2++) { - if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype - || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED) - break; - } - sc->tulip_connidx = idx2; - - if (sc->tulip_chipid == TULIP_21041) { - blocks = *dp++; - for (idx2 = 0; idx2 < blocks; idx2++) { - tulip_media_t media; - data = *dp++; - srom_media = (tulip_srom_media_t) (data & 0x3F); - for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { - if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) - break; - } - media = tulip_srom_mediums[idx3].sm_type; - if (media != TULIP_MEDIA_UNKNOWN) { - if (data & TULIP_SROM_21041_EXTENDED) { - mi->mi_type = TULIP_MEDIAINFO_SIA; - sc->tulip_mediums[media] = mi; - mi->mi_sia_connectivity = dp[0] + dp[1] * 256; - mi->mi_sia_tx_rx = dp[2] + dp[3] * 256; - mi->mi_sia_general = dp[4] + dp[5] * 256; - mi++; - } else { - switch (media) { - case TULIP_MEDIA_BNC: { - TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); - mi++; - break; - } - case TULIP_MEDIA_AUI: { - TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); - mi++; - break; - } - case TULIP_MEDIA_10BASET: { - TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); - mi++; - break; - } - case TULIP_MEDIA_10BASET_FD: { - TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); - mi++; - break; - } - default: { - break; - } - } - } - } - if (data & TULIP_SROM_21041_EXTENDED) - dp += 6; - } -#ifdef notdef - if (blocks == 0) { - TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++; - TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++; - TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++; - TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++; - } -#endif - } else { - unsigned length, type; - tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN; - if (sc->tulip_features & TULIP_HAVE_GPR) - sc->tulip_gpinit = *dp++; - blocks = *dp++; - for (idx2 = 0; idx2 < blocks; idx2++) { - const u_int8_t *ep; - if ((*dp & 0x80) == 0) { - length = 4; - type = 0; - } else { - length = (*dp++ & 0x7f) - 1; - type = *dp++ & 0x3f; - } - ep = dp + length; - switch (type & 0x3f) { - case 0: { /* 21140[A] GPR block */ - tulip_media_t media; - srom_media = (tulip_srom_media_t)(dp[0] & 0x3f); - for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { - if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) - break; - } - media = tulip_srom_mediums[idx3].sm_type; - if (media == TULIP_MEDIA_UNKNOWN) - break; - mi->mi_type = TULIP_MEDIAINFO_GPR; - sc->tulip_mediums[media] = mi; - mi->mi_gpdata = dp[1]; - if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) { - sc->tulip_gpdata = mi->mi_gpdata; - gp_media = media; - } - data = dp[2] + dp[3] * 256; - mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data); - if (data & TULIP_SROM_2114X_NOINDICATOR) { - mi->mi_actmask = 0; - } else { -#if 0 - mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0; -#endif - mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data); - mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask; - } - mi++; - break; - } - case 1: { /* 21140[A] MII block */ - const unsigned phyno = *dp++; - mi->mi_type = TULIP_MEDIAINFO_MII; - mi->mi_gpr_length = *dp++; - mi->mi_gpr_offset = dp - sc->tulip_rombuf; - dp += mi->mi_gpr_length; - mi->mi_reset_length = *dp++; - mi->mi_reset_offset = dp - sc->tulip_rombuf; - dp += mi->mi_reset_length; - - /* - * Before we probe for a PHY, use the GPR information - * to select it. If we don't, it may be inaccessible. - */ - TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET); - for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) { - DELAY(10); - TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]); - } - sc->tulip_phyaddr = mi->mi_phyaddr; - for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) { - DELAY(10); - TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]); - } - - /* - * At least write something! - */ - if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0) - TULIP_CSR_WRITE(sc, csr_gp, 0); - - mi->mi_phyaddr = TULIP_MII_NOPHY; - for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) { - DELAY(10000); - mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno); - } - if (mi->mi_phyaddr == TULIP_MII_NOPHY) { -#if defined(TULIP_DEBUG) - printf(TULIP_PRINTF_FMT ": can't find phy %d\n", - TULIP_PRINTF_ARGS, phyno); -#endif - break; - } - sc->tulip_features |= TULIP_HAVE_MII; - mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2; - mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2; - mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2; - mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2; - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD); - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX); - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4); - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD); - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET); - mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) | - tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH); - mi++; - break; - } - case 2: { /* 2114[23] SIA block */ - tulip_media_t media; - srom_media = (tulip_srom_media_t)(dp[0] & 0x3f); - for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { - if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) - break; - } - media = tulip_srom_mediums[idx3].sm_type; - if (media == TULIP_MEDIA_UNKNOWN) - break; - mi->mi_type = TULIP_MEDIAINFO_SIA; - sc->tulip_mediums[media] = mi; - if (dp[0] & 0x40) { - mi->mi_sia_connectivity = dp[1] + dp[2] * 256; - mi->mi_sia_tx_rx = dp[3] + dp[4] * 256; - mi->mi_sia_general = dp[5] + dp[6] * 256; - dp += 6; - } else { - switch (media) { - case TULIP_MEDIA_BNC: { - TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC); - break; - } - case TULIP_MEDIA_AUI: { - TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI); - break; - } - case TULIP_MEDIA_10BASET: { - TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET); - sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; - break; - } - case TULIP_MEDIA_10BASET_FD: { - TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD); - sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; - break; - } - default: { - goto bad_media; - } - } - } - mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16; - mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16; - mi++; - bad_media: - break; - } - case 3: { /* 2114[23] MII PHY block */ - const unsigned phyno = *dp++; - const u_int8_t *dp0; - mi->mi_type = TULIP_MEDIAINFO_MII; - mi->mi_gpr_length = *dp++; - mi->mi_gpr_offset = dp - sc->tulip_rombuf; - dp += 2 * mi->mi_gpr_length; - mi->mi_reset_length = *dp++; - mi->mi_reset_offset = dp - sc->tulip_rombuf; - dp += 2 * mi->mi_reset_length; - - dp0 = &sc->tulip_rombuf[mi->mi_reset_offset]; - for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) { - DELAY(10); - TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16); - } - sc->tulip_phyaddr = mi->mi_phyaddr; - dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset]; - for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) { - DELAY(10); - TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16); - } - - if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0) - TULIP_CSR_WRITE(sc, csr_sia_general, 0); - - mi->mi_phyaddr = TULIP_MII_NOPHY; - for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) { - DELAY(10000); - mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno); - } - if (mi->mi_phyaddr == TULIP_MII_NOPHY) { -#if defined(TULIP_DEBUG) - printf(TULIP_PRINTF_FMT ": can't find phy %d\n", - TULIP_PRINTF_ARGS, phyno); -#endif - break; - } - sc->tulip_features |= TULIP_HAVE_MII; - mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2; - mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2; - mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2; - mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2; - mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2; - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD); - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX); - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4); - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD); - TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET); - mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) | - tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH); - mi++; - break; - } - case 4: { /* 21143 SYM block */ - tulip_media_t media; - srom_media = (tulip_srom_media_t) dp[0]; - for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) { - if (tulip_srom_mediums[idx3].sm_srom_type == srom_media) - break; - } - media = tulip_srom_mediums[idx3].sm_type; - if (media == TULIP_MEDIA_UNKNOWN) - break; - mi->mi_type = TULIP_MEDIAINFO_SYM; - sc->tulip_mediums[media] = mi; - mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16; - mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16; - data = dp[5] + dp[6] * 256; - mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data); - if (data & TULIP_SROM_2114X_NOINDICATOR) { - mi->mi_actmask = 0; - } else { - mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0; - mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data); - mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask; - } - if (TULIP_IS_MEDIA_TP(media)) - sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL; - mi++; - break; - } -#if 0 - case 5: { /* 21143 Reset block */ - mi->mi_type = TULIP_MEDIAINFO_RESET; - mi->mi_reset_length = *dp++; - mi->mi_reset_offset = dp - sc->tulip_rombuf; - dp += 2 * mi->mi_reset_length; - mi++; - break; - } -#endif - default: { - } - } - dp = ep; - } - } - return mi - sc->tulip_mediainfo; -} - -static const struct { - void (*vendor_identify_nic)(tulip_softc_t * const sc); - unsigned char vendor_oui[3]; -} tulip_vendors[] = { - { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } }, - { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } }, - { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } }, - { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } }, - { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } }, - { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } }, - { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } }, - { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } }, - { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } }, - { NULL } -}; - -/* - * This deals with the vagaries of the address roms and the - * brain-deadness that various vendors commit in using them. - */ -static int -tulip_read_macaddr( - tulip_softc_t * const sc) -{ - unsigned cksum, rom_cksum, idx; - u_int32_t csr; - unsigned char tmpbuf[8]; - static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA }; - - sc->tulip_connidx = TULIP_SROM_LASTCONNIDX; - - if (sc->tulip_chipid == TULIP_21040) { - TULIP_CSR_WRITE(sc, csr_enetrom, 1); - for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) { - int cnt = 0; - while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000) - cnt++; - sc->tulip_rombuf[idx] = csr & 0xFF; - } - sc->tulip_boardsw = &tulip_21040_boardsw; -#if defined(TULIP_EISA) - } else if (sc->tulip_chipid == TULIP_DE425) { - int cnt; - for (idx = 0, cnt = 0; idx < sizeof(testpat) && cnt < 32; cnt++) { - tmpbuf[idx] = TULIP_CSR_READBYTE(sc, csr_enetrom); - if (tmpbuf[idx] == testpat[idx]) - ++idx; - else - idx = 0; - } - for (idx = 0; idx < 32; idx++) - sc->tulip_rombuf[idx] = TULIP_CSR_READBYTE(sc, csr_enetrom); - sc->tulip_boardsw = &tulip_21040_boardsw; -#endif /* TULIP_EISA */ - } else { - if (sc->tulip_chipid == TULIP_21041) { - /* - * Thankfully all 21041's act the same. - */ - sc->tulip_boardsw = &tulip_21041_boardsw; - } else { - /* - * Assume all 21140 board are compatible with the - * DEC 10/100 evaluation board. Not really valid but - * it's the best we can do until every one switches to - * the new SROM format. - */ - - sc->tulip_boardsw = &tulip_21140_eb_boardsw; - } - tulip_srom_read(sc); - if (tulip_srom_crcok(sc->tulip_rombuf)) { - /* - * SROM CRC is valid therefore it must be in the - * new format. - */ - sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM; - } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) { - /* - * No checksum is present. See if the SROM id checks out; - * the first 18 bytes should be 0 followed by a 1 followed - * by the number of adapters (which we don't deal with yet). - */ - for (idx = 0; idx < 18; idx++) { - if (sc->tulip_rombuf[idx] != 0) - break; - } - if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0) - sc->tulip_features |= TULIP_HAVE_ISVSROM; - } else if (sc->tulip_chipid >= TULIP_21142) { - sc->tulip_features |= TULIP_HAVE_ISVSROM; - sc->tulip_boardsw = &tulip_2114x_isv_boardsw; - } - if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) { - if (sc->tulip_chipid != TULIP_21041) - sc->tulip_boardsw = &tulip_2114x_isv_boardsw; - - /* - * If the SROM specifies more than one adapter, tag this as a - * BASE rom. - */ - if (sc->tulip_rombuf[19] > 1) - sc->tulip_features |= TULIP_HAVE_BASEROM; - if (sc->tulip_boardsw == NULL) - return -6; - goto check_oui; - } - } - - - if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) { - /* - * Some folks don't use the standard ethernet rom format - * but instead just put the address in the first 6 bytes - * of the rom and let the rest be all 0xffs. (Can we say - * ZNYX???) (well sometimes they put in a checksum so we'll - * start at 8). - */ - for (idx = 8; idx < 32; idx++) { - if (sc->tulip_rombuf[idx] != 0xFF) - return -4; - } - /* - * Make sure the address is not multicast or locally assigned - * that the OUI is not 00-00-00. - */ - if ((sc->tulip_rombuf[0] & 3) != 0) - return -4; - if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0 - && sc->tulip_rombuf[2] == 0) - return -4; - bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6); - sc->tulip_features |= TULIP_HAVE_OKROM; - goto check_oui; - } else { - /* - * A number of makers of multiport boards (ZNYX and Cogent) - * only put on one address ROM on their 21040 boards. So - * if the ROM is all zeros (or all 0xFFs), look at the - * previous configured boards (as long as they are on the same - * PCI bus and the bus number is non-zero) until we find the - * master board with address ROM. We then use its address ROM - * as the base for this board. (we add our relative board - * to the last byte of its address). - */ - for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) { - if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF) - break; - } - if (idx == sizeof(sc->tulip_rombuf)) { - int root_unit; - tulip_softc_t *root_sc = NULL; - for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) { - root_sc = TULIP_UNIT_TO_SOFTC(root_unit); - if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM) - break; - root_sc = NULL; - } - if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM) - && root_sc->tulip_chipid == sc->tulip_chipid - && root_sc->tulip_pci_busno == sc->tulip_pci_busno) { - sc->tulip_features |= TULIP_HAVE_SLAVEDROM; - sc->tulip_boardsw = root_sc->tulip_boardsw; - strcpy(sc->tulip_boardid, root_sc->tulip_boardid); - if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) { - bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf, - sizeof(sc->tulip_rombuf)); - if (!tulip_srom_decode(sc)) - return -5; - } else { - bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6); - sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit; - } - /* - * Now for a truly disgusting kludge: all 4 21040s on - * the ZX314 share the same INTA line so the mapping - * setup by the BIOS on the PCI bridge is worthless. - * Rather than reprogramming the value in the config - * register, we will handle this internally. - */ - if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) { - sc->tulip_slaves = root_sc->tulip_slaves; - root_sc->tulip_slaves = sc; - sc->tulip_features |= TULIP_HAVE_SLAVEDINTR; - } - return 0; - } - } - } - - /* - * This is the standard DEC address ROM test. - */ - - if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0) - return -3; - - tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14]; - tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12]; - tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10]; - tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8]; - if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0) - return -2; - - bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6); - - cksum = *(u_int16_t *) &sc->tulip_enaddr[0]; - cksum *= 2; - if (cksum > 65535) cksum -= 65535; - cksum += *(u_int16_t *) &sc->tulip_enaddr[2]; - if (cksum > 65535) cksum -= 65535; - cksum *= 2; - if (cksum > 65535) cksum -= 65535; - cksum += *(u_int16_t *) &sc->tulip_enaddr[4]; - if (cksum >= 65535) cksum -= 65535; - - rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6]; - - if (cksum != rom_cksum) - return -1; - - check_oui: - /* - * Check for various boards based on OUI. Did I say braindead? - */ - for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) { - if (bcmp((caddr_t) sc->tulip_enaddr, - (caddr_t) tulip_vendors[idx].vendor_oui, 3) == 0) { - (*tulip_vendors[idx].vendor_identify_nic)(sc); - break; - } - } - - sc->tulip_features |= TULIP_HAVE_OKROM; - return 0; -} - -#if defined(IFM_ETHER) -static void -tulip_ifmedia_add( - tulip_softc_t * const sc) -{ - tulip_media_t media; - int medias = 0; - - for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) { - if (sc->tulip_mediums[media] != NULL) { - ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media], - 0, 0); - medias++; - } - } - if (medias == 0) { - sc->tulip_features |= TULIP_HAVE_NOMEDIA; - ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0); - ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE); - } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) { - ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0); - ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO); - } else { - ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]); - sc->tulip_flags |= TULIP_PRINTMEDIA; - tulip_linkup(sc, sc->tulip_media); - } -} - -static int -tulip_ifmedia_change( - struct ifnet * const ifp) -{ - tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); - - sc->tulip_flags |= TULIP_NEEDRESET; - sc->tulip_probe_state = TULIP_PROBE_INACTIVE; - sc->tulip_media = TULIP_MEDIA_UNKNOWN; - if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) { - tulip_media_t media; - for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) { - if (sc->tulip_mediums[media] != NULL - && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) { - sc->tulip_flags |= TULIP_PRINTMEDIA; - sc->tulip_flags &= ~TULIP_DIDNWAY; - tulip_linkup(sc, media); - return 0; - } - } - } - sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT); - tulip_reset(sc); - tulip_init(sc); - return 0; -} - -/* - * Media status callback - */ -static void -tulip_ifmedia_status( - struct ifnet * const ifp, - struct ifmediareq *req) -{ - tulip_softc_t *sc = TULIP_IFP_TO_SOFTC(ifp); - -#if defined(__bsdi__) - if (sc->tulip_mii.mii_instance != 0) { - mii_pollstat(&sc->tulip_mii); - req->ifm_active = sc->tulip_mii.mii_media_active; - req->ifm_status = sc->tulip_mii.mii_media_status; - return; - } -#endif - if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) - return; - - req->ifm_status = IFM_AVALID; - if (sc->tulip_flags & TULIP_LINKUP) - req->ifm_status |= IFM_ACTIVE; - - req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media]; -} -#endif - -static void -tulip_addr_filter( - tulip_softc_t * const sc) -{ - struct ether_multistep step; - struct ether_multi *enm; - - sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI); - sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART; - sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; - sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; -#if defined(IFF_ALLMULTI) - sc->tulip_if.if_flags &= ~IFF_ALLMULTI; -#endif - sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */ - if (sc->tulip_multicnt > 14) { - u_int32_t *sp = sc->tulip_setupdata; - unsigned hash; - /* - * Some early passes of the 21140 have broken implementations of - * hash-perfect mode. When we get too many multicasts for perfect - * filtering with these chips, we need to switch into hash-only - * mode (this is better than all-multicast on network with lots - * of multicast traffic). - */ - if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH) - sc->tulip_flags |= TULIP_WANTHASHONLY; - else - sc->tulip_flags |= TULIP_WANTHASHPERFECT; - /* - * If we have more than 14 multicasts, we have - * go into hash perfect mode (512 bit multicast - * hash and one perfect hardware). - */ - bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata)); - ETHER_FIRST_MULTI(step, TULIP_ETHERCOM(sc), enm); - while (enm != NULL) { - if (bcmp(enm->enm_addrlo, enm->enm_addrhi, 6) == 0) { - hash = tulip_mchash(enm->enm_addrlo); -#if BYTE_ORDER == BIG_ENDIAN - sp[hash >> 4] |= bswap32(1 << (hash & 0xF)); -#else - sp[hash >> 4] |= 1 << (hash & 0xF); -#endif - } else { - sc->tulip_flags |= TULIP_ALLMULTI; - sc->tulip_flags &= ~(TULIP_WANTHASHONLY|TULIP_WANTHASHPERFECT); - break; - } - ETHER_NEXT_MULTI(step, enm); - } - /* - * No reason to use a hash if we are going to be - * receiving every multicast. - */ - if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) { - hash = tulip_mchash(etherbroadcastaddr); -#if BYTE_ORDER == BIG_ENDIAN - sp[hash >> 4] |= bswap32(1 << (hash & 0xF)); -#else - sp[hash >> 4] |= 1 << (hash & 0xF); -#endif - if (sc->tulip_flags & TULIP_WANTHASHONLY) { - hash = tulip_mchash(sc->tulip_enaddr); -#if BYTE_ORDER == BIG_ENDIAN - sp[hash >> 4] |= bswap32(1 << (hash & 0xF)); -#else - sp[hash >> 4] |= 1 << (hash & 0xF); -#endif - } else { -#if BYTE_ORDER == BIG_ENDIAN - sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16; - sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16; - sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16; -#else - sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0]; - sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1]; - sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2]; -#endif - } - } - } - if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) { - u_int32_t *sp = sc->tulip_setupdata; - int idx = 0; - if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) { - /* - * Else can get perfect filtering for 16 addresses. - */ - ETHER_FIRST_MULTI(step, TULIP_ETHERCOM(sc), enm); - for (; enm != NULL; idx++) { - if (bcmp(enm->enm_addrlo, enm->enm_addrhi, 6) == 0) { -#if BYTE_ORDER == BIG_ENDIAN - *sp++ = ((u_int16_t *) enm->enm_addrlo)[0] << 16; - *sp++ = ((u_int16_t *) enm->enm_addrlo)[1] << 16; - *sp++ = ((u_int16_t *) enm->enm_addrlo)[2] << 16; -#else - *sp++ = ((u_int16_t *) enm->enm_addrlo)[0]; - *sp++ = ((u_int16_t *) enm->enm_addrlo)[1]; - *sp++ = ((u_int16_t *) enm->enm_addrlo)[2]; -#endif - } else { - sc->tulip_flags |= TULIP_ALLMULTI; - break; - } - ETHER_NEXT_MULTI(step, enm); - } - /* - * Add the broadcast address. - */ - idx++; -#if BYTE_ORDER == BIG_ENDIAN - *sp++ = 0xFFFF << 16; - *sp++ = 0xFFFF << 16; - *sp++ = 0xFFFF << 16; -#else - *sp++ = 0xFFFF; - *sp++ = 0xFFFF; - *sp++ = 0xFFFF; -#endif - } - /* - * Pad the rest with our hardware address - */ - for (; idx < 16; idx++) { -#if BYTE_ORDER == BIG_ENDIAN - *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16; - *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16; - *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16; -#else - *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0]; - *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1]; - *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2]; -#endif - } - } -#if defined(IFF_ALLMULTI) - if (sc->tulip_flags & TULIP_ALLMULTI) - sc->tulip_if.if_flags |= IFF_ALLMULTI; -#endif -} - -static void -tulip_reset( - tulip_softc_t * const sc) -{ - tulip_ringinfo_t *ri; - tulip_desc_t *di; - u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET); - - /* - * Brilliant. Simply brilliant. When switching modes/speeds - * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS - * bits in CSR6 and then do a software reset to get the 21140 - * to properly reset its internal pathways to the right places. - * Grrrr. - */ - if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0 - && sc->tulip_boardsw->bd_media_preset != NULL) - (*sc->tulip_boardsw->bd_media_preset)(sc); - - TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); - DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at - 33MHz that comes to two microseconds but wait a - bit longer anyways) */ - - if (!inreset) { - sc->tulip_flags |= TULIP_INRESET; - sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW); - sc->tulip_if.if_flags &= ~IFF_OACTIVE; - sc->tulip_if.if_start = tulip_ifstart; - } - -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) - TULIP_CSR_WRITE(sc, csr_txlist, sc->tulip_txdescmap->dm_segs[0].ds_addr); -#else - TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0])); -#endif -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) - TULIP_CSR_WRITE(sc, csr_rxlist, sc->tulip_rxdescmap->dm_segs[0].ds_addr); -#else - TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0])); -#endif - TULIP_CSR_WRITE(sc, csr_busmode, - (1 << (TULIP_BURSTSIZE(sc->tulip_unit) + 8)) - |TULIP_BUSMODE_CACHE_ALIGN8 - |TULIP_BUSMODE_READMULTIPLE - |(BYTE_ORDER != LITTLE_ENDIAN ? - TULIP_BUSMODE_DESC_BIGENDIAN : 0)); - - sc->tulip_txtimer = 0; - sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS; - /* - * Free all the mbufs that were on the transmit ring. - */ - for (;;) { -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) - bus_dmamap_t map; -#endif - struct mbuf *m; - IF_DEQUEUE(&sc->tulip_txq, m); - if (m == NULL) - break; -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) - map = M_GETCTX(m, bus_dmamap_t); - bus_dmamap_unload(sc->tulip_dmatag, map); - sc->tulip_txmaps[sc->tulip_txmaps_free++] = map; -#endif - m_freem(m); - } - - ri = &sc->tulip_txinfo; - ri->ri_nextin = ri->ri_nextout = ri->ri_first; - ri->ri_free = ri->ri_max; - for (di = ri->ri_first; di < ri->ri_last; di++) - di->d_status = 0; -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) - bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_txdescmap, - 0, sc->tulip_txdescmap->dm_mapsize, - BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); -#endif - - /* - * We need to collect all the mbufs were on the - * receive ring before we reinit it either to put - * them back on or to know if we have to allocate - * more. - */ - ri = &sc->tulip_rxinfo; - ri->ri_nextin = ri->ri_nextout = ri->ri_first; - ri->ri_free = ri->ri_max; - for (di = ri->ri_first; di < ri->ri_last; di++) { - di->d_status = 0; - di->d_length1 = 0; di->d_addr1 = 0; - di->d_length2 = 0; di->d_addr2 = 0; - } -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) - bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_rxdescmap, - 0, sc->tulip_rxdescmap->dm_mapsize, - BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); -#endif - for (;;) { -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) - bus_dmamap_t map; -#endif - struct mbuf *m; - IF_DEQUEUE(&sc->tulip_rxq, m); - if (m == NULL) - break; -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) - map = M_GETCTX(m, bus_dmamap_t); - bus_dmamap_unload(sc->tulip_dmatag, map); - sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; -#endif - m_freem(m); - } - - /* - * If tulip_reset is being called recurisvely, exit quickly knowing - * that when the outer tulip_reset returns all the right stuff will - * have happened. - */ - if (inreset) - return; - - sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR - |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED - |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE - |TULIP_STS_RXSTOPPED; - - if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0) - (*sc->tulip_boardsw->bd_media_select)(sc); -#if defined(TULIP_DEBUG) - if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET) - printf(TULIP_PRINTF_FMT ": tulip_reset: additional reset needed?!?\n", - TULIP_PRINTF_ARGS); -#endif - tulip_media_print(sc); - if (sc->tulip_features & TULIP_HAVE_DUALSENSE) - TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status)); - - sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET - |TULIP_RXACT); - tulip_addr_filter(sc); -} - -static void -tulip_init( - tulip_softc_t * const sc) -{ - if (sc->tulip_if.if_flags & IFF_UP) { - if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) { - /* initialize the media */ - tulip_reset(sc); - } - sc->tulip_if.if_flags |= IFF_RUNNING; - if (sc->tulip_if.if_flags & IFF_PROMISC) { - sc->tulip_flags |= TULIP_PROMISC; - sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS; - sc->tulip_intrmask |= TULIP_STS_TXINTR; - } else { - sc->tulip_flags &= ~TULIP_PROMISC; - sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS; - if (sc->tulip_flags & TULIP_ALLMULTI) { - sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI; - } else { - sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI; - } - } - sc->tulip_cmdmode |= TULIP_CMD_TXRUN; - if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) { - tulip_rx_intr(sc); - sc->tulip_cmdmode |= TULIP_CMD_RXRUN; - sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; - } else { - sc->tulip_if.if_flags |= IFF_OACTIVE; - sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN; - sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED; - } - TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); - TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); - if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP) - tulip_txput_setup(sc); - } else { - sc->tulip_if.if_flags &= ~IFF_RUNNING; - tulip_reset(sc); - } -} - -static void -tulip_rx_intr( - tulip_softc_t * const sc) -{ - TULIP_PERFSTART(rxintr) - tulip_ringinfo_t * const ri = &sc->tulip_rxinfo; - struct ifnet * const ifp = &sc->tulip_if; - int fillok = 1; -#if defined(TULIP_DEBUG) - int cnt = 0; -#endif - - for (;;) { - TULIP_PERFSTART(rxget) - struct ether_header eh; - tulip_desc_t *eop = ri->ri_nextin; - int total_len = 0, last_offset = 0; - struct mbuf *ms = NULL, *me = NULL; - int accept = 0; -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) - bus_dmamap_t map; - int error; -#endif - - if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET) - goto queue_mbuf; - -#if defined(TULIP_DEBUG) - if (cnt == ri->ri_max) - break; -#endif - /* - * If the TULIP has no descriptors, there can't be any receive - * descriptors to process. - */ - if (eop == ri->ri_nextout) - break; - - /* - * 90% of the packets will fit in one descriptor. So we optimize - * for that case. - */ - TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop)); - if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) { - IF_DEQUEUE(&sc->tulip_rxq, ms); - me = ms; - } else { - /* - * If still owned by the TULIP, don't touch it. - */ - if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER) - break; - - /* - * It is possible (though improbable unless the BIG_PACKET support - * is enabled or MCLBYTES < 1518) for a received packet to cross - * more than one receive descriptor. - */ - while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) { - if (++eop == ri->ri_last) - eop = ri->ri_first; - TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop)); - if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) { -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_rxintrs++; - sc->tulip_dbg.dbg_rxpktsperintr[cnt]++; -#endif - TULIP_PERFEND(rxget); - TULIP_PERFEND(rxintr); - return; - } - total_len++; - } - - /* - * Dequeue the first buffer for the start of the packet. Hopefully - * this will be the only one we need to dequeue. However, if the - * packet consumed multiple descriptors, then we need to dequeue - * those buffers and chain to the starting mbuf. All buffers but - * the last buffer have the same length so we can set that now. - * (we add to last_offset instead of multiplying since we normally - * won't go into the loop and thereby saving a ourselves from - * doing a multiplication by 0 in the normal case). - */ - IF_DEQUEUE(&sc->tulip_rxq, ms); - for (me = ms; total_len > 0; total_len--) { -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) - map = M_GETCTX(me, bus_dmamap_t); - TULIP_RXMAP_POSTSYNC(sc, map); - bus_dmamap_unload(sc->tulip_dmatag, map); - sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; -#if defined(DIAGNOSTIC) - M_SETCTX(me, NULL); -#endif -#endif /* TULIP_BUS_DMA */ - me->m_len = TULIP_RX_BUFLEN; - last_offset += TULIP_RX_BUFLEN; - IF_DEQUEUE(&sc->tulip_rxq, me->m_next); - me = me->m_next; - } - } - - /* - * Now get the size of received packet (minus the CRC). - */ - total_len = ((eop->d_status >> 16) & 0x7FFF) - 4; - if ((sc->tulip_flags & TULIP_RXIGNORE) == 0 - && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0 -#ifdef BIG_PACKET - || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) && - (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT| - TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC| - TULIP_DSTS_RxOVERFLOW)) == 0) -#endif - )) { - me->m_len = total_len - last_offset; - -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) - map = M_GETCTX(me, bus_dmamap_t); - bus_dmamap_sync(sc->tulip_dmatag, map, 0, me->m_len, - BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE); - bus_dmamap_unload(sc->tulip_dmatag, map); - sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; -#if defined(DIAGNOSTIC) - M_SETCTX(me, NULL); -#endif -#endif /* TULIP_BUS_DMA */ - - eh = *mtod(ms, struct ether_header *); -#if NBPFILTER > 0 - if (sc->tulip_bpf != NULL) { - if (me == ms) - TULIP_BPF_TAP(sc, mtod(ms, caddr_t), total_len); - else - TULIP_BPF_MTAP(sc, ms); - } -#endif - sc->tulip_flags |= TULIP_RXACT; - if ((sc->tulip_flags & (TULIP_PROMISC|TULIP_HASHONLY)) - && (eh.ether_dhost[0] & 1) == 0 - && !TULIP_ADDREQUAL(eh.ether_dhost, sc->tulip_enaddr)) - goto next; - accept = 1; - } else { - ifp->if_ierrors++; - if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) { - sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++; - } else { -#if defined(TULIP_VERBOSE) - const char *error = NULL; -#endif - if (eop->d_status & TULIP_DSTS_RxTOOLONG) { - sc->tulip_dot3stats.dot3StatsFrameTooLongs++; -#if defined(TULIP_VERBOSE) - error = "frame too long"; -#endif - } - if (eop->d_status & TULIP_DSTS_RxBADCRC) { - if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) { - sc->tulip_dot3stats.dot3StatsAlignmentErrors++; -#if defined(TULIP_VERBOSE) - error = "alignment error"; -#endif - } else { - sc->tulip_dot3stats.dot3StatsFCSErrors++; -#if defined(TULIP_VERBOSE) - error = "bad crc"; -#endif - } - } -#if defined(TULIP_VERBOSE) - if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) { - printf(TULIP_PRINTF_FMT ": receive: " TULIP_EADDR_FMT ": %s\n", - TULIP_PRINTF_ARGS, - TULIP_EADDR_ARGS(mtod(ms, u_char *) + 6), - error); - sc->tulip_flags |= TULIP_NOMESSAGES; - } -#endif - } - -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) - map = M_GETCTX(me, bus_dmamap_t); - bus_dmamap_unload(sc->tulip_dmatag, map); - sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; -#if defined(DIAGNOSTIC) - M_SETCTX(me, NULL); -#endif -#endif /* TULIP_BUS_DMA */ - } - next: -#if defined(TULIP_DEBUG) - cnt++; -#endif - ifp->if_ipackets++; - if (++eop == ri->ri_last) - eop = ri->ri_first; - ri->ri_nextin = eop; - queue_mbuf: - /* - * Either we are priming the TULIP with mbufs (m == NULL) - * or we are about to accept an mbuf for the upper layers - * so we need to allocate an mbuf to replace it. If we - * can't replace it, send up it anyways. This may cause - * us to drop packets in the future but that's better than - * being caught in livelock. - * - * Note that if this packet crossed multiple descriptors - * we don't even try to reallocate all the mbufs here. - * Instead we rely on the test of the beginning of - * the loop to refill for the extra consumed mbufs. - */ - if (accept || ms == NULL) { - struct mbuf *m0; - MGETHDR(m0, M_DONTWAIT, MT_DATA); - if (m0 != NULL) { -#if defined(TULIP_COPY_RXDATA) - if (!accept || total_len >= (MHLEN - 2)) { -#endif - MCLGET(m0, M_DONTWAIT); - if ((m0->m_flags & M_EXT) == 0) { - m_freem(m0); - m0 = NULL; - } -#if defined(TULIP_COPY_RXDATA) - } -#endif - } - if (accept -#if defined(TULIP_COPY_RXDATA) - && m0 != NULL -#endif - ) { -#if defined(__bsdi__) - eh.ether_type = ntohs(eh.ether_type); -#endif -#if !defined(TULIP_COPY_RXDATA) - ms->m_pkthdr.len = total_len; - ms->m_pkthdr.rcvif = ifp; -#if defined(__NetBSD__) - (*ifp->if_input)(ifp, ms); -#else - m_adj(ms, sizeof(struct ether_header); - ether_input(ifp, &eh, ms); -#endif /* __NetBSD__ */ -#else -#ifdef BIG_PACKET -#error BIG_PACKET is incompatible with TULIP_COPY_RXDATA -#endif - m0->m_data += 2; /* align data after header */ - m_copydata(ms, 0, total_len, mtod(m0, caddr_t)); - m0->m_len = m0->m_pkthdr.len = total_len; - m0->m_pkthdr.rcvif = ifp; -#if defined(__NetBSD__) - (*ifp->if_input)(ifp, m0); -#else - m_adj(m0, sizeof(struct ether_header); - ether_input(ifp, &eh, m0); -#endif /* __NetBSD__ */ - m0 = ms; -#endif /* ! TULIP_COPY_RXDATA */ - } - ms = m0; - } - if (ms == NULL) { - /* - * Couldn't allocate a new buffer. Don't bother - * trying to replenish the receive queue. - */ - fillok = 0; - sc->tulip_flags |= TULIP_RXBUFSLOW; -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_rxlowbufs++; -#endif - TULIP_PERFEND(rxget); - continue; - } - /* - * Now give the buffer(s) to the TULIP and save in our - * receive queue. - */ - do { - tulip_desc_t * const nextout = ri->ri_nextout; -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) - if (sc->tulip_rxmaps_free > 0) { - map = sc->tulip_rxmaps[--sc->tulip_rxmaps_free]; - } else { - m_freem(ms); - sc->tulip_flags |= TULIP_RXBUFSLOW; -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_rxlowbufs++; -#endif - break; - } - M_SETCTX(ms, map); - error = bus_dmamap_load(sc->tulip_dmatag, map, mtod(ms, void *), - TULIP_RX_BUFLEN, NULL, BUS_DMA_NOWAIT); - if (error) { - printf(TULIP_PRINTF_FMT ": unable to load rx map, " - "error = %d\n", TULIP_PRINTF_ARGS, error); - panic("tulip_rx_intr"); /* XXX */ - } - nextout->d_addr1 = map->dm_segs[0].ds_addr; - nextout->d_length1 = map->dm_segs[0].ds_len; - if (map->dm_nsegs == 2) { - nextout->d_addr2 = map->dm_segs[1].ds_addr; - nextout->d_length2 = map->dm_segs[1].ds_len; - } else { - nextout->d_addr2 = 0; - nextout->d_length2 = 0; - } - TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(*nextout)); -#else /* TULIP_BUS_DMA */ - nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t)); - nextout->d_length1 = TULIP_RX_BUFLEN; -#endif /* TULIP_BUS_DMA */ - nextout->d_status = TULIP_DSTS_OWNER; - TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t)); - if (++ri->ri_nextout == ri->ri_last) - ri->ri_nextout = ri->ri_first; - me = ms->m_next; - ms->m_next = NULL; - IF_ENQUEUE(&sc->tulip_rxq, ms); - } while ((ms = me) != NULL); - - if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET) - sc->tulip_flags &= ~TULIP_RXBUFSLOW; - TULIP_PERFEND(rxget); - } - -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_rxintrs++; - sc->tulip_dbg.dbg_rxpktsperintr[cnt]++; -#endif - TULIP_PERFEND(rxintr); -} - -static int -tulip_tx_intr( - tulip_softc_t * const sc) -{ - TULIP_PERFSTART(txintr) - tulip_ringinfo_t * const ri = &sc->tulip_txinfo; - struct mbuf *m; - int xmits = 0; - int descs = 0; - - while (ri->ri_free < ri->ri_max) { - u_int32_t d_flag; - - TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin)); - if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER) - break; - - ri->ri_free++; - descs++; - d_flag = ri->ri_nextin->d_flag; - if (d_flag & TULIP_DFLAG_TxLASTSEG) { - if (d_flag & TULIP_DFLAG_TxSETUPPKT) { - /* - * We've just finished processing a setup packet. - * Mark that we finished it. If there's not - * another pending, startup the TULIP receiver. - * Make sure we ack the RXSTOPPED so we won't get - * an abormal interrupt indication. - */ - TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap); - sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY); - if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT) - sc->tulip_flags |= TULIP_HASHONLY; - if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) { - tulip_rx_intr(sc); - sc->tulip_cmdmode |= TULIP_CMD_RXRUN; - sc->tulip_intrmask |= TULIP_STS_RXSTOPPED; - TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED); - TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); - TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); - } - } else { - const u_int32_t d_status = ri->ri_nextin->d_status; - IF_DEQUEUE(&sc->tulip_txq, m); - if (m != NULL) { -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) - bus_dmamap_t map = M_GETCTX(m, bus_dmamap_t); - TULIP_TXMAP_POSTSYNC(sc, map); - sc->tulip_txmaps[sc->tulip_txmaps_free++] = map; -#endif /* TULIP_BUS_DMA */ -#if NBPFILTER > 0 - if (sc->tulip_bpf != NULL) - TULIP_BPF_MTAP(sc, m); -#endif - m_freem(m); -#if defined(TULIP_DEBUG) - } else { - printf(TULIP_PRINTF_FMT ": tx_intr: failed to dequeue mbuf?!?\n", TULIP_PRINTF_ARGS); -#endif - } - if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { - tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK; - if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) { -#if defined(TULIP_DEBUG) - if (d_status & TULIP_DSTS_TxNOCARR) - sc->tulip_dbg.dbg_txprobe_nocarr++; - if (d_status & TULIP_DSTS_TxEXCCOLL) - sc->tulip_dbg.dbg_txprobe_exccoll++; -#endif - event = TULIP_MEDIAPOLL_TXPROBE_FAILED; - } - (*sc->tulip_boardsw->bd_media_poll)(sc, event); - /* - * Escape from the loop before media poll has reset the TULIP! - */ - break; - } else { - xmits++; - if (d_status & TULIP_DSTS_ERRSUM) { - sc->tulip_if.if_oerrors++; - if (d_status & TULIP_DSTS_TxEXCCOLL) - sc->tulip_dot3stats.dot3StatsExcessiveCollisions++; - if (d_status & TULIP_DSTS_TxLATECOLL) - sc->tulip_dot3stats.dot3StatsLateCollisions++; - if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS)) - sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++; - if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE)) - sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++; - if (d_status & TULIP_DSTS_TxUNDERFLOW) - sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++; - if (d_status & TULIP_DSTS_TxBABBLE) - sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++; - } else { - u_int32_t collisions = - (d_status & TULIP_DSTS_TxCOLLMASK) - >> TULIP_DSTS_V_TxCOLLCNT; - sc->tulip_if.if_collisions += collisions; - if (collisions == 1) - sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++; - else if (collisions > 1) - sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++; - else if (d_status & TULIP_DSTS_TxDEFERRED) - sc->tulip_dot3stats.dot3StatsDeferredTransmissions++; - /* - * SQE is only valid for 10baseT/BNC/AUI when not - * running in full-duplex. In order to speed up the - * test, the corresponding bit in tulip_flags needs to - * set as well to get us to count SQE Test Errors. - */ - if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags) - sc->tulip_dot3stats.dot3StatsSQETestErrors++; - } - } - } - } - - if (++ri->ri_nextin == ri->ri_last) - ri->ri_nextin = ri->ri_first; - - if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) - sc->tulip_if.if_flags &= ~IFF_OACTIVE; - } - /* - * If nothing left to transmit, disable the timer. - * Else if progress, reset the timer back to 2 ticks. - */ - if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE)) - sc->tulip_txtimer = 0; - else if (xmits > 0) - sc->tulip_txtimer = TULIP_TXTIMER; - sc->tulip_if.if_opackets += xmits; - TULIP_PERFEND(txintr); - return descs; -} - -static void -tulip_print_abnormal_interrupt( - tulip_softc_t * const sc, - u_int32_t csr) -{ - const char * const *msgp = tulip_status_bits; - const char *sep; - u_int32_t mask; - const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024"; - - csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1; - printf(TULIP_PRINTF_FMT ": abnormal interrupt:", TULIP_PRINTF_ARGS); - for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) { - if ((csr & mask) && *msgp != NULL) { - printf("%s%s", sep, *msgp); - if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) { - sc->tulip_flags &= ~TULIP_NEWTXTHRESH; - if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) { - printf(" (switching to store-and-forward mode)"); - } else { - printf(" (raising TX threshold to %s)", - &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]); - } - } - sep = ", "; - } - } - printf("\n"); -} - -static void -tulip_intr_handler( - tulip_softc_t * const sc, - int *progress_p) -{ - TULIP_PERFSTART(intr) - u_int32_t csr; -#if defined(__NetBSD__) && !defined(TULIP_USE_SOFTINTR) - int only_once; - - only_once = 1; -#endif - - while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) { -#if defined(__NetBSD__) && !defined(TULIP_USE_SOFTINTR) - if (only_once == 1) { -#if NRND > 0 - rnd_add_uint32(&sc->tulip_rndsource, csr); -#endif - only_once = 0; - } -#endif - - *progress_p = 1; - TULIP_CSR_WRITE(sc, csr_status, csr); - - if (csr & TULIP_STS_SYSERROR) { - sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT; - if (sc->tulip_flags & TULIP_NOMESSAGES) { - sc->tulip_flags |= TULIP_SYSTEMERROR; - } else { - printf(TULIP_PRINTF_FMT ": system error: %s\n", - TULIP_PRINTF_ARGS, - tulip_system_errors[sc->tulip_last_system_error]); - } - sc->tulip_flags |= TULIP_NEEDRESET; - sc->tulip_system_errors++; - break; - } - if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) { -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_link_intrs++; -#endif - if (sc->tulip_boardsw->bd_media_poll != NULL) { - (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL - ? TULIP_MEDIAPOLL_LINKFAIL - : TULIP_MEDIAPOLL_LINKPASS); - csr &= ~TULIP_STS_ABNRMLINTR; - } - tulip_media_print(sc); - } - if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) { - u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames); - if (csr & TULIP_STS_RXNOBUF) - sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF; - /* - * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data - * on receive overflows. - */ - if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) { - sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++; - /* - * Stop the receiver process and spin until it's stopped. - * Tell rx_intr to drop the packets it dequeues. - */ - TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN); - while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0) - ; - TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED); - sc->tulip_flags |= TULIP_RXIGNORE; - } - tulip_rx_intr(sc); - if (sc->tulip_flags & TULIP_RXIGNORE) { - /* - * Restart the receiver. - */ - sc->tulip_flags &= ~TULIP_RXIGNORE; - TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); - } - } - if (csr & TULIP_STS_ABNRMLINTR) { - u_int32_t tmp = csr & sc->tulip_intrmask - & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR); - if (csr & TULIP_STS_TXUNDERFLOW) { - if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) { - sc->tulip_cmdmode += TULIP_CMD_THRSHLD96; - sc->tulip_flags |= TULIP_NEWTXTHRESH; - } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) { - sc->tulip_cmdmode |= TULIP_CMD_STOREFWD; - sc->tulip_flags |= TULIP_NEWTXTHRESH; - } - } - if (sc->tulip_flags & TULIP_NOMESSAGES) { - sc->tulip_statusbits |= tmp; - } else { - tulip_print_abnormal_interrupt(sc, tmp); - sc->tulip_flags |= TULIP_NOMESSAGES; - } - TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode); - } - if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) { - tulip_tx_intr(sc); - if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0) - tulip_ifstart(&sc->tulip_if); - } - } - if (sc->tulip_flags & TULIP_NEEDRESET) { - tulip_reset(sc); - tulip_init(sc); - } - TULIP_PERFEND(intr); -} - -#if defined(TULIP_USE_SOFTINTR) -/* - * This is a experimental idea to alleviate problems due to interrupt - * livelock. What is interrupt livelock? It's when you spend all your - * time servicing device interrupts and never drop below device ipl - * to do "useful" work. - * - * So what we do here is see if the device needs service and if so, - * disable interrupts (dismiss the interrupt), place it in a list of devices - * needing service, and issue a network software interrupt. - * - * When our network software interrupt routine gets called, we simply - * walk done the list of devices that we have created and deal with them - * at splnet/splsoftnet. - * - */ -static void -tulip_hardintr_handler( - tulip_softc_t * const sc, - int *progress_p) -{ - if (TULIP_CSR_READ(sc, csr_status) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR) == 0) - return; - *progress_p = 1; - /* - * disable interrupts - */ - TULIP_CSR_WRITE(sc, csr_intr, 0); - /* - * mark it as needing a software interrupt - */ - tulip_softintr_mask |= (1U << sc->tulip_unit); - -#if defined(__NetBSD__) && NRND > 0 - /* - * This isn't all that random (the value we feed in) but it is - * better than a constant probably. It isn't used in entropy - * calculation anyway, just to add something to the pool. - */ - rnd_add_uint32(&sc->tulip_rndsource, sc->tulip_flags); -#endif -} - -static void -tulip_softintr( - void) -{ - u_int32_t softintr_mask, mask; - int progress = 0; - int unit; - tulip_spl_t s; - - /* - * Copy mask to local copy and reset global one to 0. - */ - s = TULIP_RAISESPL(); - softintr_mask = tulip_softintr_mask; - tulip_softintr_mask = 0; - TULIP_RESTORESPL(s); - - /* - * Optimize for the single unit case. - */ - if (tulip_softintr_max_unit == 0) { - if (softintr_mask & 1) { - tulip_softc_t * const sc = TULIP_UNIT_TO_SOFTC(0); - /* - * Handle the "interrupt" and then reenable interrupts - */ - softintr_mask = 0; - tulip_intr_handler(sc, &progress); - TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); - } - return; - } - - /* - * Handle all "queued" interrupts in a round robin fashion. - * This is done so as not to favor a particular interface. - */ - unit = tulip_softintr_last_unit; - mask = (1U << unit); - while (softintr_mask != 0) { - if (tulip_softintr_max_unit == unit) { - unit = 0; mask = 1; - } else { - unit += 1; mask <<= 1; - } - if (softintr_mask & mask) { - tulip_softc_t * const sc = TULIP_UNIT_TO_SOFTC(unit); - /* - * Handle the "interrupt" and then reenable interrupts - */ - softintr_mask ^= mask; - tulip_intr_handler(sc, &progress); - TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); - } - } - - /* - * Save where we ending up. - */ - tulip_softintr_last_unit = unit; -} -#endif /* TULIP_USE_SOFTINTR */ - -static tulip_intrfunc_t -tulip_intr_shared( - void *arg) -{ - tulip_softc_t * sc = arg; - int progress = 0; - - for (; sc != NULL; sc = sc->tulip_slaves) { -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_intrs++; -#endif -#if defined(TULIP_USE_SOFTINTR) - tulip_hardintr_handler(sc, &progress); -#else - tulip_intr_handler(sc, &progress); -#endif - } -#if defined(TULIP_USE_SOFTINTR) - if (progress) - schednetisr(NETISR_DE); -#endif -#if !defined(TULIP_VOID_INTRFUNC) - return progress; -#endif -} - -static tulip_intrfunc_t -tulip_intr_normal( - void *arg) -{ - tulip_softc_t * sc = (tulip_softc_t *) arg; - int progress = 0; - -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_intrs++; -#endif -#if defined(TULIP_USE_SOFTINTR) - tulip_hardintr_handler(sc, &progress); - if (progress) - schednetisr(NETISR_DE); -#else - tulip_intr_handler(sc, &progress); -#endif -#if !defined(TULIP_VOID_INTRFUNC) - return progress; -#endif -} - -static struct mbuf * -tulip_mbuf_compress( - struct mbuf *m) -{ - struct mbuf *m0; -#if MCLBYTES >= ETHERMTU + 18 && !defined(BIG_PACKET) - MGETHDR(m0, M_DONTWAIT, MT_DATA); - if (m0 != NULL) { - if (m->m_pkthdr.len > MHLEN) { - MCLGET(m0, M_DONTWAIT); - if ((m0->m_flags & M_EXT) == 0) { - m_freem(m); - m_freem(m0); - return NULL; - } - } - m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t)); - m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len; - } -#else - int mlen = MHLEN; - int len = m->m_pkthdr.len; - struct mbuf **mp = &m0; - - while (len > 0) { - if (mlen == MHLEN) { - MGETHDR(*mp, M_DONTWAIT, MT_DATA); - } else { - MGET(*mp, M_DONTWAIT, MT_DATA); - } - if (*mp == NULL) { - m_freem(m0); - m0 = NULL; - break; - } - if (len > MLEN) { - MCLGET(*mp, M_DONTWAIT); - if (((*mp)->m_flags & M_EXT) == 0) { - m_freem(m0); - m0 = NULL; - break; - } - (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES; - } else { - (*mp)->m_len = len <= mlen ? len : mlen; - } - m_copydata(m, m->m_pkthdr.len - len, - (*mp)->m_len, mtod((*mp), caddr_t)); - len -= (*mp)->m_len; - mp = &(*mp)->m_next; - mlen = MLEN; - } -#endif - m_freem(m); - return m0; -} - -static struct mbuf * -tulip_txput( - tulip_softc_t * const sc, - struct mbuf *m) -{ - TULIP_PERFSTART(txput) - tulip_ringinfo_t * const ri = &sc->tulip_txinfo; - tulip_desc_t *eop, *nextout; - int segcnt, free; - u_int32_t d_status; -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) - bus_dmamap_t map; - int error; -#else - struct mbuf *m0; -#endif - -#if defined(TULIP_DEBUG) - if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { - printf(TULIP_PRINTF_FMT ": txput%s: tx not running\n", - TULIP_PRINTF_ARGS, - (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : ""); - sc->tulip_flags |= TULIP_WANTTXSTART; - sc->tulip_dbg.dbg_txput_finishes[0]++; - goto finish; - } -#endif - - /* - * Now we try to fill in our transmit descriptors. This is - * a bit reminiscent of going on the Ark two by two - * since each descriptor for the TULIP can describe - * two buffers. So we advance through packet filling - * each of the two entries at a time to to fill each - * descriptor. Clear the first and last segment bits - * in each descriptor (actually just clear everything - * but the end-of-ring or chain bits) to make sure - * we don't get messed up by previously sent packets. - * - * We may fail to put the entire packet on the ring if - * there is either not enough ring entries free or if the - * packet has more than MAX_TXSEG segments. In the former - * case we will just wait for the ring to empty. In the - * latter case we have to recopy. - */ -#if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX) - m0 = m; - again: -#endif - d_status = 0; - eop = nextout = ri->ri_nextout; - segcnt = 0; - free = ri->ri_free; - -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) - /* - * Reclaim some dma maps from if we are out. - */ - if (sc->tulip_txmaps_free == 0) { -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_no_txmaps++; -#endif - free += tulip_tx_intr(sc); - } - if (sc->tulip_txmaps_free > 0) { - map = sc->tulip_txmaps[sc->tulip_txmaps_free-1]; - } else { - sc->tulip_flags |= TULIP_WANTTXSTART; -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_txput_finishes[1]++; -#endif - goto finish; - } - error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT); - if (error != 0) { - if (error == EFBIG) { - /* - * The packet exceeds the number of transmit buffer - * entries that we can use for one packet, so we have - * to recopy it into one mbuf and then try again. - */ - m = tulip_mbuf_compress(m); - if (m == NULL) { -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_txput_finishes[2]++; -#endif - goto finish; - } - error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT); - } - if (error != 0) { - printf(TULIP_PRINTF_FMT ": unable to load tx map, " - "error = %d\n", TULIP_PRINTF_ARGS, error); -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_txput_finishes[3]++; -#endif - goto finish; - } - } - if ((free -= (map->dm_nsegs + 1) / 2) <= 0 - /* - * See if there's any unclaimed space in the transmit ring. - */ - && (free += tulip_tx_intr(sc)) <= 0) { - /* - * There's no more room but since nothing - * has been committed at this point, just - * show output is active, put back the - * mbuf and return. - */ - sc->tulip_flags |= TULIP_WANTTXSTART; -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_txput_finishes[4]++; -#endif - bus_dmamap_unload(sc->tulip_dmatag, map); - goto finish; - } - for (; map->dm_nsegs - segcnt > 1; segcnt += 2) { - eop = nextout; - eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; - eop->d_status = d_status; - eop->d_addr1 = map->dm_segs[segcnt].ds_addr; - eop->d_length1 = map->dm_segs[segcnt].ds_len; - eop->d_addr2 = map->dm_segs[segcnt+1].ds_addr; - eop->d_length2 = map->dm_segs[segcnt+1].ds_len; - d_status = TULIP_DSTS_OWNER; - if (++nextout == ri->ri_last) - nextout = ri->ri_first; - } - if (segcnt < map->dm_nsegs) { - eop = nextout; - eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; - eop->d_status = d_status; - eop->d_addr1 = map->dm_segs[segcnt].ds_addr; - eop->d_length1 = map->dm_segs[segcnt].ds_len; - eop->d_addr2 = 0; - eop->d_length2 = 0; - if (++nextout == ri->ri_last) - nextout = ri->ri_first; - } - TULIP_TXMAP_PRESYNC(sc, map); - M_SETCTX(m, map); - map = NULL; - --sc->tulip_txmaps_free; /* commit to using the dmamap */ - -#else /* !TULIP_BUS_DMA */ - - do { - int len = m0->m_len; - caddr_t addr = mtod(m0, caddr_t); - unsigned clsize = CLBYTES - (((u_long) addr) & (CLBYTES-1)); - - while (len > 0) { - unsigned slen = min(len, clsize); -#ifdef BIG_PACKET - int partial = 0; - if (slen >= 2048) - slen = 2040, partial = 1; -#endif - segcnt++; - if (segcnt > TULIP_MAX_TXSEG) { - /* - * The packet exceeds the number of transmit buffer - * entries that we can use for one packet, so we have - * recopy it into one mbuf and then try again. - */ - m = tulip_mbuf_compress(m); - if (m == NULL) - goto finish; - goto again; - } - if (segcnt & 1) { - if (--free == 0) { - /* - * See if there's any unclaimed space in the - * transmit ring. - */ - if ((free += tulip_tx_intr(sc)) == 0) { - /* - * There's no more room but since nothing - * has been committed at this point, just - * show output is active, put back the - * mbuf and return. - */ - sc->tulip_flags |= TULIP_WANTTXSTART; -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_txput_finishes[1]++; -#endif - goto finish; - } - } - eop = nextout; - if (++nextout == ri->ri_last) - nextout = ri->ri_first; - eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; - eop->d_status = d_status; - eop->d_addr1 = TULIP_KVATOPHYS(sc, addr); - eop->d_length1 = slen; - } else { - /* - * Fill in second half of descriptor - */ - eop->d_addr2 = TULIP_KVATOPHYS(sc, addr); - eop->d_length2 = slen; - } - d_status = TULIP_DSTS_OWNER; - len -= slen; - addr += slen; -#ifdef BIG_PACKET - if (partial) - continue; -#endif - clsize = CLBYTES; - } - } while ((m0 = m0->m_next) != NULL); -#endif /* TULIP_BUS_DMA */ - - /* - * The descriptors have been filled in. Now get ready - * to transmit. - */ - IF_ENQUEUE(&sc->tulip_txq, m); - m = NULL; - - /* - * Make sure the next descriptor after this packet is owned - * by us since it may have been set up above if we ran out - * of room in the ring. - */ - nextout->d_status = 0; - TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t)); - -#if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX) - /* - * If we only used the first segment of the last descriptor, - * make sure the second segment will not be used. - */ - if (segcnt & 1) { - eop->d_addr2 = 0; - eop->d_length2 = 0; - } -#endif /* TULIP_BUS_DMA */ - - /* - * Mark the last and first segments, indicate we want a transmit - * complete interrupt, and tell it to transmit! - */ - eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR; - - /* - * Note that ri->ri_nextout is still the start of the packet - * and until we set the OWNER bit, we can still back out of - * everything we have done. - */ - ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG; -#if defined(TULIP_BUS_MAP) && !defined(TULIP_BUS_DMA_NOTX) - if (eop < ri->ri_nextout) { - TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, - (caddr_t) ri->ri_last - (caddr_t) ri->ri_nextout); - TULIP_TXDESC_PRESYNC(sc, ri->ri_first, - (caddr_t) (eop + 1) - (caddr_t) ri->ri_first); - } else { - TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, - (caddr_t) (eop + 1) - (caddr_t) ri->ri_nextout); - } -#endif - ri->ri_nextout->d_status = TULIP_DSTS_OWNER; - TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t)); - - /* - * This advances the ring for us. - */ - ri->ri_nextout = nextout; - ri->ri_free = free; - - TULIP_PERFEND(txput); - - if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) { - TULIP_CSR_WRITE(sc, csr_txpoll, 1); - sc->tulip_if.if_flags |= IFF_OACTIVE; - sc->tulip_if.if_start = tulip_ifstart; - TULIP_PERFEND(txput); - return NULL; - } - - /* - * switch back to the single queueing ifstart. - */ - sc->tulip_flags &= ~TULIP_WANTTXSTART; - if (sc->tulip_txtimer == 0) - sc->tulip_txtimer = TULIP_TXTIMER; -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_txput_finishes[5]++; -#endif - - /* - * If we want a txstart, there must be not enough space in the - * transmit ring. So we want to enable transmit done interrupts - * so we can immediately reclaim some space. When the transmit - * interrupt is posted, the interrupt handler will call tx_intr - * to reclaim space and then txstart (since WANTTXSTART is set). - * txstart will move the packet into the transmit ring and clear - * WANTTXSTART thereby causing TXINTR to be cleared. - */ - finish: -#if defined(TULIP_DEBUG) - sc->tulip_dbg.dbg_txput_finishes[6]++; -#endif - if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) { - sc->tulip_if.if_flags |= IFF_OACTIVE; - sc->tulip_if.if_start = tulip_ifstart; - if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) { - sc->tulip_intrmask |= TULIP_STS_TXINTR; - TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); - } - } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) { - if (sc->tulip_intrmask & TULIP_STS_TXINTR) { - sc->tulip_intrmask &= ~TULIP_STS_TXINTR; - TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); - } - } - TULIP_CSR_WRITE(sc, csr_txpoll, 1); - TULIP_PERFEND(txput); - return m; -} - -static void -tulip_txput_setup( - tulip_softc_t * const sc) -{ - tulip_ringinfo_t * const ri = &sc->tulip_txinfo; - tulip_desc_t *nextout; - - /* - * We will transmit, at most, one setup packet per call to ifstart. - */ - -#if defined(TULIP_DEBUG) - if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) { - printf(TULIP_PRINTF_FMT ": txput_setup: tx not running\n", - TULIP_PRINTF_ARGS); - sc->tulip_flags |= TULIP_WANTTXSTART; - sc->tulip_if.if_start = tulip_ifstart; - return; - } -#endif - /* - * Try to reclaim some free descriptors.. - */ - if (ri->ri_free < 2) - tulip_tx_intr(sc); - if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) { - sc->tulip_flags |= TULIP_WANTTXSTART; - sc->tulip_if.if_start = tulip_ifstart; - return; - } - bcopy(sc->tulip_setupdata, sc->tulip_setupbuf, - sizeof(sc->tulip_setupbuf)); - /* - * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is - * set and DOINGSETUP is clear doing an XOR of the two will DTRT. - */ - sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP; - ri->ri_free--; - nextout = ri->ri_nextout; - nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN; - nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG - |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR; - if (sc->tulip_flags & TULIP_WANTHASHPERFECT) - nextout->d_flag |= TULIP_DFLAG_TxHASHFILT; - else if (sc->tulip_flags & TULIP_WANTHASHONLY) - nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT; - - nextout->d_length2 = 0; - nextout->d_addr2 = 0; -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) - nextout->d_length1 = sc->tulip_setupmap->dm_segs[0].ds_len; - nextout->d_addr1 = sc->tulip_setupmap->dm_segs[0].ds_addr; - if (sc->tulip_setupmap->dm_nsegs == 2) { - nextout->d_length2 = sc->tulip_setupmap->dm_segs[1].ds_len; - nextout->d_addr2 = sc->tulip_setupmap->dm_segs[1].ds_addr; - } - TULIP_TXMAP_PRESYNC(sc, sc->tulip_setupmap); - TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(*nextout)); -#else - nextout->d_length1 = sizeof(sc->tulip_setupbuf); - nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf); -#endif - - /* - * Advance the ring for the next transmit packet. - */ - if (++ri->ri_nextout == ri->ri_last) - ri->ri_nextout = ri->ri_first; - - /* - * Make sure the next descriptor is owned by us since it - * may have been set up above if we ran out of room in the - * ring. - */ - ri->ri_nextout->d_status = 0; - TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t)); - nextout->d_status = TULIP_DSTS_OWNER; - /* - * Flush the ownwership of the current descriptor - */ - TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t)); - TULIP_CSR_WRITE(sc, csr_txpoll, 1); - if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) { - sc->tulip_intrmask |= TULIP_STS_TXINTR; - TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask); - } -} - - -/* - * This routine is entered at splnet() (splsoftnet() on NetBSD) - * and thereby imposes no problems when TULIP_USE_SOFTINTR is - * defined or not. - */ -static int -tulip_ifioctl( - struct ifnet * ifp, - ioctl_cmd_t cmd, - caddr_t data) -{ - TULIP_PERFSTART(ifioctl) - tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); - struct ifaddr *ifa = (struct ifaddr *)data; - struct ifreq *ifr = (struct ifreq *) data; - tulip_spl_t s; - int error = 0; - -#if defined(TULIP_USE_SOFTINTR) - s = TULIP_RAISESOFTSPL(); -#else - s = TULIP_RAISESPL(); -#endif - switch (cmd) { - case SIOCSIFADDR: { - ifp->if_flags |= IFF_UP; - switch(ifa->ifa_addr->sa_family) { -#ifdef INET - case AF_INET: { - tulip_init(sc); - TULIP_ARP_IFINIT(sc, ifa); - break; - } -#endif /* INET */ - -#ifdef NS - /* - * This magic copied from if_is.c; I don't use XNS, - * so I have no way of telling if this actually - * works or not. - */ - case AF_NS: { - struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); - if (ns_nullhost(*ina)) { - ina->x_host = *(union ns_host *)(sc->tulip_enaddr); - } else { - ifp->if_flags &= ~IFF_RUNNING; - bcopy((caddr_t)ina->x_host.c_host, - (caddr_t)sc->tulip_enaddr, - sizeof(sc->tulip_enaddr)); - } - tulip_init(sc); - break; - } -#endif /* NS */ - - default: { - tulip_init(sc); - break; - } - } - break; - } - case SIOCGIFADDR: { - bcopy((caddr_t) sc->tulip_enaddr, - (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data, - 6); - break; - } - - case SIOCSIFFLAGS: { -#if !defined(IFM_ETHER) - int flags = 0; - if (ifp->if_flags & IFF_LINK0) flags |= 1; - if (ifp->if_flags & IFF_LINK1) flags |= 2; - if (ifp->if_flags & IFF_LINK2) flags |= 4; - if (flags == 7) { - ifp->if_flags &= ~(IFF_LINK0|IFF_LINK1|IFF_LINK2); - sc->tulip_media = TULIP_MEDIA_UNKNOWN; - sc->tulip_probe_state = TULIP_PROBE_INACTIVE; - sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP|TULIP_NOAUTOSENSE); - tulip_reset(sc); - } else if (flags) { - tulip_media_t media; - for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) { - if (sc->tulip_mediums[media] != NULL && --flags == 0) { - sc->tulip_flags |= TULIP_NOAUTOSENSE; - if (sc->tulip_media != media || (sc->tulip_flags & TULIP_DIDNWAY)) { - sc->tulip_flags &= ~TULIP_DIDNWAY; - tulip_linkup(sc, media); - } - break; - } - } - if (flags) - printf(TULIP_PRINTF_FMT ": ignored invalid media request\n", TULIP_PRINTF_ARGS); - } -#endif - tulip_init(sc); - break; - } - -#if defined(SIOCSIFMEDIA) - case SIOCSIFMEDIA: - case SIOCGIFMEDIA: { - error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd); - break; - } -#endif - - case SIOCADDMULTI: - case SIOCDELMULTI: { - /* - * Update multicast listeners - */ - if (cmd == SIOCADDMULTI) - error = ether_addmulti(ifr, TULIP_ETHERCOM(sc)); - else - error = ether_delmulti(ifr, TULIP_ETHERCOM(sc)); - - if (error == ENETRESET) { - tulip_addr_filter(sc); /* reset multicast filtering */ - tulip_init(sc); - error = 0; - } - break; - } -#if defined(SIOCSIFMTU) -#if !defined(ifr_mtu) -#define ifr_mtu ifr_metric -#endif - case SIOCSIFMTU: - /* - * Set the interface MTU. - */ - if (ifr->ifr_mtu > ETHERMTU -#ifdef BIG_PACKET - && sc->tulip_chipid != TULIP_21140 - && sc->tulip_chipid != TULIP_21140A - && sc->tulip_chipid != TULIP_21041 -#endif - ) { - error = EINVAL; - break; - } - ifp->if_mtu = ifr->ifr_mtu; -#ifdef BIG_PACKET - tulip_reset(sc); - tulip_init(sc); -#endif - break; -#endif /* SIOCSIFMTU */ - -#ifdef SIOCGADDRROM - case SIOCGADDRROM: { - error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf)); - break; - } -#endif -#ifdef SIOCGCHIPID - case SIOCGCHIPID: { - ifr->ifr_metric = (int) sc->tulip_chipid; - break; - } -#endif - default: { - error = EINVAL; - break; - } - } - - TULIP_RESTORESPL(s); - TULIP_PERFEND(ifioctl); - return error; -} - -/* - * These routines gets called at device spl (from ether_output). This might - * pose a problem for TULIP_USE_SOFTINTR if ether_output is called at - * device spl from another driver. - */ - -static ifnet_ret_t -tulip_ifstart( - struct ifnet * const ifp) -{ - TULIP_PERFSTART(ifstart) - tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); - - if (sc->tulip_if.if_flags & IFF_RUNNING) { - - if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP) - tulip_txput_setup(sc); - - while (sc->tulip_if.if_snd.ifq_head != NULL) { - struct mbuf *m; - IF_DEQUEUE(&sc->tulip_if.if_snd, m); - if ((m = tulip_txput(sc, m)) != NULL) { - IF_PREPEND(&sc->tulip_if.if_snd, m); - break; - } - } - if (sc->tulip_if.if_snd.ifq_head == NULL) - sc->tulip_if.if_start = tulip_ifstart_one; - } - - TULIP_PERFEND(ifstart); -} - -static ifnet_ret_t -tulip_ifstart_one( - struct ifnet * const ifp) -{ - TULIP_PERFSTART(ifstart_one) - tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); - - if ((sc->tulip_if.if_flags & IFF_RUNNING) - && sc->tulip_if.if_snd.ifq_head != NULL) { - struct mbuf *m; - IF_DEQUEUE(&sc->tulip_if.if_snd, m); - if ((m = tulip_txput(sc, m)) != NULL) - IF_PREPEND(&sc->tulip_if.if_snd, m); - } - TULIP_PERFEND(ifstart_one); -} - -/* - * Even though this routine runs at device spl, it does not break - * our use of splnet (splsoftnet under NetBSD) for the majority - * of this driver (if TULIP_USE_SOFTINTR defined) since - * if_watcbog is called from if_watchdog which is called from - * splsoftclock which is below spl[soft]net. - */ -static void -tulip_ifwatchdog( - struct ifnet *ifp) -{ - TULIP_PERFSTART(ifwatchdog) - tulip_softc_t * const sc = TULIP_IFP_TO_SOFTC(ifp); - -#if defined(TULIP_DEBUG) - u_int32_t rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs; - if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz) - sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs; - sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs; -#endif /* TULIP_DEBUG */ - - sc->tulip_if.if_timer = 1; - /* - * These should be rare so do a bulk test up front so we can just skip - * them if needed. - */ - if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) { - /* - * If the number of receive buffer is low, try to refill - */ - if (sc->tulip_flags & TULIP_RXBUFSLOW) - tulip_rx_intr(sc); - - if (sc->tulip_flags & TULIP_SYSTEMERROR) { - printf(TULIP_PRINTF_FMT ": %d system errors: last was %s\n", - TULIP_PRINTF_ARGS, sc->tulip_system_errors, - tulip_system_errors[sc->tulip_last_system_error]); - } - if (sc->tulip_statusbits) { - tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits); - sc->tulip_statusbits = 0; - } - - sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR); - } - - if (sc->tulip_txtimer) - tulip_tx_intr(sc); - if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) { - printf(TULIP_PRINTF_FMT ": transmission timeout\n", TULIP_PRINTF_ARGS); - if (TULIP_DO_AUTOSENSE(sc)) { - sc->tulip_media = TULIP_MEDIA_UNKNOWN; - sc->tulip_probe_state = TULIP_PROBE_INACTIVE; - sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP); - } - tulip_reset(sc); - tulip_init(sc); - } - - TULIP_PERFEND(ifwatchdog); - TULIP_PERFMERGE(sc, perf_intr_cycles); - TULIP_PERFMERGE(sc, perf_ifstart_cycles); - TULIP_PERFMERGE(sc, perf_ifioctl_cycles); - TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles); - TULIP_PERFMERGE(sc, perf_timeout_cycles); - TULIP_PERFMERGE(sc, perf_ifstart_one_cycles); - TULIP_PERFMERGE(sc, perf_txput_cycles); - TULIP_PERFMERGE(sc, perf_txintr_cycles); - TULIP_PERFMERGE(sc, perf_rxintr_cycles); - TULIP_PERFMERGE(sc, perf_rxget_cycles); - TULIP_PERFMERGE(sc, perf_intr); - TULIP_PERFMERGE(sc, perf_ifstart); - TULIP_PERFMERGE(sc, perf_ifioctl); - TULIP_PERFMERGE(sc, perf_ifwatchdog); - TULIP_PERFMERGE(sc, perf_timeout); - TULIP_PERFMERGE(sc, perf_ifstart_one); - TULIP_PERFMERGE(sc, perf_txput); - TULIP_PERFMERGE(sc, perf_txintr); - TULIP_PERFMERGE(sc, perf_rxintr); - TULIP_PERFMERGE(sc, perf_rxget); -} - -#if defined(__bsdi__) || (defined(__FreeBSD__) && BSD < 199506) -static ifnet_ret_t -tulip_ifwatchdog_wrapper( - int unit) -{ - tulip_ifwatchdog(&TULIP_UNIT_TO_SOFTC(unit)->tulip_if); -} -#define tulip_ifwatchdog tulip_ifwatchdog_wrapper -#endif - -/* - * All printf's are real as of now! - */ -#ifdef printf -#undef printf -#endif -#if !defined(IFF_NOTRAILERS) -#define IFF_NOTRAILERS 0 -#endif - -static void -tulip_attach( - tulip_softc_t * const sc) -{ - struct ifnet * const ifp = &sc->tulip_if; - - ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST; - ifp->if_ioctl = tulip_ifioctl; - ifp->if_start = tulip_ifstart; - ifp->if_watchdog = tulip_ifwatchdog; - ifp->if_timer = 1; -#if (!defined(__bsdi__) || _BSDI_VERSION < 199401) && !defined(__NetBSD__) - ifp->if_output = ether_output; -#endif -#if defined(__bsdi__) && _BSDI_VERSION < 199401 - ifp->if_mtu = ETHERMTU; -#endif - -#if defined(__bsdi__) && _BSDI_VERSION >= 199510 - aprint_naive(": DEC Ethernet"); - aprint_normal(": %s%s", sc->tulip_boardid, - tulip_chipdescs[sc->tulip_chipid]); - aprint_verbose(" pass %d.%d", (sc->tulip_revinfo & 0xF0) >> 4, - sc->tulip_revinfo & 0x0F); - printf("\n"); - sc->tulip_pf = aprint_normal; - aprint_normal(TULIP_PRINTF_FMT ": address " TULIP_EADDR_FMT "\n", - TULIP_PRINTF_ARGS, - TULIP_EADDR_ARGS(sc->tulip_enaddr)); -#else - printf( -#if defined(__bsdi__) - "\n" -#endif - TULIP_PRINTF_FMT ": %s%s pass %d.%d%s\n", - TULIP_PRINTF_ARGS, - sc->tulip_boardid, - tulip_chipdescs[sc->tulip_chipid], - (sc->tulip_revinfo & 0xF0) >> 4, - sc->tulip_revinfo & 0x0F, - (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM)) - == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : ""); - printf(TULIP_PRINTF_FMT ": address " TULIP_EADDR_FMT "\n", - TULIP_PRINTF_ARGS, - TULIP_EADDR_ARGS(sc->tulip_enaddr)); -#endif - -#if defined(__alpha__) - /* - * In case the SRM console told us about a bogus media, - * we need to check to be safe. - */ - if (sc->tulip_mediums[sc->tulip_media] == NULL) - sc->tulip_media = TULIP_MEDIA_UNKNOWN; -#endif - - (*sc->tulip_boardsw->bd_media_probe)(sc); -#if defined(IFM_ETHER) - ifmedia_init(&sc->tulip_ifmedia, 0, - tulip_ifmedia_change, - tulip_ifmedia_status); -#else - { - tulip_media_t media; - int cnt; - printf(TULIP_PRINTF_FMT ": media:", TULIP_PRINTF_ARGS); - for (media = TULIP_MEDIA_UNKNOWN, cnt = 1; cnt < 7 && media < TULIP_MEDIA_MAX; media++) { - if (sc->tulip_mediums[media] != NULL) { - printf(" %d=\"%s\"", cnt, tulip_mediums[media]); - cnt++; - } - } - if (cnt == 1) { - sc->tulip_features |= TULIP_HAVE_NOMEDIA; - printf(" none\n"); - } else { - printf("\n"); - } - } -#endif - sc->tulip_flags &= ~TULIP_DEVICEPROBE; -#if defined(IFM_ETHER) - tulip_ifmedia_add(sc); -#endif - - tulip_reset(sc); - -#if defined(__bsdi__) && _BSDI_VERSION >= 199510 - sc->tulip_pf = printf; - TULIP_ETHER_IFATTACH(sc); -#else - if_attach(ifp); -#if defined(__NetBSD__) || (defined(__FreeBSD__) && BSD >= 199506) - TULIP_ETHER_IFATTACH(sc); -#endif -#endif /* __bsdi__ */ - -#if NBPFILTER > 0 - TULIP_BPF_ATTACH(sc); -#endif - -#if defined(__NetBSD__) && NRND > 0 - rnd_attach_source(&sc->tulip_rndsource, sc->tulip_dev.dv_xname, - RND_TYPE_NET, 0); -#endif -} - -#if defined(TULIP_BUS_DMA) -#if !defined(TULIP_BUS_DMA_NOTX) || !defined(TULIP_BUS_DMA_NORX) -static int -tulip_busdma_allocmem( - tulip_softc_t * const sc, - size_t size, - bus_dmamap_t *map_p, - tulip_desc_t **desc_p) -{ - bus_dma_segment_t segs[1]; - int nsegs, error; - error = bus_dmamem_alloc(sc->tulip_dmatag, size, 1, CLBYTES, - segs, sizeof(segs)/sizeof(segs[0]), - &nsegs, BUS_DMA_NOWAIT); - if (error == 0) { - void *desc; - error = bus_dmamem_map(sc->tulip_dmatag, segs, nsegs, size, - (void *) &desc, BUS_DMA_NOWAIT|BUS_DMA_COHERENT); - if (error == 0) { - bus_dmamap_t map; - error = bus_dmamap_create(sc->tulip_dmatag, size, 1, size, 0, - BUS_DMA_NOWAIT, &map); - if (error == 0) { - error = bus_dmamap_load(sc->tulip_dmatag, map, desc, - size, NULL, BUS_DMA_NOWAIT); - if (error) - bus_dmamap_destroy(sc->tulip_dmatag, map); - else - *map_p = map; - } - if (error) - bus_dmamem_unmap(sc->tulip_dmatag, desc, size); - } - if (error) - bus_dmamem_free(sc->tulip_dmatag, segs, nsegs); - else - *desc_p = desc; - } - return error; -} -#endif - -static int -tulip_busdma_init( - tulip_softc_t * const sc) -{ - int error = 0; - -#if !defined(TULIP_BUS_DMA_NOTX) - /* - * Allocate dmamap for setup descriptor - */ - error = bus_dmamap_create(sc->tulip_dmatag, sizeof(sc->tulip_setupbuf), 2, - sizeof(sc->tulip_setupbuf), 0, BUS_DMA_NOWAIT, - &sc->tulip_setupmap); - if (error == 0) { - error = bus_dmamap_load(sc->tulip_dmatag, sc->tulip_setupmap, - sc->tulip_setupbuf, sizeof(sc->tulip_setupbuf), - NULL, BUS_DMA_NOWAIT); - if (error) - bus_dmamap_destroy(sc->tulip_dmatag, sc->tulip_setupmap); - } - /* - * Allocate space and dmamap for transmit ring - */ - if (error == 0) { - error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_TXDESCS, - &sc->tulip_txdescmap, - &sc->tulip_txdescs); - } - - /* - * Allocate dmamaps for each transmit descriptors - */ - if (error == 0) { - while (error == 0 && sc->tulip_txmaps_free < TULIP_TXDESCS) { - bus_dmamap_t map; - if ((error = TULIP_TXMAP_CREATE(sc, &map)) == 0) - sc->tulip_txmaps[sc->tulip_txmaps_free++] = map; - } - if (error) { - while (sc->tulip_txmaps_free > 0) - bus_dmamap_destroy(sc->tulip_dmatag, - sc->tulip_txmaps[--sc->tulip_txmaps_free]); - } - } -#else - if (error == 0) { - sc->tulip_txdescs = (tulip_desc_t *) malloc(TULIP_TXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT); - if (sc->tulip_txdescs == NULL) - error = ENOMEM; - } -#endif -#if !defined(TULIP_BUS_DMA_NORX) - /* - * Allocate space and dmamap for receive ring - */ - if (error == 0) { - error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_RXDESCS, - &sc->tulip_rxdescmap, - &sc->tulip_rxdescs); - } - - /* - * Allocate dmamaps for each receive descriptors - */ - if (error == 0) { - while (error == 0 && sc->tulip_rxmaps_free < TULIP_RXDESCS) { - bus_dmamap_t map; - if ((error = TULIP_RXMAP_CREATE(sc, &map)) == 0) - sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map; - } - if (error) { - while (sc->tulip_rxmaps_free > 0) - bus_dmamap_destroy(sc->tulip_dmatag, - sc->tulip_rxmaps[--sc->tulip_rxmaps_free]); - } - } -#else - if (error == 0) { - sc->tulip_rxdescs = (tulip_desc_t *) malloc(TULIP_RXDESCS * sizeof(tulip_desc_t), M_DEVBUF, M_NOWAIT); - if (sc->tulip_rxdescs == NULL) - error = ENOMEM; - } -#endif - return error; -} -#endif /* TULIP_BUS_DMA */ - -static void -tulip_initcsrs( - tulip_softc_t * const sc, - tulip_csrptr_t csr_base, - size_t csr_size) -{ - sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size; - sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size; - sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size; - sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size; - sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size; - sc->tulip_csrs.csr_status = csr_base + 5 * csr_size; - sc->tulip_csrs.csr_command = csr_base + 6 * csr_size; - sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size; - sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size; - sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size; - sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size; - sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size; - sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size; - sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size; - sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size; - sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size; -#if defined(TULIP_EISA) - sc->tulip_csrs.csr_enetrom = csr_base + DE425_ENETROM_OFFSET; -#endif -} - -static void -tulip_initring( - tulip_softc_t * const sc, - tulip_ringinfo_t * const ri, - tulip_desc_t *descs, - int ndescs) -{ - ri->ri_max = ndescs; - ri->ri_first = descs; - ri->ri_last = ri->ri_first + ri->ri_max; - bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max); - ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING; -} - -/* - * This is the PCI configuration support. Since the 21040 is available - * on both EISA and PCI boards, one must be careful in how defines the - * 21040 in the config file. - */ - -#define PCI_CFID 0x00 /* Configuration ID */ -#define PCI_CFCS 0x04 /* Configurtion Command/Status */ -#define PCI_CFRV 0x08 /* Configuration Revision */ -#define PCI_CFLT 0x0c /* Configuration Latency Timer */ -#define PCI_CBIO 0x10 /* Configuration Base IO Address */ -#define PCI_CBMA 0x14 /* Configuration Base Memory Address */ -#define PCI_CFIT 0x3c /* Configuration Interrupt */ -#define PCI_CFDA 0x40 /* Configuration Driver Area */ - -#if defined(TULIP_EISA) -static const int tulip_eisa_irqs[4] = { IRQ5, IRQ9, IRQ10, IRQ11 }; -#endif - -#if defined(__FreeBSD__) - -#define TULIP_PCI_ATTACH_ARGS pcici_t config_id, int unit -#define TULIP_SHUTDOWN_ARGS int howto, void * arg - -#if defined(TULIP_DEVCONF) -static void tulip_shutdown(TULIP_SHUTDOWN_ARGS); - -static int -tulip_pci_shutdown( - struct kern_devconf * const kdc, - int force) -{ - if (kdc->kdc_unit < TULIP_MAX_DEVICES) { - tulip_softc_t * const sc = TULIP_UNIT_TO_SOFTC(kdc->kdc_unit); - if (sc != NULL) - tulip_shutdown(0, sc); - } - (void) dev_detach(kdc); - return 0; -} -#endif - -static char* -tulip_pci_probe( - pcici_t config_id, - pcidi_t device_id) -{ - if (PCI_VENDORID(device_id) != DEC_VENDORID) - return NULL; - if (PCI_CHIPID(device_id) == CHIPID_21040) - return "Digital 21040 Ethernet"; - if (PCI_CHIPID(device_id) == CHIPID_21041) - return "Digital 21041 Ethernet"; - if (PCI_CHIPID(device_id) == CHIPID_21140) { - u_int32_t revinfo = pci_conf_read(config_id, PCI_CFRV) & 0xFF; - if (revinfo >= 0x20) - return "Digital 21140A Fast Ethernet"; - else - return "Digital 21140 Fast Ethernet"; - } - if (PCI_CHIPID(device_id) == CHIPID_21142) { - u_int32_t revinfo = pci_conf_read(config_id, PCI_CFRV) & 0xFF; - if (revinfo >= 0x20) - return "Digital 21143 Fast Ethernet"; - else - return "Digital 21142 Fast Ethernet"; - } - return NULL; -} - -static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS); -static u_long tulip_pci_count; - -struct pci_device dedevice = { - "de", - tulip_pci_probe, - tulip_pci_attach, - &tulip_pci_count, -#if defined(TULIP_DEVCONF) - tulip_pci_shutdown, -#endif -}; - -DATA_SET (pcidevice_set, dedevice); -#endif /* __FreeBSD__ */ - -#if defined(__bsdi__) -#define TULIP_PCI_ATTACH_ARGS struct device * const parent, struct device * const self, void * const aux -#define TULIP_SHUTDOWN_ARGS void *arg - -static int -tulip_pci_match( - pci_devaddr_t *pa) -{ - int irq; - unsigned id; - - id = pci_inl(pa, PCI_VENDOR_ID); - if (PCI_VENDORID(id) != DEC_VENDORID) - return 0; - id = PCI_CHIPID(id); - if (id != CHIPID_21040 && id != CHIPID_21041 - && id != CHIPID_21140 && id != CHIPID_21142) - return 0; - irq = pci_inl(pa, PCI_I_LINE) & 0xFF; - if (irq == 0 || irq >= 16) { - printf("de?: invalid IRQ %d; skipping\n", irq); - return 0; - } - return 1; -} - -static int -tulip_probe( - struct device *parent, - struct cfdata *cf, - void *aux) -{ - struct isa_attach_args * const ia = (struct isa_attach_args *) aux; - unsigned irq, slot; - pci_devaddr_t *pa; - -#if _BSDI_VERSION >= 199401 - switch (ia->ia_bustype) { - case BUS_PCI: -#endif - pa = pci_scan(tulip_pci_match); - if (pa == NULL) - return 0; - - irq = (1 << (pci_inl(pa, PCI_I_LINE) & 0xFF)); - - /* Get the base address; assume the BIOS set it up correctly */ -#if defined(TULIP_IOMAPPED) - ia->ia_maddr = NULL; - ia->ia_msize = 0; - ia->ia_iobase = pci_inl(pa, PCI_CBIO) & ~7; - pci_outl(pa, PCI_CBIO, 0xFFFFFFFF); - ia->ia_iosize = ((~pci_inl(pa, PCI_CBIO)) | 7) + 1; - pci_outl(pa, PCI_CBIO, (int) ia->ia_iobase); - - /* Disable memory space access */ - pci_outl(pa, PCI_COMMAND, pci_inl(pa, PCI_COMMAND) & ~2); -#else - ia->ia_maddr = (caddr_t) (pci_inl(pa, PCI_CBMA) & ~7); - pci_outl(pa, PCI_CBMA, 0xFFFFFFFF); - ia->ia_msize = ((~pci_inl(pa, PCI_CBMA)) | 7) + 1; - pci_outl(pa, PCI_CBMA, (int) ia->ia_maddr); - ia->ia_iobase = 0; - ia->ia_iosize = 0; - - /* Disable I/O space access */ - pci_outl(pa, PCI_COMMAND, pci_inl(pa, PCI_COMMAND) & ~1); -#endif /* TULIP_IOMAPPED */ - - ia->ia_aux = (void *) pa; -#if _BSDI_VERSION >= 199401 - break; - -#if defined(TULIP_EISA) - case BUS_EISA: { - unsigned tmp; - - if ((slot = eisa_match(cf, ia)) == 0) - return 0; - ia->ia_iobase = slot << 12; - ia->ia_iosize = EISA_NPORT; - eisa_slotalloc(slot); - tmp = inb(ia->ia_iobase + DE425_CFG0); - irq = tulip_eisa_irqs[(tmp >> 1) & 0x03]; - /* - * Until BSD/OS likes level interrupts, force - * the DE425 into edge-triggered mode. - */ - if ((tmp & 1) == 0) - outb(ia->ia_iobase + DE425_CFG0, tmp | 1); - /* - * CBIO needs to map to the EISA slot - * enable I/O access and Master - */ - outl(ia->ia_iobase + DE425_CBIO, ia->ia_iobase); - outl(ia->ia_iobase + DE425_CFCS, 5 | inl(ia->ia_iobase + DE425_CFCS)); - ia->ia_aux = NULL; - break; - } -#endif /* TULIP_EISA */ - default: - return 0; - } -#endif - - /* PCI bus masters don't use host DMA channels */ - ia->ia_drq = DRQNONE; - - if (ia->ia_irq != IRQUNK && irq != ia->ia_irq) { - printf("de%d: error: desired IRQ of %d does not match device's " - "actual IRQ of %d,\n", - cf->cf_unit, - ffs(ia->ia_irq) - 1, ffs(irq) - 1); - return 0; - } - if (ia->ia_irq == IRQUNK) - ia->ia_irq = irq; -#ifdef IRQSHARE - ia->ia_irq |= IRQSHARE; -#endif - return 1; -} - -static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS); - -#if defined(TULIP_EISA) -static char *tulip_eisa_ids[] = { - "DEC4250", - NULL -}; -#endif - -struct cfdriver decd = { - 0, "de", tulip_probe, tulip_pci_attach, -#if _BSDI_VERSION >= 199401 - DV_IFNET, -#endif - sizeof(tulip_softc_t), -#if defined(TULIP_EISA) - tulip_eisa_ids -#endif -}; - -#endif /* __bsdi__ */ - -#if defined(__NetBSD__) -#define TULIP_PCI_ATTACH_ARGS struct device * const parent, struct device * const self, void * const aux -#define TULIP_SHUTDOWN_ARGS void *arg -static int -tulip_pci_probe( - struct device *parent, - struct cfdata *match, - void *aux) -{ - struct pci_attach_args *pa = (struct pci_attach_args *) aux; - - if (PCI_VENDORID(pa->pa_id) != DEC_VENDORID) - return 0; - if (PCI_CHIPID(pa->pa_id) == CHIPID_21040 - || PCI_CHIPID(pa->pa_id) == CHIPID_21041 - || PCI_CHIPID(pa->pa_id) == CHIPID_21140 - || PCI_CHIPID(pa->pa_id) == CHIPID_21142) - return 1; - - return 0; -} - -static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS); - -struct cfattach de_ca = { - sizeof(tulip_softc_t), tulip_pci_probe, tulip_pci_attach -}; - -#endif /* __NetBSD__ */ - -static void -tulip_shutdown( - TULIP_SHUTDOWN_ARGS) -{ - tulip_softc_t * const sc = arg; - TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); - DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at - 33MHz that comes to two microseconds but wait a - bit longer anyways) */ -} - -static void -tulip_pci_attach( - TULIP_PCI_ATTACH_ARGS) -{ -#if defined(__FreeBSD__) - tulip_softc_t *sc; -#define PCI_CONF_WRITE(r, v) pci_conf_write(config_id, (r), (v)) -#define PCI_CONF_READ(r) pci_conf_read(config_id, (r)) -#define PCI_GETBUSDEVINFO(sc) ((void)((sc)->tulip_pci_busno = ((config_id.cfg1 >> 16) & 0xFF), /* XXX */ \ - (sc)->tulip_pci_devno = ((config_id.cfg1 >> 11) & 0x1F))) /* XXX */ -#endif -#if defined(__bsdi__) - tulip_softc_t * const sc = (tulip_softc_t *) self; - struct isa_attach_args * const ia = (struct isa_attach_args *) aux; - pci_devaddr_t *pa = (pci_devaddr_t *) ia->ia_aux; - const int unit = sc->tulip_dev.dv_unit; -#define PCI_CONF_WRITE(r, v) pci_outl(pa, (r), (v)) -#define PCI_CONF_READ(r) pci_inl(pa, (r)) -#define PCI_GETBUSDEVINFO(sc) ((void)((sc)->tulip_pci_busno = pa->d_bus, \ - (sc)->tulip_pci_devno = pa->d_agent)) -#endif -#if defined(__NetBSD__) - tulip_softc_t * const sc = (tulip_softc_t *) self; - struct pci_attach_args * const pa = (struct pci_attach_args *) aux; - const int unit = sc->tulip_dev.dv_unit; -#define PCI_CONF_WRITE(r, v) pci_conf_write(pa->pa_pc, pa->pa_tag, (r), (v)) -#define PCI_CONF_READ(r) pci_conf_read(pa->pa_pc, pa->pa_tag, (r)) -#define PCI_GETBUSDEVINFO(sc) do { \ - (sc)->tulip_pci_busno = parent; \ - (sc)->tulip_pci_devno = pa->pa_device; \ - } while (0) -#if defined(__alpha__) - tulip_media_t media = TULIP_MEDIA_UNKNOWN; -#endif -#endif /* __NetBSD__ */ - int retval, idx; - u_int32_t revinfo, cfdainfo, id; -#if !defined(TULIP_IOMAPPED) && defined(__FreeBSD__) - vaddr_t pa_csrs; -#endif - unsigned csroffset = TULIP_PCI_CSROFFSET; - unsigned csrsize = TULIP_PCI_CSRSIZE; - tulip_csrptr_t csr_base; - tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN; - - if (unit >= TULIP_MAX_DEVICES) { -#ifdef __FreeBSD__ - printf("de%d", unit); -#endif - printf(": not configured; limit of %d reached or exceeded\n", - TULIP_MAX_DEVICES); - return; - } - -#if defined(__bsdi__) - if (pa != NULL) { - revinfo = pci_inl(pa, PCI_CFRV) & 0xFF; - id = pci_inl(pa, PCI_CFID); - cfdainfo = pci_inl(pa, PCI_CFDA); -#if defined(TULIP_EISA) - } else { - revinfo = inl(ia->ia_iobase + DE425_CFRV) & 0xFF; - csroffset = TULIP_EISA_CSROFFSET; - csrsize = TULIP_EISA_CSRSIZE; - chipid = TULIP_DE425; - cfdainfo = 0; -#endif /* TULIP_EISA */ - } -#else /* __bsdi__ */ - revinfo = PCI_CONF_READ(PCI_CFRV) & 0xFF; - id = PCI_CONF_READ(PCI_CFID); - cfdainfo = PCI_CONF_READ(PCI_CFDA); -#endif /* __bsdi__ */ - - if (PCI_VENDORID(id) == DEC_VENDORID) { - if (PCI_CHIPID(id) == CHIPID_21040) - chipid = TULIP_21040; - else if (PCI_CHIPID(id) == CHIPID_21041) - chipid = TULIP_21041; - else if (PCI_CHIPID(id) == CHIPID_21140) - chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140; - else if (PCI_CHIPID(id) == CHIPID_21142) - chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142; - } - if (chipid == TULIP_CHIPID_UNKNOWN) - return; - - if ((chipid == TULIP_21040 || chipid == TULIP_DE425) && revinfo < 0x20) { -#ifdef __FreeBSD__ - printf("de%d", unit); -#endif - printf(": not configured; 21040 pass 2.0 required (%d.%d found)\n", - revinfo >> 4, revinfo & 0x0f); - return; - } else if (chipid == TULIP_21140 && revinfo < 0x11) { -#ifndef __FreeBSD__ - printf("\n"); -#endif - printf("de%d: not configured; 21140 pass 1.1 required (%d.%d found)\n", - unit, revinfo >> 4, revinfo & 0x0f); - return; - } - -#if defined(__FreeBSD__) - sc = (tulip_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT); - if (sc == NULL) - return; - bzero(sc, sizeof(*sc)); /* Zero out the softc*/ -#endif - - PCI_GETBUSDEVINFO(sc); - sc->tulip_chipid = chipid; - sc->tulip_flags |= TULIP_DEVICEPROBE; - if (chipid == TULIP_21140 || chipid == TULIP_21140A) - sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD; - if (chipid == TULIP_21140A && revinfo <= 0x22) - sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW; - if (chipid == TULIP_21140) - sc->tulip_features |= TULIP_HAVE_BROKEN_HASH; - if (chipid != TULIP_21040 && chipid != TULIP_DE425 && chipid != TULIP_21140) - sc->tulip_features |= TULIP_HAVE_POWERMGMT; - if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) { - sc->tulip_features |= TULIP_HAVE_DUALSENSE; - if (chipid != TULIP_21041 || revinfo >= 0x20) - sc->tulip_features |= TULIP_HAVE_SIANWAY; - if (chipid != TULIP_21041) - sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD; - if (chipid != TULIP_21041 && revinfo >= 0x20) - sc->tulip_features |= TULIP_HAVE_SIA100; - } - - if (sc->tulip_features & TULIP_HAVE_POWERMGMT - && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) { - cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE); - PCI_CONF_WRITE(PCI_CFDA, cfdainfo); - DELAY(11*1000); - } -#if defined(__alpha__) && defined(__NetBSD__) - /* - * The Alpha SRM console encodes a console set media in the driver - * part of the CFDA register. Note that the Multia presents a - * problem in that its BNC mode is really EXTSIA. So in that case - * force a probe. - */ - switch ((cfdainfo >> 8) & 0xff) { - case 1: media = chipid > TULIP_DE425 ? TULIP_MEDIA_AUI : TULIP_MEDIA_AUIBNC; break; - case 2: media = chipid > TULIP_DE425 ? TULIP_MEDIA_BNC : TULIP_MEDIA_UNKNOWN; break; - case 3: media = TULIP_MEDIA_10BASET; break; - case 4: media = TULIP_MEDIA_10BASET_FD; break; - case 5: media = TULIP_MEDIA_100BASETX; break; - case 6: media = TULIP_MEDIA_100BASETX_FD; break; - default: media = TULIP_MEDIA_UNKNOWN; break; - } -#endif - -#if defined(__NetBSD__) - bcopy(self->dv_xname, sc->tulip_if.if_xname, IFNAMSIZ); - sc->tulip_if.if_softc = sc; - sc->tulip_pc = pa->pa_pc; -#if defined(TULIP_BUS_DMA) - sc->tulip_dmatag = pa->pa_dmat; -#endif -#else - sc->tulip_unit = unit; - sc->tulip_name = "de"; -#endif - sc->tulip_revinfo = revinfo; -#if defined(__FreeBSD__) -#if BSD >= 199506 - sc->tulip_if.if_softc = sc; -#endif -#if defined(TULIP_IOMAPPED) - retval = pci_map_port(config_id, PCI_CBIO, &csr_base); -#else - retval = pci_map_mem(config_id, PCI_CBMA, (vaddr_t *) &csr_base, &pa_csrs); -#endif - if (!retval) { - free((caddr_t) sc, M_DEVBUF); - return; - } - tulips[unit] = sc; -#endif /* __FreeBSD__ */ - -#if defined(__bsdi__) - sc->tulip_pf = printf; -#if defined(TULIP_IOMAPPED) - csr_base = ia->ia_iobase; -#else - csr_base = (vaddr_t) mapphys((vaddr_t) ia->ia_maddr, ia->ia_msize); -#endif -#endif /* __bsdi__ */ - -#if defined(__NetBSD__) - csr_base = 0; - { - bus_space_tag_t iot, memt; - bus_space_handle_t ioh, memh; - int ioh_valid, memh_valid; - - ioh_valid = (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, - &iot, &ioh, NULL, NULL) == 0); - memh_valid = (pci_mapreg_map(pa, PCI_CBMA, - PCI_MAPREG_TYPE_MEM | - PCI_MAPREG_MEM_TYPE_32BIT, - 0, &memt, &memh, NULL, NULL) == 0); - if (memh_valid) { - sc->tulip_bustag = memt; - sc->tulip_bushandle = memh; - } else if (ioh_valid) { - sc->tulip_bustag = iot; - sc->tulip_bushandle = ioh; - } else { - printf(": unable to map device registers\n"); - return; - } - - /* Make sure bus mastering is enabled. */ - pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, - pci_conf_read(pa->pa_pc, pa->pa_tag, - PCI_COMMAND_STATUS_REG) | - PCI_COMMAND_MASTER_ENABLE); - } -#endif /* __NetBSD__ */ - - tulip_initcsrs(sc, csr_base + csroffset, csrsize); - -#if defined(TULIP_BUS_DMA) - if ((retval = tulip_busdma_init(sc)) != 0) { - printf("error initing bus_dma: %d\n", retval); - return; - } -#else - sc->tulip_txdescs = (tulip_desc_t *) malloc((TULIP_TXDESCS+TULIP_RXDESCS)*sizeof(tulip_desc_t), M_DEVBUF, M_WAITOK); - sc->tulip_rxdescs = sc->tulip_txdescs + TULIP_TXDESCS; -#endif - - tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS); - tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS); - - /* - * Make sure there won't be any interrupts or such... - */ - TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET); - DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at - 33MHz that comes to two microseconds but wait a - bit longer anyways) */ - - if ((retval = tulip_read_macaddr(sc)) < 0) { -#if defined(__FreeBSD__) - printf(TULIP_PRINTF_FMT, TULIP_PRINTF_ARGS); -#endif - printf(": can't read ENET ROM (why=%d) (", retval); - for (idx = 0; idx < 32; idx++) - printf("%02x", sc->tulip_rombuf[idx]); - printf("\n"); - printf(TULIP_PRINTF_FMT ": %s%s pass %d.%d\n", - TULIP_PRINTF_ARGS, - sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid], - (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F); - printf(TULIP_PRINTF_FMT ": address unknown\n", TULIP_PRINTF_ARGS); - } else { - tulip_spl_t s; - tulip_intrfunc_t (*intr_rtn)(void *) = tulip_intr_normal; - - if (sc->tulip_features & TULIP_HAVE_SHAREDINTR) - intr_rtn = tulip_intr_shared; - -#if defined(__NetBSD__) - if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) { - pci_intr_handle_t intrhandle; - const char *intrstr; - - printf("\n"); - - if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin, - pa->pa_intrline, &intrhandle)) { - printf("%s: couldn't map interrupt\n", sc->tulip_dev.dv_xname); - return; - } - intrstr = pci_intr_string(pa->pa_pc, intrhandle); - sc->tulip_ih = pci_intr_establish(pa->pa_pc, intrhandle, IPL_NET, - intr_rtn, sc); - if (sc->tulip_ih == NULL) { - printf("%s: couldn't establish interrupt", - sc->tulip_dev.dv_xname); - if (intrstr != NULL) - printf(" at %s", intrstr); - printf("\n"); - return; - } - printf("%s: interrupting at %s\n", sc->tulip_dev.dv_xname, intrstr); - } - sc->tulip_ats = shutdownhook_establish(tulip_shutdown, sc); - if (sc->tulip_ats == NULL) - printf("%s: warning: couldn't establish shutdown hook\n", - sc->tulip_xname); -#endif -#if defined(__FreeBSD__) - if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) { - if (!pci_map_int (config_id, intr_rtn, (void*) sc, &net_imask)) { - printf(TULIP_PRINTF_FMT ": couldn't map interrupt\n", - TULIP_PRINTF_ARGS); - return; - } - } -#if !defined(TULIP_DEVCONF) - at_shutdown(tulip_shutdown, sc, SHUTDOWN_POST_SYNC); -#endif -#endif -#if defined(__bsdi__) - if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) { - isa_establish(&sc->tulip_id, &sc->tulip_dev); - - sc->tulip_ih.ih_fun = intr_rtn; - sc->tulip_ih.ih_arg = (void *) sc; - intr_establish(ia->ia_irq, &sc->tulip_ih, DV_NET); - } - - sc->tulip_ats.func = tulip_shutdown; - sc->tulip_ats.arg = (void *) sc; - atshutdown(&sc->tulip_ats, ATSH_ADD); -#endif -#if defined(TULIP_USE_SOFTINTR) - if (sc->tulip_unit > tulip_softintr_max_unit) - tulip_softintr_max_unit = sc->tulip_unit; -#endif - - s = TULIP_RAISESPL(); -#if defined(__alpha__) && defined(__NetBSD__) - sc->tulip_media = media; -#endif - tulip_attach(sc); -#if defined(__alpha__) && defined(__NetBSD__) - if (sc->tulip_media != TULIP_MEDIA_UNKNOWN) - tulip_linkup(sc, media); -#endif - TULIP_RESTORESPL(s); - } -} diff --git a/sys/pci/if_devar.h b/sys/pci/if_devar.h deleted file mode 100644 index 0f0c972710f4..000000000000 --- a/sys/pci/if_devar.h +++ /dev/null @@ -1,1140 +0,0 @@ -/* $NetBSD: if_devar.h,v 1.32 1999/04/01 14:55:25 tsubai Exp $ */ - -/*- - * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com) - * 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. The name of the author may not be used to endorse or promote products - * derived from this software withough specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - * - * Id: if_devar.h,v 1.28 1997/07/03 16:55:07 thomas Exp - */ - -#if !defined(_DEVAR_H) -#define _DEVAR_H - -#if defined(__NetBSD__) - -#include "rnd.h" -#if NRND > 0 -#include <sys/rnd.h> -#endif - -#if NetBSD >= 199803 -#define TULIP_BUS_DMA 1 -/* #define TULIP_BUS_DMA_NORX 1 */ -/* #define TULIP_BUS_DMA_NOTX 1 */ -#endif - -typedef bus_addr_t tulip_csrptr_t; - -#define TULIP_CSR_READ(sc, csr) \ - bus_space_read_4((sc)->tulip_bustag, (sc)->tulip_bushandle, (sc)->tulip_csrs.csr) -#define TULIP_CSR_WRITE(sc, csr, val) \ - bus_space_write_4((sc)->tulip_bustag, (sc)->tulip_bushandle, (sc)->tulip_csrs.csr, (val)) - -#define TULIP_CSR_READBYTE(sc, csr) \ - bus_space_read_1((sc)->tulip_bustag, (sc)->tulip_bushandle, (sc)->tulip_csrs.csr) -#define TULIP_CSR_WRITEBYTE(sc, csr, val) \ - bus_space_write_1((sc)->tulip_bustag, (sc)->tulip_bushandle, (sc)->tulip_csrs.csr, (val)) -#endif /* __NetBSD__ */ - -#ifdef TULIP_IOMAPPED -#define TULIP_EISA_CSRSIZE 16 -#define TULIP_EISA_CSROFFSET 0 -#define TULIP_PCI_CSRSIZE 8 -#define TULIP_PCI_CSROFFSET 0 - -#if !defined(__NetBSD__) -typedef u_int16_t tulip_csrptr_t; - -#define TULIP_CSR_READ(sc, csr) (inl((sc)->tulip_csrs.csr)) -#define TULIP_CSR_WRITE(sc, csr, val) outl((sc)->tulip_csrs.csr, val) - -#define TULIP_CSR_READBYTE(sc, csr) (inb((sc)->tulip_csrs.csr)) -#define TULIP_CSR_WRITEBYTE(sc, csr, val) outb((sc)->tulip_csrs.csr, val) -#endif /* __NetBSD__ */ - -#else /* TULIP_IOMAPPED */ - -#define TULIP_PCI_CSRSIZE 8 -#define TULIP_PCI_CSROFFSET 0 - -#if !defined(__NetBSD__) -typedef volatile u_int32_t *tulip_csrptr_t; - -/* - * macros to read and write CSRs. Note that the "0 +" in - * READ_CSR is to prevent the macro from being an lvalue - * and WRITE_CSR shouldn't be assigned from. - */ -#define TULIP_CSR_READ(sc, csr) (0 + *(sc)->tulip_csrs.csr) -#define TULIP_CSR_WRITE(sc, csr, val) ((void)(*(sc)->tulip_csrs.csr = (val))) -#endif /* __NetBSD__ */ - -#endif /* TULIP_IOMAPPED */ - -/* - * This structure contains "pointers" for the registers on - * the various 21x4x chips. CSR0 through CSR8 are common - * to all chips. After that, it gets messy... - */ -typedef struct { - tulip_csrptr_t csr_busmode; /* CSR0 */ - tulip_csrptr_t csr_txpoll; /* CSR1 */ - tulip_csrptr_t csr_rxpoll; /* CSR2 */ - tulip_csrptr_t csr_rxlist; /* CSR3 */ - tulip_csrptr_t csr_txlist; /* CSR4 */ - tulip_csrptr_t csr_status; /* CSR5 */ - tulip_csrptr_t csr_command; /* CSR6 */ - tulip_csrptr_t csr_intr; /* CSR7 */ - tulip_csrptr_t csr_missed_frames; /* CSR8 */ - tulip_csrptr_t csr_9; /* CSR9 */ - tulip_csrptr_t csr_10; /* CSR10 */ - tulip_csrptr_t csr_11; /* CSR11 */ - tulip_csrptr_t csr_12; /* CSR12 */ - tulip_csrptr_t csr_13; /* CSR13 */ - tulip_csrptr_t csr_14; /* CSR14 */ - tulip_csrptr_t csr_15; /* CSR15 */ -} tulip_regfile_t; - -#define csr_enetrom csr_9 /* 21040 */ -#define csr_reserved csr_10 /* 21040 */ -#define csr_full_duplex csr_11 /* 21040 */ -#define csr_bootrom csr_10 /* 21041/21140A/?? */ -#define csr_gp csr_12 /* 21140* */ -#define csr_watchdog csr_15 /* 21140* */ -#define csr_gp_timer csr_11 /* 21041/21140* */ -#define csr_srom_mii csr_9 /* 21041/21140* */ -#define csr_sia_status csr_12 /* 2104x */ -#define csr_sia_connectivity csr_13 /* 2104x */ -#define csr_sia_tx_rx csr_14 /* 2104x */ -#define csr_sia_general csr_15 /* 2104x */ - -/* - * While 21x4x allows chaining of its descriptors, this driver - * doesn't take advantage of it. We keep the descriptors in a - * traditional FIFO ring. - */ -typedef struct { - tulip_desc_t *ri_first; /* first entry in ring */ - tulip_desc_t *ri_last; /* one after last entry */ - tulip_desc_t *ri_nextin; /* next to processed by host */ - tulip_desc_t *ri_nextout; /* next to processed by adapter */ - int ri_max; - int ri_free; -} tulip_ringinfo_t; - -/* - * The 21040 has a stupid restriction in that the receive - * buffers must be longword aligned. But since Ethernet - * headers are not a multiple of longwords in size this forces - * the data to non-longword aligned. Since IP requires the - * data to be longword aligned, we need to copy it after it has - * been DMA'ed in our memory. - * - * Since we have to copy it anyways, we might as well as allocate - * dedicated receive space for the input. This allows to use a - * small receive buffer size and more ring entries to be able to - * better keep with a flood of tiny Ethernet packets. - * - * The receive space MUST ALWAYS be a multiple of the page size. - * And the number of receive descriptors multiplied by the size - * of the receive buffers must equal the recevive space. This - * is so that we can manipulate the page tables so that even if a - * packet wraps around the end of the receive space, we can - * treat it as virtually contiguous. - * - * The above used to be true (the stupid restriction is still true) - * but we gone to directly DMA'ing into MBUFs (unless it's on an - * architecture which can't handle unaligned accesses) because with - * 100Mb/s cards the copying is just too much of a hit. - */ -#if !defined(__i386__) && !defined(__vax__) -#define TULIP_COPY_RXDATA 1 -#endif - -#define TULIP_DATA_PER_DESC 2032 -#define TULIP_TXTIMER 4 -#define TULIP_RXDESCS 48 -#define TULIP_TXDESCS 32 -#define TULIP_RXQ_TARGET 32 -#if TULIP_RXQ_TARGET >= TULIP_RXDESCS -#error TULIP_RXQ_TARGET must be less than TULIP_RXDESCS -#endif -#define TULIP_RX_BUFLEN ((MCLBYTES < 2048 ? MCLBYTES : 2048) - 16) - -/* - * Forward reference to make C happy. - */ -typedef struct _tulip_softc_t tulip_softc_t; - -/* - * The various controllers support. Technically the DE425 is just - * a 21040 on EISA. But since it remarkably difference from normal - * 21040s, we give it its own chip id. - */ - -typedef enum { - TULIP_21040, TULIP_DE425, - TULIP_21041, - TULIP_21140, TULIP_21140A, TULIP_21142, - TULIP_21143, - TULIP_CHIPID_UNKNOWN -} tulip_chipid_t; - -/* - * Various physical media types supported. - * BNCAUI is BNC or AUI since on the 21040 you can't really tell - * which is in use. - */ -typedef enum { - TULIP_MEDIA_UNKNOWN, - TULIP_MEDIA_10BASET, - TULIP_MEDIA_10BASET_FD, - TULIP_MEDIA_BNC, - TULIP_MEDIA_AUI, - TULIP_MEDIA_EXTSIA, - TULIP_MEDIA_AUIBNC, - TULIP_MEDIA_100BASETX, - TULIP_MEDIA_100BASETX_FD, - TULIP_MEDIA_100BASET4, - TULIP_MEDIA_100BASEFX, - TULIP_MEDIA_100BASEFX_FD, - TULIP_MEDIA_MAX -} tulip_media_t; - -#define TULIP_BIT(b) (1L << ((int)(b))) -#define TULIP_FDBIT(m) (1L << ((int)TULIP_MEDIA_ ## m ## _FD)) -#define TULIP_MBIT(m) (1L << ((int)TULIP_MEDIA_ ## m )) -#define TULIP_IS_MEDIA_FD(m) (TULIP_BIT(m) & \ - (TULIP_FDBIT(10BASET) \ - |TULIP_FDBIT(100BASETX) \ - |TULIP_FDBIT(100BASEFX))) -#define TULIP_CAN_MEDIA_FD(m) (TULIP_BIT(m) & \ - (TULIP_MBIT(10BASET) \ - |TULIP_MBIT(100BASETX) \ - |TULIP_MBIT(100BASEFX))) -#define TULIP_FD_MEDIA_OF(m) ((tulip_media_t)((m) + 1)) -#define TULIP_HD_MEDIA_OF(m) ((tulip_media_t)((m) - 1)) -#define TULIP_IS_MEDIA_100MB(m) ((m) >= TULIP_MEDIA_100BASETX) -#define TULIP_IS_MEDIA_TP(m) ((TULIP_BIT(m) & \ - (TULIP_MBIT(BNC) \ - |TULIP_MBIT(AUI) \ - |TULIP_MBIT(AUIBNC) \ - |TULIP_MBIT(EXTSIA))) == 0) - -#define TULIP_SROM_ATTR_MII 0x0100 -#define TULIP_SROM_ATTR_NWAY 0x0200 -#define TULIP_SROM_ATTR_AUTOSENSE 0x0400 -#define TULIP_SROM_ATTR_POWERUP 0x0800 -#define TULIP_SROM_ATTR_NOLINKPASS 0x1000 - -typedef struct { - enum { - TULIP_MEDIAINFO_NONE, - TULIP_MEDIAINFO_SIA, - TULIP_MEDIAINFO_GPR, - TULIP_MEDIAINFO_MII, - TULIP_MEDIAINFO_RESET, - TULIP_MEDIAINFO_SYM - } mi_type; - union { - struct { - u_int16_t sia_connectivity; - u_int16_t sia_tx_rx; - u_int16_t sia_general; - u_int32_t sia_gp_control; /* 21142/21143 */ - u_int32_t sia_gp_data; /* 21142/21143 */ - } un_sia; - struct { - u_int32_t gpr_cmdmode; - u_int32_t gpr_gpcontrol; /* 21142/21143 */ - u_int32_t gpr_gpdata; - u_int8_t gpr_actmask; - u_int8_t gpr_actdata; - u_int8_t gpr_default : 1; - } un_gpr; - struct { - u_int32_t mii_mediamask; - u_int16_t mii_capabilities; - u_int16_t mii_advertisement; - u_int16_t mii_full_duplex; - u_int16_t mii_tx_threshold; - u_int16_t mii_interrupt; /* 21142/21143 */ - u_int8_t mii_phyaddr; - u_int8_t mii_gpr_length; - u_int8_t mii_gpr_offset; - u_int8_t mii_reset_length; - u_int8_t mii_reset_offset; - u_int32_t mii_phyid; - } un_mii; - } mi_un; -} tulip_media_info_t; - -#define mi_sia_connectivity mi_un.un_sia.sia_connectivity -#define mi_sia_tx_rx mi_un.un_sia.sia_tx_rx -#define mi_sia_general mi_un.un_sia.sia_general -#define mi_sia_gp_control mi_un.un_sia.sia_gp_control -#define mi_sia_gp_data mi_un.un_sia.sia_gp_data - -#define mi_gpcontrol mi_un.un_gpr.gpr_gpcontrol -#define mi_gpdata mi_un.un_gpr.gpr_gpdata -#define mi_actmask mi_un.un_gpr.gpr_actmask -#define mi_actdata mi_un.un_gpr.gpr_actdata -#define mi_default mi_un.un_gpr.gpr_default -#define mi_cmdmode mi_un.un_gpr.gpr_cmdmode - -#define mi_phyaddr mi_un.un_mii.mii_phyaddr -#define mi_gpr_length mi_un.un_mii.mii_gpr_length -#define mi_gpr_offset mi_un.un_mii.mii_gpr_offset -#define mi_reset_length mi_un.un_mii.mii_reset_length -#define mi_reset_offset mi_un.un_mii.mii_reset_offset -#define mi_capabilities mi_un.un_mii.mii_capabilities -#define mi_advertisement mi_un.un_mii.mii_advertisement -#define mi_full_duplex mi_un.un_mii.mii_full_duplex -#define mi_tx_threshold mi_un.un_mii.mii_tx_threshold -#define mi_mediamask mi_un.un_mii.mii_mediamask -#define mi_mii_interrupt mi_un.un_mii.mii_interrupt -#define mi_phyid mi_un.un_mii.mii_phyid - -#define TULIP_MEDIAINFO_SIA_INIT(sc, mi, chipid, media) do { \ - (mi)->mi_type = TULIP_MEDIAINFO_SIA; \ - sc->tulip_mediums[TULIP_MEDIA_ ## media] = (mi); \ - (mi)->mi_sia_connectivity = TULIP_ ## chipid ## _SIACONN_ ## media; \ - (mi)->mi_sia_tx_rx = TULIP_ ## chipid ## _SIATXRX_ ## media; \ - (mi)->mi_sia_general = TULIP_ ## chipid ## _SIAGEN_ ## media; \ -} while (0) - -#define TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, media) do { \ - if ((sc)->tulip_mediums[TULIP_MEDIA_ ## media] == NULL \ - && ((mi)->mi_capabilities & PHYSTS_ ## media)) { \ - (sc)->tulip_mediums[TULIP_MEDIA_ ## media] = (mi); \ - (mi)->mi_mediamask |= TULIP_BIT(TULIP_MEDIA_ ## media); \ - } \ -} while (0) - -#define TULIP_MII_NOPHY 32 -/* - * Some boards need to treated specially. The following enumeration - * identifies the cards with quirks (or those we just want to single - * out for special merit or scorn). - */ -typedef enum { - TULIP_21040_GENERIC, /* Generic 21040 (works with most any board) */ - TULIP_21140_ISV, /* Digital Semicondutor 21140 ISV SROM Format */ - TULIP_21142_ISV, /* Digital Semicondutor 21142 ISV SROM Format */ - TULIP_21143_ISV, /* Digital Semicondutor 21143 ISV SROM Format */ - TULIP_21140_DEC_EB, /* Digital Semicondutor 21140 Evaluation Board */ - TULIP_21140_MII, /* 21140[A] with MII */ - TULIP_21140_DEC_DE500, /* Digital DE500-?? 10/100 */ - TULIP_21140_SMC_9332, /* SMC 9332 */ - TULIP_21140_COGENT_EM100, /* Cogent EM100 100 only */ - TULIP_21140_ZNYX_ZX34X, /* ZNYX ZX342 10/100 */ - TULIP_21140_ASANTE, /* AsanteFast 10/100 */ - TULIP_21140_EN1207, /* Accton EN2107 10/100 BNC */ - TULIP_21041_GENERIC /* Generic 21041 card */ -} tulip_board_t; - -typedef enum { - TULIP_MEDIAPOLL_TIMER, /* 100ms timer fired */ - TULIP_MEDIAPOLL_FASTTIMER, /* <100ms timer fired */ - TULIP_MEDIAPOLL_LINKFAIL, /* called from interrupt routine */ - TULIP_MEDIAPOLL_LINKPASS, /* called from interrupt routine */ - TULIP_MEDIAPOLL_START, /* start a media probe (called from reset) */ - TULIP_MEDIAPOLL_TXPROBE_OK, /* txprobe succeeded */ - TULIP_MEDIAPOLL_TXPROBE_FAILED, /* txprobe failed */ - TULIP_MEDIAPOLL_MAX -} tulip_mediapoll_event_t; - -typedef enum { - TULIP_LINK_DOWN, /* Link is down */ - TULIP_LINK_UP, /* link is ok */ - TULIP_LINK_UNKNOWN /* we can't tell either way */ -} tulip_link_status_t; - - -/* - * This data structure is used to abstract out the quirks. - * media_probe = tries to determine the media type. - * media_select = enables the current media (or autosenses) - * media_poll = autosenses media - * media_preset = 21140, etal requires bit to set before the - * the software reset; hence pre-set. Should be - * pre-reset but that's ugly. - */ - -typedef struct { - tulip_board_t bd_type; - void (*bd_media_probe)(tulip_softc_t * const sc); - void (*bd_media_select)(tulip_softc_t * const sc); - void (*bd_media_poll)(tulip_softc_t * const sc, tulip_mediapoll_event_t event); - void (*bd_media_preset)(tulip_softc_t * const sc); -#if defined(__bsdi__) && _BSDI_VERSION >= 199701 - struct ifmedia_entry *bd_media_list; - int bd_media_cnt; - int bd_media_options_mask; -#endif -} tulip_boardsw_t; - -/* - * The next few declarations are for MII/PHY based board. - * - * The first enumeration identifies a superset of various datums - * that can be obtained from various PHY chips. Not all PHYs will - * support all datums. - * The modedata structure indicates what register contains - * a datum, what mask is applied the register contents, and what the - * result should be. - * The attr structure records information about a supported PHY. - * The phy structure records information about a PHY instance. - */ - -typedef enum { - PHY_MODE_10T, - PHY_MODE_100TX, - PHY_MODE_100T4, - PHY_MODE_FULLDUPLEX, - PHY_MODE_MAX -} tulip_phy_mode_t; - -typedef struct { - u_int16_t pm_regno; - u_int16_t pm_mask; - u_int16_t pm_value; -} tulip_phy_modedata_t; - -typedef struct { - u_int32_t attr_id; - u_int16_t attr_flags; -#define PHY_NEED_HARD_RESET 0x0001 -#define PHY_DUAL_CYCLE_TA 0x0002 - tulip_phy_modedata_t attr_modes[PHY_MODE_MAX]; -#ifdef TULIP_DEBUG - const char *attr_name; -#endif -} tulip_phy_attr_t; - -/* - * Various probe states used when trying to autosense the media. - */ - -typedef enum { - TULIP_PROBE_INACTIVE, - TULIP_PROBE_PHYRESET, - TULIP_PROBE_PHYAUTONEG, - TULIP_PROBE_GPRTEST, - TULIP_PROBE_MEDIATEST, - TULIP_PROBE_FAILED -} tulip_probe_state_t; - -typedef struct { - /* - * Transmit Statistics - */ - u_int32_t dot3StatsSingleCollisionFrames; - u_int32_t dot3StatsMultipleCollisionFrames; - u_int32_t dot3StatsSQETestErrors; - u_int32_t dot3StatsDeferredTransmissions; - u_int32_t dot3StatsLateCollisions; - u_int32_t dot3StatsExcessiveCollisions; - u_int32_t dot3StatsCarrierSenseErrors; - u_int32_t dot3StatsInternalMacTransmitErrors; - u_int32_t dot3StatsInternalTransmitUnderflows; /* not in rfc1650! */ - u_int32_t dot3StatsInternalTransmitBabbles; /* not in rfc1650! */ - /* - * Receive Statistics - */ - u_int32_t dot3StatsMissedFrames; /* not in rfc1650! */ - u_int32_t dot3StatsAlignmentErrors; - u_int32_t dot3StatsFCSErrors; - u_int32_t dot3StatsFrameTooLongs; - u_int32_t dot3StatsInternalMacReceiveErrors; -} tulip_dot3_stats_t; - -/* - * Now to important stuff. This is softc structure (where does softc - * come from??? No idea) for the tulip device. - * - */ -struct _tulip_softc_t { -#if defined(__bsdi__) - struct device tulip_dev; /* base device */ - struct isadev tulip_id; /* ISA device */ - struct intrhand tulip_ih; /* intrrupt vectoring */ - struct atshutdown tulip_ats; /* shutdown hook */ -#if _BSDI_VERSION < 199401 - caddr_t tulip_bpf; /* for BPF */ -#else - prf_t tulip_pf; /* printf function */ -#if _BSDI_VERSION >= 199701 - struct mii_data tulip_mii; /* Generic MII and media data */ -#define tulip_ifmedia tulip_mii.mii_media -#endif /* _BSDI_VERSION >= 199701 */ -#endif /* _BSDI_VERSION < 199401 */ -#endif /* __bsdi__ */ -#if defined(__NetBSD__) - struct device tulip_dev; /* base device */ - void *tulip_ih; /* intrrupt vectoring */ - void *tulip_ats; /* shutdown hook */ - bus_space_tag_t tulip_bustag; - bus_space_handle_t tulip_bushandle; /* CSR region handle */ - pci_chipset_tag_t tulip_pc; - struct ethercom tulip_ec; - u_int8_t tulip_enaddr[ETHER_ADDR_LEN]; -#endif -#if !defined(tulip_ifmedia) && defined(IFM_ETHER) - struct ifmedia tulip_ifmedia; -#endif -#if defined(TULIP_BUS_DMA) - bus_dma_tag_t tulip_dmatag; /* bus DMA tag */ -#if !defined(TULIP_BUS_DMA_NOTX) - bus_dmamap_t tulip_setupmap; - bus_dmamap_t tulip_txdescmap; - bus_dmamap_t tulip_txmaps[TULIP_TXDESCS]; - unsigned tulip_txmaps_free; -#endif -#if !defined(TULIP_BUS_DMA_NORX) - bus_dmamap_t tulip_rxdescmap; - bus_dmamap_t tulip_rxmaps[TULIP_RXDESCS]; - unsigned tulip_rxmaps_free; -#endif -#endif -#if !defined(__NetBSD__) - struct arpcom tulip_ac; -#endif - tulip_regfile_t tulip_csrs; - u_int32_t tulip_flags; -#define TULIP_WANTSETUP 0x00000001 -#define TULIP_WANTHASHPERFECT 0x00000002 -#define TULIP_WANTHASHONLY 0x00000004 -#define TULIP_DOINGSETUP 0x00000008 -#define TULIP_PRINTMEDIA 0x00000010 -#define TULIP_TXPROBE_ACTIVE 0x00000020 -#define TULIP_ALLMULTI 0x00000040 -#define TULIP_WANTRXACT 0x00000080 -#define TULIP_RXACT 0x00000100 -#define TULIP_INRESET 0x00000200 -#define TULIP_NEEDRESET 0x00000400 -#define TULIP_SQETEST 0x00000800 -#define TULIP_xxxxxx0 0x00001000 -#define TULIP_xxxxxx1 0x00002000 -#define TULIP_WANTTXSTART 0x00004000 -#define TULIP_NEWTXTHRESH 0x00008000 -#define TULIP_NOAUTOSENSE 0x00010000 -#define TULIP_PRINTLINKUP 0x00020000 -#define TULIP_LINKUP 0x00040000 -#define TULIP_RXBUFSLOW 0x00080000 -#define TULIP_NOMESSAGES 0x00100000 -#define TULIP_SYSTEMERROR 0x00200000 -#define TULIP_TIMEOUTPENDING 0x00400000 -#define TULIP_xxxxxx2 0x00800000 -#define TULIP_TRYNWAY 0x01000000 -#define TULIP_DIDNWAY 0x02000000 -#define TULIP_RXIGNORE 0x04000000 -#define TULIP_PROBE1STPASS 0x08000000 -#define TULIP_DEVICEPROBE 0x10000000 -#define TULIP_PROMISC 0x20000000 -#define TULIP_HASHONLY 0x40000000 -#define TULIP_xxxxxx3 0x80000000 - /* only 4 bits left! */ - u_int32_t tulip_features; /* static bits indicating features of chip */ -#define TULIP_HAVE_GPR 0x00000001 /* have gp register (140[A]) */ -#define TULIP_HAVE_RXBADOVRFLW 0x00000002 /* RX corrupts on overflow */ -#define TULIP_HAVE_POWERMGMT 0x00000004 /* Snooze/sleep modes */ -#define TULIP_HAVE_MII 0x00000008 /* Some medium on MII */ -#define TULIP_HAVE_SIANWAY 0x00000010 /* SIA does NWAY */ -#define TULIP_HAVE_DUALSENSE 0x00000020 /* SIA senses both AUI & TP */ -#define TULIP_HAVE_SIAGP 0x00000040 /* SIA has a GP port */ -#define TULIP_HAVE_BROKEN_HASH 0x00000080 /* Broken Multicast Hash */ -#define TULIP_HAVE_ISVSROM 0x00000100 /* uses ISV SROM Format */ -#define TULIP_HAVE_BASEROM 0x00000200 /* Board ROM can be cloned */ -#define TULIP_HAVE_SLAVEDROM 0x00000400 /* Board ROM cloned */ -#define TULIP_HAVE_SLAVEDINTR 0x00000800 /* Board slaved interrupt */ -#define TULIP_HAVE_SHAREDINTR 0x00001000 /* Board shares interrupts */ -#define TULIP_HAVE_OKROM 0x00002000 /* ROM was recognized */ -#define TULIP_HAVE_NOMEDIA 0x00004000 /* did not detect any media */ -#define TULIP_HAVE_STOREFWD 0x00008000 /* have CMD_STOREFWD */ -#define TULIP_HAVE_SIA100 0x00010000 /* has LS100 in SIA status */ -#define TULIP_HAVE_OKSROM 0x00020000 /* SROM CRC is OK */ - u_int32_t tulip_intrmask; /* our copy of csr_intr */ - u_int32_t tulip_cmdmode; /* our copy of csr_cmdmode */ - u_int32_t tulip_last_system_error : 3; /* last system error (only value is TULIP_SYSTEMERROR is also set) */ - u_int32_t tulip_txtimer : 2; /* transmission timer */ - u_int32_t tulip_system_errors; /* number of system errors encountered */ - u_int32_t tulip_statusbits; /* status bits from CSR5 that may need to be printed */ - - tulip_media_info_t *tulip_mediums[TULIP_MEDIA_MAX]; /* indexes into mediainfo */ - tulip_media_t tulip_media; /* current media type */ - u_int32_t tulip_abilities; /* remote system's abiltities (as defined in IEEE 802.3u) */ - - u_int8_t tulip_revinfo; /* revision of chip */ - u_int8_t tulip_phyaddr; /* 0..31 -- address of current phy */ - u_int8_t tulip_gpinit; /* active pins on 21140 */ - u_int8_t tulip_gpdata; /* default gpdata for 21140 */ - - struct { - u_int8_t probe_count; /* count of probe operations */ - int32_t probe_timeout; /* time in ms of probe timeout */ - tulip_probe_state_t probe_state; /* current media probe state */ - tulip_media_t probe_media; /* current media being probed */ - u_int32_t probe_mediamask; /* medias checked */ - u_int32_t probe_passes; /* times autosense failed */ - u_int32_t probe_txprobes; /* txprobes attempted */ - } tulip_probe; -#define tulip_probe_count tulip_probe.probe_count -#define tulip_probe_timeout tulip_probe.probe_timeout -#define tulip_probe_state tulip_probe.probe_state -#define tulip_probe_media tulip_probe.probe_media -#define tulip_probe_mediamask tulip_probe.probe_mediamask -#define tulip_probe_passes tulip_probe.probe_passes - - tulip_chipid_t tulip_chipid; /* type of chip we are using */ - const tulip_boardsw_t *tulip_boardsw; /* board/chip characteristics */ - tulip_softc_t *tulip_slaves; /* slaved devices (ZX3xx) */ -#if defined(TULIP_DEBUG) - /* - * Debugging/Statistical information - */ - struct { - tulip_media_t dbg_last_media; - u_int32_t dbg_intrs; - u_int32_t dbg_media_probes; - u_int32_t dbg_txprobe_nocarr; - u_int32_t dbg_txprobe_exccoll; - u_int32_t dbg_link_downed; - u_int32_t dbg_link_suspected; - u_int32_t dbg_link_intrs; - u_int32_t dbg_link_pollintrs; - u_int32_t dbg_link_failures; - u_int32_t dbg_nway_starts; - u_int32_t dbg_nway_failures; - u_int16_t dbg_phyregs[32][4]; - u_int32_t dbg_rxlowbufs; - u_int32_t dbg_rxintrs; - u_int32_t dbg_last_rxintrs; - u_int32_t dbg_high_rxintrs_hz; - u_int32_t dbg_no_txmaps; - u_int32_t dbg_txput_finishes[8]; - u_int32_t dbg_txprobes_ok[TULIP_MEDIA_MAX]; - u_int32_t dbg_txprobes_failed[TULIP_MEDIA_MAX]; - u_int32_t dbg_events[TULIP_MEDIAPOLL_MAX]; - u_int32_t dbg_rxpktsperintr[TULIP_RXDESCS]; - } tulip_dbg; -#endif -#if defined(TULIP_PERFSTATS) -#define TULIP_PERF_CURRENT 0 -#define TULIP_PERF_PREVIOUS 1 -#define TULIP_PERF_TOTAL 2 -#define TULIP_PERF_MAX 3 - struct tulip_perfstats { - u_quad_t perf_intr_cycles; - u_quad_t perf_ifstart_cycles; - u_quad_t perf_ifstart_one_cycles; - u_quad_t perf_ifioctl_cycles; - u_quad_t perf_ifwatchdog_cycles; - u_quad_t perf_timeout_cycles; - u_quad_t perf_txput_cycles; - u_quad_t perf_txintr_cycles; - u_quad_t perf_rxintr_cycles; - u_quad_t perf_rxget_cycles; - unsigned perf_intr; - unsigned perf_ifstart; - unsigned perf_ifstart_one; - unsigned perf_ifioctl; - unsigned perf_ifwatchdog; - unsigned perf_timeout; - unsigned perf_txput; - unsigned perf_txintr; - unsigned perf_rxintr; - unsigned perf_rxget; - } tulip_perfstats[TULIP_PERF_MAX]; -#define tulip_curperfstats tulip_perfstats[TULIP_PERF_CURRENT] -#endif - struct ifqueue tulip_txq; - struct ifqueue tulip_rxq; - tulip_dot3_stats_t tulip_dot3stats; - tulip_ringinfo_t tulip_rxinfo; - tulip_ringinfo_t tulip_txinfo; - tulip_media_info_t tulip_mediainfo[10]; - /* - * The setup buffers for sending the setup frame to the chip. - * one is the one being sent while the other is the one being - * filled. - */ - u_int32_t tulip_setupbuf[192/sizeof(u_int32_t)]; - u_int32_t tulip_setupdata[192/sizeof(u_int32_t)]; - char tulip_boardid[16]; /* buffer for board ID */ - u_int8_t tulip_rombuf[128]; -#if defined(__NetBSD__) - struct device *tulip_pci_busno; /* needed for multiport boards */ -#else - u_int8_t tulip_pci_busno; /* needed for multiport boards */ -#endif - u_int8_t tulip_pci_devno; /* needed for multiport boards */ - u_int8_t tulip_connidx; - tulip_srom_connection_t tulip_conntype; - tulip_desc_t *tulip_rxdescs; - tulip_desc_t *tulip_txdescs; -#if defined(__NetBSD__) && NRND > 0 - rndsource_element_t tulip_rndsource; -#endif -}; - -#if defined(IFM_ETHER) -#define TULIP_DO_AUTOSENSE(sc) (IFM_SUBTYPE((sc)->tulip_ifmedia.ifm_media) == IFM_AUTO) -#else -#define TULIP_DO_AUTOSENSE(sc) (((sc)->tulip_flags & TULIP_NOAUTOSENSE) == 0) -#endif - - -#if defined(TULIP_HDR_DATA) -static const char * const tulip_chipdescs[] = { - "21040 [10Mb/s]", -#if defined(TULIP_EISA) - "DE425 [10Mb/s]", -#else - NULL, -#endif - "21041 [10Mb/s]", - "21140 [10-100Mb/s]", - "21140A [10-100Mb/s]", - "21142 [10-100Mb/s]", - "21143 [10-100Mb/s]", -}; - -static const char * const tulip_mediums[] = { - "unknown", /* TULIP_MEDIA_UNKNOWN */ - "10baseT", /* TULIP_MEDIA_10BASET */ - "Full Duplex 10baseT", /* TULIP_MEDIA_10BASET_FD */ - "BNC", /* TULIP_MEDIA_BNC */ - "AUI", /* TULIP_MEDIA_AUI */ - "External SIA", /* TULIP_MEDIA_EXTSIA */ - "AUI/BNC", /* TULIP_MEDIA_AUIBNC */ - "100baseTX", /* TULIP_MEDIA_100BASET */ - "Full Duplex 100baseTX", /* TULIP_MEDIA_100BASET_FD */ - "100baseT4", /* TULIP_MEDIA_100BASET4 */ - "100baseFX", /* TULIP_MEDIA_100BASEFX */ - "Full Duplex 100baseFX", /* TULIP_MEDIA_100BASEFX_FD */ -}; - -#if defined(IFM_ETHER) -static const int tulip_media_to_ifmedia[] = { - IFM_ETHER | IFM_NONE, /* TULIP_MEDIA_UNKNOWN */ - IFM_ETHER | IFM_10_T, /* TULIP_MEDIA_10BASET */ - IFM_ETHER | IFM_10_T | IFM_FDX, /* TULIP_MEDIA_10BASET_FD */ - IFM_ETHER | IFM_10_2, /* TULIP_MEDIA_BNC */ - IFM_ETHER | IFM_10_5, /* TULIP_MEDIA_AUI */ - IFM_ETHER | IFM_MANUAL, /* TULIP_MEDIA_EXTSIA */ - IFM_ETHER | IFM_10_5, /* TULIP_MEDIA_AUIBNC */ - IFM_ETHER | IFM_100_TX, /* TULIP_MEDIA_100BASET */ - IFM_ETHER | IFM_100_TX | IFM_FDX, /* TULIP_MEDIA_100BASET_FD */ - IFM_ETHER | IFM_100_T4, /* TULIP_MEDIA_100BASET4 */ - IFM_ETHER | IFM_100_FX, /* TULIP_MEDIA_100BASEFX */ - IFM_ETHER | IFM_100_FX | IFM_FDX, /* TULIP_MEDIA_100BASEFX_FD */ -}; -#endif /* defined(IFM_ETHER) */ - -static const char * const tulip_system_errors[] = { - "parity error", - "master abort", - "target abort", - "reserved #3", - "reserved #4", - "reserved #5", - "reserved #6", - "reserved #7", -}; - -static const char * const tulip_status_bits[] = { - NULL, - "transmit process stopped", - NULL, - "transmit jabber timeout", - - NULL, - "transmit underflow", - NULL, - "receive underflow", - - "receive process stopped", - "receive watchdog timeout", - NULL, - NULL, - - "link failure", - NULL, - NULL, -}; - -static const struct { - tulip_srom_connection_t sc_type; - tulip_media_t sc_media; - u_int32_t sc_attrs; -} tulip_srom_conninfo[] = { - { TULIP_SROM_CONNTYPE_10BASET, TULIP_MEDIA_10BASET }, - { TULIP_SROM_CONNTYPE_BNC, TULIP_MEDIA_BNC }, - { TULIP_SROM_CONNTYPE_AUI, TULIP_MEDIA_AUI }, - { TULIP_SROM_CONNTYPE_100BASETX, TULIP_MEDIA_100BASETX }, - { TULIP_SROM_CONNTYPE_100BASET4, TULIP_MEDIA_100BASET4 }, - { TULIP_SROM_CONNTYPE_100BASEFX, TULIP_MEDIA_100BASEFX }, - { TULIP_SROM_CONNTYPE_MII_10BASET, TULIP_MEDIA_10BASET, - TULIP_SROM_ATTR_MII }, - { TULIP_SROM_CONNTYPE_MII_100BASETX, TULIP_MEDIA_100BASETX, - TULIP_SROM_ATTR_MII }, - { TULIP_SROM_CONNTYPE_MII_100BASET4, TULIP_MEDIA_100BASET4, - TULIP_SROM_ATTR_MII }, - { TULIP_SROM_CONNTYPE_MII_100BASEFX, TULIP_MEDIA_100BASEFX, - TULIP_SROM_ATTR_MII }, - { TULIP_SROM_CONNTYPE_10BASET_NWAY, TULIP_MEDIA_10BASET, - TULIP_SROM_ATTR_NWAY }, - { TULIP_SROM_CONNTYPE_10BASET_FD, TULIP_MEDIA_10BASET_FD }, - { TULIP_SROM_CONNTYPE_MII_10BASET_FD, TULIP_MEDIA_10BASET_FD, - TULIP_SROM_ATTR_MII }, - { TULIP_SROM_CONNTYPE_100BASETX_FD, TULIP_MEDIA_100BASETX_FD }, - { TULIP_SROM_CONNTYPE_MII_100BASETX_FD, TULIP_MEDIA_100BASETX_FD, - TULIP_SROM_ATTR_MII }, - { TULIP_SROM_CONNTYPE_10BASET_NOLINKPASS, TULIP_MEDIA_10BASET, - TULIP_SROM_ATTR_NOLINKPASS }, - { TULIP_SROM_CONNTYPE_AUTOSENSE, TULIP_MEDIA_UNKNOWN, - TULIP_SROM_ATTR_AUTOSENSE }, - { TULIP_SROM_CONNTYPE_AUTOSENSE_POWERUP, TULIP_MEDIA_UNKNOWN, - TULIP_SROM_ATTR_AUTOSENSE|TULIP_SROM_ATTR_POWERUP }, - { TULIP_SROM_CONNTYPE_AUTOSENSE_NWAY, TULIP_MEDIA_UNKNOWN, - TULIP_SROM_ATTR_AUTOSENSE|TULIP_SROM_ATTR_NWAY }, - { TULIP_SROM_CONNTYPE_NOT_USED, TULIP_MEDIA_UNKNOWN } -}; -#define TULIP_SROM_LASTCONNIDX \ - (sizeof(tulip_srom_conninfo)/sizeof(tulip_srom_conninfo[0]) - 1) - -static const struct { - tulip_media_t sm_type; - tulip_srom_media_t sm_srom_type; -} tulip_srom_mediums[] = { - { TULIP_MEDIA_100BASEFX_FD, TULIP_SROM_MEDIA_100BASEFX_FD }, - { TULIP_MEDIA_100BASEFX, TULIP_SROM_MEDIA_100BASEFX }, - { TULIP_MEDIA_100BASET4, TULIP_SROM_MEDIA_100BASET4 }, - { TULIP_MEDIA_100BASETX_FD, TULIP_SROM_MEDIA_100BASETX_FD }, - { TULIP_MEDIA_100BASETX, TULIP_SROM_MEDIA_100BASETX }, - { TULIP_MEDIA_10BASET_FD, TULIP_SROM_MEDIA_10BASET_FD }, - { TULIP_MEDIA_AUI, TULIP_SROM_MEDIA_AUI }, - { TULIP_MEDIA_BNC, TULIP_SROM_MEDIA_BNC }, - { TULIP_MEDIA_10BASET, TULIP_SROM_MEDIA_10BASET }, - { TULIP_MEDIA_UNKNOWN } -}; -#endif /* TULIP_HDR_DATA */ - -/* - * This driver supports a maximum of 32 tulip boards. - * This should be enough for the forseeable future. - */ -#define TULIP_MAX_DEVICES 32 - -#if defined(TULIP_USE_SOFTINTR) && defined(TULIP_HDR_DATA) -static u_int32_t tulip_softintr_mask; -static int tulip_softintr_last_unit; -static int tulip_softintr_max_unit; -static void tulip_softintr(void); -#endif - -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX) -#define TULIP_RXDESC_PRESYNC(sc, di, s) \ - bus_dmamap_sync((sc)->tulip_dmatag, (sc)->tulip_rxdescmap, \ - (caddr_t) di - (caddr_t) (sc)->tulip_rxdescs, \ - (s), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE) -#define TULIP_RXDESC_POSTSYNC(sc, di, s) \ - bus_dmamap_sync((sc)->tulip_dmatag, (sc)->tulip_rxdescmap, \ - (caddr_t) di - (caddr_t) (sc)->tulip_rxdescs, \ - (s), BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE) -#define TULIP_RXMAP_PRESYNC(sc, map) \ - bus_dmamap_sync((sc)->tulip_dmatag, (map), 0, (map)->dm_mapsize, \ - BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE) -#define TULIP_RXMAP_POSTSYNC(sc, map) \ - bus_dmamap_sync((sc)->tulip_dmatag, (map), 0, (map)->dm_mapsize, \ - BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE) -#define TULIP_RXMAP_CREATE(sc, mapp) \ - bus_dmamap_create((sc)->tulip_dmatag, TULIP_RX_BUFLEN, 2, \ - TULIP_DATA_PER_DESC, 0, \ - BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW, (mapp)) -#else -#define TULIP_RXDESC_PRESYNC(sc, di, s) do { } while (0) -#define TULIP_RXDESC_POSTSYNC(sc, di, s) do { } while (0) -#define TULIP_RXMAP_PRESYNC(sc, map) do { } while (0) -#define TULIP_RXMAP_POSTSYNC(sc, map) do { } while (0) -#define TULIP_RXMAP_CREATE(sc, mapp) do { } while (0) -#endif - -#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX) -#define TULIP_TXDESC_PRESYNC(sc, di, s) \ - bus_dmamap_sync((sc)->tulip_dmatag, (sc)->tulip_txdescmap, \ - (caddr_t) di - (caddr_t) (sc)->tulip_txdescs, \ - (s), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE) -#define TULIP_TXDESC_POSTSYNC(sc, di, s) \ - bus_dmamap_sync((sc)->tulip_dmatag, (sc)->tulip_txdescmap, \ - (caddr_t) di - (caddr_t) (sc)->tulip_txdescs, \ - (s), BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE) -#define TULIP_TXMAP_PRESYNC(sc, map) \ - bus_dmamap_sync((sc)->tulip_dmatag, (map), 0, (map)->dm_mapsize, \ - BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE) -#define TULIP_TXMAP_POSTSYNC(sc, map) \ - bus_dmamap_sync((sc)->tulip_dmatag, (map), 0, (map)->dm_mapsize, \ - BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE) -#define TULIP_TXMAP_CREATE(sc, mapp) \ - bus_dmamap_create((sc)->tulip_dmatag, TULIP_DATA_PER_DESC, \ - TULIP_MAX_TXSEG, TULIP_DATA_PER_DESC, \ - 0, BUS_DMA_NOWAIT, (mapp)) -#else -#define TULIP_TXDESC_PRESYNC(sc, di, s) do { } while (0) -#define TULIP_TXDESC_POSTSYNC(sc, di, s) do { } while (0) -#define TULIP_TXMAP_PRESYNC(sc, map) do { } while (0) -#define TULIP_TXMAP_POSTSYNC(sc, map) do { } while (0) -#define TULIP_TXMAP_CREATE(sc, mapp) do { } while (0) -#endif - -#ifdef notyet -#define SIOCGADDRROM _IOW('i', 240, struct ifreq) /* get 128 bytes of ROM */ -#define SIOCGCHIPID _IOWR('i', 241, struct ifreq) /* get chipid */ -#endif - -#if defined(__FreeBSD__) -typedef void ifnet_ret_t; -typedef int ioctl_cmd_t; -#if defined(TULIP_HDR_DATA) -static tulip_softc_t *tulips[TULIP_MAX_DEVICES]; -#endif -#if BSD >= 199506 -#define TULIP_IFP_TO_SOFTC(ifp) ((tulip_softc_t *)((ifp)->if_softc)) -#if NBPFILTER > 0 -#define TULIP_BPF_MTAP(sc, m) bpf_mtap(&(sc)->tulip_if, m) -#define TULIP_BPF_TAP(sc, p, l) bpf_tap(&(sc)->tulip_if, p, l) -#define TULIP_BPF_ATTACH(sc) bpfattach(&(sc)->tulip_if, DLT_EN10MB, sizeof(struct ether_header)) -#endif -#define tulip_intrfunc_t void -#define TULIP_VOID_INTRFUNC -#define IFF_NOTRAILERS 0 -#define CLBYTES PAGE_SIZE -#if 0 -#define TULIP_KVATOPHYS(sc, va) kvtop(va) -#endif -#define TULIP_EADDR_FMT "%6D" -#define TULIP_EADDR_ARGS(addr) addr, ":" -#else -extern int bootverbose; -#define TULIP_IFP_TO_SOFTC(ifp) (TULIP_UNIT_TO_SOFTC((ifp)->if_unit)) -#include <sys/devconf.h> -#define TULIP_DEVCONF -#endif -#if defined(TULIP_USE_SOFTINTR) -NETISR_SET(NETISR_DE, tulip_softintr); -#endif -#define TULIP_UNIT_TO_SOFTC(unit) (tulips[unit]) -#define TULIP_BURSTSIZE(unit) pci_max_burst_len -#define loudprintf if (bootverbose) printf -#endif - -#if defined(__bsdi__) -typedef int ifnet_ret_t; -typedef u_long ioctl_cmd_t; -extern struct cfdriver decd; -#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) decd.cd_devs[unit]) -#define TULIP_IFP_TO_SOFTC(ifp) (TULIP_UNIT_TO_SOFTC((ifp)->if_unit)) -#define TULIP_ETHER_IFATTACH(sc) ether_attach(&(sc)->tulip_if) -#if _BSDI_VERSION >= 199510 -#if 0 -#define TULIP_BURSTSIZE(unit) log2_burst_size -#endif -#define loudprintf aprint_verbose -#define printf (*sc->tulip_pf) -#define MCNT(x) (sizeof(x) / sizeof(struct ifmedia_entry)) -#elif _BSDI_VERSION <= 199401 -#define DRQNONE 0 -#define loudprintf printf -static void -arp_ifinit( - struct arpcom *ac, - struct ifaddr *ifa) -{ - ac->ac_ipaddr = IA_SIN(ifa)->sin_addr; - arpwhohas(ac, &ac->ac_ipaddr); -} -#endif -#endif /* __bsdi__ */ - -#if defined(__NetBSD__) -typedef void ifnet_ret_t; -typedef u_long ioctl_cmd_t; -extern struct cfattach de_ca; -extern struct cfdriver de_cd; -#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) de_cd.cd_devs[unit]) -#define TULIP_IFP_TO_SOFTC(ifp) ((tulip_softc_t *)((ifp)->if_softc)) -#define tulip_unit tulip_dev.dv_unit -#define tulip_xname tulip_if.if_xname -#define TULIP_RAISESPL() splnet() -#define TULIP_RAISESOFTSPL() splsoftnet() -#define TULIP_RESTORESPL(s) splx(s) -#define tulip_if tulip_ec.ec_if -#define tulip_enaddr tulip_enaddr -#define tulip_multicnt tulip_ec.ec_multicnt -#define TULIP_ETHERCOM(sc) (&(sc)->tulip_ec) -#define TULIP_ARP_IFINIT(sc, ifa) arp_ifinit(&(sc)->tulip_if, (ifa)) -#define TULIP_ETHER_IFATTACH(sc) ether_ifattach(&(sc)->tulip_if, (sc)->tulip_enaddr) -#define loudprintf printf -#define TULIP_PRINTF_FMT "%s" -#define TULIP_PRINTF_ARGS sc->tulip_xname -#if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NORX) || defined(TULIP_BUS_DMA_NOTX) -#if defined(__alpha__) -/* XXX XXX NEED REAL DMA MAPPING SUPPORT XXX XXX */ -#define TULIP_KVATOPHYS(sc, va) alpha_XXX_dmamap((vaddr_t)(va)) -#endif -#endif -#endif /* __NetBSD__ */ - -#ifndef TULIP_PRINTF_FMT -#define TULIP_PRINTF_FMT "%s%d" -#endif -#ifndef TULIP_PRINTF_ARGS -#define TULIP_PRINTF_ARGS sc->tulip_name, sc->tulip_unit -#endif - -#ifndef TULIP_BURSTSIZE -#define TULIP_BURSTSIZE(unit) 3 -#endif - -#ifndef tulip_if -#define tulip_if tulip_ac.ac_if -#endif -#ifndef tulip_unit -#define tulip_unit tulip_if.if_unit -#endif -#define tulip_name tulip_if.if_name -#ifndef tulip_enaddr -#define tulip_enaddr tulip_ac.ac_enaddr -#endif -#ifndef tulip_multicnt -#define tulip_multicnt tulip_ac.ac_multicnt -#endif - -#if !defined(TULIP_ETHERCOM) -#define TULIP_ETHERCOM(sc) (&(sc)->tulip_ac) -#endif - -#if !defined(TULIP_ARP_IFINIT) -#define TULIP_ARP_IFINIT(sc, ifa) arp_ifinit(TULIP_ETHERCOM(sc), (ifa)) -#endif - -#if !defined(TULIP_ETHER_IFATTACH) -#define TULIP_ETHER_IFATTACH(sc) ether_ifattach(&(sc)->tulip_if) -#endif - -#if !defined(tulip_bpf) && (!defined(__bsdi__) || _BSDI_VERSION >= 199401) -#define tulip_bpf tulip_if.if_bpf -#endif - -#if !defined(tulip_intrfunc_t) -#define tulip_intrfunc_t int -#endif - -#if !defined(TULIP_KVATOPHYS) && (!defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NORX) || defined(TULIP_BUS_DMA_NOTX)) -#define TULIP_KVATOPHYS(sc, va) vtophys(va) -#endif - -#ifndef TULIP_RAISESPL -#define TULIP_RAISESPL() splimp() -#endif -#ifndef TULIP_RAISESOFTSPL -#define TULIP_RAISESOFTSPL() splnet() -#endif -#ifndef TULIP_RESTORESPL -#define TULIP_RESTORESPL(s) splx(s) -#endif - -/* - * While I think FreeBSD's 2.2 change to the bpf is a nice simplification, - * it does add yet more conditional code to this driver. Sigh. - */ -#if !defined(TULIP_BPF_MTAP) && NBPFILTER > 0 -#define TULIP_BPF_MTAP(sc, m) bpf_mtap((sc)->tulip_bpf, m) -#define TULIP_BPF_TAP(sc, p, l) bpf_tap((sc)->tulip_bpf, p, l) -#define TULIP_BPF_ATTACH(sc) bpfattach(&(sc)->tulip_bpf, &(sc)->tulip_if, DLT_EN10MB, sizeof(struct ether_header)) -#endif - -#if defined(TULIP_PERFSTATS) -#define TULIP_PERFMERGE(sc, member) \ - do { (sc)->tulip_perfstats[TULIP_PERF_TOTAL].member \ - += (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member; \ - (sc)->tulip_perfstats[TULIP_PERF_PREVIOUS].member \ - = (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member; \ - (sc)->tulip_perfstats[TULIP_PERF_CURRENT].member = 0; } while (0) -#define TULIP_PERFSTART(name) const tulip_cycle_t perfstart_ ## name = TULIP_PERFREAD(); -#define TULIP_PERFEND(name) do { \ - (sc)->tulip_curperfstats.perf_ ## name ## _cycles += TULIP_PERFDIFF(perfstart_ ## name, TULIP_PERFREAD()); \ - (sc)->tulip_curperfstats.perf_ ## name ++; \ - } while (0) -#if defined(__i386__) -typedef u_quad_t tulip_cycle_t; -static __inline__ tulip_cycle_t -TULIP_PERFREAD( - void) -{ - tulip_cycle_t x; - __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); - return x; -} -#define TULIP_PERFDIFF(s, f) ((f) - (s)) -#elif defined(__alpha__) -typedef unsigned long tulip_cycle_t; -static __inline__ tulip_cycle_t -TULIP_PERFREAD( - void) -{ - tulip_cycle_t x; - __asm__ volatile ("rpcc %0" : "=r" (x)); - return x; -} -#define TULIP_PERFDIFF(s, f) ((unsigned int) ((f) - (s))) -#endif -#else -#define TULIP_PERFSTART(name) -#define TULIP_PERFEND(name) do { } while (0) -#define TULIP_PERFMERGE(s,n) do { } while (0) -#endif /* TULIP_PERFSTATS */ - -/* - * However, this change to FreeBSD I am much less enamored with. - */ -#if !defined(TULIP_EADDR_FMT) -#define TULIP_EADDR_FMT "%s" -#define TULIP_EADDR_ARGS(addr) ether_sprintf(addr) -#endif - -#define TULIP_CRC32_POLY 0xEDB88320UL /* CRC-32 Poly -- Little Endian */ -#define TULIP_MAX_TXSEG 30 - -#define TULIP_ADDREQUAL(a1, a2) \ - (((u_int16_t *)a1)[0] == ((u_int16_t *)a2)[0] \ - && ((u_int16_t *)a1)[1] == ((u_int16_t *)a2)[1] \ - && ((u_int16_t *)a1)[2] == ((u_int16_t *)a2)[2]) -#define TULIP_ADDRBRDCST(a1) \ - (((u_int16_t *)a1)[0] == 0xFFFFU \ - && ((u_int16_t *)a1)[1] == 0xFFFFU \ - && ((u_int16_t *)a1)[2] == 0xFFFFU) - -typedef int tulip_spl_t; - -#endif /* !defined(_DEVAR_H) */ diff --git a/sys/sys/ccdvar.h b/sys/sys/ccdvar.h deleted file mode 100644 index 00d2f2c81768..000000000000 --- a/sys/sys/ccdvar.h +++ /dev/null @@ -1,206 +0,0 @@ -/* $NetBSD: ccdvar.h,v 1.7.2.1 1995/10/12 21:30:18 thorpej Exp $ */ - -/* - * Copyright (c) 1995 Jason R. Thorpe. - * 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 for the NetBSD Project - * by Jason R. Thorpe. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -/* - * Copyright (c) 1988 University of Utah. - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * the Systems Programming Group of the University of Utah Computer - * Science Department. - * - * 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. - * - * from: Utah $Hdr: cdvar.h 1.1 90/07/09$ - * - * @(#)cdvar.h 8.1 (Berkeley) 6/10/93 - */ - -/* - * Dynamic configuration and disklabel support by: - * Jason R. Thorpe <thorpej@nas.nasa.gov> - * Numerical Aerodynamic Simulation Facility - * Mail Stop 258-6 - * NASA Ames Research Center - * Moffett Field, CA 94035 - */ - -/* - * A concatenated disk is described at initialization time by this structure. - */ -struct ccddevice { - int ccd_unit; /* logical unit of this ccd */ - int ccd_interleave; /* interleave (DEV_BSIZE blocks) */ - int ccd_flags; /* misc. information */ - int ccd_dk; /* disk number */ - struct vnode **ccd_vpp; /* array of component vnodes */ - char **ccd_cpp; /* array of component pathnames */ - int ccd_ndev; /* number of component devices */ -}; - -/* - * This structure is used to configure a ccd via ioctl(2). - */ -struct ccd_ioctl { - char **ccio_disks; /* pointer to component paths */ - int ccio_ndisks; /* number of disks to concatenate */ - int ccio_ileave; /* interleave (DEV_BSIZE blocks) */ - int ccio_flags; /* misc. information */ - int ccio_unit; /* unit number: use varies */ - size_t ccio_size; /* (returned) size of ccd */ -}; - -/* ccd_flags */ -#define CCDF_SWAP 0x01 /* interleave should be dmmax */ -#define CCDF_UNIFORM 0x02 /* use LCCD of sizes for uniform interleave */ - -/* Mask of user-settable ccd flags. */ -#define CCDF_USERMASK (CCDF_SWAP|CCDF_UNIFORM) - -/* - * Component info table. - * Describes a single component of a concatenated disk. - */ -struct ccdcinfo { - struct vnode *ci_vp; /* device's vnode */ - dev_t ci_dev; /* XXX: device's dev_t */ - size_t ci_size; /* size */ - char *ci_path; /* path to component */ - size_t ci_pathlen; /* length of component path */ -}; - -/* - * Interleave description table. - * Computed at boot time to speed irregular-interleave lookups. - * The idea is that we interleave in "groups". First we interleave - * evenly over all component disks up to the size of the smallest - * component (the first group), then we interleave evenly over all - * remaining disks up to the size of the next-smallest (second group), - * and so on. - * - * Each table entry describes the interleave characteristics of one - * of these groups. For example if a concatenated disk consisted of - * three components of 5, 3, and 7 DEV_BSIZE blocks interleaved at - * DEV_BSIZE (1), the table would have three entries: - * - * ndisk startblk startoff dev - * 3 0 0 0, 1, 2 - * 2 9 3 0, 2 - * 1 13 5 2 - * 0 - - - - * - * which says that the first nine blocks (0-8) are interleaved over - * 3 disks (0, 1, 2) starting at block offset 0 on any component disk, - * the next 4 blocks (9-12) are interleaved over 2 disks (0, 2) starting - * at component block 3, and the remaining blocks (13-14) are on disk - * 2 starting at offset 5. - */ -struct ccdiinfo { - int ii_ndisk; /* # of disks range is interleaved over */ - daddr_t ii_startblk; /* starting scaled block # for range */ - daddr_t ii_startoff; /* starting component offset (block #) */ - int *ii_index; /* ordered list of components in range */ -}; - -/* - * Concatenated disk pseudo-geometry information. - */ -struct ccdgeom { - u_int32_t ccg_secsize; /* # bytes per sector */ - u_int32_t ccg_nsectors; /* # data sectors per track */ - u_int32_t ccg_ntracks; /* # tracks per cylinder */ - u_int32_t ccg_ncylinders; /* # cylinders per unit */ -}; - -/* - * A concatenated disk is described after initialization by this structure. - */ -struct ccd_softc { - int sc_unit; /* logical unit number */ - int sc_flags; /* flags */ - int sc_cflags; /* configuration flags */ - size_t sc_size; /* size of ccd */ - int sc_ileave; /* interleave */ - int sc_nccdisks; /* number of components */ - struct ccdcinfo *sc_cinfo; /* component info */ - struct ccdiinfo *sc_itable; /* interleave table */ - int sc_nactive; /* number of requests active */ - int sc_dk; /* disk index */ - struct ccdgeom sc_geom; /* pseudo geometry info */ - struct dkdevice sc_dkdev; /* generic disk device info */ -}; - -/* sc_flags */ -#define CCDF_INITED 0x01 /* unit has been initialized */ -#define CCDF_WLABEL 0x02 /* label area is writable */ -#define CCDF_LABELLING 0x04 /* unit is currently being labelled */ -#define CCDF_WANTED 0x40 /* someone is waiting to obtain a lock */ -#define CCDF_LOCKED 0x80 /* unit is locked */ - -/* - * Before you can use a unit, it must be configured with CCDIOCSET. - * The configuration persists across opens and closes of the device; - * a CCDIOCCLR must be used to reset a configuration. An attempt to - * CCDIOCSET an already active unit will return EBUSY. Attempts to - * CCDIOCCLR an inactive unit will return ENXIO. - */ -#define CCDIOCSET _IOWR('F', 16, struct ccd_ioctl) /* enable ccd */ -#define CCDIOCCLR _IOW('F', 17, struct ccd_ioctl) /* disable ccd */ diff --git a/usr.bin/sort/Makefile b/usr.bin/sort/Makefile deleted file mode 100644 index d7259ba3e4f6..000000000000 --- a/usr.bin/sort/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $NetBSD: Makefile,v 1.3 2001/01/08 19:16:49 jdolecek Exp $ -# from: @(#)Makefile 8.1 (Berkeley) 6/6/93 - -PROG= sort -SRCS= append.c fields.c files.c fsort.c init.c msort.c sort.c tmp.c - -.include <bsd.prog.mk> diff --git a/usr.bin/sort/append.c b/usr.bin/sort/append.c deleted file mode 100644 index d24b9fea3a7f..000000000000 --- a/usr.bin/sort/append.c +++ /dev/null @@ -1,205 +0,0 @@ -/* $NetBSD: append.c,v 1.9 2001/01/18 20:59:43 jdolecek Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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. - */ - -#include "sort.h" - -#ifndef lint -__RCSID("$NetBSD: append.c,v 1.9 2001/01/18 20:59:43 jdolecek Exp $"); -__SCCSID("@(#)append.c 8.1 (Berkeley) 6/6/93"); -#endif /* not lint */ - -#include <stdlib.h> -#include <string.h> - -#define OUTPUT { \ - if ((n = cpos - ppos) > 1) { \ - for (; ppos < cpos; ++ppos) \ - *ppos -= odepth; \ - ppos -= n; \ - if (stable_sort) \ - sradixsort(ppos, n, wts1, REC_D); \ - else \ - radixsort(ppos, n, wts1, REC_D); \ - for (; ppos < cpos; ppos++) { \ - prec = (const RECHEADER *) (*ppos - sizeof(TRECHEADER));\ - put(prec, fp); \ - } \ - } else put(prec, fp); \ -} - -/* - * copy sorted lines to output; check for uniqueness - */ -void -append(keylist, nelem, depth, fp, put, ftbl) - const u_char **keylist; - int nelem; - int depth; - FILE *fp; - put_func_t put; - struct field *ftbl; -{ - u_char *wts, *wts1; - int n, odepth; - const u_char **cpos, **ppos, **lastkey; - const u_char *cend, *pend, *start; - const struct recheader *crec, *prec; - - if (*keylist == '\0' && UNIQUE) - return; - wts1 = wts = ftbl[0].weights; - if ((!UNIQUE) && SINGL_FLD) { - if ((ftbl[0].flags & F) && (ftbl[0].flags & R)) - wts1 = Rascii; - else if (ftbl[0].flags & F) - wts1 = ascii; - odepth = depth; - } - lastkey = keylist + nelem; - depth += sizeof(TRECHEADER); - if (SINGL_FLD && (UNIQUE || wts1 != wts)) { - ppos = keylist; - prec = (const RECHEADER *) (*ppos - depth); - if (UNIQUE) - put(prec, fp); - for (cpos = &keylist[1]; cpos < lastkey; cpos++) { - crec = (const RECHEADER *) (*cpos - depth); - if (crec->length == prec->length) { - /* - * Set pend and cend so that trailing NUL and - * record separator is ignored. - */ - pend = (const u_char *) &prec->data + prec->length - 2; - cend = (const u_char *) &crec->data + crec->length - 2; - for (start = *cpos; cend >= start; cend--) { - if (wts[*cend] != wts[*pend]) - break; - pend--; - } - if (pend + 1 != *ppos) { - if (!UNIQUE) { - OUTPUT; - } else - put(crec, fp); - ppos = cpos; - prec = crec; - } - } else { - if (!UNIQUE) { - OUTPUT; - } else - put(crec, fp); - ppos = cpos; - prec = crec; - } - } - if (!UNIQUE) { OUTPUT; } - } else if (UNIQUE) { - ppos = keylist; - prec = (const RECHEADER *) (*ppos - depth); - put(prec, fp); - for (cpos = &keylist[1]; cpos < lastkey; cpos++) { - crec = (const RECHEADER *) (*cpos - depth); - if (crec->offset == prec->offset) { - /* - * Set pend and cend so that trailing NUL and - * record separator is ignored. - */ - pend = (const u_char *) &prec->data + prec->offset - 2; - cend = (const u_char *) &crec->data + crec->offset - 2; - for (start = *cpos; cend >= start; cend--) { - if (wts[*cend] != wts[*pend]) - break; - pend--; - } - if (pend + 1 != *ppos) { - ppos = cpos; - prec = crec; - put(prec, fp); - } - } else { - ppos = cpos; - prec = crec; - put(prec, fp); - } - } - } else for (cpos = keylist; cpos < lastkey; cpos++) { - crec = (const RECHEADER *) (*cpos - depth); - put(crec, fp); - } -} - -/* - * output the already sorted eol bin. - */ -void -rd_append(binno, infl0, nfiles, outfp, buffer, bufend) - u_char *buffer; - int infl0; - int binno, nfiles; - FILE *outfp; - u_char *bufend; -{ - RECHEADER *rec; - - rec = (RECHEADER *) buffer; - if (!getnext(binno, infl0, NULL, nfiles, - (RECHEADER *) buffer, bufend, 0)) { - putline(rec, outfp); - while (getnext(binno, infl0, NULL, nfiles, (RECHEADER *) buffer, - bufend, 0) == 0) { - if (!UNIQUE) - putline(rec, outfp); - } - } -} - -/* - * append plain text--used after sorting the biggest bin. - */ -void -concat(a, b) - FILE *a, *b; -{ - int nread; - char buffer[4096]; - - rewind(b); - while ((nread = fread(buffer, 1, 4096, b)) > 0) - EWRITE(buffer, 1, nread, a); -} diff --git a/usr.bin/sort/extern.h b/usr.bin/sort/extern.h deleted file mode 100644 index cdfb9fe2bd90..000000000000 --- a/usr.bin/sort/extern.h +++ /dev/null @@ -1,69 +0,0 @@ -/* $NetBSD: extern.h,v 1.5 2001/01/12 19:31:25 jdolecek Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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. - * - * @(#)extern.h 8.1 (Berkeley) 6/6/93 - */ - -void append __P((const u_char **, int, int, FILE *, - void (*)(const RECHEADER *, FILE *), struct field *)); -void concat __P((FILE *, FILE *)); -length_t enterkey __P((RECHEADER *, DBT *, int, struct field *)); -void fixit __P((int *, char **)); -void fldreset __P((struct field *)); -FILE *ftmp __P((void)); -void fmerge __P((int, int, struct filelist *, int, - get_func_t, FILE *, put_func_t, struct field *)); -void fsort __P((int, int, int, struct filelist *, int, FILE *, - struct field *)); -int geteasy __P((int, int, struct filelist *, - int, RECHEADER *, u_char *, struct field *)); -int getnext __P((int, int, struct filelist *, - int, RECHEADER *, u_char *, struct field *)); -int makekey __P((int, int, struct filelist *, - int, RECHEADER *, u_char *, struct field *)); -int makeline __P((int, int, struct filelist *, - int, RECHEADER *, u_char *, struct field *)); -void merge __P((int, int, get_func_t, FILE *, put_func_t, struct field *)); -void num_init __P((void)); -void onepass __P((const u_char **, int, long, long *, u_char *, FILE *)); -int optval __P((int, int)); -void order __P((struct filelist *, get_func_t, struct field *)); -void putline __P((const RECHEADER *, FILE *)); -void putrec __P((const RECHEADER *, FILE *)); -void rd_append __P((int, int, int, FILE *, u_char *, u_char *)); -int setfield __P((const char *, struct field *, int)); -void settables __P((int)); diff --git a/usr.bin/sort/fields.c b/usr.bin/sort/fields.c deleted file mode 100644 index 175b87fb1fba..000000000000 --- a/usr.bin/sort/fields.c +++ /dev/null @@ -1,339 +0,0 @@ -/* $NetBSD: fields.c,v 1.9 2001/02/19 19:52:27 jdolecek Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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. - */ - -/* Subroutines to generate sort keys. */ - -#include "sort.h" - -#ifndef lint -__RCSID("$NetBSD: fields.c,v 1.9 2001/02/19 19:52:27 jdolecek Exp $"); -__SCCSID("@(#)fields.c 8.1 (Berkeley) 6/6/93"); -#endif /* not lint */ - -#define blancmange(ptr) { \ - if (BLANK & d_mask[*(ptr)]) \ - while (BLANK & d_mask[*(++(ptr))]); \ -} - -#define NEXTCOL(pos) { \ - if (!SEP_FLAG) \ - while (BLANK & l_d_mask[*(++pos)]); \ - while (!((FLD_D | REC_D_F) & l_d_mask[*++pos])); \ -} - -static u_char *enterfield __P((u_char *, u_char *, struct field *, int)); -static u_char *number __P((u_char *, u_char *, u_char *, u_char *, int)); - -extern struct coldesc clist[(ND+1)*2]; -extern int ncols; - -#define DECIMAL '.' -#define OFFSET 128 - -u_char TENS[10]; /* TENS[0] = REC_D <= 128 ? 130 - '0' : 2 -'0'... */ -u_char NEGTENS[10]; /* NEGTENS[0] = REC_D <= 128 ? 126 + '0' : 252 +'0' */ -u_char *OFF_TENS, *OFF_NTENS; /* TENS - '0', NEGTENS - '0' */ -u_char fnum[NBINS], rnum[NBINS]; - -/* - * constructs sort key with leading recheader, followed by the key, - * followed by the original line. - */ -length_t -enterkey(keybuf, line, size, fieldtable) - RECHEADER *keybuf; /* pointer to start of key */ - DBT *line; - int size; - struct field fieldtable[]; -{ - int i; - u_char *l_d_mask; - u_char *lineend, *pos; - u_char *endkey, *keypos; - struct coldesc *clpos; - int col = 1; - struct field *ftpos; - l_d_mask = d_mask; - pos = (u_char *) line->data - 1; - lineend = (u_char *) line->data + line->size-1; - /* don't include rec_delimiter */ - - for (i = 0; i < ncols; i++) { - clpos = clist + i; - for (; (col < clpos->num) && (pos < lineend); col++) { - NEXTCOL(pos); - } - if (pos >= lineend) - break; - clpos->start = SEP_FLAG ? pos + 1 : pos; - NEXTCOL(pos); - clpos->end = pos; - col++; - if (pos >= lineend) { - clpos->end = lineend; - i++; - break; - } - } - for (; i <= ncols; i++) - clist[i].start = clist[i].end = lineend; - if (clist[0].start < (u_char *) line->data) - clist[0].start++; - - keypos = keybuf->data; - endkey = (u_char *) keybuf + size - line->size; - for (ftpos = fieldtable + 1; ftpos->icol.num; ftpos++) - if ((keypos = enterfield(keypos, endkey, ftpos, - fieldtable->flags)) == NULL) - return (1); - - keybuf->offset = keypos - keybuf->data; - keybuf->length = keybuf->offset + line->size; - if (keybuf->length + sizeof(TRECHEADER) > size) { - /* line too long for buffer */ - return (1); - } - - /* - * Make [s]radixsort() only sort by relevant part of key if: - * 1. we want to choose unique items by relevant field[s] - * 2. we want stable sort and so the items should be sorted only by - * the relevant field[s] - */ - if (UNIQUE || (stable_sort && keybuf->offset < line->size)) - keypos[-1] = REC_D; - - memcpy(keybuf->data + keybuf->offset, line->data, line->size); - return (0); -} - -/* - * constructs a field (as defined by -k) within a key - */ -static u_char * -enterfield(tablepos, endkey, cur_fld, gflags) - struct field *cur_fld; - u_char *tablepos, *endkey; - int gflags; -{ - u_char *start, *end, *lineend, *mask, *lweight; - struct column icol, tcol; - u_int flags; - u_int Rflag; - - icol = cur_fld->icol; - tcol = cur_fld->tcol; - flags = cur_fld->flags; - start = icol.p->start; - lineend = clist[ncols].end; - if (flags & BI) - blancmange(start); - start += icol.indent; - start = min(start, lineend); - - if (!tcol.num) - end = lineend; - else { - if (tcol.indent) { - end = tcol.p->start; - if (flags & BT) - blancmange(end); - end += tcol.indent; - end = min(end, lineend); - } else - end = tcol.p->end; - } - - if (flags & N) { - Rflag = (gflags & R ) ^ (flags & R) ? 1 : 0; - return number(tablepos, endkey, start, end, Rflag); - } - - mask = cur_fld->mask; - lweight = cur_fld->weights; - for (; start < end; start++) - if (mask[*start]) { - if (*start <= 1) { - if (tablepos+2 >= endkey) - return (NULL); - *tablepos++ = lweight[1]; - *tablepos++ = lweight[*start ? 2 : 1]; - } else { - if (tablepos+1 >= endkey) - return (NULL); - *tablepos++ = lweight[*start]; - } - } - *tablepos++ = lweight[0]; - return (tablepos == endkey ? NULL : tablepos); -} - -/* Uses the first bin to assign sign, expsign, 0, and the first - * 61 out of the exponent ( (254 - 3 origins - 4 over/underflows)/4 = 61 ). - * When sorting in forward order: - * use (0-99) -> (130->240) for sorting the mantissa if REC_D <=128; - * else use (0-99)->(2-102). - * If the exponent is >=61, use another byte for each additional 253 - * in the exponent. Cutoff is at 567. - * To avoid confusing the exponent and the mantissa, use a field delimiter - * if the exponent is exactly 61, 61+252, etc--this is ok, since it's the - * only time a field delimiter can come in that position. - * Reverse order is done analagously. - */ - -static u_char * -number(pos, bufend, line, lineend, Rflag) - u_char *line, *pos, *bufend, *lineend; - int Rflag; -{ - int or_sign, parity = 0; - int expincr = 1, exponent = -1; - int bite, expsign = 1, sign = 1; - u_char lastvalue, *nonzero, *tline, *C_TENS; - u_char *nweights; - - if (Rflag) - nweights = rnum; - else - nweights = fnum; - if (pos > bufend - 8) - return (NULL); - /* - * or_sign sets the sort direction: - * (-r: +/-)(sign: +/-)(expsign: +/-) - */ - or_sign = sign ^ expsign ^ Rflag; - blancmange(line); - if (*line == '-') { /* set the sign */ - or_sign ^= 1; - sign = 0; - line++; - } - /* eat initial zeroes */ - for (; *line == '0' && line < lineend; line++) - ; - /* calculate exponents < 0 */ - if (*line == DECIMAL) { - exponent = 1; - while (*++line == '0' && line < lineend) - exponent++; - expincr = 0; - expsign = 0; - } - /* next character better be a digit */ - if (*line < '1' || *line > '9' || line >= lineend) { - *pos++ = nweights[127]; - return (pos); - } - if (expincr) { - for (tline = line-1; *++tline >= '0' && - *tline <= '9' && tline < lineend;) - exponent++; - } - if (exponent > 567) { - *pos++ = nweights[sign ? (expsign ? 254 : 128) - : (expsign ? 0 : 126)]; - warnx("exponent out of bounds"); - return (pos); - } - bite = min(exponent, 61); - *pos++ = nweights[(sign) ? (expsign ? 189+bite : 189-bite) - : (expsign ? 64-bite : 64+bite)]; - if (bite >= 61) { - do { - exponent -= bite; - bite = min(exponent, 254); - *pos++ = nweights[or_sign ? 254-bite : bite]; - } while (bite == 254); - } - C_TENS = or_sign ? OFF_NTENS : OFF_TENS; - for (; line < lineend; line++) { - if (*line >= '0' && *line <= '9') { - if (parity) { - *pos++ = C_TENS[lastvalue] + (or_sign ? - *line - : *line); - if (pos == bufend) - return (NULL); - if (*line != '0' || lastvalue != '0') - nonzero = pos; - } else - lastvalue = *line; - parity ^= 1; - } else if(*line == DECIMAL) { - if(!expincr) /* a decimal already occurred once */ - break; - expincr = 0; - } else - break; - } - if (parity && lastvalue != '0') { - *pos++ = or_sign ? OFF_NTENS[lastvalue] - '0' : - OFF_TENS[lastvalue] + '0'; - } else - pos = nonzero; - if (pos > bufend-1) - return (NULL); - *pos++ = or_sign ? nweights[254] : nweights[0]; - return (pos); -} - -/* This forces a gap around the record delimiter - * Thus fnum has vaues over (0,254) -> ((0,REC_D-1),(REC_D+1,255)); - * rnum over (0,254) -> (255,REC_D+1),(REC_D-1,0)) - */ -void -num_init() -{ - int i; - TENS[0] = REC_D <=128 ? 130 - '0' : 2 - '0'; - NEGTENS[0] = REC_D <=128 ? 126 + '0' : 254 + '0'; - OFF_TENS = TENS - '0'; - OFF_NTENS = NEGTENS - '0'; - for (i = 1; i < 10; i++) { - TENS[i] = TENS[i - 1] + 10; - NEGTENS[i] = NEGTENS[i - 1] - 10; - } - for (i = 0; i < REC_D; i++) { - fnum[i] = i; - rnum[255 - i] = i; - } - for (i = REC_D; i <255; i++) { - fnum[i] = i + 1; - rnum[255 - i] = i - 1; - } -} diff --git a/usr.bin/sort/files.c b/usr.bin/sort/files.c deleted file mode 100644 index f53d45678f36..000000000000 --- a/usr.bin/sort/files.c +++ /dev/null @@ -1,372 +0,0 @@ -/* $NetBSD: files.c,v 1.16 2001/02/19 20:50:17 jdolecek Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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. - */ - -#include "sort.h" -#include "fsort.h" - -#ifndef lint -__RCSID("$NetBSD: files.c,v 1.16 2001/02/19 20:50:17 jdolecek Exp $"); -__SCCSID("@(#)files.c 8.1 (Berkeley) 6/6/93"); -#endif /* not lint */ - -#include <string.h> - -static int seq __P((FILE *, DBT *, DBT *)); - -/* - * this is the subroutine for file management for fsort(). - * It keeps the buffers for all temporary files. - */ -int -getnext(binno, infl0, filelist, nfiles, pos, end, dummy) - int binno, infl0; - struct filelist *filelist; - int nfiles; - RECHEADER *pos; - u_char *end; - struct field *dummy; -{ - int i; - u_char *hp; - static size_t nleft = 0; - static int cnt = 0, flag = -1; - static u_char maxb = 0; - static FILE *fp; - - if (nleft == 0) { - if (binno < 0) /* reset files. */ { - for (i = 0; i < nfiles; i++) { - rewind(fstack[infl0 + i].fp); - fstack[infl0 + i].max_o = 0; - } - flag = -1; - nleft = cnt = 0; - return (-1); - } - maxb = fstack[infl0].maxb; - for (; nleft == 0; cnt++) { - if (cnt >= nfiles) { - cnt = 0; - return (EOF); - } - fp = fstack[infl0 + cnt].fp; - fread(&nleft, sizeof(nleft), 1, fp); - if (binno < maxb) - fstack[infl0+cnt].max_o - += sizeof(nleft) + nleft; - else if (binno == maxb) { - if (binno != fstack[infl0].lastb) { - fseek(fp, fstack[infl0+ - cnt].max_o, SEEK_SET); - fread(&nleft, sizeof(nleft), 1, fp); - } - if (nleft == 0) - fclose(fp); - } else if (binno == maxb + 1) { /* skip a bin */ - fseek(fp, nleft, SEEK_CUR); - fread(&nleft, sizeof(nleft), 1, fp); - flag = cnt; - } - } - } - if ((u_char *) pos > end - sizeof(TRECHEADER)) - return (BUFFEND); - fread(pos, sizeof(TRECHEADER), 1, fp); - if (end - pos->data < pos->length) { - hp = ((u_char *)pos) + sizeof(TRECHEADER); - for (i = sizeof(TRECHEADER); i ; i--) - ungetc(*--hp, fp); - return (BUFFEND); - } - fread(pos->data, pos->length, 1, fp); - nleft -= pos->length + sizeof(TRECHEADER); - if (nleft == 0 && binno == fstack[infl0].maxb) - fclose(fp); - return (0); -} - -/* - * this is called when there is no special key. It's only called - * in the first fsort pass. - */ -int -makeline(flno, top, filelist, nfiles, recbuf, bufend, dummy2) - int flno, top; - struct filelist *filelist; - int nfiles; - RECHEADER *recbuf; - u_char *bufend; - struct field *dummy2; -{ - static u_char *obufend; - static size_t osz; - char *pos; - static int filenum = 0, overflow = 0; - static FILE *fp = 0; - int c; - - pos = (char *) recbuf->data; - if (overflow) { - /* - * Buffer shortage is solved by either of two ways: - * o flush previous buffered data and start using the - * buffer from start (see fsort()) - * o realloc buffer and bump bufend - * - * The former is preferred, realloc is only done when - * there is exactly one item in buffer which does not fit. - */ - if (bufend == obufend) - memmove(pos, bufend - osz, osz); - - pos += osz; - overflow = 0; - } - for (;;) { - if (flno >= 0 && (fp = fstack[flno].fp) == NULL) - return (EOF); - else if (fp == NULL) { - if (filenum >= nfiles) - return (EOF); - if (!(fp = fopen(filelist->names[filenum], "r"))) - err(2, "%s", filelist->names[filenum]); - filenum++; - } - while ((pos < (char *)bufend) && ((c = getc(fp)) != EOF)) { - if ((*pos++ = c) == REC_D) { - recbuf->offset = 0; - recbuf->length = pos - (char *) recbuf->data; - return (0); - } - } - if (pos >= (char *)bufend) { - if (recbuf->data < bufend) { - overflow = 1; - obufend = bufend; - osz = (pos - (char *) recbuf->data); - } - return (BUFFEND); - } else if (c == EOF) { - if (recbuf->data != (u_char *) pos) { - *pos++ = REC_D; - recbuf->offset = 0; - recbuf->length = pos - (char *) recbuf->data; - return (0); - } - FCLOSE(fp); - fp = 0; - if (flno >= 0) - fstack[flno].fp = 0; - } else { - - warnx("makeline: line too long: ignoring '%.100s...'", recbuf->data); - - /* Consume the rest of line from input */ - while((c = getc(fp)) != REC_D && c != EOF) - ; - - recbuf->offset = 0; - recbuf->length = 0; - - return (BUFFEND); - } - } -} - -/* - * This generates keys. It's only called in the first fsort pass - */ -int -makekey(flno, top, filelist, nfiles, recbuf, bufend, ftbl) - int flno, top; - struct filelist *filelist; - int nfiles; - RECHEADER *recbuf; - u_char *bufend; - struct field *ftbl; -{ - static int filenum = 0; - static FILE *dbdesc = 0; - static DBT dbkey[1], line[1]; - static int overflow = 0; - int c; - - if (overflow) { - overflow = enterkey(recbuf, line, bufend - (u_char *)recbuf, - ftbl); - if (overflow) - return (BUFFEND); - else - return (0); - } - - for (;;) { - if (flno >= 0) { - if (!(dbdesc = fstack[flno].fp)) - return (EOF); - } else if (!dbdesc) { - if (filenum >= nfiles) - return (EOF); - dbdesc = fopen(filelist->names[filenum], "r"); - if (!dbdesc) - err(2, "%s", filelist->names[filenum]); - filenum++; - } - if (!(c = seq(dbdesc, line, dbkey))) { - if ((signed)line->size > bufend - recbuf->data) { - overflow = 1; - } else { - overflow = enterkey(recbuf, line, - bufend - (u_char *) recbuf, ftbl); - } - if (overflow) - return (BUFFEND); - else - return (0); - } - if (c == EOF) { - FCLOSE(dbdesc); - dbdesc = 0; - if (flno >= 0) - fstack[flno].fp = 0; - } else { - ((char *) line->data)[60] = '\000'; - warnx("makekey: line too long: ignoring %.100s...", - (char *)line->data); - } - } -} - -/* - * get a key/line pair from fp - */ -static int -seq(fp, line, key) - FILE *fp; - DBT *key, *line; -{ - static char *buf, flag = 1; - char *end, *pos; - int c; - - if (flag) { - flag = 0; - buf = (char *) linebuf; - end = buf + linebuf_size; - line->data = buf; - } - pos = buf; - while ((c = getc(fp)) != EOF) { - if ((*pos++ = c) == REC_D) { - line->size = pos - buf; - return (0); - } - if (pos == end) { - linebuf_size *= 2; - linebuf = realloc(linebuf, linebuf_size); - if (!linebuf) - err(2, "realloc of linebuf to %lu bytes failed", - (unsigned long)linebuf_size); - - end = linebuf + linebuf_size; - pos = linebuf + (pos - buf); - line->data = buf = (char *)linebuf; - continue; - } - } - if (pos != buf) { - *pos++ = REC_D; - line->size = pos - buf; - return (0); - } else - return (EOF); -} - -/* - * write a key/line pair to a temporary file - */ -void -putrec(rec, fp) - const RECHEADER *rec; - FILE *fp; -{ - EWRITE(rec, 1, rec->length + sizeof(TRECHEADER), fp); -} - -/* - * write a line to output - */ -void -putline(rec, fp) - const RECHEADER *rec; - FILE *fp; -{ - EWRITE(rec->data+rec->offset, 1, rec->length - rec->offset, fp); -} - -/* - * get a record from a temporary file. (Used by merge sort.) - */ -int -geteasy(flno, top, filelist, nfiles, rec, end, dummy2) - int flno, top; - struct filelist *filelist; - int nfiles; - RECHEADER *rec; - u_char *end; - struct field *dummy2; -{ - int i; - FILE *fp; - - fp = fstack[flno].fp; - if ((u_char *) rec > end - sizeof(TRECHEADER)) - return (BUFFEND); - if (!fread(rec, 1, sizeof(TRECHEADER), fp)) { - fclose(fp); - fstack[flno].fp = 0; - return (EOF); - } - if (end - rec->data < rec->length) { - for (i = sizeof(TRECHEADER) - 1; i >= 0; i--) - ungetc(*((char *) rec + i), fp); - return (BUFFEND); - } - fread(rec->data, rec->length, 1, fp); - return (0); -} diff --git a/usr.bin/sort/fsort.c b/usr.bin/sort/fsort.c deleted file mode 100644 index a38c79da6458..000000000000 --- a/usr.bin/sort/fsort.c +++ /dev/null @@ -1,358 +0,0 @@ -/* $NetBSD: fsort.c,v 1.19 2001/05/15 11:19:45 jdolecek Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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. - */ - -/* - * Read in the next bin. If it fits in one segment sort it; - * otherwise refine it by segment deeper by one character, - * and try again on smaller bins. Sort the final bin at this level - * of recursion to keep the head of fstack at 0. - * After PANIC passes, abort to merge sort. - */ -#include "sort.h" -#include "fsort.h" - -#ifndef lint -__RCSID("$NetBSD: fsort.c,v 1.19 2001/05/15 11:19:45 jdolecek Exp $"); -__SCCSID("@(#)fsort.c 8.1 (Berkeley) 6/6/93"); -#endif /* not lint */ - -#include <stdlib.h> -#include <string.h> - -static const u_char **keylist = 0; -u_char *buffer = 0, *linebuf = 0; -size_t bufsize = DEFBUFSIZE; -size_t linebuf_size; -struct tempfile fstack[MAXFCT]; -extern char *toutpath; -#define FSORTMAX 4 -int PANIC = FSORTMAX; - -#define MSTART (MAXFCT - MERGE_FNUM) -#define SALIGN(n) ((n+sizeof(length_t)-1) & ~(sizeof(length_t)-1)) - -void -fsort(binno, depth, top, filelist, nfiles, outfp, ftbl) - int binno, depth, top; - struct filelist *filelist; - int nfiles; - FILE *outfp; - struct field *ftbl; -{ - const u_char **keypos; - u_char *bufend, *tmpbuf; - u_char *weights; - int ntfiles, mfct = 0, total, i, maxb, lastb, panic = 0; - int c, nelem, base; - long sizes [NBINS+1]; - get_func_t get; - struct recheader *crec; - struct field tfield[2]; - FILE *prevfp, *tailfp[FSORTMAX+1]; - - memset(tailfp, 0, sizeof(tailfp)); - prevfp = outfp; - memset(tfield, 0, sizeof(tfield)); - if (ftbl[0].flags & R) - tfield[0].weights = Rascii; - else - tfield[0].weights = ascii; - tfield[0].icol.num = 1; - weights = ftbl[0].weights; - if (!buffer) { - buffer = malloc(bufsize); - keylist = malloc(MAXNUM * sizeof(u_char *)); - memset(keylist, 0, MAXNUM * sizeof(u_char *)); - if (!SINGL_FLD) { - linebuf_size = DEFLLEN; - if ((linebuf = malloc(linebuf_size)) == NULL) - errx(2, "cannot allocate memory"); - } - } - bufend = buffer + bufsize; - if (binno >= 0) { - base = top + nfiles; - get = getnext; - } else { - base = 0; - if (SINGL_FLD) - get = makeline; - else - get = makekey; - } - for (;;) { - memset(sizes, 0, sizeof(sizes)); - c = ntfiles = 0; - if (binno == weights[REC_D] && - !(SINGL_FLD && ftbl[0].flags & F)) { /* pop */ - rd_append(weights[REC_D], top, - nfiles, prevfp, buffer, bufend); - break; - } else if (binno == weights[REC_D]) { - depth = 0; /* start over on flat weights */ - ftbl = tfield; - weights = ftbl[0].weights; - } - while (c != EOF) { - keypos = keylist; - nelem = 0; - crec = (RECHEADER *) buffer; - - do_read: - while((c = get(binno, top, filelist, nfiles, crec, - bufend, ftbl)) == 0) { - *keypos++ = crec->data + depth; - if (++nelem == MAXNUM) { - c = BUFFEND; - break; - } - crec =(RECHEADER *) ((char *) crec + - SALIGN(crec->length) + sizeof(TRECHEADER)); - } - - if (c == BUFFEND && nelem < MAXNUM - && bufsize < MAXBUFSIZE) { - const u_char **keyp; - u_char *oldb = buffer; - - /* buffer was too small for data, allocate - * bigger buffer */ - bufsize *= 2; - buffer = realloc(buffer, bufsize); - if (!buffer) { - err(2, "failed to realloc buffer to %ld bytes", - (unsigned long) bufsize); - } - bufend = buffer + bufsize; - - /* patch up keylist[] */ - for(keyp = &keypos[-1]; keyp >= keylist; keyp--) - *keyp = buffer + (*keyp - oldb); - - crec = (RECHEADER *) (buffer + ((u_char *)crec - oldb)); - goto do_read; - } - - if (c != BUFFEND && !ntfiles && !mfct) { - /* do not push */ - continue; - } - - /* push */ - if (panic >= PANIC) { - fstack[MSTART + mfct].fp = ftmp(); - if ((stable_sort) - ? sradixsort(keylist, nelem, - weights, REC_D) - : radixsort(keylist, nelem, - weights, REC_D) ) - err(2, NULL); - append(keylist, nelem, depth, - fstack[MSTART + mfct].fp, putrec, - ftbl); - mfct++; - /* reduce number of open files */ - if (mfct == MERGE_FNUM ||(c == EOF && ntfiles)) { - /* - * Only copy extra incomplete crec - * data if there are any. - */ - int nodata = (bufend >= (u_char *)crec - && bufend <= crec->data); - - if (!nodata) { - tmpbuf = malloc(bufend - - crec->data); - memmove(tmpbuf, crec->data, - bufend - crec->data); - } - - fstack[base + ntfiles].fp = ftmp(); - fmerge(0, MSTART, filelist, - mfct, geteasy, fstack[base].fp, - putrec, ftbl); - ntfiles++; - mfct = 0; - - if (!nodata) { - memmove(crec->data, tmpbuf, - bufend - crec->data); - free(tmpbuf); - } - } - } else { - fstack[base + ntfiles].fp= ftmp(); - onepass(keylist, depth, nelem, sizes, - weights, fstack[base + ntfiles].fp); - ntfiles++; - } - } - if (!ntfiles && !mfct) { /* everything in memory--pop */ - if (nelem > 1 - && ((stable_sort) - ? sradixsort(keylist, nelem, weights, REC_D) - : radixsort(keylist, nelem, weights, REC_D) )) - err(2, NULL); - if (nelem > 0) - append(keylist, nelem, depth, outfp, putline, ftbl); - break; /* pop */ - } - if (panic >= PANIC) { - if (!ntfiles) - fmerge(0, MSTART, filelist, mfct, geteasy, - outfp, putline, ftbl); - else - fmerge(0, base, filelist, ntfiles, geteasy, - outfp, putline, ftbl); - break; - - } - total = maxb = lastb = 0; /* find if one bin dominates */ - for (i = 0; i < NBINS; i++) - if (sizes[i]) { - if (sizes[i] > sizes[maxb]) - maxb = i; - lastb = i; - total += sizes[i]; - } - if (sizes[maxb] < max((total / 2) , BUFSIZE)) - maxb = lastb; /* otherwise pop after last bin */ - fstack[base].lastb = lastb; - fstack[base].maxb = maxb; - - /* start refining next level. */ - getnext(-1, base, NULL, ntfiles, crec, bufend, 0); /* rewind */ - for (i = 0; i < maxb; i++) { - if (!sizes[i]) /* bin empty; step ahead file offset */ - getnext(i, base, NULL,ntfiles, crec, bufend, 0); - else - fsort(i, depth+1, base, filelist, ntfiles, - outfp, ftbl); - } - - get = getnext; - - if (lastb != maxb) { - if (prevfp != outfp) - tailfp[panic] = prevfp; - prevfp = ftmp(); - for (i = maxb+1; i <= lastb; i++) - if (!sizes[i]) - getnext(i, base, NULL, ntfiles, crec, - bufend,0); - else - fsort(i, depth+1, base, filelist, - ntfiles, prevfp, ftbl); - } - - /* sort biggest (or last) bin at this level */ - depth++; - panic++; - binno = maxb; - top = base; - nfiles = ntfiles; /* so overwrite them */ - } - if (prevfp != outfp) { - concat(outfp, prevfp); - fclose(prevfp); - } - for (i = panic; i >= 0; --i) - if (tailfp[i]) { - concat(outfp, tailfp[i]); - fclose(tailfp[i]); - } - - /* If on top level, free our structures */ - if (depth == 0) { - free(keylist), keylist = NULL; - free(buffer), buffer = NULL; - } -} - -/* - * This is one pass of radix exchange, dumping the bins to disk. - */ -#define swap(a, b, t) t = a, a = b, b = t -void -onepass(a, depth, n, sizes, tr, fp) - const u_char **a; - int depth; - long n, sizes[]; - u_char *tr; - FILE *fp; -{ - size_t tsizes[NBINS+1]; - const u_char **bin[257], ***bp, ***bpmax, **top[256], ***tp; - static int histo[256]; - int *hp; - int c; - const u_char **an, *t, **aj; - const u_char **ak, *r; - - memset(tsizes, 0, sizeof(tsizes)); - depth += sizeof(TRECHEADER); - an = &a[n]; - for (ak = a; ak < an; ak++) { - histo[c = tr[**ak]]++; - tsizes[c] += ((const RECHEADER *) (*ak -= depth))->length; - } - - bin[0] = a; - bpmax = bin + 256; - tp = top, hp = histo; - for (bp = bin; bp < bpmax; bp++) { - *tp++ = *(bp+1) = *bp + (c = *hp); - *hp++ = 0; - if (c <= 1) - continue; - } - for (aj = a; aj < an; *aj = r, aj = bin[c+1]) - for (r = *aj; aj < (ak = --top[c = tr[r[depth]]]) ;) - swap(*ak, r, t); - - for (ak = a, c = 0; c < 256; c++) { - an = bin[c+1]; - n = an - ak; - tsizes[c] += n * sizeof(TRECHEADER); - /* tell getnext how many elements in this bin, this segment. */ - EWRITE(&tsizes[c], sizeof(size_t), 1, fp); - sizes[c] += tsizes[c]; - for (; ak < an; ++ak) - putrec((const RECHEADER *) *ak, fp); - } -} diff --git a/usr.bin/sort/fsort.h b/usr.bin/sort/fsort.h deleted file mode 100644 index f1d170202715..000000000000 --- a/usr.bin/sort/fsort.h +++ /dev/null @@ -1,77 +0,0 @@ -/* $NetBSD: fsort.h,v 1.8 2001/02/19 20:50:17 jdolecek Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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. - * - * @(#)fsort.h 8.1 (Berkeley) 6/6/93 - */ - -#define BUFSIZE (1<<20) -#define MAXNUM 131072 /* low guess at average record count */ -#define BUFFEND (EOF-2) -#define MAXFCT 1000 -#define DEFLLEN 65536 - -/* - * Default (initial) and maximum size of record buffer for fsort(). - * Note that no more than MAXNUM records are stored in the buffer, - * even if the buffer is not full yet. - */ -#define DEFBUFSIZE (1 << 20) /* 1MB */ -#define MAXBUFSIZE (8 << 20) /* 10 MB */ - -/* - * Number of files merge() can merge in one pass. - * This should be power of two so that it's possible to use this value - * for rouding. - */ -#define MERGE_FNUM 16 - -extern u_char *buffer, *linebuf; -extern size_t bufsize, linebuf_size; - -/* temp files in the stack have a file descriptor, a largest bin (maxb) - * which becomes the last non-empty bin (lastb) when the actual largest - * bin is smaller than max(half the total file, BUFSIZE) - * Max_o is the offset of maxb so it can be sought after the other bins - * are sorted. -*/ -struct tempfile { - FILE *fp; - u_char maxb; - u_char lastb; - int max_o; -}; -extern struct tempfile fstack[MAXFCT]; diff --git a/usr.bin/sort/init.c b/usr.bin/sort/init.c deleted file mode 100644 index 8b965b196a7c..000000000000 --- a/usr.bin/sort/init.c +++ /dev/null @@ -1,355 +0,0 @@ -/* $NetBSD: init.c,v 1.5 2001/02/19 20:50:17 jdolecek Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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. - */ - -#include "sort.h" - -#ifndef lint -__RCSID("$NetBSD: init.c,v 1.5 2001/02/19 20:50:17 jdolecek Exp $"); -__SCCSID("@(#)init.c 8.1 (Berkeley) 6/6/93"); -#endif /* not lint */ - -#include <ctype.h> -#include <string.h> - -static void insertcol __P((struct field *)); -static const char *setcolumn __P((const char *, struct field *, int)); -int setfield __P((const char *, struct field *, int)); - -extern struct coldesc clist[(ND+1)*2]; -extern int ncols; -u_char gweights[NBINS]; - -/* - * masks of ignored characters. Alltable is 256 ones. - */ -static u_char alltable[NBINS], dtable[NBINS], itable[NBINS]; - -/* - * clist (list of columns which correspond to one or more icol or tcol) - * is in increasing order of columns. - * Fields are kept in increasing order of fields. - */ - -/* - * keep clist in order--inserts a column in a sorted array - */ -static void -insertcol(field) - struct field *field; -{ - int i; - for (i = 0; i < ncols; i++) - if (field->icol.num <= clist[i].num) - break; - if (field->icol.num != clist[i].num) { - memmove(clist+i+1, clist+i, sizeof(COLDESC)*(ncols-i)); - clist[i].num = field->icol.num; - ncols++; - } - if (field->tcol.num && field->tcol.num != field->icol.num) { - for (i = 0; i < ncols; i++) - if (field->tcol.num <= clist[i].num) - break; - if (field->tcol.num != clist[i].num) { - memmove(clist+i+1, clist+i,sizeof(COLDESC)*(ncols-i)); - clist[i].num = field->tcol.num; - ncols++; - } - } -} - -/* - * matches fields with the appropriate columns--n^2 but who cares? - */ -void -fldreset(fldtab) - struct field *fldtab; -{ - int i; - fldtab[0].tcol.p = clist+ncols-1; - for (++fldtab; fldtab->icol.num; ++fldtab) { - for (i = 0; fldtab->icol.num != clist[i].num; i++) - ; - fldtab->icol.p = clist + i; - if (!fldtab->tcol.num) - continue; - for (i = 0; fldtab->tcol.num != clist[i].num; i++) - ; - fldtab->tcol.p = clist + i; - } -} - -/* - * interprets a column in a -k field - */ -static const char * -setcolumn(pos, cur_fld, gflag) - const char *pos; - struct field *cur_fld; - int gflag; -{ - struct column *col; - int tmp; - col = cur_fld->icol.num ? (&(*cur_fld).tcol) : (&(*cur_fld).icol); - pos += sscanf(pos, "%d", &(col->num)); - while (isdigit(*pos)) - pos++; - if (col->num <= 0 && !(col->num == 0 && col == &(cur_fld->tcol))) - errx(2, "field numbers must be positive"); - if (*pos == '.') { - if (!col->num) - errx(2, "cannot indent end of line"); - ++pos; - pos += sscanf(pos, "%d", &(col->indent)); - while (isdigit(*pos)) - pos++; - if (&cur_fld->icol == col) - col->indent--; - if (col->indent < 0) - errx(2, "illegal offset"); - } - if (optval(*pos, cur_fld->tcol.num)) - while ((tmp = optval(*pos, cur_fld->tcol.num))) { - cur_fld->flags |= tmp; - pos++; - } - if (cur_fld->icol.num == 0) - cur_fld->icol.num = 1; - return (pos); -} - -int -setfield(pos, cur_fld, gflag) - const char *pos; - struct field *cur_fld; - int gflag; -{ - static int nfields = 0; - int tmp; - - if (++nfields == ND) - errx(2, "too many sort keys. (Limit is %d)", ND-1); - - cur_fld->weights = ascii; - cur_fld->mask = alltable; - - pos = setcolumn(pos, cur_fld, gflag); - if (*pos == '\0') /* key extends to EOL. */ - cur_fld->tcol.num = 0; - else { - if (*pos != ',') - errx(2, "illegal field descriptor"); - setcolumn((++pos), cur_fld, gflag); - } - if (!cur_fld->flags) - cur_fld->flags = gflag; - tmp = cur_fld->flags; - - /* - * Assign appropriate mask table and weight table. - * If the global weights are reversed, the local field - * must be "re-reversed". - */ - if (((tmp & R) ^ (gflag & R)) && (tmp & F)) - cur_fld->weights = RFtable; - else if (tmp & F) - cur_fld->weights = Ftable; - else if ((tmp & R) ^ (gflag & R)) - cur_fld->weights = Rascii; - - if (tmp & I) - cur_fld->mask = itable; - else if (tmp & D) - cur_fld->mask = dtable; - - cur_fld->flags |= (gflag & (BI | BT)); - if (!cur_fld->tcol.indent) /* BT has no meaning at end of field */ - cur_fld->flags &= ~BT; - - if (cur_fld->tcol.num && !(!(cur_fld->flags & BI) - && cur_fld->flags & BT) && (cur_fld->tcol.num <= cur_fld->icol.num - && cur_fld->tcol.indent < cur_fld->icol.indent)) - errx(2, "fields out of order"); - insertcol(cur_fld); - return (cur_fld->tcol.num); -} - -int -optval(desc, tcolflag) - int desc, tcolflag; -{ - switch(desc) { - case 'b': - if (!tcolflag) - return (BI); - else - return (BT); - case 'd': return (D); - case 'f': return (F); - case 'i': return (I); - case 'n': return (N); - case 'r': return (R); - default: return (0); - } -} - -void -fixit(argc, argv) - int *argc; - char **argv; -{ - int i, j, v, w, x; - static char vbuf[ND*20], *vpos, *tpos; - vpos = vbuf; - - for (i = 1; i < *argc; i++) { - if (argv[i][0] == '+') { - tpos = argv[i]+1; - argv[i] = vpos; - vpos += sprintf(vpos, "-k"); - tpos += sscanf(tpos, "%d", &v); - while (isdigit(*tpos)) - tpos++; - vpos += sprintf(vpos, "%d", v+1); - if (*tpos == '.') { - ++tpos; - tpos += sscanf(tpos, "%d", &x); - vpos += sprintf(vpos, ".%d", x+1); - } - while (*tpos) - *vpos++ = *tpos++; - vpos += sprintf(vpos, ","); - if (argv[i+1] && - argv[i+1][0] == '-' && isdigit(argv[i+1][1])) { - tpos = argv[i+1] + 1; - tpos += sscanf(tpos, "%d", &w); - while (isdigit(*tpos)) - tpos++; - x = 0; - if (*tpos == '.') { - ++tpos; - tpos += sscanf(tpos, "%d", &x); - while (isdigit(*tpos)) - tpos++; - } - if (x) { - vpos += sprintf(vpos, "%d", w+1); - vpos += sprintf(vpos, ".%d", x); - } else - vpos += sprintf(vpos, "%d", w); - while (*tpos) - *vpos++ = *tpos++; - for (j= i+1; j < *argc; j++) - argv[j] = argv[j+1]; - *argc -= 1; - } - } - } -} - -/* - * ascii, Rascii, Ftable, and RFtable map - * REC_D -> REC_D; {not REC_D} -> {not REC_D}. - * gweights maps REC_D -> (0 or 255); {not REC_D} -> {not gweights[REC_D]}. - * Note: when sorting in forward order, to encode character zero in a key, - * use \001\001; character 1 becomes \001\002. In this case, character 0 - * is reserved for the field delimiter. Analagously for -r (fld_d = 255). - * Note: this is only good for ASCII sorting. For different LC 's, - * all bets are off. See also num_init in number.c - */ -void -settables(gflags) - int gflags; -{ - u_char *wts; - int i, incr; - for (i=0; i < 256; i++) { - ascii[i] = i; - if (i > REC_D && i < 255 - REC_D+1) - Rascii[i] = 255 - i + 1; - else - Rascii[i] = 255 - i; - if (islower(i)) { - Ftable[i] = Ftable[toupper(i)]; - RFtable[i] = RFtable[toupper(i)]; - } else if (REC_D>= 'A' && REC_D < 'Z' && i < 'a' && i > REC_D) { - Ftable[i] = i + 1; - RFtable[i] = Rascii[i] - 1; - } else { - Ftable[i] = i; - RFtable[i] = Rascii[i]; - } - alltable[i] = 1; - - if (i == '\n' || isprint(i)) - itable[i] = 1; - else - itable[i] = 0; - - if (i == '\n' || i == '\t' || i == ' ' || isalnum(i)) - dtable[i] = 1; - else - dtable[i] = 0; - } - - Rascii[REC_D] = RFtable[REC_D] = REC_D; - if (isupper(REC_D)) - Ftable[tolower(REC_D)]++; - - if ((gflags & R) && !((gflags & F) && SINGL_FLD)) - wts = Rascii; - else if (!((gflags & F) && SINGL_FLD)) - wts = ascii; - else if (gflags & R) - wts = RFtable; - else - wts = Ftable; - - memmove(gweights, wts, sizeof(gweights)); - incr = (gflags & R) ? -1 : 1; - for (i = 0; i < REC_D; i++) - gweights[i] += incr; - gweights[REC_D] = ((gflags & R) ? 255 : 0); - if (SINGL_FLD && (gflags & F)) { - for (i = 0; i < REC_D; i++) { - ascii[i] += incr; - Rascii[i] += incr; - } - ascii[REC_D] = Rascii[REC_D] = gweights[REC_D]; - } -} diff --git a/usr.bin/sort/msort.c b/usr.bin/sort/msort.c deleted file mode 100644 index f66db0b2e02d..000000000000 --- a/usr.bin/sort/msort.c +++ /dev/null @@ -1,390 +0,0 @@ -/* $NetBSD: msort.c,v 1.9 2001/01/19 10:50:31 jdolecek Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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. - */ - -#include "sort.h" -#include "fsort.h" - -#ifndef lint -__RCSID("$NetBSD: msort.c,v 1.9 2001/01/19 10:50:31 jdolecek Exp $"); -__SCCSID("@(#)msort.c 8.1 (Berkeley) 6/6/93"); -#endif /* not lint */ - -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -/* Subroutines using comparisons: merge sort and check order */ -#define DELETE (1) - -typedef struct mfile { - u_char *end; - short flno; - struct recheader rec[1]; -} MFILE; - -static u_char *wts, *wts1 = NULL; - -static int cmp __P((RECHEADER *, RECHEADER *)); -static int insert __P((struct mfile **, struct mfile **, int, int)); - -void -fmerge(binno, top, filelist, nfiles, get, outfp, fput, ftbl) - int binno, top; - struct filelist *filelist; - int nfiles; - get_func_t get; - FILE *outfp; - put_func_t fput; - struct field *ftbl; -{ - FILE *tout; - int i, j, last; - put_func_t put; - struct tempfile *l_fstack; - - wts = ftbl->weights; - if (!UNIQUE && SINGL_FLD && ftbl->flags & F) - wts1 = (ftbl->flags & R) ? Rascii : ascii; - - if (!buffer) { - buffer = malloc(bufsize); - if (!buffer) - err(2, "fmerge(): realloc"); - - if (!linebuf && !SINGL_FLD) { - linebuf_size = DEFLLEN; - linebuf = malloc(linebuf_size); - } - } - - if (binno >= 0) - l_fstack = fstack + top; - else - l_fstack = fstack; - - while (nfiles) { - put = putrec; - for (j = 0; j < nfiles; j += MERGE_FNUM) { - if (nfiles <= MERGE_FNUM) { - tout = outfp; - put = fput; - } - else - tout = ftmp(); - last = min(MERGE_FNUM, nfiles - j); - if (binno < 0) { - for (i = 0; i < last; i++) - if (!(l_fstack[i+MAXFCT-1-MERGE_FNUM].fp = - fopen(filelist->names[j+i], "r"))) - err(2, "%s", - filelist->names[j+i]); - merge(MAXFCT-1-MERGE_FNUM, last, get, tout, put, ftbl); - } else { - for (i = 0; i< last; i++) - rewind(l_fstack[i+j].fp); - merge(top+j, last, get, tout, put, ftbl); - } - if (nfiles > MERGE_FNUM) - l_fstack[j/MERGE_FNUM].fp = tout; - } - nfiles = (nfiles + (MERGE_FNUM - 1)) / MERGE_FNUM; - if (nfiles == 1) - nfiles = 0; - if (binno < 0) { - binno = 0; - get = geteasy; - top = 0; - } - } -} - -void -merge(infl0, nfiles, get, outfp, put, ftbl) - int infl0, nfiles; - get_func_t get; - put_func_t put; - FILE *outfp; - struct field *ftbl; -{ - int c, i, j, nf = nfiles; - struct mfile *flist[MERGE_FNUM], *cfile; - size_t availsz = bufsize; - static void *bufs[MERGE_FNUM+1]; - static size_t bufs_sz[MERGE_FNUM+1]; - - /* - * We need nfiles + 1 buffers. One is 'buffer', the - * rest needs to be allocated. - */ - bufs[0] = buffer; - bufs_sz[0] = bufsize; - for(i=1; i < nfiles+1; i++) { - if (bufs[i]) - continue; - - bufs[i] = malloc(DEFLLEN); - if (!bufs[i]) - err(2, "merge(): realloc"); - bufs_sz[i] = DEFLLEN; - } - - for (i = j = 0; i < nfiles; i++) { - cfile = (struct mfile *) bufs[j]; - cfile->flno = infl0 + j; - cfile->end = (u_char *) bufs[j] + bufs_sz[j]; - for (c = 1; c == 1;) { - if (EOF == (c = get(cfile->flno, 0, NULL, nfiles, - cfile->rec, cfile->end, ftbl))) { - --i; - --nfiles; - break; - } - - if (c == BUFFEND) { - cfile = realloc(bufs[j], bufs_sz[j] *= 2); - bufs[j] = (void *) cfile; - - if (!cfile) - err(2, "merge(): realloc"); - - cfile->end = (u_char *)cfile + bufs_sz[j]; - - c = 1; - continue; - } - - if (i) - c = insert(flist, &cfile, i, !DELETE); - else - flist[0] = cfile; - } - j++; - } - - cfile = (struct mfile *) bufs[nf]; - cfile->flno = flist[0]->flno; - cfile->end = (u_char *) cfile + bufs_sz[nf]; - while (nfiles) { - for (c = 1; c == 1;) { - if (EOF == (c = get(cfile->flno, 0, NULL, nfiles, - cfile->rec, cfile->end, ftbl))) { - put(flist[0]->rec, outfp); - memmove(flist, flist + 1, - sizeof(MFILE *) * (--nfiles)); - cfile->flno = flist[0]->flno; - break; - } - if (c == BUFFEND) { - char *oldbuf = (char *) cfile; - availsz = (char *) cfile->end - oldbuf; - availsz *= 2; - cfile = realloc(oldbuf, availsz); - for(i=0; i < nf+1; i++) { - if (bufs[i] == oldbuf) { - bufs[i] = (char *)cfile; - bufs_sz[i] = availsz; - break; - } - } - - if (!cfile) - err(2, "merge: realloc"); - - cfile->end = (u_char *)cfile + availsz; - c = 1; - continue; - } - - if (!(c = insert(flist, &cfile, nfiles, DELETE))) - put(cfile->rec, outfp); - } - } - - if (bufs_sz[0] > bufsize) { - buffer = bufs[0]; - bufsize = bufs_sz[0]; - } -} - -/* - * if delete: inserts *rec in flist, deletes flist[0], and leaves it in *rec; - * otherwise just inserts *rec in flist. - */ -static int -insert(flist, rec, ttop, delete) - struct mfile **flist, **rec; - int delete, ttop; /* delete = 0 or 1 */ -{ - struct mfile *tmprec = *rec; - int mid, top = ttop, bot = 0, cmpv = 1; - - for (mid = top/2; bot +1 != top; mid = (bot+top)/2) { - cmpv = cmp(tmprec->rec, flist[mid]->rec); - if (cmpv < 0) - top = mid; - else if (cmpv > 0) - bot = mid; - else { - if (UNIQUE) - break; - - if (stable_sort) { - /* - * Apply sort by fileno, to give priority - * to earlier specified files, hence providing - * more stable sort. - * If fileno is same, the new record should - * be put _after_ the previous entry. - */ - cmpv = tmprec->flno - flist[mid]->flno; - if (cmpv >= 0) - bot = mid; - else /* cmpv == 0 */ - bot = mid - 1; - } else { - /* non-stable sort */ - bot = mid - 1; - } - - break; - } - } - - if (delete) { - if (UNIQUE) { - if (!bot && cmpv) - cmpv = cmp(tmprec->rec, flist[0]->rec); - if (!cmpv) - return (1); - } - tmprec = flist[0]; - if (bot) - memmove(flist, flist+1, bot * sizeof(MFILE **)); - flist[bot] = *rec; - *rec = tmprec; - (*rec)->flno = flist[0]->flno; - return (0); - } else { - if (!bot && !(UNIQUE && !cmpv)) { - cmpv = cmp(tmprec->rec, flist[0]->rec); - if (cmpv < 0) - bot = -1; - } - if (UNIQUE && !cmpv) - return (1); - bot++; - memmove(flist + bot+1, flist + bot, - (ttop - bot) * sizeof(MFILE **)); - flist[bot] = *rec; - return (0); - } -} - -/* - * check order on one file - */ -void -order(filelist, get, ftbl) - struct filelist *filelist; - get_func_t get; - struct field *ftbl; -{ - u_char *crec_end, *prec_end, *trec_end; - int c; - RECHEADER *crec, *prec, *trec; - - if (!SINGL_FLD) - linebuf = malloc(DEFLLEN); - buffer = malloc(2 * (DEFLLEN + sizeof(TRECHEADER))); - crec = (RECHEADER *) buffer; - crec_end = buffer + DEFLLEN + sizeof(TRECHEADER); - prec = (RECHEADER *) (buffer + DEFLLEN + sizeof(TRECHEADER)); - prec_end = buffer + 2*(DEFLLEN + sizeof(TRECHEADER)); - wts = ftbl->weights; - if (SINGL_FLD && (ftbl->flags & F)) - wts1 = (ftbl->flags & R) ? Rascii : ascii; - else - wts1 = NULL; - if (0 == get(-1, 0, filelist, 1, prec, prec_end, ftbl)) - while (0 == get(-1, 0, filelist, 1, crec, crec_end, ftbl)) { - if (0 < (c = cmp(prec, crec))) { - crec->data[crec->length-1] = 0; - errx(1, "found disorder: %s", crec->data+crec->offset); - } - if (UNIQUE && !c) { - crec->data[crec->length-1] = 0; - errx(1, "found non-uniqueness: %s", - crec->data+crec->offset); - } - /* - * Swap pointers so that this record is on place pointed - * to by prec and new record is read to place pointed to by - * crec. - */ - trec = prec; - prec = crec; - crec = trec; - trec_end = prec_end; - prec_end = crec_end; - crec_end = trec_end; - } - exit(0); -} - -static int -cmp(rec1, rec2) - RECHEADER *rec1, *rec2; -{ - int r; - u_char *pos1, *pos2, *end; - u_char *cwts; - for (cwts = wts; cwts; cwts = (cwts == wts1 ? NULL : wts1)) { - pos1 = rec1->data; - pos2 = rec2->data; - if (!SINGL_FLD && (UNIQUE || stable_sort)) - end = pos1 + min(rec1->offset, rec2->offset); - else - end = pos1 + min(rec1->length, rec2->length); - - for (; pos1 < end; ) { - if ((r = cwts[*pos1++] - cwts[*pos2++])) - return (r); - } - } - return (0); -} diff --git a/usr.bin/sort/pathnames.h b/usr.bin/sort/pathnames.h deleted file mode 100644 index dcd404c3f786..000000000000 --- a/usr.bin/sort/pathnames.h +++ /dev/null @@ -1,41 +0,0 @@ -/* $NetBSD: pathnames.h,v 1.2 2000/10/07 18:37:10 bjh21 Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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. - * - * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 - */ - -#define _PATH_STDIN "/dev/stdin" diff --git a/usr.bin/sort/sort.1 b/usr.bin/sort/sort.1 deleted file mode 100644 index 65c6103168e8..000000000000 --- a/usr.bin/sort/sort.1 +++ /dev/null @@ -1,441 +0,0 @@ -.\" $NetBSD: sort.1,v 1.17 2001/12/08 19:16:07 wiz Exp $ -.\" -.\" Copyright (c) 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" the Institute of Electrical and Electronics Engineers, Inc. -.\" -.\" 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. -.\" -.\" @(#)sort.1 8.1 (Berkeley) 6/6/93 -.\" -.Dd January 13, 2001 -.Dt SORT 1 -.Os -.Sh NAME -.Nm sort -.Nd sort or merge text files -.Sh SYNOPSIS -.Nm sort -.Op Fl cmubdfHinrsS -.Op Fl t Ar char -.Op Fl R Ar char -.Oo -.Fl k -.Ar field1 Ns Op Li \&, Ns Ar field2 -.Oc -.Op Fl T Ar dir -.Op Fl o Ar output -.Op Ar -.Sh DESCRIPTION -The -.Nm -utility sorts text files by lines. -Comparisons are based on one or more sort keys extracted -from each line of input, and are performed lexicographically. -By default, if keys are not given, -.Nm -regards each input line as a single field. -.Pp -The following options are available: -.Bl -tag -width Fl -.It Fl c -Check that the single input file is sorted. -If the file is not sorted, -.Nm -produces the appropriate error messages and exits with code 1; otherwise, -.Nm -returns 0. -.Nm -.Fl c -produces no output. -.It Fl m -Merge only; the input files are assumed to be pre-sorted. -.It Fl o Ar output -The argument given is the name of an -.Ar output -file to be used instead of the standard output. -This file can be the same as one of the input files. -.It Fl T Ar dir -Use -.Ar dir -as the directory for temporary files. -The default is the value specified in the environment variable -.Ev TMPDIR or -.Pa /tmp -if -.Ev TMPDIR -is not defined. -.It Fl u -Unique: suppress all but one in each set of lines having equal keys. -If used with the -.Fl c -option, check that there are no lines with duplicate keys. -.El -.Pp -The following options override the default ordering rules. -When ordering options appear independent of key field -specifications, the requested field ordering rules are -applied globally to all sort keys. -When attached to a specific key (see -.Fl k ) , -the ordering options override -all global ordering options for that key. -.Bl -tag -width Fl -.It Fl d -Only blank space and alphanumeric characters -.\" according -.\" to the current setting of LC_CTYPE -are used -in making comparisons. -.It Fl f -Considers all lowercase characters that have uppercase -equivalents to be the same for purposes of comparison. -.It Fl i -Ignore all non-printable characters. -.It Fl n -An initial numeric string, consisting of optional blank space, optional -minus sign, and zero or more digits (including decimal point) -.\" with -.\" optional radix character and thousands -.\" separator -.\" (as defined in the current locale), -is sorted by arithmetic value. -(The -.Fl n -option no longer implies the -.Fl b -option.) -.It Fl r -Reverse the sense of comparisons. -.It Fl S -Don't use stable sort. -Default is to use stable sort. -.It Fl s -Use stable sort. -This is the default. -Provided for compatiblity with other -.Nm -implementations only. -.It Fl H -Use a merge sort instead of a radix sort. -This option should be used for files larger than 60Mb. -.El -.Pp -The treatment of field separators can be altered using these options: -.Bl -tag -width Fl -.It Fl b -Ignores leading blank space when determining the start -and end of a restricted sort key. -A -.Fl b -option specified before the first -.Fl k -option applies globally to all -.Fl k -options. -Otherwise, the -.Fl b -option can be attached independently to each -.Ar field -argument of the -.Fl k -option (see below). -Note that the -.Fl b -option has no effect unless key fields are specified. -.It Fl t Ar char -.Ar char -is used as the field separator character. -The initial -.Ar char -is not considered to be part of a field when determining -key offsets (see below). -Each occurrence of -.Ar char -is significant (for example, -.Dq Ar charchar -delimits an empty field). -If -.Fl t -is not specified, the default field separator is a sequence of -blank-space characters, and consecutive blank spaces do -.Em not -delimit an empty field; further, the initial blank space -.Em is -considered part of a field when determining key offsets. -.It Fl R Ar char -.Ar char -is used as the record separator character. -This should be used with discretion; -.Fl R Ar \*[Lt]alphanumeric\*[Gt] -usually produces undesirable results. -The default record separator is newline. -.It Xo -.Fl k -.Ar field1 Ns Op Li \&, Ns Ar field2 -.Xc -Designates the starting position, -.Ar field1 , -and optional ending position, -.Ar field2 , -of a key field. -The -.Fl k -option replaces the obsolescent options -.Cm \(pl Ns Ar pos1 -and -.Fl Ns Ar pos2 . -.El -.Pp -The following operands are available: -.Bl -tag -width Ar -.It Ar file -The pathname of a file to be sorted, merged, or checked. -If no -.Ar file -operands are specified, or if -a -.Ar file -operand is -.Fl , -the standard input is used. -.El -.Pp -A field is defined as a minimal sequence of characters followed by a -field separator or a newline character. -By default, the first -blank space of a sequence of blank spaces acts as the field separator. -All blank spaces in a sequence of blank spaces are considered -as part of the next field; for example, all blank spaces at -the beginning of a line are considered to be part of the -first field. -.Pp -Fields are specified -by the -.Fl k -.Ar field1 Ns Op \&, Ns Ar field2 -argument. -A missing -.Ar field2 -argument defaults to the end of a line. -.Pp -The arguments -.Ar field1 -and -.Ar field2 -have the form -.Ar m Ns Li \&. Ns Ar n -and can be followed by one or more of the letters -.Cm b , d , f , i , -.Cm n , -and -.Cm r , -which correspond to the options discussed above. -A -.Ar field1 -position specified by -.Ar m Ns Li \&. Ns Ar n -.Pq Ar m , n No \*[Gt] 0 -is interpreted as the -.Ar n Ns th -character in the -.Ar m Ns th -field. -A missing -.Li \&. Ns Ar n -in -.Ar field1 -means -.Ql \&.1 , -indicating the first character of the -.Ar m Ns th -field; if the -.Fl b -option is in effect, -.Ar n -is counted from the first non-blank character in the -.Ar m Ns th -field; -.Ar m Ns Li \&.1b -refers to the first non-blank character in the -.Ar m Ns th -field. -.Pp -A -.Ar field2 -position specified by -.Ar m Ns Li \&. Ns Ar n -is interpreted as -the -.Ar n Ns th -character (including separators) of the -.Ar m Ns th -field. -A missing -.Li \&. Ns Ar n -indicates the last character of the -.Ar m Ns th -field; -.Ar m -= \&0 -designates the end of a line. -Thus the option -.Fl k -.Sm off -.Xo -.Ar v Li \&. Ar x Li \&, -.Ar w Li \&. Ar y -.Xc -.Sm on -is synonymous with the obsolescent option -.Sm off -.Cm \(pl Ar v-\&1 Li \&. Ar x-\&1 -.Fl Ar w-\&1 Li \&. Ar y ; -.Sm on -when -.Ar y -is omitted, -.Fl k -.Sm off -.Ar v Li \&. Ar x Li \&, Ar w -.Sm on -is synonymous with -.Sm off -.Cm \(pl Ar v-\&1 Li \&. Ar x-\&1 -.Fl Ar w+1 Li \&.0 . -.Sm on -The obsolescent -.Cm \(pl Ns Ar pos1 -.Fl Ns Ar pos2 -option is still supported, except for -.Fl Ns Ar w Ns Li \&.0b , -which has no -.Fl k -equivalent. -.Sh RETURN VALUES -Sort exits with one of the following values: -.Bl -tag -width flag -compact -.It 0 -Normal behavior. -.It 1 -On disorder (or non-uniqueness) with the -.Fl c -option -.It 2 -An error occurred. -.El -.Sh ENVIRONMENT -If the following environment variable exists, it is utilized by -.Nm "" . -.Bl -tag -width Ev -.It Ev TMPDIR -.Nm -uses the contents of the -.Ev TMPDIR -environment variable as the path in which to store -temporary files. -.El -.Sh FILES -.Bl -tag -width outputNUMBER+some -compact -.It Pa /tmp/sort.* -Default temporary files. -.It Pa Ar output Ns NUMBER -Temporary file which is used for output if -.Ar output -already exists. -Once sorting is finished, this file replaces -.Ar output -(via -.Xr link 2 -and -.Xr unlink 2 ) . -.El -.Sh SEE ALSO -.Xr comm 1 , -.Xr join 1 , -.Xr uniq 1 , -.Xr qsort 3 , -.Xr radixsort 3 -.Sh HISTORY -A -.Nm -command appeared in -.At v5 . -This -.Nm -implementation appeared in -.Bx 4.4 -and is used since -.Nx 1.6 . -.Sh BUGS -To sort files larger than 60Mb, use -.Nm -.Fl H ; -files larger than 704Mb must be sorted in smaller pieces, then merged. -.Sh NOTES -This -.Nm -has no limits on input line length (other than imposed by available -memory) or any restrictions on bytes allowed within lines. -.Pp -To protect data -.Nm -.Fl o -calls -.Xr link 2 -and -.Xr unlink 2 , -and thus fails on protected directories. -.Pp -Input files should be text files. -If file doesn't end with record separator (which is typically newline), the -.Nm -utility silently supplies one. -.Pp -The current -.Nm -uses lexicographic radix sorting, which requires -that sort keys be kept in memory (as opposed to previous versions which used quick -and merge sorts and did not.) -Thus performance depends highly on efficient choice of sort keys, and the -.Fl b -option and the -.Ar field2 -argument of the -.Fl k -option should be used whenever possible. -Similarly, -.Nm -.Fl k1f -is equivalent to -.Nm -.Fl f -and may take twice as long. diff --git a/usr.bin/sort/sort.c b/usr.bin/sort/sort.c deleted file mode 100644 index 57e235762082..000000000000 --- a/usr.bin/sort/sort.c +++ /dev/null @@ -1,332 +0,0 @@ -/* $NetBSD: sort.c,v 1.26 2001/04/30 00:25:09 ross Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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. - */ - -/* Sort sorts a file using an optional user-defined key. - * Sort uses radix sort for internal sorting, and allows - * a choice of merge sort and radix sort for external sorting. - */ - -#include "sort.h" -#include "fsort.h" -#include "pathnames.h" - -#ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1993\n\ - The Regents of the University of California. All rights reserved.\n"); -#endif /* not lint */ - -#ifndef lint -__RCSID("$NetBSD: sort.c,v 1.26 2001/04/30 00:25:09 ross Exp $"); -__SCCSID("@(#)sort.c 8.1 (Berkeley) 6/6/93"); -#endif /* not lint */ - -#include <sys/types.h> -#include <sys/time.h> -#include <sys/resource.h> - -#include <paths.h> -#include <signal.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <locale.h> - -int REC_D = '\n'; -u_char d_mask[NBINS]; /* flags for rec_d, field_d, <blank> */ -/* - * weight tables. Gweights is one of ascii, Rascii.. - * modified to weight rec_d = 0 (or 255) - */ -u_char ascii[NBINS], Rascii[NBINS], RFtable[NBINS], Ftable[NBINS]; -int SINGL_FLD = 0, SEP_FLAG = 0, UNIQUE = 0; -struct coldesc clist[(ND+1)*2]; -int ncols = 0; -extern struct coldesc clist[(ND+1)*2]; -extern int ncols; - -/* - * Default to stable sort. - */ -int stable_sort = 1; - -char toutpath[MAXPATHLEN]; - -const char *tmpdir; /* where temporary files should be put */ - -static void cleanup __P((void)); -static void onsignal __P((int)); -static void usage __P((const char *)); -static void many_files __P((void)); - -int main __P((int argc, char **argv)); - -int -main(argc, argv) - int argc; - char *argv[]; -{ - get_func_t get; - int ch, i, stdinflag = 0, tmp = 0; - char cflag = 0, mflag = 0; - char *outfile, *outpath = 0; - struct field fldtab[ND+2], *ftpos; - struct filelist filelist; - FILE *outfp = NULL; - - setlocale(LC_ALL, ""); - - memset(fldtab, 0, (ND+2)*sizeof(struct field)); - memset(d_mask, 0, NBINS); - d_mask[REC_D = '\n'] = REC_D_F; - SINGL_FLD = SEP_FLAG = 0; - d_mask['\t'] = d_mask[' '] = BLANK | FLD_D; - ftpos = fldtab; - many_files(); - - fixit(&argc, argv); - if (!(tmpdir = getenv("TMPDIR"))) - tmpdir = _PATH_TMP; - - while ((ch = getopt(argc, argv, "bcdfik:mHno:rR:sSt:T:ux")) != -1) { - switch (ch) { - case 'b': - fldtab->flags |= BI | BT; - break; - case 'c': - cflag = 1; - break; - case 'd': case 'f': case 'i': case 'n': case 'r': - tmp |= optval(ch, 0); - if ((tmp & R) && (tmp & F)) - fldtab->weights = RFtable; - else if (tmp & F) - fldtab->weights = Ftable; - else if (tmp & R) - fldtab->weights = Rascii; - fldtab->flags |= tmp; - break; - case 'H': - PANIC = 0; - break; - case 'k': - setfield(optarg, ++ftpos, fldtab->flags); - break; - case 'm': - mflag = 1; - break; - case 'o': - outpath = optarg; - break; - case 's': - /* for GNU sort compatibility (this is our default) */ - stable_sort = 1; - break; - case 'S': - stable_sort = 0; - break; - case 't': - if (SEP_FLAG) - usage("multiple field delimiters"); - SEP_FLAG = 1; - d_mask[' '] &= ~FLD_D; - d_mask['\t'] &= ~FLD_D; - d_mask[(u_char)*optarg] |= FLD_D; - if (d_mask[(u_char)*optarg] & REC_D_F) - errx(2, "record/field delimiter clash"); - break; - case 'R': - if (REC_D != '\n') - usage("multiple record delimiters"); - if ('\n' == (REC_D = *optarg)) - break; - d_mask['\n'] = d_mask[' ']; - d_mask[REC_D] = REC_D_F; - break; - case 'T': - /* -T tmpdir */ - tmpdir = optarg; - break; - case 'u': - UNIQUE = 1; - break; - case '?': - default: - usage(NULL); - } - } - if (cflag && argc > optind+1) - errx(2, "too many input files for -c option"); - if (argc - 2 > optind && !strcmp(argv[argc-2], "-o")) { - outpath = argv[argc-1]; - argc -= 2; - } - if (mflag && argc - optind > (MAXFCT - (16+1))*16) - errx(2, "too many input files for -m option"); - for (i = optind; i < argc; i++) { - /* allow one occurrence of /dev/stdin */ - if (!strcmp(argv[i], "-") || !strcmp(argv[i], _PATH_STDIN)) { - if (stdinflag) - warnx("ignoring extra \"%s\" in file list", - argv[i]); - else - stdinflag = 1; - - /* change to /dev/stdin if '-' */ - if (argv[i][0] == '-') - argv[i] = _PATH_STDIN; - - } else if ((ch = access(argv[i], R_OK))) - err(2, "%s", argv[i]); - } - if (!(fldtab->flags & (I|D|N) || fldtab[1].icol.num)) { - SINGL_FLD = 1; - fldtab[0].icol.num = 1; - } else { - if (!fldtab[1].icol.num) { - fldtab[0].flags &= ~(BI|BT); - setfield("1", ++ftpos, fldtab->flags); - } - fldreset(fldtab); - fldtab[0].flags &= ~F; - } - settables(fldtab[0].flags); - num_init(); - fldtab->weights = gweights; - if (optind == argc) { - static const char * const names[] = { _PATH_STDIN, NULL }; - - filelist.names = names; - optind--; - } else - filelist.names = (const char * const *) &argv[optind]; - - if (SINGL_FLD) - get = makeline; - else - get = makekey; - - if (cflag) { - order(&filelist, get, fldtab); - /* NOT REACHED */ - } - if (!outpath) { - (void)snprintf(toutpath, - sizeof(toutpath), "%sstdout", _PATH_DEV); - outfile = outpath = toutpath; - outfp = stdout; - } else if (!(ch = access(outpath, 0)) && - strncmp(_PATH_DEV, outpath, 5)) { - static const struct sigaction act = - { onsignal, {{0}}, SA_RESTART | SA_RESETHAND }; - static const int sigtable[] = {SIGHUP, SIGINT, SIGPIPE, - SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF, 0}; - int outfd; - errno = 0; - if (access(outpath, W_OK)) - err(2, "%s", outpath); - (void)snprintf(toutpath, sizeof(toutpath), "%sXXXXXX", - outpath); - if ((outfd = mkstemp(toutpath)) == -1) - err(2, "Cannot create temporary file `%s'", toutpath); - if ((outfp = fdopen(outfd, "w")) == NULL) - err(2, "Cannot open temporary file `%s'", toutpath); - outfile = toutpath; - (void)atexit(cleanup); - for (i = 0; sigtable[i]; ++i) /* always unlink toutpath */ - sigaction(sigtable[i], &act, 0); - } else - outfile = outpath; - - if (outfp == NULL && (outfp = fopen(outfile, "w")) == NULL) - err(2, "output file %s", outfile); - - if (mflag) { - fmerge(-1, 0, &filelist, argc-optind, get, outfp, putline, - fldtab); - } else - fsort(-1, 0, 0, &filelist, argc-optind, outfp, fldtab); - - if (outfile != outpath) { - if (access(outfile, 0)) - err(2, "%s", outfile); - (void)unlink(outpath); - if (link(outfile, outpath)) - err(2, "cannot link %s: output left in %s", - outpath, outfile); - (void)unlink(outfile); - } - exit(0); -} - -static void -onsignal(sig) - int sig; -{ - cleanup(); -} - -static void -cleanup() -{ - if (toutpath[0]) - (void)unlink(toutpath); -} - -static void -usage(msg) - const char *msg; -{ - if (msg != NULL) - (void)fprintf(stderr, "sort: %s\n", msg); - (void)fprintf(stderr, "usage: [-o output] [-cmubdfinrsS] [-t char] "); - (void)fprintf(stderr, "[-R char] [-k keydef] ... [files]\n"); - exit(2); -} - -static void -many_files() -{ -#if 0 - struct rlimit rlp_many_files[1]; - - if (getrlimit(RLIMIT_NOFILE, rlp_many_files) == 0) { - rlp_many_files->rlim_cur = rlp_many_files->rlim_max; - setrlimit(RLIMIT_NOFILE, rlp_many_files); - } -#endif -} diff --git a/usr.bin/sort/sort.h b/usr.bin/sort/sort.h deleted file mode 100644 index 6e1169f8d4d8..000000000000 --- a/usr.bin/sort/sort.h +++ /dev/null @@ -1,149 +0,0 @@ -/* $NetBSD: sort.h,v 1.11 2001/01/19 10:14:31 jdolecek Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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. - * - * @(#)sort.h 8.1 (Berkeley) 6/6/93 - */ - -#include <sys/param.h> - -#include <db.h> -#include <err.h> -#include <errno.h> -#include <fcntl.h> -#include <limits.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#define NBINS 256 -#define MAXMERGE 16 - -/* values for masks, weights, and other flags. */ -#define I 1 /* mask out non-printable characters */ -#define D 2 /* sort alphanumeric characters only */ -#define N 4 /* Field is a number */ -#define F 8 /* weight lower and upper case the same */ -#define R 16 /* Field is reversed with respect to the global weight */ -#define BI 32 /* ignore blanks in icol */ -#define BT 64 /* ignore blanks in tcol */ - -/* masks for delimiters: blanks, fields, and termination. */ -#define BLANK 1 /* ' ', '\t'; '\n' if -T is invoked */ -#define FLD_D 2 /* ' ', '\t' default; from -t otherwise */ -#define REC_D_F 4 /* '\n' default; from -T otherwise */ - -#define ND 10 /* limit on number of -k options. */ - -#define min(a, b) ((a) < (b) ? (a) : (b)) -#define max(a, b) ((a) > (b) ? (a) : (b)) - -#define FCLOSE(file) { \ - if (EOF == fclose(file)) \ - err(2, "%p", file); \ -} - -#define EWRITE(ptr, size, n, f) { \ - if (!fwrite(ptr, size, n, f)) \ - err(2, NULL); \ -} - -/* length of record is currently limited to maximum string length (size_t) */ -typedef size_t length_t; - -/* a record is a key/line pair starting at rec.data. It has a total length - * and an offset to the start of the line half of the pair. - */ -typedef struct recheader { - length_t length; - length_t offset; - u_char data[1]; -} RECHEADER; - -typedef struct trecheader { - length_t length; - length_t offset; -} TRECHEADER; - -/* This is the column as seen by struct field. It is used by enterfield. - * They are matched with corresponding coldescs during initialization. - */ -struct column { - struct coldesc *p; - int num; - int indent; -}; - -/* a coldesc has a number and pointers to the beginning and end of the - * corresponding column in the current line. This is determined in enterkey. - */ -typedef struct coldesc { - u_char *start; - u_char *end; - int num; -} COLDESC; - -/* A field has an initial and final column; an omitted final column - * implies the end of the line. Flags regulate omission of blanks and - * numerical sorts; mask determines which characters are ignored (from -i, -d); - * weights determines the sort weights of a character (from -f, -r). - */ -struct field { - struct column icol; - struct column tcol; - u_int flags; - u_char *mask; - u_char *weights; -}; - -struct filelist { - const char * const * names; -}; - -typedef int (*get_func_t) __P((int, int, struct filelist *, int, - RECHEADER *, u_char *, struct field *)); -typedef void (*put_func_t) __P((const struct recheader *, FILE *)); - -extern int PANIC; /* maximum depth of fsort before fmerge is called */ -extern u_char ascii[NBINS], Rascii[NBINS], Ftable[NBINS], RFtable[NBINS]; -extern u_char d_mask[NBINS]; -extern int SINGL_FLD, SEP_FLAG, UNIQUE; -extern int REC_D; -extern const char *tmpdir; -extern int stable_sort; -extern u_char gweights[NBINS]; - -#include "extern.h" diff --git a/usr.bin/sort/tmp.c b/usr.bin/sort/tmp.c deleted file mode 100644 index 55ca383dc58c..000000000000 --- a/usr.bin/sort/tmp.c +++ /dev/null @@ -1,84 +0,0 @@ -/* $NetBSD: tmp.c,v 1.7 2001/02/19 15:45:45 jdolecek Exp $ */ - -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Peter McIlroy. - * - * 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. - */ - -#include <ctype.h> - -#ifndef lint -__RCSID("$NetBSD: tmp.c,v 1.7 2001/02/19 15:45:45 jdolecek Exp $"); -__SCCSID("@(#)tmp.c 8.1 (Berkeley) 6/6/93"); -#endif /* not lint */ - -#include <sys/param.h> - -#include <err.h> -#include <errno.h> -#include <limits.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "sort.h" -#include "pathnames.h" - -#define _NAME_TMP "sort.XXXXXXXX" - -FILE * -ftmp() -{ - sigset_t set, oset; - FILE *fp; - int fd; - char pathb[MAXPATHLEN], *path; - - path = pathb; - (void)snprintf(path, sizeof(pathb), "%s%s%s", tmpdir, - (tmpdir[strlen(tmpdir)-1] != '/') ? "/" : "", _NAME_TMP); - - sigfillset(&set); - (void)sigprocmask(SIG_BLOCK, &set, &oset); - if ((fd = mkstemp(path)) < 0) - err(2, "ftmp: mkstemp(\"%s\")", path); - if (!(fp = fdopen(fd, "w+"))) - err(2, "ftmp: fdopen(\"%s\")", path); - (void)unlink(path); - - (void)sigprocmask(SIG_SETMASK, &oset, NULL); - return (fp); -} diff --git a/usr.bin/stat/Makefile b/usr.bin/stat/Makefile deleted file mode 100644 index 0c95721859c0..000000000000 --- a/usr.bin/stat/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $FreeBSD$ - -PROG= stat -MAN= stat.1 -SRCS= stat.c -WARNS?= 2 - -.include <bsd.prog.mk> diff --git a/usr.bin/stat/stat.1 b/usr.bin/stat/stat.1 deleted file mode 100644 index cd238233e1f3..000000000000 --- a/usr.bin/stat/stat.1 +++ /dev/null @@ -1,434 +0,0 @@ -.\" $NetBSD: stat.1,v 1.4 2002/05/09 17:52:03 atatat Exp $ -.\" -.\" Copyright (c) 2002 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" -.\" This code is derived from software contributed to The NetBSD Foundation -.\" by Andrew Brown and Jan Schaumann. -.\" -.\" 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 NetBSD -.\" Foundation, Inc. and its contributors. -.\" 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. -.\" -.\" $FreeBSD$ -.\" -.Dd April 24, 2002 -.Dt STAT 1 -.Os -.Sh NAME -.Nm stat -.Nd display file status -.Sh SYNOPSIS -.Nm -.Op Fl FLn -.Oo -.Fl f Ar format | -.Fl l | -.Fl r | -.Fl s | -.Fl x -.Oc -.Op Fl t Ar timefmt -.Op Ar -.Sh DESCRIPTION -The -.Nm -utility displays information about the file pointed to by -.Ar file . -Read, write or execute permissions of the named file are not required, but -all directories listed in the path name leading to the file must be -searchable. If no argument is given, -.Nm -displays information about the file descriptor for standard input. -.Pp -The information displayed is obtained by calling -.Xr lstat 2 -with the given argument and evaluating the returned structure. -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl F -As in -.Ic ls , -display a slash (/) immediately after each pathname that is a directory, an -asterisk (*) after each that is executable, an at sign (@) after each symbolic -link, a percent sign (%) after each whiteout, an equal sign (=) after each -socket, and a vertical bar (|) after each that is a FIFO. The use of -.Fl F -implies -.Fl l . -.It Fl L -Use -.Xr stat 2 -instead of -.Xr lstat 2 . -The information reported by -.Nm -will refer to the target of -.Ar file , -if file is a symbolic link, and not to -.Ar file -itself. -.It Fl n -Do not force a newline to appear at the end of each piece of output. -.It Fl f Ar format -Display information using the specified format. See the FORMATS section -for a description of valid formats. -.It Fl l -Display output in -.Ic ls Fl lT -format. -.It Fl r -Display raw information. That is, for all the fields in the stat-structure, -display the raw, numerical value (for example, times in seconds since the -epoch, etc.) -.It Fl s -Display information in ``shell output'', suitable for initializing variables. -.It Fl x -Display information in a more verbose way as known from some Linux -distributions. -.It Fl t Ar timefmt -Display timestamps using the specified format. This format is -passed directly to -.Xr strftime 3 . -.El -.Ss FORMATS -Format strings are similar to -.Xr printf 3 -formats in that they start with -.Cm % , -are then followed by a sequence of formatting characters, and end in -a character that selects the field of the struct stat which is to be -formatted. If the -.Cm % -is immediately followed by one of -.Cm n , -.Cm t , -.Cm % , -or -.Cm @ , -then a newline character, a tab character, a percent character, -or the current file number is printed, otherwise the string is -examined for the following: -.Pp -Any of the following optional flags: -.Bl -tag -width Ds -.It Cm # -Selects an alternate output form for octal and hexadecimal output. -Non-zero octal output will have a leading zero, and non-zero -hexadecimal output will have ``0x'' prepended to it. -.It Cm + -Asserts that a sign indicating whether a number is positive or negative -should always be printed. Non-negative numbers are not usually printed -with a sign. -.It Cm - -Aligns string output to the left of the field, instead of to the right. -.It Cm 0 -Sets the fill character for left padding to the 0 character, instead of -a space. -.It space -Reserves a space at the front of non-negative signed output fields. A -.Sq Cm + -overrides a space if both are used. -.El -.Pp -Then the following fields: -.Bl -tag -width Ds -.It Cm size -An optional decimal digit string specifying the minimum field width. -.It Cm prec -An optional precision composed of a decimal point -.Sq Cm \&. -and a decimal digit string that indicates the maximum string length, -the number of digits to appear after the decimal point in floating point -output, or the minimum number of digits to appear in numeric output. -.It Cm fmt -An optional output format specifier which is one of -.Cm D , -.Cm O , -.Cm U , -.Cm X , -.Cm F , -or -.Cm S . -These represent signed decimal output, octal output, unsigned decimal -output, hexadecimal output, floating point output, and string output, -respectively. Some output formats do not apply to all fields. -Floating point output only applies to timespec fields (the -.Cm a , -.Cm m , -and -.Cm c -fields). -.Pp -The special output specifier -.Cm S -may be used to indicate that the output, if -applicable, should be in string format. May be used in combination with -.Bl -tag -width Ds -.It Cm amc -Display date in strftime(3) format. -.It Cm dr -Display actual device name. -.It Cm gu -Display group or user name. -.It Cm p -Display the mode of -.Ar file -as in -.Ic ls -lTd . -.It Cm N -Displays the name of -.Ar file . -.It Cm T -Displays the type of -.Ar file . -.It Cm Y -Insert a `` -\*[Gt] '' into the output. Note that the default output format -for -.Cm Y -is a string, but if specified explicitly, these four characters are -prepended. -.El -.It Cm sub -An optional sub field specifier (high, middle, low). Only applies to -the -.Cm p , -.Cm d , -.Cm r , -and -.Cm T -output formats. It can be one of the following: -.Bl -tag -width Ds -.It Cm H -``High'' -- specifies the major number for devices from -.Cm r -or -.Cm d , -the ``user'' bits for permissions from the string form of -.Cm p , -the file ``type'' bits from the numeric forms of -.Cm p , -and the long output form of -.Cm T . -.It Cm L -``Low'' -- specifies the minor number for devices from -.Cm r -or -.Cm d , -the ``other'' bits for permissions from the string form of -.Cm p , -the ``user'', ``group'', and ``other'' bits from the numeric forms of -.Cm p , -and the -.Ic ls -F -style output character for file type when used with -.Cm T -(the use of -.Cm L -for this is optional). -.It Cm M -``Middle'' -- specifies the ``group'' bits for permissions from the -string output form of -.Cm p , -or the ``suid'', ``sgid'', and ``sticky'' bits for the numeric forms of -.Cm p . -.El -.It Cm datum -A required field specifier, being one of the following: -.Bl -tag -width Ds -.It Cm d -Device upon which -.Ar file -resides. -.It Cm i -.Ar file Ap s -inode number. -.It Cm p -File type and permissions. -.It Cm l -Number of hard links to -.Ar file . -.It Cm u , g -User-id and group-id of -.Ar file Ap s -owner. -.It Cm r -Device number for character and block device special files. -.It Cm a , m , c -The time -.Ar file -was last accessed, modified, or of when the inode was last changed. -.It Cm z -The size of -.Ar file -in bytes. -.It Cm b -Number of blocks allocated for -.Ar file . -.It Cm k -Optimal file system I/O operation block size. -.It Cm f -User defined flags for -.Ar file . -.It Cm v -Inode generation number. -.El -.Pp -The following four field specifiers are not drawn directly from the -data in struct stat, but are -.Bl -tag -width Ds -.It Cm N -The name of the file. -.It Cm T -The file type, either as in -.Ic ls -F -or in a more descriptive form if the sub field specifier -.Cm H -is given. -.It Cm Y -The target of a symbolic link. -.It Cm Z -Expands to ``major,minor'' from the rdev field for character or block -special devices and gives size output for all others. -.El -.El -.Pp -Only the -.Cm % -and the field specifier are required. Most field -specifiers default to -.Cm U -as an output form, with the -exception of -.Cm p -which defaults to -.Cm O , -.Cm a , m , -and -.Cm c -which default to -.Cm D , -and -.Cm Y , T , -and -.Cm N , -which default to -.Cm S . -.Sh EXIT STATUS -.Nm -exits 0 on success, and \*[Gt]0 if an error occurred. -.Sh EXAMPLES -Given a symbolic link ``foo'' that points from /tmp/foo to /, you would use -.Nm -as follows: -.Bd -literal -offset indent -\*[Gt] stat -F /tmp/foo -lrwxrwxrwx 1 jschauma cs 1 Apr 24 16:37:28 2002 /tmp/foo@ -\*[Gt] / - -\*[Gt] stat -LF /tmp/foo -lrwxrwxrwx 16 root wheel 512 Apr 19 10:57:54 2002 /tmp/foo/ -.Ed -.Pp -To initialize some shell-variables, you could use the -.Fl s -flag as follows: -.Bd -literal -offset indent -\*[Gt] csh -% eval set `stat -s .cshrc` -% echo $st_size $st_mtimespec -1148 1015432481 - -\*[Gt] sh -$ eval $(stat -s .profile) -$ echo $st_size $st_mtimespec -1148 1015432481 -.Ed -.Pp -In order to get a list of the kind of files including files pointed to if the -file is a symbolic link, you could use the following format: -.Bd -literal -offset indent -$ stat -f "%N: %HT%SY" /tmp/* -/tmp/bar: Symbolic Link -\*[Gt] /tmp/foo -/tmp/output25568: Regular File -/tmp/blah: Directory -/tmp/foo: Symbolic Link -\*[Gt] / -.Ed -.Pp -In order to get a list of the devices, their types and the major and minor -device numbers, formatted with tabs and linebreaks, you could use the -following format: -.Bd -literal -offset indent -stat -f "Name: %N%n%tType: %HT%n%tMajor: %Hr%n%tMinor: %Lr%n%n" /dev/* -[...] -Name: /dev/wt8 - Type: Block Device - Major: 3 - Minor: 8 - -Name: /dev/zero - Type: Character Device - Major: 2 - Minor: 12 -.Ed -.Pp -In order to determine the permissions set on a file separately, you could use -the following format: -.Bd -literal -offset indent -\*[Gt] stat -f "%Sp -\*[Gt] owner=%SHp group=%SMp other=%SLp" . -drwxr-xr-x -\*[Gt] owner=rwx group=r-x other=r-x -.Ed -.Pp -In order to determine the three files that have been modified most recently, -you could use the following format: -.Bd -literal -offset indent -\*[Gt] stat -f "%m%t%Sm %N" /tmp/* | sort -rn | head -3 | cut -f2- -Apr 25 11:47:00 2002 /tmp/blah -Apr 25 10:36:34 2002 /tmp/bar -Apr 24 16:47:35 2002 /tmp/foo -.Ed -.Sh SEE ALSO -.Xr file 1 , -.Xr ls 1 , -.Xr lstat 2 , -.Xr readlink 2 , -.Xr stat 2 , -.Xr printf 3 , -.Xr strftime 3 -.Sh HISTORY -The -.Nm -utility appeared in -.Nx 1.6 . -.Sh AUTHORS -The -.Nm -utility was written by Andrew Brown -.Aq atatat@netbsd.org . -This man page -was written by Jan Schaumann -.Aq jschauma@netbsd.org . diff --git a/usr.bin/stat/stat.c b/usr.bin/stat/stat.c deleted file mode 100644 index d8810eeaf115..000000000000 --- a/usr.bin/stat/stat.c +++ /dev/null @@ -1,891 +0,0 @@ -/* $NetBSD: stat.c,v 1.3 2002/05/31 16:45:16 atatat Exp $ */ - -/* - * Copyright (c) 2002 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Andrew Brown. - * - * 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 NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. - */ - -#include <sys/cdefs.h> -#ifndef lint -__RCSID("$NetBSD: stat.c,v 1.3 2002/05/31 16:45:16 atatat Exp $"); -__FBSDID("$FreeBSD$"); -#endif - -#include <sys/types.h> -#include <sys/param.h> -#include <sys/stat.h> -#include <unistd.h> -#include <err.h> -#include <string.h> -#include <stdio.h> -#include <ctype.h> -#include <stddef.h> -#include <stdlib.h> -#include <pwd.h> -#include <grp.h> - -#define DEF_FORMAT \ - "%d %i %Sp %l %Su %Sg %r %z \"%Sa\" \"%Sm\" \"%Sc\" %k %b %N" -#define RAW_FORMAT "%d %i %#p %l %u %g %r %z %a %m %c %k %b %N" -#define LS_FORMAT "%Sp %l %Su %Sg %Z %Sm %N%SY" -#define LSF_FORMAT "%Sp %l %Su %Sg %Z %Sm %N%T%SY" -#define SHELL_FORMAT \ - "st_dev=%d st_ino=%i st_mode=%#p st_nlink=%l " \ - "st_uid=%u st_gid=%g st_rdev=%r st_size=%z " \ - "st_atimespec=%a st_mtimespec=%m st_ctimespec=%c " \ - "st_blksize=%k st_blocks=%b" -#define LINUX_FORMAT \ - " File: \"%N\"%n" \ - " Size: %-11z FileType: %HT%n" \ - " Mode: (%04OLp/%.10Sp) Uid: (%5u/%8Su) Gid: (%5g/%8Sg)%n" \ - "Device: %Hd,%Ld Inode: %i Links: %l%n" \ - "Access: %Sa%n" \ - "Modify: %Sm%n" \ - "Change: %Sc" - -#define TIME_FORMAT "%b %e %T %Y" - -#define FLAG_POUND 0x01 -#define FLAG_SPACE 0x02 -#define FLAG_PLUS 0x04 -#define FLAG_ZERO 0x08 -#define FLAG_MINUS 0x10 - -/* - * These format characters must all be unique, except the magic one. - */ -#define FMT_MAGIC '%' -#define FMT_DOT '.' - -#define SIMPLE_NEWLINE 'n' -#define SIMPLE_TAB 't' -#define SIMPLE_PERCENT '%' -#define SIMPLE_NUMBER '@' - -#define FMT_POUND '#' -#define FMT_SPACE ' ' -#define FMT_PLUS '+' -#define FMT_ZERO '0' -#define FMT_MINUS '-' - -#define FMT_DECIMAL 'D' -#define FMT_OCTAL 'O' -#define FMT_UNSIGNED 'U' -#define FMT_HEX 'X' -#define FMT_FLOAT 'F' -#define FMT_STRING 'S' - -#define HIGH_PIECE 'H' -#define MIDDLE_PIECE 'M' -#define LOW_PIECE 'L' - -#define SHOW_st_dev 'd' -#define SHOW_st_ino 'i' -#define SHOW_st_mode 'p' -#define SHOW_st_nlink 'l' -#define SHOW_st_uid 'u' -#define SHOW_st_gid 'g' -#define SHOW_st_rdev 'r' -#define SHOW_st_atime 'a' -#define SHOW_st_mtime 'm' -#define SHOW_st_ctime 'c' -#define SHOW_st_size 'z' -#define SHOW_st_blocks 'b' -#define SHOW_st_blksize 'k' -#define SHOW_st_flags 'f' -#define SHOW_st_gen 'v' -#define SHOW_symlink 'Y' -#define SHOW_filetype 'T' -#define SHOW_filename 'N' -#define SHOW_sizerdev 'Z' - -void usage(void); -void output(const struct stat *, const char *, - const char *, int, int); -int format1(const struct stat *, /* stat info */ - const char *, /* the file name */ - const char *, int, /* the format string itself */ - char *, size_t, /* a place to put the output */ - int, int, int, int, /* the parsed format */ - int, int); - -char *timefmt; - -#define addchar(b, n, l, c, nl) \ - do { \ - if ((*(n)) < (l)) { \ - (b)[(*(n))++] = (c); \ - (*nl) = ((c) == '\n'); \ - } \ - } while (0/*CONSTCOND*/) - -int -main(int argc, char *argv[]) -{ - struct stat st; - int ch, rc, errs; - int lsF, fmtchar, usestat, fn, nonl; - char *statfmt; - - lsF = 0; - fmtchar = '\0'; - usestat = 0; - nonl = 0; - statfmt = NULL; - timefmt = NULL; - - while ((ch = getopt(argc, argv, "f:FlLnrst:x")) != -1) - switch (ch) { - case 'F': - lsF = 1; - break; - case 'L': - usestat = 1; - break; - case 'n': - nonl = 1; - break; - case 'f': - statfmt = optarg; - /* FALLTHROUGH */ - case 'l': - case 'r': - case 's': - case 'x': - if (fmtchar != 0) - errx(1, "can't use format '%c' with '%c'", - fmtchar, ch); - fmtchar = ch; - break; - case 't': - timefmt = optarg; - break; - default: - usage(); - } - - argc -= optind; - argv += optind; - fn = 1; - - if (fmtchar == '\0') { - if (lsF) - fmtchar = 'l'; - else { - fmtchar = 'f'; - statfmt = DEF_FORMAT; - } - } - - if (lsF && fmtchar != 'l') - errx(1, "can't use format '%c' with -F", fmtchar); - - switch (fmtchar) { - case 'f': - /* statfmt already set */ - break; - case 'l': - statfmt = lsF ? LSF_FORMAT : LS_FORMAT; - break; - case 'r': - statfmt = RAW_FORMAT; - break; - case 's': - statfmt = SHELL_FORMAT; - break; - case 'x': - statfmt = LINUX_FORMAT; - if (timefmt == NULL) - timefmt = "%c"; - break; - default: - usage(); - /*NOTREACHED*/ - } - - if (timefmt == NULL) - timefmt = TIME_FORMAT; - - errs = 0; - do { - if (argc == 0) - rc = fstat(STDIN_FILENO, &st); - else if (usestat) - rc = stat(argv[0], &st); - else - rc = lstat(argv[0], &st); - - if (rc == -1) { - errs = 1; - warn("%s: stat", argc == 0 ? "(stdin)" : argv[0]); - } - else - output(&st, argv[0], statfmt, fn, nonl); - - argv++; - argc--; - fn++; - } while (argc > 0); - - return (errs); -} - -void -usage(void) -{ - - (void)fprintf(stderr, - "usage: %s [-FlLnrsx] [-f format] [-t timefmt] [file ...]\n", - getprogname()); - exit(1); -} - -/* - * Parses a format string. - */ -void -output(const struct stat *st, const char *file, - const char *statfmt, int fn, int nonl) -{ - int flags, size, prec, ofmt, hilo, what; - char buf[4096], subbuf[MAXPATHLEN]; - const char *subfmt; - int nl, t, i; - size_t len; - - len = 0; - while (*statfmt != '\0') { - - /* - * Non-format characters go straight out. - */ - if (*statfmt != FMT_MAGIC) { - addchar(buf, &len, sizeof(buf), *statfmt, &nl); - statfmt++; - continue; - } - - /* - * The current format "substring" starts here, - * and then we skip the magic. - */ - subfmt = statfmt; - statfmt++; - - /* - * Some simple one-character "formats". - */ - switch (*statfmt) { - case SIMPLE_NEWLINE: - addchar(buf, &len, sizeof(buf), '\n', &nl); - statfmt++; - continue; - case SIMPLE_TAB: - addchar(buf, &len, sizeof(buf), '\t', &nl); - statfmt++; - continue; - case SIMPLE_PERCENT: - addchar(buf, &len, sizeof(buf), '%', &nl); - statfmt++; - continue; - case SIMPLE_NUMBER: { - char num[12], *p; - - snprintf(num, sizeof(num), "%d", fn); - for (p = &num[0]; *p; p++) - addchar(buf, &len, sizeof(buf), *p, &nl); - statfmt++; - continue; - } - } - - /* - * This must be an actual format string. Format strings are - * similar to printf(3) formats up to a point, and are of - * the form: - * - * % required start of format - * [-# +0] opt. format characters - * size opt. field width - * . opt. decimal separator, followed by - * prec opt. precision - * fmt opt. output specifier (string, numeric, etc.) - * sub opt. sub field specifier (high, middle, low) - * datum required field specifier (size, mode, etc) - * - * Only the % and the datum selector are required. All data - * have reasonable default output forms. The "sub" specifier - * only applies to certain data (mode, dev, rdev, filetype). - * The symlink output defaults to STRING, yet will only emit - * the leading " -> " if STRING is explicitly specified. The - * sizerdev datum will generate rdev output for character or - * block devices, and size output for all others. - */ - flags = 0; - do { - if (*statfmt == FMT_POUND) - flags |= FLAG_POUND; - else if (*statfmt == FMT_SPACE) - flags |= FLAG_SPACE; - else if (*statfmt == FMT_PLUS) - flags |= FLAG_PLUS; - else if (*statfmt == FMT_ZERO) - flags |= FLAG_ZERO; - else if (*statfmt == FMT_MINUS) - flags |= FLAG_MINUS; - else - break; - statfmt++; - } while (1/*CONSTCOND*/); - - size = -1; - if (isdigit((unsigned)*statfmt)) { - size = 0; - while (isdigit((unsigned)*statfmt)) { - size = (size * 10) + (*statfmt - '0'); - statfmt++; - if (size < 0) - goto badfmt; - } - } - - prec = -1; - if (*statfmt == FMT_DOT) { - statfmt++; - - prec = 0; - while (isdigit((unsigned)*statfmt)) { - prec = (prec * 10) + (*statfmt - '0'); - statfmt++; - if (prec < 0) - goto badfmt; - } - } - -#define fmtcase(x, y) case (y): (x) = (y); statfmt++; break - switch (*statfmt) { - fmtcase(ofmt, FMT_DECIMAL); - fmtcase(ofmt, FMT_OCTAL); - fmtcase(ofmt, FMT_UNSIGNED); - fmtcase(ofmt, FMT_HEX); - fmtcase(ofmt, FMT_FLOAT); - fmtcase(ofmt, FMT_STRING); - default: - ofmt = 0; - break; - } - - switch (*statfmt) { - fmtcase(hilo, HIGH_PIECE); - fmtcase(hilo, MIDDLE_PIECE); - fmtcase(hilo, LOW_PIECE); - default: - hilo = 0; - break; - } - - switch (*statfmt) { - fmtcase(what, SHOW_st_dev); - fmtcase(what, SHOW_st_ino); - fmtcase(what, SHOW_st_mode); - fmtcase(what, SHOW_st_nlink); - fmtcase(what, SHOW_st_uid); - fmtcase(what, SHOW_st_gid); - fmtcase(what, SHOW_st_rdev); - fmtcase(what, SHOW_st_atime); - fmtcase(what, SHOW_st_mtime); - fmtcase(what, SHOW_st_ctime); - fmtcase(what, SHOW_st_size); - fmtcase(what, SHOW_st_blocks); - fmtcase(what, SHOW_st_blksize); - fmtcase(what, SHOW_st_flags); - fmtcase(what, SHOW_st_gen); - fmtcase(what, SHOW_symlink); - fmtcase(what, SHOW_filetype); - fmtcase(what, SHOW_filename); - fmtcase(what, SHOW_sizerdev); - default: - goto badfmt; - } -#undef fmtcase - - t = format1(st, - file, - subfmt, statfmt - subfmt, - subbuf, sizeof(subbuf), - flags, size, prec, ofmt, hilo, what); - - for (i = 0; i < t && i < sizeof(subbuf); i++) - addchar(buf, &len, sizeof(buf), subbuf[i], &nl); - - continue; - - badfmt: - errx(1, "%.*s: bad format", - (int)(statfmt - subfmt + 1), subfmt); - } - - (void)write(STDOUT_FILENO, buf, len); - if (!nl && !nonl) - (void)write(STDOUT_FILENO, "\n", sizeof("\n") - 1); -} - -/* - * Arranges output according to a single parsed format substring. - */ -int -format1(const struct stat *st, - const char *file, - const char *fmt, int flen, - char *buf, size_t blen, - int flags, int size, int prec, int ofmt, - int hilo, int what) -{ - u_int64_t data; - char *sdata, lfmt[24], tmp[20]; - char smode[12], sid[12], path[MAXPATHLEN + 4]; - struct passwd *pw; - struct group *gr; - const struct timespec *tsp; - struct timespec ts; - struct tm *tm; - int l, small, formats; - - tsp = NULL; - formats = 0; - small = 0; - - /* - * First, pick out the data and tweak it based on hilo or - * specified output format (symlink output only). - */ - switch (what) { - case SHOW_st_dev: - case SHOW_st_rdev: - small = (sizeof(st->st_dev) == 4); - data = (what == SHOW_st_dev) ? st->st_dev : st->st_rdev; - sdata = (what == SHOW_st_dev) ? - devname(st->st_dev, S_IFBLK) : - devname(st->st_rdev, - S_ISCHR(st->st_mode) ? S_IFCHR : - S_ISBLK(st->st_mode) ? S_IFBLK : - 0U); - if (sdata == NULL) - sdata = "???"; - if (hilo == HIGH_PIECE) { - data = major(data); - hilo = 0; - } - else if (hilo == LOW_PIECE) { - data = minor((unsigned)data); - hilo = 0; - } - formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX | - FMT_STRING; - if (ofmt == 0) - ofmt = FMT_UNSIGNED; - break; - case SHOW_st_ino: - small = (sizeof(st->st_ino) == 4); - data = st->st_ino; - sdata = NULL; - formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX; - if (ofmt == 0) - ofmt = FMT_UNSIGNED; - break; - case SHOW_st_mode: - small = (sizeof(st->st_mode) == 4); - data = st->st_mode; - strmode(st->st_mode, smode); - sdata = smode; - l = strlen(sdata); - if (sdata[l - 1] == ' ') - sdata[--l] = '\0'; - if (hilo == HIGH_PIECE) { - data >>= 12; - sdata += 1; - sdata[3] = '\0'; - hilo = 0; - } - else if (hilo == MIDDLE_PIECE) { - data = (data >> 9) & 07; - sdata += 4; - sdata[3] = '\0'; - hilo = 0; - } - else if (hilo == LOW_PIECE) { - data &= 0777; - sdata += 7; - sdata[3] = '\0'; - hilo = 0; - } - formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX | - FMT_STRING; - if (ofmt == 0) - ofmt = FMT_OCTAL; - break; - case SHOW_st_nlink: - small = (sizeof(st->st_dev) == 4); - data = st->st_nlink; - sdata = NULL; - formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX; - if (ofmt == 0) - ofmt = FMT_UNSIGNED; - break; - case SHOW_st_uid: - small = (sizeof(st->st_uid) == 4); - data = st->st_uid; - if ((pw = getpwuid(st->st_uid)) != NULL) - sdata = pw->pw_name; - else { - snprintf(sid, sizeof(sid), "(%ld)", (long)st->st_uid); - sdata = sid; - } - formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX | - FMT_STRING; - if (ofmt == 0) - ofmt = FMT_UNSIGNED; - break; - case SHOW_st_gid: - small = (sizeof(st->st_gid) == 4); - data = st->st_gid; - if ((gr = getgrgid(st->st_gid)) != NULL) - sdata = gr->gr_name; - else { - snprintf(sid, sizeof(sid), "(%ld)", (long)st->st_gid); - sdata = sid; - } - formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX | - FMT_STRING; - if (ofmt == 0) - ofmt = FMT_UNSIGNED; - break; - case SHOW_st_atime: - tsp = &st->st_atimespec; - /* FALLTHROUGH */ - case SHOW_st_mtime: - if (tsp == NULL) - tsp = &st->st_mtimespec; - /* FALLTHROUGH */ - case SHOW_st_ctime: - if (tsp == NULL) - tsp = &st->st_ctimespec; - ts = *tsp; /* copy so we can muck with it */ - small = (sizeof(ts.tv_sec) == 4); - data = ts.tv_sec; - small = 1; - tm = localtime(&ts.tv_sec); - (void)strftime(path, sizeof(path), timefmt, tm); - sdata = path; - formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX | - FMT_FLOAT | FMT_STRING; - if (ofmt == 0) - ofmt = FMT_DECIMAL; - break; - case SHOW_st_size: - small = (sizeof(st->st_size) == 4); - data = st->st_size; - sdata = NULL; - formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX; - if (ofmt == 0) - ofmt = FMT_UNSIGNED; - break; - case SHOW_st_blocks: - small = (sizeof(st->st_blocks) == 4); - data = st->st_blocks; - sdata = NULL; - formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX; - if (ofmt == 0) - ofmt = FMT_UNSIGNED; - break; - case SHOW_st_blksize: - small = (sizeof(st->st_blksize) == 4); - data = st->st_blksize; - sdata = NULL; - formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX; - if (ofmt == 0) - ofmt = FMT_UNSIGNED; - break; - case SHOW_st_flags: - small = (sizeof(st->st_flags) == 4); - data = st->st_flags; - sdata = NULL; - formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX; - if (ofmt == 0) - ofmt = FMT_UNSIGNED; - break; - case SHOW_st_gen: - small = (sizeof(st->st_gen) == 4); - data = st->st_gen; - sdata = NULL; - formats = FMT_DECIMAL | FMT_OCTAL | FMT_UNSIGNED | FMT_HEX; - if (ofmt == 0) - ofmt = FMT_UNSIGNED; - break; - case SHOW_symlink: - small = 0; - data = 0; - if (S_ISLNK(st->st_mode)) { - snprintf(path, sizeof(path), " -> "); - l = readlink(file, path + 4, sizeof(path) - 4); - if (l == -1) { - l = 0; - path[0] = '\0'; - } - path[l + 4] = '\0'; - sdata = path + (ofmt == FMT_STRING ? 0 : 4); - } - else - sdata = ""; - formats = FMT_STRING; - if (ofmt == 0) - ofmt = FMT_STRING; - break; - case SHOW_filetype: - small = 0; - data = 0; - sdata = smode; - sdata[0] = '\0'; - if (hilo == 0 || hilo == LOW_PIECE) { - switch (st->st_mode & S_IFMT) { - case S_IFIFO: (void)strcat(sdata, "|"); break; - case S_IFDIR: (void)strcat(sdata, "/"); break; - case S_IFREG: - if (st->st_mode & - (S_IXUSR | S_IXGRP | S_IXOTH)) - (void)strcat(sdata, "*"); - break; - case S_IFLNK: (void)strcat(sdata, "@"); break; - case S_IFSOCK: (void)strcat(sdata, "="); break; - case S_IFWHT: (void)strcat(sdata, "%"); break; - } - hilo = 0; - } - else if (hilo == HIGH_PIECE) { - switch (st->st_mode & S_IFMT) { - case S_IFIFO: sdata = "Fifo File"; break; - case S_IFCHR: sdata = "Character Device"; break; - case S_IFDIR: sdata = "Directory"; break; - case S_IFBLK: sdata = "Block Device"; break; - case S_IFREG: sdata = "Regular File"; break; - case S_IFLNK: sdata = "Symbolic Link"; break; - case S_IFSOCK: sdata = "Socket"; break; - case S_IFWHT: sdata = "Whiteout File"; break; - default: sdata = "???"; break; - } - hilo = 0; - } - formats = FMT_STRING; - if (ofmt == 0) - ofmt = FMT_STRING; - break; - case SHOW_filename: - small = 0; - data = 0; - if (file == NULL) - (void)strncpy(path, "(stdin)", sizeof(path)); - else - (void)strncpy(path, file, sizeof(path)); - sdata = path; - formats = FMT_STRING; - if (ofmt == 0) - ofmt = FMT_STRING; - break; - case SHOW_sizerdev: - if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) { - char majdev[20], mindev[20]; - int l1, l2; - - l1 = format1(st, - file, - fmt, flen, - majdev, sizeof(majdev), - flags, size, prec, - ofmt, HIGH_PIECE, SHOW_st_rdev); - l2 = format1(st, - file, - fmt, flen, - mindev, sizeof(mindev), - flags, size, prec, - ofmt, LOW_PIECE, SHOW_st_rdev); - return (snprintf(buf, blen, "%.*s,%.*s", - l1, majdev, l2, mindev)); - } - else { - return (format1(st, - file, - fmt, flen, - buf, blen, - flags, size, prec, - ofmt, 0, SHOW_st_size)); - } - /*NOTREACHED*/ - default: - errx(1, "%.*s: bad format", (int)flen, fmt); - } - - /* - * If a subdatum was specified but not supported, or an output - * format was selected that is not supported, that's an error. - */ - if (hilo != 0 || (ofmt & formats) == 0) - errx(1, "%.*s: bad format", (int)flen, fmt); - - /* - * Assemble the format string for passing to printf(3). - */ - lfmt[0] = '\0'; - (void)strcat(lfmt, "%"); - if (flags & FLAG_POUND) - (void)strcat(lfmt, "#"); - if (flags & FLAG_SPACE) - (void)strcat(lfmt, " "); - if (flags & FLAG_PLUS) - (void)strcat(lfmt, "+"); - if (flags & FLAG_MINUS) - (void)strcat(lfmt, "-"); - if (flags & FLAG_ZERO) - (void)strcat(lfmt, "0"); - - /* - * Only the timespecs support the FLOAT output format, and that - * requires work that differs from the other formats. - */ - if (ofmt == FMT_FLOAT) { - /* - * Nothing after the decimal point, so just print seconds. - */ - if (prec == 0) { - if (size != -1) { - (void)snprintf(tmp, sizeof(tmp), "%d", size); - (void)strcat(lfmt, tmp); - } - (void)strcat(lfmt, "d"); - return (snprintf(buf, blen, lfmt, ts.tv_sec)); - } - - /* - * Unspecified precision gets all the precision we have: - * 9 digits. - */ - if (prec == -1) - prec = 9; - - /* - * Adjust the size for the decimal point and the digits - * that will follow. - */ - size -= prec + 1; - - /* - * Any leftover size that's legitimate will be used. - */ - if (size > 0) { - (void)snprintf(tmp, sizeof(tmp), "%d", size); - (void)strcat(lfmt, tmp); - } - (void)strcat(lfmt, "d"); - - /* - * The stuff after the decimal point always needs zero - * filling. - */ - (void)strcat(lfmt, ".%0"); - - /* - * We can "print" at most nine digits of precision. The - * rest we will pad on at the end. - */ - (void)snprintf(tmp, sizeof(tmp), "%dd", prec > 9 ? 9 : prec); - (void)strcat(lfmt, tmp); - - /* - * For precision of less that nine digits, trim off the - * less significant figures. - */ - for (; prec < 9; prec++) - ts.tv_nsec /= 10; - - /* - * Use the format, and then tack on any zeroes that - * might be required to make up the requested precision. - */ - l = snprintf(buf, blen, lfmt, ts.tv_sec, ts.tv_nsec); - for (; prec > 9 && l < blen; prec--, l++) - (void)strcat(buf, "0"); - return (l); - } - - /* - * Add on size and precision, if specified, to the format. - */ - if (size != -1) { - (void)snprintf(tmp, sizeof(tmp), "%d", size); - (void)strcat(lfmt, tmp); - } - if (prec != -1) { - (void)snprintf(tmp, sizeof(tmp), ".%d", prec); - (void)strcat(lfmt, tmp); - } - - /* - * String output uses the temporary sdata. - */ - if (ofmt == FMT_STRING) { - if (sdata == NULL) - errx(1, "%.*s: bad format", (int)flen, fmt); - (void)strcat(lfmt, "s"); - return (snprintf(buf, blen, lfmt, sdata)); - } - - /* - * Ensure that sign extension does not cause bad looking output - * for some forms. - */ - if (small && ofmt != FMT_DECIMAL) - data = (u_int32_t)data; - - /* - * The four "numeric" output forms. - */ - (void)strcat(lfmt, "ll"); - switch (ofmt) { - case FMT_DECIMAL: (void)strcat(lfmt, "d"); break; - case FMT_OCTAL: (void)strcat(lfmt, "o"); break; - case FMT_UNSIGNED: (void)strcat(lfmt, "u"); break; - case FMT_HEX: (void)strcat(lfmt, "x"); break; - } - - return (snprintf(buf, blen, lfmt, data)); -} diff --git a/usr.bin/units/Makefile b/usr.bin/units/Makefile deleted file mode 100644 index 15679b5a7ce0..000000000000 --- a/usr.bin/units/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# $Id: Makefile,v 1.2 1996/04/06 06:00:58 thorpej Exp $ - -PROG= units - -beforeinstall: - install -c -o ${BINOWN} -g ${BINGRP} -m 444 \ - ${.CURDIR}/units.lib ${DESTDIR}/usr/share/misc - -.include <bsd.prog.mk> diff --git a/usr.bin/units/README b/usr.bin/units/README deleted file mode 100644 index ffb88a993165..000000000000 --- a/usr.bin/units/README +++ /dev/null @@ -1,18 +0,0 @@ -# $Id: README,v 1.2 1996/04/06 06:00:59 thorpej Exp $ - -This is a program which I wrote as a clone of the UNIX 'units' -command. I threw it together in a couple days, but it seems to work, -with some restrictions. I have tested it under DOS with Borland C and -Ultrix 4.2, and SunOS 4.1. - -This program differs from the unix units program in the following -ways: - it can gracefully handle exponents larger than 9 in output - it uses 'e' to denote exponentiation in numbers - prefixes are listed in the units file - it tries both -s and -es plurals - it allows use of * for multiply and ^ for exponentiation in the input - the output format is somewhat different - -Adrian Mariano (adrian@cam.cornell.edu or mariano@geom.umn.edu) - diff --git a/usr.bin/units/pathnames.h b/usr.bin/units/pathnames.h deleted file mode 100644 index b315c5b5823b..000000000000 --- a/usr.bin/units/pathnames.h +++ /dev/null @@ -1,33 +0,0 @@ -/* $Id: pathnames.h,v 1.3 1996/04/06 06:01:00 thorpej Exp $ */ - -/* - * Copyright (c) 1993 Christopher G. Demetriou - * 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 Christopher G. Demetriou. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -#define _PATH_UNITSLIB "/usr/share/misc/units.lib" diff --git a/usr.bin/units/units.1 b/usr.bin/units/units.1 deleted file mode 100644 index 891605247bfa..000000000000 --- a/usr.bin/units/units.1 +++ /dev/null @@ -1,124 +0,0 @@ -.\" $Id: units.1,v 1.6 1996/04/06 06:01:02 thorpej Exp $ -.TH UNITS 1 "14 July 1993" -.SH NAME -units - conversion program -.SH SYNTAX -.B units -[-f filename] [-qv] [from-unit to-unit] -.SH SUMMARY -.TP 4 -.B -f filename -Specifies the name of the units data file to load. -.LP -.TP 4 -.B -q -Suppresses prompting of the user for units and the display of statistics -about the number of units loaded. -.LP -.TP 4 -.B -v -Prints the version number. -.LP -.TP 4 -.B from-unit to-unit -Allows a single unit conversion to be done directly from the command -line. No prompting will occur. The units program will print out -only the result of this single conversion. - -.SH DESCRIPTION -The units program converts quantities expression in various scales to -their equivalents in other scales. The units program can only -handle multiplicative scale changes. It cannot convert Centigrade -to Fahrenheit, for example. It works interactively by prompting -the user for input: -.nf - - You have: meters - You want: feet - * 3.2808399 - / 0.3048 - - You have: cm^3 - You want: gallons - * 0.00026417205 - / 3785.4118 - -.fi -Powers of units can be specified using the '^' character as shown in -the example, or by simple concatenation: 'cm3' is equivalent to 'cm^3'. -Multiplication of units can be specified by using spaces, a dash or -an asterisk. Division of units is indicated by the slash ('/'). -Note that multiplication has a higher precedence than division, -so 'm/s/s' is the same as 'm/s^2' or 'm/s s'. -If the user enters incompatible unit types, the units program will -print a message indicating that the units are not conformable and -it will display the reduced form for each unit: -.nf - - You have: ergs/hour - You want: fathoms kg^2 / day - conformability error - 2.7777778e-11 kg m^2 / sec^3 - 2.1166667e-05 kg^2 m / sec - -.fi -.LP -The conversion information is read from a units data file. The default -file includes definitions for most familiar units, abbreviations and -metric prefixes. Some constants of nature included are: -.in +4m -.ta -.ta 9m + -.nf - -pi ratio of circumference to diameter -c speed of light -e charge on an electron -g acceleration of gravity -force same as g -mole Avogadro's number -water pressure per unit height of water -mercury pressure per unit height of mercury -au astronomical unit - -.fi -.in -4m -\'Pound' is a unit of mass. Compound names are run together -so 'poundforce' is a unit of force. British units that differ from their -US counterparts are prefixed with 'br', and currency is prefixed with -its country name: 'belgiumfranc', 'britainpound'. When searching for -a unit, if the specified string does not appear exactly as a unit -name, then the units program will try to remove a trailing 's' or -a trailing 'es' and check again for a match. -.LP -All of these definitions can be read in the standard units file, or you -can supply your own file. A unit is specified on a single line by -giving its name and an equivalence. One should be careful to define -new units in terms of old ones so that a reduction leads to the -primitive units which are marked with '!' characters. -The units program will not detect infinite loops that could be caused -by careless unit definitions. -.LP -Prefixes are defined in the same was as standard units, but with -a trailing dash at the end of the prefix name. -.SH BUGS -.LP -The effect of including a '/' in a prefix is surprising. -.LP -Exponents entered by the user can be only one digit. -You can work around this by multiplying several terms. -.LP -The user must use | to indicate division of numbers and / to -indicate division of symbols. This distinction should not -be necessary. -.LP -The program contains various arbitrary limits on the length -of the units converted and on the length of the data file. -.LP -The program should use a hash table to store units so that -it doesn't take so long to load the units list and check -for duplication. -.SH FILES -/usr/share/misc/units.lib - the standard units library -.SH AUTHOR -Adrian Mariano (adrian@cam.cornell.edu or mariano@geom.umn.edu) diff --git a/usr.bin/units/units.c b/usr.bin/units/units.c deleted file mode 100644 index 83e5b4223b22..000000000000 --- a/usr.bin/units/units.c +++ /dev/null @@ -1,706 +0,0 @@ -/* $Id: units.c,v 1.6 1996/04/06 06:01:03 thorpej Exp $ */ - -/* - * units.c Copyright (c) 1993 by Adrian Mariano (adrian@cam.cornell.edu) - * - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * Disclaimer: This software is provided by the author "as is". The author - * shall not be liable for any damages caused in any way by this software. - * - * I would appreciate (though I do not require) receiving a copy of any - * improvements you might make to this program. - */ - -#include <ctype.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#include "pathnames.h" - -#define VERSION "1.0" - -#ifndef UNITSFILE -#define UNITSFILE _PATH_UNITSLIB -#endif - -#define MAXUNITS 1000 -#define MAXPREFIXES 50 - -#define MAXSUBUNITS 500 - -#define PRIMITIVECHAR '!' - -char *powerstring = "^"; - -struct { - char *uname; - char *uval; -} unittable[MAXUNITS]; - -struct unittype { - char *numerator[MAXSUBUNITS]; - char *denominator[MAXSUBUNITS]; - double factor; -}; - -struct { - char *prefixname; - char *prefixval; -} prefixtable[MAXPREFIXES]; - - -char *NULLUNIT = ""; - -int unitcount; -int prefixcount; - - -char * -dupstr(char *str) -{ - char *ret; - - ret = malloc(strlen(str) + 1); - if (!ret) { - fprintf(stderr, "Memory allocation error\n"); - exit(3); - } - strcpy(ret, str); - return (ret); -} - - -void -readerror(int linenum) -{ - fprintf(stderr, "Error in units file '%s' line %d\n", UNITSFILE, - linenum); -} - - -void -readunits(char *userfile) -{ - FILE *unitfile; - char line[80], *lineptr; - int len, linenum, i; - - unitcount = 0; - linenum = 0; - - if (userfile) { - unitfile = fopen(userfile, "rt"); - if (!unitfile) { - fprintf(stderr, "Unable to open units file '%s'\n", - userfile); - exit(1); - } - } - else { - unitfile = fopen(UNITSFILE, "rt"); - if (!unitfile) { - char *direc, *env; - char filename[1000]; - char separator[2]; - - env = getenv("PATH"); - if (env) { - if (strchr(env, ';')) - strcpy(separator, ";"); - else - strcpy(separator, ":"); - direc = strtok(env, separator); - while (direc) { - strcpy(filename, ""); - strncat(filename, direc, 999); - strncat(filename, "/", - 999 - strlen(filename)); - strncat(filename, UNITSFILE, - 999 - strlen(filename)); - unitfile = fopen(filename, "rt"); - if (unitfile) - break; - direc = strtok(NULL, separator); - } - } - if (!unitfile) { - fprintf(stderr, "Can't find units file '%s'\n", - UNITSFILE); - exit(1); - } - } - } - while (!feof(unitfile)) { - if (!fgets(line, 79, unitfile)) - break; - linenum++; - lineptr = line; - if (*lineptr == '/') - continue; - lineptr += strspn(lineptr, " \n\t"); - len = strcspn(lineptr, " \n\t"); - lineptr[len] = 0; - if (!strlen(lineptr)) - continue; - if (lineptr[strlen(lineptr) - 1] == '-') { /* it's a prefix */ - if (prefixcount == MAXPREFIXES) { - fprintf(stderr, "Memory for prefixes exceeded in line %d\n", - linenum); - continue; - } - lineptr[strlen(lineptr) - 1] = 0; - prefixtable[prefixcount].prefixname = dupstr(lineptr); - for (i = 0; i < prefixcount; i++) - if (!strcmp(prefixtable[i].prefixname, lineptr)) { - fprintf(stderr, "Redefinition of prefix '%s' on line %d ignored\n", - lineptr, linenum); - continue; - } - lineptr += len + 1; - if (!strlen(lineptr)) { - readerror(linenum); - continue; - } - lineptr += strspn(lineptr, " \n\t"); - len = strcspn(lineptr, "\n\t"); - lineptr[len] = 0; - prefixtable[prefixcount++].prefixval = dupstr(lineptr); - } - else { /* it's not a prefix */ - if (unitcount == MAXUNITS) { - fprintf(stderr, "Memory for units exceeded in line %d\n", - linenum); - continue; - } - unittable[unitcount].uname = dupstr(lineptr); - for (i = 0; i < unitcount; i++) - if (!strcmp(unittable[i].uname, lineptr)) { - fprintf(stderr, "Redefinition of unit '%s' on line %d ignored\n", - lineptr, linenum); - continue; - } - lineptr += len + 1; - lineptr += strspn(lineptr, " \n\t"); - if (!strlen(lineptr)) { - readerror(linenum); - continue; - } - len = strcspn(lineptr, "\n\t"); - lineptr[len] = 0; - unittable[unitcount++].uval = dupstr(lineptr); - } - } - fclose(unitfile); -} - -void -initializeunit(struct unittype * theunit) -{ - theunit->factor = 1.0; - theunit->numerator[0] = theunit->denominator[0] = NULL; -} - - -int -addsubunit(char *product[], char *toadd) -{ - char **ptr; - - for (ptr = product; *ptr && *ptr != NULLUNIT; ptr++); - if (ptr >= product + MAXSUBUNITS) { - fprintf(stderr, "Memory overflow in unit reduction\n"); - return 1; - } - if (!*ptr) - *(ptr + 1) = 0; - *ptr = dupstr(toadd); - return 0; -} - - -void -showunit(struct unittype * theunit) -{ - char **ptr; - int printedslash; - int counter = 1; - - printf("\t%.8g", theunit->factor); - for (ptr = theunit->numerator; *ptr; ptr++) { - if (ptr > theunit->numerator && **ptr && - !strcmp(*ptr, *(ptr - 1))) - counter++; - else { - if (counter > 1) - printf("%s%d", powerstring, counter); - if (**ptr) - printf(" %s", *ptr); - counter = 1; - } - } - if (counter > 1) - printf("%s%d", powerstring, counter); - counter = 1; - printedslash = 0; - for (ptr = theunit->denominator; *ptr; ptr++) { - if (ptr > theunit->denominator && **ptr && - !strcmp(*ptr, *(ptr - 1))) - counter++; - else { - if (counter > 1) - printf("%s%d", powerstring, counter); - if (**ptr) { - if (!printedslash) - printf(" /"); - printedslash = 1; - printf(" %s", *ptr); - } - counter = 1; - } - } - if (counter > 1) - printf("%s%d", powerstring, counter); - printf("\n"); -} - - -void -zeroerror() -{ - fprintf(stderr, "Unit reduces to zero\n"); -} - -/* - Adds the specified string to the unit. - Flip is 0 for adding normally, 1 for adding reciprocal. - - Returns 0 for successful addition, nonzero on error. -*/ - -int -addunit(struct unittype * theunit, char *toadd, int flip) -{ - char *scratch, *savescr; - char *item; - char *divider, *slash; - int doingtop; - - savescr = scratch = dupstr(toadd); - for (slash = scratch + 1; *slash; slash++) - if (*slash == '-' && - (tolower(*(slash - 1)) != 'e' || - !strchr(".0123456789", *(slash + 1)))) - *slash = ' '; - slash = strchr(scratch, '/'); - if (slash) - *slash = 0; - doingtop = 1; - do { - item = strtok(scratch, " *\t\n/"); - while (item) { - if (strchr("0123456789.", *item)) { /* item is a number */ - double num; - - divider = strchr(item, '|'); - if (divider) { - *divider = 0; - num = atof(item); - if (!num) { - zeroerror(); - return 1; - } - if (doingtop ^ flip) - theunit->factor *= num; - else - theunit->factor /= num; - num = atof(divider + 1); - if (!num) { - zeroerror(); - return 1; - } - if (doingtop ^ flip) - theunit->factor /= num; - else - theunit->factor *= num; - } - else { - num = atof(item); - if (!num) { - zeroerror(); - return 1; - } - if (doingtop ^ flip) - theunit->factor *= num; - else - theunit->factor /= num; - - } - } - else { /* item is not a number */ - int repeat = 1; - - if (strchr("23456789", - item[strlen(item) - 1])) { - repeat = item[strlen(item) - 1] - '0'; - item[strlen(item) - 1] = 0; - } - for (; repeat; repeat--) - if (addsubunit(doingtop ^ flip ? theunit->numerator : theunit->denominator, item)) - return 1; - } - item = strtok(NULL, " *\t/\n"); - } - doingtop--; - if (slash) { - scratch = slash + 1; - } - else - doingtop--; - } while (doingtop >= 0); - free(savescr); - return 0; -} - - -int -compare(const void *item1, const void *item2) -{ - return strcmp(*(char **) item1, *(char **) item2); -} - - -void -sortunit(struct unittype * theunit) -{ - char **ptr; - int count; - - for (count = 0, ptr = theunit->numerator; *ptr; ptr++, count++); - qsort(theunit->numerator, count, sizeof(char *), compare); - for (count = 0, ptr = theunit->denominator; *ptr; ptr++, count++); - qsort(theunit->denominator, count, sizeof(char *), compare); -} - - -void -cancelunit(struct unittype * theunit) -{ - char **den, **num; - int comp; - - den = theunit->denominator; - num = theunit->numerator; - - while (*num && *den) { - comp = strcmp(*den, *num); - if (!comp) { -/* if (*den!=NULLUNIT) free(*den); - if (*num!=NULLUNIT) free(*num);*/ - *den++ = NULLUNIT; - *num++ = NULLUNIT; - } - else if (comp < 0) - den++; - else - num++; - } -} - - - - -/* - Looks up the definition for the specified unit. - Returns a pointer to the definition or a null pointer - if the specified unit does not appear in the units table. -*/ - -static char buffer[100]; /* buffer for lookupunit answers with - prefixes */ - -char * -lookupunit(char *unit) -{ - int i; - char *copy; - - for (i = 0; i < unitcount; i++) { - if (!strcmp(unittable[i].uname, unit)) - return unittable[i].uval; - } - - if (unit[strlen(unit) - 1] == '^') { - copy = dupstr(unit); - copy[strlen(copy) - 1] = 0; - for (i = 0; i < unitcount; i++) { - if (!strcmp(unittable[i].uname, copy)) { - strcpy(buffer, copy); - free(copy); - return buffer; - } - } - free(copy); - } - if (unit[strlen(unit) - 1] == 's') { - copy = dupstr(unit); - copy[strlen(copy) - 1] = 0; - for (i = 0; i < unitcount; i++) { - if (!strcmp(unittable[i].uname, copy)) { - strcpy(buffer, copy); - free(copy); - return buffer; - } - } - if (copy[strlen(copy) - 1] == 'e') { - copy[strlen(copy) - 1] = 0; - for (i = 0; i < unitcount; i++) { - if (!strcmp(unittable[i].uname, copy)) { - strcpy(buffer, copy); - free(copy); - return buffer; - } - } - } - free(copy); - } - for (i = 0; i < prefixcount; i++) { - if (!strncmp(prefixtable[i].prefixname, unit, - strlen(prefixtable[i].prefixname))) { - unit += strlen(prefixtable[i].prefixname); - if (!strlen(unit) || lookupunit(unit)) { - strcpy(buffer, prefixtable[i].prefixval); - strcat(buffer, " "); - strcat(buffer, unit); - return buffer; - } - } - } - return 0; -} - - - -/* - reduces a product of symbolic units to primitive units. - The three low bits are used to return flags: - - bit 0 (1) set on if reductions were performed without error. - bit 1 (2) set on if no reductions are performed. - bit 2 (4) set on if an unknown unit is discovered. -*/ - - -#define ERROR 4 - -int -reduceproduct(struct unittype * theunit, int flip) -{ - - char *toadd; - char **product; - int didsomething = 2; - - if (flip) - product = theunit->denominator; - else - product = theunit->numerator; - - for (; *product; product++) { - - for (;;) { - if (!strlen(*product)) - break; - toadd = lookupunit(*product); - if (!toadd) { - printf("unknown unit '%s'\n", *product); - return ERROR; - } - if (strchr(toadd, PRIMITIVECHAR)) - break; - didsomething = 1; - if (*product != NULLUNIT) { - free(*product); - *product = NULLUNIT; - } - if (addunit(theunit, toadd, flip)) - return ERROR; - } - } - return didsomething; -} - - -/* - Reduces numerator and denominator of the specified unit. - Returns 0 on success, or 1 on unknown unit error. -*/ - -int -reduceunit(struct unittype * theunit) -{ - int ret; - - ret = 1; - while (ret & 1) { - ret = reduceproduct(theunit, 0) | reduceproduct(theunit, 1); - if (ret & 4) - return 1; - } - return 0; -} - - -int -compareproducts(char **one, char **two) -{ - while (*one || *two) { - if (!*one && *two != NULLUNIT) - return 1; - if (!*two && *one != NULLUNIT) - return 1; - if (*one == NULLUNIT) - one++; - else if (*two == NULLUNIT) - two++; - else if (strcmp(*one, *two)) - return 1; - else - one++, two++; - } - return 0; -} - - -/* Return zero if units are compatible, nonzero otherwise */ - -int -compareunits(struct unittype * first, struct unittype * second) -{ - return - compareproducts(first->numerator, second->numerator) || - compareproducts(first->denominator, second->denominator); -} - - -int -completereduce(struct unittype * unit) -{ - if (reduceunit(unit)) - return 1; - sortunit(unit); - cancelunit(unit); - return 0; -} - - -void -showanswer(struct unittype * have, struct unittype * want) -{ - if (compareunits(have, want)) { - printf("conformability error\n"); - showunit(have); - showunit(want); - } - else - printf("\t* %.8g\n\t/ %.8g\n", have->factor / want->factor, - want->factor / have->factor); -} - - -void -usage() -{ - fprintf(stderr, "\nunits [-f unitsfile] [-q] [-v] [from-unit to-unit]\n"); - fprintf(stderr, "\n -f specify units file\n"); - fprintf(stderr, " -q supress prompting (quiet)\n"); - fprintf(stderr, " -v print version number\n"); - exit(3); -} - - -int -main(int argc, char **argv) -{ - - struct unittype have, want; - char havestr[81], wantstr[81]; - int optchar; - char *userfile = 0; - int quiet = 0; - - extern char *optarg; - extern int optind; - - while ((optchar = getopt(argc, argv, "vqf:")) != -1) { - switch (optchar) { - case 'f': - userfile = optarg; - break; - case 'q': - quiet = 1; - break; - case 'v': - fprintf(stderr, "\n units version %s Copyright (c) 1993 by Adrian Mariano\n", - VERSION); - fprintf(stderr, " This program may be freely distributed\n"); - usage(); - default: - usage(); - break; - } - } - - if (optind != argc - 2 && optind != argc) - usage(); - - readunits(userfile); - - if (optind == argc - 2) { - strcpy(havestr, argv[optind]); - strcpy(wantstr, argv[optind + 1]); - initializeunit(&have); - addunit(&have, havestr, 0); - completereduce(&have); - initializeunit(&want); - addunit(&want, wantstr, 0); - completereduce(&want); - showanswer(&have, &want); - } - else { - if (!quiet) - printf("%d units, %d prefixes\n\n", unitcount, - prefixcount); - for (;;) { - do { - initializeunit(&have); - if (!quiet) - printf("You have: "); - if (!fgets(havestr, 80, stdin)) { - if (!quiet); - putchar('\n'); - exit(0); - } - } while (addunit(&have, havestr, 0) || - completereduce(&have)); - do { - initializeunit(&want); - if (!quiet) - printf("You want: "); - if (!fgets(wantstr, 80, stdin)) { - if (!quiet) - putchar('\n'); - exit(0); - } - } while (addunit(&want, wantstr, 0) || - completereduce(&want)); - showanswer(&have, &want); - } - } -} diff --git a/usr.bin/units/units.lib b/usr.bin/units/units.lib deleted file mode 100644 index ef4e8d7a9a25..000000000000 --- a/usr.bin/units/units.lib +++ /dev/null @@ -1,610 +0,0 @@ -/ $Id: units.lib,v 1.3 1996/04/06 06:01:04 thorpej Exp $ - -/ primitive units - -m !a! -kg !b! -sec !c! -coul !d! -candela !e! -dollar !f! -bit !h! -erlang !i! -K !j! - -/ prefixes - -yotta- 1e24 -zetta- 1e21 -exa- 1e18 -peta- 1e15 -tera- 1e12 -giga- 1e9 -mega- 1e6 -myria- 1e4 -kilo- 1e3 -hecto- 1e2 -deka- 1e1 -deci- 1e-1 -centi- 1e-2 -milli- 1e-3 -micro- 1e-6 -nano- 1e-9 -pico- 1e-12 -femto- 1e-15 -atto- 1e-18 -zopto- 1e-21 -yocto- 1e-24 - -semi- .5 -demi- .5 - -Y- yotta -Z- zetta -E- exa -P- peta -T- tera -G- giga -M- mega -k- kilo -h- hecto -da- deka -d- deci -c- centi -m- milli -p- pico -f- femto -a- atto -z- zopto -y- yocto - -/ constants - -fuzz 1 -pi 3.14159265358979323846 -c 2.99792458e+8 m/sec fuzz -g 9.80665 m/sec2 -au 1.49597871e+11 m fuzz -mole 6.022169e+23 fuzz -e 1.6021917e-19 coul fuzz -energy c2 -force g -mercury 1.33322e+5 kg/m2-sec2 -hg mercury - -/ dimensionless - -radian .5 / pi -degree 1|180 pi-radian -circle 2 pi-radian -turn 2 pi-radian -revolution turn -rev turn -grade .9 degree -arcdeg 1 degree -arcmin 1|60 arcdeg -ccs 1|36 erlang -arcsec 1|60 arcmin - -steradian radian2 -sphere 4 pi-steradian -sr steradian - -/ Time - -second sec -s sec -minute 60 sec -min minute -hour 60 min -hr hour -day 24 hr -da day -week 7 day -year 365.24219879 day fuzz -yr year -month 1|12 year -ms millisec -us microsec - -/ Mass - -gram millikg -gm gram -mg milligram -metricton kilokg - -/ Avoirdupois - -lb .45359237 kg -pound lb -lbf lb g -ounce 1|16 lb -oz ounce -dram 1|16 oz -dr dram -grain 1|7000 lb -gr grain -shortton 2000 lb -ton shortton -longton 2240 lb - -/ Apothecary - -scruple 20 grain -apdram 60 grain -apounce 480 grain -appound 5760 grain -troypound appound - -/ Length - -meter m -cm centimeter -mm millimeter -km kilometer -nm nanometer -micron micrometer -angstrom decinanometer - -inch 2.54 cm -in inch -foot 12 in -feet foot -ft foot -yard 3 ft -yd yard -rod 5.5 yd -rd rod -mile 5280 ft -mi mile - -british 1200|3937 m/ft -nmile 1852 m - -acre 4840 yd2 - -cc cm3 -liter kilocc -ml milliliter - -/ US Liquid - -gallon 231 in3 -imperial 1.20095 -gal gallon -quart 1|4 gal -qt quart -pint 1|2 qt -pt pint - -floz 1|16 pt -fldr 1|8 floz - -/ US Dry - -dry 268.8025 in3/gallon fuzz -peck 8 dry-quart -pk peck -bushel 4 peck -bu bushel -chaldron 36 bushel - -/ British - -brgallon 277.420 in3 fuzz -brquart 1|4 brgallon -brpint 1|2 brquart -brfloz 1|20 brpint -brpeck 554.84 in3 fuzz -brbushel 4 brpeck - -/ Energy Work - -newton kg-m/sec2 -nt newton -N newton -joule nt-m -cal 4.1868 joule - -/ Electrical - -coulomb coul -C coul -ampere coul/sec -amp ampere -watt joule/sec -volt watt/amp -ohm volt/amp -mho /ohm -farad coul/volt -henry sec2/farad -weber volt-sec - -/ Light - -cd candela -lumen cd sr -lux cd sr/m2 - -/ Wall Street Journal, July 2, 1993 - -$ dollar -argentinapeso $ -australiadollar .66 $ -austriaschilling .83 $ -bahraindinar 2.6522 $ -belgiumfranc .028 $ -brazilcruzeiro .000019 $ -britainpound 1.49 $ -canadadollar .77 $ -czechkoruna .034 $ -chilepeso .0025 $ -chinarenminbi .174856 $ -colombiapeso .001495 $ -denmarkkrone .15 $ -ecuadorsucre .000539 $ -finlandmarkka .17 $ -francefranc .17 $ -germanymark .58 $ -greatbritainpound britainpound -greecedrachma .0043 $ -hongkongdollar .13 $ -hungaryforint .011 $ -indiarupee .03211 $ -indonesiarupiah .0004782 $ -irelandpunt 1.43 $ -israelshekel .3642 $ -italylira .00064 $ -japanyen .0093 $ -jordandinar 1.4682 $ -kuwaitdinar 3.3173 $ -lebanonpound .000578 $ -malaysiaringgit .338 $ -maltalira 2.6042 $ -mexicopeso .3205128 $ -netherlandguilder .52 $ -newzealanddollar .539 $ -norwaykrone .139 $ -pakistanrupee .037 $ -perunewsol .5065 $ -philippinespeso .03738 $ -polandzloty .000059 $ -portugalescudo .00617 $ -saudiarabiariyal .26702 $ -singaporedollar .6157 $ -slovakkoruna .034 $ -southamericarand .21 $ -southkoreawon .001 $ -spainpeseta .007 $ -swedenkrona .13 $ -switzerlandfranc .66 $ -taiwandollar .038285 $ -thailandbaht .03962 $ -turkeylira .0000929 $ -unitedarabdirham .2723 $ -uruguaynewpeso .246852 $ -venezuelabolivar .011 $ - -mark germanymark -bolivar venezuelabolivar -peseta spainpeseta -rand southafricarand -escudo portugalescudo -sol perusol -guilder netherlandsguilder -hollandguilder netherlandsguilder -peso mexicopeso -yen japanyen -lira italylira -rupee indiarupee -drachma greecedrachma -franc francefranc -markka finlandmarkka -sucre ecuadorsucre -poundsterling britainpound -cruzeiro brazilcruzeiro - -/ computer - -baud bit/sec -byte 8 bit -block 512 byte -kbyte 1024 byte -megabyte 1024 kbyte -gigabyte 1024 megabyte -meg megabyte - - -/ Trivia - -% 1|100 -admiraltyknot 6080 ft/hr -apostilb cd/pi-m2 -are 1e+2 m2 -arpentcan 27.52 mi -arpentlin 191.835 ft -astronomicalunit au -atmosphere 1.01325e+5 nt/m2 -atm atmosphere -atomicmassunit 1.66044e-27 kg fuzz -amu atomicmassunit -bag 94 lb -bakersdozen 13 -bar 1e+5 nt/m2 -barie 1e-1 nt/m2 -barleycorn 1|3 in -barn 1e-28 m2 -barrel 42 gal -barye 1e-1 nt/m2 -bev 1e+9 e-volt -biot 10 amp -blondel cd/pi-m2 -boardfoot 144 in3 -bolt 40 yd -bottommeasure 1|40 in -britishthermalunit 1.05506e+3 joule fuzz -btu britishthermalunit -refrigeration 12000 btu/ton-hour -buck dollar -cable 720 ft -caliber 1e-2 in -calorie cal -carat 205 mg -caratgold 1|24 -cent centidollar -cental 100 lb -centesimalminute 1e-2 grade -centesimalsecond 1e-4 grade -century 100 year -cfs ft3/sec -chain 66 ft -circularinch 1|4 pi-in2 -circularmil 1e-6|4 pi-in2 -clusec 1e-8 mm-hg m3/s -coomb 4 bu -cord 128 ft3 -cordfoot cord -crith 9.06e-2 gm -cubit 18 in -cup 1|2 pt -curie 3.7e+10 /sec -dalton amu -decade 10 yr -dipotre /m -displacementton 35 ft3 -doppelzentner 100 kg -dozen 12 -drop .03 cm3 -dyne cm-gm/sec2 -electronvolt e-volt -ell 45 in -engineerschain 100 ft -engineerslink 100|100 ft -equivalentfootcandle lumen/pi-ft2 -equivalentlux lumen/pi-m2 -equivalentphot cd/pi-cm2 -erg cm2-gm/sec2 -ev e-volt -faraday 9.652e+4 coul -fathom 6 ft -fermi 1e-15 m -fifth 4|5 qt -fin 5 dollar -finger 7|8 in -firkin 9 gal -footcandle lumen/ft2 -footlambert cd/pi-ft2 -fortnight 14 da -franklin 3.33564e-10 coul -frigorie kilocal -furlong 220 yd -galileo 1e-2 m/sec2 -gamma 1e-9 weber/m2 -gauss 1e-4 weber/m2 -geodeticfoot british-ft -geographicalmile 1852 m -gilbert 7.95775e-1 amp -gill 1|4 pt -gross 144 -gunterschain 22 yd -hand 4 in -hectare 1e+4 m2 -hefnercandle .92 cd -hertz /sec -Hz hertz -hogshead 2 barrel -hd hogshead -homestead 1|4 mi2 -horsepower 550 ft-lb-g/sec -hp horsepower -hyl gm force sec2/m -hz /sec -imaginarycubicfoot 1.4 ft3 -jeroboam 4|5 gal -karat 1|24 -kcal kilocal -kcalorie kilocal -kev 1e+3 e-volt -key kg -khz 1e+3 /sec -kilderkin 18 gal -knot nmile/hr -lambert cd/pi-cm2 -langley cal/cm2 -last 80 bu -league 3 mi -lightyear c-yr -line 1|12 in -link 66|100 ft -longhundredweight 112 lb -longquarter 28 lb -lusec 1e-6 mm-hg m3/s -mach 331.46 m/sec -magnum 2 qt -marineleague 3 nmile -maxwell 1e-8 weber -metriccarat 200 mg -mgd megagal/day -mh millihenry -mhz 1e+6 /sec -mil 1e-3 in -millenium 1000 year -minersinch 1.5 ft3/min -minim 1|60 fldr -mo month -mpg mile/gal -mph mile/hr -nail 1|16 yd -nauticalmile nmile -nit cd/m2 -noggin 1|8 qt -nox 1e-3 lux -ns nanosec -oersted 2.5e+2 pi-amp/m -oe oersted -pace 36 in -palm 3 in -parasang 3.5 mi -parsec au-radian/arcsec -pascal nt/m2 -pc parsec -pennyweight 1|20 oz -pwt pennyweight -percent % -perch rd -pf picofarad -phot lumen/cm2 -pica 1|6 in -pieze 1e+3 nt/m2 -pipe 4 barrel -point 1|72 in -poise gm/cm-sec -pole rd -poundal ft-lb/sec2 -pdl poundal -proof 1|200 -psi lb-g/in2 -quarter 9 in -quartersection 1|4 mi2 -quintal 100 kg -quire 25 -rad 100 erg/gm -ream 500 -registerton 100 ft3 -rehoboam 156 floz -rhe 10 m2/nt-sec -rontgen 2.58e-4 curie/kg -rood 1.21e+3 yd -rope 20 ft -rutherford 1e+6 /sec -rydberg 1.36054e+1 ev -sabin 1 ft2 -sack 3 bu -seam 8 bu -section mi2 -shippington 40 ft3 -shorthundredweight 100 lb -shortquarter 25 lb -siemens /ohm -sigma microsec -skein 120 yd -skot 1e-3 apostilb -slug lb-g-sec2/ft -span 9 in -spat 4 pi sr -spindle 14400 yd -square 100 ft2 -stere m3 -sthene 1e+3 nt -stilb cd/cm2 -stoke 1e-4 m2/sec -stone 14 lb -strike 2 bu -surveyfoot british-ft -surveyyard 3 surveyfoot -surveyorschain 66 ft -surveyorslink 66|100 ft -tablespoon 4 fldr -teaspoon 4|3 fldr -tesla weber/m2 -therm 1e+5 btu -thermie 1e+6 cal -timberfoot ft3 -tnt 4.6e+6 m2/sec2 -tonne 1e+6 gm -torr mm hg -township 36 mi2 -tun 8 barrel -water gram g / cc -wey 40 bu -weymass 252 lb -Xunit 1.00202e-13 m -k 1.38047e-16 erg/degC - - -degC K -kelvin K -brewster 1e-12 m2/newton -degF 5|9 degC -degreesrankine degF -degrankine degreesrankine -degreerankine degF -degreaumur 10|8 degC -drachm 60 grain -poncelet 100 kg m g / sec -denier .05|450 gram / m -tex .001 gram / m -englishell 45 inch -scottishell 37.2 inch -flemishell 27 inch -planck 6.626e-34 joule-sec -hbar 1.055e-34 joule-sec -electronmass 9.1095e-31 kg -protonmass 1.6726e-27 kg -neutronmass 1.6606e-27 kg -V volt -eV e V -bohrradius hbar2-C2/8.988e9 N m2-e2-electronmass -becquerel 1|3.7e10 curie -fresnel 1e12 hertz -statcoul 1|2.99792458e9 coul -statamp 1|2.99792458e9 amp -statvolt 2.99792458e2 volt -statcoulomb statcoul -statampere statamp -debye 3.336e-30 coul-m -pulsatance 2 pi/sec -rpm rev/minute -rps rev/sec -kilohm kiloohm -megohm megaohm -siderealyear 365.256360417 day -siderealday 23.934469444 hour -siderealhour 1|24 sidereal day -lunarmonth 29.5305555 day -synodicmonth lunarmonth -siderealmonth 27.32152777 day -tropicalyear year -solaryear year -lunaryear 12 lunarmonth -cran 37.5 brgallon -kip 1000 lbf -frenchfoot 16|15 ft -frenchfeet frenchfoot -toise 6 frenchfeet -sievert 8.4 rontgen -candle 1.02 candela -militarypace 2.5 feet -metre meter -litre liter -gramme gram -iudiptheria 62.8 microgram -iupenicillin .6 microgram -iuinsulin 41.67 microgram -cottonyarncount 2520 ft/pound -linenyarncount 900 ft/pound -worstedyarncount 1680 ft/pound -metricyarncount meter/gram -jewlerspoint 2 milligram - diff --git a/usr.sbin/bootpd/Makefile b/usr.sbin/bootpd/Makefile deleted file mode 100644 index fe2d43510306..000000000000 --- a/usr.sbin/bootpd/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# bootpd/Makefile -# $Id: Makefile,v 1.1.1.1 1994/06/27 21:25:49 gwr Exp $ - -PROG= bootpd -CFLAGS+= -DETC_ETHERS -DSYSLOG -DDEBUG -DVEND_CMU - -SRCS= bootpd.c dovend.c readfile.c hash.c dumptab.c \ - lookup.c getif.c hwaddr.c report.c tzone.c - -MAN5= bootptab.0 -MAN8= bootpd.0 -MLINKS= bootpd.8 bootpgw.8 - -.include <bsd.prog.mk> diff --git a/usr.sbin/bootpd/getether.c b/usr.sbin/bootpd/getether.c deleted file mode 100644 index d131b50f7f89..000000000000 --- a/usr.sbin/bootpd/getether.c +++ /dev/null @@ -1,374 +0,0 @@ -/* - * getether.c : get the ethernet address of an interface - * - * All of this code is quite system-specific. As you may well - * guess, it took a good bit of detective work to figure out! - * - * If you figure out how to do this on another system, - * please let me know. <gwr@mc.com> - */ - -#include <sys/types.h> -#include <sys/socket.h> - -#include <ctype.h> -#include <syslog.h> - -#include "report.h" -#define EALEN 6 - -#if defined(ultrix) || (defined(__osf__) && defined(__alpha)) -/* - * This is really easy on Ultrix! Thanks to - * Harald Lundberg <hl@tekla.fi> for this code. - * - * The code here is not specific to the Alpha, but that was the - * only symbol we could find to identify DEC's version of OSF. - * (Perhaps we should just define DEC in the Makefile... -gwr) - */ - -#include <sys/ioctl.h> -#include <net/if.h> /* struct ifdevea */ - -getether(ifname, eap) - char *ifname, *eap; -{ - int rc = -1; - int fd; - struct ifdevea phys; - bzero(&phys, sizeof(phys)); - strcpy(phys.ifr_name, ifname); - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - report(LOG_ERR, "getether: socket(INET,DGRAM) failed"); - return -1; - } - if (ioctl(fd, SIOCRPHYSADDR, &phys) < 0) { - report(LOG_ERR, "getether: ioctl SIOCRPHYSADDR failed"); - } else { - bcopy(&phys.current_pa[0], eap, EALEN); - rc = 0; - } - close(fd); - return rc; -} - -#define GETETHER -#endif /* ultrix|osf1 */ - - -#ifdef SUNOS - -#include <sys/sockio.h> -#include <sys/time.h> /* needed by net_if.h */ -#include <net/nit_if.h> /* for NIOCBIND */ -#include <net/if.h> /* for struct ifreq */ - -getether(ifname, eap) - char *ifname; /* interface name from ifconfig structure */ - char *eap; /* Ether address (output) */ -{ - int rc = -1; - - struct ifreq ifrnit; - int nit; - - bzero((char *) &ifrnit, sizeof(ifrnit)); - strncpy(&ifrnit.ifr_name[0], ifname, IFNAMSIZ); - - nit = open("/dev/nit", 0); - if (nit < 0) { - report(LOG_ERR, "getether: open /dev/nit: %s", - get_errmsg()); - return rc; - } - do { - if (ioctl(nit, NIOCBIND, &ifrnit) < 0) { - report(LOG_ERR, "getether: NIOCBIND on nit"); - break; - } - if (ioctl(nit, SIOCGIFADDR, &ifrnit) < 0) { - report(LOG_ERR, "getether: SIOCGIFADDR on nit"); - break; - } - bcopy(&ifrnit.ifr_addr.sa_data[0], eap, EALEN); - rc = 0; - } while (0); - close(nit); - return rc; -} - -#define GETETHER -#endif /* SUNOS */ - - -#if defined(__386BSD__) || defined(__NetBSD__) -/* Thanks to John Brezak <brezak@ch.hp.com> for this code. */ -#include <sys/ioctl.h> -#include <net/if.h> -#include <net/if_dl.h> -#include <net/if_types.h> - -getether(ifname, eap) - char *ifname; /* interface name from ifconfig structure */ - char *eap; /* Ether address (output) */ -{ - int fd, rc = -1; - register int n; - struct ifreq ibuf[16], ifr; - struct ifconf ifc; - register struct ifreq *ifrp, *ifend; - - /* Fetch the interface configuration */ - fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd < 0) { - report(LOG_ERR, "getether: socket %s: %s", ifname, get_errmsg()); - return (fd); - } - ifc.ifc_len = sizeof(ibuf); - ifc.ifc_buf = (caddr_t) ibuf; - if (ioctl(fd, SIOCGIFCONF, (char *) &ifc) < 0 || - ifc.ifc_len < sizeof(struct ifreq)) { - report(LOG_ERR, "getether: SIOCGIFCONF: %s", get_errmsg); - goto out; - } - /* Search interface configuration list for link layer address. */ - ifrp = ibuf; - ifend = (struct ifreq *) ((char *) ibuf + ifc.ifc_len); - while (ifrp < ifend) { - /* Look for interface */ - if (strcmp(ifname, ifrp->ifr_name) == 0 && - ifrp->ifr_addr.sa_family == AF_LINK && - ((struct sockaddr_dl *) &ifrp->ifr_addr)->sdl_type == IFT_ETHER) { - bcopy(LLADDR((struct sockaddr_dl *) &ifrp->ifr_addr), eap, EALEN); - rc = 0; - break; - } - /* Bump interface config pointer */ - n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name); - if (n < sizeof(*ifrp)) - n = sizeof(*ifrp); - ifrp = (struct ifreq *) ((char *) ifrp + n); - } - - out: - close(fd); - return (rc); -} - -#define GETETHER -#endif /* __NetBSD__ */ - - -#ifdef SVR4 -/* - * This is for "Streams TCP/IP" by Lachman Associates. - * They sure made this cumbersome! -gwr - */ - -#include <sys/sockio.h> -#include <sys/dlpi.h> -#include <stropts.h> -#ifndef NULL -#define NULL 0 -#endif - -getether(ifname, eap) - char *ifname; /* interface name from ifconfig structure */ - char *eap; /* Ether address (output) */ -{ - int rc = -1; - char devname[32]; - char tmpbuf[sizeof(union DL_primitives) + 16]; - struct strbuf cbuf; - int fd, flags; - union DL_primitives *dlp; - char *enaddr; - int unit = -1; /* which unit to attach */ - - sprintf(devname, "/dev/%s", ifname); - fd = open(devname, 2); - if (fd < 0) { - /* Try without the trailing digit. */ - char *p = devname + 5; - while (isalpha(*p)) - p++; - if (isdigit(*p)) { - unit = *p - '0'; - *p = '\0'; - } - fd = open(devname, 2); - if (fd < 0) { - report(LOG_ERR, "getether: open %s: %s", - devname, get_errmsg()); - return rc; - } - } -#ifdef DL_ATTACH_REQ - /* - * If this is a "Style 2" DLPI, then we must "attach" first - * to tell the driver which unit (board, port) we want. - * For now, decide this based on the device name. - * (Should do "info_req" and check dl_provider_style ...) - */ - if (unit >= 0) { - memset(tmpbuf, 0, sizeof(tmpbuf)); - dlp = (union DL_primitives *) tmpbuf; - dlp->dl_primitive = DL_ATTACH_REQ; - dlp->attach_req.dl_ppa = unit; - cbuf.buf = tmpbuf; - cbuf.len = DL_ATTACH_REQ_SIZE; - if (putmsg(fd, &cbuf, NULL, 0) < 0) { - report(LOG_ERR, "getether: attach: putmsg: %s", get_errmsg()); - goto out; - } - /* Recv the ack. */ - cbuf.buf = tmpbuf; - cbuf.maxlen = sizeof(tmpbuf); - flags = 0; - if (getmsg(fd, &cbuf, NULL, &flags) < 0) { - report(LOG_ERR, "getether: attach: getmsg: %s", get_errmsg()); - goto out; - } - /* - * Check the type, etc. - */ - if (dlp->dl_primitive == DL_ERROR_ACK) { - report(LOG_ERR, "getether: attach: dlpi_errno=%d, unix_errno=%d", - dlp->error_ack.dl_errno, - dlp->error_ack.dl_unix_errno); - goto out; - } - if (dlp->dl_primitive != DL_OK_ACK) { - report(LOG_ERR, "getether: attach: not OK or ERROR"); - goto out; - } - } /* unit >= 0 */ -#endif /* DL_ATTACH_REQ */ - - /* - * Get the Ethernet address the same way the ARP module - * does when it is pushed onto a new stream (bind). - * One should instead be able just do an dl_info_req - * but many drivers do not supply the hardware address - * in the response to dl_info_req (they MUST supply it - * for dl_bind_ack because the ARP module requires it). - */ - memset(tmpbuf, 0, sizeof(tmpbuf)); - dlp = (union DL_primitives *) tmpbuf; - dlp->dl_primitive = DL_BIND_REQ; - dlp->bind_req.dl_sap = 0x8FF; /* XXX - Unused SAP */ - cbuf.buf = tmpbuf; - cbuf.len = DL_BIND_REQ_SIZE; - if (putmsg(fd, &cbuf, NULL, 0) < 0) { - report(LOG_ERR, "getether: bind: putmsg: %s", get_errmsg()); - goto out; - } - /* Recv the ack. */ - cbuf.buf = tmpbuf; - cbuf.maxlen = sizeof(tmpbuf); - flags = 0; - if (getmsg(fd, &cbuf, NULL, &flags) < 0) { - report(LOG_ERR, "getether: bind: getmsg: %s", get_errmsg()); - goto out; - } - /* - * Check the type, etc. - */ - if (dlp->dl_primitive == DL_ERROR_ACK) { - report(LOG_ERR, "getether: bind: dlpi_errno=%d, unix_errno=%d", - dlp->error_ack.dl_errno, - dlp->error_ack.dl_unix_errno); - goto out; - } - if (dlp->dl_primitive != DL_BIND_ACK) { - report(LOG_ERR, "getether: bind: not OK or ERROR"); - goto out; - } - if (dlp->bind_ack.dl_addr_offset == 0) { - report(LOG_ERR, "getether: bind: ack has no address"); - goto out; - } - if (dlp->bind_ack.dl_addr_length < EALEN) { - report(LOG_ERR, "getether: bind: ack address truncated"); - goto out; - } - /* - * Copy the Ethernet address out of the message. - */ - enaddr = tmpbuf + dlp->bind_ack.dl_addr_offset; - memcpy(eap, enaddr, EALEN); - rc = 0; - - out: - close(fd); - return rc; -} - -#define GETETHER -#endif /* SVR4 */ - - -#ifdef linux -/* - * This is really easy on Linux! This version (for linux) - * written by Nigel Metheringham <nigelm@ohm.york.ac.uk> - * - * The code is almost identical to the Ultrix code - however - * the names are different to confuse the innocent :-) - * Most of this code was stolen from the Ultrix bit above. - */ - -#include <sys/ioctl.h> -#include <net/if.h> /* struct ifreq */ - -/* In a properly configured system this should be either sys/socketio.h - or sys/sockios.h, but on my distribution these don't line up correctly */ -#include <linux/sockios.h> /* Needed for IOCTL defs */ - -getether(ifname, eap) - char *ifname, *eap; -{ - int rc = -1; - int fd; - struct ifreq phys; - bzero(&phys, sizeof(phys)); - strcpy(phys.ifr_name, ifname); - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - report(LOG_ERR, "getether: socket(INET,DGRAM) failed"); - return -1; - } - if (ioctl(fd, SIOCGIFHWADDR, &phys) < 0) { - report(LOG_ERR, "getether: ioctl SIOCGIFHWADDR failed"); - } else { - bcopy(phys.ifr_hwaddr, eap, EALEN); - rc = 0; - } - close(fd); - return rc; -} - -#define GETETHER -#endif /* linux */ - - -/* If we don't know how on this system, just return an error. */ -#ifndef GETETHER -getether(ifname, eap) - char *ifname, *eap; -{ - return -1; -} - -#endif /* !GETETHER */ - -/* - * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-argdecl-indent: 4 - * c-continued-statement-offset: 4 - * c-continued-brace-offset: -4 - * c-label-offset: -4 - * c-brace-offset: 0 - * End: - */ diff --git a/usr.sbin/bootpd/hwaddr.c b/usr.sbin/bootpd/hwaddr.c deleted file mode 100644 index ec515c40e062..000000000000 --- a/usr.sbin/bootpd/hwaddr.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * hwaddr.c - routines that deal with hardware addresses. - * (i.e. Ethernet) - */ - -#include <sys/types.h> -#include <sys/param.h> -#include <sys/socket.h> -#include <sys/ioctl.h> - -#if defined(SUNOS) || defined(SVR4) -#include <sys/sockio.h> -#endif -#ifdef SVR4 -#include <sys/stream.h> -#include <stropts.h> -#include <fcntl.h> -#endif - -#include <net/if_arp.h> -#include <netinet/in.h> -#include <stdio.h> -#ifndef NO_UNISTD -#include <unistd.h> -#endif -#include <syslog.h> - -#ifndef USE_BFUNCS -/* Yes, memcpy is OK here (no overlapped copies). */ -#include <memory.h> -#define bcopy(a,b,c) memcpy(b,a,c) -#define bzero(p,l) memset(p,0,l) -#define bcmp(a,b,c) memcmp(a,b,c) -#endif - -#include "bptypes.h" -#include "hwaddr.h" -#include "report.h" - -extern int debug; - -/* - * Hardware address lengths (in bytes) and network name based on hardware - * type code. List in order specified by Assigned Numbers RFC; Array index - * is hardware type code. Entries marked as zero are unknown to the author - * at this time. . . . - */ - -struct hwinfo hwinfolist[] = -{ - {0, "Reserved"}, /* Type 0: Reserved (don't use this) */ - {6, "Ethernet"}, /* Type 1: 10Mb Ethernet (48 bits) */ - {1, "3Mb Ethernet"}, /* Type 2: 3Mb Ethernet (8 bits) */ - {0, "AX.25"}, /* Type 3: Amateur Radio AX.25 */ - {1, "ProNET"}, /* Type 4: Proteon ProNET Token Ring */ - {0, "Chaos"}, /* Type 5: Chaos */ - {6, "IEEE 802"}, /* Type 6: IEEE 802 Networks */ - {0, "ARCNET"} /* Type 7: ARCNET */ -}; -int hwinfocnt = sizeof(hwinfolist) / sizeof(hwinfolist[0]); - - -/* - * Setup the arp cache so that IP address 'ia' will be temporarily - * bound to hardware address 'ha' of length 'len'. - */ -void -setarp(s, ia, ha, len) - int s; /* socket fd */ - struct in_addr *ia; - u_char *ha; - int len; -{ -#ifdef SIOCSARP - struct arpreq arpreq; /* Arp request ioctl block */ - struct sockaddr_in *si; -#ifdef SVR4 - int fd; - struct strioctl iocb; -#endif /* SVR4 */ - - bzero((caddr_t) & arpreq, sizeof(arpreq)); - arpreq.arp_flags = ATF_INUSE | ATF_COM; - - /* Set up the protocol address. */ - arpreq.arp_pa.sa_family = AF_INET; - si = (struct sockaddr_in *) &arpreq.arp_pa; - si->sin_addr = *ia; - - /* Set up the hardware address. */ - bcopy(ha, arpreq.arp_ha.sa_data, len); - -#ifdef SVR4 - /* - * And now the stuff for System V Rel 4.x which does not - * appear to allow SIOCxxx ioctls on a socket descriptor. - * Thanks to several people: (all sent the same fix) - * Barney Wolff <barney@databus.com>, - * bear@upsys.se (Bj|rn Sj|holm), - * Michael Kuschke <Michael.Kuschke@Materna.DE>, - */ - if ((fd=open("/dev/arp", O_RDWR)) < 0) { - report(LOG_ERR, "open /dev/arp: %s\n", get_errmsg()); - } - iocb.ic_cmd = SIOCSARP; - iocb.ic_timout = 0; - iocb.ic_dp = (char *)&arpreq; - iocb.ic_len = sizeof(arpreq); - if (ioctl(fd, I_STR, (caddr_t)&iocb) < 0) { - report(LOG_ERR, "ioctl I_STR: %s\n", get_errmsg()); - } - close (fd); - -#else /* SVR4 */ - /* - * On SunOS, the ioctl sometimes returns ENXIO, and it - * appears to happen when the ARP cache entry you tried - * to add is already in the cache. (Sigh...) - * XXX - Should this error simply be ignored? -gwr - */ - if (ioctl(s, SIOCSARP, (caddr_t) & arpreq) < 0) { - report(LOG_ERR, "ioctl SIOCSARP: %s", get_errmsg()); - } -#endif /* SVR4 */ -#else /* SIOCSARP */ - /* - * Oh well, SIOCSARP is not defined. Just run arp(8). - * XXX - Gag! - */ - char buf[256]; - int status; - - sprintf(buf, "arp -s %s %s temp", - inet_ntoa(*ia), haddrtoa(ha, len)); - if (debug > 2) - report(LOG_INFO, buf); - status = system(buf); - if (status) - report(LOG_ERR, "arp failed, exit code=0x%x", status); - return; -#endif /* SIOCSARP */ -} - - -/* - * Convert a hardware address to an ASCII string. - */ -char * -haddrtoa(haddr, hlen) - u_char *haddr; - int hlen; -{ - static char haddrbuf[3 * MAXHADDRLEN + 1]; - char *bufptr; - - if (hlen > MAXHADDRLEN) - hlen = MAXHADDRLEN; - - bufptr = haddrbuf; - while (hlen > 0) { - sprintf(bufptr, "%02X:", (unsigned) (*haddr++ & 0xFF)); - bufptr += 3; - hlen--; - } - bufptr[-1] = 0; - return (haddrbuf); -} - - -/* - * haddr_conv802() - * -------------- - * - * Converts a backwards address to a canonical address and a canonical address - * to a backwards address. - * - * INPUTS: - * adr_in - pointer to six byte string to convert (unsigned char *) - * addr_len - how many bytes to convert - * - * OUTPUTS: - * addr_out - The string is updated to contain the converted address. - * - * CALLER: - * many - * - * DATA: - * Uses conv802table to bit-reverse the address bytes. - */ - -static u_char conv802table[256] = -{ - /* 0x00 */ 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, - /* 0x08 */ 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, - /* 0x10 */ 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, - /* 0x18 */ 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, - /* 0x20 */ 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, - /* 0x28 */ 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, - /* 0x30 */ 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, - /* 0x38 */ 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, - /* 0x40 */ 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, - /* 0x48 */ 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, - /* 0x50 */ 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, - /* 0x58 */ 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, - /* 0x60 */ 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, - /* 0x68 */ 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, - /* 0x70 */ 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, - /* 0x78 */ 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, - /* 0x80 */ 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, - /* 0x88 */ 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, - /* 0x90 */ 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, - /* 0x98 */ 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, - /* 0xA0 */ 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, - /* 0xA8 */ 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, - /* 0xB0 */ 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, - /* 0xB8 */ 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, - /* 0xC0 */ 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, - /* 0xC8 */ 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, - /* 0xD0 */ 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, - /* 0xD8 */ 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, - /* 0xE0 */ 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, - /* 0xE8 */ 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, - /* 0xF0 */ 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, - /* 0xF8 */ 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF, -}; - -void -haddr_conv802(addr_in, addr_out, len) - register u_char *addr_in, *addr_out; - int len; -{ - u_char *lim; - - lim = addr_out + len; - while (addr_out < lim) - *addr_out++ = conv802table[*addr_in++]; -} - -#if 0 -/* - * For the record, here is a program to generate the - * bit-reverse table above. - */ -static int -bitrev(n) - int n; -{ - int i, r; - - r = 0; - for (i = 0; i < 8; i++) { - r <<= 1; - r |= (n & 1); - n >>= 1; - } - return r; -} - -main() -{ - int i; - for (i = 0; i <= 0xFF; i++) { - if ((i & 7) == 0) - printf("/* 0x%02X */", i); - printf(" 0x%02X,", bitrev(i)); - if ((i & 7) == 7) - printf("\n"); - } -} - -#endif - -/* - * Local Variables: - * tab-width: 4 - * c-indent-level: 4 - * c-argdecl-indent: 4 - * c-continued-statement-offset: 4 - * c-continued-brace-offset: -4 - * c-label-offset: -4 - * c-brace-offset: 0 - * End: - */ diff --git a/usr.sbin/bootpef/Makefile b/usr.sbin/bootpef/Makefile deleted file mode 100644 index dccbc69694f9..000000000000 --- a/usr.sbin/bootpef/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# bootpef/Makefile -# $Id: Makefile,v 1.2 1994/06/27 21:31:21 gwr Exp $ - -PROG= bootpef -SRCDIR= ${.CURDIR}/../bootpd -CFLAGS+= -DETC_ETHERS -DDEBUG -I${SRCDIR} -.PATH: ${SRCDIR} - -SRCS= bootpef.c dovend.c readfile.c hash.c dumptab.c \ - lookup.c hwaddr.c report.c tzone.c - -MAN8= bootpef.0 - -.include <bsd.prog.mk> - diff --git a/usr.sbin/bootpgw/Makefile b/usr.sbin/bootpgw/Makefile deleted file mode 100644 index 677868d5dfb6..000000000000 --- a/usr.sbin/bootpgw/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# bootpgw/Makefile -# $Id: Makefile,v 1.1.1.1 1994/06/27 21:29:46 gwr Exp $ - -PROG= bootpgw -SRCDIR= ${.CURDIR}/../bootpd -CFLAGS+= -DSYSLOG -DDEBUG -I${SRCDIR} -.PATH: ${SRCDIR} - -SRCS= bootpgw.c getif.c hwaddr.c report.c - -MAN8= - -.include <bsd.prog.mk> - diff --git a/usr.sbin/bootptest/Makefile b/usr.sbin/bootptest/Makefile deleted file mode 100644 index c47790ca2d24..000000000000 --- a/usr.sbin/bootptest/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# bootptest/Makefile -# $Id: Makefile,v 1.3 1994/08/22 22:19:04 gwr Exp $ - -PROG= bootptest -SRCDIR= ${.CURDIR}/../bootpd -CFLAGS+= -I${SRCDIR} -.PATH: ${SRCDIR} - -SRCS= bootptest.c print-bootp.c getif.c getether.c report.c - -MAN8= bootptest.0 - -.include <bsd.prog.mk> - diff --git a/usr.sbin/mailwrapper/Makefile b/usr.sbin/mailwrapper/Makefile deleted file mode 100644 index ed1130fbfcf7..000000000000 --- a/usr.sbin/mailwrapper/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $NetBSD: Makefile,v 1.4 1999/03/25 16:40:18 is Exp $ - -PROG= mailwrapper -MAN= mailwrapper.8 mailer.conf.5 - -DPADD+= ${LIBUTIL} -LDADD+= -lutil - -SYMLINKS= /usr/sbin/mailwrapper /usr/sbin/sendmail \ - /usr/sbin/mailwrapper /usr/bin/newaliases \ - /usr/sbin/mailwrapper /usr/bin/mailq - -.include <bsd.prog.mk> diff --git a/usr.sbin/mailwrapper/mailwrapper.8 b/usr.sbin/mailwrapper/mailwrapper.8 deleted file mode 100644 index eb34a12becc8..000000000000 --- a/usr.sbin/mailwrapper/mailwrapper.8 +++ /dev/null @@ -1,144 +0,0 @@ -.\" $NetBSD: mailwrapper.8,v 1.6 1999/03/25 16:40:17 is Exp $ -.\" -.\" Copyright (c) 1998 -.\" Perry E. Metzger. 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 acknowledgment: -.\" This product includes software developed for the NetBSD Project -.\" by Perry E. Metzger. -.\" 4. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. -.\" -.\" The following requests are required for all man pages. -.Dd December 16, 1998 -.Dt MAILWRAPPER 8 -.Os -.Sh NAME -.Nm mailwrapper -.Nd invoke appropriate MTA software based on configuration file -.Sh SYNOPSIS -Special. See below. -.Sh DESCRIPTION -At one time, the only Mail Transfer Agent (MTA) software easily available -was -.Xr sendmail 8 . -As a result of this, most Mail User Agents (MUAs) such as -.Xr mail 1 -had the path and calling conventions expected by -.Xr sendmail 8 -compiled in. -.Pp -Times have changed, however. -On a modern -.Nx -system, the administrator may wish to use one of several -available MTAs. -.Pp -It would be difficult to modify all MUA software typically available -on a system, so most of the authors of alternative MTAs have written -their front end message submission programs so that they use the same -calling conventions as -.Xr sendmail 8 -and may be put into place instead of -.Xr sendmail 8 -in -.Pa /usr/sbin/sendmail . -.Pp -.Xr sendmail 8 -also typically has aliases named -.Xr mailq 1 -and -.Xr newaliases 1 -linked to it. The program knows to behave differently when its -.Va argv[0] -is -.Dq mailq -or -.Dq newaliases -and behaves appropriately. Typically, replacement MTAs provide similar -functionality, either through a program that also switches behavior -based on calling name, or through a set of programs that provide -similar functionality. -.Pp -Although having replacement programs that plug replace -.Xr sendmail 8 -helps in installing alternative MTAs, it essentially makes the -configuration of the system depend on hard installing new programs in -.Pa /usr . -This leads to configuration problems for many administrators, since -they may wish to install a new MTA without altering the system -provided -.Pa /usr . -(This may be, for example, to avoid having upgrade problems when a new -version of the system is installed over the old.) -They may also have a shared -.Pa /usr -among several -machines, and may wish to avoid placing implicit configuration -information in a read-only -.Pa /usr . -.Pp -The -.Nm -program is designed to replace -.Pa /usr/sbin/sendmail -and to invoke an appropriate MTA instead of -.Xr sendmail 8 -based on configuration information placed in -.Pa /etc/mailer.conf . -This permits the administrator to configure which MTA is to be invoked on -the system at run time. -.Sh FILES -Configuration for -.Nm -is kept in -.Pa /etc/mailer.conf . -.Pa /usr/sbin/sendmail -is typically set up as a symlink to -.Nm -which is not usually invoked on its own. -.Sh DIAGNOSTICS -.Nm -will return an error value and print a diagnostic if its configuration -file is missing or malformed, or does not contain a mapping for the -name under which -.Nm -was invoked. -.Sh SEE ALSO -.Xr mail 1 , -.Xr mailq 1 , -.Xr mailer.conf 5 , -.Xr newaliases 1 , -.Xr sendmail 8 . -.Sh HISTORY -.Nm -appeared in -.Nx 1.4 . -.Sh AUTHORS -Perry E. Metzger <perry@piermont.com> -.Sh BUGS -The entire reason this program exists is a crock. Instead, a command -for how to submit mail should be standardized, and all the "behave -differently if invoked with a different name" behavior of things like -.Xr mailq 1 -should go away. diff --git a/usr.sbin/mailwrapper/mailwrapper.c b/usr.sbin/mailwrapper/mailwrapper.c deleted file mode 100644 index 4d7d67d1a8df..000000000000 --- a/usr.sbin/mailwrapper/mailwrapper.c +++ /dev/null @@ -1,165 +0,0 @@ -/* $NetBSD: mailwrapper.c,v 1.3 1999/05/29 18:18:15 christos Exp $ */ - -/* - * Copyright (c) 1998 - * Perry E. Metzger. 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 acknowledgment: - * This product includes software developed for the NetBSD Project - * by Perry E. Metzger. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - */ - -#include <err.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <util.h> - -#define _PATH_MAILERCONF "/etc/mailer.conf" - -struct arglist { - size_t argc, maxc; - char **argv; -}; - -int main __P((int, char *[], char *[])); - -static void initarg __P((struct arglist *)); -static void addarg __P((struct arglist *, const char *, int)); -static void freearg __P((struct arglist *, int)); - -extern const char *__progname; /* from crt0.o */ - -static void -initarg(al) - struct arglist *al; -{ - al->argc = 0; - al->maxc = 10; - if ((al->argv = malloc(al->maxc * sizeof(char *))) == NULL) - err(1, "mailwrapper"); -} - -static void -addarg(al, arg, copy) - struct arglist *al; - const char *arg; - int copy; -{ - if (al->argc == al->maxc) { - al->maxc <<= 1; - if ((al->argv = realloc(al->argv, - al->maxc * sizeof(char *))) == NULL) - err(1, "mailwrapper"); - } - if (copy) { - if ((al->argv[al->argc++] = strdup(arg)) == NULL) - err(1, "mailwrapper:"); - } else - al->argv[al->argc++] = (char *)arg; -} - -static void -freearg(al, copy) - struct arglist *al; - int copy; -{ - size_t i; - if (copy) - for (i = 0; i < al->argc; i++) - free(al->argv[i]); - free(al->argv); -} - -int -main(argc, argv, envp) - int argc; - char *argv[]; - char *envp[]; -{ - FILE *config; - char *line, *cp, *from, *to, *ap; - size_t len, lineno = 0; - struct arglist al; - - initarg(&al); - for (len = 0; len < argc; len++) - addarg(&al, argv[len], 0); - - if ((config = fopen(_PATH_MAILERCONF, "r")) == NULL) - err(1, "mailwrapper: can't open %s", _PATH_MAILERCONF); - - for (;;) { - if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL) { - if (feof(config)) - errx(1, "mailwrapper: no mapping in %s", - _PATH_MAILERCONF); - err(1, "mailwrapper"); - } - -#define WS " \t\n" - cp = line; - - cp += strspn(cp, WS); - if (cp[0] == '\0') { - /* empty line */ - free(line); - continue; - } - - if ((from = strsep(&cp, WS)) == NULL) - goto parse_error; - - cp += strspn(cp, WS); - - if ((to = strsep(&cp, WS)) == NULL) - goto parse_error; - - if (strcmp(from, __progname) == 0) { - for (ap = strsep(&cp, WS); ap != NULL; - ap = strsep(&cp, WS)) - if (*ap) - addarg(&al, ap, 0); - break; - } - - free(line); - } - - (void)fclose(config); - - execve(to, al.argv, envp); - freearg(&al, 0); - free(line); - err(1, "mailwrapper: execing %s", to); - /*NOTREACHED*/ -parse_error: - freearg(&al, 0); - free(line); - errx(1, "mailwrapper: parse error in %s at line %lu", - _PATH_MAILERCONF, (u_long)lineno); - /*NOTREACHED*/ -} diff --git a/usr.sbin/newsyslog/Makefile b/usr.sbin/newsyslog/Makefile deleted file mode 100644 index c04af65ac0db..000000000000 --- a/usr.sbin/newsyslog/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# $Id: Makefile,v 1.6 1994/12/22 12:30:26 cgd Exp $ - -PROG= newsyslog - -CFLAGS+= -DOSF -CFLAGS+= -DCONF=\"/etc/newsyslog.conf\" -CFLAGS+= -DPIDFILE=\"/var/run/syslog.pid\" -CFLAGS+= -DCOMPRESS=\"/usr/bin/gzip\" -CFLAGS+= -DCOMPRESS_POSTFIX=\".gz\" - -BINOWN= root - -MAN8= newsyslog.8 - -.include <bsd.prog.mk> diff --git a/usr.sbin/newsyslog/newsyslog.8 b/usr.sbin/newsyslog/newsyslog.8 deleted file mode 100644 index 72e481655db3..000000000000 --- a/usr.sbin/newsyslog/newsyslog.8 +++ /dev/null @@ -1,168 +0,0 @@ -.TH NEWSYSLOG 8 "January 12, 1989" "Project Athena" -.ns -.\" This file contains changes from the Open Software Foundation. -.\" -.\" from: @(#)newsyslog.8 -.\" $Id: newsyslog.8,v 1.6 1995/01/06 19:20:20 jtc Exp $ -.\" -.\" Copyright 1988, 1989 by the Massachusetts Institute of Technology -.\" -.\" Permission to use, copy, modify, and distribute this software -.\" and its documentation for any purpose and without fee is -.\" hereby granted, provided that the above copyright notice -.\" appear in all copies and that both that copyright notice and -.\" this permission notice appear in supporting documentation, -.\" and that the names of M.I.T. and the M.I.T. S.I.P.B. not be -.\" used in advertising or publicity pertaining to distribution -.\" of the software without specific, written prior permission. -.\" M.I.T. and the M.I.T. S.I.P.B. make no representations about -.\" the suitability of this software for any purpose. It is -.\" provided "as is" without express or implied warranty. -.\" -.sp -.SH NAME -newsyslog \- maintain system log files to manageable sizes -.SH SYNOPSIS -.B /usr/bin/newsyslog -[ -.B \-vnr -] [ -.B \-f -.I configuration file -] -.SH DESCRIPTION -.I Newsyslog -is a program that should be scheduled to run periodically by -.IR crontab . -When it is executed it archives log files if necessary. If a log file -is determined to require archiving, -.I newsyslog -rearranges the files so that ``logfile'' is empty, ``logfile.0'' has -the last period's logs in it, ``logfile.1'' has the next to last -period's logs in it, and so on, up to a user-specified number of -archived logs. Optionally the archived logs can be compressed to save -space. -.PP -A log can be archived because of two reasons. The log file can have -grown bigger than a preset size in kilobytes, or a preset number of -hours may have elapsed since the last log archive. The granularity of -.I newsyslog -is dependent on how often it is scheduled to run in crontab. Since -the program is quite fast, it may be scheduled to run every hour -without any ill effects. -.PP -When starting up, -.I newsyslog -reads in a configuration file to determine which logs should be looked -at. By default, this configuration file is -.IR /etc/newsyslog.conf . -Each line of the file contains information about a particular log file -that should be handled by -.IR newsyslog . -Each line has five mandatory fields and two optional fields, with a -whitespace separating each field. Blank lines or lines beginning with -``#'' are ignored. The fields of the configuration file are as -follows: -.br - logfile name -.br - owner.group of archives (optional) -.br - mode of logfile & archives -.br - number of archives -.br - size of archives -.br - archive interval -.br - flags (optional) -.PP -The -.I logfile name -entry is the name of the system log file to be archived. -.PP -The optional -.I owner.group -entry specifies an ownership and group for the archive file. -The "." is essential, even if the -.I owner -or -.I group -field is left blank. The -fields may be numeric, or a name which is looked up in -.I /etc/passwd -or -.IR /etc/group . -.PP -The -.I number of archives -entry specifies the number of archives to be kept besides the log file -itself. -.PP -When the size of the logfile reaches -.I size of -.IR archives , -the logfile becomes trimmed as described above. If this field is -replaced by a ``*'', then the size of the logfile is not taken into -account when determining when to trim the log file. -.PP -The -.I number of hours -entry specifies the time separation between the trimming of the log -file. If this field is replaced by a ``*'', then the number of hours -since the last time the log was trimmed will not be taken into -consideration. -.PP -The -.I flags -field specifies if the archives should have any special processing -done to the archived log files. The ``Z'' flag will make the archive -files compressed to save space using /usr/bin/gzip. The ``B'' flag -means that the file is a binary file, and so the ascii message which -.I newsyslog -inserts to indicate the fact that the logs have been turned over -should not be included. -.PP -.SH OPTIONS -The following options can be used with newsyslog: -.TP -.B \-f \fIconfig-file -instructs newsyslog to use -.I config-file -instead of /etc/newsyslog.conf for its configuration file. -.TP -.B \-v -places -.I newsyslog -in verbose mode. In this mode it will print out each log and its -reasons for either trimming that log or skipping it. -.TP -.B \-n -causes -.I newsyslog -not to trim the logs, but to print out what it would do if this option -were not specified. -.TP -.B \-r -removes the restriction that -.I newsyslog -must be running as root. Of course, -.I newsyslog -will not be able to send a HUP signal to -.IR syslogd , -so this option should only be used in debugging. -.SH FILES -/etc/newsyslog.conf -.SH BUGS -Doesn't yet automatically read the logs to find security breaches. - - -.SH AUTHOR -Theodore Ts'o, MIT Project Athena -.br -Copyright 1987, Massachusetts Institute of Technology -.SH "SEE ALSO" -syslogd(8), syslog(3), gzip(1) -.ns -.sp diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c deleted file mode 100644 index ba21b6ee84e6..000000000000 --- a/usr.sbin/newsyslog/newsyslog.c +++ /dev/null @@ -1,568 +0,0 @@ -/* - * This file contains changes from the Open Software Foundation. - */ - -/* - -Copyright 1988, 1989 by the Massachusetts Institute of Technology - -Permission to use, copy, modify, and distribute this software -and its documentation for any purpose and without fee is -hereby granted, provided that the above copyright notice -appear in all copies and that both that copyright notice and -this permission notice appear in supporting documentation, -and that the names of M.I.T. and the M.I.T. S.I.P.B. not be -used in advertising or publicity pertaining to distribution -of the software without specific, written prior permission. -M.I.T. and the M.I.T. S.I.P.B. make no representations about -the suitability of this software for any purpose. It is -provided "as is" without express or implied warranty. - -*/ - -/* - * newsyslog - roll over selected logs at the appropriate time, - * keeping the a specified number of backup files around. - * - * $Source: /a/cvsroot/src/usr.bin/newsyslog/newsyslog.c,v $ - * $Author: jtc $ - */ - -#ifndef lint -static char rcsid[] = "$Id: newsyslog.c,v 1.9 1995/01/21 21:53:46 jtc Exp $"; -#endif /* not lint */ - -#ifndef CONF -#define CONF "/etc/athena/newsyslog.conf" /* Configuration file */ -#endif -#ifndef PIDFILE -#define PIDFILE "/etc/syslog.pid" -#endif -#ifndef COMPRESS -#define COMPRESS "/usr/ucb/compress" /* File compression program */ -#endif -#ifndef COMPRESS_POSTFIX -#define COMPRESS_POSTFIX ".Z" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <signal.h> -#include <pwd.h> -#include <grp.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/stat.h> -#include <sys/param.h> -#include <sys/wait.h> - -#define kbytes(size) (((size) + 1023) >> 10) -#ifdef _IBMR2 -/* Calculates (db * DEV_BSIZE) */ -#define dbtob(db) ((unsigned)(db) << UBSHIFT) -#endif - -#define CE_COMPACT 1 /* Compact the achived log files */ -#define CE_BINARY 2 /* Logfile is in binary, don't add */ - /* status messages */ -#define NONE -1 - -struct conf_entry { - char *log; /* Name of the log */ - int uid; /* Owner of log */ - int gid; /* Group of log */ - int numlogs; /* Number of logs to keep */ - int size; /* Size cutoff to trigger trimming the log */ - int hours; /* Hours between log trimming */ - int permissions; /* File permissions on the log */ - int flags; /* Flags (CE_COMPACT & CE_BINARY) */ - struct conf_entry *next; /* Linked list pointer */ -}; - -extern int optind; -extern char *optarg; -extern char *malloc(); -extern uid_t getuid(),geteuid(); -extern time_t time(); - -char *progname; /* contains argv[0] */ -int verbose = 0; /* Print out what's going on */ -int needroot = 1; /* Root privs are necessary */ -int noaction = 0; /* Don't do anything, just show it */ -char *conf = CONF; /* Configuration file to use */ -time_t timenow; -int syslog_pid; /* read in from /etc/syslog.pid */ -#define MIN_PID 3 -#define MAX_PID 65534 -char hostname[64]; /* hostname */ -char *daytime; /* timenow in human readable form */ - - -struct conf_entry *parse_file(); -char *sob(), *son(), *strdup(), *missing_field(); - -main(argc,argv) - int argc; - char **argv; -{ - struct conf_entry *p, *q; - - PRS(argc,argv); - if (needroot && getuid() && geteuid()) { - fprintf(stderr,"%s: must have root privs\n",progname); - exit(1); - } - p = q = parse_file(); - while (p) { - do_entry(p); - p=p->next; - free((char *) q); - q=p; - } - exit(0); -} - -do_entry(ent) - struct conf_entry *ent; - -{ - int size, modtime; - - if (verbose) { - if (ent->flags & CE_COMPACT) - printf("%s <%dZ>: ",ent->log,ent->numlogs); - else - printf("%s <%d>: ",ent->log,ent->numlogs); - } - size = sizefile(ent->log); - modtime = age_old_log(ent->log); - if (size < 0) { - if (verbose) - printf("does not exist.\n"); - } else { - if (verbose && (ent->size > 0)) - printf("size (Kb): %d [%d] ", size, ent->size); - if (verbose && (ent->hours > 0)) - printf(" age (hr): %d [%d] ", modtime, ent->hours); - if (((ent->size > 0) && (size >= ent->size)) || - ((ent->hours > 0) && ((modtime >= ent->hours) - || (modtime < 0)))) { - if (verbose) - printf("--> trimming log....\n"); - if (noaction && !verbose) { - if (ent->flags & CE_COMPACT) - printf("%s <%dZ>: trimming", - ent->log,ent->numlogs); - else - printf("%s <%d>: trimming", - ent->log,ent->numlogs); - } - dotrim(ent->log, ent->numlogs, ent->flags, - ent->permissions, ent->uid, ent->gid); - } else { - if (verbose) - printf("--> skipping\n"); - } - } -} - -PRS(argc,argv) - int argc; - char **argv; -{ - int c; - FILE *f; - char line[BUFSIZ]; - char *p; - - progname = argv[0]; - timenow = time((time_t *) 0); - daytime = ctime(&timenow) + 4; - daytime[16] = '\0'; - - /* Let's find the pid of syslogd */ - syslog_pid = 0; - f = fopen(PIDFILE,"r"); - if (f && fgets(line,BUFSIZ,f)) - syslog_pid = atoi(line); - if (f) - (void)fclose(f); - - /* Let's get our hostname */ - (void) gethostname(hostname, sizeof(hostname)); - - /* Truncate domain */ - if (p = strchr(hostname, '.')) { - *p = '\0'; - } - - optind = 1; /* Start options parsing */ - while ((c=getopt(argc,argv,"nrvf:t:")) != EOF) - switch (c) { - case 'n': - noaction++; /* This implies needroot as off */ - /* fall through */ - case 'r': - needroot = 0; - break; - case 'v': - verbose++; - break; - case 'f': - conf = optarg; - break; - default: - usage(); - } - } - -usage() -{ - fprintf(stderr, - "Usage: %s <-nrv> <-f config-file>\n", progname); - exit(1); -} - -/* Parse a configuration file and return a linked list of all the logs - * to process - */ -struct conf_entry *parse_file() -{ - FILE *f; - char line[BUFSIZ], *parse, *q; - char *errline, *group; - struct conf_entry *first = NULL; - struct conf_entry *working; - struct passwd *pass; - struct group *grp; - - if (strcmp(conf,"-")) - f = fopen(conf,"r"); - else - f = stdin; - if (!f) { - (void) fprintf(stderr,"%s: ",progname); - perror(conf); - exit(1); - } - while (fgets(line,BUFSIZ,f)) { - if ((line[0]== '\n') || (line[0] == '#')) - continue; - errline = strdup(line); - if (!first) { - working = (struct conf_entry *) malloc(sizeof(struct conf_entry)); - first = working; - } else { - working->next = (struct conf_entry *) malloc(sizeof(struct conf_entry)); - working = working->next; - } - - q = parse = missing_field(sob(line),errline); - *(parse = son(line)) = '\0'; - working->log = strdup(q); - - q = parse = missing_field(sob(++parse),errline); - *(parse = son(parse)) = '\0'; - if ((group = strchr(q, '.')) != NULL) { - *group++ = '\0'; - if (*q) { - if (!(isnumber(*q))) { - if ((pass = getpwnam(q)) == NULL) { - fprintf(stderr, - "Error in config file; unknown user:\n"); - fputs(errline,stderr); - exit(1); - } - working->uid = pass->pw_uid; - } else - working->uid = atoi(q); - } else - working->uid = NONE; - - q = group; - if (*q) { - if (!(isnumber(*q))) { - if ((grp = getgrnam(q)) == NULL) { - fprintf(stderr, - "Error in config file; unknown group:\n"); - fputs(errline,stderr); - exit(1); - } - working->gid = grp->gr_gid; - } else - working->gid = atoi(q); - } else - working->gid = NONE; - - q = parse = missing_field(sob(++parse),errline); - *(parse = son(parse)) = '\0'; - } - else - working->uid = working->gid = NONE; - - if (!sscanf(q,"%o",&working->permissions)) { - fprintf(stderr, - "Error in config file; bad permissions:\n"); - fputs(errline,stderr); - exit(1); - } - - q = parse = missing_field(sob(++parse),errline); - *(parse = son(parse)) = '\0'; - if (!sscanf(q,"%d",&working->numlogs)) { - fprintf(stderr, - "Error in config file; bad number:\n"); - fputs(errline,stderr); - exit(1); - } - - q = parse = missing_field(sob(++parse),errline); - *(parse = son(parse)) = '\0'; - if (isdigit(*q)) - working->size = atoi(q); - else - working->size = -1; - - q = parse = missing_field(sob(++parse),errline); - *(parse = son(parse)) = '\0'; - if (isdigit(*q)) - working->hours = atoi(q); - else - working->hours = -1; - - q = parse = sob(++parse); /* Optional field */ - *(parse = son(parse)) = '\0'; - working->flags = 0; - while (q && *q && !isspace(*q)) { - if ((*q == 'Z') || (*q == 'z')) - working->flags |= CE_COMPACT; - else if ((*q == 'B') || (*q == 'b')) - working->flags |= CE_BINARY; - else { - fprintf(stderr, - "Illegal flag in config file -- %c\n", - *q); - exit(1); - } - q++; - } - - free(errline); - } - if (working) - working->next = (struct conf_entry *) NULL; - (void) fclose(f); - return(first); -} - -char *missing_field(p,errline) - char *p,*errline; -{ - if (!p || !*p) { - fprintf(stderr,"Missing field in config file:\n"); - fputs(errline,stderr); - exit(1); - } - return(p); -} - -dotrim(log,numdays,flags,perm,owner_uid,group_gid) - char *log; - int numdays; - int flags; - int perm; - int owner_uid; - int group_gid; -{ - char file1[128], file2[128]; - char zfile1[128], zfile2[128]; - int fd; - struct stat st; - -#ifdef _IBMR2 -/* AIX 3.1 has a broken fchown- if the owner_uid is -1, it will actually */ -/* change it to be owned by uid -1, instead of leaving it as is, as it is */ -/* supposed to. */ - if (owner_uid == -1) - owner_uid = geteuid(); -#endif - - /* Remove oldest log */ - (void) sprintf(file1,"%s.%d",log,numdays); - (void) strcpy(zfile1, file1); - (void) strcat(zfile1, COMPRESS_POSTFIX); - - if (noaction) { - printf("rm -f %s\n", file1); - printf("rm -f %s\n", zfile1); - } else { - (void) unlink(file1); - (void) unlink(zfile1); - } - - /* Move down log files */ - while (numdays--) { - (void) strcpy(file2,file1); - (void) sprintf(file1,"%s.%d",log,numdays); - (void) strcpy(zfile1, file1); - (void) strcpy(zfile2, file2); - if (lstat(file1, &st)) { - (void) strcat(zfile1, COMPRESS_POSTFIX); - (void) strcat(zfile2, COMPRESS_POSTFIX); - if (lstat(zfile1, &st)) continue; - } - if (noaction) { - printf("mv %s %s\n",zfile1,zfile2); - printf("chmod %o %s\n", perm, zfile2); - printf("chown %d.%d %s\n", - owner_uid, group_gid, zfile2); - } else { - (void) rename(zfile1, zfile2); - (void) chmod(zfile2, perm); - (void) chown(zfile2, owner_uid, group_gid); - } - } - if (!noaction && !(flags & CE_BINARY)) - (void) log_trim(log); /* Report the trimming to the old log */ - - if (noaction) - printf("mv %s to %s\n",log,file1); - else - (void) rename(log,file1); - if (noaction) - printf("Start new log..."); - else { - fd = creat(log,perm); - if (fd < 0) { - perror("can't start new log"); - exit(1); - } - if (fchown(fd, owner_uid, group_gid)) { - perror("can't chmod new log file"); - exit(1); - } - (void) close(fd); - if (!(flags & CE_BINARY)) - if (log_trim(log)) { /* Add status message */ - perror("can't add status message to log"); - exit(1); - } - } - if (noaction) - printf("chmod %o %s...",perm,log); - else - (void) chmod(log,perm); - if (noaction) - printf("kill -HUP %d (syslogd)\n",syslog_pid); - else - if (syslog_pid < MIN_PID || syslog_pid > MAX_PID) { - fprintf(stderr,"%s: preposterous process number: %d\n", - progname, syslog_pid); - } else if (kill(syslog_pid,SIGHUP)) { - fprintf(stderr,"%s: ",progname); - perror("warning - could not restart syslogd"); - } - if (flags & CE_COMPACT) { - if (noaction) - printf("Compress %s.0\n",log); - else - compress_log(log); - } -} - -/* Log the fact that the logs were turned over */ -log_trim(log) - char *log; -{ - FILE *f; - if ((f = fopen(log,"a")) == NULL) - return(-1); - fprintf(f,"%s %s newsyslog[%d]: logfile turned over\n", - daytime, hostname, getpid()); - if (fclose(f) == EOF) { - perror("log_trim: fclose:"); - exit(1); - } - return(0); -} - -/* Fork of /usr/ucb/compress to compress the old log file */ -compress_log(log) - char *log; -{ - int pid; - char tmp[128]; - - pid = fork(); - (void) sprintf(tmp,"%s.0",log); - if (pid < 0) { - fprintf(stderr,"%s: ",progname); - perror("fork"); - exit(1); - } else if (!pid) { - (void) execl(COMPRESS,"compress","-f",tmp,0); - fprintf(stderr,"%s: ",progname); - perror(COMPRESS); - exit(1); - } -} - -/* Return size in kilobytes of a file */ -int sizefile(file) - char *file; -{ - struct stat sb; - - if (stat(file,&sb) < 0) - return(-1); - return(kbytes(dbtob(sb.st_blocks))); -} - -/* Return the age of old log file (file.0) */ -int age_old_log(file) - char *file; -{ - struct stat sb; - char tmp[MAXPATHLEN+3]; - - (void) strcpy(tmp,file); - if (stat(strcat(tmp,".0"),&sb) < 0) - if (stat(strcat(tmp,COMPRESS_POSTFIX), &sb) < 0) - return(-1); - return( (int) (timenow - sb.st_mtime + 1800) / 3600); -} - - -#ifndef OSF -/* Duplicate a string using malloc */ - -char *strdup(strp) -register char *strp; -{ - register char *cp; - - if ((cp = malloc((unsigned) strlen(strp) + 1)) == NULL) - abort(); - return(strcpy (cp, strp)); -} -#endif - -/* Skip Over Blanks */ -char *sob(p) - register char *p; -{ - while (p && *p && isspace(*p)) - p++; - return(p); -} - -/* Skip Over Non-Blanks */ -char *son(p) - register char *p; -{ - while (p && *p && !isspace(*p)) - p++; - return(p); -} diff --git a/usr.sbin/quot/Makefile b/usr.sbin/quot/Makefile deleted file mode 100644 index aca581b820d3..000000000000 --- a/usr.sbin/quot/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $Id: Makefile,v 1.3 1994/12/22 11:39:03 cgd Exp $ - -PROG= quot -MAN= quot.8 - -.include <bsd.prog.mk> diff --git a/usr.sbin/quot/quot.8 b/usr.sbin/quot/quot.8 deleted file mode 100644 index 7b964d944c33..000000000000 --- a/usr.sbin/quot/quot.8 +++ /dev/null @@ -1,96 +0,0 @@ -.\" Copyright (C) 1994 Wolfgang Solfrank. -.\" Copyright (C) 1994 TooLs GmbH. -.\" 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 TooLs GmbH. -.\" 4. The name of TooLs GmbH may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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. -.\" -.\" $Id: quot.8,v 1.3 1994/03/19 07:59:47 cgd Exp $ -.\" -.Dd February 8, 1994 -.Dt QUOT 8 -.Os BSD 4 -.Sh NAME -.Nm quot -.Nd display disk space occupied by each user -.Sh SYNOPSIS -.Nm quot -.Op Fl acfhknv -.Op Ar filesystem ... -.Sh DESCRIPTION -.Nm Quot -is used to gather statistics about the disk usage for each local user. -.Pp -The following options are available: -.Bl -tag -width Ds -.It Fl a -Include statistics for all mounted filesystems. -.It Fl c -Display three columns containing number of blocks per file, -number of files in this category, and aggregate total of -blocks in files with this or lower size. -.It Fl f -For each user, display count of files and space occupied. -.It Fl h -Estimate the number of blocks in each file based on its size. -Despite that this doesn't give the correct resuls (it doesn't -account for the holes in files), this option isn't any faster -and thus is discouraged. -.It Fl k -By default, all sizes are reported in 512-byte block counts. -The -.Fl k -options causes the numbers to be reported in kilobyte counts. -.It Fl n -Given a list of inodes (plus some optional data on each line) -in the standard input, for each file print out the owner (plus -the remainder of the input line). This is traditionally used -in the pipe: -.Bd -literal -offset indent -ncheck filesystem | sort +0n | quot -n filesystem -.Ed -.Pp -to get a report of files and their owners. -.It Fl v -In addition to the default output, display the number of files -not accessed within 30, 60 and 90 days. -.El -.Sh ENVIRONMENTAL VARIABLES -.Bl -tag -width BLOCKSIZE -.It Ev BLOCKSIZE -If the environmental variable -.Ev BLOCKSIZE -is set, and the -.Gl k -option is not specified, the block counts will be displayed in units of that -size block. -.El -.\".Sh BUGS -.Sh SEE ALSO -.Xr df 1 , -.Xr quota 1 , -.Xr getmntinfo 3 , -.Xr fstab 5 , -.Xr mount 8 , diff --git a/usr.sbin/quot/quot.c b/usr.sbin/quot/quot.c deleted file mode 100644 index e5f2daad68c7..000000000000 --- a/usr.sbin/quot/quot.c +++ /dev/null @@ -1,583 +0,0 @@ -/* - * Copyright (C) 1991, 1994 Wolfgang Solfrank. - * Copyright (C) 1991, 1994 TooLs GmbH. - * 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 TooLs GmbH. - * 4. The name of TooLs GmbH may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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 rcsid[] = "$Id: quot.c,v 1.6.4.1 1995/11/01 00:06:41 jtc Exp $"; -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/time.h> -#include <ufs/ffs/fs.h> -#include <ufs/ufs/quota.h> -#include <ufs/ufs/inode.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include <pwd.h> - -/* some flags of what to do: */ -static char estimate; -static char count; -static char unused; -static int (*func)(); -static long blocksize; -static char *header; -static int headerlen; - -/* - * Original BSD quot doesn't round to number of frags/blocks, - * doesn't account for indirection blocks and gets it totally - * wrong if the size is a multiple of the blocksize. - * The new code always counts the number of 512 byte blocks - * instead of the number of kilobytes and converts them to - * kByte when done (on request). - */ -#ifdef COMPAT -#define SIZE(n) (n) -#else -#define SIZE(n) (((n) * 512 + blocksize - 1)/blocksize) -#endif - -#define INOCNT(fs) ((fs)->fs_ipg) -#define INOSZ(fs) (sizeof(struct dinode) * INOCNT(fs)) - -static struct dinode *get_inode(fd,super,ino) - struct fs *super; - ino_t ino; -{ - static struct dinode *ip; - static ino_t last; - - if (fd < 0) { /* flush cache */ - if (ip) { - free(ip); - ip = 0; - } - return 0; - } - - if (!ip || ino < last || ino >= last + INOCNT(super)) { - if (!ip - && !(ip = (struct dinode *)malloc(INOSZ(super)))) { - perror("allocate inodes"); - exit(1); - } - last = (ino / INOCNT(super)) * INOCNT(super); - if (lseek(fd,ino_to_fsba(super,last) << super->fs_fshift,0) < 0 - || read(fd,ip,INOSZ(super)) != INOSZ(super)) { - perror("read inodes"); - exit(1); - } - } - - return ip + ino % INOCNT(super); -} - -#ifdef COMPAT -#define actualblocks(super,ip) ((ip)->di_blocks/2) -#else -#define actualblocks(super,ip) ((ip)->di_blocks) -#endif - -static virtualblocks(super,ip) - struct fs *super; - struct dinode *ip; -{ - register off_t nblk, sz; - - sz = ip->di_size; -#ifdef COMPAT - if (lblkno(super,sz) >= NDADDR) { - nblk = blkroundup(super,sz); - if (sz == nblk) - nblk += super->fs_bsize; - } - - return sz / 1024; - -#else /* COMPAT */ - - if (lblkno(super,sz) >= NDADDR) { - nblk = blkroundup(super,sz); - sz = lblkno(super,nblk); - sz = (sz - NDADDR + NINDIR(super) - 1) / NINDIR(super); - while (sz > 0) { - nblk += sz * super->fs_bsize; - /* sz - 1 rounded up */ - sz = (sz - 1 + NINDIR(super) - 1) / NINDIR(super); - } - } else - nblk = fragroundup(super,sz); - - return nblk / 512; -#endif /* COMPAT */ -} - -static isfree(ip) - struct dinode *ip; -{ -#ifdef COMPAT - return (ip->di_mode&IFMT) == 0; -#else /* COMPAT */ - - switch (ip->di_mode&IFMT) { - case IFIFO: - case IFLNK: /* should check FASTSYMLINK? */ - case IFDIR: - case IFREG: - return 0; - default: - return 1; - } -#endif -} - -static struct user { - uid_t uid; - char *name; - daddr_t space; - long count; - daddr_t spc30; - daddr_t spc60; - daddr_t spc90; -} *users; -static int nusers; - -static inituser() -{ - register i; - register struct user *usr; - - if (!nusers) { - nusers = 8; - if (!(users = - (struct user *)calloc(nusers,sizeof(struct user)))) { - perror("allocate users"); - exit(1); - } - } else { - for (usr = users, i = nusers; --i >= 0; usr++) { - usr->space = usr->spc30 = usr->spc60 = usr->spc90 = 0; - usr->count = 0; - } - } -} - -static usrrehash() -{ - register i; - register struct user *usr, *usrn; - struct user *svusr; - - svusr = users; - nusers <<= 1; - if (!(users = (struct user *)calloc(nusers,sizeof(struct user)))) { - perror("allocate users"); - exit(1); - } - for (usr = svusr, i = nusers >> 1; --i >= 0; usr++) { - for (usrn = users + (usr->uid&(nusers - 1)); usrn->name; - usrn--) { - if (usrn <= users) - usrn = users + nusers; - } - *usrn = *usr; - } -} - -static struct user *user(uid) - uid_t uid; -{ - register struct user *usr; - register i; - struct passwd *pwd; - - while (1) { - for (usr = users + (uid&(nusers - 1)), i = nusers; --i >= 0; - usr--) { - if (!usr->name) { - usr->uid = uid; - - if (!(pwd = getpwuid(uid))) { - if (usr->name = (char *)malloc(7)) - sprintf(usr->name,"#%d",uid); - } else { - if (usr->name = (char *) - malloc(strlen(pwd->pw_name) + 1)) - strcpy(usr->name,pwd->pw_name); - } - if (!usr->name) { - perror("allocate users"); - exit(1); - } - - return usr; - - } else if (usr->uid == uid) - return usr; - - if (usr <= users) - usr = users + nusers; - } - usrrehash(); - } -} - -static cmpusers(u1,u2) - struct user *u1, *u2; -{ - return u2->space - u1->space; -} - -#define sortusers(users) (qsort((users),nusers,sizeof(struct user), \ - cmpusers)) - -static uses(uid,blks,act) - uid_t uid; - daddr_t blks; - time_t act; -{ - static time_t today; - register struct user *usr; - - if (!today) - time(&today); - - usr = user(uid); - usr->count++; - usr->space += blks; - - if (today - act > 90L * 24L * 60L * 60L) - usr->spc90 += blks; - if (today - act > 60L * 24L * 60L * 60L) - usr->spc60 += blks; - if (today - act > 30L * 24L * 60L * 60L) - usr->spc30 += blks; -} - -#ifdef COMPAT -#define FSZCNT 500 -#else -#define FSZCNT 512 -#endif -struct fsizes { - struct fsizes *fsz_next; - daddr_t fsz_first, fsz_last; - ino_t fsz_count[FSZCNT]; - daddr_t fsz_sz[FSZCNT]; -} *fsizes; - -static initfsizes() -{ - register struct fsizes *fp; - register i; - - for (fp = fsizes; fp; fp = fp->fsz_next) { - for (i = FSZCNT; --i >= 0;) { - fp->fsz_count[i] = 0; - fp->fsz_sz[i] = 0; - } - } -} - -static dofsizes(fd,super,name) - struct fs *super; - char *name; -{ - ino_t inode, maxino; - struct dinode *ip; - daddr_t sz, ksz; - struct fsizes *fp, **fsp; - register i; - - maxino = super->fs_ncg * super->fs_ipg - 1; -#ifdef COMPAT - if (!(fsizes = (struct fsizes *)malloc(sizeof(struct fsizes)))) { - perror("alloc fsize structure"); - exit(1); - } -#endif /* COMPAT */ - for (inode = 0; inode < maxino; inode++) { - errno = 0; - if ((ip = get_inode(fd,super,inode)) -#ifdef COMPAT - && ((ip->di_mode&IFMT) == IFREG - || (ip->di_mode&IFMT) == IFDIR) -#else /* COMPAT */ - && !isfree(ip) -#endif /* COMPAT */ - ) { - sz = estimate ? virtualblocks(super,ip) : - actualblocks(super,ip); -#ifdef COMPAT - if (sz >= FSZCNT) { - fsizes->fsz_count[FSZCNT-1]++; - fsizes->fsz_sz[FSZCNT-1] += sz; - } else { - fsizes->fsz_count[sz]++; - fsizes->fsz_sz[sz] += sz; - } -#else /* COMPAT */ - ksz = SIZE(sz); - for (fsp = &fsizes; fp = *fsp; fsp = &fp->fsz_next) { - if (ksz < fp->fsz_last) - break; - } - if (!fp || ksz < fp->fsz_first) { - if (!(fp = (struct fsizes *) - malloc(sizeof(struct fsizes)))) { - perror("alloc fsize structure"); - exit(1); - } - fp->fsz_next = *fsp; - *fsp = fp; - fp->fsz_first = (ksz / FSZCNT) * FSZCNT; - fp->fsz_last = fp->fsz_first + FSZCNT; - for (i = FSZCNT; --i >= 0;) { - fp->fsz_count[i] = 0; - fp->fsz_sz[i] = 0; - } - } - fp->fsz_count[ksz % FSZCNT]++; - fp->fsz_sz[ksz % FSZCNT] += sz; -#endif /* COMPAT */ - } else if (errno) { - perror(name); - exit(1); - } - } - sz = 0; - for (fp = fsizes; fp; fp = fp->fsz_next) { - for (i = 0; i < FSZCNT; i++) { - if (fp->fsz_count[i]) - printf("%d\t%d\t%d\n",fp->fsz_first + i, - fp->fsz_count[i], - SIZE(sz += fp->fsz_sz[i])); - } - } -} - -static douser(fd,super,name) - struct fs *super; - char *name; -{ - ino_t inode, maxino; - struct user *usr, *usrs; - struct dinode *ip; - register n; - - maxino = super->fs_ncg * super->fs_ipg - 1; - for (inode = 0; inode < maxino; inode++) { - errno = 0; - if ((ip = get_inode(fd,super,inode)) - && !isfree(ip)) - uses(ip->di_uid, - estimate ? virtualblocks(super,ip) : - actualblocks(super,ip), - ip->di_atime); - else if (errno) { - perror(name); - exit(1); - } - } - if (!(usrs = (struct user *)malloc(nusers * sizeof(struct user)))) { - perror("allocate users"); - exit(1); - } - bcopy(users,usrs,nusers * sizeof(struct user)); - sortusers(usrs); - for (usr = usrs, n = nusers; --n >= 0 && usr->count; usr++) { - printf("%5d",SIZE(usr->space)); - if (count) - printf("\t%5d",usr->count); - printf("\t%-8s",usr->name); - if (unused) - printf("\t%5d\t%5d\t%5d", - SIZE(usr->spc30), - SIZE(usr->spc60), - SIZE(usr->spc90)); - printf("\n"); - } - free(usrs); -} - -static donames(fd,super,name) - struct fs *super; - char *name; -{ - int c; - ino_t inode, inode1; - ino_t maxino; - struct dinode *ip; - - maxino = super->fs_ncg * super->fs_ipg - 1; - /* first skip the name of the filesystem */ - while ((c = getchar()) != EOF && (c < '0' || c > '9')) - while ((c = getchar()) != EOF && c != '\n'); - ungetc(c,stdin); - inode1 = -1; - while (scanf("%d",&inode) == 1) { - if (inode < 0 || inode > maxino) { - fprintf(stderr,"illegal inode %d\n",inode); - return; - } - errno = 0; - if ((ip = get_inode(fd,super,inode)) - && !isfree(ip)) { - printf("%s\t",user(ip->di_uid)->name); - /* now skip whitespace */ - while ((c = getchar()) == ' ' || c == '\t'); - /* and print out the remainder of the input line */ - while (c != EOF && c != '\n') { - putchar(c); - c = getchar(); - } - putchar('\n'); - inode1 = inode; - } else { - if (errno) { - perror(name); - exit(1); - } - /* skip this line */ - while ((c = getchar()) != EOF && c != '\n'); - } - if (c == EOF) - break; - } -} - -static usage() -{ -#ifdef COMPAT - fprintf(stderr,"Usage: quot [-nfcvha] [filesystem ...]\n"); -#else /* COMPAT */ - fprintf(stderr,"Usage: quot [ -acfhknv ] [ filesystem ... ]\n"); -#endif /* COMPAT */ - exit(1); -} - -static char superblock[SBSIZE]; - -quot(name,mp) - char *name, *mp; -{ - int fd; - - get_inode(-1); /* flush cache */ - inituser(); - initfsizes(); - if ((fd = open(name,0)) < 0 - || lseek(fd,SBOFF,0) != SBOFF - || read(fd,superblock,SBSIZE) != SBSIZE) { - perror(name); - close(fd); - return; - } - if (((struct fs *)superblock)->fs_magic != FS_MAGIC) { - fprintf(stderr,"%s: not a BSD filesystem\n",name); - close(fd); - return; - } - printf("%s:",name); - if (mp) - printf(" (%s)",mp); - putchar('\n'); - (*func)(fd,superblock,name); - close(fd); -} - -int main(argc,argv) - char **argv; -{ - int fd; - char all = 0; - FILE *fp; - struct statfs *mp; - char dev[MNAMELEN + 1]; - char *nm; - int cnt; - - func = douser; -#ifndef COMPAT - header = getbsize(&headerlen,&blocksize); -#endif - while (--argc > 0 && **++argv == '-') { - while (*++*argv) { - switch (**argv) { - case 'n': - func = donames; - break; - case 'c': - func = dofsizes; - break; - case 'a': - all = 1; - break; - case 'f': - count = 1; - break; - case 'h': - estimate = 1; - break; -#ifndef COMPAT - case 'k': - blocksize = 1024; - break; -#endif /* COMPAT */ - case 'v': - unused = 1; - break; - default: - usage(); - } - } - } - if (all) { - cnt = getmntinfo(&mp,MNT_NOWAIT); - for (; --cnt >= 0; mp++) { - if (!strncmp(mp->f_fstypename, MOUNT_FFS, MFSNAMELEN)) { - if (nm = strrchr(mp->f_mntfromname,'/')) { - sprintf(dev,"/dev/r%s",nm + 1); - nm = dev; - } else - nm = mp->f_mntfromname; - quot(nm,mp->f_mntonname); - } - } - } - while (--argc >= 0) - quot(*argv++,0); - return 0; -} diff --git a/usr.sbin/sa/Makefile b/usr.sbin/sa/Makefile deleted file mode 100644 index ee412a6e6c7d..000000000000 --- a/usr.sbin/sa/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $Id: Makefile,v 1.1 1994/03/24 18:41:48 cgd Exp $ - -PROG= sa -MAN8= sa.0 -SRCS= main.c pdb.c usrdb.c - -.include <bsd.prog.mk> diff --git a/usr.sbin/sa/extern.h b/usr.sbin/sa/extern.h deleted file mode 100644 index 6d5291458d9d..000000000000 --- a/usr.sbin/sa/extern.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 1994 Christopher G. Demetriou - * 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 Christopher G. Demetriou. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - * - * $Id: extern.h,v 1.1 1994/03/24 18:41:50 cgd Exp $ - */ - -#include <sys/types.h> -#include <sys/param.h> -#include <db.h> - -/* structures */ - -struct cmdinfo { - char ci_comm[MAXCOMLEN+2]; /* command name (+ '*') */ - u_long ci_uid; /* user id */ - u_quad_t ci_calls; /* number of calls */ - u_quad_t ci_etime; /* elapsed time */ - u_quad_t ci_utime; /* user time */ - u_quad_t ci_stime; /* system time */ - u_quad_t ci_mem; /* memory use */ - u_quad_t ci_io; /* number of disk i/o ops */ - u_int ci_flags; /* flags; see below */ -}; -#define CI_UNPRINTABLE 0x0001 /* unprintable chars in name */ - -struct userinfo { - u_long ui_uid; /* user id; for consistency */ - u_quad_t ui_calls; /* number of invocations */ - u_quad_t ui_utime; /* user time */ - u_quad_t ui_stime; /* system time */ - u_quad_t ui_mem; /* memory use */ - u_quad_t ui_io; /* number of disk i/o ops */ -}; - -/* typedefs */ - -typedef int (*cmpf_t) __P((const DBT *, const DBT *)); - -/* external functions in sa.c */ -int main __P((int, char **)); - -/* external functions in pdb.c */ -int pacct_init __P((void)); -void pacct_destroy __P((void)); -int pacct_add __P((const struct cmdinfo *)); -int pacct_update __P((void)); -void pacct_print __P((void)); - -/* external functions in usrdb.c */ -int usracct_init __P((void)); -void usracct_destroy __P((void)); -int usracct_add __P((const struct cmdinfo *)); -int usracct_update __P((void)); -void usracct_print __P((void)); - -/* variables */ - -extern int aflag, bflag, cflag, dflag, Dflag, fflag, iflag, jflag, kflag; -extern int Kflag, lflag, mflag, qflag, rflag, sflag, tflag, uflag, vflag; -extern int cutoff; -extern cmpf_t sa_cmp; - -/* some #defines to help with db's stupidity */ - -#define DB_CLOSE(db) \ - ((*(db)->close)(db)) -#define DB_GET(db, key, data, flags) \ - ((*(db)->get)((db), (key), (data), (flags))) -#define DB_PUT(db, key, data, flags) \ - ((*(db)->put)((db), (key), (data), (flags))) -#define DB_SYNC(db, flags) \ - ((*(db)->sync)((db), (flags))) -#define DB_SEQ(db, key, data, flags) \ - ((*(db)->seq)((db), (key), (data), (flags))) diff --git a/usr.sbin/sa/main.c b/usr.sbin/sa/main.c deleted file mode 100644 index dac27240c4f5..000000000000 --- a/usr.sbin/sa/main.c +++ /dev/null @@ -1,542 +0,0 @@ -/* - * Copyright (c) 1994 Christopher G. Demetriou - * 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 Christopher G. Demetriou. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 copright[] = -"@(#) Copyright (c) 1994 Christopher G. Demetriou\n\ - All rights reserved.\n"; - -static char rcsid[] = "$Id: main.c,v 1.1 1994/03/24 18:41:51 cgd Exp $"; -#endif - -/* - * sa: system accounting - */ - -#include <sys/types.h> -#include <sys/acct.h> -#include <ctype.h> -#include <err.h> -#include <fcntl.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include "extern.h" -#include "pathnames.h" - -static int acct_load __P((char *, int)); -static u_quad_t decode_comp_t __P((comp_t)); -static int cmp_comm __P((const char *, const char *)); -static int cmp_usrsys __P((const DBT *, const DBT *)); -static int cmp_avgusrsys __P((const DBT *, const DBT *)); -static int cmp_dkio __P((const DBT *, const DBT *)); -static int cmp_avgdkio __P((const DBT *, const DBT *)); -static int cmp_cpumem __P((const DBT *, const DBT *)); -static int cmp_avgcpumem __P((const DBT *, const DBT *)); -static int cmp_calls __P((const DBT *, const DBT *)); - -int aflag, bflag, cflag, dflag, Dflag, fflag, iflag, jflag, kflag; -int Kflag, lflag, mflag, qflag, rflag, sflag, tflag, uflag, vflag; -int cutoff = 1; - -static char *dfltargv[] = { _PATH_ACCT }; -static int dfltargc = (sizeof dfltargv/sizeof(char *)); - -/* default to comparing by sum of user + system time */ -cmpf_t sa_cmp = cmp_usrsys; - -int -main(argc, argv) - int argc; - char **argv; -{ - char ch; - int error; - - while ((ch = getopt(argc, argv, "abcdDfijkKlmnqrstuv:")) != -1) - switch (ch) { - case 'a': - /* print all commands */ - aflag = 1; - break; - case 'b': - /* sort by per-call user/system time average */ - bflag = 1; - sa_cmp = cmp_avgusrsys; - break; - case 'c': - /* print percentage total time */ - cflag = 1; - break; - case 'd': - /* sort by averge number of disk I/O ops */ - dflag = 1; - sa_cmp = cmp_avgdkio; - break; - case 'D': - /* print and sort by total disk I/O ops */ - Dflag = 1; - sa_cmp = cmp_dkio; - break; - case 'f': - /* force no interactive threshold comprison */ - fflag = 1; - break; - case 'i': - /* do not read in summary file */ - iflag = 1; - break; - case 'j': - /* instead of total minutes, give sec/call */ - jflag = 1; - break; - case 'k': - /* sort by cpu-time average memory usage */ - kflag = 1; - sa_cmp = cmp_avgcpumem; - break; - case 'K': - /* print and sort by cpu-storage integral */ - sa_cmp = cmp_cpumem; - Kflag = 1; - break; - case 'l': - /* seperate system and user time */ - lflag = 1; - break; - case 'm': - /* print procs and time per-user */ - mflag = 1; - break; - case 'n': - /* sort by number of calls */ - sa_cmp = cmp_calls; - break; - case 'q': - /* quiet; error messages only */ - qflag = 1; - break; - case 'r': - /* reverse order of sort */ - rflag = 1; - break; - case 's': - /* merge accounting file into summaries */ - sflag = 1; - break; - case 't': - /* report ratio of user and system times */ - tflag = 1; - break; - case 'u': - /* first, print uid and command name */ - uflag = 1; - break; - case 'v': - /* cull junk */ - vflag = 1; - cutoff = atoi(optarg); - break; - case '?': - default: - (void)fprintf(stderr, - "usage: sa [-abcdDfijkKlmnqrstu] [-v cutoff] [file ...]\n"); - exit(1); - } - - argc -= optind; - argv += optind; - - /* various argument checking */ - if (fflag && !vflag) - errx(1, "only one of -f requires -v"); - if (fflag && aflag) - errx(1, "only one of -a and -v may be specified"); - /* XXX need more argument checking */ - - if (!uflag) { - /* initialize tables */ - if ((sflag || (!mflag && !qflag)) && pacct_init() != 0) - errx(1, "process accounting initialization failed"); - if ((sflag || (mflag && !qflag)) && usracct_init() != 0) - errx(1, "user accounting initialization failed"); - } - - if (argc == 0) { - argc = dfltargc; - argv = dfltargv; - } - - /* for each file specified */ - for (; argc > 0; argc--, argv++) { - int fd; - - /* - * load the accounting data from the file. - * if it fails, go on to the next file. - */ - fd = acct_load(argv[0], sflag); - if (fd < 0) - continue; - - if (!uflag && sflag) { -#ifndef DEBUG - sigset_t nmask, omask; - int unmask = 1; - - /* - * block most signals so we aren't interrupted during - * the update. - */ - if (sigfillset(&nmask) == -1) { - warn("sigfillset"); - unmask = 0; - error = 1; - } - if (unmask && - (sigprocmask(SIG_BLOCK, &nmask, &omask) == -1)) { - warn("couldn't set signal mask "); - unmask = 0; - error = 1; - } -#endif /* DEBUG */ - - /* - * truncate the accounting data file ASAP, to avoid - * losing data. don't worry about errors in updating - * the saved stats; better to underbill than overbill, - * but we want every accounting record intact. - */ - if (ftruncate(fd, 0) == -1) { - warn("couldn't truncate %s", argv); - error = 1; - } - - /* - * update saved user and process accounting data. - * note errors for later. - */ - if (pacct_update() != 0 || usracct_update() != 0) - error = 1; - -#ifndef DEBUG - /* - * restore signals - */ - if (unmask && - (sigprocmask(SIG_SETMASK, &omask, NULL) == -1)) { - warn("couldn't restore signal mask"); - error = 1; - } -#endif /* DEBUG */ - } - - /* - * close the opened accounting file - */ - if (close(fd) == -1) { - warn("close %s", argv); - error = 1; - } - } - - if (!uflag && !qflag) { - /* print any results we may have obtained. */ - if (!mflag) - pacct_print(); - else - usracct_print(); - } - - if (!uflag) { - /* finally, deallocate databases */ - if (sflag || (!mflag && !qflag)) - pacct_destroy(); - if (sflag || (mflag && !qflag)) - usracct_destroy(); - } - - exit(error); -} - -static int -acct_load(pn, wr) - char *pn; - int wr; -{ - struct acct ac; - struct cmdinfo ci; - ssize_t rv; - int fd, i; - - /* - * open the file - */ - fd = open(pn, wr ? O_RDWR : O_RDONLY, 0); - if (fd == -1) { - warn("open %s %s", pn, wr ? "for read/write" : "read-only"); - return (-1); - } - - /* - * read all we can; don't stat and open because more processes - * could exit, and we'd miss them - */ - while (1) { - /* get one accounting entry and punt if there's an error */ - rv = read(fd, &ac, sizeof(struct acct)); - if (rv == -1) - warn("error reading %s", pn); - else if (rv > 0 && rv < sizeof(struct acct)) - warnx("short read of accounting data in %s", pn); - if (rv != sizeof(struct acct)) - break; - - /* decode it */ - ci.ci_calls = 1; - for (i = 0; i < sizeof ac.ac_comm && ac.ac_comm[i] != '\0'; - i++) { - char c = ac.ac_comm[i]; - - if (!isascii(c) || iscntrl(c)) { - ci.ci_comm[i] = '?'; - ci.ci_flags |= CI_UNPRINTABLE; - } else - ci.ci_comm[i] = c; - } - if (ac.ac_flag & AFORK) - ci.ci_comm[i++] = '*'; - ci.ci_comm[i++] = '\0'; - ci.ci_etime = decode_comp_t(ac.ac_etime); - ci.ci_utime = decode_comp_t(ac.ac_utime); - ci.ci_stime = decode_comp_t(ac.ac_stime); - ci.ci_uid = ac.ac_uid; - ci.ci_mem = ac.ac_mem; - ci.ci_io = decode_comp_t(ac.ac_io) / AHZ; - - if (!uflag) { - /* and enter it into the usracct and pacct databases */ - if (sflag || (!mflag && !qflag)) - pacct_add(&ci); - if (sflag || (mflag && !qflag)) - usracct_add(&ci); - } else if (!qflag) - printf("%6u %12.2lf cpu %12quk mem %12qu io %s\n", - ci.ci_uid, - (ci.ci_utime + ci.ci_stime) / (double) AHZ, - ci.ci_mem, ci.ci_io, ci.ci_comm); - } - - /* finally, return the file descriptor for possible truncation */ - return (fd); -} - -static u_quad_t -decode_comp_t(comp) - comp_t comp; -{ - u_quad_t rv; - - /* - * for more info on the comp_t format, see: - * /usr/src/sys/kern/kern_acct.c - * /usr/src/sys/sys/acct.h - * /usr/src/usr.bin/lastcomm/lastcomm.c - */ - rv = comp & 0x1fff; /* 13 bit fraction */ - comp >>= 13; /* 3 bit base-8 exponent */ - while (comp--) - rv <<= 3; - - return (rv); -} - -/* sort commands, doing the right thing in terms of reversals */ -static int -cmp_comm(s1, s2) - const char *s1, *s2; -{ - int rv; - - rv = strcmp(s1, s2); - if (rv == 0) - rv = -1; - return (rflag ? rv : -rv); -} - -/* sort by total user and system time */ -static int -cmp_usrsys(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - u_quad_t t1, t2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - t1 = c1->ci_utime + c1->ci_stime; - t2 = c2->ci_utime + c2->ci_stime; - - if (t1 < t2) - return -1; - else if (t1 == t2) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} - -/* sort by average user and system time */ -static int -cmp_avgusrsys(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - double t1, t2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - t1 = c1->ci_utime + c1->ci_stime; - t1 /= (double) (c1->ci_calls ? c1->ci_calls : 1); - - t2 = c2->ci_utime + c2->ci_stime; - t2 /= (double) (c2->ci_calls ? c2->ci_calls : 1); - - if (t1 < t2) - return -1; - else if (t1 == t2) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} - -/* sort by total number of disk I/O operations */ -static int -cmp_dkio(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - if (c1->ci_io < c2->ci_io) - return -1; - else if (c1->ci_io == c2->ci_io) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} - -/* sort by average number of disk I/O operations */ -static int -cmp_avgdkio(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - double n1, n2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - n1 = (double) c1->ci_io / (double) (c1->ci_calls ? c1->ci_calls : 1); - n2 = (double) c2->ci_io / (double) (c2->ci_calls ? c2->ci_calls : 1); - - if (n1 < n2) - return -1; - else if (n1 == n2) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} - -/* sort by the cpu-storage integral */ -static int -cmp_cpumem(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - if (c1->ci_mem < c2->ci_mem) - return -1; - else if (c1->ci_mem == c2->ci_mem) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} - -/* sort by the cpu-time average memory usage */ -static int -cmp_avgcpumem(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - u_quad_t t1, t2; - double n1, n2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - t1 = c1->ci_utime + c1->ci_stime; - t2 = c2->ci_utime + c2->ci_stime; - - n1 = (double) c1->ci_mem / (double) (t1 ? t1 : 1); - n2 = (double) c2->ci_mem / (double) (t2 ? t2 : 1); - - if (n1 < n2) - return -1; - else if (n1 == n2) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} - -/* sort by the number of invocations */ -static int -cmp_calls(d1, d2) - const DBT *d1, *d2; -{ - struct cmdinfo *c1, *c2; - - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; - - if (c1->ci_calls < c2->ci_calls) - return -1; - else if (c1->ci_calls == c2->ci_calls) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); - else - return 1; -} diff --git a/usr.sbin/sa/pathnames.h b/usr.sbin/sa/pathnames.h deleted file mode 100644 index 31721c25fcd2..000000000000 --- a/usr.sbin/sa/pathnames.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 1994 Christopher G. Demetriou - * 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 Christopher G. Demetriou. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - * - * $Id: pathnames.h,v 1.1 1994/03/24 18:41:53 cgd Exp $ - */ - -#define _PATH_ACCT "/var/account/acct" -#define _PATH_SAVACCT "/var/account/savacct" -#define _PATH_USRACCT "/var/account/usracct" diff --git a/usr.sbin/sa/pdb.c b/usr.sbin/sa/pdb.c deleted file mode 100644 index 083f9daa87da..000000000000 --- a/usr.sbin/sa/pdb.c +++ /dev/null @@ -1,418 +0,0 @@ -/* - * Copyright (c) 1994 Christopher G. Demetriou - * 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 Christopher G. Demetriou. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 rcsid[] = "$Id: pdb.c,v 1.1 1994/03/24 18:41:54 cgd Exp $"; -#endif - -#include <sys/types.h> -#include <sys/acct.h> -#include <err.h> -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include "extern.h" -#include "pathnames.h" - -static int check_junk __P((struct cmdinfo *)); -static void add_ci __P((const struct cmdinfo *, struct cmdinfo *)); -static void print_ci __P((const struct cmdinfo *, const struct cmdinfo *)); - -static DB *pacct_db; - -int -pacct_init() -{ - DB *saved_pacct_db; - int error; - - pacct_db = dbopen(NULL, O_RDWR, 0, DB_BTREE, NULL); - if (pacct_db == NULL) - return (-1); - - error = 0; - if (!iflag) { - DBT key, data; - int serr, nerr; - - saved_pacct_db = dbopen(_PATH_SAVACCT, O_RDONLY, 0, DB_BTREE, - NULL); - if (saved_pacct_db == NULL) { - error = errno == ENOENT ? 0 : -1; - if (error) - warn("retrieving process accounting summary"); - goto out; - } - - serr = DB_SEQ(saved_pacct_db, &key, &data, R_FIRST); - if (serr < 0) { - warn("retrieving process accounting summary"); - error = -1; - goto closeout; - } - while (serr == 0) { - nerr = DB_PUT(pacct_db, &key, &data, 0); - if (nerr < 0) { - warn("initializing process accounting stats"); - error = -1; - break; - } - - serr = DB_SEQ(saved_pacct_db, &key, &data, R_NEXT); - if (serr < 0) { - warn("retrieving process accounting summary"); - error = -1; - break; - } - } - -closeout: if (DB_CLOSE(saved_pacct_db) < 0) { - warn("closing process accounting summary"); - error = -1; - } - } - -out: if (error != 0) - pacct_destroy(); - return (error); -} - -void -pacct_destroy() -{ - if (DB_CLOSE(pacct_db) < 0) - warn("destroying process accounting stats"); -} - -int -pacct_add(ci) - const struct cmdinfo *ci; -{ - DBT key, data; - struct cmdinfo newci; - char keydata[sizeof ci->ci_comm]; - int rv; - - bcopy(ci->ci_comm, &keydata, sizeof keydata); - key.data = &keydata; - key.size = strlen(keydata); - - rv = DB_GET(pacct_db, &key, &data, 0); - if (rv < 0) { - warn("get key %s from process accounting stats", ci->ci_comm); - return (-1); - } else if (rv == 0) { /* it's there; copy whole thing */ - /* XXX compare size if paranoid */ - /* add the old data to the new data */ - bcopy(data.data, &newci, data.size); - } else { /* it's not there; zero it and copy the key */ - bzero(&newci, sizeof newci); - bcopy(key.data, newci.ci_comm, key.size); - } - - add_ci(ci, &newci); - - data.data = &newci; - data.size = sizeof newci; - rv = DB_PUT(pacct_db, &key, &data, 0); - if (rv < 0) { - warn("add key %s to process accounting stats", ci->ci_comm); - return (-1); - } else if (rv == 1) { - warnx("duplicate key %s in process accounting stats", - ci->ci_comm); - return (-1); - } - - return (0); -} - -int -pacct_update() -{ - DB *saved_pacct_db; - DBT key, data; - int error, serr, nerr; - - saved_pacct_db = dbopen(_PATH_SAVACCT, O_RDWR|O_CREAT|O_TRUNC, 0644, - DB_BTREE, NULL); - if (saved_pacct_db == NULL) { - warn("creating process accounting summary"); - return (-1); - } - - error = 0; - - serr = DB_SEQ(pacct_db, &key, &data, R_FIRST); - if (serr < 0) { - warn("retrieving process accounting stats"); - error = -1; - } - while (serr == 0) { - nerr = DB_PUT(saved_pacct_db, &key, &data, 0); - if (nerr < 0) { - warn("saving process accounting summary"); - error = -1; - break; - } - - serr = DB_SEQ(pacct_db, &key, &data, R_NEXT); - if (serr < 0) { - warn("retrieving process accounting stats"); - error = -1; - break; - } - } - - if (DB_SYNC(saved_pacct_db, 0) < 0) { - warn("syncing process accounting summary"); - error = -1; - } - if (DB_CLOSE(saved_pacct_db) < 0) { - warn("closing process accounting summary"); - error = -1; - } - return error; -} - -void -pacct_print() -{ - BTREEINFO bti; - DBT key, data, ndata; - DB *output_pacct_db; - struct cmdinfo *cip, ci, ci_total, ci_other, ci_junk; - int rv; - - bzero(&ci_total, sizeof ci_total); - strcpy(ci_total.ci_comm, ""); - bzero(&ci_other, sizeof ci_other); - strcpy(ci_other.ci_comm, "***other"); - bzero(&ci_junk, sizeof ci_junk); - strcpy(ci_junk.ci_comm, "**junk**"); - - /* - * Retrieve them into new DB, sorted by appropriate key. - * At the same time, cull 'other' and 'junk' - */ - bzero(&bti, sizeof bti); - bti.compare = sa_cmp; - output_pacct_db = dbopen(NULL, O_RDWR, 0, DB_BTREE, &bti); - if (output_pacct_db == NULL) { - warn("couldn't sort process accounting stats"); - return; - } - - ndata.data = NULL; - ndata.size = 0; - rv = DB_SEQ(pacct_db, &key, &data, R_FIRST); - if (rv < 0) - warn("retrieving process accounting stats"); - while (rv == 0) { - cip = (struct cmdinfo *) data.data; - bcopy(cip, &ci, sizeof ci); - - /* add to total */ - add_ci(&ci, &ci_total); - - if (vflag && ci.ci_calls <= cutoff && - (fflag || check_junk(&ci))) { - /* put it into **junk** */ - add_ci(&ci, &ci_junk); - goto next; - } - if (!aflag && - ((ci.ci_flags & CI_UNPRINTABLE) != 0 || ci.ci_calls <= 1)) { - /* put into ***other */ - add_ci(&ci, &ci_other); - goto next; - } - rv = DB_PUT(output_pacct_db, &data, &ndata, 0); - if (rv < 0) - warn("sorting process accounting stats"); - -next: rv = DB_SEQ(pacct_db, &key, &data, R_NEXT); - if (rv < 0) - warn("retrieving process accounting stats"); - } - - /* insert **junk** and ***other */ - if (ci_junk.ci_calls != 0) { - data.data = &ci_junk; - data.size = sizeof ci_junk; - rv = DB_PUT(output_pacct_db, &data, &ndata, 0); - if (rv < 0) - warn("sorting process accounting stats"); - } - if (ci_other.ci_calls != 0) { - data.data = &ci_other; - data.size = sizeof ci_other; - rv = DB_PUT(output_pacct_db, &data, &ndata, 0); - if (rv < 0) - warn("sorting process accounting stats"); - } - - /* print out the total */ - print_ci(&ci_total, &ci_total); - - /* print out; if reversed, print first (smallest) first */ - rv = DB_SEQ(output_pacct_db, &data, &ndata, rflag ? R_FIRST : R_LAST); - if (rv < 0) - warn("retrieving process accounting report"); - while (rv == 0) { - cip = (struct cmdinfo *) data.data; - bcopy(cip, &ci, sizeof ci); - - print_ci(&ci, &ci_total); - - rv = DB_SEQ(output_pacct_db, &data, &ndata, - rflag ? R_NEXT : R_PREV); - if (rv < 0) - warn("retrieving process accounting report"); - } - DB_CLOSE(output_pacct_db); -} - -static int -check_junk(cip) - struct cmdinfo *cip; -{ - char *cp; - size_t len; - - fprintf(stderr, "%s (%qu) -- ", cip->ci_comm, cip->ci_calls); - cp = fgetln(stdin, &len); - - return (cp && (cp[0] == 'y' || cp[0] == 'Y')) ? 1 : 0; -} - -static void -add_ci(fromcip, tocip) - const struct cmdinfo *fromcip; - struct cmdinfo *tocip; -{ - tocip->ci_calls += fromcip->ci_calls; - tocip->ci_etime += fromcip->ci_etime; - tocip->ci_utime += fromcip->ci_utime; - tocip->ci_stime += fromcip->ci_stime; - tocip->ci_mem += fromcip->ci_mem; - tocip->ci_io += fromcip->ci_io; -} - -static void -print_ci(cip, totalcip) - const struct cmdinfo *cip, *totalcip; -{ - double t, c; - int uflow; - - c = cip->ci_calls ? cip->ci_calls : 1; - t = (cip->ci_utime + cip->ci_stime) / (double) AHZ; - if (t < 0.01) { - t = 0.01; - uflow = 1; - } else - uflow = 0; - - printf("%8qu ", cip->ci_calls); - if (cflag) { - if (cip != totalcip) - printf(" %4.2f%% ", - cip->ci_calls / (double) totalcip->ci_calls); - else - printf(" %4s ", ""); - } - - if (jflag) - printf("%11.2fre ", cip->ci_etime / (double) (AHZ * c)); - else - printf("%11.2fre ", cip->ci_etime / (60.0 * AHZ)); - if (cflag) { - if (cip != totalcip) - printf(" %4.2f%% ", - cip->ci_etime / (double) totalcip->ci_etime); - else - printf(" %4s ", ""); - } - - if (!lflag) { - if (jflag) - printf("%11.2fcp ", t / (double) cip->ci_calls); - else - printf("%11.2fcp ", t / 60.0); - if (cflag) { - if (cip != totalcip) - printf(" %4.2f%% ", - (cip->ci_utime + cip->ci_stime) / (double) - (totalcip->ci_utime + totalcip->ci_stime)); - else - printf(" %4s ", ""); - } - } else { - if (jflag) - printf("%11.2fu ", cip->ci_utime / (double) (AHZ * c)); - else - printf("%11.2fu ", cip->ci_utime / (60.0 * AHZ)); - if (cflag) { - if (cip != totalcip) - printf(" %4.2f%% ", cip->ci_utime / (double) totalcip->ci_utime); - else - printf(" %4s ", ""); - } - if (jflag) - printf("%11.2fs ", cip->ci_stime / (double) (AHZ * c)); - else - printf("%11.2fs ", cip->ci_stime / (60.0 * AHZ)); - if (cflag) { - if (cip != totalcip) - printf(" %4.2f%% ", cip->ci_stime / (double) totalcip->ci_stime); - else - printf(" %4s ", ""); - } - } - - if (tflag) - if (!uflow) - printf("%8.2fre/cp ", cip->ci_etime / (double) (cip->ci_utime + cip->ci_stime)); - else - printf("%8 ", "*ignore*"); - - if (Dflag) - printf("%10qutio ", cip->ci_io); - else - printf("%8.0favio ", cip->ci_io / c); - - if (Kflag) - printf("%10quk*sec ", cip->ci_mem); - else - printf("%8.0fk ", cip->ci_mem / t); - - printf(" %s\n", cip->ci_comm); -} diff --git a/usr.sbin/sa/sa.8 b/usr.sbin/sa/sa.8 deleted file mode 100644 index 83ec1f4aacbf..000000000000 --- a/usr.sbin/sa/sa.8 +++ /dev/null @@ -1,246 +0,0 @@ -.\" -.\" Copyright (c) 1994 Christopher G. Demetriou -.\" 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 Christopher G. Demetriou. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. -.\" -.\" $Id: sa.8,v 1.1 1994/03/24 18:41:59 cgd Exp $ -.\" -.Dd February 25, 1994 -.Dt SA 8 -.Os NetBSD 0.9a -.Sh NAME -.Nm sa -.Nd print system accounting statistics -.Sh SYNOPSIS -.Nm sa -.Op Fl abcdDfijkKlmnqrstu -.Op Fl v Ar cutoff -.Op Ar -.Sh DESCRIPTION -The -.Nm sa -utility reports on, cleans up, -and generally maintains system -accounting files. -.Pp -.Nm Sa -is able to condense the the information in -.Pa /var/account/acct -into the summary files -.Pa /var/account/savacct -and -.Pa /var/account/usracct , -which contain system statistics according -to command name and login id, respectively. -This condensation is desirable because on a -large system, -.Pa /var/account/acct -can grow by hundreds of blocks per day. -The summary files are normally read before -the accounting file, so that reports include -all available information. -.Pp -If file names are supplied, they are read instead of -.Pa /var/account/account . -After each file is read, if the summary -files are being updated, an updated summary will -be saved to disk. Only one report is printed, -after the last file is processed. -.Pp -The labels used in the output indicate the following, except -where otherwise specified by individual options: -.Bl -tag -width k*sec -.It Dv avio -Average number of I/O operations per execution -.It Dv cp -Sum of user and system time, in minutes -.It Dv cpu -Same as -.Dv cp -.It Dv k -CPU-time averaged core usage, in 1k units -.It Dv k*sec -CPU storage integral, in 1k-core seconds -.It Dv re -Real time, in minutes -.It Dv s -System time, in minutes -.It Dv tio -Total number of I/O operations -.It Dv u -User time, in minutes -.El -.Pp -The options to -.Nm sa -are: -.Bl -tag -width Ds -.It Fl a -List all command names, including those containing unprintable -characters and those used only once. By default, -.Nm sa -places all names containing unprintable characters and -those used only once under the name ``***other''. -.It Fl b -If printing command statistics, sort output by the sum of user and system -time divided by number of calls. -.It Fl c -In addition to the number of calls and the user, system and real times -for each command, print their percentage of the total over all commands. -.It Fl d -If printing command statistics, sort by the average number of disk -I/O operations. If printing user statistics, print the average number of -disk I/O operations per user. -.It Fl D -If printing command statistics, sort and print by the total number -of disk I/O operations. -.It Fl f -Force no interactive threshold comparison with the -.Fl v -option. -.It Fl i -Do not read in the summary files. -.It Fl j -Instead of the total minutes per category, give seconds per call. -.It Fl k -If printing command statistics, sort by the cpu-time average memory -usage. If printing user statistics, print the cpu-time average -memory usage. -.It Fl K -If printing command statistics, print and sort by the cpu-storage integral. -.It Fl l -Separate system and user time; normally they are combined. -.It Fl m -Print per-user statistics rather than per-command statistics. -.It Fl n -Sort by number of calls. -.It Fl q -Create no output other than error messages. -.It Fl r -Reverse order of sort. -.It Fl s -Truncate the accounting files when done and merge their data -into the summary files. -.It Fl t -For each command, report the ratio of real time to the sum -of user and system cpu times. -If the cpu time is too small to report, ``*ignore*'' appears in -this field. -.It Fl u -Superseding all other flags, for each entry -in the accounting file, print the user ID, total seconds of cpu usage, -total memory usage, number of I/O operations performed, and -command name. -.It Fl v Ar cutoff -For each command used -.Ar cutoff -times or fewer, print the command name and await a reply -from the terminal. If the reply begins with ``y'', add -the command to the category ``**junk**''. This flag is -used to strip garbage from the report. -.El -.Pp -By default, per-command statistics will be printed. The number of -calls, the total elapsed time in minutes, total cpu and user time -in minutes, average number of I/O operations, and CPU-time -averaged core usage will be printed. If the -.Fl m -option is specified, per-user statistics will be printed, including -the user name, the number of commands invoked, total cpu time used -(in minutes), total number of I/O operations, and CPU storage integral -for each user. If the -.Fl u -option is specified, the uid, user and system time (in seconds), -CPU storage integral, I/O usage, and command name will be printed -for each entry in the accounting data file. -.Pp -If the -.Fl u -flag is specified, all flags other than -.Fl q -are ignored. If the -.Fl m -flag is specified, only the -.Fl b , -.Fl d , -.Fl i , -.Fl k , -.Fl q , -and -.Fl s -flags are honored. -.Pp -The -.Nm sa -utility exits 0 on success, and >0 if an error occurs. -.Sh FILES -.Bl -tag -width /var/account/usracct -compact -.It Pa /var/account/acct -raw accounting data file -.It Pa /var/account/savacct -per-command accounting summary database -.It Pa /var/account/usracct -per-user accounting summary database -.El -.Sh SEE ALSO -.Xr ac 8 , -.Xr acct 5 , -.Xr accton 8 , -.Xr lastcomm 1 -.Sh BUGS -The number of options to this program is absurd, especially considering -that there's not much logic behind their lettering. -.Pp -The field labels should be more consistent. -.Pp -NetBSD's VM system does not record the CPU storage integral. -.Sh CAVEATS -While the behavior of the options in this version of -.Nm sa -was modeled after the original version, there are some intentional -differences and undoubtedly some unintentional ones as well. In -particular, the -.Fl q -option has been added, and the -.Fl m -option now understands more options than it used to. -.Pp -The formats of the summary files created by this version of -.Nm sa -are very different than the those used by the original version. -This is not considered a problem, however, because the accounting record -format has changed as well (since user ids are now 32 bits). -.Sh HISTORY -.Nm Sa -was written for -.Nx 0.9a -from the specification provided by various systems' manual pages. -Its date of origin is unknown to the author. -.Sh AUTHOR -.Bl -tag -Chris G. Demetriou, cgd@postgres.berkeley.edu -.El diff --git a/usr.sbin/sa/usrdb.c b/usr.sbin/sa/usrdb.c deleted file mode 100644 index af7d0fdbad40..000000000000 --- a/usr.sbin/sa/usrdb.c +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Copyright (c) 1994 Christopher G. Demetriou - * 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 Christopher G. Demetriou. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 rcsid[] = "$Id: usrdb.c,v 1.1 1994/03/24 18:42:01 cgd Exp $"; -#endif - -#include <sys/types.h> -#include <sys/acct.h> -#include <err.h> -#include <errno.h> -#include <fcntl.h> -#include "extern.h" -#include "pathnames.h" - -static int uid_compare __P((const DBT *, const DBT *)); - -static DB *usracct_db; - -int -usracct_init() -{ - DB *saved_usracct_db; - BTREEINFO bti; - int error; - - bzero(&bti, sizeof bti); - bti.compare = uid_compare; - - usracct_db = dbopen(NULL, O_RDWR, 0, DB_BTREE, &bti); - if (usracct_db == NULL) - return (-1); - - error = 0; - if (!iflag) { - DBT key, data; - int serr, nerr; - - saved_usracct_db = dbopen(_PATH_USRACCT, O_RDONLY, 0, DB_BTREE, - &bti); - if (saved_usracct_db == NULL) { - error = (errno == ENOENT) ? 0 : -1; - if (error) - warn("retrieving user accounting summary"); - goto out; - } - - serr = DB_SEQ(saved_usracct_db, &key, &data, R_FIRST); - if (serr < 0) { - warn("retrieving user accounting summary"); - error = -1; - goto closeout; - } - while (serr == 0) { - nerr = DB_PUT(usracct_db, &key, &data, 0); - if (nerr < 0) { - warn("initializing user accounting stats"); - error = -1; - break; - } - - serr = DB_SEQ(saved_usracct_db, &key, &data, R_NEXT); - if (serr < 0) { - warn("retrieving user accounting summary"); - error = -1; - break; - } - } - -closeout: - if (DB_CLOSE(saved_usracct_db) < 0) { - warn("closing user accounting summary"); - error = -1; - } - } - -out: - if (error != 0) - usracct_destroy(); - return (error); -} - -void -usracct_destroy() -{ - if (DB_CLOSE(usracct_db) < 0) - warn("destroying user accounting stats"); -} - -int -usracct_add(ci) - const struct cmdinfo *ci; -{ - DBT key, data; - struct userinfo newui; - u_long uid; - int rv; - - uid = ci->ci_uid; - key.data = &uid; - key.size = sizeof uid; - - rv = DB_GET(usracct_db, &key, &data, 0); - if (rv < 0) { - warn("get key %d from user accounting stats", uid); - return (-1); - } else if (rv == 0) { /* it's there; copy whole thing */ - /* add the old data to the new data */ - bcopy(data.data, &newui, data.size); - if (newui.ui_uid != uid) { - warnx("key %d != expected record number %d", - newui.ui_uid, uid); - warnx("inconsistent user accounting stats"); - return (-1); - } - } else { /* it's not there; zero it and copy the key */ - bzero(&newui, sizeof newui); - newui.ui_uid = ci->ci_uid; - } - - newui.ui_calls += ci->ci_calls; - newui.ui_utime += ci->ci_utime; - newui.ui_stime += ci->ci_stime; - newui.ui_mem += ci->ci_mem; - newui.ui_io += ci->ci_io; - - data.data = &newui; - data.size = sizeof newui; - rv = DB_PUT(usracct_db, &key, &data, 0); - if (rv < 0) { - warn("add key %d to user accounting stats", uid); - return (-1); - } else if (rv != 0) { - warnx("DB_PUT returned 1"); - return (-1); - } - - return (0); -} - -int -usracct_update() -{ - DB *saved_usracct_db; - DBT key, data; - BTREEINFO bti; - u_long uid; - int error, serr, nerr; - - bzero(&bti, sizeof bti); - bti.compare = uid_compare; - - saved_usracct_db = dbopen(_PATH_USRACCT, O_RDWR|O_CREAT|O_TRUNC, 0644, - DB_BTREE, &bti); - if (saved_usracct_db == NULL) { - warn("creating user accounting summary"); - return (-1); - } - - error = 0; - - serr = DB_SEQ(usracct_db, &key, &data, R_FIRST); - if (serr < 0) { - warn("retrieving user accounting stats"); - error = -1; - } - while (serr == 0) { - nerr = DB_PUT(saved_usracct_db, &key, &data, 0); - if (nerr < 0) { - warn("saving user accounting summary"); - error = -1; - break; - } - - serr = DB_SEQ(usracct_db, &key, &data, R_NEXT); - if (serr < 0) { - warn("retrieving user accounting stats"); - error = -1; - break; - } - } - - if (DB_SYNC(saved_usracct_db, 0) < 0) { - warn("syncing process accounting summary"); - error = -1; - } -out: - if (DB_CLOSE(saved_usracct_db) < 0) { - warn("closing process accounting summary"); - error = -1; - } - return error; -} - -void -usracct_print() -{ - DBT key, data; - struct userinfo *ui; - double t; - int rv; - - rv = DB_SEQ(usracct_db, &key, &data, R_FIRST); - if (rv < 0) - warn("retrieving user accounting stats"); - - while (rv == 0) { - ui = (struct userinfo *) data.data; - - printf("%-8s %9qu ", - user_from_uid(ui->ui_uid, 0), ui->ui_calls); - - t = (double) (ui->ui_utime + ui->ui_stime) / - (double) AHZ; - if (t < 0.0001) /* kill divide by zero */ - t = 0.0001; - - printf("%12.2lf%s ", t / 60.0, "cpu"); - - /* ui->ui_calls is always != 0 */ - if (dflag) - printf("%12qu%s", ui->ui_io / ui->ui_calls, "avio"); - else - printf("%12qu%s", ui->ui_io, "tio"); - - /* t is always >= 0.0001; see above */ - if (kflag) - printf("%12qu%s", ui->ui_mem / t, "k"); - else - printf("%12qu%s", ui->ui_mem, "k*sec"); - - printf("\n"); - - rv = DB_SEQ(usracct_db, &key, &data, R_NEXT); - if (rv < 0) - warn("retrieving user accounting stats"); - } -} - -static int -uid_compare(k1, k2) - const DBT *k1, *k2; -{ - u_long d1, d2; - - bcopy(k1->data, &d1, sizeof d1); - bcopy(k2->data, &d2, sizeof d2); - - if (d1 < d2) - return -1; - else if (d1 == d2) - return 0; - else - return 1; -} diff --git a/usr.sbin/spray/Makefile b/usr.sbin/spray/Makefile deleted file mode 100644 index 5ecd1c5be0e9..000000000000 --- a/usr.sbin/spray/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $Id: Makefile,v 1.2 1995/07/11 01:18:05 jtc Exp $ - -PROG= spray -MAN8= spray.8 -LDADD= -lrpcsvc - -.include <bsd.prog.mk> diff --git a/usr.sbin/spray/spray.8 b/usr.sbin/spray/spray.8 deleted file mode 100644 index a47c899ed841..000000000000 --- a/usr.sbin/spray/spray.8 +++ /dev/null @@ -1,76 +0,0 @@ -.\" -.\" Copyright (c) 1994 James A. Jegers -.\" 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. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. -.\" -.Dd July 10, 1995 -.Dt SPRAY 8 -.Os FreeBSD -.Sh NAME -.Nm spray -.Nd send many packets to host -.Sh SYNOPSIS -.Nm spray -.Op Fl c Ar count -.Op Fl d Ar delay -.Op Fl l Ar length -.Ar host -\&... -.Ek -.Sh DESCRIPTION -.Nm Spray -sends multiple RPC packets to -.Ar host -and records how many of them were correctly received and how long it took. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl c Ar count -Send -.Ar count -packets. -.It Fl d Ar delay -Pause -.Ar delay -microseconds between sending each packet. -.It Fl l Ar length -Set the length of the packet that holds the RPC call message to -.Ar length -bytes. -Not all values of -.Ar length -are possible because RPC data is encoded using XDR. -.Nm Spray -rounds up to the nearest possible value. -.El -.Pp -.Nm Spray -is intended for use in network testing, measurement, and management. -This command -.Bf -emphasis -can be very hard on a network and should be used with caution. -.Ef -.Pp -.Sh SEE ALSO -.Xr netstat 1 , -.Xr ifconfig 8 , -.Xr ping 8 , -.Xr rpc.sprayd 8 diff --git a/usr.sbin/spray/spray.c b/usr.sbin/spray/spray.c deleted file mode 100644 index 607abc15b3fa..000000000000 --- a/usr.sbin/spray/spray.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (c) 1993 Winning Strategies, Inc. - * 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 Winning Strategies, Inc. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. - * - * $Id: spray.c,v 1.3 1994/12/23 16:42:47 cgd Exp $ - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include <rpc/rpc.h> -#include <rpcsvc/spray.h> - -#ifndef SPRAYOVERHEAD -#define SPRAYOVERHEAD 86 -#endif - -void usage (); -void print_xferstats (); - -/* spray buffer */ -char spray_buffer[SPRAYMAX]; - -/* RPC timeouts */ -struct timeval NO_DEFAULT = { -1, -1 }; -struct timeval ONE_WAY = { 0, 0 }; -struct timeval TIMEOUT = { 25, 0 }; - -int -main(argc, argv) - int argc; - char **argv; -{ - char *progname; - spraycumul host_stats; - sprayarr host_array; - CLIENT *cl; - int c; - int i; - int count = 0; - int delay = 0; - int length = 0; - double xmit_time; /* time to receive data */ - - progname = *argv; - while ((c = getopt(argc, argv, "c:d:l:")) != -1) { - switch (c) { - case 'c': - count = atoi(optarg); - break; - case 'd': - delay = atoi(optarg); - break; - case 'l': - length = atoi(optarg); - break; - default: - usage(); - /* NOTREACHED */ - } - } - argc -= optind; - argv += optind; - - if (argc != 1) { - usage(); - /* NOTREACHED */ - } - - - /* Correct packet length. */ - if (length > SPRAYMAX) { - length = SPRAYMAX; - } else if (length < SPRAYOVERHEAD) { - length = SPRAYOVERHEAD; - } else { - /* The RPC portion of the packet is a multiple of 32 bits. */ - length -= SPRAYOVERHEAD - 3; - length &= ~3; - length += SPRAYOVERHEAD; - } - - - /* - * The default value of count is the number of packets required - * to make the total stream size 100000 bytes. - */ - if (!count) { - count = 100000 / length; - } - - /* Initialize spray argument */ - host_array.sprayarr_len = length - SPRAYOVERHEAD; - host_array.sprayarr_val = spray_buffer; - - - /* create connection with server */ - cl = clnt_create(*argv, SPRAYPROG, SPRAYVERS, "udp"); - if (cl == NULL) { - clnt_pcreateerror(progname); - exit(1); - } - - - /* - * For some strange reason, RPC 4.0 sets the default timeout, - * thus timeouts specified in clnt_call() are always ignored. - * - * The following (undocumented) hack resets the internal state - * of the client handle. - */ - clnt_control(cl, CLSET_TIMEOUT, (caddr_t)&NO_DEFAULT); - - - /* Clear server statistics */ - if (clnt_call(cl, SPRAYPROC_CLEAR, xdr_void, NULL, xdr_void, NULL, TIMEOUT) != RPC_SUCCESS) { - clnt_perror(cl, progname); - exit(1); - } - - - /* Spray server with packets */ - printf ("sending %d packets of lnth %d to %s ...", count, length, *argv); - fflush (stdout); - - for (i = 0; i < count; i++) { - clnt_call(cl, SPRAYPROC_SPRAY, xdr_sprayarr, &host_array, xdr_void, NULL, ONE_WAY); - - if (delay) { - usleep(delay); - } - } - - - /* Collect statistics from server */ - if (clnt_call(cl, SPRAYPROC_GET, xdr_void, NULL, xdr_spraycumul, &host_stats, TIMEOUT) != RPC_SUCCESS) { - clnt_perror(cl, progname); - exit(1); - } - - xmit_time = host_stats.clock.sec + - (host_stats.clock.usec / 1000000.0); - - printf ("\n\tin %.2f seconds elapsed time\n", xmit_time); - - - /* report dropped packets */ - if (host_stats.counter != count) { - int packets_dropped = count - host_stats.counter; - - printf("\t%d packets (%.2f%%) dropped\n", - packets_dropped, - 100.0 * packets_dropped / count ); - } else { - printf("\tno packets dropped\n"); - } - - printf("Sent:"); - print_xferstats(count, length, xmit_time); - - printf("Rcvd:"); - print_xferstats(host_stats.counter, length, xmit_time); - - exit (0); -} - - -void -print_xferstats(packets, packetlen, xfertime) - int packets; - int packetlen; - double xfertime; -{ - int datalen; - double pps; /* packets per second */ - double bps; /* bytes per second */ - - datalen = packets * packetlen; - pps = packets / xfertime; - bps = datalen / xfertime; - - printf("\t%.0f packets/sec, ", pps); - - if (bps >= 1024) - printf ("%.1fK ", bps / 1024); - else - printf ("%.0f ", bps); - - printf("bytes/sec\n"); -} - - -void -usage () -{ - fprintf(stderr, "usage: spray [-c count] [-l length] [-d delay] host\n"); - exit(1); -} |