2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
10 #include <aros/debug.h>
12 #include "dos_intern.h"
13 #include <dos/filesystem.h>
14 #include <dos/notify.h>
15 #include <proto/exec.h>
18 /*****************************************************************************
21 #include <proto/dos.h>
23 AROS_LH0(struct DosPacket
*, WaitPkt
,
29 struct DosLibrary
*, DOSBase
, 42, Dos
)
33 Wait for a packet to arrive at your process' pr_MsgPort. It will call
34 pr_PktWait if such a function is installed.
40 The packet we received.
44 The packet will be released from the port.
46 This function should NOT be used. It's there only for AmigaOS
57 *****************************************************************************/
61 struct Process
*me
= (struct Process
*)FindTask(NULL
);
63 return internal_WaitPkt(&me
->pr_MsgPort
, DOSBase
);
69 struct DosPacket
*internal_WaitPkt(struct MsgPort
*msgPort
,
70 struct DosLibrary
*DOSBase
)
72 struct Message
*msg
= NULL
;
73 struct DosPacket
*packet
;
74 struct Process
*me
= (struct Process
*)FindTask(NULL
);
75 struct IOFileSys
*iofs
;
79 /* Call the packet wait function if the user has one installed.
80 Unfortunately, in case of IOFS the user gets something completely different than
81 a packet, but we cannot do anything about that... */
84 msg
= AROS_UFC3(struct Message
*, me
->pr_PktWait
,
85 AROS_UFCA(APTR
, me
->pr_PktWait
, A0
),
86 AROS_UFCA(struct MsgPort
*, msgPort
, A1
),
87 AROS_UFCA(struct ExecBase
*, SysBase
, A6
));
92 /* Make sure we have a packet -- we may be woken up even if there is
93 not a packet for us as SIGF_DOS may be used and we may have another
94 message port that waits for packets, too. */
95 while ((msg
= GetMsg(msgPort
)) == NULL
)
97 Wait(1 << msgPort
->mp_SigBit
);
101 /* If ln_Name is filled in, this means we are talking to a real packet-style handler and we got back
103 if (msg
->mn_Node
.ln_Name
) {
104 D(bug("[DOS] WaitPkt(): got DOS packet 0x%p in message 0x%p\n", msg
->mn_Node
.ln_Name
, msg
));
105 return (struct DosPacket
*)msg
->mn_Node
.ln_Name
;
108 D(bug("[DOS] WaitPkt(): got IOFS IORequest 0x%p\n", msg
));
109 iofs
= (struct IOFileSys
*)msg
;
110 packet
= iofs
->io_PacketEmulation
;
112 /* Convert AROS IOFileSys results back to DosPacket results */
114 switch (iofs
->IOFS
.io_Command
)
117 packet
->dp_Res1
= (IPTR
)iofs
->io_Union
.io_SEEK
.io_Offset
;
118 packet
->dp_Res2
= iofs
->io_DosError
;
121 /* This FSA corrsponds to ACTION_LOCATE_OBJECT, ACTION_COPY_DIR and
122 ACTION_COPY_DIR_FH */
125 struct FileHandle
*fh
= (struct FileHandle
*)packet
->dp_Arg6
;
127 packet
->dp_Res1
= (IPTR
)MKBADDR(fh
);
128 packet
->dp_Res2
= iofs
->io_DosError
;
130 if (iofs
->io_DosError
!= 0)
132 FreeDosObject(DOS_FILEHANDLE
, fh
);
135 fh
->fh_Device
= iofs
->IOFS
.io_Device
;
136 fh
->fh_Unit
= iofs
->IOFS
.io_Unit
;
140 /* This corresponds to ACTION_FINDINPUT, ACTION_FINDOUTPUT,
141 ACTION_FINDUPDATE which fortunately have the same return values */
144 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(packet
->dp_Arg1
);
146 fh
->fh_Device
= iofs
->IOFS
.io_Device
;
147 fh
->fh_Unit
= iofs
->IOFS
.io_Unit
;
149 packet
->dp_Res1
= iofs
->io_DosError
== 0;
150 packet
->dp_Res2
= iofs
->io_DosError
;
156 packet
->dp_Res1
= (IPTR
)iofs
->io_Union
.io_READ_WRITE
.io_Length
;
157 D(kprintf("Packet (%p) length = %u", packet
, packet
->dp_Res1
));
158 packet
->dp_Res2
= iofs
->io_DosError
;
162 packet
->dp_Res1
= iofs
->io_DosError
== 0;
163 FreeDosObject(DOS_FILEHANDLE
, (APTR
)packet
->dp_Arg1
);
169 /* Get supplied FileInfoBlock */
170 struct FileInfoBlock
*fib
= (struct FileInfoBlock
*)BADDR(packet
->dp_Arg2
);
171 struct ExAllData
*ead
= iofs
->io_Union
.io_EXAMINE
.io_ead
;
173 packet
->dp_Res1
= iofs
->io_DosError
== 0;
174 packet
->dp_Res2
= iofs
->io_DosError
;
176 /* in fib_DiskKey the result from telldir is being stored which
177 gives us important info for a call to ExNext() */
178 fib
->fib_DiskKey
= iofs
->io_DirPos
;
179 fib
->fib_DirEntryType
= ead
->ed_Type
;
181 strncpy(fib
->fib_FileName
, ead
->ed_Name
, MAXFILENAMELENGTH
);
183 fib
->fib_Protection
= ead
->ed_Prot
;
184 fib
->fib_EntryType
= ead
->ed_Type
;
185 fib
->fib_Size
= ead
->ed_Size
;
186 fib
->fib_Date
.ds_Days
= ead
->ed_Days
;
187 fib
->fib_Date
.ds_Minute
= ead
->ed_Mins
;
188 fib
->fib_Date
.ds_Tick
= ead
->ed_Ticks
;
190 if (ead
->ed_Comment
!= NULL
)
192 strncpy(fib
->fib_Comment
, ead
->ed_Comment
, MAXCOMMENTLENGTH
);
195 fib
->fib_OwnerUID
= ead
->ed_OwnerUID
;
196 fib
->fib_OwnerGID
= ead
->ed_OwnerGID
;
198 /* Release temporary buffer memory */
203 case FSA_EXAMINE_NEXT
:
204 case FSA_SET_FILE_SIZE
:
205 case FSA_DELETE_OBJECT
:
207 case FSA_SET_PROTECT
:
208 case FSA_SET_COMMENT
:
211 case FSA_IS_FILESYSTEM
:
212 case FSA_LOCK_RECORD
:
213 case FSA_UNLOCK_RECORD
:
215 case FSA_CREATE_HARDLINK
:
216 case FSA_CREATE_SOFTLINK
:
217 packet
->dp_Res1
= iofs
->io_DosError
== 0;
218 packet
->dp_Res2
= iofs
->io_DosError
;
221 case FSA_REMOVE_NOTIFY
:
223 struct NotifyRequest
*notify
= iofs
->io_Union
.io_NOTIFY
.io_NotificationRequest
;
225 if (notify
->nr_Flags
& NRF_SEND_MESSAGE
)
227 struct Node
*tempNode
;
228 struct NotifyMessage
*nm
;
232 ForeachNodeSafe(¬ify
->nr_stuff
.nr_Msg
.nr_Port
->mp_MsgList
,
235 if (notify
->nr_MsgCount
== 0)
240 if (nm
->nm_NReq
== notify
)
242 notify
->nr_MsgCount
--;
243 Remove((struct Node
*)nm
);
244 ReplyMsg((struct Message
*)nm
);
256 struct FileHandle
*fh
= AllocDosObject(DOS_FILEHANDLE
, NULL
);
258 /* If the allocation operation failed, we are in trouble as we
259 have to UnLock() the created directory -- this should be moved
264 /* Crash... well, we keep the lock for now */
266 packet
->dp_Res1
= DOSFALSE
;
267 packet
->dp_Res2
= ERROR_NO_FREE_STORE
;
271 fh
->fh_Unit
= iofs
->IOFS
.io_Unit
;
272 fh
->fh_Device
= iofs
->IOFS
.io_Device
;
273 packet
->dp_Res1
= (IPTR
)MKBADDR(fh
);
278 packet
->dp_Res1
= (IPTR
)(iofs
->io_Union
.io_SAME_LOCK
.io_Same
== LOCK_SAME
);
279 packet
->dp_Res2
= iofs
->io_DosError
;
282 case FSA_EXAMINE_ALL
:
284 /* ExAll() seems to be flawed(?)... have to investigate this. */
289 packet
->dp_Res1
= iofs
->io_DosError
== 0;
293 packet
->dp_Res1
= iofs
->io_Union
.io_RELABEL
.io_Result
;
297 packet
->dp_Res1
= iofs
->io_DosError
== 0;
298 packet
->dp_Res2
= iofs
->io_Union
.io_MORE_CACHE
.io_NumBuffers
;
303 case FSA_READ_SOFTLINK
:
306 kprintf("Filesystem action %i not handled yet in WaitPkt()\n",
307 iofs
->IOFS
.io_Command
);