home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l440 / 2.ddi / CHAP3 / DEVCON.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-14  |  2.7 KB  |  109 lines

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