2 Copyright © 1995-2001, 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 *****************************************************************************/
58 AROS_LIBBASE_EXT_DECL(struct DosLibrary
*,DOSBase
)
60 ASSERT_VALID_PTR(name
);
68 BPTR con
= NULL
, ast
= NULL
;
71 /* Get pointer to process structure */
73 me
= (struct Process
*)FindTask(NULL
);
75 /* Create filehandle */
77 ret
= (struct FileHandle
*)AllocDosObject(DOS_FILEHANDLE
, NULL
);
81 /* Get pointer to I/O request. Use stackspace for now. */
82 struct IOFileSys iofs
;
84 /* Prepare I/O request. */
85 InitIOFS(&iofs
, FSA_OPEN
, DOSBase
);
87 /* io_Args[0] is the name which is set by DoName(). */
91 iofs
.io_Union
.io_OPEN
.io_FileMode
= FMF_LOCK
| FMF_READ
;
93 ast
= me
->pr_CES
? me
->pr_CES
: me
->pr_COS
;
97 iofs
.io_Union
.io_OPEN
.io_FileMode
= FMF_READ
;
98 con
= ast
= me
->pr_CIS
;
102 iofs
.io_Union
.io_OPEN
.io_FileMode
= accessMode
;
103 con
= ast
= me
->pr_CIS
;
107 #define iofs_SetDeviceUnit(_iofs, _fh) \
109 (_iofs).IOFS.io_Device = ((struct FileHandle *)BADDR((_fh)))->fh_Device; \
110 (_iofs).IOFS.io_Unit = ((struct FileHandle *)BADDR((_fh)))->fh_Unit; \
113 if(!Stricmp(name
, "IN:") || !Stricmp(name
, "STDIN:"))
115 iofs_SetDeviceUnit(iofs
, me
->pr_CIS
);
117 iofs
.io_Union
.io_OPEN_FILE
.io_Filename
= "";
121 error
= me
->pr_Result2
= iofs
.io_DosError
;
123 else if(!Stricmp(name
, "OUT:") || !Stricmp(name
, "STDOUT:"))
125 iofs_SetDeviceUnit(iofs
, me
->pr_COS
);
127 iofs
.io_Union
.io_OPEN_FILE
.io_Filename
= "";
131 error
= me
->pr_Result2
= iofs
.io_DosError
;
133 else if(!Stricmp(name
, "ERR:") || !Stricmp(name
, "STDERR:"))
135 if (NULL
!= me
->pr_CES
)
137 iofs_SetDeviceUnit(iofs
, me
->pr_CES
);
141 iofs_SetDeviceUnit(iofs
, me
->pr_COS
);
144 iofs
.io_Union
.io_OPEN_FILE
.io_Filename
= "";
148 error
= me
->pr_Result2
= iofs
.io_DosError
;
150 else if(!Stricmp(name
, "CONSOLE:"))
152 iofs_SetDeviceUnit(iofs
, con
);
154 iofs
.io_Union
.io_OPEN_FILE
.io_Filename
= "";
158 error
= me
->pr_Result2
= iofs
.io_DosError
;
160 else if(!Stricmp(name
, "*"))
162 iofs_SetDeviceUnit(iofs
, ast
);
164 iofs
.io_Union
.io_OPEN_FILE
.io_Filename
= "";
168 error
= me
->pr_Result2
= iofs
.io_DosError
;
172 error
= DoName(&iofs
, name
, DOSBase
);
177 ret
->fh_Device
= iofs
.IOFS
.io_Device
;
178 ret
->fh_Unit
= iofs
.IOFS
.io_Unit
;
184 FreeDosObject(DOS_FILEHANDLE
, ret
);
189 SetIoErr(ERROR_NO_FREE_STORE
);