
#define MTLUN 0
#define MTBUSID 2

static char cmdblk[6] = { 0, (MTLUN<<5)|01, 0, 0, 0, 0 }; 

extern char *dptrlo;
extern pageaddr dptrhi;
extern int dlen;
extern char *cptr;
extern int busid;
extern scsiop();


mt_read(minor, rawflag)
int minor;
int rawflag;
{
    cmdblk[0] = 0x08;
    return(mtrdwr());
}


mt_write(minor, rawflag)
int minor;
int rawflag;
{
    cmdblk[0] = 0x0a;
    return(mtrdwr());
}


static
mtrdwr()
{
    char *mt_stat();
    char *statptr;

    busid = MTBUSID;
    cptr = cmdblk;
    cmdblk[4] = udata.u_count >> 9;
    dlen = cmdblk[4] << 9;
    dptrlo = udata.u_base;
    dptrhi = padr(1, udata.u_base);

    if (scsiop())
    {
	statptr = mt_stat();
	kprintf("MT error %x\n",statptr[2] & 0xff);
	udata.u_error = EIO;
	return (-1);
    }
    else
	return (cmdblk[4] << 9);
}


mt_open()
{
    char *mt_stat();

    mt_stat();
    return(0);
}



mt_close()
{
    mt_rewind();
}


static
mt_rewind()
{
    static char cmdblk[6] = { 0x01, MTLUN<<5, 0, 0, 0, 0 }; 

    busid = MTBUSID;
    cptr = cmdblk;
    dlen = 0;
    dptrlo = NULL;
    dptrhi = 0;
    return(scsiop());

}


static char *
mt_stat()
{
    static char cmdblk[6] = { 0x03, MTLUN<<5, 0, 0, 10, 0 }; 
    static char statbuf[10];
    busid = MTBUSID;
    cptr = cmdblk;
    dlen = 10;
    dptrlo = statbuf;
    dptrhi = padr(1, statbuf);
    scsiop();
    return (statbuf);
}
