home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
useful
/
disk
/
misc
/
btntape
/
src
/
btn.c
next >
Wrap
C/C++ Source or Header
|
1994-04-03
|
38KB
|
1,000 lines
/**** BTNtape Handler for SCSI tape drives ****/
/**** Author: Bob Rethemeyer (drBob@cup.portal.com) ****/
#define VERSDATE "(03.14.94)" /* (DD.MM.YY) */
#define VERSNAME "BTNtape-RAR 3.0 "
/* (If you recompile BTN, ^^^ put your initials here!) */
/*--------------------------------------------------------------------------
* (c) Copyright 1990,1994 Robert Rethemeyer.
* This software may be freely distributed and redistributed,
* for non-commercial purposes, provided this notice is included.
*--------------------------------------------------------------------------
* BTNtape is an AmigaDOS device handler to make a simple DOS TAPE: device.
* It converts DOS packets for the device into I/O requests to a
* "SCSI-direct" compatible device driver. It is based on "my.handler"
* by Phillip Lindsay and a SCSI-direct program by Robert Mitchell.
* Seek() handling derived from code by Dennis J. Brueni, 8-24-91.
* Source is ANSI C compliant. Compile with SAS/C v6.
*
* This handler works in conjunction with the accompanying TapeMon program.
*--------------------------------------------------------------------------
*/
#define _STRICT_ANSI
#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/ports.h>
#include <exec/tasks.h>
#include <exec/libraries.h>
#include <exec/io.h>
#include <exec/memory.h>
#include <devices/scsidisk.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <libraries/filehandler.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include "btn.h"
#include "tplink.h"
#include <proto/exec.h>
#include <proto/intuition.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/intuition_pragmas.h>
/* sense keys of interest */
#define NOS 0x00 /* no sense */
#define RCV 0x01 /* recovered error */
#define ILL 0x05 /* illegal request */
#define UAT 0x06 /* unit attention */
#define BLC 0x08 /* blank check */
#define VOF 0x0d /* volume overflow */
/* pseudo sense keys returned by DoSense */
#define FMK 0x10 /* filemark */
#define EOM 0x11 /* end of tape */
#define ILI 0x12 /* incorr leng */
#define SERR 0x13 /* SCSI error */
/*======== Global data */
struct ExecBase *SysBase;
struct IntuitionBase *IntuitionBase=NULL;
UBYTE *cdb; /* pointer to SCSI command buffer */
UBYTE *sns; /* pointer to sense data buffer */
UBYTE *inq; /* pointer to inquiry data */
struct SCSICmd *cmd; /* pointer to scsidirect command */
struct IOStdReq *ior; /* pointer to io request structure*/
UBYTE *TapeBuff[2]={NULL,NULL};/* pointers to 2 tape buffers */
struct Process *myproc; /* ptr to handler's process struct*/
struct DosPacket *mypkt; /* ptr to dos packet sent */
struct tplink *linktp; /* pointer to link structure */
struct MsgPort *monport=NULL; /* ptr to mon communication msg port */
struct MsgPort *btnport; /* ptr to btn communication msg port */
struct BTNmsg monmsg; /* message we will send to tapemon*/
ULONG blknum; /* block number for io operation */
ULONG blksize = 512; /* bytes per tape block */
ULONG numblks = 1; /* number of blocks per io oper */
ULONG TBSize; /* bytes in a tape buffer */
ULONG rwlen; /* bytes in a tape read/write */
ULONG rdlen; /* bytes/blks in a read */
ULONG expect; /* expect num of bytes transferred*/
ULONG bugmask = 0; /* 2090A bug circumvention */
long filenum = -1; /* current file position on tape */
long lastwrtn= -1; /* last filenum written */
long actual; /* actual num of bytes transferred*/
long res1; /* #bytes xfered packet return */
long Boff; /* current offset in tape buffer */
long tpsize ; /* tape size in blocks */
long reserved = 0; /* number of reserved blks at BOT */
int tapenum; /* tape volume number */
BOOL inprog = FALSE; /* io operation in progress flag */
BOOL reten = FALSE; /* retension-on-UAT flag */
BOOL mbusy = FALSE; /* waiting for reply from tapemon */
BOOL bswap = FALSE; /* swap-bytes flag */
BOOL dbug = FALSE; /* print debug info */
char *z; /* scratch */
char *devname, nbuf[32]; /* file name reference from Open()*/
char dbb[80]; /* buffer for monitor messages */
UBYTE Lun = 0; /* Logical Unit number << 5 */
UBYTE varblk = 0; /* variable-block flag for SEQ */
UBYTE fixedbit = 0; /* fixed-block mode bit for SEQ */
UBYTE versiontag[] = "$VER: " VERSNAME VERSDATE;
char *cpywr = "(c) Copyright 1990-1994 R. Rethemeyer";
/*********************** Main program ********************************/
void _main(char *nu)
{
struct SCSICmd scsicmd; /* SCSIdirect command buffer */
UBYTE snsarea[64]; /* sense data buffer */
UBYTE cmdbuff[16]; /* SCSI command buffer */
UBYTE inqdata[40]; /* inquiry data buffer */
struct tplink tpl; /* structure to link hndlr & mon */
struct DeviceNode *mynode; /* ptr to devnode passed in pkt Arg3 */
struct MsgPort *mp; /* ptr to io message port */
struct MsgPort *pktport; /* ptr to process message port */
struct Message *m;
struct BTNmsg *b;
ULONG dvnode; /* ptr to devnode passed in pkt Arg3 */
ULONG unit=99999; /* device SCSI unit address */
ULONG bufmemtype=0; /* type of mem for dynamic buffers */
ULONG gotopos=0; /* position to open at (blk/filemark)*/
ULONG fmarks=1; /* # file marks for write/skip */
ULONG pktsig; /* signal mask for process msg port */
ULONG btnsig=0; /* signal mask for mon comm msg port */
char *driver; /* name of SCSI device driver */
UBYTE *dptr; /* ptr to next byte in dos buffer */
long dflags=0; /* device flags */
long iostat; /* status of previous read */
long dcnt; /* count of dos packet bytes to move */
long mcnt; /* count of bytes to move */
long rcnt; /* count of bytes moved for read */
long current; /* current byte position in file */
long remain; /* bytes remaining in tape buffer */
long pkcnt; /* flag to indicate data written */
long x;
int y=0;
int opmode=0; /* how has the handler been opened */
#define CLOSED 0 /* not doing anything */
#define READING 1 /* reading tape */
#define WRITING 2 /* writing tape */
#define CURRPOS 3 /* read current file position */
#define RAWMODE 4 /* raw command mode */
#define UMODSEL 5 /* user mode select */
int Bn; /* current buffer number, 0 or 1 */
int position; /* how to position tape at Open */
#define POSREW 0 /* rewind to beginning */
#define POSNREW 1 /* don't move */
#define POSAPP 2 /* append to eod (seq) */
#define POSEND 3 /* append to eod (seq) */
#define POSSKIP 4 /* skip to file/block */
int nrflag=POSREW; /* rewind behavior of TAPE: */
BOOL rewcl = FALSE; /* rewind-on-close flag */
BOOL eject = FALSE; /* eject-on-close flag */
BOOL dirty = FALSE; /* buffer has unwritten data in it */
BOOL atend; /* flags filemark encountered */
BOOL eot; /* flags end-of-tape encountered */
BOOL rderr; /* flags error during read */
BOOL errec = FALSE; /* attempt error recovery flag */
BOOL aonly = FALSE; /* append-only flag */
BOOL rdonly =FALSE; /* read-only flag */
BOOL starting=FALSE;/* flag detects first open message */
BOOL dos2=FALSE; /* indicates i