home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / aix / 12645 < prev    next >
Encoding:
Internet Message Format  |  1992-12-17  |  2.4 KB

  1. Path: sparky!uunet!stanford.edu!unixhub!fnnews.fnal.gov!dcdmwm.fnal.gov!mengel
  2. From: mengel@dcdmwm.fnal.gov (Marc Mengel)
  3. Newsgroups: comp.unix.aix
  4. Subject: Re: Checking for write protect on 8mm tapes.
  5. Date: 17 Dec 1992 15:50:42 GMT
  6. Organization: Fermi National Accelerator Laboratory, Batavia IL
  7. Lines: 62
  8. Distribution: world
  9. Message-ID: <1gq7kiINNdc7@fnnews.fnal.gov>
  10. References: <707@dwp.la.ca.us>
  11. NNTP-Posting-Host: dcdmwm.fnal.gov
  12.  
  13. In article <707@dwp.la.ca.us>, carlson@dwp.la.ca.us (CarlsonPeters 7898) writes:
  14. |> 
  15. |> Is there anyway to check to see if the write protect tab is set on an
  16. |> 8mm tape via software without actually trying to write to the tape?  I
  17. |> am writing a front-end for tar/tctl and it would be really nice to
  18. |> disable the backup menu if the write-protect tab is on.  Checking by
  19. |> writing to tape is not an option.
  20.  
  21. The only good way is to use the scsi pass-through ioctl() calls, and you
  22. have to be root and open the device in diagnostics mode(!!).
  23. The code looks like this:
  24.  
  25. do_status(char *pcTape)
  26. {
  27.         int i;
  28.         int nTapeDiag;
  29.         static char buf[SIZE];
  30.         static struct sc_iocmd  scInquiry = {
  31.                 0x38, buf, 5, 0, 0, 0, 0, 0, 0, 0, B_READ, 0, 0, 0,
  32.                 6, { 0x12, 0, 0, 0, 0x38, 0  }
  33.         };
  34.         static struct sc_iocmd  scMode = {
  35.                 80, buf, 5, 0, 0, 0, 0, 0, 0, 0, B_READ, 0, 0, 0,
  36.                 6, { 0x1a, 0, 0, 0, 80, }
  37.         };
  38.  
  39.  
  40.         if (debug)
  41.                 fprintf(stderr,"do_status\n");
  42.  
  43.         if (0 > (nTapeDiag = openx(pcTape,O_RDONLY,0,SC_DIAGNOSTIC))) {
  44.                 perror("openx\n");
  45.                 return 1;
  46.         }
  47.         printf("Drive %s", pcTape);
  48.         if (0 > ioctl(nTapeDiag,STIOCMD,&scMode) &&
  49.                  0 > ioctl(nTapeDiag,STIOCMD,&scMode)) {
  50.                 perror("ioctl IOCMD {1a, 0, 0, 0, 0xff, 0}");
  51.                 return 1;
  52.         }
  53.         if (buf[1] == 0) {
  54.                 printf(" is off line");
  55.         } else {
  56.                 printf(" is on line");
  57.  
  58.                 if (buf[2]&0x80)
  59.                         printf(", write-protected");
  60.                 else
  61.                         printf(", read/write");
  62.                 printf("\n");
  63.         }
  64.         close(nTapeDiag);
  65.         printf("\n");
  66.         return 0;
  67. }
  68.  
  69. There's lots of other good status bits in there you can check; look in
  70. the EXABYTE manual for details on the hex 1A Mode Sense command.
  71.  
  72. -------
  73. Marc Mengel
  74. mengel@fnal.fnal.gov
  75.