4

I have a SCSI tape (/dev/st0) and I would like to get information about how much of it is used.

How can I do that, preferably with a command?

  • manufacturer might have implemented some 'magic' like echo foo > /sys/device/... you might ask him or visit web site. – Archemar Jul 29 '16 at 13:48
2

if it's a LTO or other tape with auxiliary memory:

sg_logs -a /dev/sgX

where sgX is the SCSI-generic device corresponding to your tape drive (sg_map or sg_scan may help you find it, if you don't already know it from e.g., tape alert checking)

  • Yep, LTO should report a "Tape capacity log page" . – derobert Jan 13 '17 at 22:36
1

The way modern tape drives work, you can't know how much of the tape is used without reading it.

Tapes are simple character devices with rewind capability, so when writing, the tape puts an EOM marker when the write is completed, then rewinds. When when reading, it will rewind the tape, then it simply reads the entire tape until it hits the EOM.

So you can do a

dd if=/dev/st0 of=/dev/null

and when dd completes (with an error since it will try read past EOM) it will tell you the amount of data it read.

If you know the tape has megabytes of data, and are willing to be off a megabyte, adding bs=1M will make this go faster- - it will try to read 1M at a time instead a byte at a time.

  • 1
    This is the way to do it, but (a) if there are multiple tape files on the tape, you need to do the dd repeatedly (using the no-rewind version of the device) until you get a double EOF and (b) it's best to tell dd to use a large block size, 64K or more. Using a read size smaller than the block size on the tape will return an error. Reading with a size larger than the actual block size is OK; it won't give incorrect results or errors (unless it's so large that the driver rejects it.) – Mark Plotnick Jul 29 '16 at 15:55
  • Can't you just do mt -f /dev/nst0 eod ; mt -f /dev/nst0 status to see where the "end of data" mark is? – Stephen Harris Jul 29 '16 at 18:38
  • @StephenHarris That'll tell you how many files are on the tape, but not how much of the tape is used (unless the files are all the same size (which actually isn't unreasonable; we used ~2GiB files)). – Mark Plotnick Jul 29 '16 at 23:51
  • I thought it also reported blocks; "file number" and "block number". But it's been a long long time since I used tape so I don't recall if that's blocks into the current file or absolute blocks! – Stephen Harris Jul 29 '16 at 23:54
  • 1
    It's the number of blocks into the current file. – Mark Plotnick Jul 30 '16 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.