2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Retrieve thew full pathname from a lock.
8 #include <proto/exec.h>
10 #include <dos/filesystem.h>
11 #include "dos_intern.h"
12 #include <aros/debug.h>
17 UBYTE filenamebuffer
[MAXFILENAMELENGTH
+ 1];
20 /*****************************************************************************
23 #include <proto/dos.h>
25 AROS_LH3(BOOL
, NameFromLock
,
28 AROS_LHA(BPTR
, lock
, D1
),
29 AROS_LHA(STRPTR
, buffer
, D2
),
30 AROS_LHA(LONG
, length
, D3
),
33 struct DosLibrary
*, DOSBase
, 67, Dos
)
36 Get the full path name associated with a lock to a file or
37 directory into a user supplied buffer.
40 lock - Lock to file or directory.
41 buffer - Buffer to fill. Contains a NUL terminated string if
43 length - Size of the buffer in bytes.
46 !=0 if all went well, 0 in case of an error. IoErr() will
47 give additional information in that case.
49 *****************************************************************************/
51 /*****************************************************************************
54 #include <clib/dos_protos.h>
56 AROS_LH3(LONG, NameFromFH,
59 AROS_LHA(BPTR , fh, D1),
60 AROS_LHA(STRPTR, buffer, D2),
61 AROS_LHA(LONG , len, D3),
64 struct DosLibrary *, DOSBase, 68, Dos)
67 Get the full path name associated with file-handle into a
71 fh - File-handle to file or directory.
72 buffer - Buffer to fill. Contains a NUL terminated string if
74 length - Size of the buffer in bytes.
77 !=0 if all went well, 0 in case of an error. IoErr() will
78 give additional information in that case.
80 *****************************************************************************/
81 /*AROS alias NameFromFH NameFromLock */
84 AROS_LIBBASE_EXT_DECL(struct DosLibrary
*,DOSBase
)
87 struct Unit
*curlock
, *oldlock
=NULL
;
88 struct MyExAllData stackead
;
89 struct ExAllData
*ead
= &stackead
.ead
;
92 /* Get pointer to filehandle */
93 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(DupLock(lock
));
95 /* Get pointer to process structure */
96 struct Process
*me
= (struct Process
*)FindTask(NULL
);
98 /* Get pointer to I/O request. Use stackspace for now. */
99 struct IOFileSys io
, *iofs
= &io
;
106 SetIoErr(ERROR_LINE_TOO_LONG
);
111 /* Prepare I/O request. */
112 iofs
->IOFS
.io_Message
.mn_Node
.ln_Type
= NT_REPLYMSG
;
113 iofs
->IOFS
.io_Message
.mn_ReplyPort
= &me
->pr_MsgPort
;
114 iofs
->IOFS
.io_Message
.mn_Length
= sizeof(struct IOFileSys
);
116 iofs
->IOFS
.io_Device
= (fh
== NULL
)
117 ? DOSBase
->dl_NulHandler
120 /* Construct the name from top to bottom */
121 name
= buffer
+ length
;
123 curlock
= fh
->fh_Unit
;
128 /* Read name of current lock (into the user supplied buffer) */
129 iofs
->IOFS
.io_Unit
= curlock
;
130 iofs
->IOFS
.io_Command
= FSA_EXAMINE
;
131 iofs
->io_Union
.io_EXAMINE
.io_ead
= ead
;
132 iofs
->io_Union
.io_EXAMINE
.io_Size
= sizeof(stackead
);
133 iofs
->io_Union
.io_EXAMINE
.io_Mode
= ED_TYPE
;
135 DosDoIO(&iofs
->IOFS
);
137 error
= iofs
->io_DosError
;
139 /* Move name to the top of the buffer. */
142 s1
= s2
= ead
->ed_Name
;
149 if(ead
->ed_Type
== ST_ROOT
)
157 error
= ERROR_LINE_TOO_LONG
;
160 else if(oldlock
!= NULL
)
168 error
= ERROR_LINE_TOO_LONG
;
176 if (name
- (s2
- s1
) >= buffer
)
185 error
= ERROR_LINE_TOO_LONG
;
191 /* Read the parent's lock (if there is a parent) */
192 if(!error
&& (ead
->ed_Type
!= ST_ROOT
))
194 iofs
->IOFS
.io_Command
= FSA_OPEN
;
195 iofs
->io_Union
.io_OPEN
.io_Filename
= "/";
196 iofs
->io_Union
.io_OPEN
.io_FileMode
= 0;
198 DosDoIO(&iofs
->IOFS
);
200 curlock
= iofs
->IOFS
.io_Unit
;
201 error
= iofs
->io_DosError
;
204 /* Free the old lock if it was allocated by NameFromLock(). */
207 iofs
->IOFS
.io_Unit
= oldlock
;
208 iofs
->IOFS
.io_Command
= FSA_CLOSE
;
210 DosDoIO(&iofs
->IOFS
);
216 while(!error
&& (ead
->ed_Type
!= ST_ROOT
));
218 /* Move the name from the top to the bottom of the buffer. */
222 UBYTE c
, old_c
= '\0';
228 if ((c
!= '/') || (old_c
!= ':'))
239 UnLock((BPTR
)MKBADDR(fh
));