home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 13 / MA_Cover_13.bin / source / c / stefanb_src / private_projects / yath / doit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-23  |  2.1 KB  |  117 lines

  1. #include <stdio.h>
  2. #include <exec/memory.h>
  3.  
  4. #include "io.h"
  5.  
  6. struct scsichan sc={"scsi.device",6,0,NULL,NULL};
  7.  
  8. #define BLOCKLEN 2048
  9. #define BLOCKS   100
  10. #define DATALEN  BLOCKLEN*BLOCKS
  11. /* __aligned UBYTE data[DATALEN]; */
  12. UBYTE *data;
  13. __aligned UBYTE scmd[10]={0,0,0,0,0,0,0,0,0,0};
  14. __aligned UBYTE sense[255];
  15. __aligned struct SCSICmd sioc={NULL,DATALEN,0,scmd,10,0,0,0,sense,255,0};
  16.  
  17. main(int argc,char **argv)
  18. {
  19.  int i,j;
  20.  BYTE rc;
  21.  
  22.  if (!(data=AllocMem(DATALEN,MEMF_CLEAR|MEMF_PUBLIC))) {
  23.   fprintf(stderr,"no memory\n");
  24.   CloseSCSIchan(&sc);
  25.   exit(0);
  26.  }
  27.  sioc.scsi_Data=data;
  28.  fprintf(stderr,"SCSI Geƶffnet!\n");
  29.  sioc.scsi_Flags=SCSIF_READ;
  30.  
  31.  if (argc<2) exit(0);
  32.  if (OpenSCSIchan(&sc))
  33.   {
  34.    fprintf(stderr,"Fehler beim oeffnen!\n");
  35.    exit(0);
  36.   }
  37.  
  38.  scmd[0]=0x12;
  39.  scmd[4]=255;
  40.  if (rc=DoSCSIcmd(&sc,&sioc))
  41.   {
  42.    fprintf(stderr,"Fehler %d\n",rc);
  43.    CloseSCSIchan(&sc);
  44.    FreeMem(data,DATALEN);
  45.    exit(0);
  46.   }
  47.  fprintf(stderr,"Inquiry Data: %s\n",&data[8]);
  48.  
  49.  if (!strcmp("-r",argv[1]))
  50.   {
  51.    fprintf(stderr,"Rewinding...\n");
  52.    scmd[0]=0x1;
  53.    scmd[1]=1;
  54.    scmd[2]=0;
  55.    scmd[3]=0;
  56.    scmd[4]=0;
  57.    scmd[5]=0;
  58.    if (rc=DoSCSIcmd(&sc,&sioc))
  59.     {
  60.      fprintf(stderr,"Fehler %d\n",rc);
  61.     }
  62.    CloseSCSIchan(&sc);
  63.    FreeMem(data,DATALEN);
  64.    exit(0);
  65.   }
  66.  
  67. #if 0
  68.  j=atoi(argv[1]);
  69.  fprintf(stderr,"\nReading %d blocks\n",j);
  70.    while (j>0)
  71.     {
  72.      fprintf(stderr,"%d\n",j);
  73. #endif
  74.      scmd[0]=0x43;
  75.      scmd[1]=0;
  76.      scmd[2]=0;
  77.      scmd[3]=0;
  78.      scmd[4]=0;
  79.      scmd[5]=0;
  80.      scmd[6]=0;
  81.      scmd[7]=(DATALEN>>8) & 0xff;
  82.      scmd[8]=DATALEN & 0xff;
  83.      scmd[9]=0;
  84.      if (rc=DoSCSIcmd(&sc,&sioc))
  85.       {
  86.        fprintf(stderr,"Fehler %d\n",rc);
  87.        CloseSCSIchan(&sc);
  88.        FreeMem(data,DATALEN);
  89.        exit(0);
  90.       }
  91.  
  92.      fwrite(data,DATALEN,1,stdout);
  93. #if 0
  94.      j-=BLOCKS;
  95.     }
  96.    fprintf(stderr,"\n");
  97.  
  98.    /* Media removal */
  99.    scmd[0]=0x1e;
  100.    scmd[1]=0;
  101.    scmd[2]=0;
  102.    scmd[3]=0;
  103.    scmd[4]=1;
  104.    scmd[5]=0;
  105.    if (rc=DoSCSIcmd(&sc,&sioc))
  106.     {
  107.      fprintf(stderr,"Fehler %d\n",rc);
  108.      CloseSCSIchan(&sc);
  109.      FreeMem(data,DATALEN);
  110.      exit(0);
  111.     }
  112. #endif
  113.  
  114.  CloseSCSIchan(&sc);
  115.  FreeMem(data,DATALEN);
  116. }
  117.