1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
27 #include "diskimage_device.h"
29 static struct DiskImageUnit
*FindUnit (struct DiskImageBase
*libBase
, ULONG unit_num
) {
30 struct DiskImageUnit
*unit
;
31 unit
= (struct DiskImageUnit
*)libBase
->Units
->lh_Head
;
32 while (unit
->Node
.ln_Succ
) {
33 if (unit
->UnitNum
== unit_num
) {
36 unit
= (struct DiskImageUnit
*)unit
->Node
.ln_Succ
;
41 static LONG
Internal_UnitControl (ULONG unit_num
, struct TagItem
*tags
, struct DiskImageBase
*libBase
) {
42 struct Library
*SysBase
= libBase
->SysBase
;
43 struct DiskImageUnit
*unit
;
44 struct DiskImageMsg
*msg
;
45 struct MsgPort
*replyport
, *port
;
47 ObtainSemaphoreShared(libBase
->UnitSemaphore
);
48 unit
= FindUnit(libBase
, unit_num
);
50 ReleaseSemaphore(libBase
->UnitSemaphore
);
51 return ERROR_BAD_NUMBER
;
54 ObtainSemaphore(unit
->MsgSemaphore
);
55 replyport
= unit
->ReplyPort
;
57 msg
= unit
->DiskImageMsg
;
59 replyport
->mp_SigTask
= FindTask(NULL
);
60 replyport
->mp_Flags
= PA_SIGNAL
;
61 msg
->dim_Command
= DICMD_TAGLIST
;
64 PutMsg(port
, &msg
->dim_Msg
);
68 replyport
->mp_Flags
= PA_IGNORE
;
69 replyport
->mp_SigTask
= NULL
;
71 ReleaseSemaphore(unit
->MsgSemaphore
);
72 ReleaseSemaphore(libBase
->UnitSemaphore
);
78 AROS_LH2(LONG
, MountImage
,
79 AROS_LHA(ULONG
, unit_num
, D0
),
80 AROS_LHA(CONST_STRPTR
, filename
, A0
),
81 struct DiskImageBase
*, libBase
, 7, DiskImage
86 LONG
MountImage (REG(d0
, ULONG unit_num
), REG(a0
, CONST_STRPTR filename
),
87 REG(a6
, struct DiskImageBase
*libBase
))
90 LONG error
= NO_ERROR
;
92 struct TagItem tags
[4];
93 tags
[0].ti_Tag
= DITAG_Error
;
94 tags
[0].ti_Data
= (IPTR
)&error
;
95 tags
[1].ti_Tag
= DITAG_CurrentDir
;
96 tags
[1].ti_Data
= (IPTR
)GetCurrentDir();
97 tags
[2].ti_Tag
= DITAG_Filename
;
98 tags
[2].ti_Data
= (IPTR
)filename
;
99 tags
[3].ti_Tag
= TAG_END
;
100 error2
= Internal_UnitControl(unit_num
, tags
, libBase
);
101 return error
? error
: error2
;
108 AROS_LH3(LONG
, UnitInfo
,
109 AROS_LHA(ULONG
, unit_num
, D0
),
110 AROS_LHA(STRPTR
*, filename
, A0
),
111 AROS_LHA(BOOL
*, writeprotect
, A1
),
112 struct DiskImageBase
*, libBase
, 8, DiskImage
117 LONG
UnitInfo (REG(d0
, ULONG unit_num
), REG(a0
, STRPTR
*filename
), REG(a1
, BOOL
*writeprotect
),
118 REG(a6
, struct DiskImageBase
*libBase
))
121 LONG error
= NO_ERROR
;
123 struct TagItem tags
[4];
124 tags
[0].ti_Tag
= DITAG_Error
;
125 tags
[0].ti_Data
= (IPTR
)&error
;
126 tags
[1].ti_Tag
= DITAG_GetImageName
;
127 tags
[1].ti_Data
= (IPTR
)filename
;
128 tags
[2].ti_Tag
= DITAG_GetWriteProtect
;
129 tags
[2].ti_Data
= (IPTR
)writeprotect
;
130 tags
[3].ti_Tag
= TAG_END
;
131 error2
= Internal_UnitControl(unit_num
, tags
, libBase
);
132 return error
? error
: error2
;
139 AROS_LH2(LONG
, WriteProtect
,
140 AROS_LHA(ULONG
, unit_num
, D0
),
141 AROS_LHA(BOOL
, writeprotect
, D1
),
142 struct DiskImageBase
*, libBase
, 9, DiskImage
147 LONG
WriteProtect (REG(d0
, ULONG unit_num
), REG(d1
, BOOL writeprotect
),
148 REG(a6
, struct DiskImageBase
*libBase
))
151 LONG error
= NO_ERROR
;
153 struct TagItem tags
[3];
154 tags
[0].ti_Tag
= DITAG_Error
;
155 tags
[0].ti_Data
= (IPTR
)&error
;
156 tags
[1].ti_Tag
= DITAG_WriteProtect
;
157 tags
[1].ti_Data
= writeprotect
;
158 tags
[2].ti_Tag
= TAG_END
;
159 error2
= Internal_UnitControl(unit_num
, tags
, libBase
);
160 return error
? error
: error2
;
167 AROS_LH2(LONG
, UnitControlA
,
168 AROS_LHA(ULONG
, unit_num
, D0
),
169 AROS_LHA(struct TagItem
*, tags
, A0
),
170 struct DiskImageBase
*, libBase
, 10, DiskImage
175 LONG
UnitControlA (REG(d0
, ULONG unit_num
), REG(a0
, struct TagItem
*tags
),
176 REG(a6
, struct DiskImageBase
*libBase
))
179 return Internal_UnitControl(unit_num
, tags
, libBase
);
185 static const struct TagItem unmount_tags
[] = {
186 { DITAG_Filename
, (IPTR
)NULL
},
191 AROS_LH0(LONG
, ReloadPlugins
,
192 struct DiskImageBase
*, libBase
, 11, DiskImage
197 LONG
ReloadPlugins (REG(a6
, struct DiskImageBase
*libBase
)) {
199 struct Library
*SysBase
= libBase
->SysBase
;
200 struct Library
*UtilityBase
= libBase
->UtilityBase
;
201 struct MsgPort
*replyport
, *port
;
202 struct DiskImageMsg
*msg
;
203 struct DiskImageUnit
*unit
;
206 ObtainSemaphore(libBase
->UnitSemaphore
);
208 /* Unmount all units */
209 unit
= (struct DiskImageUnit
*)libBase
->Units
->lh_Head
;
210 while (unit
->Node
.ln_Succ
) {
211 ObtainSemaphore(unit
->MsgSemaphore
);
213 replyport
= unit
->ReplyPort
;
214 port
= unit
->MsgPort
;
215 msg
= unit
->DiskImageMsg
;
217 replyport
->mp_SigTask
= FindTask(NULL
);
218 replyport
->mp_Flags
= PA_SIGNAL
;
219 msg
->dim_Command
= DICMD_TAGLIST
;
220 msg
->dim_Tags
= unmount_tags
;
222 PutMsg(port
, &msg
->dim_Msg
);
226 ReleaseSemaphore(unit
->MsgSemaphore
);
228 unit
= (struct DiskImageUnit
*)unit
->Node
.ln_Succ
;
231 ObtainSemaphore(libBase
->PluginSemaphore
);
232 FreePlugins(libBase
);
233 LoadPlugins(libBase
);
234 hook
= (struct Hook
*)libBase
->ReloadPluginsHooks
->lh_Head
;
235 while (hook
->h_MinNode
.mln_Succ
) {
236 CallHookPkt(hook
, SysBase
, hook
->h_Data
);
237 hook
= (struct Hook
*)hook
->h_MinNode
.mln_Succ
;
239 ReleaseSemaphore(libBase
->PluginSemaphore
);
241 ReleaseSemaphore(libBase
->UnitSemaphore
);
250 AROS_LH1(void, DoHookPlugins
,
251 AROS_LHA(struct Hook
*, hook
, A0
),
252 struct DiskImageBase
*, libBase
, 12, DiskImage
257 void DoHookPlugins (REG(a0
, struct Hook
*hook
), REG(a6
, struct DiskImageBase
*libBase
)) {
259 struct Library
*SysBase
= libBase
->SysBase
;
260 struct Library
*UtilityBase
= libBase
->UtilityBase
;
263 ObtainSemaphoreShared(libBase
->PluginSemaphore
);
264 plugin
= libBase
->Plugins
->lh_Head
;
265 while (plugin
->ln_Succ
) {
266 CallHookPkt(hook
, plugin
, hook
->h_Data
);
267 plugin
= plugin
->ln_Succ
;
269 ReleaseSemaphore(libBase
->PluginSemaphore
);
276 AROS_LH2(void, AddDiskChangeHook
,
277 AROS_LHA(struct Hook
*, hook
, A0
),
278 AROS_LHA(BOOL
, add_or_remove
, D0
),
279 struct DiskImageBase
*, libBase
, 13, DiskImage
284 void AddDiskChangeHook (REG(a0
, struct Hook
*hook
), REG(d0
, BOOL add_or_remove
),
285 REG(a6
, struct DiskImageBase
*libBase
))
288 struct Library
*SysBase
= libBase
->SysBase
;
290 ObtainSemaphore(libBase
->DiskChangeSemaphore
);
292 AddTail(libBase
->DiskChangeHooks
, (struct Node
*)hook
);
294 Remove((struct Node
*)hook
);
296 ReleaseSemaphore(libBase
->DiskChangeSemaphore
);
303 AROS_LH2(void, AddReloadPluginsHook
,
304 AROS_LHA(struct Hook
*, hook
, A0
),
305 AROS_LHA(BOOL
, add_or_remove
, D0
),
306 struct DiskImageBase
*, libBase
, 14, DiskImage
311 void AddReloadPluginsHook (REG(a0
, struct Hook
*hook
), REG(d0
, BOOL add_or_remove
),
312 REG(a6
, struct DiskImageBase
*libBase
))
315 struct Library
*SysBase
= libBase
->SysBase
;
317 ObtainSemaphore(libBase
->PluginSemaphore
);
319 AddTail(libBase
->ReloadPluginsHooks
, (struct Node
*)hook
);
321 Remove((struct Node
*)hook
);
323 ReleaseSemaphore(libBase
->PluginSemaphore
);