cpl@ednor.bbc.com (Chuck Lambros) (04/10/90)
I have already posted this request in comp.unix.wizards. Although I received a few responses, none were a workable solution to my dilema. So at the risk of being redundant, I will attempt to repost the request here... I am working on a C program to manipulate (read and write) tapes which requires knowledge of the following: o when a tape is at BOT, o when a tape is a EOT. It is essential to have this information because special header records are written at the beginning-of-tape, and special trailer records are written before the end-of-tape. The tapes that I am reading do not necessary follow normal conventions where two consecutive filemarks indicate end-of-tape. It is possible that these marks will be written beyond the photoreflective EOT marker tape. Since most Unix systems do not allow you to safely read beyond the photoreflective EOT marker, I must have a method of detecting this marker. The present version of my program has been developed using Berkley 4.2 Unix. I am using the 'ioctl' function to obtain tape status information. On most Unix systems, passing ioctl the MTIOCGET option will fill the tape device status in the mt_dsreg field of the mtget structure supplied. The information returned in this field is GROSSLY hardware specific. This requires a vast amount of tape device specific information to be stored. It will also limit the program to those device of which I am knowledgeable. Systems such as the HP9000/835 have generic macros define in include/sys/mtio.h which intrepret the results of the ioctl call. This has made the port to this system very painless. However, it is the only system I have found with such a handy feature. Also, the ioctl function does always support the MTIOCGET option on all System V versions of Unix. This approach is therefore not the preferred method of creating a portable software package. When writing to the tape, I realize that I can check the return code passed back from the 'write' function call. The knowledge that when 'write' returns -1, and sets errno to ENOSPC, is sufficient to signify that we are at end of tape (EOT). Once found, I need to back up a couple of records and write a proper tape terminator (as predefined by the software). When a write returns -1 and sets errno to ENOSPC, I have not been able to back up. If I call ioctl using the MTIOCGET option, it backs up fine. This however leaves me in a "catch-22" situation, since I wish to eliminate the ioctl call. With regards to determining BOT without using the non-portable ioctl call, I haven't got a clue. In summation, I really could use ANY hints of methods for determining a tape's status without knowledge of tape device specifics (i.e. a portable method of determining a tapes status). I am searching for methods for both Berkely 4.2, as well as System V. Although preferred, the methods do not have to be the same for the two versions of Unix. Please email any info, and thanks in advance. -- Chuck Lambros Boston Business Computing, Ltd. cpl@ednor.bbc.com