Detabbed
[AROS.git] / rom / dos / adddosentry.c
blob53e880a866638af055c50c1eea94c9b21c99de8b
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <dos/dosextens.h>
11 #include <proto/exec.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 implementation. LDF_DELETE is not used at all.
70 *****************************************************************************/
72 AROS_LIBFUNC_INIT
74 LONG success = DOSTRUE;
75 struct DosList *dl;
77 if (dlist == NULL)
78 return success;
80 D(bug("[AddDosEntry] Adding '%b' type %d from addr %x Task '%s'\n",
81 dlist->dol_Name, dlist->dol_Type, dlist,
82 FindTask(NULL)->tc_Node.ln_Name));
84 dl = LockDosList(LDF_ALL | LDF_READ);
86 LockDosList(LDF_ENTRY|LDF_WRITE);
87 if(dlist->dol_Type != DLT_VOLUME)
89 while(TRUE)
91 dl = BADDR(dl->dol_Next);
93 if(dl == NULL)
94 break;
96 if(dl->dol_Type != DLT_VOLUME && !CMPBSTR(dl->dol_Name, dlist->dol_Name))
98 D(bug("[AddDosEntry] Name clash for %08lx->dol_Name: %b and %08lx->dol_Name %b\n", dl, dl->dol_Name, dlist, dlist->dol_Name));
99 success = DOSFALSE;
100 break;
105 if(success)
107 struct DosInfo *dinf = BADDR(DOSBase->dl_Root->rn_Info);
109 dlist->dol_Next = dinf->di_DevInfo;
110 dinf->di_DevInfo = MKBADDR(dlist);
113 UnLockDosList(LDF_ENTRY|LDF_WRITE);
114 UnLockDosList(LDF_ALL | LDF_READ);
116 return success;
118 AROS_LIBFUNC_EXIT
119 } /* AddDosEntry */