acpica.library: Add AcpiScanTables() Hook based helper
[AROS.git] / rom / dos / assignlate.c
blobf1b5221375816063b04486f30a799c7d8d48d543
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Create a late-binding (deferred) assign.
6 Lang: English
7 */
8 #include <exec/memory.h>
9 #include <proto/exec.h>
10 #include <dos/dos.h>
11 #include <dos/dosextens.h>
12 #include "dos_intern.h"
14 /*****************************************************************************
16 NAME */
17 #include <proto/dos.h>
19 AROS_LH2(BOOL, AssignLate,
21 /* SYNOPSIS */
22 AROS_LHA(CONST_STRPTR, name, D1),
23 AROS_LHA(CONST_STRPTR, path, D2),
25 /* LOCATION */
26 struct DosLibrary *, DOSBase, 103, Dos)
28 /* FUNCTION
29 Create an assign for the given name, which will be resolved upon the
30 first reference to it. If this succeeds (i.e. the path exists and
31 can be locked) it will be turned into an AssignLock() type assign.
32 This way you can create assigns to unmounted volumes which will only
33 be requested when accessed.
35 INPUTS
36 name -- NULL terminated name of the assign.
37 path -- NULL terminated path to be resolved on the first reference.
39 RESULT
40 != 0 success, 0 on failure. IoErr() gives additional information
41 in that case.
43 NOTES
45 EXAMPLE
47 BUGS
49 SEE ALSO
50 Lock(), AssignAdd(), AssignPath(), AssignLock()
52 INTERNALS
54 *****************************************************************************/
56 AROS_LIBFUNC_INIT
58 struct DosList *dl, *newdl;
59 CONST_STRPTR s2;
61 BOOL result = DOSTRUE;
62 STRPTR pathcopy;
63 ULONG namelen;
65 newdl = MakeDosEntry(name, DLT_LATE);
67 if (newdl == NULL)
68 return DOSFALSE;
70 s2 = path;
72 while(*s2++)
75 namelen = s2 - path + 1;
76 pathcopy = AllocVec(namelen, MEMF_PUBLIC | MEMF_CLEAR);
78 if(pathcopy == NULL)
80 FreeDosEntry(newdl);
81 SetIoErr(ERROR_NO_FREE_STORE);
83 return DOSFALSE;
86 CopyMem(path, pathcopy, namelen);
87 newdl->dol_misc.dol_assign.dol_AssignName = pathcopy;
89 dl = LockDosList(LDF_ALL | LDF_WRITE);
90 dl = FindDosEntry(dl, name, LDF_ALL);
92 if(dl == NULL)
94 AddDosEntry(newdl);
96 else if(dl->dol_Type == DLT_VOLUME || dl->dol_Type == DLT_DEVICE)
98 dl = NULL;
99 FreeVec(newdl->dol_misc.dol_assign.dol_AssignName);
100 FreeDosEntry(newdl);
101 SetIoErr(ERROR_OBJECT_EXISTS);
102 result = DOSFALSE;
104 else
106 RemDosEntry(dl);
107 AddDosEntry(newdl);
110 if(dl != NULL)
112 UnLock(dl->dol_Lock);
114 if(dl->dol_misc.dol_assign.dol_List != NULL)
116 struct AssignList *al, *oal;
118 for(al = dl->dol_misc.dol_assign.dol_List; al; )
120 UnLock(al->al_Lock);
121 oal = al;
122 al = al->al_Next;
123 FreeVec(oal);
127 FreeVec(dl->dol_misc.dol_assign.dol_AssignName);
128 FreeDosEntry(dl);
131 UnLockDosList(LDF_ALL | LDF_WRITE);
133 return result;
135 AROS_LIBFUNC_EXIT
136 } /* AssignLate */