home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.pascal.borland      Borland Pascal was actually pretty neat      2,978 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 1,152 of 2,978   
   Samuel Fleischer to All   
   Re: Disk-Write-Protection-Check   
   03 Dec 04 16:31:50   
   
   From: LiveSucks@hotmail.com   
      
   I wrote:   
   > Is it posible to create a routine in Borland Pascal 7   
   > (- DOS/Real-platform but apps should also run under Win   
   > in a DOS-shell -) which detects if this little switch   
   > on the cover of a floppy is in write-protect-position   
   > or not, even when the disk is unformatted or has a   
   > corrupted surface?   
      
   Meanwhile I found a snippet but as my assembler-skills   
   are not the best, I cannot get it to work - all disks are   
   recognized as "write-protected". Where is the error/how   
   can this be fixed?   
      
   Function DiskProtected(drive:Byte):Boolean;   
   BEGIN   
     {Issue a disk-reset to the desired drive (let us say drive 0).   
      You do this by issuing interrupt 13h with AL = 0 and DL =   
      drive (0 as we assumed).   
     }   
     ASM   
       mov ah,00;   
       mov dl,Byte Ptr Drive; { 0= A:, 1= B: ect }   
       int $13;   
     {Then try to read the first sector of the disk: int13h, ah=2,   
      al=number of sectors (1), ch=track number (0), cl=sector_number   
      (1, i.e. the first sector on track), dh=head (0), dl=drive (0),   
      ES:BX contains the address of the 512-byte destination buffer (i.e.   
      the size of disk sector).   
     }   
       mov ah,02;   
       mov al,01;   
       mov ch,00;   
       mov cl,01;   
       mov dh,00;   
       mov dl,Byte Ptr Drive; { 0= A:, 1= B: ect }   
       int $13;   
     {If the disk has been recently changed, the first read will always   
      fail. That's why you must repeat the disk_reset -operation ...   
     }   
       mov ah,00;   
       mov dl,Byte Ptr Drive; { 0= A:, 1= B: ect }   
       int $13;   
     {...and try to read again.   
     }   
       mov ah,02;   
       mov al,01;   
       mov ch,00;   
       mov cl,01;   
       mov dh,00;   
       mov dl,Byte Ptr Drive; { 0= A:, 1= B: ect }   
       int $13;   
     {Now, if you return from BIOS with carry set, ah will contain the   
      error code, which most often is one of the following:   
      06h  : disk has been removed (and put back) since the last   
             BIOS-operation   
      80h  : disk time out (i.e. no disk in drive)   
      If you want to detect whether the disk is write protected, you must   
      try to write into disk.  If the previous read-operation was   
      successful, you have a valid copy of the first sector of the disk.   
      Now you can safely try to rewrite it back into disk!   
      Issue int13h with ah=3, al=number of sectors (1), ch=track (0),   
      cl=sector number (1), dh=head (0), dl=drive (0), ES:BX = address of   
      your buffer where the data is located.   
      If your disk is write protected, you return from BIOS with carry set   
      and the errorcode in ah is 03h!   
     }   
         mov ah,03;   
         mov al,01;   
         mov ch,00;   
         mov cl,01;   
         mov dh,00;   
         mov dl,Byte Ptr Drive; { 0= A:, 1= B: ect }   
         int $13;   
         cmp Ah,03;   
         jne @No;   
         mov al,true;   
         je @done;   
       @No:   
         cmp al, al;   
       @Done:   
     END;   
   END;   
      
   { Example: }   
      
   BEGIN   
     if Diskprotected(0) Then Write(' Write protect was used on last operation');   
   END.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca