home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sources / 3b1 / 77 < prev    next >
Encoding:
Internet Message Format  |  1992-07-21  |  16.0 KB

  1. Path: sparky!uunet!comp-sources-3b1
  2. From: dave@galaxia.network23.com (David H. Brierley)
  3. Newsgroups: comp.sources.3b1
  4. Subject: v02i024:  Floppy disk related utilities for the 3b1, Part01/01
  5. Date: 21 Jul 1992 22:27:51 -0400
  6. Organization: UUNET Communications
  7. Lines: 563
  8. Sender: dhb@ftp.UU.NET
  9. Approved: dave@galaxia.network23.com
  10. Message-ID: <14ih37INNd72@ftp.UU.NET>
  11. NNTP-Posting-Host: ftp.uu.net
  12. X-Checksum-Snefru: 2f5d4167 d6912fdf ff50b008 82433370
  13.  
  14. Submitted-by: dave@galaxia.network23.com (David H. Brierley)
  15. Posting-number: Volume 2, Issue 24
  16. Archive-name: floppy/part01
  17.  
  18. This is the README file for the Dave Brierley collection of miscellaneous
  19. source programs.  The collection is posted in seven separate pieces but
  20. all of the source came from the "misc" directory on my machine.  As a result
  21. of this, there is only one README file and only one Makefile, although each
  22. of the seven postings will contain a copy of these two files.  I suggest
  23. that you obtain (or save) as many of these postings as you are interested
  24. in, unpack them all in a single directory, and then compile the sources.
  25. Note that some of the programs are actually shell scripts and therefore do
  26. not need compilation.
  27.  
  28. disktest.c
  29.  A program used by the format script to test the floppy disk to be doubly
  30.  sure that it is usable.
  31.  
  32. format.sh
  33.  Format a floppy disk.  Asks questions to determine desired parameters, such
  34.  as number of cylinders and number of sectors.  Will optionally run an
  35.  intensive surface test of the floppy (see disktest.c), build a file system
  36.  structure, and make the floppy bootable.  The main processing is done in a
  37.  loop so you can format multiple floppies easily.
  38.  
  39. newfs.sh
  40.  Reads the VHB from the floppy and then builds a file system structure on it.
  41.  
  42. #! /bin/sh
  43. # This is a shell archive.  Remove anything before this line, then unpack
  44. # it by saving it into a file and typing "sh file".  To overwrite existing
  45. # files, type "sh file -c".  You can also feed this as standard input via
  46. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  47. # will see the following message at the end:
  48. #        "End of archive 1 (of 1)."
  49. # Contents:  MANIFEST Makefile README disktest.c format.sh newfs.sh
  50. # Wrapped by dave@galaxia on Tue Jul 21 10:40:08 1992
  51. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  52. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  53.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  54. else
  55. echo shar: Extracting \"'MANIFEST'\" \(282 characters\)
  56. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  57. X   File Name        Archive #    Description
  58. X-----------------------------------------------------------
  59. X MANIFEST                   1    
  60. X Makefile                   1    
  61. X README                     1    
  62. X disktest.c                 1    
  63. X format.sh                  1    
  64. X newfs.sh                   1    
  65. END_OF_FILE
  66. if test 282 -ne `wc -c <'MANIFEST'`; then
  67.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  68. fi
  69. # end of 'MANIFEST'
  70. fi
  71. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  72.   echo shar: Will not clobber existing file \"'Makefile'\"
  73. else
  74. echo shar: Extracting \"'Makefile'\" \(374 characters\)
  75. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  76. XCFLAGS    = -O
  77. X
  78. Xall:        bsdln disktest email ndf techo wclipper
  79. X
  80. Xbsdln:        bsdln.o
  81. X        $(CC) bsdln.o
  82. X        mv a.out bsdln
  83. X
  84. Xdisktest:    disktest.o
  85. X        $(CC) disktest.o
  86. X        mv a.out disktest
  87. X
  88. Xemail:        email.o
  89. X        $(CC) email.o
  90. X        mv a.out email
  91. X
  92. Xndf:        ndf.o
  93. X        $(CC) ndf.o
  94. X        mv a.out ndf
  95. X
  96. Xtecho:        techo.o
  97. X        $(CC) techo.o
  98. X        mv a.out techo
  99. X
  100. Xwclipper:    wclipper.o
  101. X        $(CC) wclipper.o
  102. X        mv a.out wclipper
  103. X
  104. END_OF_FILE
  105. if test 374 -ne `wc -c <'Makefile'`; then
  106.     echo shar: \"'Makefile'\" unpacked with wrong size!
  107. fi
  108. # end of 'Makefile'
  109. fi
  110. if test -f 'README' -a "${1}" != "-c" ; then 
  111.   echo shar: Will not clobber existing file \"'README'\"
  112. else
  113. echo shar: Extracting \"'README'\" \(4280 characters\)
  114. sed "s/^X//" >'README' <<'END_OF_FILE'
  115. XThis is the README file for the Dave Brierley collection of miscellaneous
  116. Xsource programs.  The collection is posted in seven separate pieces but
  117. Xall of the source came from the "misc" directory on my machine.  As a result
  118. Xof this, there is only one README file and only one Makefile, although each
  119. Xof the seven postings will contain a copy of these two files.  I suggest
  120. Xthat you obtain (or save) as many of these postings as you are interested
  121. Xin, unpack them all in a single directory, and then compile the sources.
  122. XNote that some of the programs are actually shell scripts and therefore do
  123. Xnot need compilation.
  124. X
  125. XINSTALLATION INSTRUCTIONS:
  126. X1. Compile all the source programs by typing "make all".  Edit the Makefile
  127. X   if you did not unpack all seven of the pieces.  Note that the Makefile
  128. X   does not contain explicit commands for using the shared library.  I always
  129. X   depend on "ccc" to do this for me.
  130. X2. Copy the resultant executables to your favorite bin directory.  I always
  131. X   use "/usr/local/bin".
  132. X3. Copy the various shell scripts to the bin directory and make then executable
  133. X   using the chmod command.  The shell scripts are all distributed with a
  134. X   suffix of ".sh".  I suggest you remove this suffix when you install it, but
  135. X   that is entirely up to you.
  136. X
  137. X
  138. XDescription of programs included in this package.  There is a line of dashes
  139. Xseparating each of the seven pieces.
  140. X
  141. Xbsdln.c
  142. X A version of the ln command that follows the BSD behaviour.  I.e. if the
  143. X target file exists, the command will fail.  The standard 3b1 version will
  144. X remove the target.
  145. X
  146. X--------------------------------------------------------------------------
  147. X
  148. Xinstall.sh
  149. X A shell script version of the BSD install command.
  150. X
  151. Xnull.sh
  152. X Zero out one or more files.
  153. X
  154. Xtolower.sh
  155. X Convert file names to lower case.  Requires ksh.
  156. X
  157. Xtoupper.sh
  158. X Convert file names to upper case.  Requires ksh.
  159. X
  160. X--------------------------------------------------------------------------
  161. X
  162. Xndf.c
  163. X Almost emulates the BSD df command.  I say "almost" because I chose to
  164. X display the numbers in terms of blocks instead of kbytes since everything
  165. X else on the machine displays sizes in blocks.  Supports the "-i" option
  166. X to displays inode information.  Also supports specifying any random
  167. X directory as an argument and it will figure out what file system it is.
  168. X
  169. X--------------------------------------------------------------------------
  170. X
  171. Xdisktest.c
  172. X A program used by the format script to test the floppy disk to be doubly
  173. X sure that it is usable.
  174. X
  175. Xformat.sh
  176. X Format a floppy disk.  Asks questions to determine desired parameters, such
  177. X as number of cylinders and number of sectors.  Will optionally run an
  178. X intensive surface test of the floppy (see disktest.c), build a file system
  179. X structure, and make the floppy bootable.  The main processing is done in a
  180. X loop so you can format multiple floppies easily.
  181. X
  182. Xnewfs.sh
  183. X Reads the VHB from the floppy and then builds a file system structure on it.
  184. X
  185. X--------------------------------------------------------------------------
  186. X
  187. Xtecho.c
  188. X A version of echo that allows direct access to termcap capabilities.  A lot
  189. X easier to use than intermixing calls to echo with calls to tput.
  190. X
  191. Xtecho.1
  192. X Hey, I actually wrote a man page for this one!
  193. X
  194. X--------------------------------------------------------------------------
  195. X
  196. Xwclipper.c
  197. X A program to read in the wtmp file and output the tail end of it.  Useful
  198. X if you want to maintain an N-day history of who has been using your system.
  199. X The output size can be specified in terms of days or kbytes.
  200. X
  201. Xwtmp.fix.sh
  202. X A shell script to control the operation of wclipper.
  203. X
  204. X--------------------------------------------------------------------------
  205. X
  206. Xemail.c
  207. X A version of the "email" program.  This program should be installed as
  208. X /usr/bin/email and it will be used by pcmgr (or by smgr) when you click
  209. X on the envelope icon.  It provides a safe interface to the mail program
  210. X by making sure the uid is set correctly and by doing a chdir to the
  211. X users home directory (both of which are already being done by pcmgr).
  212. X This version also provides a unique feature of reading an "rc" file
  213. X from the users home directory (~/.email.rc), which can be used to specify
  214. X what mail program to use.  See the sample provided.
  215. X
  216. Xemail.rc
  217. X Sample .email.rc file.
  218. END_OF_FILE
  219. if test 4280 -ne `wc -c <'README'`; then
  220.     echo shar: \"'README'\" unpacked with wrong size!
  221. fi
  222. # end of 'README'
  223. fi
  224. if test -f 'disktest.c' -a "${1}" != "-c" ; then 
  225.   echo shar: Will not clobber existing file \"'disktest.c'\"
  226. else
  227. echo shar: Extracting \"'disktest.c'\" \(3483 characters\)
  228. sed "s/^X//" >'disktest.c' <<'END_OF_FILE'
  229. X#include <stdio.h>
  230. X#include <sys/gdioctl.h>
  231. X#include <sys/gdisk.h>
  232. X#include <fcntl.h>
  233. X
  234. Xmain (argc, argv)
  235. Xint         argc;
  236. Xchar       *argv[];
  237. X{
  238. X    int         fd;
  239. X    int         verbose;
  240. X    int         optch;
  241. X    int         passno;
  242. X    int         numpass;
  243. X    int         track;
  244. X    int         numtrks;
  245. X    extern char *optarg;
  246. X    char        buffer[512 * 10];
  247. X    char        readbuf[512 * 10];
  248. X    int         bufsize;
  249. X    int         n;
  250. X    char        patterns[16];
  251. X
  252. X    printf ("\nCheck disk size.\n\n");
  253. X    bufsize = fsize ();
  254. X    switch (bufsize) {
  255. X
  256. X    case 10:
  257. X    printf ("This disk has 10 sectors per track\n");
  258. X    break;
  259. X    case 8:
  260. X    printf ("This disk has 8 sectors per track\n");
  261. X    break;
  262. X    case 4:
  263. X    printf ("Invalid format!\n");
  264. X    exit (3);
  265. X    break;
  266. X    default:
  267. X    printf ("Invalid Format!\n");
  268. X    exit (4);
  269. X    }
  270. X    numpass = 1;
  271. X    verbose = 0;
  272. X    while ((optch = getopt (argc, argv, "vp:")) != EOF) {
  273. X    switch (optch) {
  274. X    case 'v':
  275. X        verbose = 1;
  276. X        break;
  277. X        /* case 's': */
  278. X        /* bufsize = atoi (optarg); */
  279. X        /* break; */
  280. X    case 'p':
  281. X        numpass = atoi (optarg);
  282. X        if (numpass > 16) {
  283. X        numpass = 16;
  284. X        }
  285. X        if (numpass < 1) {
  286. X        numpass = 1;
  287. X        }
  288. X        break;
  289. X    }
  290. X    }
  291. X
  292. X    if ((bufsize != 8) && (bufsize != 10)) {
  293. X    printf ("Error: specify either 8 or 10 sectors per track\n");
  294. X    exit (1);
  295. X    }
  296. X
  297. X    bufsize *= 512;
  298. X    patterns[0] = 0x55;
  299. X    patterns[1] = 0xaa;
  300. X    patterns[2] = 0x39;
  301. X    patterns[3] = 0xff;
  302. X    patterns[4] = 0xcc;
  303. X    patterns[5] = 0x1d;
  304. X    patterns[6] = 0xf0;
  305. X    patterns[7] = 0x0f;
  306. X    patterns[8] = 0x44;
  307. X    patterns[9] = 0x11;
  308. X    patterns[10] = 0x72;
  309. X    patterns[11] = 0x92;
  310. X    patterns[12] = 0x6d;
  311. X    patterns[13] = 0x77;
  312. X    patterns[14] = 0xff;
  313. X    patterns[15] = 0x00;
  314. X
  315. X    fd = open ("/dev/rfp021", 2);
  316. X    if (fd < 0) {
  317. X    perror ("disktest");
  318. X    printf ("Unable to open /dev/rfp021\n");
  319. X    exit (1);
  320. X    }
  321. X
  322. X    /* fill the disk */
  323. X    for (passno = 0; passno < numpass; passno++) {
  324. X    for (n = 0; n < bufsize; n++) {
  325. X        buffer[n] = patterns[passno];
  326. X    }
  327. X    printf ("Beginning pass number %d\n", passno + 1);
  328. X    for (numtrks = 0;; numtrks++) {
  329. X        if (write (fd, buffer, bufsize) != bufsize) {
  330. X        break;
  331. X        }
  332. X        if (verbose == 1) {
  333. X        write (1, "w", 1);
  334. X        }
  335. X    }
  336. X    if (verbose == 1) {
  337. X        write (1, "\n", 1);
  338. X    }
  339. X    if (lseek (fd, 0, 0) == -1) {
  340. X        printf ("Unable to rewind floppy disk\n");
  341. X        exit (1);
  342. X    }
  343. X    for (track = 0; track < numtrks; track++) {
  344. X        if (verbose == 1) {
  345. X        write (1, "r", 1);
  346. X        }
  347. X        for (n = 0; n < bufsize; n++) {
  348. X        readbuf[n] = 0x33;
  349. X        }
  350. X        if (read (fd, readbuf, bufsize) != bufsize) {
  351. X        printf ("\nError re-reading floppy disk at track %d\n", track);
  352. X        exit (1);
  353. X        }
  354. X        if (compare (readbuf, buffer, bufsize) != 0) {
  355. X        printf ("\nFloppy compare error\n");
  356. X        exit (1);
  357. X        }
  358. X    }
  359. X    if (verbose == 1) {
  360. X        write (1, "\n", 1);
  361. X    }
  362. X    if (lseek (fd, 0, 0) == -1) {
  363. X        printf ("Unable to rewind floppy disk\n");
  364. X        exit (1);
  365. X    }
  366. X    }
  367. X
  368. X    printf ("Floppy disk surface check OK, tracks = %d\n", numtrks);
  369. X    exit (0);
  370. X}
  371. X
  372. Xcompare (b1, b2, size)
  373. Xchar       *b1;
  374. Xchar       *b2;
  375. Xint         size;
  376. X{
  377. X
  378. X    while (size-- > 0) {
  379. X    if (*b1++ != *b2++)
  380. X        return (1);
  381. X    }
  382. X    return (0);
  383. X
  384. X}
  385. X
  386. X
  387. Xfsize ()
  388. X{
  389. X    int         fd;
  390. X    struct gdctl finfo;
  391. X
  392. X    if ((fd = open ("/dev/rfp020", O_RDONLY)) < 0) {
  393. X    perror ("open");
  394. X    return (-1);
  395. X    }
  396. X
  397. X    if (ioctl (fd, GDGETA, &finfo) < 0) {
  398. X    perror ("ioctl");
  399. X    return (-2);
  400. X    }
  401. X    close (fd);
  402. X
  403. X    return (finfo.params.psectrk);
  404. X}
  405. END_OF_FILE
  406. if test 3483 -ne `wc -c <'disktest.c'`; then
  407.     echo shar: \"'disktest.c'\" unpacked with wrong size!
  408. fi
  409. # end of 'disktest.c'
  410. fi
  411. if test -f 'format.sh' -a "${1}" != "-c" ; then 
  412.   echo shar: Will not clobber existing file \"'format.sh'\"
  413. else
  414. echo shar: Extracting \"'format.sh'\" \(2172 characters\)
  415. sed "s/^X//" >'format.sh' <<'END_OF_FILE'
  416. X:
  417. Xwhile test "${SECT}" != "8" -a "${SECT}" != "10" -a "${SECT}" != "9"
  418. Xdo
  419. X    echo "Format: 8 sectors per track or 10? \c"
  420. X    read SECT
  421. Xdone
  422. Xwhile true
  423. Xdo
  424. X    case "${CYL}" in
  425. X    4[012]|8[01234])
  426. X        break
  427. X        ;;
  428. X    esac
  429. X    echo "How many cylinders (40/42/80/84) ? \c"
  430. X    read CYL
  431. Xdone
  432. Xwhile true
  433. Xdo
  434. X    case "${PASS}" in
  435. X    [0-9]|1[0-6])    break ;;
  436. X    esac
  437. X    echo "How many passes do you want for the surface check? \c"
  438. X    read PASS
  439. Xdone
  440. Xwhile true
  441. Xdo
  442. X    case "${BUILDFS}" in
  443. X    y*|Y*)    BUILDFS="yes"; break ;;
  444. X    n*|N*)    BUILDFS="no";  break ;;
  445. X    esac
  446. X    echo "Do you want to build a file system on the disk? \c"
  447. X    read BUILDFS
  448. Xdone
  449. XVHB_TRKS=1
  450. Xwhile test "${BUILDFS}" = "yes"
  451. Xdo
  452. X    case "${LOADER}" in
  453. X    y*|Y*)    LOADER="s4load.silent"
  454. X        break
  455. X        ;;
  456. X    n*|N*)    LOADER=""
  457. X        VHB_TRKS=1
  458. X        break
  459. X        ;;
  460. X    v*|V*)    LOADER="s4load.verbose"
  461. X        break
  462. X        ;;
  463. X    esac
  464. X    echo "Do you want the disk to be bootable (y/n/v) ? \c"
  465. X    read LOADER
  466. Xdone
  467. Xcat >/tmp/FD$$ <<E_O_F
  468. Xtype        FD
  469. Xname        floppy
  470. Xcylinders    ${CYL}
  471. Xheads        2
  472. Xsectors        ${SECT}
  473. Xsteprate    0
  474. X$
  475. XE_O_F
  476. Xif test "${LOADER}" != ""
  477. Xthen
  478. X    VHB_BLKS=`ls -s /usr/lib/iv/${LOADER} | awk '{print $1}'`
  479. X    VHB_BLKS=`expr $VHB_BLKS + 4`        # allow room for VHB itself
  480. X    VHB_TRKS=`expr $VHB_BLKS / $SECT`    # calculate number of tracks
  481. X    if test "`expr $VHB_TRKS \* $SECT`" -lt "${VHB_BLKS}"
  482. X    then
  483. X        VHB_TRKS=`expr $VHB_TRKS + 1`
  484. X    fi
  485. X    echo "loader /usr/lib/iv/${LOADER}" >> /tmp/FD$$
  486. Xfi
  487. Xcat >>/tmp/FD$$ <<E_O_F
  488. X$
  489. X$
  490. X0
  491. X${VHB_TRKS}
  492. X$
  493. X$
  494. XE_O_F
  495. XBLKS=`expr \( $CYL '*' 2 - $VHB_TRKS \) '*' $SECT`
  496. XINODES=`expr $BLKS / 4`
  497. XCYLSIZE=`expr $SECT '*' 2`
  498. Xwhile true
  499. Xdo
  500. X    echo ""
  501. X    echo "Press Return to format new floppy or Q to quit: \c"
  502. X    read ANS
  503. X    case "${ANS}" in
  504. X    q*|Q*) break ;;
  505. X    esac
  506. X    date
  507. X    echo "Formatting floppy with $SECT sectors per track, $CYL tracks"
  508. X    iv -iw /dev/rfp020 /tmp/FD$$
  509. X    if test $? -ne 0; then continue; fi
  510. X    iv -t /dev/rfp020
  511. X    if test "${PASS}" = "0"; then
  512. X        echo "skipping disk surface analysis check"
  513. X    else
  514. X        echo "Doing disk surface analysis check"
  515. X        disktest -s ${SECT} -p ${PASS}
  516. X        if test $? -ne 0; then continue; fi
  517. X    fi
  518. X    case "${BUILDFS}" in
  519. X    y*)    echo "Building file system"
  520. X        mkfs /dev/rfp021 ${BLKS}:${INODES} 2 ${CYLSIZE}
  521. X        ;;
  522. X    esac
  523. X    echo "It is now safe to remove the floppy"
  524. Xdone
  525. Xrm -f /tmp/FD$$
  526. END_OF_FILE
  527. if test 2172 -ne `wc -c <'format.sh'`; then
  528.     echo shar: \"'format.sh'\" unpacked with wrong size!
  529. fi
  530. chmod +x 'format.sh'
  531. # end of 'format.sh'
  532. fi
  533. if test -f 'newfs.sh' -a "${1}" != "-c" ; then 
  534.   echo shar: Will not clobber existing file \"'newfs.sh'\"
  535. else
  536. echo shar: Extracting \"'newfs.sh'\" \(338 characters\)
  537. sed "s/^X//" >'newfs.sh' <<'END_OF_FILE'
  538. X: 'sh or ksh'
  539. Xiv -d /dev/rfp020 > /tmp/newfs.$$
  540. XCYL=`awk '$1 == "cylinders" {print $2; exit}' /tmp/newfs.$$`
  541. XSECT=`awk '$1 == "sectors" {print $2; exit}' /tmp/newfs.$$`
  542. XBLKS=`expr \( $CYL '*' 2 - 1 \) '*' $SECT`
  543. XINODES=`expr $BLKS / 4`
  544. XCYLSIZE=`expr $SECT '*' 2`
  545. Xmkfs /dev/rfp021 ${BLKS}:${INODES} 2 ${CYLSIZE}
  546. Xrm -f /tmp/newfs.$$
  547. Xexit 0
  548. END_OF_FILE
  549. if test 338 -ne `wc -c <'newfs.sh'`; then
  550.     echo shar: \"'newfs.sh'\" unpacked with wrong size!
  551. fi
  552. chmod +x 'newfs.sh'
  553. # end of 'newfs.sh'
  554. fi
  555. echo shar: End of archive 1 \(of 1\).
  556. cp /dev/null ark1isdone
  557. MISSING=""
  558. for I in 1 ; do
  559.     if test ! -f ark${I}isdone ; then
  560.     MISSING="${MISSING} ${I}"
  561.     fi
  562. done
  563. if test "${MISSING}" = "" ; then
  564.     echo You have the archive.
  565.     rm -f ark[1-9]isdone
  566. else
  567.     echo You still need to unpack the following archives:
  568.     echo "        " ${MISSING}
  569. fi
  570. ##  End of shell archive.
  571. exit 0
  572. -- 
  573. David H. Brierley
  574. Home: dave@galaxia.network23.com; Work: dhb@quahog.ssd.ray.com
  575. Send comp.sources.3b1 submissions to comp-sources-3b1@galaxia.network23.com
  576. %% Can I be excused, my brain is full. **
  577.