A computer program product for writing to a tape recording device, wherein the tape recording device receives a plurality of read commands and a plurality of write commands from an upper-layer device and comprises a buffer for temporarily storing data related to each read command and each write command, a tape for recording the data stored in the buffer, a reading and writing head for reading data from the tape into the buffer and for writing the data from the buffer onto the tape, and a controller for reading data from a designated position of the tape and storing the data in the buffer in response to each read command and for writing the data stored in the buffer onto the tape from a written data end position (EOD) in response to each write command, the computer program product comprising a non-transitory computer-readable storage medium including computer-readable program code portions stored therein, the computer-readable program code portions comprising:
- computer code for receiving a plurality of write commands and a subsequent read/write command;
- computer code for determining a current position of the head and a first position of the head for starting the subsequent read/write command;
- computer code for determining a second position for starting a first write command, a third position for finishing the first write command, and a first write direction for the first write command;
- computer code for determining a fourth position for starting a second write command, a fifth position for finishing the second write command, and a second write direction for the second write command;
- computer code for performing both the first write command and the second write command prior to the subsequent read/write command if the second position, the third position, fourth position, and fifth position are each located between the current position and the first position;
- computer code for performing both the first write command and the second write command prior to the subsequent read/write command if the second position, the third position, and fourth position, are each located between the current position and the first position and if the first write direction and the second write direction are in a same direction;
- computer code for performing the first write command prior to the subsequent read/write command if both the second position and the third position are located between the current position and the first position;
- computer code for performing both the first write command and the second write command after the subsequent read/write command if the second position or the third position is not located between the current position and the first starting position;
- and
- computer code for performing the second write command after the subsequent read/write command if the first write direction and the second write direction are different directions.