"Fossies" - the Fresh Open Source Software Archive

Member "dvdisaster-0.79.5/scsi-layer.h" (25 Oct 2015, 7180 Bytes) of package /linux/misc/dvdisaster-0.79.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "scsi-layer.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes reports: 0.79.3_vs_0.79.5 or 0.72.6_vs_0.79.5.

    1 /*  dvdisaster: Additional error correction for optical media.
    2  *  Copyright (C) 2004-2015 Carsten Gnoerlich.
    3  *
    4  *  Email: carsten@dvdisaster.org  -or-  cgnoerlich@fsfe.org
    5  *  Project homepage: http://www.dvdisaster.org
    6  *
    7  *  This file is part of dvdisaster.
    8  *
    9  *  dvdisaster is free software: you can redistribute it and/or modify
   10  *  it under the terms of the GNU General Public License as published by
   11  *  the Free Software Foundation, either version 3 of the License, or
   12  *  (at your option) any later version.
   13  *
   14  *  dvdisaster is distributed in the hope that it will be useful,
   15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17  *  GNU General Public License for more details.
   18  *
   19  *  You should have received a copy of the GNU General Public License
   20  *  along with dvdisaster. If not, see <http://www.gnu.org/licenses/>.
   21  */
   22 
   23 #ifndef SCSI_LAYER_H
   24 #define SCSI_LAYER_H
   25 
   26 #ifdef SYS_LINUX
   27 #include <sys/ioctl.h>
   28 #include <linux/cdrom.h>
   29 #endif
   30 
   31 #ifdef SYS_FREEBSD
   32 #include <camlib.h>
   33 #endif
   34 
   35 /***
   36  *** Global settings
   37  ***/
   38 
   39 /* Theretically not needed, but using less causes DMA breakage 
   40    on some chipsets. */
   41 
   42 #define MIN_TRANSFER_LEN 4  
   43 
   44 /***
   45  *** Define the Sense data structure.
   46  ***/
   47 
   48 /* 
   49  * Linux already has one 
   50  */
   51 
   52 #ifdef SYS_LINUX
   53 #define MAX_CDB_SIZE CDROM_PACKET_SIZE
   54 
   55 /* Now globally defined for all OSes here */
   56 //typedef struct request_sense Sense;
   57 #endif
   58 
   59 #ifdef SYS_FREEBSD
   60 #define MAX_CDB_SIZE SCSI_MAX_CDBLEN
   61 #endif
   62 
   63 #if defined(SYS_UNKNOWN) || defined(SYS_NETBSD)
   64 #define MAX_CDB_SIZE 16   /* longest possible SCSI command */
   65 #endif
   66 
   67 /* 
   68  * The sense struct is named differently on various OSes,
   69  * Some have subtle differences in the used data types.
   70  * To avoid typecasting mayhem we simply reproduce the Linux
   71  * version here and use it on all OS versions.
   72  */
   73 
   74 typedef struct _Sense {
   75     guint8 error_code       : 7;
   76     guint8 valid            : 1;
   77     guint8 segment_number;
   78     guint8 sense_key        : 4;
   79     guint8 reserved2        : 1;
   80     guint8 ili          : 1;
   81     guint8 reserved1        : 2;
   82     guint8 information[4];
   83     guint8 add_sense_len;
   84     guint8 command_info[4];
   85     guint8 asc;
   86     guint8 ascq;
   87     guint8 fruc;
   88     guint8 sks[3];
   89     guint8 asb[46];
   90 } Sense;
   91 
   92 /***
   93  ***  The DeviceHandle is pretty much our device abstraction layer. 
   94  ***
   95  * It contains info about the opened device and the inserted medium.
   96  */
   97 
   98 typedef struct _DeviceHandle
   99 {  /*
  100     * OS-specific data for device access
  101     */
  102 #if defined(SYS_LINUX) || defined(SYS_NETBSD)
  103    int fd;                    /* device file descriptor */
  104 #endif
  105 #ifdef SYS_FREEBSD
  106    struct cam_device *camdev; /* camlib device handle */
  107    union ccb *ccb;
  108 #endif
  109 
  110   /*
  111    * Simulated images
  112    */
  113   
  114    LargeFile *simImage;       /* Image for simulation mode */
  115    int pass;                  /* provided by the reader to simulate failure in specific passes */
  116   
  117    /*
  118     * OS-independent data about the device
  119     */
  120 
  121    char *device;              /* /dev/foo or whatever the OS uses to name it */
  122    char devinfo[34];          /* whole device info string from INQUIRY */
  123    char vendor[34];           /* vendor and product info only */
  124 
  125    Sense sense;               /* sense data from last operation */
  126    int senseSize;             /* OS may have differently sized struct */
  127 
  128    double singleRate;         /* supposed KB/sec @ single speed */
  129    int maxRate;               /* guessed maximum transfer rate */
  130    int clusterSize;           /* number of sectors per cluster */
  131 
  132    /*
  133     * Raw reading support
  134     */
  135 
  136    int canReadDefective;      /* TRUE if drive claims to raw read uncorrectable sectors */
  137    int canC2Scan;             /* TRUE if drive supports C2 error scanning */
  138    int c2[MAX_CLUSTER_SIZE];  /* C2 errors per sector */
  139    unsigned char previousReadMode;/* read mode prior to switching to raw reads */
  140    unsigned char previousRetries; /* retries prior to switching */
  141    unsigned char currentReadMode; /* current raw read mode */
  142    RawBuffer *rawBuffer;      /* for performing raw read analysis */
  143    int (*read)(struct _DeviceHandle*, unsigned char*, int, int);
  144    int (*readRaw)(struct _DeviceHandle*, unsigned char*, int, int);
  145 
  146    /* 
  147     * Information about currently inserted medium 
  148     */
  149 
  150    gint64 sectors;            /* actually used number of sectors */
  151    int sessions;              /* number of sessions */
  152    int layers;                /* and layers */
  153    char manuID[20];           /* Manufacturer info from ADIP/lead-in */
  154    int mainType;              /* CD or DVD */
  155    int subType;               /* see enum below */
  156    char *typeDescr;           /* human readable form of subType */
  157    int bookType;              /* book type */
  158    char *bookDescr;           /* human readable of above */
  159    int profile;               /* profile selected by drive */
  160    char *profileDescr;        /* human readable form of above */
  161    char *shortProfile;        /* short version of above */
  162    int isDash;                /* DVD- */
  163    int isPlus;                /* DVD+ */
  164    int incomplete;            /* disc is not finalized or otherwise broken */
  165    int discStatus;            /* obtained from READ DISC INFORMATION query */
  166    int rewriteable;
  167    char *mediumDescr;         /* textual description of medium */
  168 
  169    /*
  170     * size alternatives from different sources 
  171     */
  172 
  173    gint64 readCapacity;       /* value returned by READ CAPACITY */
  174    gint64 userAreaSize;       /* size of user area according to DVD Info struct */
  175    gint64 blankCapacity;      /* blank capacity (maybe 0 if query failed) */
  176 
  177    /*
  178     * debugging stuff
  179     */
  180 
  181    Bitmap *defects;           /* for defect simulation */
  182 } DeviceHandle;
  183 
  184 /* 
  185  * Media types seem not to be standardized anywhere,
  186  * so we make up our own here.
  187  */
  188 
  189 #define MAIN_TYPE_MASK 0xf0
  190 
  191 #define CD             0x10
  192 #define DATA1          0x11
  193 #define XA21           0x12
  194 
  195 #define DVD            0x20
  196 #define DVD_RAM        0x21
  197 #define DVD_DASH_R     0x22
  198 #define DVD_DASH_RW    0x23
  199 #define DVD_PLUS_R     0x24
  200 #define DVD_PLUS_RW    0x25
  201 #define DVD_DASH_R_DL  0x26
  202 #define DVD_DASH_RW_DL 0x27
  203 #define DVD_PLUS_R_DL  0x28
  204 #define DVD_PLUS_RW_DL 0x29
  205 
  206 #define BD             0x40
  207 #define BD_R           0x41
  208 #define BD_RE          0x42
  209 
  210 #define UNSUPPORTED    0x00 
  211 
  212 /* transport io modes */
  213 
  214 #define DATA_WRITE 0
  215 #define DATA_READ  1
  216 #define DATA_NONE  2
  217 
  218 /***
  219  *** Exported functions
  220  ***/
  221 
  222 /*
  223  * OS-dependent wrappers from scsi-<os>.c
  224  */
  225 
  226 DeviceHandle* OpenDevice(char*);
  227 
  228 int SendPacket(DeviceHandle*, unsigned char*, int, unsigned char*, int, Sense*, int);
  229 int SimulateSendPacket(DeviceHandle*, unsigned char*, int, unsigned char*, int, Sense*, int);
  230 
  231 /*** 
  232  *** scsi-layer.c
  233  ***
  234  * The really user-visible stuff
  235  */
  236 
  237 enum 
  238 {  MODE_PAGE_UNSET, 
  239    MODE_PAGE_SET
  240 };
  241 
  242 
  243 gint64 CurrentMediumSize(int);
  244 void CloseDevice(DeviceHandle*);
  245 
  246 int InquireDevice(DeviceHandle*, int); 
  247 void SetRawMode(DeviceHandle*, int);
  248 
  249 void SpinupDevice(DeviceHandle*);
  250 void LoadMedium(struct _DeviceHandle*, int);
  251 int  TestUnitReady(DeviceHandle*);
  252 
  253 int ReadSectors(DeviceHandle*, unsigned char*, gint64, int);
  254 int ReadSectorsFast(DeviceHandle*, unsigned char*, gint64, int);
  255 
  256 #endif /* SCSI_LAYER_H */