Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / dos / waitpkt.c
blob19397b8519bcc70e725b16953b0af44dc114fa09
1 /*
2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #define DEBUG 0
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 = NULL;
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, in case of IOFS the user gets something completely different than
81 a packet, but we cannot do anything about that... */
82 if (me->pr_PktWait)
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));
91 if (!msg) {
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
102 a real packet. */
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)
116 case FSA_SEEK:
117 packet->dp_Res1 = (IPTR)iofs->io_Union.io_SEEK.io_Offset;
118 packet->dp_Res2 = iofs->io_DosError;
119 break;
121 /* This FSA corrsponds to ACTION_LOCATE_OBJECT, ACTION_COPY_DIR and
122 ACTION_COPY_DIR_FH */
123 case FSA_OPEN:
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;
137 break;
140 /* This corresponds to ACTION_FINDINPUT, ACTION_FINDOUTPUT,
141 ACTION_FINDUPDATE which fortunately have the same return values */
142 case FSA_OPEN_FILE:
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;
151 break;
154 case FSA_READ:
155 case FSA_WRITE:
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;
159 break;
161 case FSA_CLOSE:
162 packet->dp_Res1 = iofs->io_DosError == 0;
163 FreeDosObject(DOS_FILEHANDLE, (APTR)packet->dp_Arg1);
164 break;
167 case FSA_EXAMINE:
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 */
199 FreeVec(ead);
200 break;
203 case FSA_EXAMINE_NEXT:
204 case FSA_SET_FILE_SIZE:
205 case FSA_DELETE_OBJECT:
206 case FSA_RENAME:
207 case FSA_SET_PROTECT:
208 case FSA_SET_COMMENT:
209 case FSA_SET_DATE:
210 case FSA_FORMAT:
211 case FSA_IS_FILESYSTEM:
212 case FSA_LOCK_RECORD:
213 case FSA_UNLOCK_RECORD:
214 case FSA_ADD_NOTIFY:
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;
219 break;
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;
230 Disable();
232 ForeachNodeSafe(&notify->nr_stuff.nr_Msg.nr_Port->mp_MsgList,
233 nm, tempNode)
235 if (notify->nr_MsgCount == 0)
237 break;
240 if (nm->nm_NReq == notify)
242 notify->nr_MsgCount--;
243 Remove((struct Node *)nm);
244 ReplyMsg((struct Message *)nm);
248 Enable();
252 break;
254 case FSA_CREATE_DIR:
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
260 to SendPkt()! */
262 if (fh == NULL)
264 /* Crash... well, we keep the lock for now */
266 packet->dp_Res1 = DOSFALSE;
267 packet->dp_Res2 = ERROR_NO_FREE_STORE;
268 break;
271 fh->fh_Unit = iofs->IOFS.io_Unit;
272 fh->fh_Device = iofs->IOFS.io_Device;
273 packet->dp_Res1 = (IPTR)MKBADDR(fh);
274 break;
277 case FSA_SAME_LOCK:
278 packet->dp_Res1 = (IPTR)(iofs->io_Union.io_SAME_LOCK.io_Same == LOCK_SAME);
279 packet->dp_Res2 = iofs->io_DosError;
280 break;
282 case FSA_EXAMINE_ALL:
283 /* TODO */
284 /* ExAll() seems to be flawed(?)... have to investigate this. */
285 break;
287 case FSA_DISK_INFO:
288 case FSA_INHIBIT:
289 packet->dp_Res1 = iofs->io_DosError == 0;
290 break;
292 case FSA_RELABEL:
293 packet->dp_Res1 = iofs->io_Union.io_RELABEL.io_Result;
294 break;
296 case FSA_MORE_CACHE:
297 packet->dp_Res1 = iofs->io_DosError == 0;
298 packet->dp_Res2 = iofs->io_Union.io_MORE_CACHE.io_NumBuffers;
299 break;
302 /* TODO */
303 case FSA_READ_SOFTLINK:
304 case FSA_FILE_MODE:
305 default:
306 kprintf("Filesystem action %i not handled yet in WaitPkt()\n",
307 iofs->IOFS.io_Command);
308 break;
311 return packet;