2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
9 #include "dos_intern.h"
11 #include <dos/dosextens.h>
12 #include <intuition/intuition.h>
13 #include <exec/ports.h>
15 #include <aros/debug.h>
17 /*****************************************************************************
20 #include <proto/dos.h>
22 AROS_LH4(BOOL
, ErrorReport
,
25 AROS_LHA(LONG
, code
, D1
),
26 AROS_LHA(LONG
, type
, D2
),
27 AROS_LHA(IPTR
, arg1
, D3
),
28 AROS_LHA(struct MsgPort
*, device
, D4
),
31 struct DosLibrary
*, DOSBase
, 80, Dos
)
34 Displays a requester with Retry/Cancel buttons for an error.
35 IoErr() is set to "code".
39 code -- The error to put up the requester for
40 type -- Type of request
42 REPORT_LOCK -- arg1 is a lock (BPTR).
43 REPORT_FH -- arg1 is a filehandle (BPTR).
44 REPORT_VOLUME -- arg1 is a volumenode (C pointer).
45 REPORT_INSERT -- arg1 is the string for the volumename
47 arg1 -- Argument according to type (see above)
48 device -- Optional handler task address (obsolete!)
51 DOSFALSE - user has selected "Retry"
52 DOSTRUE - user has selected "Cancel" or code wasn't understood or
53 pr_WindowPtr is -1 or if an attempt to open the requester fails.
57 Locks and filehandles are the same in AROS so there is redundancy in
58 the parameters. Furthermore, the 'device' argument is not cared about
59 as AROS doesn't build filesystems with handlers.
69 *****************************************************************************/
73 struct Process
*me
= (struct Process
*) FindTask(NULL
);
75 BOOL want_volume
= FALSE
;
76 BOOL want_device
= FALSE
;
77 STRPTR volname
= NULL
;
78 STRPTR devname
= NULL
;
79 struct DeviceList
*dl
= NULL
;
80 struct Device
*handler
= NULL
;
81 struct Unit
*unit
= NULL
;
90 /* do nothing if errors are disabled */
91 if (me
->pr_WindowPtr
== (APTR
) -1) {
96 /* first setup the error format and work out which args we need */
98 /* Volume FOO: is not validated */
99 case ERROR_DISK_NOT_VALIDATED
:
100 format
= DosGetString(STRING_DISK_NOT_VALIDATED
);
104 /* Volume FOO: is write protected */
105 case ERROR_DISK_WRITE_PROTECTED
:
106 format
= DosGetString(STRING_DISK_WRITE_PROTECTED
);
110 /* Please (insert|replace) volume FOO: in ... */
111 case ERROR_DEVICE_NOT_MOUNTED
:
112 if (type
== REPORT_INSERT
) {
113 format
= DosGetString(STRING_DEVICE_NOT_MOUNTED_INSERT
);
116 else if (type
== REPORT_STREAM
) {
117 format
= DosGetString(STRING_DEVICE_NOT_MOUNTED_REPLACE_TARGET
);
118 want_volume
= want_device
= TRUE
;
121 format
= DosGetString(STRING_DEVICE_NOT_MOUNTED_REPLACE
);
124 idcmp
= IDCMP_DISKINSERTED
;
127 /* Volume FOO: is full */
128 case ERROR_DISK_FULL
:
129 format
= DosGetString(STRING_DISK_FULL
);
133 /* Not a DOS disk in ...*/
134 case ERROR_NOT_A_DOS_DISK
:
135 format
= DosGetString(STRING_NOT_A_DOS_DISK
);
139 /* No disk present in ...*/
141 format
= DosGetString(STRING_NO_DISK
);
145 /* You MUST replace volume FOO: in ... */
147 format
= DosGetString(STRING_ABORT_BUSY
);
148 want_volume
= want_device
= TRUE
;
149 idcmp
= IDCMP_DISKINSERTED
;
152 /* Volume FOO: has a read/write error */
153 case ABORT_DISK_ERROR
:
154 format
= DosGetString(STRING_ABORT_DISK_ERROR
);
158 /* do nothing with other errors */
163 /* now we need to determine the volume name. if they gave it to use
164 * (REPORT_INSERT), we just use it. otherwise, we get it from the device
165 * list (REPORT_VOLUME). if we don't have one, we use the handler/unit
170 if (arg1
== (IPTR
)NULL
)
173 handler
= ((struct FileHandle
*) BADDR(arg1
))->fh_Device
;
174 unit
= ((struct FileHandle
*) BADDR(arg1
))->fh_Unit
;
178 /* XXX what is this? */
183 /* if they provided a lock, just use it */
184 if (arg1
!= (IPTR
)NULL
) {
185 handler
= ((struct FileHandle
*) BADDR(arg1
))->fh_Device
;
186 unit
= ((struct FileHandle
*) BADDR(arg1
))->fh_Unit
;
189 /* otherwise we use the secondary device, and we look through the
190 * doslist to determine the unit */
192 handler
= (struct Device
*) device
;
194 /* find the doslist entry */
195 dol
= LockDosList(LDF_READ
| LDF_ALL
);
196 while (dol
!= NULL
&& (dol
->dol_Type
!= DLT_VOLUME
||
197 dol
->dol_Ext
.dol_AROS
.dol_Device
!= handler
))
200 /* found it, steal its unit */
202 unit
= dol
->dol_Ext
.dol_AROS
.dol_Unit
;
204 UnLockDosList(LDF_READ
| LDF_ALL
);
206 /* if we didn't find it, there's not much more we can do */
213 /* a volume, ie a DeviceList */
215 if (arg1
== (IPTR
)NULL
)
218 dl
= (struct DeviceList
*) arg1
;
221 /* raw volume name */
223 if (arg1
== (IPTR
)NULL
)
226 volname
= (STRPTR
) arg1
;
227 /* rip off any trailing stuff, if its there */
228 if (SplitName(volname
, ':', buf
, 0, sizeof(buf
)-1) == -1)
232 /* do nothing with other types */
237 /* get the name if we don't already have it */
238 if (volname
== NULL
) {
240 /* just use the volume pointer if we already have it */
242 volname
= dl
->dl_Ext
.dl_AROS
.dol_DevName
;
244 /* otherwise we have to get it from the handler */
246 /* XXX for packets we'd just call ACTION_CURRENT_DEVICE */
248 struct FileHandle
*fh
;
251 /* remember the current error just in case this fails. I don't know if
252 * this is actually necessary but I'm trying to keep side-effects to a
256 /* make a fake lock (filehandle) */
257 if ((fh
= AllocDosObject(DOS_FILEHANDLE
, 0)) == NULL
) {
262 fh
->fh_Device
= handler
;
265 /* get the handler to give us the name */
266 if (!NameFromLock(MKBADDR(fh
), buf
, 127)) {
267 FreeDosObject(DOS_FILEHANDLE
, fh
);
273 FreeDosObject(DOS_FILEHANDLE
, fh
);
276 /* find the volume seperator */
277 for (p
= buf
; *p
!= ':' && *p
!= '\0'; p
++);
279 /* not there. can this happen? */
283 /* overwrite it, and we have a volume name */
290 /* for the device name we need the doslist entry */
292 /* XXX for packets we just search the doslist for a DLT_DEVICE with
293 * the same task pointer. no need to worry about multiple units */
295 /* remember the current error in case we have to bail out */
298 /* get the entry for the volume */
299 if ((dvp
= GetDeviceProc(volname
, NULL
)) == NULL
) {
304 /* search the list for a device node with the same handler/port as the
306 dol
= LockDosList(LDF_READ
| LDF_ALL
);
307 while (dol
!= NULL
&& (dol
->dol_Type
!= DLT_DEVICE
||
308 dol
->dol_Ext
.dol_AROS
.dol_Device
!= (struct Device
*) dvp
->dvp_Port
||
309 dol
->dol_Ext
.dol_AROS
.dol_Unit
!= dvp
->dvp_DevNode
->dol_Ext
.dol_AROS
.dol_Unit
))
314 devname
= dol
->dol_Ext
.dol_AROS
.dol_DevName
;
316 /* XXX can this happen? */
320 UnLockDosList(LDF_READ
| LDF_ALL
);
325 /* have all we need, now to build the arg array */
331 else if (want_device
)
334 /* display it. idcmp is set further up to catch "disk insert" events if
335 * we're waiting for them to insert something */
337 res
= DisplayError(format
, idcmp
, &args
);
341 return res
== 0 ? DOSFALSE
: DOSTRUE
;