home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / 3b1 / volume02 / floppy / part01 < prev    next >
Encoding:
Internet Message Format  |  1992-07-20  |  15.8 KB

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