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

  1. MODULE zapper;
  2.  
  3. (* zap DH0 device node name     *)
  4. (* by J Davis v1.3 26 6/90      *)
  5. (* compiled using TDI m-2 3.01a *)
  6.  
  7.  
  8. (*
  9.   this is an attempt to get around the problem with 2090's where
  10.   the first partition MUST be OFS and is called DH0. This is a real
  11.   problem when you have a main FFS partition, on which you have all
  12.   your programs etc, and programs that insist on using DH0
  13.  
  14.    This program zaps the DH0 node name so as it is called ZH0.
  15.    this is _extremely_ grungy, illegal etc ... but if it works
  16.    then it is a good way to cure the problem.
  17. *)
  18.  
  19. (* v1.1 changes 
  20.    cleaned up screen output
  21.    now also renames df2: -> df1: for people like me who have
  22.    one internal and one external floppy drive
  23. *)
  24.  
  25. (* v1.2 changes 
  26.         only renames df2: -> df1: if no df1: present already
  27.         gets around nastiness if you have 2 internals and an external :-)
  28. *)
  29.  
  30. (* v1.3 changes
  31.         changed strategy on df2:, now clones the device node, links it
  32.         back into the device list and renames the clone
  33. *)
  34.  
  35. FROM Memory          IMPORT AllocMem,MemReqSet,MemPublic,MemClear;
  36. FROM DOSLibrary      IMPORT DOSName,DOSBase,BPTR,BSTR;
  37. FROM DOSExtensions   IMPORT DosBaseRec,RootNode,DosInfo,DeviceList;
  38. FROM AmigaUtils      IMPORT PtrFromBPTR,BPTRFromPtr;
  39. FROM SYSTEM          IMPORT NULL;
  40. FROM InOut           IMPORT WriteString,WriteLn;
  41. FROM Libraries       IMPORT OpenLibrary,CloseLibrary;
  42. FROM DOSLibrary      IMPORT DateStampRec;
  43. FROM SYSTEM          IMPORT TSIZE;
  44.  
  45. TYPE 
  46.  
  47. string = ARRAY [0..255] OF CHAR;
  48. strptr = POINTER TO string;
  49.  
  50.  
  51. VAR
  52.  
  53. ourdosbase : POINTER TO DosBaseRec; (* use this to access dosbase *)
  54. infoptr    : POINTER TO DosInfo;    (* points to DOSinfo node     *)
  55. devlistptr : POINTER TO DeviceList; (* points to current place is DOS devlist *)
  56. nameptr    : strptr;
  57. df1present : BOOLEAN;               (* flag to indicate df1: is already mounted *)
  58. cloneptr   : POINTER TO DeviceList; (* for cloning operation *)
  59.  
  60. BEGIN
  61.  
  62. DOSBase:=OpenLibrary(DOSName,0);   (* open the dos lib *)
  63.  
  64. WriteString("ZAPDh0 v1.3 By John Davis 6/90");
  65. WriteLn;
  66.  
  67. ourdosbase:=DOSBase;                              
  68. (* get a usable pointer onto dosbase *)
  69.  
  70. infoptr:=PtrFromBPTR(ourdosbase^.dlRoot^.rnInfo); 
  71. (* get pointer dosinfo struct *)
  72.  
  73. devlistptr:=PtrFromBPTR(infoptr^.diDevInfo);      
  74. (* get a pointer to start of devlist *)
  75.  
  76. df1present:=FALSE;                                
  77. (* initially assume df1: is not present *)
  78.  
  79. WHILE devlistptr<>NULL DO
  80.       (* scan down device list checking as we go *)
  81.           
  82.       nameptr:=PtrFromBPTR(BPTR(devlistptr^.dlName));
  83.       (* get pointer to nodename *)
  84.  
  85.       IF (nameptr^[1]='D') AND (nameptr^[2]='H') AND (nameptr^[3]='0') THEN
  86.          (* this is dh0 so zap it *)
  87.          WriteString("   renamed DH0: to ZH0: ");
  88.          WriteLn;
  89.          nameptr^[1]:='Z'; (* we'll make it be called zh0: instead *)
  90.       END;
  91.       
  92.       IF (nameptr^[1]='D') AND (nameptr^[2]='F') AND (nameptr^[3]='1') THEN
  93.          (* found an existing df1 .. set flag so as not to try rename of df2 *)
  94.          WriteString("   found existing DF1:, will not attempt to rename DF2:");
  95.          WriteLn;
  96.          df1present:=TRUE;
  97.       END;
  98.       
  99.       devlistptr:=PtrFromBPTR(devlistptr^.dlNext); 
  100.       (* scan on down devlist *)
  101. END;
  102.  
  103. IF NOT df1present THEN 
  104.    (* didn't find df1:, see if we can find df2 
  105.       go back to start of devlist and re-scan
  106.    *)
  107.  
  108.    devlistptr:=PtrFromBPTR(infoptr^.diDevInfo); 
  109.    (* get a pointer to the start of the devlist *)
  110.  
  111.    WHILE devlistptr<>NULL DO
  112.          (* scan down device list checking as we go *)
  113.           
  114.          nameptr:=PtrFromBPTR(BPTR(devlistptr^.dlName));
  115.          
  116.          IF (nameptr^[1]='D') AND (nameptr^[2]='F') AND (nameptr^[3]='2') THEN 
  117.             (* this is df2:,so clone it *)
  118.   
  119.              WriteString("   found df2:, creating clone as df1:");
  120.              WriteLn;
  121.       
  122.              cloneptr:=AllocMem(TSIZE(DeviceList),MemReqSet{MemPublic,MemClear});
  123.             
  124.              (* first link in our clone on the devlist *)
  125.              cloneptr^.dlNext   :=devlistptr^.dlNext;
  126.              devlistptr^.dlNext :=BPTRFromPtr(cloneptr);
  127.             
  128.              (* now copy the rest of the df2 struct over *)
  129.              cloneptr^.dlType       :=devlistptr^.dlType;
  130.              cloneptr^.dlTask       :=devlistptr^.dlTask;
  131.              cloneptr^.dlLock       :=devlistptr^.dlLock;
  132.              cloneptr^.dlVolumeDate :=devlistptr^.dlVolumeDate;
  133.              cloneptr^.dlLockList   :=devlistptr^.dlLockList;
  134.              cloneptr^.dlDiskType   :=devlistptr^.dlDiskType;
  135.              cloneptr^.dlunused     :=devlistptr^.dlunused;
  136.       
  137.       
  138.              (* now alter the name of the clone to be df1: *)
  139.              nameptr:=AllocMem(4,MemReqSet{MemPublic,MemClear});
  140.              cloneptr^.dlName:=BPTRFromPtr(nameptr);
  141.       
  142.              (* now put BSTR 'df1'into name *)
  143.              nameptr^[0]:=CHR(3);
  144.              nameptr^[1]:='D';
  145.              nameptr^[2]:='F';
  146.              nameptr^[3]:='1';
  147.     
  148.          END; (* found df2 if *)
  149.        
  150.          devlistptr:=PtrFromBPTR(devlistptr^.dlNext); 
  151.          (* scan on down devlist *)
  152.  
  153.     END; (* while *)
  154.  
  155. END; (* if not found df1 *)
  156.  
  157. CloseLibrary(DOSBase);
  158.  
  159. END zapper.
  160.