Appendix E.2 Creating an input file on variable-length blocked tape

Organization of this subsection
(1) Principal media
(2) File name examples
(3) Creating a file name
(4) Overview
(5) Creation example

(1) Principal media

DAT,CGMT,OMT

(2) File name examples

/dev/dat/vdat010 (internal DAT),

/dev/cgmt/vcgmt160 (cartridge magnetic tape),

/dev/omt/vomt055 (open reel magnetic tape)

(3) Creating a file name

To install a variable-length blocked device, the file name must first be created.

The super user then executes the following command:

/etc/mknod /dev/dat/vdat010 c 119 0x010001
/bin/chmod 0666 /dev/dat/vdat010
Explanation:
Normally, when this command is executed, a variable-length blocked access device for the internal DAT is created.
/dev/dat/vdat010: Device name
c: Character special file
119: Major number (indicates DAT variable-block usage)
0x010001: Minor number (indicates internal DAT will be used in compressed mode)
See man below for unknown words or concepts.
mknod or chmod: man lm mknod or man chmod
Instruction name rule for major numbers, minor numbers, and device names: man 6 mt

(4) Overview

Blocks of any lengths can be written on variable-length blocked tape.

Because blocks of any lengths can be written, this type of tape can directly handle data in binary format, in addition to data in DAT format. The tape must be read in blocks the same length as they were written (for example, if a block written in 64 KB is read in 32 KB, the remaining 32 KB are discarded). Because there is no means of communicating to a reader that the record length changes, all blocks except the last block are normally written at the same length, and only the last block is written as a fractional block length.

Because the database load utility (pdload) makes that last block 32 KB, tapes with block lengths longer than 32 KB cannot be read correctly.

[Figure]

When a file is created, the block length should be 32 KB or less.

In the following example, the block length is set at 32 KB when the file is created.

(5) Creation example

The file is created in the same way in DAT format and binary format.

(a) Regular file to variable-length blocked tape

Because the cp command cannot set the buffer length, it cannot be used; the dd command must be used instead.

/usr/bin/vi output to /dev/dat/vdat010 variable-length blocked tape
dd if=/usr/bin/vi of=/dev/dat/vdat010 bs=32k
[Figure] 7+1 input records
[Figure]7+1 output records

[Figure]System output

Explanation:
7+1 indicates that seven 32-KB blocks and one block with fewer than 32 KB were processed.
(b) Creating programs

When the following types of programs are created, data of any length (specified by data_len) is output to variable-length blocked tape in 32-KB blocks. This is done by allocating the 32-KB write_buf to the system buffer and specifying full buffering (_IOFBF).

#define PROC_BUFSIZ 1024 * 32
FILE* fp;
int data_len; /* data length (needed in binary format) */
char write_buf[PROC_BUFSIZ]; /* buf system call */
char data_buf[PROC_BUFSIZ]; /* buf user */
:
fp = fopen("/dev/dat/vdat010","w")
setvbuf(fp, write_buf, _IOFBF, PROC_BUFSIZ)
:
while(while there is data) {
data write processing
}
:
fclose(fp);
Explanation:
Data write processing
  • DAT format
    Load data into data_buf. Data + \n + \0
    fputs (data_buf, fp);
  • Binary format
    Load data into data_buf. The data length is data_len.
    fwrite (data_buf, data_len, 1, fp);
(c) Data loaded mistakenly with the cp command

If the original data was in a regular file, it must be reloaded using the method in (a).

When there are two DAT devices, the buffer length can be converted with the following method:

dd if=/dev/vdat010 ibs=64k of=/dev/vdat011 obs=32k
Explanation:
/dev/vdat010: Data loaded mistakenly with the cp command
/dev/vdat011: Tape to be newly loaded for pdload