2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Locks a file or directory.
9 #include <proto/exec.h>
10 #include <utility/tagitem.h>
11 #include <dos/dosextens.h>
12 #include <dos/filesystem.h>
13 #include <proto/dos.h>
14 #include <proto/utility.h>
15 #include "dos_intern.h"
18 #include <aros/debug.h>
21 /*****************************************************************************
24 #include <proto/dos.h>
29 AROS_LHA(CONST_STRPTR
, name
, D1
),
30 AROS_LHA(LONG
, accessMode
, D2
),
33 struct DosLibrary
*, DOSBase
, 14, Dos
)
36 Gets a lock on a file or directory. There may be more than one
37 shared lock on a file but only one if it is an exclusive one.
38 Locked files or directories may not be deleted.
41 name - NUL terminated name of the file or directory.
42 accessMode - One of SHARED_LOCK
46 Handle to the file or directory or 0 if the object couldn't be locked.
47 IoErr() gives additional information in that case.
50 The lock structure returned by this function is different
51 from that of AmigaOS (in fact it is identical to a filehandle).
52 Do not try to read any internal fields.
54 *****************************************************************************/
62 ASSERT_VALID_PTR(name
);
68 /* Get pointer to process structure */
70 me
= (struct Process
*)FindTask(NULL
);
72 /* Create filehandle */
74 ret
= (struct FileHandle
*)AllocDosObject(DOS_FILEHANDLE
, NULL
);
78 /* Get pointer to I/O request. Use stackspace for now. */
79 struct IOFileSys iofs
;
81 /* Prepare I/O request. */
82 InitIOFS(&iofs
, FSA_OPEN
, DOSBase
);
87 iofs
.io_Union
.io_OPEN
.io_FileMode
= FMF_LOCK
| FMF_READ
;
91 iofs
.io_Union
.io_OPEN
.io_FileMode
= FMF_READ
;
95 D(bug("[Lock] incompatible mode %d\n", accessMode
));
96 FreeDosObject(DOS_FILEHANDLE
, ret
);
97 SetIoErr(ERROR_ACTION_NOT_KNOWN
);
101 /* catch the zero-length special case. we can't (currently) call
102 * GetDeviceProc(), as it will call NameFromLock(), which will
103 * DupLock(), which will end up here */
106 struct FileHandle
*fh
;
108 cur
= me
->pr_CurrentDir
;
110 cur
= DOSBase
->dl_SYSLock
;
115 iofs
.io_Union
.io_OPEN
.io_Filename
= "";
117 iofs
.IOFS
.io_Device
= fh
->fh_Device
;
118 iofs
.IOFS
.io_Unit
= fh
->fh_Unit
;
122 error
= me
->pr_Result2
= iofs
.io_DosError
;
124 error
= ERROR_OBJECT_NOT_FOUND
;
130 iofs
.io_Union
.io_OPEN
.io_Filename
= StripVolume(name
);
135 if ((dvp
= GetDeviceProc(name
, dvp
)) == NULL
) {
140 error
= DoIOFS(&iofs
, dvp
, NULL
, DOSBase
);
141 } while (error
== ERROR_OBJECT_NOT_FOUND
);
143 if (error
== ERROR_NO_MORE_ENTRIES
)
144 error
= me
->pr_Result2
= ERROR_OBJECT_NOT_FOUND
;
151 ret
->fh_Device
= iofs
.IOFS
.io_Device
;
152 ret
->fh_Unit
= iofs
.IOFS
.io_Unit
;
158 FreeDosObject(DOS_FILEHANDLE
, ret
);
163 SetIoErr(ERROR_NO_FREE_STORE
);