home *** CD-ROM | disk | FTP | other *** search
- Path: comp-sources-3b1
- From: dave@galaxia.network23.com (David H. Brierley)
- Subject: v02i024: Floppy disk related utilities for the 3b1, Part01/01
- Newsgroups: comp.sources.3b1
- Approved: dave@galaxia.network23.com
- X-Checksum-Snefru: 2f5d4167 d6912fdf ff50b008 82433370
-
- Submitted-by: dave@galaxia.network23.com (David H. Brierley)
- Posting-number: Volume 2, Issue 24
- Archive-name: floppy/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.
-
- disktest.c
- A program used by the format script to test the floppy disk to be doubly
- sure that it is usable.
-
- format.sh
- Format a floppy disk. Asks questions to determine desired parameters, such
- as number of cylinders and number of sectors. Will optionally run an
- intensive surface test of the floppy (see disktest.c), build a file system
- structure, and make the floppy bootable. The main processing is done in a
- loop so you can format multiple floppies easily.
-
- newfs.sh
- Reads the VHB from the floppy and then builds a file system structure on it.
-
- #! /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 disktest.c format.sh newfs.sh
- # Wrapped by dave@galaxia on Tue Jul 21 10:40:08 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'\" \(282 characters\)
- sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
- X File Name Archive # Description
- X-----------------------------------------------------------
- X MANIFEST 1
- X Makefile 1
- X README 1
- X disktest.c 1
- X format.sh 1
- X newfs.sh 1
- END_OF_FILE
- if test 282 -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 'disktest.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'disktest.c'\"
- else
- echo shar: Extracting \"'disktest.c'\" \(3483 characters\)
- sed "s/^X//" >'disktest.c' <<'END_OF_FILE'
- X#include <stdio.h>
- X#include <sys/gdioctl.h>
- X#include <sys/gdisk.h>
- X#include <fcntl.h>
- X
- Xmain (argc, argv)
- Xint argc;
- Xchar *argv[];
- X{
- X int fd;
- X int verbose;
- X int optch;
- X int passno;
- X int numpass;
- X int track;
- X int numtrks;
- X extern char *optarg;
- X char buffer[512 * 10];
- X char readbuf[512 * 10];
- X int bufsize;
- X int n;
- X char patterns[16];
- X
- X printf ("\nCheck disk size.\n\n");
- X bufsize = fsize ();
- X switch (bufsize) {
- X
- X case 10:
- X printf ("This disk has 10 sectors per track\n");
- X break;
- X case 8:
- X printf ("This disk has 8 sectors per track\n");
- X break;
- X case 4:
- X printf ("Invalid format!\n");
- X exit (3);
- X break;
- X default:
- X printf ("Invalid Format!\n");
- X exit (4);
- X }
- X numpass = 1;
- X verbose = 0;
- X while ((optch = getopt (argc, argv, "vp:")) != EOF) {
- X switch (optch) {
- X case 'v':
- X verbose = 1;
- X break;
- X /* case 's': */
- X /* bufsize = atoi (optarg); */
- X /* break; */
- X case 'p':
- X numpass = atoi (optarg);
- X if (numpass > 16) {
- X numpass = 16;
- X }
- X if (numpass < 1) {
- X numpass = 1;
- X }
- X break;
- X }
- X }
- X
- X if ((bufsize != 8) && (bufsize != 10)) {
- X printf ("Error: specify either 8 or 10 sectors per track\n");
- X exit (1);
- X }
- X
- X bufsize *= 512;
- X patterns[0] = 0x55;
- X patterns[1] = 0xaa;
- X patterns[2] = 0x39;
- X patterns[3] = 0xff;
- X patterns[4] = 0xcc;
- X patterns[5] = 0x1d;
- X patterns[6] = 0xf0;
- X patterns[7] = 0x0f;
- X patterns[8] = 0x44;
- X patterns[9] = 0x11;
- X patterns[10] = 0x72;
- X patterns[11] = 0x92;
- X patterns[12] = 0x6d;
- X patterns[13] = 0x77;
- X patterns[14] = 0xff;
- X patterns[15] = 0x00;
- X
- X fd = open ("/dev/rfp021", 2);
- X if (fd < 0) {
- X perror ("disktest");
- X printf ("Unable to open /dev/rfp021\n");
- X exit (1);
- X }
- X
- X /* fill the disk */
- X for (passno = 0; passno < numpass; passno++) {
- X for (n = 0; n < bufsize; n++) {
- X buffer[n] = patterns[passno];
- X }
- X printf ("Beginning pass number %d\n", passno + 1);
- X for (numtrks = 0;; numtrks++) {
- X if (write (fd, buffer, bufsize) != bufsize) {
- X break;
- X }
- X if (verbose == 1) {
- X write (1, "w", 1);
- X }
- X }
- X if (verbose == 1) {
- X write (1, "\n", 1);
- X }
- X if (lseek (fd, 0, 0) == -1) {
- X printf ("Unable to rewind floppy disk\n");
- X exit (1);
- X }
- X for (track = 0; track < numtrks; track++) {
- X if (verbose == 1) {
- X write (1, "r", 1);
- X }
- X for (n = 0; n < bufsize; n++) {
- X readbuf[n] = 0x33;
- X }
- X if (read (fd, readbuf, bufsize) != bufsize) {
- X printf ("\nError re-reading floppy disk at track %d\n", track);
- X exit (1);
- X }
- X if (compare (readbuf, buffer, bufsize) != 0) {
- X printf ("\nFloppy compare error\n");
- X exit (1);
- X }
- X }
- X if (verbose == 1) {
- X write (1, "\n", 1);
- X }
- X if (lseek (fd, 0, 0) == -1) {
- X printf ("Unable to rewind floppy disk\n");
- X exit (1);
- X }
- X }
- X
- X printf ("Floppy disk surface check OK, tracks = %d\n", numtrks);
- X exit (0);
- X}
- X
- Xcompare (b1, b2, size)
- Xchar *b1;
- Xchar *b2;
- Xint size;
- X{
- X
- X while (size-- > 0) {
- X if (*b1++ != *b2++)
- X return (1);
- X }
- X return (0);
- X
- X}
- X
- X
- Xfsize ()
- X{
- X int fd;
- X struct gdctl finfo;
- X
- X if ((fd = open ("/dev/rfp020", O_RDONLY)) < 0) {
- X perror ("open");
- X return (-1);
- X }
- X
- X if (ioctl (fd, GDGETA, &finfo) < 0) {
- X perror ("ioctl");
- X return (-2);
- X }
- X close (fd);
- X
- X return (finfo.params.psectrk);
- X}
- END_OF_FILE
- if test 3483 -ne `wc -c <'disktest.c'`; then
- echo shar: \"'disktest.c'\" unpacked with wrong size!
- fi
- # end of 'disktest.c'
- fi
- if test -f 'format.sh' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'format.sh'\"
- else
- echo shar: Extracting \"'format.sh'\" \(2172 characters\)
- sed "s/^X//" >'format.sh' <<'END_OF_FILE'
- X:
- Xwhile test "${SECT}" != "8" -a "${SECT}" != "10" -a "${SECT}" != "9"
- Xdo
- X echo "Format: 8 sectors per track or 10? \c"
- X read SECT
- Xdone
- Xwhile true
- Xdo
- X case "${CYL}" in
- X 4[012]|8[01234])
- X break
- X ;;
- X esac
- X echo "How many cylinders (40/42/80/84) ? \c"
- X read CYL
- Xdone
- Xwhile true
- Xdo
- X case "${PASS}" in
- X [0-9]|1[0-6]) break ;;
- X esac
- X echo "How many passes do you want for the surface check? \c"
- X read PASS
- Xdone
- Xwhile true
- Xdo
- X case "${BUILDFS}" in
- X y*|Y*) BUILDFS="yes"; break ;;
- X n*|N*) BUILDFS="no"; break ;;
- X esac
- X echo "Do you want to build a file system on the disk? \c"
- X read BUILDFS
- Xdone
- XVHB_TRKS=1
- Xwhile test "${BUILDFS}" = "yes"
- Xdo
- X case "${LOADER}" in
- X y*|Y*) LOADER="s4load.silent"
- X break
- X ;;
- X n*|N*) LOADER=""
- X VHB_TRKS=1
- X break
- X ;;
- X v*|V*) LOADER="s4load.verbose"
- X break
- X ;;
- X esac
- X echo "Do you want the disk to be bootable (y/n/v) ? \c"
- X read LOADER
- Xdone
- Xcat >/tmp/FD$$ <<E_O_F
- Xtype FD
- Xname floppy
- Xcylinders ${CYL}
- Xheads 2
- Xsectors ${SECT}
- Xsteprate 0
- X$
- XE_O_F
- Xif test "${LOADER}" != ""
- Xthen
- X VHB_BLKS=`ls -s /usr/lib/iv/${LOADER} | awk '{print $1}'`
- X VHB_BLKS=`expr $VHB_BLKS + 4` # allow room for VHB itself
- X VHB_TRKS=`expr $VHB_BLKS / $SECT` # calculate number of tracks
- X if test "`expr $VHB_TRKS \* $SECT`" -lt "${VHB_BLKS}"
- X then
- X VHB_TRKS=`expr $VHB_TRKS + 1`
- X fi
- X echo "loader /usr/lib/iv/${LOADER}" >> /tmp/FD$$
- Xfi
- Xcat >>/tmp/FD$$ <<E_O_F
- X$
- X$
- X0
- X${VHB_TRKS}
- X$
- X$
- XE_O_F
- XBLKS=`expr \( $CYL '*' 2 - $VHB_TRKS \) '*' $SECT`
- XINODES=`expr $BLKS / 4`
- XCYLSIZE=`expr $SECT '*' 2`
- Xwhile true
- Xdo
- X echo ""
- X echo "Press Return to format new floppy or Q to quit: \c"
- X read ANS
- X case "${ANS}" in
- X q*|Q*) break ;;
- X esac
- X date
- X echo "Formatting floppy with $SECT sectors per track, $CYL tracks"
- X iv -iw /dev/rfp020 /tmp/FD$$
- X if test $? -ne 0; then continue; fi
- X iv -t /dev/rfp020
- X if test "${PASS}" = "0"; then
- X echo "skipping disk surface analysis check"
- X else
- X echo "Doing disk surface analysis check"
- X disktest -s ${SECT} -p ${PASS}
- X if test $? -ne 0; then continue; fi
- X fi
- X case "${BUILDFS}" in
- X y*) echo "Building file system"
- X mkfs /dev/rfp021 ${BLKS}:${INODES} 2 ${CYLSIZE}
- X ;;
- X esac
- X echo "It is now safe to remove the floppy"
- Xdone
- Xrm -f /tmp/FD$$
- END_OF_FILE
- if test 2172 -ne `wc -c <'format.sh'`; then
- echo shar: \"'format.sh'\" unpacked with wrong size!
- fi
- chmod +x 'format.sh'
- # end of 'format.sh'
- fi
- if test -f 'newfs.sh' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'newfs.sh'\"
- else
- echo shar: Extracting \"'newfs.sh'\" \(338 characters\)
- sed "s/^X//" >'newfs.sh' <<'END_OF_FILE'
- X: 'sh or ksh'
- Xiv -d /dev/rfp020 > /tmp/newfs.$$
- XCYL=`awk '$1 == "cylinders" {print $2; exit}' /tmp/newfs.$$`
- XSECT=`awk '$1 == "sectors" {print $2; exit}' /tmp/newfs.$$`
- XBLKS=`expr \( $CYL '*' 2 - 1 \) '*' $SECT`
- XINODES=`expr $BLKS / 4`
- XCYLSIZE=`expr $SECT '*' 2`
- Xmkfs /dev/rfp021 ${BLKS}:${INODES} 2 ${CYLSIZE}
- Xrm -f /tmp/newfs.$$
- Xexit 0
- END_OF_FILE
- if test 338 -ne `wc -c <'newfs.sh'`; then
- echo shar: \"'newfs.sh'\" unpacked with wrong size!
- fi
- chmod +x 'newfs.sh'
- # end of 'newfs.sh'
- 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. **
-