home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / docum / dos-ref.doc / examples / chap3.arj / DEVCON.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-25  |  2.4 KB  |  100 lines

  1. /* DEVCON.C */
  2.  
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <dos.h>
  7.  
  8. /* some device attribute bits */
  9. #define CHAR_DEV    (1 << 15)
  10. #define INT29       (1 << 4)
  11. #define IS_CLOCK    (1 << 3)
  12. #define IS_NUL      (1 << 2)
  13.  
  14. #pragma pack(1)
  15.  
  16. typedef unsigned char BYTE;
  17.  
  18. typedef struct DeviceDriver {
  19.     struct DeviceDriver far *next;
  20.     unsigned attr;
  21.     unsigned strategy;
  22.     unsigned intr;
  23.     union {
  24.         BYTE name[8];
  25.         BYTE blk_cnt;
  26.         } u;
  27.     } DeviceDriver;
  28.  
  29. typedef struct {
  30.     void far *dpb;
  31.     void far *sft;
  32.     DeviceDriver far *clock;
  33.     DeviceDriver far *con;
  34.     unsigned max_bytes;
  35.     void far *disk_buff;
  36.     void far *cds;
  37.     void far *fcb;
  38.     unsigned prot_fcb;
  39.     unsigned char blk_dev;
  40.     unsigned char lastdrv;
  41.     DeviceDriver nul;   /* not a pointer */
  42.     unsigned char join;
  43.     // ...
  44.     } ListOfLists;  // DOS 3.1+
  45.         
  46. void fail(char *s) { puts(s); exit(1); }
  47.  
  48. main(int argc, char *argv[])
  49. {
  50.     ListOfLists far *doslist;
  51.     DeviceDriver far *dd;
  52.     
  53.     _asm {
  54.         xor bx, bx
  55.         mov es, bx
  56.         mov ah, 52h
  57.         int 21h
  58.         mov doslist, bx
  59.         mov doslist+2, es
  60.         }
  61.  
  62.     if (! doslist)
  63.         fail("INT 21h Function 52h not supported");
  64.     if (_fmemcmp(doslist->nul.u.name, "NUL     ", 8) != 0)
  65.         fail("NUL name wrong");
  66.     if (! (doslist->nul.attr & IS_NUL))
  67.         fail("NUL attr wrong");
  68.     if (_fmemcmp(doslist->con->u.name, "CON     ", 8) != 0)
  69.         fail("CON name wrong");
  70.     if (! (doslist->con->attr & CHAR_DEV))
  71.         fail("CON attr wrong");
  72.     if (_fmemcmp(doslist->clock->u.name, "CLOCK$  ", 8) != 0)
  73.         fail("CLOCK$ name wrong");
  74.     if (! (doslist->clock->attr & IS_CLOCK))
  75.         fail("CLOCK$ attr wrong");
  76.  
  77.     if (argv[1][0] == '-')
  78.     {
  79.         /* print out device chain */
  80.         dd = &doslist->nul;
  81.         do { 
  82.             if (dd->attr & CHAR_DEV)
  83.                 printf("%.8Fs\n", dd->u.name); 
  84.             else
  85.                 printf("Block dev: %u unit(s)\n", dd->u.blk_cnt);
  86.             dd = dd->next;
  87.         } while (FP_OFF(dd->next) != -1);
  88.     }
  89.  
  90.     /* go back to first CON driver */
  91.     dd = &doslist->nul;
  92.     while (_fmemcmp(dd->u.name, "CON     ", 8) != 0)
  93.         dd = dd->next;
  94.     
  95.     /* DOS List Of Lists holds separate ptr to latest CON driver */
  96.     puts(dd == doslist->con ? "no new CON" : "new CON");
  97.     
  98.     return 0;
  99. }
  100.