Subject: checking kernel options - checkconf.pl
To: None <current-users@sun-lamp.cs.berkeley.edu>
From: Luke Mewburn <lm@rmit.edu.au>
List: current-users
Date: 08/06/1994 20:08:39
Here's the latest update of my checkconf perl script, which may
be useful to i386 users who want to see what is and isn't correct
about their config files (assuming my info is correct of course ;)
It should be possible to add information for other ports that use
config (not config.new), so if someone wants to mail me changes
I'll incorporate them.

I've enhanced this over my previous release; for devices you only need
an entry for the entire group in the %devices associative array (eg `ed'
instead of `ed0', `ed1'), and the % specifier %d is replaced by the
number. Similar thing for pseudo devices, except %s is available as
well, which = "" if %d == 1, else "s" (a pluralizer)

Feel free to send back comments, etc.

--- cut here --- file: checkconf
#!/usr/bin/perl
#
# Copyright 1994 Luke Mewburn <lm@rmit.edu.au>.  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 Luke Mewburn.
# 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: checkconf,v 1.3 1994/08/06 10:01:04 root Exp root $
#
# checkconf --
#	check the validity of netbsd kernel config files
#
# $Log: checkconf,v $
# Revision 1.3  1994/08/06  10:01:04  root
# updated %devices entries for more generic definitions
# updated %pseudo-devices for the same
# cleaned up a couple more options
#
# Revision 1.2  1994/08/06  08:48:04  root
# fixed up a few of the descriptions as suggested by Charles Hannum
#
# Revision 1.1  1994/08/06  08:33:30  root
# Initial revision
#

#
#	constants
#
$MAX_COLS = 80;

#
#	known machine types
#
%machines = (
    'i386',		'Intel 386 or higher',
);

#
#	known cpu types
#
%cpus = (
    'I386_CPU',	'80386',
    'I486_CPU',	'i486',
    'I586_CPU',	'pentium',
);

#
#	known options
#
%options = (
    'MATH_EMULATE',	'floating point emulation',
    'DUMMY_NOPS',	'make the kernel a little faster; will break on some machines',
    'MACHINE_NONCONTIG','temporary kluge while adding support for non-contiguous physical memory',
    'SWAPPAGER',	'paging of processes; REQUIRED',
    'VNODEPAGER',	'allow mmap() of vnodes; REQUIRED',
    'DEVPAGER',		'allow mmap() of devices; REQUIRED',
    'DIAGNOSTIC',	'kernel diagnostics',
    'KTRACE',		'system call tracing, a la ktrace(1)',
    'FASTLINKS',	'store short symlinks in the inode instead of the filesystem [OBSOLETE]',
    'FIFO',		'FIFOs',
    'SYSVMSG',		'System V-like message queues',
    'SYSVSEM',		'System V-like semaphores',
    'SYSVSHM',		'System V-like memory sharing',
    'SHMMAXPGS',	'maximum pages for SYSVSHM, default = 1024 pages',
    'SCSI',		'generic SCSI system',
    'FFS',		'UFS',
    'LKM',		'loadable kernel modules',
    'XSERVER',		'allows machine to be an X server with PCVT',
    'UCONSOLE',		'allow non-root users to aquire console with TIOCCONS',
    'QUOTA',		'quotas in UFS',
    'MFS',		'memory file system (shares memory and swap space)',
    'NFSSERVER',	'Network File System (NFS) server',
    'NFSCLIENT',	'Network File System (NFS) client',
    'ISOFS',		'ISO 9660 file system, with Rock Ridge [OBSOLETE]',
    'CD9660',		'ISO 9660 file system, with Rock Ridge',
    'MSDOSFS',		'MS-DOS file system',
    'PCFS',		'MS-DOS file system [OBSOLETE]',
    'LOFS',		'loopback filesystem [OBSOLETE]',
    'NULLFS',		'null filesystem (incorporates lofs)',
    'PORTAL',		'portal filesystem',
    'PROCFS',		'proc filesystem',
    'FDESC',		'/dev/fd',
    'KERNFS',		'kernel file system',
    'IMP',		'host-to-IMP from ARPAnet days [NONEXISTANT]',
    'INET',		'internet domain sockets',
    'NS',		'xerox ns protocol',
    'ISO',		'OSI',
    'TPIP',		'connection-based (a la TCP) protocol for ISO',
    'EON',		'XXX: CLNP/TPIP tunnelling over IP?',
    'CCITT',		'X.25',
    'HDLC',		'X.25 hdlc (needed by CCITT)',
    'LLC',		'X.25 llc (needed by CCITT)',
    'GATEWAY',		'packet forwarding',
    'MULTICAST',	'multicast networking - always there [OBSOLETE]',
    'MROUTING',		'multicast routing',
    'DDB',		'kernel debugger',
    'USER_LDT',		'user creatable i386 LDTs (for Wine Windows emulator)',
    'COMPAT_NOMID',	'NetBSD 0.8 compatibility (executable format?)',
    'COMPAT_09',	'NetBSD 0.9 compatibility',
    'COMPAT_43',	'BSD 4.3 compatibility',
    'TCP_COMPAT_42',	'BSD 4.2 TCP/IP compatibility',
    'SBPRO',		'SoundBlaster Pro',
    'DEBUG',		'XXX: unknown debugging option',
    'SETUIDSCRIPTS',	'allow Execute only and SetUID scripts via /dev/fd',
    'FDSCRIPTS',	'exec Execute only scripts via /dev/fd',
);

#
#	known devices (master, controller, device, disk, and tape entries)
#
# these entries are matched with the regex '(\D+)(\d)$' for ease.
# '%d' in the description matches the actual device number
%devices = (
    'isa',	'PC clone ISA bus',
    'pc',	'pccons console driver for PC keyboard & monitor',
    'vt',	'pcvt virtual multi-console driver PC keyboard & monitor',
    'npx',	'80x87 numeric co-processor',
    'wdc',	'PC ST506/IDE controller %d',
    'wd',	'PC ST506/IDE disk %d',
    'fdc',	'PC floppy controller %d',
    'fd',	'PC floppy drive %d',
    'aha',	'Adaptec 154x ISA SCSI controller %d',
    'ahb',	'Adaptec 174x EISA SCSI controller %d',
    'bt',	'BusLogic 742 SCSI controller %d',
    'uha',	'UltraStor 14f SCSI controller %d',
    'sea',	'XXX: unknown Seagate SCSI controller %d',
    'aic',	'Adaptec 6360-based SCSI controller %d',
    'scsibus',	'SCSI bus %d',
    'ast',	'4 port serial card #%d',
    'com',	'serial port %d',
    'lpt',	'parallel port %d',
    'mms',	'microsoft InPort bus mouse %d',
    'lms',	'logitech mouse %d',
    'pms',	'PS/2 auxiliary port %d',
    'wt',	'non-scsi tape drive %d',
    'mcd',	'mitsumi non-scsi CDROM %d',
    'sb',	'sound blaster %d',
    'ed',	'wd 80x3, 3com 3c503, ne[12]000 ethernet %d',
    'hp',	'hp ISA ethernet %d',
    'is',	'isolan ethernet %d [OBSOLETE? - use le%d]',
    'ie',	'intel 82586 ethernet %d',
    'le',	'lance ethernet %d',
    'ep',	'3com 3c579? ethernet %d',
    'sd',	'SCSI disk %d',
    'st',	'SCSI tape %d',
    'cd',	'SCSI CDROM %d',
    'ch',	'SCSI tape changer %d',
);

#
#	pseudo devices
#
# %d is the actual argument, %s is "" if %d == 1, else "s"
%pseudo_devices = (
    'pty',	'%d pseudo terminal%s',
    'loop',	'loopback inet, %d interface%s',
    'ether',	'ethernet; REQUIRED for any ethernet device',
    'log',	'kernel gateway into syslogd',
    'bpfilter',	'berkeley packet filter (%d FD%s maximum)',
    'sl',	'compressed SLIP, %d interface%s',
    'ppp',	'point-to-point protocol, %d interface%s',
    'vn',	'%d vn virtual filesystem device%s',
    'speaker',	'speaker queue',
    'tb',	'tablet line discipline',
    'tun',	'network tunnel line discipline',
    'audio',	'/dev/audio',
);

#
#	changable entries
#


%geninfo = ();
@cpuinfo = ();
%optinfo = ();
%devinfo = ();
%pseudodevinfo = ();


#
#	slurp in the file
#
while (<>)
{
    chop;
    next if $_ eq "";		# skip blank lines
    next if /^#/;		# skip full comment lines
    s/#.*//;			# remove extra comments
    local($cmd, $arg, @rest) = split;
    $arg =~ s/"//g;		# remove quotes
    ENTRY:
    {
	$cmd eq "machine" && do
	{
	    print "machine already specified as $geninfo{'machine'}\n"
		    if defined($geninfo{'machine'});
	    $geninfo{'machine'} = $machines{$arg} || ($arg . " [UNDEFINED]");
	    last ENTRY;
	};
	$cmd eq "cpu" && do
	{
	    push(@cpuinfo, $cpus{$arg} || ($arg . " [UNDEFINED]"));
	    last ENTRY;
	};
	$cmd eq "ident" && do
	{
	    print "ident already specified as $geninfo{'ident'}\n"
		    if defined($geninfo{'ident'});
	    $geninfo{'ident'} = $arg;
	    last ENTRY;
	};
	$cmd eq "maxusers" && do
	{
	    print "maxusers already specified as $geninfo{'maxusers'}\n"
		    if defined($geninfo{'maxusers'});
	    $geninfo{'maxusers'} = $arg;
	    last ENTRY;
	};
	$cmd eq "maxfdescs" && do
	{
	    print "maxfdescs already specified as $geninfo{'maxfdescs'}\n"
		    if defined($geninfo{'maxfdescs'});
	    print "maxfdescs has been obsoleted. Please remove it from your config file.\n";
	    $geninfo{'maxfdescs'} = $arg;
	    last ENTRY;
	};
	$cmd eq "timezone" && do			# XXX: improve
	{
	    $geninfo{'timezone'} = $arg . ' ' . join(' ',@rest);
	    last ENTRY;
	};
	$cmd eq "options" && do
	{
	    $arg .= join(' ',@rest);	# add in any options that had whitespace
	    $arg =~ s/\s+//g;		# remove whitespace
	    local(@opts) = split(',', $arg);
	    foreach $option (@opts)
	    {
		local($argname, $argval) = split('=', $option);
		$argval = " = " . $argval if (defined($argval));
		$optinfo{$argname} = $argval;
	    }
	    last ENTRY;
	};
	$cmd eq "config" && do				# XXX: improve
	{
	    print "config already specified as $geninfo{'config'}\n"
		    if defined($geninfo{'config'});
	    $geninfo{'config'} = $arg . ' ' . join(' ',@rest);
	    last ENTRY;
	};
	$cmd =~ /^(master|controller|device|disk|tape)$/ && do
	{
	    $devinfo{$arg} = join(' ', @rest);
	    last ENTRY;
	};
	$cmd eq "pseudo-device" && do
	{
	    $pseudodevinfo{$arg} = join(' ', @rest);
	    last ENTRY;
	};
	print "Unknown directive: $cmd\n";
    } # ENTRY
} # while

#
#	print the config file's innermost secrets :)
#

grep ((do {$geninfo{$_} = "undefined" unless defined($geninfo{$_})} ),
	('machine', 'ident', 'maxusers', 'timezone', 'config'));
$cpuinfo = join(' ', @cpuinfo);

print <<GENINFO;
Machine:	$geninfo{'machine'}
Cpus:		$cpuinfo
Ident:		$geninfo{'ident'}
Config:		$geninfo{'config'}
Max Users:	$geninfo{'maxusers'}
GENINFO

print "\nOptions:\n--------\n";
foreach $opt (sort keys %optinfo)
{
    &print_block($opt . $optinfo{$opt}, 24, $options{$opt} || " [UNDEFINED]");
}

print "\nDevices:\n--------\n";
foreach $ent (sort keys %devinfo)
{
    ($devname, $devnum) = ($ent =~ /(\D+)(\d)$/);
    ($desc = $devices{$devname}) =~ s/%d/$devnum/g;
    &print_block($ent, 24, $desc || " [UNDEFINED]");
}

print "\nPseudo devices:\n---------------\n";
foreach $ent (sort keys %pseudodevinfo)
{
    $num = $pseudodevinfo{$ent} || 1;		# defaults to 1 ("defined")
    ($desc = $pseudo_devices{$ent}) =~ s/%d/$num/g;
    $numstr = ($num == 1 ? "" : "s");
    $desc =~ s/%s/$numstr/g;
    $ent .= " = " . $num if ($num != 1);	# even if explicit =1, ignore
    &print_block($ent, 24, $desc || " [UNDEFINED]");
}

exit 0;


#
# print_block --
#	display info in the form:
#
#  v---------$MAX_COLS------------------v
#  v--$offset--v  
#  $tag           $lines
#
#	($lines may cross multiple lines. $tag is printed for 1st line only)
#

sub
print_block
{
    local($tag, $offset, $lines) = @_;
    local($width) = $MAX_COLS - $offset - 2;
    local($indent) = '@' . '<' x ($offset - 1);
    local($para) = '^' . '<' x ($width - 1);
    local($form) = <<"ENDOFFORM";
format STDOUT =
$indent $para
\$tag,  \$lines
.
ENDOFFORM
    eval $form;
    write;
    $tag = "";
    write while ($lines);
} # print_block
--- cut here ---

-- 
"When I left the monastery, it was not in pursuit of scholarship,
however, but in pursuit of an unparalleled career in crime.
It was quite a shock for me to discover that crime was so easy    Luke Mewburn
that it was boring.  [ ...  ] Solving crime, I had belatedly    <lm@rmit.edu.au>
discovered, was at least a hundred times more difficult than
committing it, so I hung the sign of a half-closed eye above
my door and I have never regretted it."
	-- Li Kao, in Barry Hughart's "Bridge of Birds".

------------------------------------------------------------------------------