revert between 56095 -> 55830 in arch
[AROS.git] / rom / dos / assignpath.c
blobbb79f1b9ae3e2834e28d71f41900f0b8c1c9ddd7
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Create a non-binding (path) 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, AssignPath,
21 /* SYNOPSIS */
22 AROS_LHA(CONST_STRPTR, name, D1),
23 AROS_LHA(CONST_STRPTR, path, D2),
25 /* LOCATION */
26 struct DosLibrary *, DOSBase, 104, Dos)
28 /* FUNCTION
29 Create an assign for the given name, which will be resolved upon
30 each reference to it. There will be no permanent lock kept on the
31 specified path. This way you can create assigns to unmounted volumes
32 which will only be requested when accessed. Also, using AssignPath()
33 to assign C: to df0:c would make references go to to df0:c even if
34 you change the disk.
36 INPUTS
37 name -- NULL terminated name of the assign.
38 path -- NULL terminated path to be resolved on each reference.
40 RESULT
41 != 0 in case of success, 0 on failure. IoErr() gives additional
42 information in that case.
44 NOTES
46 EXAMPLE
48 BUGS
50 SEE ALSO
51 AssignAdd(), AssignLock(), AssignLate(), Open()
53 INTERNALS
55 *****************************************************************************/
57 AROS_LIBFUNC_INIT
59 CONST_STRPTR s2;
60 struct DosList *dl, *newdl;
62 BOOL result = DOSTRUE;
63 STRPTR pathcopy;
64 ULONG namelen;
66 newdl = MakeDosEntry(name, DLT_NONBINDING);
68 if(newdl == NULL)
69 return DOSFALSE;
71 s2 = path;
73 while(*s2++)
76 namelen = s2 - path + 1;
77 pathcopy = AllocVec(namelen, MEMF_PUBLIC | MEMF_CLEAR);
79 if(pathcopy == NULL)
81 FreeDosEntry(newdl);
82 SetIoErr(ERROR_NO_FREE_STORE);
84 return DOSFALSE;
87 CopyMem(path, pathcopy, namelen);
88 newdl->dol_misc.dol_assign.dol_AssignName = pathcopy;
90 dl = LockDosList(LDF_ALL | LDF_WRITE);
91 dl = FindDosEntry(dl, name, LDF_ALL);
93 if(dl == NULL)
95 AddDosEntry(newdl);
97 else if(dl->dol_Type == DLT_VOLUME || dl->dol_Type == DLT_DEVICE)
99 dl = NULL;
100 FreeVec(newdl->dol_misc.dol_assign.dol_AssignName);
101 FreeDosEntry(newdl);
102 SetIoErr(ERROR_OBJECT_EXISTS);
104 result = DOSFALSE;
106 else
108 RemDosEntry(dl);
109 AddDosEntry(newdl);
112 if(dl != NULL)
114 UnLock(dl->dol_Lock);
116 if(dl->dol_misc.dol_assign.dol_List != NULL)
118 struct AssignList *al, *oal;
120 for(al = dl->dol_misc.dol_assign.dol_List; al; )
122 UnLock(al->al_Lock);
123 oal = al;
124 al = al->al_Next;
125 FreeVec(oal);
129 FreeVec(dl->dol_misc.dol_assign.dol_AssignName);
130 FreeDosEntry(dl);
133 UnLockDosList(LDF_ALL | LDF_WRITE);
135 return result;
137 AROS_LIBFUNC_EXIT
138 } /* AssignPath */