STIOCQRYPOS

This command queries the tape position. Tape position is defined as the location where the next read or write operation occurs. The query function can be used independently of, or with, the STIOCSETPOS IOCTL command.

A write filemark of count 0 is always issued to the drive, which flushes all data from the buffers to the tape media. After the write filemark finishes, the query is issued.

After a query operation, the curpos field is set to an unsigned integer that represents the current position.

The eot field is set to TRUE if the tape is positioned between the early warning and the physical end of the tape. Otherwise, it is set to FALSE.

The lbot field is valid only if the last command was a write command. If a query is issued and the last command was not a write, lbot contains the value LBOT_UNKNOWN.

Note: lbot indicates the last block of data that is transferred to the tape.

The number of blocks and number of bytes currently in the tape device buffers is returned in the num_blocks and num_bytes fields.

The bot field is set to TRUE if the tape position is at the beginning of the tape. Otherwise, it is set to FALSE.

The returned partition_number field is the current partition of the loaded tape.

The block ID of the next block of data to be transferred to or from the physical tape is returned in the tapepos field.

The position data structure is
typedef unsigned int blockid_t;
struct stpos_s {
   char      block_type;                /* Format of block ID information  */
      #define QP_LOGICAL 0              /* SCSI logical block ID format    */
      #define QP_PHYSICAL 1             /* Vendor-specific block ID format */
   boolean   eot;                       /* Position is after early warning,*/
                                        /* before physical end of tape.    */
   blockid_t curpos;                    /* For query pos, current position.*/
                                        /* For set pos, position to go to. */
   blockid_t lbot;                      /* Last block written to tape.     */
      #define LBOT_NONE 0xFFFFFFFF      /* No blocks written to tape.*/
      #define LBOT_UNKNOWN 0xFFFFFFFE   /* Unable to determine info. */
   uint      num_blocks;                /* Number of blocks in buffer.     */
   uint      num_bytes;                 /* Number of bytes in buffer.      */
   boolean   bot;                       /* Position is at beginning of tape*/
   unchar     partition_number;         /* Current partition number on tape*/
   unchar     reserved1[2];
   blockid_t tapepos;                   /* Next block to be transferred.   */
   unchar      reserved2[48];
};
An example of the STIOCQRYPOS command is
#include <sys/IBM_tape.h>
struct stpos_s stpos;
stpos.block_type=QP_PHYSICAL;
if (ioctl(tapefd,STIOCQRYPOS,&stpos)) {
   printf("ioctl failure.  errno=%d",errno);
   exit(errno);
}
oldposition=stpos.curpos;