home *** CD-ROM | disk | FTP | other *** search
- Path: comp-sources-3b1
- From: dave@galaxia.network23.com (David H. Brierley)
- Subject: v02i026: Berkeley style df command for the 3b1, Part01/01
- Newsgroups: comp.sources.3b1
- Approved: dave@galaxia.network23.com
- X-Checksum-Snefru: e11676cc 0dc24940 8bb79820 b9e61c38
-
- Submitted-by: dave@galaxia.network23.com (David H. Brierley)
- Posting-number: Volume 2, Issue 26
- Archive-name: ndf/part01
-
- This is the README file for the Dave Brierley collection of miscellaneous
- source programs. The collection is posted in seven separate pieces but
- all of the source came from the "misc" directory on my machine. As a result
- of this, there is only one README file and only one Makefile, although each
- of the seven postings will contain a copy of these two files. I suggest
- that you obtain (or save) as many of these postings as you are interested
- in, unpack them all in a single directory, and then compile the sources.
- Note that some of the programs are actually shell scripts and therefore do
- not need compilation.
-
- ndf.c
- Almost emulates the BSD df command. I say "almost" because I chose to
- display the numbers in terms of blocks instead of kbytes since everything
- else on the machine displays sizes in blocks. Supports the "-i" option
- to displays inode information. Also supports specifying any random
- directory as an argument and it will figure out what file system it is.
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 1 (of 1)."
- # Contents: MANIFEST Makefile README ndf.c
- # Wrapped by dave@galaxia on Tue Jul 21 10:38:47 1992
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'MANIFEST' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'MANIFEST'\"
- else
- echo shar: Extracting \"'MANIFEST'\" \(220 characters\)
- sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
- X File Name Archive # Description
- X-----------------------------------------------------------
- X MANIFEST 1
- X Makefile 1
- X README 1
- X ndf.c 1
- END_OF_FILE
- if test 220 -ne `wc -c <'MANIFEST'`; then
- echo shar: \"'MANIFEST'\" unpacked with wrong size!
- fi
- # end of 'MANIFEST'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(374 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- XCFLAGS = -O
- X
- Xall: bsdln disktest email ndf techo wclipper
- X
- Xbsdln: bsdln.o
- X $(CC) bsdln.o
- X mv a.out bsdln
- X
- Xdisktest: disktest.o
- X $(CC) disktest.o
- X mv a.out disktest
- X
- Xemail: email.o
- X $(CC) email.o
- X mv a.out email
- X
- Xndf: ndf.o
- X $(CC) ndf.o
- X mv a.out ndf
- X
- Xtecho: techo.o
- X $(CC) techo.o
- X mv a.out techo
- X
- Xwclipper: wclipper.o
- X $(CC) wclipper.o
- X mv a.out wclipper
- X
- END_OF_FILE
- if test 374 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(4280 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- XThis is the README file for the Dave Brierley collection of miscellaneous
- Xsource programs. The collection is posted in seven separate pieces but
- Xall of the source came from the "misc" directory on my machine. As a result
- Xof this, there is only one README file and only one Makefile, although each
- Xof the seven postings will contain a copy of these two files. I suggest
- Xthat you obtain (or save) as many of these postings as you are interested
- Xin, unpack them all in a single directory, and then compile the sources.
- XNote that some of the programs are actually shell scripts and therefore do
- Xnot need compilation.
- X
- XINSTALLATION INSTRUCTIONS:
- X1. Compile all the source programs by typing "make all". Edit the Makefile
- X if you did not unpack all seven of the pieces. Note that the Makefile
- X does not contain explicit commands for using the shared library. I always
- X depend on "ccc" to do this for me.
- X2. Copy the resultant executables to your favorite bin directory. I always
- X use "/usr/local/bin".
- X3. Copy the various shell scripts to the bin directory and make then executable
- X using the chmod command. The shell scripts are all distributed with a
- X suffix of ".sh". I suggest you remove this suffix when you install it, but
- X that is entirely up to you.
- X
- X
- XDescription of programs included in this package. There is a line of dashes
- Xseparating each of the seven pieces.
- X
- Xbsdln.c
- X A version of the ln command that follows the BSD behaviour. I.e. if the
- X target file exists, the command will fail. The standard 3b1 version will
- X remove the target.
- X
- X--------------------------------------------------------------------------
- X
- Xinstall.sh
- X A shell script version of the BSD install command.
- X
- Xnull.sh
- X Zero out one or more files.
- X
- Xtolower.sh
- X Convert file names to lower case. Requires ksh.
- X
- Xtoupper.sh
- X Convert file names to upper case. Requires ksh.
- X
- X--------------------------------------------------------------------------
- X
- Xndf.c
- X Almost emulates the BSD df command. I say "almost" because I chose to
- X display the numbers in terms of blocks instead of kbytes since everything
- X else on the machine displays sizes in blocks. Supports the "-i" option
- X to displays inode information. Also supports specifying any random
- X directory as an argument and it will figure out what file system it is.
- X
- X--------------------------------------------------------------------------
- X
- Xdisktest.c
- X A program used by the format script to test the floppy disk to be doubly
- X sure that it is usable.
- X
- Xformat.sh
- X Format a floppy disk. Asks questions to determine desired parameters, such
- X as number of cylinders and number of sectors. Will optionally run an
- X intensive surface test of the floppy (see disktest.c), build a file system
- X structure, and make the floppy bootable. The main processing is done in a
- X loop so you can format multiple floppies easily.
- X
- Xnewfs.sh
- X Reads the VHB from the floppy and then builds a file system structure on it.
- X
- X--------------------------------------------------------------------------
- X
- Xtecho.c
- X A version of echo that allows direct access to termcap capabilities. A lot
- X easier to use than intermixing calls to echo with calls to tput.
- X
- Xtecho.1
- X Hey, I actually wrote a man page for this one!
- X
- X--------------------------------------------------------------------------
- X
- Xwclipper.c
- X A program to read in the wtmp file and output the tail end of it. Useful
- X if you want to maintain an N-day history of who has been using your system.
- X The output size can be specified in terms of days or kbytes.
- X
- Xwtmp.fix.sh
- X A shell script to control the operation of wclipper.
- X
- X--------------------------------------------------------------------------
- X
- Xemail.c
- X A version of the "email" program. This program should be installed as
- X /usr/bin/email and it will be used by pcmgr (or by smgr) when you click
- X on the envelope icon. It provides a safe interface to the mail program
- X by making sure the uid is set correctly and by doing a chdir to the
- X users home directory (both of which are already being done by pcmgr).
- X This version also provides a unique feature of reading an "rc" file
- X from the users home directory (~/.email.rc), which can be used to specify
- X what mail program to use. See the sample provided.
- X
- Xemail.rc
- X Sample .email.rc file.
- END_OF_FILE
- if test 4280 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'ndf.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ndf.c'\"
- else
- echo shar: Extracting \"'ndf.c'\" \(8245 characters\)
- sed "s/^X//" >'ndf.c' <<'END_OF_FILE'
- X/***************************************************************************
- X *
- X * Program: Berkeley style df program
- X *
- X * Author: David H. Brierley, October 1987
- X * Galaxia Systems Ltd.
- X * {cbosgd,gatech,necntc,uiucdcs}!rayssd!galaxia!dave
- X *
- X * Function:
- X * Provides a Berkeley style df command for non-Berkeley systems.
- X * Standard output includes the total size of the file system, the
- X * number of used and available block, and the percent used. The
- X * -i option requests similar information for the inode table.
- X * Additional arguments may be supplied which specify which file
- X * system(s) is to be displayed. The name may be specified either
- X * as a device name or a directory name within the mounted file
- X * system.
- X *
- X * Note: This program was written for the ATT Unix PC (7300). Since
- X * it is relatively straight forward it should be easy to port
- X * to other systems if you want to. Send me mail if you do port
- X * it so that I can include the changes into my official source.
- X *
- X * Note: This program does not contain any Berkeley code (or any other
- X * licensed code for that matter). The only reason I call the
- X * program "a Berkeley style df" is that the output is similar
- X * to the output produced by the df command from Berkeley.
- X *
- X * Copyright notice:
- X * Copyright 1987 David H. Brierley
- X * Permission is granted to freely copy, modify, and use this software
- X * in any way that you see fit, subject to the following restrictions:
- X * 1. This software may not be used for commercial gain without the
- X * express written permission of the author.
- X * 2. The author assumes no liability for any consequences arising
- X * from the use of this software.
- X * 3. Derivative works must be clearly labelled as such and must not
- X * be misrepresented as the original software.
- X * 4. This notice must be retained in all copies and derivative works.
- X *
- X ***************************************************************************/
- X
- X#ifndef lint
- Xstatic char *SccsId = "@(#) SCCS/s.df.c: version 1.2 8/15/90";
- X#endif
- X
- X#include <stdio.h>
- X#include <string.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X#include <mnttab.h>
- X#include <sys/filsys.h>
- X#include <sys/param.h>
- X#include <sys/ino.h>
- X
- X#define MNTTAB "/etc/mnttab"
- X#define INOPERBLK (512 / sizeof (struct dinode))
- X
- X/*
- X * table for holding info about mounted file systems
- X */
- Xstruct mtable {
- X char m_device[16];
- X char m_filsys[16];
- X dev_t m_dev;
- X};
- X
- X/* declare external routines */
- Xextern void exit ();
- Xextern void perror ();
- Xextern long lseek ();
- X
- Xmain (argc, argv)
- Xint argc;
- Xchar *argv[];
- X{
- X struct mtable m_info[NMOUNT];
- X int m_size;
- X int optch;
- X int iflag;
- X int n;
- X extern int optind;
- X
- X iflag = 0;
- X while ((optch = getopt (argc, argv, "i")) != EOF) {
- X switch (optch) {
- X case 'i':
- X iflag = 1;
- X break;
- X default:
- X (void) printf ("df: unknown option '%c'\n", optch);
- X exit (1);
- X }
- X }
- X
- X /*
- X * read the mount table
- X */
- X m_size = read_mtab (m_info);
- X
- X (void) printf ("DeviceName Blocks used avail %%used");
- X if (iflag) {
- X (void) printf (" iused ifree %%iused");
- X }
- X (void) printf (" Mounted on\n");
- X
- X /*
- X * if no arguments, print the mount table
- X */
- X if (optind == argc) {
- X for (n = 0; n < m_size; n++) {
- X display (&m_info[n], iflag);
- X }
- X exit (0);
- X }
- X
- X /*
- X * process the specified file systems
- X */
- X for (; optind < argc; optind++) {
- X fscheck (argv[optind], m_info, m_size, iflag);
- X }
- X
- X return (0);
- X
- X}
- X
- X/*
- X * Routine: read_mtab
- X *
- X * Read the mount table and extract info about each file
- X * system. The file system is also "stat"ed to extract
- X * the device number.
- X *
- X */
- X
- Xread_mtab (info)
- Xstruct mtable info[];
- X{
- X int n;
- X int fd;
- X struct mnttab mtab;
- X struct stat sbuf;
- X
- X#define L_DEV (sizeof(mtab.mt_dev))
- X#define L_FILSYS (sizeof(mtab.mt_filsys))
- X
- X if ((fd = open (MNTTAB, 0)) == -1) {
- X perror ("df");
- X (void) printf ("Unable to open file %s\n", MNTTAB);
- X exit (1);
- X }
- X
- X n = 0;
- X while (read (fd, &mtab, sizeof (mtab)) == sizeof (mtab)) {
- X (void) strcpy (info[n].m_device, "/dev/");
- X (void) strncat (info[n].m_device, mtab.mt_dev, L_DEV);
- X info[n].m_device[L_DEV] = '\0';
- X (void) strncpy (info[n].m_filsys, mtab.mt_filsys, L_FILSYS);
- X info[n].m_filsys[L_FILSYS] = '\0';
- X if (stat (info[n].m_device, &sbuf) == -1) {
- X continue;
- X }
- X info[n].m_dev = sbuf.st_rdev;
- X n++;
- X }
- X
- X (void) close (fd);
- X return (n);
- X
- X}
- X
- X/*
- X * Routine: display
- X *
- X * Display information about the specified file system.
- X *
- X */
- X
- Xdisplay (mtbl, iflag)
- Xstruct mtable *mtbl;
- Xint iflag;
- X{
- X int tot;
- X int used;
- X int avail;
- X double pct;
- X struct filsys fsys;
- X int fd;
- X int type;
- X
- X /* sync 3 times on the console if you want me, */
- X /* twice on the pipe if the answer is no. */
- X sync ();
- X sync ();
- X
- X if ((fd = open (mtbl -> m_device)) == -1) {
- X perror ("df");
- X (void) printf ("%s: unable to open device\n", mtbl -> m_device);
- X return;
- X }
- X
- X /*
- X * Read and validate the super-block
- X */
- X if (lseek (fd, 512L, 0) == -1L) {
- X perror ("df");
- X (void) printf ("%s: unable to seek to super-block\n", mtbl -> m_device);
- X (void) close (fd);
- X return;
- X }
- X
- X if (read (fd, &fsys, sizeof (fsys)) != sizeof (fsys)) {
- X perror ("df");
- X (void) printf ("%s: i/o error reading super-block\n", mtbl -> m_device);
- X (void) close (fd);
- X return;
- X }
- X (void) close (fd);
- X
- X if (sbcheck (&fsys) == -1) {
- X (void) printf ("%s: invalid super-block\n", mtbl -> m_device);
- X return;
- X }
- X
- X type = 1;
- X if (fsys.s_magic == FsMAGIC) {
- X type = fsys.s_type;
- X }
- X
- X /*
- X * calculate the numbers and print them out
- X */
- X tot = fsys.s_fsize * type;
- X avail = fsys.s_tfree * type;
- X used = tot - avail;
- X if (tot > 0) {
- X pct = ((double) used / (double) tot) * 100.0;
- X }
- X (void) printf ("%-12s", mtbl -> m_device);
- X (void) printf ("%7d%7d%7d%6.0f%%", tot, used, avail, pct);
- X if (iflag) {
- X tot = ((fsys.s_isize - 2) * type) * INOPERBLK;
- X avail = fsys.s_tinode;
- X used = tot - avail;
- X if (tot > 0) {
- X pct = ((double) used / (double) tot) * 100.0;
- X }
- X (void) printf ("%7d%7d%6.0f%%", used, avail, pct);
- X }
- X (void) printf (" %s\n", mtbl -> m_filsys);
- X
- X}
- X
- X/*
- X * Routine: sbcheck
- X *
- X * Perform various sanity checks on the fields in the super block.
- X * This is to prevent things like reading a non-filesystem format
- X * floppy.
- X *
- X */
- X
- Xsbcheck (fsys)
- Xstruct filsys *fsys;
- X{
- X
- X if (fsys -> s_isize & 0x8000) {
- X return (-1);
- X }
- X if (fsys -> s_fsize < 0) {
- X return (-1);
- X }
- X if (fsys -> s_isize >= fsys -> s_fsize) {
- X return (-1);
- X }
- X if (fsys -> s_nfree > NICFREE) {
- X return (-1);
- X }
- X if (fsys -> s_ninode > NICINOD) {
- X return (-1);
- X }
- X if (fsys -> s_tfree >= fsys -> s_fsize) {
- X return (-1);
- X }
- X if (fsys -> s_tfree < 0) {
- X return (-1);
- X }
- X if (fsys -> s_tinode >= fsys -> s_fsize) {
- X return (-1);
- X }
- X
- X return (0);
- X
- X}
- X
- X/*
- X * Routine: fscheck
- X *
- X * Check to see if the specified path name is part of a mounted
- X * filesystem or is a special device file. If so, print out the
- X * info. If not, print out an error message.
- X *
- X */
- X
- Xfscheck (DirName, m_info, m_size, iflag)
- Xchar *DirName;
- Xstruct mtable m_info[];
- Xint m_size;
- Xint iflag;
- X{
- X struct stat sbuf;
- X struct mtable fake;
- X int n;
- X
- X if (stat (DirName, &sbuf) == -1) {
- X perror ("df");
- X (void) printf ("%s: unable to access file\n", DirName);
- X return;
- X }
- X
- X if ((sbuf.st_mode & S_IFMT) == S_IFBLK) {
- X (void) strcpy (fake.m_device, DirName);
- X (void) strcpy (fake.m_filsys, "");
- X display (&fake, iflag);
- X return;
- X }
- X
- X if ((sbuf.st_mode & S_IFMT) == S_IFCHR) {
- X (void) strcpy (fake.m_device, DirName);
- X (void) strcpy (fake.m_filsys, "");
- X display (&fake, iflag);
- X return;
- X }
- X
- X for (n = 0; n < m_size; n++) {
- X if (sbuf.st_dev == m_info[n].m_dev) {
- X display (&m_info[n], iflag);
- X return;
- X }
- X }
- X
- X (void) printf ("%s: mounted on unknown device\n", DirName);
- X
- X}
- END_OF_FILE
- if test 8245 -ne `wc -c <'ndf.c'`; then
- echo shar: \"'ndf.c'\" unpacked with wrong size!
- fi
- # end of 'ndf.c'
- fi
- echo shar: End of archive 1 \(of 1\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have the archive.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
- --
- David H. Brierley
- Home: dave@galaxia.network23.com; Work: dhb@quahog.ssd.ray.com
- Send comp.sources.3b1 submissions to comp-sources-3b1@galaxia.network23.com
- %% Can I be excused, my brain is full. **
-