st(4) Device Drivers Manual st(4) st - SCSI #include 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); The st driver provides the interface to a variety of SCSI tape devices. Currently, the driver takes control of all detected devices of type "sequential-access". The st driver uses major device number 9. Each device uses eight minor device numbers. The lowermost five bits in the minor numbers are assigned sequentially in the order of detection. In the 2.6 kernel, the bits above the eight lowermost bits are concatenated to the five lowermost bits to form the tape number. The minor numbers can be grouped into two sets of four numbers: the principal (auto-rewind) minor device numbers, n, and the "no-rewind" device numbers, (n + 128). Devices opened using the principal device number will be sent a REWIND command when they are closed. Devices opened using the "no-rewind" device number will not. (Note that using an auto-rewind device for positioning the tape with, for instance, mt does not lead to the desired result: the tape is rewound after the mt command and the next command starts from the beginning of the tape). ( : , , ). , . , ( ). . 32 . , 64- . : mknod -m 666 /dev/st0 c 9 0 mknod -m 666 /dev/st0l c 9 32 mknod -m 666 /dev/st0m c 9 64 mknod -m 666 /dev/st0a c 9 96 mknod -m 666 /dev/nst0 c 9 128 mknod -m 666 /dev/nst0l c 9 160 mknod -m 666 /dev/nst0m c 9 192 mknod -m 666 /dev/nst0a c 9 224 . The driver uses an internal buffer that has to be large enough to hold at least one tape block. Before Linux 2.1.121, the buffer is allocated as one contiguous block. This limits the block size to the largest contiguous block of memory the kernel allocator can provide. The limit is currently 128 kB for 32-bit architectures and 256 kB for 64-bit architectures. In newer kernels the driver allocates the buffer in several parts if necessary. By default, the maximum number of parts is 16. This means that the maximum block size is very large (2 MB if allocation of 16 blocks of 128 kB succeeds). The driver's internal buffer size is determined by a compile-time constant which can be overridden with a kernel startup option. In addition to this, the driver tries to allocate a larger temporary buffer at run time if necessary. However, run-time allocation of large contiguous blocks of memory may fail and it is advisable not to rely too much on dynamic buffer allocation before Linux 2.1.121 (this applies also to demand-loading the driver with kerneld or kmod). . . , , . ioctl(2) , . ( ). . , . , , , ( ). , . , . . ioctl(2). . , ioctl(2). . ( ). ioctl(2), . , /dev/tape . Starting from Linux 2.6.2, the driver exports in the sysfs directory /sys/class/scsi_tape the attached devices and some parameters assigned to the devices. : ( ). , , . , . , : , . . , , , . , , . In fixed-block mode the read byte counts can be arbitrary if buffering is enabled, or a multiple of the tape block size if buffering is disabled. Before Linux 2.1.121 allow writes with arbitrary byte count if buffering is enabled. In all other cases (before Linux 2.1.121 with buffering disabled or newer kernel) the write byte count must be a multiple of the tape block size. In Linux 2.6, the driver tries to use direct transfers between the user buffer and the device. If this is not possible, the driver's internal buffer is used. The reasons for not using direct transfers include improper alignment of the user buffer (default is 512 bytes but this can be changed by the HBA driver), one or more pages of the user buffer not reachable by the SCSI adapter, and so on. , . , . , . . . . , , . ioctl ioctl(2). , st, SCSI. , , /usr/include/linux/mtio.h: MTIOCTOP -- perform a tape operation (struct mtop *). . EIO, . /* MTIOCTOP - . */ struct mtop { short mt_op; /* */ int mt_count; /* */ }; : MTBSF mt_count . MTBSFM mt_count . EOT . MTBSR mt_count ( ). MTBSS mt_count (setmarks) . MTCOMPRESSION , mt_count 0, , mt_count 0. MODE page 15, DAT-. MTEOM ( ). MTERASE Erase tape. With Linux 2.6, short erase (mark tape empty) is performed if the argument is zero. Otherwise, long erase (erase all) is done. MTFSF mt_count . MTFSFM mt_count . BOT . MTFSR mt_count ( ). MTFSS mt_count . MTLOAD SCSI- . HP . mt_count MT_ST_HPLOADER_OFFSET , . MTLOCK . MTMKPART Format the tape into one or two partitions. If mt_count is positive, it gives the size of partition 1 and partition 0 contains the rest of the tape. If mt_count is zero, the tape is formatted into one partition. From Linux 4.6, a negative mt_count specifies the size of partition 0 and the rest of the tape contains partition 1. The physical ordering of partitions depends on the drive. This command is not allowed for a drive unless the partition support is enabled for the drive (see MT_ST_CAN_PARTITIONS below). MTNOP No op--flushes the driver's buffer as a side effect. Should be used before reading status with MTIOCGET. MTOFFL . MTRESET . MTRETEN . MTREW . MTSEEK mt_count. SCSI-2, LOCATE (, ), Tandberg- SCSI-1 (Tandberg, Archive Viper, Wangtek, ... ). , MTIOCPOS, , . MTSETBLK mt_count. . MTSETDENSITY mt_count. , , . MTSETPART mt_count. . (. MT_ST_CAN_PARTITIONS ). MTUNLOAD SCSI- ( ). MTUNLOCK . MTWEOF mt_count . MTWSM mt_count . ( ): MTSETDRVBUFFER Set various drive and driver options according to bits encoded in mt_count. These consist of the drive's buffering mode, a set of Boolean driver options, the buffer write threshold, defaults for the block size and density, and timeouts (only since Linux 2.1). A single operation can affect only one item in the list below (the Booleans counted as one item.) 4- . : 0 , (GOOD) , . 1 , , . 2 , , : () () . mt_count MT_ST_WRITE_THRESHOLD (OR) 28- . 1024 , . . (. ). mt_count : MT_ST_BOOLEANS, MT_ST_SETBOOLEANS, MT_ST_CLEARBOOLEANS, MT_ST_DEFBOOLEANS . MT_ST_BOOLEANS . MT_ST_SETBOOLEANS , MT_ST_DEFBOOLEANS -- . MT_ST_DEFBOOLEANS. (, 32 160) . , , , . : MT_ST_BUFFER_WRITES ( true) . false , . false. MT_ST_ASYNC_WRITES ( true) true, , , . , SCSI-. , , . false. MT_ST_READ_AHEAD ( true) . false , . MT_ST_TWO_FM ( false) . . true, . : true QIC, . , . , . MT_ST_DEBUGGING ( false) ( , DEBUG). MT_ST_FAST_EOM ( false) MTEOM , , , MTIOCGET. MT_ST_FAST_EOM false, MTEOM, . MT_ST_AUTO_LOCK ( false) When this option is true, the drive door is locked when the device file is opened and unlocked when it is closed. MT_ST_DEF_WRITES ( false) ( , , ..) , , , , . , SCSI, , . false, SCSI . true, SCSI . , SCSI . MT_ST_CAN_BSR ( false) When read-ahead is used, the tape must sometimes be spaced backward to the correct position when the device is closed and the SCSI command to space backward over records is used for this purpose. Some older drives can't process this command reliably and this option can be used to instruct the driver not to use the command. The end result is that, with read-ahead and fixed-block mode, the tape may not be correctly positioned within a file when the device is closed. With Linux 2.6, the default is true for drives supporting SCSI-3. MT_ST_NO_BLKLIMS ( false) SCSI- READ BLOCK LIMITS. , . , . MT_ST_CAN_PARTITIONS ( false) . , . MT_ST_SCSI2LOGICAL ( false) , SCSI-2 ( MTSEEK MTIOCPOS , ). , , . . MT_ST_SYSV ( false) , System V. BSD. ( , , ) : SYSV , . BSD . MT_NO_WAIT ( false) (.., ) (, rewind). : struct mtop mt_cmd; mt_cmd.mt_op = MTSETDRVBUFFER; mt_cmd.mt_count = MT_ST_BOOLEANS | MT_ST_BUFFER_WRITES | MT_ST_ASYNC_WRITES; ioctl(fd, MTIOCTOP, mt_cmd); MT_ST_DEF_BLKSIZE, MT_ST_DEFDENSITY. . With Linux 2.1.x and later, the timeout values can be set with the subcommand MT_ST_SET_TIMEOUT ORed with the timeout in seconds. The long timeout (used for rewinds and other commands that may take a long time) can be set with MT_ST_SET_LONG_TIMEOUT. The kernel defaults are very long to make sure that a successful command is not timed out with any drive. Because of this, the driver may seem stuck even if it is only waiting for the timeout. These commands can be used to set more practical values for a specific drive. The timeouts set for one device apply for all devices linked to the same drive. Starting from Linux 2.4.19 and Linux 2.5.43, the driver supports a status bit which indicates whether the drive requests cleaning. The method used by the drive to return cleaning information is set using the MT_ST_SEL_CLN subcommand. If the value is zero, the cleaning bit is always zero. If the value is one, the TapeAlert data defined in the SCSI-3 standard is used (not yet implemented). Values 2-17 are reserved. If the lowest eight bits are >= 18, bits from the extended sense data are used. The bits 9-16 specify a mask to select the bits to look at and the bits 17-23 specify the bit pattern to look for. If the bit pattern is zero, one or more bits under the mask indicate the cleaning request. If the pattern is nonzero, the pattern must match the masked sense data byte. MTIOCGET -- get status (struct mtget *). /* MTIOCGET - */ struct mtget { long mt_type; long mt_resid; /* */ long mt_dsreg; long mt_gstat; long mt_erreg; /* */ daddr_t mt_fileno; daddr_t mt_blkno; }; mt_type mt_type, MT_ISSCSI1 ( SCSI-1) MT_ISSCSI2 ( SCSI-2). mt_resid . mt_dsreg ( 24- ) ( 8- ). MT_ST_BLKSIZE_SHIFT, MT_ST_BLKSIZE_MASK, MT_ST_DENSITY_SHIFT MT_ST_DENSITY_MASK. mt_gstat ( ) . : GMT_EOF(x) ( false MTSEEK). GMT_BOT(x) ( false MTSEEK). GMT_EOT(x) . GMT_SM(x) ( false MTSEEK). GMT_EOD(x) . GMT_WR_PROT(x) . , ( ). GMT_ONLINE(x) open(2) , . GMT_D_6250(x) GMT_D_1600(x) GMT_D_800(x) This "generic" status information reports the current density setting for 9-track 1/2" tape drives only. GMT_DR_OPEN(x) . GMT_IM_REP_EN(x) . , , . , . GMT_CLN(x) The drive has requested cleaning. Implemented since Linux 2.4.19 and Linux 2.5.43. mt_erreg ( 16 ) , MT_ST_SOFTERR_SHIFT MT_ST_SOFTERR_MASK. - , ( , SCSI- MODE SELECT). mt_fileno ( 0). , -1 (, MTBSS MTSEEK). mt_blkno ( 0) . , -1 (, MTBSF, MTBSS MTSEEK). MTIOCPOS -- get tape position (struct mtpos *). , mt_blkno, MTIOCGET. SCSI-2, READ POSITION (, ), Tandberg- SCSI-1 (Tandberg, Archive Viper, Wangtek, ). /* MTIOCPOS - */ struct mtpos { long mt_blkno; /* */ }; EACCES , . ( open(2).) EBUSY , . EFAULT , . EINVAL ioctl(2) , . EIO . ENOMEM The byte count in read(2) is smaller than the next physical block on the tape. (Before Linux 2.2.18 and Linux 2.4.0 the extra bytes have been silently ignored.) ENOSPC , . ENOSYS ioctl(2). ENXIO , . EOVERFLOW , , . EROFS O_WRONLY O_RDWR, . /dev/st* SCSI /dev/nst* SCSI o . , , . , . , DAT, DLT .. , Linux (.., MTSETBLK MTSETDEFBLK ), . , SCSI. o (, tar(1)) . , , . o SCSI, SCSI, SCSI- SCSI . SCSI- , , , , . o /. SENSE, , , SCSI. o read(2) write(2). 2.6. (, ). , . . mt(1) drivers/scsi/README.st Documentation/scsi/st.txt ( >= 2.6) Linux Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . st(4)