home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_07_02 / v7n2063a.txt < prev    next >
Text File  |  1988-09-15  |  4KB  |  100 lines

  1. /* RQH.H **    Device Driver definitions and templates.
  2.          **    The DOS device header and DOS Request Header is mapped.
  3.                                                     -- R.D.Allen, 9/3/87
  4. Copyright 1987, 1988 PARS Service Partnership
  5. */
  6.  
  7. /* Convenient method for mapping an INTEL far pointer in C */
  8.  
  9. union _farp {
  10.     struct {
  11.         unsigned int offset;
  12.         unsigned int segment;
  13.     } address;
  14.     char far *string;
  15. };
  16.  
  17. /* A method to map the device header structure required by DOS
  18.    and declared in the startup file DVR_MAIN.ASM                 */
  19.  
  20. extern struct _header {
  21.     union _farp next_dev;
  22.     union _ioctl {
  23.         unsigned int word;
  24.         struct {
  25.             unsigned int stout    : 1;    /* Bit 0 ** Is stdout device        */
  26.             unsigned int stin    : 1;    /* Bit 1 ** Is stdin device            */
  27.             unsigned int nul    : 1;    /* Bit 2 ** Is the NULL device        */
  28.             unsigned int clock    : 1;    /* Bit 3 ** Is the $CLOCK device    */
  29.             unsigned int rsv4    : 1;    /* Bit 4 **    reserved                */
  30.             unsigned int raw    : 1;    /* Bit 5 ** Raw mode status            */
  31.             unsigned int eof    : 1;    /* Bit 6 ** At end of file status    */
  32.             unsigned int isdev    : 1;    /* Bit 7 ** Is a device                */
  33.             unsigned int rsv810    : 3;    /* Bits 8 - 10 ** reserved            */
  34.             unsigned int ocr    : 1;    /* Bit 11 ** I forgot?                */
  35.             unsigned int rsv12    : 1;    /* Bit 12 ** reserved                */
  36.             unsigned int obusy    : 1;    /* Bit 13 ** Output busy status        */
  37.             unsigned int ioctl    : 1;    /* Bit 14 ** Supports IOCTL calls    */
  38.             unsigned int cdev    : 1;    /* Bit 15 ** Character device        */
  39.         } bits;
  40.     } io;
  41.     unsigned int strat;                    /* Address of STRATEGY Routine      */
  42.     unsigned int intr;                    /* Address of INTERRUPT Routine        */
  43.     char name[8];                        /* DOS file name of device            */
  44. } header;
  45.  
  46. /* The tail of a Request Header is mapped differently for different
  47.    commands. These structures will define all necessary access methods.        */
  48.  
  49. struct _init {            /* Command tail used only during initialization        */
  50.     char    units;            /* Number of Units as required for Block Device    */
  51.     union    _farp end;        /* Ending address of driver reported to DOS        */
  52.     union    _farp args;        /* CONFIG.SYS line after "DEVICE="                */
  53.     char    devnum;            /* Beginning Device Number, this Block Device    */
  54. };
  55.  
  56. struct _io {            /* Command tail used for most other commands        */
  57.     char    media;                /* Block Device media field                    */
  58.     union    _farp data;            /* Address for data Input/Output            */
  59.     int        count;                /* Number of bytes to be transferred        */
  60.     int        sec_num;            /* Block Device sector number                */
  61.     union    _farp volume;        /* Block Device Volume label                */
  62. };
  63.  
  64. /* A union to hold all the different Request Header command tail formats.    */
  65.                     
  66. union _rq_tail {
  67.     struct _init    init;            /* Initialization command tail            */
  68.     struct _io        io;                /* Most read, write routines            */
  69.     char            peek;            /* Non-destructive read, no wait        */
  70. };
  71.  
  72. /* DOS Request Header format. This structure unites all the different
  73.    parts of a request header so they may be accessed in C.                     */
  74.  
  75. struct _rq_hdr {
  76.     char    count;                /* total bytes in header                    */
  77.     char    unit_code;            /* Block Device Garbage (not used)            */
  78.     char    command;            /* Device driver command                    */
  79.     struct    _st_bits {            /* Bit fields to map Status word            */
  80.         unsigned int err_type    : 8;    /** DOS error to report                */
  81.         unsigned int done        : 1;    /** Done status (normally returned) */
  82.         unsigned int busy        : 1;    /** Busy status (normal not used)    */
  83.         unsigned int reserved    : 5;        
  84.         unsigned int err_flag    : 1;    /** If set, ERR_TYPE should used    */
  85.     } status;                        /* Status word returned to DOS            */
  86.     struct    _rq_hdr far *next_rq;    /* RESERVED -- front pointer            */
  87.     struct    _rq_hdr    far *pending;    /* Chain pointer for queued req.        */
  88.     union    _rq_tail tail;            /* Request Header Command Tail            */
  89. };
  90.  
  91. /* Request Header address storage as used by STRATEGY routine. */
  92.  
  93. union _ptr {
  94.     struct {
  95.         unsigned int offset;
  96.         unsigned int segment;
  97.     } address;
  98.     struct _rq_hdr far *rq;            /* far pointer to access request header */
  99. };
  100.