[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 434
  • Last Modified:

Get SCSI tape status

Can anybody tell me how and what ioctl command is to be used to get the SCSI tape status (available space and used space)?




0
jowelle
Asked:
jowelle
  • 3
  • 2
1 Solution
 
kruemelmoCommented:
See the man page st(4):

SYNOPSIS
       #include <sys/mtio.h>

       int ioctl(int fd, int request [, (void *)arg3]);
       int ioctl(int fd, MTIOCTOP, (struct mtop *)mt_cmd);
       int ioctl(int fd, MTIOCGET, (struct mtget *)mt_status);
       int ioctl(int fd, MTIOCPOS, (struct mtpos *)mt_pos);

In order to find the available space and used space, you need to know the total space. As far as I know there is not command to get the tape capacity; you can get the tape drive type, but you have to know the capacity on your own because teh SCSI tape interface is generic and works for many different tape drives.

Find the space used by issuing the MTEOM ioctl - the tape will move to the end of data on the tape - and then use MTIOCPOS to get the current block number. Use MTIOCGET to get the block size. You can then find the "current byte".

I haven't tried it, but I would think it should work.

Moritz




0
 
kruemelmoCommented:
..adding some pseudo code:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mtio.h>

...

   int fd;
   struct mtget mt_status;
   struct mtpos mt_pos;
   struct mtop mt_cmd;

   fd = open("/dev/tape", O_RDWR);
   if (fd < 0)
      perror("opening tape device");
   mt_cmd.mt_op = MTEOM;
   mt_cmd.mt_count = 1;
   if (ioctl(fd, MTIOCTOP, &mt_cmd))
      perror("EOM");
   if (ioctl(fd, MTIOCGET, &mt_status))
      perror("MTIOCGET");
   if (ioctl(fd, MTIOCPOS, &mt_pos))
      perror("MTIOCPOS");
   // used bytes is now
   // (mt_status.mt_dsreg & MT_ST_BLKSIZE_MASK) * mt_pos.mt_blkno;
   // this might not fit into a long!
0
 
jowelleAuthor Commented:
Thanks for the information.
I thought there is an MTIOCGETSIZE ioctl...
0
 
jowelleAuthor Commented:
Is it possible to go to the
last block of the tape or the
end of the reel?
0
 
kruemelmoCommented:
Hi howelle,

the MTEOM operation shown above goes to the last block on tape (end of media). I have no idea how to get to the end of the reel. After all, the remaining part of the tape may not ever have been written to so it might be unformatted...

You could, of course, go to end of media, remember the file number, and then write to the tape until error message - then you know what you want to know...

Greetings and thanks for accepting the answer,
Moritz
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now