1: /*
   2:  * Copyright (c) 1986 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  *
   6:  *	@(#)maketape.c	1.1 (2.10BSD Berkeley) 12/1/86
   7:  *			    (2.11BSD Contel) 4/20/91
   8:  *		TU81s didn't like open/close/write at 1600bpi, use
   9:  *		ioctl to write tape marks instead.
  10:  */
  11: 
  12: #include <stdio.h>
  13: #include <sys/types.h>
  14: #include <sys/ioctl.h>
  15: #include <sys/mtio.h>
  16: 
  17: #define MAXB 30
  18: 
  19: extern  int errno;
  20: 
  21: char    buf[MAXB * 512];
  22: char    name[50];
  23: struct  mtop mtio;
  24: int blksz, recsz;
  25: int mt;
  26: int fd;
  27: int cnt;
  28: 
  29: main(argc, argv)
  30:     int argc;
  31:     char *argv[];
  32: {
  33:     register int i, j = 0, k = 0;
  34:     FILE *mf;
  35: 
  36:     if (argc != 3) {
  37:         fprintf(stderr, "usage: maketape tapedrive makefile\n");
  38:         exit(1);
  39:     }
  40:     if ((mt = creat(argv[1], 0666)) < 0) {
  41:         perror(argv[1]);
  42:         exit(1);
  43:     }
  44:     if ((mf = fopen(argv[2], "r")) == NULL) {
  45:         perror(argv[2]);
  46:         exit(1);
  47:     }
  48: 
  49:     for (;;) {
  50:         if ((i = fscanf(mf, "%s %d", name, &blksz))== EOF)
  51:             exit(0);
  52:         if (i != 2) {
  53:             fprintf(stderr, "Help! Scanf didn't read 2 things (%d)\n", i);
  54:             exit(1);
  55:         }
  56:         if (blksz <= 0 || blksz > MAXB) {
  57:             fprintf(stderr, "Block size %d is invalid\n", blksz);
  58:             exit(1);
  59:         }
  60:         recsz = blksz * 512;    /* convert to bytes */
  61:         if (strcmp(name, "*") == 0) {
  62:             mtio.mt_op = MTWEOF;
  63:             mtio.mt_count = 1;
  64:             if (ioctl(mt, MTIOCTOP, &mtio) < 0)
  65:                 fprintf(stderr, "MTIOCTOP err: %d\n", errno);
  66:             k++;
  67:             continue;
  68:         }
  69:         fd = open(name, 0);
  70:         if (fd < 0) {
  71:             perror(name);
  72:             exit(1);
  73:         }
  74:         printf("%s: block %d, file %d\n", name, j, k);
  75: 
  76:         /*
  77: 		 * wfj fix to final block output.
  78: 		 * we pad the last record with nulls
  79: 		 * (instead of the bell std. of padding with trash).
  80: 		 * this allows you to access text files on the
  81: 		 * tape without garbage at the end of the file.
  82: 		 * (note that there is no record length associated
  83: 		 *  with tape files)
  84: 		 */
  85: 
  86:         while ((cnt=read(fd, buf, recsz)) == recsz) {
  87:             j++;
  88:             if (write(mt, buf, cnt) < 0) {
  89:                 perror(argv[1]);
  90:                 exit(1);
  91:             }
  92:         }
  93:         if (cnt>0) {
  94:             j++;
  95:             bzero(buf + cnt, recsz - cnt);
  96:             if (write(mt, buf, recsz) < 0) {
  97:                 perror(argv[1]);
  98:                 exit(1);
  99:             }
 100:         }
 101:     close(fd);
 102:     }
 103: }

Defined functions

main defined in line 29; never used

Defined variables

blksz defined in line 24; used 5 times
buf defined in line 21; used 4 times
cnt defined in line 27; used 5 times
fd defined in line 26; used 4 times
mt defined in line 25; used 4 times
mtio defined in line 23; used 3 times
name defined in line 22; used 5 times
recsz defined in line 24; used 5 times

Defined macros

MAXB defined in line 17; used 2 times
Last modified: 1991-04-29
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1421
Valid CSS Valid XHTML 1.0 Strict