Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / diskimage / device / io.c
blob562e4e3c0c197a1f9736a9c524f164b4c42b74ad
1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
2 **
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
5 ** are met:
6 **
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
9 **
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[] = {
30 NSCMD_DEVICEQUERY,
31 CMD_UPDATE,
32 CMD_CLEAR,
33 TD_MOTOR,
34 CMD_READ,
35 CMD_WRITE,
36 TD_FORMAT,
37 ETD_READ,
38 ETD_WRITE,
39 ETD_FORMAT,
40 TD_CHANGENUM,
41 TD_CHANGESTATE,
42 TD_PROTSTATUS,
43 TD_GETGEOMETRY,
44 TD_EJECT,
45 TD_REMOVE,
46 TD_ADDCHANGEINT,
47 TD_REMCHANGEINT,
48 TD_READ64,
49 TD_WRITE64,
50 TD_FORMAT64,
51 NSCMD_TD_READ64,
52 NSCMD_TD_WRITE64,
53 NSCMD_TD_FORMAT64,
54 NSCMD_ETD_READ64,
55 NSCMD_ETD_WRITE64,
56 NSCMD_ETD_FORMAT64,
57 HD_SCSICMD,
61 #ifdef __AROS__
62 AROS_LH1(void, LibBeginIO,
63 AROS_LHA(struct IOExtTD *, iotd, A1),
64 struct DiskImageBase *, libBase, 5, DiskImage
67 AROS_LIBFUNC_INIT
68 #else
69 void LibBeginIO (REG(a1, struct IOExtTD *iotd), REG(a6, struct DiskImageBase *libBase)) {
70 #endif
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",
78 unit->UnitNum,
79 iotd->iotd_Req.io_Command));
81 switch (iotd->iotd_Req.io_Command) {
82 case CMD_READ:
83 case CMD_WRITE:
84 case TD_FORMAT:
85 case ETD_READ:
86 case ETD_WRITE:
87 case ETD_FORMAT:
88 case TD_GETGEOMETRY:
89 case TD_EJECT:
90 case TD_REMOVE:
91 case TD_ADDCHANGEINT:
92 case TD_REMCHANGEINT:
93 case TD_READ64:
94 case TD_WRITE64:
95 case TD_FORMAT64:
96 case NSCMD_TD_READ64:
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:
102 case HD_SCSICMD:
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);
108 return;
110 case CMD_UPDATE:
111 case CMD_CLEAR:
112 case TD_MOTOR:
113 /* handle as no-ops */
114 iotd->iotd_Req.io_Error = IOERR_SUCCESS;
115 break;
117 case TD_CHANGENUM:
118 iotd->iotd_Req.io_Actual = unit->ChangeCnt;
119 iotd->iotd_Req.io_Error = IOERR_SUCCESS;
120 break;
122 case TD_CHANGESTATE:
123 iotd->iotd_Req.io_Actual = unit->ImageData ? 0 : 1;
124 iotd->iotd_Req.io_Error = IOERR_SUCCESS;
125 break;
127 case TD_PROTSTATUS:
128 iotd->iotd_Req.io_Actual = unit->WriteProtect;
129 iotd->iotd_Req.io_Error = IOERR_SUCCESS;
130 break;
132 case NSCMD_DEVICEQUERY:
133 if (iotd->iotd_Req.io_Length < sizeof(struct NSDeviceQueryResult)) {
134 iotd->iotd_Req.io_Error = IOERR_BADLENGTH;
135 } else {
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;
146 break;
148 default:
149 /* not supported */
150 iotd->iotd_Req.io_Error = IOERR_NOCMD;
151 break;
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);
158 #ifdef __AROS__
159 AROS_LIBFUNC_EXIT
160 #endif
163 #ifdef __AROS__
164 AROS_LH1(LONG, LibAbortIO,
165 AROS_LHA(struct IOStdReq *, which_io, A1),
166 struct DiskImageBase *, libBase, 6, DiskImage
169 AROS_LIBFUNC_INIT
170 #else
171 LONG LibAbortIO (REG(a1, struct IOStdReq *which_io), REG(a6, struct DiskImageBase *libBase)) {
172 #endif
173 struct Library *SysBase = libBase->SysBase;
174 struct DiskImageUnit *unit;
175 struct IOStdReq *io;
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
182 processed */
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);
190 io->io_Actual = 0;
191 error = io->io_Error = IOERR_ABORTED;
193 /* reply the message, as usual */
194 ReplyMsg(&io->io_Message);
195 break;
197 io = (struct IOStdReq *)io->io_Message.mn_Node.ln_Succ;
200 ReleaseSemaphore(unit->IOSemaphore);
202 return error;
203 #ifdef __AROS__
204 AROS_LIBFUNC_EXIT
205 #endif