home *** CD-ROM | disk | FTP | other *** search
- /*
- ** this creation just reads raw tape file specified as
- ** 1st argument. it then reports on record size etc. on
- ** double tapemark it stops.
- */
-
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <signal.h>
- #include <stdio.h>
- #include <fcntl.h>
-
- #define NBUF 44 /* Maximum size tape block likely to be encountered */
- #define NERR 10 /* NERR consecutive ==> giveup */
-
- char buf[NBUF*BUFSIZ];
- int flag;
- int err;
-
- catch(s)
- int s;
- {
- signal(s, SIG_IGN);
- flag = 1;
- }
-
- main(argc, argv)
- int argc;
- char ** argv;
- {
- register iold;
- register i;
- register nrec;
- register infd;
- struct stat sbuf;
-
- signal(SIGHUP, catch);
- if ( signal(SIGINT, SIG_IGN) == SIG_DFL )
- signal(SIGINT, catch);
- if ( signal(SIGQUIT, SIG_IGN) == SIG_DFL )
- signal(SIGQUIT, catch);
-
- if(argc != 2)
- {
- fprintf(stderr, "Usage: %s file\n", argv[0]);
- return 2;
- }
-
- if((infd = open(argv[1], O_RDONLY)) == -1)
- {
- perror(argv[1]);
- return 2;
- }
-
- fstat(infd, &sbuf);
- if((sbuf.st_mode&S_IFMT) != S_IFCHR)
- {
- fprintf(stderr, "%s not a raw device !!\n", argv[1]);
- return 2;
- }
-
- nrec = 0;
- iold = read(infd, buf, sizeof buf);
- for(;;)
- {
- nrec++;
- i = read(infd, buf, sizeof buf);
- if(i == iold && i == 0)
- goto fini; /* considered end-of-tape */
- if ( (i==iold) && (i==-1) && (nrec==NERR) )
- {
- printf("%d consecutive errors: EOT assumed\n",NERR);
- return 1;
- }
- if((i == iold) && !flag)
- continue;
- if(iold)
- {
- if(iold != -1)
- {
- printf("%6d. * %6o(%6d.)\n",
- nrec, iold, iold);
- }
- else
- {
- printf("%6d. * ERR \n", nrec);
- err++;
- if(nrec > 1)
- return err;
- }
- }
- else
- {
- printf("\tTM\n");
- }
- nrec = 0;
- iold = i;
- if(flag)
- {
- printf("Interrupted\n");
- return 1;
- }
- }
- fini:
- printf("\tEOT\n");
- return err;
- }
-