2 Copyright © 1995-2007, 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 */
86 struct Unit
*curlock
, *oldlock
=NULL
;
87 struct MyExAllData stackead
;
88 struct ExAllData
*ead
= &stackead
.ead
;
91 /* Get pointer to filehandle */
92 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(DupLock(lock
));
94 /* Get pointer to process structure */
95 struct Process
*me
= (struct Process
*)FindTask(NULL
);
97 /* Get pointer to I/O request. Use stackspace for now. */
98 struct IOFileSys io
, *iofs
= &io
;
105 SetIoErr(ERROR_LINE_TOO_LONG
);
110 /* Prepare I/O request. */
111 iofs
->IOFS
.io_Message
.mn_Node
.ln_Type
= NT_REPLYMSG
;
112 iofs
->IOFS
.io_Message
.mn_ReplyPort
= &me
->pr_MsgPort
;
113 iofs
->IOFS
.io_Message
.mn_Length
= sizeof(struct IOFileSys
);
115 iofs
->IOFS
.io_Device
= (fh
== NULL
)
116 ? DOSBase
->dl_NulHandler
119 /* Construct the name from top to bottom */
120 name
= buffer
+ length
;
122 curlock
= fh
->fh_Unit
;
127 /* Read name of current lock (into the user supplied buffer) */
128 iofs
->IOFS
.io_Unit
= curlock
;
129 iofs
->IOFS
.io_Command
= FSA_EXAMINE
;
130 iofs
->io_Union
.io_EXAMINE
.io_ead
= ead
;
131 iofs
->io_Union
.io_EXAMINE
.io_Size
= sizeof(stackead
);
132 iofs
->io_Union
.io_EXAMINE
.io_Mode
= ED_TYPE
;
134 DosDoIO(&iofs
->IOFS
);
136 error
= iofs
->io_DosError
;
138 /* Move name to the top of the buffer. */
141 s1
= s2
= ead
->ed_Name
;
148 if(ead
->ed_Type
== ST_ROOT
)
156 error
= ERROR_LINE_TOO_LONG
;
159 else if(oldlock
!= NULL
)
167 error
= ERROR_LINE_TOO_LONG
;
175 if (name
- (s2
- s1
) >= buffer
)
184 error
= ERROR_LINE_TOO_LONG
;
190 /* Read the parent's lock (if there is a parent) */
191 if(!error
&& (ead
->ed_Type
!= ST_ROOT
))
193 iofs
->IOFS
.io_Command
= FSA_OPEN
;
194 iofs
->io_Union
.io_OPEN
.io_Filename
= "/";
195 iofs
->io_Union
.io_OPEN
.io_FileMode
= 0;
197 DosDoIO(&iofs
->IOFS
);
199 curlock
= iofs
->IOFS
.io_Unit
;
200 error
= iofs
->io_DosError
;
203 /* Free the old lock if it was allocated by NameFromLock(). */
206 iofs
->IOFS
.io_Unit
= oldlock
;
207 iofs
->IOFS
.io_Command
= FSA_CLOSE
;
209 DosDoIO(&iofs
->IOFS
);
215 while(!error
&& (ead
->ed_Type
!= ST_ROOT
));
217 /* Move the name from the top to the bottom of the buffer. */
221 UBYTE c
, old_c
= '\0';
227 if ((c
!= '/') || (old_c
!= ':'))
238 UnLock((BPTR
)MKBADDR(fh
));