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 const UWORD cmd_list
[] = {
62 AROS_LH1(void, LibBeginIO
,
63 AROS_LHA(struct IOExtTD
*, iotd
, A1
),
64 struct DiskImageBase
*, libBase
, 5, DiskImage
69 void LibBeginIO (REG(a1
, struct IOExtTD
*iotd
), REG(a6
, struct DiskImageBase
*libBase
)) {
71 struct Library
*SysBase
= libBase
->SysBase
;
72 struct DiskImageUnit
*unit
;
74 unit
= (struct DiskImageUnit
*)iotd
->iotd_Req
.io_Unit
;
76 dbug(("BeginIO()\n"));
77 dbug(("unit: %ld, command: %ld\n",
79 iotd
->iotd_Req
.io_Command
));
81 switch (iotd
->iotd_Req
.io_Command
) {
97 case NSCMD_TD_WRITE64
:
98 case NSCMD_TD_FORMAT64
:
99 case NSCMD_ETD_READ64
:
100 case NSCMD_ETD_WRITE64
:
101 case NSCMD_ETD_FORMAT64
:
103 /* forward to unit process */
104 iotd
->iotd_Req
.io_Flags
&= ~IOF_QUICK
;
105 ObtainSemaphore(unit
->IOSemaphore
);
106 PutMsg(unit
->IOPort
, &iotd
->iotd_Req
.io_Message
);
107 ReleaseSemaphore(unit
->IOSemaphore
);
113 /* handle as no-ops */
114 iotd
->iotd_Req
.io_Error
= IOERR_SUCCESS
;
118 iotd
->iotd_Req
.io_Actual
= unit
->ChangeCnt
;
119 iotd
->iotd_Req
.io_Error
= IOERR_SUCCESS
;
123 iotd
->iotd_Req
.io_Actual
= unit
->ImageData
? 0 : 1;
124 iotd
->iotd_Req
.io_Error
= IOERR_SUCCESS
;
128 iotd
->iotd_Req
.io_Actual
= unit
->WriteProtect
;
129 iotd
->iotd_Req
.io_Error
= IOERR_SUCCESS
;
132 case NSCMD_DEVICEQUERY
:
133 if (iotd
->iotd_Req
.io_Length
< sizeof(struct NSDeviceQueryResult
)) {
134 iotd
->iotd_Req
.io_Error
= IOERR_BADLENGTH
;
136 struct NSDeviceQueryResult
*dq
;
137 dq
= (struct NSDeviceQueryResult
*)iotd
->iotd_Req
.io_Data
;
138 dq
->DevQueryFormat
= 0;
139 iotd
->iotd_Req
.io_Actual
= dq
->SizeAvailable
=
140 sizeof(struct NSDeviceQueryResult
);
141 dq
->DeviceType
= NSDEVTYPE_TRACKDISK
;
142 dq
->DeviceSubType
= 0;
143 dq
->SupportedCommands
= (UWORD
*)cmd_list
;
144 iotd
->iotd_Req
.io_Error
= IOERR_SUCCESS
;
150 iotd
->iotd_Req
.io_Error
= IOERR_NOCMD
;
154 iotd
->iotd_Req
.io_Message
.mn_Node
.ln_Type
= NT_MESSAGE
;
156 if (!(iotd
->iotd_Req
.io_Flags
& IOF_QUICK
))
157 ReplyMsg(&iotd
->iotd_Req
.io_Message
);
164 AROS_LH1(LONG
, LibAbortIO
,
165 AROS_LHA(struct IOStdReq
*, which_io
, A1
),
166 struct DiskImageBase
*, libBase
, 6, DiskImage
171 LONG
LibAbortIO (REG(a1
, struct IOStdReq
*which_io
), REG(a6
, struct DiskImageBase
*libBase
)) {
173 struct Library
*SysBase
= libBase
->SysBase
;
174 struct DiskImageUnit
*unit
;
176 LONG error
= IOERR_SUCCESS
;
178 unit
= (struct DiskImageUnit
*)which_io
->io_Unit
;
179 ObtainSemaphore(unit
->IOSemaphore
);
181 /* Check if the request is still in the queue, waiting to be
184 io
= (struct IOStdReq
*)unit
->IOPort
->mp_MsgList
.lh_Head
;
185 while (io
->io_Message
.mn_Node
.ln_Succ
) {
186 if (io
== which_io
) {
187 /* remove it from the queue and tag it as aborted */
188 Remove(&io
->io_Message
.mn_Node
);
191 error
= io
->io_Error
= IOERR_ABORTED
;
193 /* reply the message, as usual */
194 ReplyMsg(&io
->io_Message
);
197 io
= (struct IOStdReq
*)io
->io_Message
.mn_Node
.ln_Succ
;
200 ReleaseSemaphore(unit
->IOSemaphore
);