Procedure CheckDiskProtection()

AmigaOS specific forum
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.

Hi,

here a little procedure which tests if the given drive is writeprotected.
To avoid an upcoming "Please insert volume ..." requester you can use the
procedure ExistDiskDrive() before. This will check if the drive is available.
After that you can use ExistDisk() to check if a disk is inserted in the drive.

This procedure also works with harddisk (to test use the dos command 'Lock').

Parameter: the drive (e.g. "df0:" or "df1:" or "dh0:" etc).
Returns : TRUE (-1) if the disk is NOT writeprotected, FALSE (0) if writeprotected.

The procedure uses the dos functions Lock(), UnLock() and Info(), so the
dos.library must opened. Also a InitMemoryBank(0) at program start is needed,
because the procedure uses Bank 0.

Procedure.b CheckDiskProtection(drive$)
info.l=AllocateMemoryBank(0,36,#MEMF_FAST|#MEMF_CLEAR) ; some mem for the info structure
lock.l=Lock_(@drive$,-2) ; try to get a lock (to write=-2) at the drive
If lock ; we have the lock
Info_(lock,info) ; we need some info about the drive
UnLock_(lock) ; free what we get from the system
status.l=PeekL(info+8) ; read the state
If status=82 ; disk ok
ret.b=-1 ; we cab write to it -> return -1
Else
ret.b=0 : writeprotected -> return 0
EndIf
Else
ret.b=0
EndIf
FreeMemoryBank(0)
ProcedureReturn ret
EndProcedure

OpenDosLibrary_(36)
InitMemoryBank(0)

ok.b=CheckDiskProtection("df0:")
If ok=-1
PrintN("Disk is not writeprotected!")
Else
PrintN("Disk is writeprotected!")
EndIf
End


Greetings ..
Roxxler