2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Lock - Set the write protect status of a device.
9 /**************************************************************************
15 Lock <drive> [ON|OFF] [<passkey>]
18 DRIVE/A,ON/S,OFF/S,PASSKEY
24 Lock will cause the specified device or partition to be made write-
25 protected or write-enabled. This write protection is a soft write
26 protection which is handled by the volume filesystem. Hence the
27 protection will be reset (to writable) on the next system reboot.
29 It is possible to specify an optional passkey which can be used to
30 password protect the locking. The same passkey that is used to lock
31 the volume must be used to unlock the volume. The passkey may be
32 any number of characters in length.
34 The volume given MUST be the device or root volume name, not an
41 This will lock the volume called Work: without a passkey.
44 1.SYS:> MakeDir Work:SomeDir
45 Can't create directory Work:Test
46 MakeDir: Disk is write-protected
48 The volume Work: is locked, so it is impossible to create a
51 1.SYS:> Lock Work: OFF
53 This will unlock the volume work.
55 1.SYS:> Lock Work: MyPassword
57 This will lock Work: with the passkey "MyPassword"
59 **************************************************************************/
61 #include <exec/types.h>
62 #include <exec/memory.h>
63 #include <dos/dosextens.h>
64 #include <dos/filesystem.h>
65 #include <dos/rdargs.h>
66 #include <proto/exec.h>
67 #include <proto/dos.h>
68 #include <utility/tagitem.h>
70 #define ARG_TEMPLATE "DRIVE/A,ON/S,OFF/S,PASSKEY"
77 const TEXT version
[] = "$VER: Lock 41.2 (16.1.1999)";
78 static const char exthelp
[] =
79 "Lock : Set the write-protect state of a volume\n"
80 "\tDRIVE/A The name of the volume to lock\n"
81 "\tON/S Turn write protect on\n"
82 "\tOFF/S Turn write protect off\n"
83 "\tPASSKEY The password string for the lock (optional)\n";
85 int lockDevice(struct IOFileSys
*iofs
, STRPTR key
)
87 if( iofs
->io_Union
.io_MOUNT_MODE
.io_MountMode
& MMF_LOCKED
)
89 /* We are already locked? What do we do? */
90 return ERROR_DISK_WRITE_PROTECTED
;
92 iofs
->io_Union
.io_MOUNT_MODE
.io_MountMode
= MMF_LOCKED
;
93 iofs
->io_Union
.io_MOUNT_MODE
.io_Mask
= MMF_LOCKED
;
94 iofs
->io_Union
.io_MOUNT_MODE
.io_Password
= key
;
96 DoIO((struct IORequest
*)iofs
);
97 return iofs
->io_DosError
;
100 int unlockDevice(struct IOFileSys
*iofs
, STRPTR key
)
102 if(!(iofs
->io_Union
.io_MOUNT_MODE
.io_MountMode
& MMF_LOCKED
))
104 /* We are not locked, so lets return success. */
107 /* We are locked, lets try and unlock it */
108 iofs
->io_Union
.io_MOUNT_MODE
.io_MountMode
= 0;
109 iofs
->io_Union
.io_MOUNT_MODE
.io_Mask
= MMF_LOCKED
;
110 iofs
->io_Union
.io_MOUNT_MODE
.io_Password
= key
;
112 DoIO((struct IORequest
*)iofs
);
113 return iofs
->io_DosError
;
120 struct Process
*pr
= (struct Process
*)FindTask(NULL
);
121 struct RDArgs
*rd
, *rda
= NULL
;
122 IPTR args
[TOTAL_ARGS
] = { NULL
, FALSE
, FALSE
, NULL
};
123 struct IOFileSys
*iofs
;
127 if((rda
= AllocDosObject(DOS_RDARGS
, NULL
)))
129 rda
->RDA_ExtHelp
= (STRPTR
)exthelp
;
130 if((rd
= ReadArgs(ARG_TEMPLATE
, args
, NULL
)))
132 /* Firstly, find out the volume */
133 dp
= GetDeviceProc((STRPTR
)args
[ARG_DRIVE
], NULL
);
135 if( dp
== NULL
|| dp
->dvp_DevNode
== NULL
136 || ( dp
->dvp_DevNode
->dol_Type
!= DLT_DEVICE
137 && dp
->dvp_DevNode
->dol_Type
!= DLT_VOLUME
)
141 error
= ERROR_OBJECT_WRONG_TYPE
;
148 It is a real volume, not an assign...
149 We send the device a I/O request.
151 iofs
= (struct IOFileSys
*)CreateIORequest(
152 &pr
->pr_MsgPort
, sizeof(struct IOFileSys
)
156 /* First of find out current state. */
157 iofs
->io_Union
.io_MOUNT_MODE
.io_Mask
= 0;
158 iofs
->IOFS
.io_Device
= (struct Device
*)dp
->dvp_Port
;
159 iofs
->IOFS
.io_Command
= FSA_MOUNT_MODE
;
161 DoIO((struct IORequest
*)iofs
);
162 if (args
[ARG_ON
] && args
[ARG_OFF
])
165 error
= ERROR_TOO_MANY_ARGS
;
167 else if (args
[ARG_OFF
])
169 error
= unlockDevice(iofs
, (STRPTR
)args
[ARG_PASSKEY
]);
173 error
= lockDevice(iofs
, (STRPTR
)args
[ARG_PASSKEY
]);
175 DeleteIORequest((struct IORequest
*)iofs
);
179 error
= ERROR_NO_FREE_STORE
;
186 } /* if( ReadArgs() ) */
190 FreeDosObject(DOS_RDARGS
, rda
);
191 } /* if( AllocDosObject() ) */
193 error
= ERROR_NO_FREE_STORE
;
197 PrintFault(error
, "Lock");