Commit of the code which was suggested by Georg as a fix for:
[cake.git] / rom / dos / waitpkt.c
blob98da8de186e3ee13ab542b49d9a2cb00e8b8e50d
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #define DEBUG 1
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>
16 #include <string.h>
18 /*****************************************************************************
20 NAME */
21 #include <proto/dos.h>
23 AROS_LH0(struct DosPacket *, WaitPkt,
25 /* SYNOPSIS */
26 /* void */
28 /* LOCATION */
29 struct DosLibrary *, DOSBase, 42, Dos)
31 /* FUNCTION
33 Wait for a packet to arrive at your process' pr_MsgPort. It will call
34 pr_PktWait if such a function is installed.
36 INPUTS
38 RESULT
40 The packet we received.
42 NOTES
44 The packet will be released from the port.
46 This function should NOT be used. It's there only for AmigaOS
47 compatibility.
49 EXAMPLE
51 BUGS
53 SEE ALSO
55 INTERNALS
57 *****************************************************************************/
59 AROS_LIBFUNC_INIT
61 struct Process *me = (struct Process *)FindTask(NULL);
63 return internal_WaitPkt(&me->pr_MsgPort, DOSBase);
65 AROS_LIBFUNC_EXIT
66 } /* WaitPkt */
69 struct DosPacket *internal_WaitPkt(struct MsgPort *msgPort,
70 struct DosLibrary *DOSBase)
72 struct Message *msg;
73 struct DosPacket *packet;
74 struct Process *me = (struct Process *)FindTask(NULL);
75 struct IOFileSys *iofs;
77 if (__is_process(me))
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... */
82 #if 0
83 if (me->pr_PktWait != NULL)
85 me->pr_PktWait();
87 #endif
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)
105 case FSA_SEEK:
106 packet->dp_Res1 = (IPTR)iofs->io_Union.io_SEEK.io_Offset;
107 packet->dp_Res2 = iofs->io_DosError;
108 break;
110 /* This FSA corrsponds to ACTION_LOCATE_OBJECT, ACTION_COPY_DIR and
111 ACTION_COPY_DIR_FH */
112 case FSA_OPEN:
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;
126 break;
129 /* This corresponds to ACTION_FINDINPUT, ACTION_FINDOUTPUT,
130 ACTION_FINDUPDATE which fortunately have the same return values */
131 case FSA_OPEN_FILE:
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;
140 break;
143 case FSA_READ:
144 case FSA_WRITE:
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;
148 break;
150 case FSA_CLOSE:
151 packet->dp_Res1 = iofs->io_DosError == 0;
152 FreeDosObject(DOS_FILEHANDLE, (APTR)packet->dp_Arg1);
153 break;
156 case FSA_EXAMINE:
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 */
188 FreeVec(ead);
189 break;
192 case FSA_EXAMINE_NEXT:
193 case FSA_SET_FILE_SIZE:
194 case FSA_DELETE_OBJECT:
195 case FSA_RENAME:
196 case FSA_SET_PROTECT:
197 case FSA_SET_COMMENT:
198 case FSA_SET_DATE:
199 case FSA_FORMAT:
200 case FSA_IS_FILESYSTEM:
201 case FSA_LOCK_RECORD:
202 case FSA_UNLOCK_RECORD:
203 case FSA_ADD_NOTIFY:
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;
208 break;
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;
219 Disable();
221 ForeachNodeSafe(&notify->nr_stuff.nr_Msg.nr_Port->mp_MsgList,
222 nm, tempNode)
224 if (notify->nr_MsgCount == 0)
226 break;
229 if (nm->nm_NReq == notify)
231 notify->nr_MsgCount--;
232 Remove((struct Node *)nm);
233 ReplyMsg((struct Message *)nm);
237 Enable();
241 break;
243 case FSA_CREATE_DIR:
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
249 to SendPkt()! */
251 if (fh == NULL)
253 /* Crash... well, we keep the lock for now */
255 packet->dp_Res1 = DOSFALSE;
256 packet->dp_Res2 = ERROR_NO_FREE_STORE;
257 break;
260 fh->fh_Unit = iofs->IOFS.io_Unit;
261 fh->fh_Device = iofs->IOFS.io_Device;
262 packet->dp_Res1 = (IPTR)MKBADDR(fh);
263 break;
266 case FSA_SAME_LOCK:
267 packet->dp_Res1 = (IPTR)(iofs->io_Union.io_SAME_LOCK.io_Same == LOCK_SAME);
268 packet->dp_Res2 = iofs->io_DosError;
269 break;
271 case FSA_EXAMINE_ALL:
272 /* TODO */
273 /* ExAll() seems to be flawed(?)... have to investigate this. */
274 break;
276 case FSA_DISK_INFO:
277 case FSA_INHIBIT:
278 packet->dp_Res1 = iofs->io_DosError == 0;
279 break;
281 case FSA_RELABEL:
282 packet->dp_Res1 = iofs->io_Union.io_RELABEL.io_Result;
283 break;
285 case FSA_MORE_CACHE:
286 packet->dp_Res1 = iofs->io_DosError == 0;
287 packet->dp_Res2 = iofs->io_Union.io_MORE_CACHE.io_NumBuffers;
288 break;
291 /* TODO */
292 case FSA_READ_SOFTLINK:
293 case FSA_FILE_MODE:
294 default:
295 kprintf("Filesystem action %i not handled yet in WaitPkt()\n",
296 iofs->IOFS.io_Command);
297 break;
300 return packet;