1

I got this point from a book,it says

Because the tape device is a disposable I/O device,so we can't use commands like 'cp' to copy.

And the author recommended to use 'tar':

tar -cvf /dev/st0 /home

I know 'cp' will read and write contents to somewhere repeatedly,but I think use 'cp' to copy things to the tape device can also succeed.But I don't have such device and can't validate my assumption. So,your opinions?

1

You use cp to copy a file to another file, not to a device. You can't send a file to the printer with cp file /dev/lp0 either.

You may be able to use cat file > /dev/st0 to write the file to tape, but then you would have no way to know what the name of the file was, nor its permissions or other metadata. tar prefixes the file data with a header containing that information so that it can be reconstructed when reading it back.

BTW I don't know what your book means with "disposable I/O device"; it's a character device (which ironically means that you can only write aligned blocks to it). This also means that the cat command above may fail at the end if the file size is not an exact multiple of the required block size.

So just use tar :-)

  • You can send a file to the printer with cp file /dev/lp0 (assuming it's a parallel printer, at least as far as the OS is concerned). If it's in the right format for that particular printer, you'll even get the desired printout. – Gilles 'SO- stop being evil' Nov 19 '14 at 23:23
  • I still can't understand.I don't have a printer and I tried to do what you said below but what does the output mean?Seemed like if I do have a printer than it will succeed:[root@www ~]# cp nano.save /dev/loop0 cp:overwriting "/dev/loop0"? y cp: writing "/dev/loop0": no space on the device @gilles – cain abel Nov 19 '14 at 23:51
  • @cainabel /dev/loop0 is a block device, they behave rather differently from a character device like /dev/lp0. When you write to /dev/lp0, that sends the bytes to the printer. If you get the format right, on a parallel printer or a USB printer which uses parallel-over-USB, that will print a job. – Gilles 'SO- stop being evil' Nov 19 '14 at 23:55
  • Than how about this?Does the output below belong to the incorrect format?[root@www ~]# cp nano.save /dev/lp0 cp:overwriting "/dev/lp0"? yI don't have a real printer@gilles – cain abel Nov 19 '14 at 23:59
  • What you two guys said confuse me.Can I use 'cp' on character device exactly? If can't,then why?the command cp file /dev/lp0 seems reasonable.@gilles – cain abel Nov 20 '14 at 1:31
0

A tape contains files but not a filesystem*. Using the word 'file' for both is a bit misleading. A file on a tape is nothing more than a stream of bytes closed with an EOF mark. That is all. As wurtel wrote, a "file" on a tape has no name, no attributes. In other words, there is no catalogue of these files. Catalogue = filesystem.

cp deals with files in file systems. It copies the file named on the command line from one filesystem to a different directory on the same or another filesystem. Think about it: the fact that there is no filesystem on a tape means that there are no file names and there are no directories. cp has nothing to do with tapes.

It is not by accident that the book author recommends tar to store several files on a tape. TAR means Tape ARchive. The TAR format and utility was created to be able to package the content, name and attributes of several files along with their placement in a directory tree and write the whole thing onto a tape. Not always, but frequently this is how you want to store files on a tape.

*Footnote: there IS a tape file system, which is called LTFS. This is a relatively new thing. The tape is divided into two partitions, the first contains the catalogue, the second contains the file contents. LTFS behaves like any usual file system, you can copy with cp, or even drag-drop files. But if you simply mentions "tape", I assume you are talking about the usual, basic tape configuration, without LTFS.

  • LTFS appeared with LTO5, maybe this is not the case in this question. – Sandburg Apr 14 at 14:57
0

You can use cp to a tape. But a device like /dev/st0 is configured for rewind-on-close. So a second cp will overwrite the first. Were you to use /dev/nst0 (?), which is the no-rewind-on-close device, you would get an EOF mark on the tape at the end of each file. When you eject the tape a second EOF would be written indicating End Of Tape. It's possible to seek quickly to an EOT mark so rapid retrieval of the Nth file is quite possible. What is not possible is to update a file at the beginning of the tape - the close writes an EOF and the rewind writes a second, indicating End Of Tape.

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.