grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / dos / adddosentry.c
bloba767a8ab85c75de8fbfe81975f4da73789c7078f
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Adds a given dos list entry to the dos list.
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 except that the time stamps must differ.
34 INPUTS
35 dlist - Pointer to DOS list entry.
37 RESULT
38 DOSTRUE if all went well.
39 DOSFALSE for errors; IoErr() will return additional error code.
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 The dlist pointer may become invalid after a call to AddDosEntry()
49 unless you have locked the DOS list.
51 EXAMPLE
53 BUGS
55 SEE ALSO
56 RemDosEntry(), FindDosEntry(), NextDosEntry(), LockDosList(),
57 MakeDosEntry(), FreeDosEntry(), AttemptLockDosList()
59 INTERNALS
60 Behavior of this function is slightly different from AmigaOS 3.x
61 and MorphOS. Instead of LDF_WRITE it locks DosList with LDF_READ
62 flag. This is done because in AROS handlers are run with DosList
63 locked with LDF_READ flag and this could cause a lockup if we use
64 LDF_WRITE here.
66 Due to nature of the DosList it is safe to read the list while
67 someone is adding a node, adding operation is atomic to other
68 readers. The only problem here would happen if more than one
69 process attempts to add a DosNode at the same time. In order to
70 avoid this race condition we make this call single-threaded
71 using an LDF_ENTRY lock in LDF_WRITE mode.
73 LDF_ENTRY is NOT touched when a handler is started up in this
74 dos.library implementation. LDF_DELETE is not used at all.
76 *****************************************************************************/
78 AROS_LIBFUNC_INIT
80 LONG success = DOSTRUE;
81 struct DosList *dl;
83 if (dlist == NULL)
84 return success;
86 D(bug("[AddDosEntry] Adding '%b' type %d from addr %x Task '%s'\n",
87 dlist->dol_Name, dlist->dol_Type, dlist,
88 FindTask(NULL)->tc_Node.ln_Name));
90 dl = LockDosList(LDF_ALL | LDF_READ);
92 LockDosList(LDF_ENTRY|LDF_WRITE);
93 if(dlist->dol_Type != DLT_VOLUME)
95 while(TRUE)
97 dl = BADDR(dl->dol_Next);
99 if(dl == NULL)
100 break;
102 if(dl->dol_Type != DLT_VOLUME && !CMPBSTR(dl->dol_Name, dlist->dol_Name))
104 D(bug("[AddDosEntry] Name clash for %08lx->dol_Name: %b and %08lx->dol_Name %b\n", dl, dl->dol_Name, dlist, dlist->dol_Name));
105 success = DOSFALSE;
106 break;
111 if(success)
113 struct DosInfo *dinf = BADDR(DOSBase->dl_Root->rn_Info);
115 dlist->dol_Next = dinf->di_DevInfo;
116 dinf->di_DevInfo = MKBADDR(dlist);
119 UnLockDosList(LDF_ENTRY|LDF_WRITE);
120 UnLockDosList(LDF_ALL | LDF_READ);
122 return success;
124 AROS_LIBFUNC_EXIT
125 } /* AddDosEntry */