//#include #include #include #include #include int fh; struct mtget stblk; struct mtop opblk; #define BLKLEN 512 char buf [BLKLEN] = "0123456789"; void disp_stat () { int stat; char buf [256]; ioctl (fh, MTIOCGET, (char*)&stblk); stat = stblk.mt_gstat; /* Display tape status */ sprintf (buf, "Status: %8.8X", stat); if (GMT_EOF(stat)) strcat (buf, " EOF"); if (GMT_BOT(stat)) strcat (buf, " BOT"); if (GMT_EOT(stat)) strcat (buf, " EOT"); if (GMT_SM(stat)) strcat (buf, " SET-MARK"); if (GMT_EOD(stat)) strcat (buf, " EOD"); if (GMT_WR_PROT(stat)) strcat (buf, " WR-PROT"); if (GMT_ONLINE(stat)) strcat (buf, " ON-LINE"); if (GMT_D_6250(stat)) strcat (buf, " 6250"); if (GMT_D_1600(stat)) strcat (buf, " 1600"); if (GMT_D_800(stat)) strcat (buf, " 800"); if (GMT_DR_OPEN(stat)) strcat (buf, " NO-TAPE"); printf ("ST0: %s\n", buf); }; void common () { printf ("stblk.mt_blkno=%d\n", stblk.mt_blkno); }; void set_blk (int len) { int rc; if (len) printf ("Setting length %d records.", len); else printf ("Setting variable records."); fflush (stdout); opblk.mt_op = MTSETBLK; opblk.mt_count = len; rc = ioctl (fh, MTIOCTOP, (char*)&opblk); printf (" rc=%d\n", rc); }; void my_read (int fh) { int rc; char buf2 [65535]; printf ("read..."); fflush (stdout); memset (buf2, ' ', 10); rc = read (fh, buf2, 65535); printf (" rc=%d\n", rc); buf2 [10] = 0; printf ("%s\n", buf2); disp_stat (); common (); }; void my_write (int fh) { int rc; printf ("write..."); fflush (stdout); rc = write (fh, buf, BLKLEN); printf (" rc=%d\n", rc); disp_stat (); common (); }; void my_bksp (int fh) { int rc; printf ("backspace..."); fflush (stdout); opblk.mt_op = MTBSR; opblk.mt_count = 1; rc = ioctl (fh, MTIOCTOP, (char*)&opblk); printf (" rc=%d\n", rc); disp_stat (); common (); }; void my_rew (int fh) { int rc; printf ("rewind..."); fflush (stdout); opblk.mt_op = MTREW; opblk.mt_count = 1; rc = ioctl (fh, MTIOCTOP, (char*)&opblk); printf (" rc=%d\n", rc); disp_stat (); }; int main (int argc) { int rc; printf ("Opening Tape Handle\n"); fh = open ("/dev/st0", O_RDWR); if (fh >= 0) { rc = ioctl (fh, MTIOCGET, (char*)&stblk); if (rc < 0) { printf ("Failed to IOCTL the Tape\n"); } else { common (); }; disp_stat (); set_blk (0); disp_stat (); my_rew (fh); buf [0] = 'A'; my_write (fh); my_bksp (fh); my_read (fh); if (argc != 1) { // Use any parameter to test this case. set_blk (0); disp_stat (); }; buf [0] = 'B'; my_write (fh); my_bksp (fh); my_read (fh); my_rew (fh); printf ("Closing Tape Handle\n"); close (fh); } else { printf ("Failed to Open Tape\n"); }; return (0); };