2 Copyright © 1995-2007, 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
)
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, the user gets something completely different than
81 a packet, but we cannot do anything about that... */
83 if (me
->pr_PktWait
!= NULL
)
90 /* Make sure we have a packet -- we may be woken up even if there is
91 not a packet for us as SIGF_DOS may be used and we may have another
92 message port that waits for packets, too. */
93 while ((msg
= GetMsg(msgPort
)) == NULL
)
95 Wait(1 << msgPort
->mp_SigBit
);
98 iofs
= (struct IOFileSys
*)msg
;
99 packet
= iofs
->io_PacketEmulation
;
101 /* Convert AROS IOFileSys results back to DosPacket results */
103 switch (iofs
->IOFS
.io_Command
)
106 packet
->dp_Res1
= (IPTR
)iofs
->io_Union
.io_SEEK
.io_Offset
;
107 packet
->dp_Res2
= iofs
->io_DosError
;
110 /* This FSA corrsponds to ACTION_LOCATE_OBJECT, ACTION_COPY_DIR and
111 ACTION_COPY_DIR_FH */
114 struct FileHandle
*fh
= (struct FileHandle
*)packet
->dp_Arg6
;
116 packet
->dp_Res1
= (IPTR
)MKBADDR(fh
);
117 packet
->dp_Res2
= iofs
->io_DosError
;
119 if (iofs
->io_DosError
!= 0)
121 FreeDosObject(DOS_FILEHANDLE
, fh
);
124 fh
->fh_Device
= iofs
->IOFS
.io_Device
;
125 fh
->fh_Unit
= iofs
->IOFS
.io_Unit
;
129 /* This corresponds to ACTION_FINDINPUT, ACTION_FINDOUTPUT,
130 ACTION_FINDUPDATE which fortunately have the same return values */
133 struct FileHandle
*fh
= (struct FileHandle
*)BADDR(packet
->dp_Arg1
);
135 fh
->fh_Device
= iofs
->IOFS
.io_Device
;
136 fh
->fh_Unit
= iofs
->IOFS
.io_Unit
;
138 packet
->dp_Res1
= iofs
->io_DosError
== 0;
139 packet
->dp_Res2
= iofs
->io_DosError
;
145 packet
->dp_Res1
= (IPTR
)iofs
->io_Union
.io_READ_WRITE
.io_Length
;
146 kprintf("Packet (%p) length = %u", packet
, packet
->dp_Res1
);
147 packet
->dp_Res2
= iofs
->io_DosError
;
151 packet
->dp_Res1
= iofs
->io_DosError
== 0;
152 FreeDosObject(DOS_FILEHANDLE
, (APTR
)packet
->dp_Arg1
);
158 /* Get supplied FileInfoBlock */
159 struct FileInfoBlock
*fib
= (struct FileInfoBlock
*)BADDR(packet
->dp_Arg2
);
160 struct ExAllData
*ead
= iofs
->io_Union
.io_EXAMINE
.io_ead
;
162 packet
->dp_Res1
= iofs
->io_DosError
== 0;
163 packet
->dp_Res2
= iofs
->io_DosError
;
165 /* in fib_DiskKey the result from telldir is being stored which
166 gives us important info for a call to ExNext() */
167 fib
->fib_DiskKey
= iofs
->io_DirPos
;
168 fib
->fib_DirEntryType
= ead
->ed_Type
;
170 strncpy(fib
->fib_FileName
, ead
->ed_Name
, MAXFILENAMELENGTH
);
172 fib
->fib_Protection
= ead
->ed_Prot
;
173 fib
->fib_EntryType
= ead
->ed_Type
;
174 fib
->fib_Size
= ead
->ed_Size
;
175 fib
->fib_Date
.ds_Days
= ead
->ed_Days
;
176 fib
->fib_Date
.ds_Minute
= ead
->ed_Mins
;
177 fib
->fib_Date
.ds_Tick
= ead
->ed_Ticks
;
179 if (ead
->ed_Comment
!= NULL
)
181 strncpy(fib
->fib_Comment
, ead
->ed_Comment
, MAXCOMMENTLENGTH
);
184 fib
->fib_OwnerUID
= ead
->ed_OwnerUID
;
185 fib
->fib_OwnerGID
= ead
->ed_OwnerGID
;
187 /* Release temporary buffer memory */
192 case FSA_EXAMINE_NEXT
:
193 case FSA_SET_FILE_SIZE
:
194 case FSA_DELETE_OBJECT
:
196 case FSA_SET_PROTECT
:
197 case FSA_SET_COMMENT
:
200 case FSA_IS_FILESYSTEM
:
201 case FSA_LOCK_RECORD
:
202 case FSA_UNLOCK_RECORD
:
204 case FSA_CREATE_HARDLINK
:
205 case FSA_CREATE_SOFTLINK
:
206 packet
->dp_Res1
= iofs
->io_DosError
== 0;
207 packet
->dp_Res2
= iofs
->io_DosError
;
210 case FSA_REMOVE_NOTIFY
:
212 struct NotifyRequest
*notify
= iofs
->io_Union
.io_NOTIFY
.io_NotificationRequest
;
214 if (notify
->nr_Flags
& NRF_SEND_MESSAGE
)
216 struct Node
*tempNode
;
217 struct NotifyMessage
*nm
;
221 ForeachNodeSafe(¬ify
->nr_stuff
.nr_Msg
.nr_Port
->mp_MsgList
,
224 if (notify
->nr_MsgCount
== 0)
229 if (nm
->nm_NReq
== notify
)
231 notify
->nr_MsgCount
--;
232 Remove((struct Node
*)nm
);
233 ReplyMsg((struct Message
*)nm
);
245 struct FileHandle
*fh
= AllocDosObject(DOS_FILEHANDLE
, NULL
);
247 /* If the allocation operation failed, we are in trouble as we
248 have to UnLock() the created directory -- this should be moved
253 /* Crash... well, we keep the lock for now */
255 packet
->dp_Res1
= DOSFALSE
;
256 packet
->dp_Res2
= ERROR_NO_FREE_STORE
;
260 fh
->fh_Unit
= iofs
->IOFS
.io_Unit
;
261 fh
->fh_Device
= iofs
->IOFS
.io_Device
;
262 packet
->dp_Res1
= (IPTR
)MKBADDR(fh
);
267 packet
->dp_Res1
= (IPTR
)(iofs
->io_Union
.io_SAME_LOCK
.io_Same
== LOCK_SAME
);
268 packet
->dp_Res2
= iofs
->io_DosError
;
271 case FSA_EXAMINE_ALL
:
273 /* ExAll() seems to be flawed(?)... have to investigate this. */
278 packet
->dp_Res1
= iofs
->io_DosError
== 0;
282 packet
->dp_Res1
= iofs
->io_Union
.io_RELABEL
.io_Result
;
286 packet
->dp_Res1
= iofs
->io_DosError
== 0;
287 packet
->dp_Res2
= iofs
->io_Union
.io_MORE_CACHE
.io_NumBuffers
;
292 case FSA_READ_SOFTLINK
:
295 kprintf("Filesystem action %i not handled yet in WaitPkt()\n",
296 iofs
->IOFS
.io_Command
);