home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 458.lha / zapdh0_v1.3 / listdevs.mod < prev    next >
Text File  |  1990-12-12  |  7KB  |  217 lines

  1. MODULE lister;
  2.  
  3. (* example code showing how to scan the DOS device list
  4.    to work out what devices are available to DOS,
  5.    what their types are ( whether they're a device, a dir etc ),
  6.    and how to extract info on properties of devices ( host device
  7.    physical parameters etc )
  8. *)
  9.  
  10. (* by J Davis v1.0 10/89            *)
  11. (*            v1.1 6/90             *)
  12. (* compiled using TDI M-2 v3.01a    *)
  13.  
  14. (* thanks to Patrick Horgan for the  code he 
  15.    posted to UseNet showing how to do the enviroment probing 
  16. *)
  17.  
  18. FROM DOSLibrary      IMPORT DOSName,DOSBase,BPTR,BSTR;
  19. FROM DOSExtensions   IMPORT DosBaseRec,RootNode,DosInfo,DeviceList;
  20. FROM AmigaUtils      IMPORT PtrFromBPTR;
  21. FROM SYSTEM          IMPORT NULL;
  22. FROM InOut           IMPORT WriteString,WriteLn,Write;
  23. FROM LongInOut       IMPORT WriteLongCard,WriteLongInt,WriteLongHex;
  24. FROM Libraries       IMPORT OpenLibrary,CloseLibrary;
  25. FROM DOSLibrary      IMPORT DateStampRec;
  26. FROM FileHandler     IMPORT DeviceNode,FileSysStartupMsg;
  27. FROM SYSTEM          IMPORT ADDRESS,BYTE;
  28.  
  29. TYPE 
  30.  
  31. string = ARRAY [0..255] OF CHAR;
  32. strptr = POINTER TO string;
  33.  
  34. DOSenv = ARRAY [0..255] OF LONGCARD;
  35.  
  36. VAR
  37.  
  38. ourdosbase : POINTER TO DosBaseRec;             (* use this to access dosbase *)
  39. infoptr    : POINTER TO DosInfo;                (* points to DOSinfo node     *)
  40. devlistptr : POINTER TO DeviceList;             (* points to current place is DOS devlist *)
  41. devnodeptr : POINTER TO DeviceNode;             (* used for accessing device nodes *)
  42. fssm       : POINTER TO FileSysStartupMsg;      (* used to access the filesystemstartupmessage *)  
  43. dosenvptr  : POINTER TO DOSenv;
  44.  
  45. nameptr    : strptr;
  46. cptr       : POINTER TO CHAR;
  47. p          : CARDINAL;
  48.  
  49.  
  50.  
  51. PROCEDURE WriteBSTR(b:BPTR);
  52. (* output a BSTR *)
  53. VAR
  54. nptr : strptr;
  55. c    : CARDINAL;
  56. BEGIN
  57. nptr:=PtrFromBPTR(b);
  58. IF nptr^[0]>=CHR(1) THEN
  59.    FOR c:=1 TO ORD(nptr^[0]) DO
  60.        Write(nptr^[c]);
  61.    END;
  62. END;
  63. END WriteBSTR;
  64.  
  65.  
  66. BEGIN
  67.  
  68. DOSBase:=OpenLibrary(DOSName,0);   
  69. (* open the dos lib *)
  70.  
  71. WriteString("listdevs v1.2 By John Davis 6/90");
  72. WriteLn;
  73.  
  74. ourdosbase:=DOSBase;                              
  75. (* get a usable pointer onto dosbase *)
  76.  
  77. infoptr:=PtrFromBPTR(ourdosbase^.dlRoot^.rnInfo); 
  78. (* get pointer to dosinfo struct *)
  79.  
  80. devlistptr:=PtrFromBPTR(infoptr^.diDevInfo);      
  81. (* get a pointer to start of devlist *)
  82.  
  83. WHILE devlistptr<>NULL DO
  84.       (* scan down device list checking as we go *)
  85.           
  86.       (* print out the device name *)
  87.       WriteString("node name : ");
  88.       WriteBSTR(devlistptr^.dlName);
  89.       WriteLn;
  90.       
  91.       Write(CHR(9));
  92.       
  93.       (* determine the nodes type and display it *)
  94.       IF devlistptr^.dlType=0 THEN
  95.          WriteString("Type         : DEV ");
  96.          WriteLn;
  97.       ELSIF devlistptr^.dlType=1 THEN
  98.          WriteString("Type         : DIR ");
  99.          WriteLn;
  100.       ELSIF devlistptr^.dlType=2 THEN
  101.          WriteString("Type         : VOL ");
  102.          WriteLn;
  103.       ELSE
  104.          WriteString("Type         : ??? ");
  105.          WriteLn;
  106.       END;
  107.          
  108.       (* I'm primarily interested in devices,  
  109.              VOLUMES are simply currently mounted disks
  110.              DIRS are assigned logical drives ( such as fonts: )
  111.       *)
  112.  
  113.       IF devlistptr^.dlType=0 THEN
  114.          (* node is a device node, extract extra info *)
  115.         
  116.          devnodeptr:=ADDRESS(devlistptr);          
  117.          (* transform to right type *)
  118.           
  119.          fssm:=PtrFromBPTR(devnodeptr^.dnStartup); 
  120.          (* get pointer to filesystemstartup block *)
  121.          
  122.          dosenvptr:=PtrFromBPTR(fssm^.fssmEnviron);
  123.          (* get pointer into enviroment block *)
  124.                   
  125.          (* if there's no fssm the fssmptr _should_ be null, but this
  126.             doesn't seem to be always true ( espec on par, prt and ser )
  127.             so check to see if the dosenv[de_tablesize] makes sense also
  128.          *)
  129.          IF (fssm<>NULL) AND (dosenvptr^[0]<=16) THEN
  130.  
  131.             (* printout host device for this dev *)
  132.             Write(CHR(9));
  133.             WriteString("Device       : ");
  134.             WriteBSTR(fssm^.fssmDevice);
  135.             WriteLn;
  136.  
  137.             (* and the host devices unit *)
  138.             Write(CHR(9));
  139.             WriteString("Unit         : ");
  140.             WriteLongCard(fssm^.fssmUnit,8);
  141.             WriteLn;
  142.             
  143.             (* now probe the enivroment space *)
  144.            
  145.             FOR p:=0 TO SHORT(dosenvptr^[0]) DO
  146.                 Write(CHR(9));
  147.                 
  148.                 CASE p OF
  149.                    0:  WriteString("env size     : "); |
  150.                    1:  WriteString("block size   : "); |
  151.                    2:  WriteString("SecOrg       : "); |
  152.                    3:  WriteString("Num Heads    : "); |
  153.                    4:  WriteString("Sec / Blk    : "); |
  154.                    5:  WriteString("blks / track : "); |
  155.                    6:  WriteString("reserved     : "); |
  156.                    7:  WriteString("prefac       : "); |
  157.                    8:  WriteString("Interleave   : "); |
  158.                    9:  WriteString("Low Cyl      : "); |
  159.                   10:  WriteString("High Cyl     : "); |
  160.                   11:  WriteString("Buffers      : "); |
  161.                   12:  WriteString("bufmemtype   : "); |
  162.                   13:  WriteString("Maxtransfer  : "); |
  163.                   14:  WriteString("Mask         : "); |
  164.                   15:  WriteString("bootpri      : "); |
  165.                   16:  WriteString("DOStype      : ");
  166.                 END;
  167.          
  168.                 IF p<>16 THEN
  169.                    WriteLongCard(dosenvptr^[p],8);
  170.                 ELSE
  171.                    WriteLongHex(dosenvptr^[p],16);
  172.                 END;
  173.          
  174.                 WriteLn;
  175.             END;         
  176.          END;
  177.          
  178.          (* display the taskpri of the device handler *)
  179.          Write(CHR(9));
  180.          WriteString("Pri          : ");
  181.          WriteLongInt(devnodeptr^.dnPriority,8);
  182.          WriteLn;
  183.  
  184.          (* and the amunt of stack for that task *)
  185.          Write(CHR(9));
  186.          WriteString("Stack        : ");
  187.          WriteLongCard(devnodeptr^.dnStackSize,8);
  188.          WriteLn;
  189.          
  190.          (* print out the name of the handler *)
  191.          Write(CHR(9));
  192.          WriteString("Handler      : ");
  193.          cptr:=PtrFromBPTR(devnodeptr^.dnHandler);
  194.          IF cptr^ = CHR(0) THEN
  195.             WriteString(" default dos handler");
  196.          ELSE
  197.             WriteBSTR(devnodeptr^.dnHandler);
  198.          END;
  199.          WriteLn;
  200.                
  201.       END; (* device case *)
  202.  
  203.       (* I don't bother extracting any info from VOLUMES|DIRS
  204.          there's not much of interest in there anyway
  205.       *)
  206.     
  207.       WriteLn;
  208.       
  209.       devlistptr:=PtrFromBPTR(devlistptr^.dlNext); 
  210.       (* scan on down devlist *)
  211. END;
  212.  
  213.  
  214. CloseLibrary(DOSBase);
  215.  
  216. END lister.
  217.