home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / SoundAndMusic / cmix / tape.backup / nwritelabel.c < prev    next >
C/C++ Source or Header  |  1991-11-25  |  1KB  |  58 lines

  1. /* sfbackup will not allow anyone else to access tape, sfrestore and tapescan
  2.    will  (except root for sfbackup)*/
  3. #include "../H/sfheader.h"
  4. #include <stdio.h>
  5. #include <sys/file.h>
  6. #include <sys/types.h>
  7. #include <sys/mtio.h>
  8. #include <sys/ioctl.h>
  9. #include <sys/stat.h>
  10. #include <signal.h>
  11. #include <errno.h>
  12. #include <sys/time.h>
  13. #include "nlabel.h"
  14.  
  15. char tapename[16] = NEW_TAPE_DEVICE;
  16.  
  17. main(argc,argv)
  18. int argc;
  19. char *argv[];
  20. {
  21.     struct label label;
  22.     char date[26];
  23.     int now,file,i;
  24.     struct mtget mtget ;
  25.     struct mtop mtop ;
  26.  
  27.     if(argc < 2) {
  28.         printf("usage: writelabel tape#\n");
  29.         exit(1);
  30.     }
  31.     label.date = time(0);
  32.     printf("Enter comment, terminated by CR\n");
  33.     gets(label.comment); /* LF/CR terminates comment */
  34.     label.tapenumber = atoi(argv[1]);
  35.     label.owner_uid = getuid();
  36.     file = open(tapename,2); 
  37.     write(file,&label,1024);
  38.     mtop.mt_op = MTWEOF;
  39.     mtop.mt_count = 1;
  40.     if((ioctl(file,MTIOCTOP,&mtop)) == -1) {
  41.         printf("error writing eof on tape\n");
  42.         exit(-2);
  43.     }
  44.     mtop.mt_op = MTREW;
  45.     mtop.mt_count = 1;
  46.     if((ioctl(file,MTIOCTOP,&mtop)) == -1) {
  47.         printf("error rewinding tape\n");
  48.         exit(-2);
  49.     }
  50.     if(read(file,&label,SIZEOFLABEL) != SIZEOFLABEL) {
  51.         printf("trouble reading back label from tape\n");
  52.         exit(-2);
  53.     }
  54.     strcpy(date,ctime(&label.date));
  55.     printf("\nContents of label, as read from tape:\n");
  56.     printf("uid = %d\ntapenumber = %d\ndate = %scomment = %s\n",label.owner_uid,label.tapenumber,date,label.comment);
  57. }
  58.