#include <exec/types.h>
#include <exec/io.h>
#include <devices/scsidisk.h>
#include <FastTrak.h>

int SCSIdirect(int,int,UWORD *,ULONG,int);	/* Function prototype */

UBYTE    Packet[10];
struct   SCSICmd        SCSIinfo;
struct   MsgPort        *MyPort;
struct   IOStdReq       *Req;


main(argc,argv)
int   argc;
char **argv;
{
int   j,unit;
char  *ptr;
UBYTE    params[256];

   if ((argc!=2)||(argv[1][0]=='?')) {
      printf("Usage: %ls <unit>\n",argv[0]);
      exit(FALSE);
   }

   j=0;                    /* Get unit number from CLI command line */
   ptr = argv[1];
   while (*ptr) {
      j *= 10;
      j += *ptr - 48;
      ptr++;
   }
   unit = j;

   Packet[0] = 1;          /* Assemble Command Descriptor Block */
   Packet[1] =
   Packet[2] =
   Packet[3] =
   Packet[4] =
   Packet[5] = 0;

   printf("Zeroing unit...");

   if (SCSIdirect(6,unit,(UWORD *)params,0,READ))
      printf("failed\n");
   else
      printf("OK\n");
}


int SCSIdirect(cnt,unit,buffer,len,rw)
int   cnt,unit;
UWORD *buffer;
ULONG len;
int   rw;
{
   int   status;
   int   OpenFlag = 1;

   status = -1;       /* device error */

   MyPort = (struct MsgPort *)CreatePort("ft_Tools",0);
   if (MyPort) {
      Req = (struct IOStdReq *)CreateStdIO(MyPort);
      if (Req) {
         OpenFlag = OpenDevice("harddisk.device",unit,Req,0);
         if (!OpenFlag) {

            SCSIinfo.scsi_Data = buffer;
            SCSIinfo.scsi_Length = len;
            SCSIinfo.scsi_Command = (UBYTE *)&Packet;
            SCSIinfo.scsi_CmdLength = cnt;
            SCSIinfo.scsi_Flags = rw?SCSIF_READ:SCSIF_WRITE;

            Req->io_Command = 28;
            Req->io_Data = (APTR)&SCSIinfo;
            Req->io_Length = sizeof(struct SCSICmd);
            DoIO(Req);                         /* Start process */

            status = Req->io_Error;

            CloseDevice(Req);
         }
         DeleteStdIO(Req);
      }
      DeletePort(MyPort);
   }
   return(status);
}
