Workaround for includes conflict that stopped compilation with GCC 3.
[cake.git] / rom / dos / adddosentry.c
blob30ddb80f590a7df72db1abcc47f552b429d20089
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
8 #define DEBUG 0
10 #include <aros/debug.h>
11 #include <dos/dosextens.h>
12 #include <proto/utility.h>
13 #include "dos_intern.h"
15 /*****************************************************************************
17 NAME */
18 #include <proto/dos.h>
20 AROS_LH1(LONG, AddDosEntry,
22 /* SYNOPSIS */
23 AROS_LHA(struct DosList *, dlist, D1),
25 /* LOCATION */
26 struct DosLibrary *, DOSBase, 113, Dos)
28 /* FUNCTION
29 Adds a given dos list entry to the dos list. Automatically
30 locks the list for writing. There may be not more than one device
31 or assign node of the same name. There are no restrictions on
32 volume nodes.
34 INPUTS
35 dlist - pointer to dos list entry.
37 RESULT
38 != 0 if all went well, 0 otherwise.
40 NOTES
41 Since anybody who wants to use a device or volume node in the
42 dos list has to lock the list, filesystems may be called with
43 the dos list locked. So if you want to add a dos list entry
44 out of a filesystem don't just wait on the lock but serve all
45 incoming requests until the dos list is free instead.
47 EXAMPLE
49 BUGS
51 SEE ALSO
53 INTERNALS
54 Behaviour of this function is slightly different from AmigaOS 3.x
55 and MorphOS. Instead of LDF_WRITE it locks DosList with LDF_READ
56 flag. This is done because in AROS handlers are run with DosList
57 locked with LDF_READ flag and this could cause a lockup if we use
58 LDF_WRITE here.
60 Due to nature of the DosList it is safe to read the list while
61 someone is adding a node, adding operation is atomic to other
62 readers. The only problem here would happen if more than one
63 process attempts to add a DosNode at the same time. In order to
64 avoid this race condition we make this call single-threaded
65 using an LDF_ENTRY lock in LDF_WRITE mode.
67 LDF_ENTRY is NOT touched when a handler is started up in this
68 dos.library implmentation. LDF_DELETE is not used at all.
70 *****************************************************************************/
72 AROS_LIBFUNC_INIT
74 LONG success = 1;
75 struct DosList *dl, *scan;
77 if (dlist == NULL) return success;
79 D(bug("[AddDosEntry] Adding %b\n", dlist->dol_Name));
80 dl = LockDosList(LDF_ALL | LDF_READ);
82 /* If the passed entry has dol_Task defined, then it's a packet-based
83 * handler, and probably doesn't have valid dol_DevName, dol_Device and
84 * dol_Unit fields, which will be needed. So we search through the DOS
85 * list looking for the packet.handler entry for the same process, and
86 * fill in the values from there.
88 * This all falls down if the handler does somehow know these fields and
89 * adds different values. We can't just test for NULL, as the handler may
90 * not have cleared it. I can't think of a single good reason why a
91 * handler would do this, so I'm not worrying about it for now.
93 * It will also break if the handler has set dol_Task to something other
94 * than its original packet.handler task. In that case we won't be able to
95 * match it correctly in the DOS list, and so the three fields will remain
96 * bogus, probably causing crashes shortly after. Again, I'll worry about
97 * it if and when it happens.
99 if (dlist->dol_Task != NULL) {
100 for (scan = dl; scan != NULL; scan = scan->dol_Next)
101 if (scan->dol_Task == dlist->dol_Task && scan->dol_Type == DLT_DEVICE) {
102 dlist->dol_Ext.dol_AROS.dol_DevName = AROS_BSTR_ADDR(dlist->dol_Name);
103 dlist->dol_Ext.dol_AROS.dol_Device = scan->dol_Ext.dol_AROS.dol_Device;
104 dlist->dol_Ext.dol_AROS.dol_Unit = scan->dol_Ext.dol_AROS.dol_Unit;
105 break;
108 /* Software ported from AmigaOS may be unaware of dol_DevName existance.
109 * In this case dol_DevName will be NULL (this assumes that it allocates
110 * the DosNode in a system-friendly manner using AllocDosObject().
112 if (!dlist->dol_Ext.dol_AROS.dol_DevName) {
113 dlist->dol_Ext.dol_AROS.dol_DevName = AROS_BSTR_ADDR(dlist->dol_Name);
114 D(bug("[AddDosEntry] Filling in dol_DevName: %s\n", dlist->dol_Ext.dol_AROS.dol_DevName));
117 LockDosList(LDF_ENTRY|LDF_WRITE);
118 if(dlist->dol_Type != DLT_VOLUME)
120 while(TRUE)
122 dl = dl->dol_Next;
124 if(dl == NULL)
125 break;
127 if(dl->dol_Type != DLT_VOLUME &&
128 !Stricmp(dl->dol_Ext.dol_AROS.dol_DevName, dlist->dol_Ext.dol_AROS.dol_DevName))
130 success = 0;
131 break;
136 if(success)
138 dlist->dol_Next = DOSBase->dl_DevInfo;
139 DOSBase->dl_DevInfo = dlist;
142 UnLockDosList(LDF_ENTRY|LDF_WRITE);
143 UnLockDosList(LDF_ALL | LDF_READ);
145 return success;
147 AROS_LIBFUNC_EXIT
148 } /* AddDosEntry */