Do not try to get stack pointer from invalid ESP field, which coincidentally
[AROS.git] / rom / dos / assignlock.c
bloba2dccb000512ffaf61896c7391899a6e17d2e82d
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Create an assign.
6 Lang: English
7 */
8 #include <exec/memory.h>
9 #include <proto/exec.h>
10 #include <dos/filesystem.h>
11 #include "dos_intern.h"
13 /*****************************************************************************
15 NAME */
16 #include <proto/dos.h>
18 AROS_LH2(LONG, AssignLock,
20 /* SYNOPSIS */
21 AROS_LHA(CONST_STRPTR, name, D1),
22 AROS_LHA(BPTR, lock, D2),
24 /* LOCATION */
25 struct DosLibrary *, DOSBase, 102, Dos)
27 /* FUNCTION
28 Create an assign from a given name to a lock. Replaces any older
29 assignments from that name, 0 cancels the assign completely. Do not
30 use or free the lock after calling this function - it becomes
31 the assign and will be freed by the system if the assign is removed.
33 INPUTS
34 name -- NUL terminated name of the assign.
35 lock -- Lock to assigned directory.
37 RESULT
38 != 0 success, 0 on failure. IoErr() gives additional information
39 in that case. The lock is not freed on failure.
41 NOTES
43 EXAMPLE
45 BUGS
47 SEE ALSO
49 INTERNALS
51 *****************************************************************************/
53 AROS_LIBFUNC_INIT
55 BOOL success = DOSTRUE;
57 struct DosList *dl, *newdl = NULL;
59 if (lock != NULL)
61 newdl = MakeDosEntry(name, DLT_DIRECTORY);
63 if (newdl == NULL)
64 return DOSFALSE;
65 else
67 #ifdef AROS_DOS_PACKETS
68 struct FileLock *fl = BADDR(lock);
70 newdl->dol_Task = fl->fl_Task;
71 #else
72 struct FileHandle *fh = (struct FileHandle *)BADDR(lock);
74 newdl->dol_Ext.dol_AROS.dol_Unit = fh->fh_Unit;
75 newdl->dol_Ext.dol_AROS.dol_Device = fh->fh_Device;
76 #endif
77 newdl->dol_Lock = lock;
81 dl = LockDosList(LDF_ALL | LDF_WRITE);
82 dl = FindDosEntry(dl, name, LDF_ALL);
84 if (dl == NULL)
86 AddDosEntry(newdl);
88 else if (dl->dol_Type == DLT_DEVICE || dl->dol_Type == DLT_VOLUME)
90 dl = NULL;
91 FreeDosEntry(newdl);
92 SetIoErr(ERROR_OBJECT_EXISTS);
93 success = DOSFALSE;
95 else
97 RemDosEntry(dl);
99 AddDosEntry(newdl);
102 if (dl != NULL)
104 if (dl->dol_Lock)
106 UnLock(dl->dol_Lock);
109 if (dl->dol_misc.dol_assign.dol_List != NULL)
111 struct AssignList *al, *oal;
113 for (al = dl->dol_misc.dol_assign.dol_List; al; )
115 UnLock(al->al_Lock);
116 oal = al;
117 al = al->al_Next;
118 FreeVec(oal);
122 FreeVec(dl->dol_misc.dol_assign.dol_AssignName);
123 FreeDosEntry(dl);
126 UnLockDosList(LDF_ALL | LDF_WRITE);
128 return success;
130 AROS_LIBFUNC_EXIT
131 } /* AssignLock */