kms.library: Fix wrong LVO number
[AROS.git] / rom / dos / adddosentry.c
blob053612ea36ef2ae95b07e17a8beca3db1ed46a6d
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
8 #include <dos/dosextens.h>
9 #include <proto/exec.h>
10 #include <proto/utility.h>
11 #include "dos_intern.h"
13 #define DEBUG 0
14 #include <aros/debug.h>
16 /*****************************************************************************
18 NAME */
19 #include <proto/dos.h>
21 AROS_LH1(LONG, AddDosEntry,
23 /* SYNOPSIS */
24 AROS_LHA(struct DosList *, dlist, D1),
26 /* LOCATION */
27 struct DosLibrary *, DOSBase, 113, Dos)
29 /* FUNCTION
30 Adds a given dos list entry to the dos list. Automatically
31 locks the list for writing. There may be not more than one device
32 or assign node of the same name. There are no restrictions on
33 volume nodes.
35 INPUTS
36 dlist - pointer to dos list entry.
38 RESULT
39 != 0 if all went well, 0 otherwise.
41 NOTES
42 Since anybody who wants to use a device or volume node in the
43 dos list has to lock the list, filesystems may be called with
44 the dos list locked. So if you want to add a dos list entry
45 out of a filesystem don't just wait on the lock but serve all
46 incoming requests until the dos list is free instead.
48 EXAMPLE
50 BUGS
52 SEE ALSO
54 INTERNALS
55 Behaviour of this function is slightly different from AmigaOS 3.x
56 and MorphOS. Instead of LDF_WRITE it locks DosList with LDF_READ
57 flag. This is done because in AROS handlers are run with DosList
58 locked with LDF_READ flag and this could cause a lockup if we use
59 LDF_WRITE here.
61 Due to nature of the DosList it is safe to read the list while
62 someone is adding a node, adding operation is atomic to other
63 readers. The only problem here would happen if more than one
64 process attempts to add a DosNode at the same time. In order to
65 avoid this race condition we make this call single-threaded
66 using an LDF_ENTRY lock in LDF_WRITE mode.
68 LDF_ENTRY is NOT touched when a handler is started up in this
69 dos.library implementation. LDF_DELETE is not used at all.
71 *****************************************************************************/
73 AROS_LIBFUNC_INIT
75 LONG success = DOSTRUE;
76 struct DosList *dl;
78 if (dlist == NULL)
79 return success;
81 D(bug("[AddDosEntry] Adding '%b' type %d from addr %x Task '%s'\n",
82 dlist->dol_Name, dlist->dol_Type, dlist,
83 FindTask(NULL)->tc_Node.ln_Name));
85 dl = LockDosList(LDF_ALL | LDF_READ);
87 LockDosList(LDF_ENTRY|LDF_WRITE);
88 if(dlist->dol_Type != DLT_VOLUME)
90 while(TRUE)
92 dl = BADDR(dl->dol_Next);
94 if(dl == NULL)
95 break;
97 if(dl->dol_Type != DLT_VOLUME && !CMPBSTR(dl->dol_Name, dlist->dol_Name))
99 D(bug("[AddDosEntry] Name clash for %08lx->dol_Name: %b and %08lx->dol_Name %b\n", dl, dl->dol_Name, dlist, dlist->dol_Name));
100 success = DOSFALSE;
101 break;
106 if(success)
108 struct DosInfo *dinf = BADDR(DOSBase->dl_Root->rn_Info);
110 dlist->dol_Next = dinf->di_DevInfo;
111 dinf->di_DevInfo = MKBADDR(dlist);
114 UnLockDosList(LDF_ENTRY|LDF_WRITE);
115 UnLockDosList(LDF_ALL | LDF_READ);
117 return success;
119 AROS_LIBFUNC_EXIT
120 } /* AddDosEntry */