5 Copyright (C) 2001-2008 Neil Cafferkey
6 Copyright (C) 2011 The AROS Development Team
8 This file is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation; either version 2.1 of the
11 License, or (at your option) any later version.
13 This file is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this file; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 #include <aros/debug.h>
26 #include <aros/asmcall.h>
28 #include "handler_protos.h"
31 /* Global variables */
34 struct ExecBase
*SysBase
;
40 extern struct ExecBase
*AbsExecBase
;
43 /* Function prototypes */
45 static struct DosPacket
*GetPacket(struct MsgPort
*port
);
46 static VOID
ReplyPacket(struct MsgPort
*proc_port
, struct DosPacket
*packet
,
47 PINT result1
, PINT result2
);
48 static TEXT
*BStr(struct Handler
*h
, UBYTE
*b_str
);
49 static TEXT
*BStr2(struct Handler
*h
, UBYTE
*b_str
);
52 LONG
RAMMain(struct ExecBase
*SysBase
)
57 struct Handler
*handler
;
58 struct MsgPort
*proc_port
;
59 struct DosPacket
*packet
;
65 struct Message
*message
;
68 handler
= AllocMem(sizeof(struct Handler
), MEMF_CLEAR
);
73 SysBase
= AbsExecBase
;
76 DOSBase
= (struct DosLibrary
*)OpenLibrary(DOSNAME
, DOS_VERSION
);
78 FreeMem(handler
, sizeof(struct Handler
));
82 /* Process start-up packet */
84 proc_port
= &((*(struct Process
*)FindTask(NULL
)).pr_MsgPort
);
87 packet
= GetPacket(proc_port
);
89 exit
= CmdStartup(handler
, BStr(handler
, BADDR(packet
->dp_Arg1
)),
90 BADDR(packet
->dp_Arg3
), proc_port
);
92 ReplyPacket(proc_port
, packet
, DOSBOOL(!exit
), IoErr());
94 /* Set up port signals */
96 port_signals
= 1 << (proc_port
->mp_SigBit
);
97 Signal(proc_port
->mp_SigTask
, port_signals
);
99 port_signals
|= 1 << (handler
->notify_port
->mp_SigBit
);
101 /* Service packet requests */
107 /* Accept returning messages from notification clients */
109 while((message
= GetMsg(handler
->notify_port
)) != NULL
)
111 ReceiveNotifyReply(handler
, (APTR
)message
);
114 /* Service packet requests */
116 while((packet
= GetPacket(proc_port
)) != NULL
)
121 switch(packet
->dp_Type
)
130 case ACTION_IS_FILESYSTEM
:
132 if(!CmdIsFileSystem())
136 case ACTION_FINDOUTPUT
:
138 if(!CmdFind(handler
, BADDR(packet
->dp_Arg1
),
139 BADDR(packet
->dp_Arg2
), BStr(handler
, BADDR(packet
->dp_Arg3
)),
144 case ACTION_FINDUPDATE
:
146 if(!CmdFind(handler
, BADDR(packet
->dp_Arg1
),
147 BADDR(packet
->dp_Arg2
), BStr(handler
, BADDR(packet
->dp_Arg3
)),
152 case ACTION_FINDINPUT
:
154 if(!CmdFind(handler
, BADDR(packet
->dp_Arg1
),
155 BADDR(packet
->dp_Arg2
), BStr(handler
, BADDR(packet
->dp_Arg3
)),
160 case ACTION_FH_FROM_LOCK
:
162 result
= CmdFHFromLock(handler
, BADDR(packet
->dp_Arg1
),
163 BADDR(packet
->dp_Arg2
));
168 if(!CmdEnd(handler
, (APTR
)packet
->dp_Arg1
))
174 result
= CmdRead(handler
, (struct Opening
*)packet
->dp_Arg1
,
175 (UBYTE
*)packet
->dp_Arg2
, packet
->dp_Arg3
);
180 result
= CmdWrite(handler
, (struct Opening
*)packet
->dp_Arg1
,
181 (UBYTE
*)packet
->dp_Arg2
, packet
->dp_Arg3
);
185 result
= CmdSeek(handler
, (struct Opening
*)packet
->dp_Arg1
,
186 packet
->dp_Arg2
, packet
->dp_Arg3
);
189 case ACTION_SET_FILE_SIZE
:
191 result
= CmdSetFileSize(handler
, (APTR
)packet
->dp_Arg1
,
192 packet
->dp_Arg2
, packet
->dp_Arg3
);
195 case ACTION_LOCATE_OBJECT
:
197 result
= (PINT
)MKBADDR(CmdLocateObject(handler
,
198 BADDR(packet
->dp_Arg1
), BStr(handler
, BADDR(packet
->dp_Arg2
)),
202 case ACTION_FREE_LOCK
:
204 if(!CmdFreeLock(handler
, BADDR(packet
->dp_Arg1
)))
208 case ACTION_COPY_DIR
:
210 result
= (PINT
)MKBADDR(CmdCopyDir(handler
, BADDR(packet
->dp_Arg1
)));
213 case ACTION_COPY_DIR_FH
:
215 result
= (PINT
)MKBADDR(CmdCopyDirFH(handler
, (APTR
)packet
->dp_Arg1
));
220 result
= (PINT
)MKBADDR(CmdParent(handler
, BADDR(packet
->dp_Arg1
)));
223 case ACTION_PARENT_FH
:
225 result
= (PINT
)MKBADDR(CmdParentFH(handler
, (APTR
)packet
->dp_Arg1
));
228 case ACTION_SAME_LOCK
:
230 if(!CmdSameLock(handler
, BADDR(packet
->dp_Arg1
), BADDR(packet
->dp_Arg2
)))
234 case ACTION_CREATE_DIR
:
236 result
= (PINT
)MKBADDR(CmdCreateDir(handler
, BADDR(packet
->dp_Arg1
),
237 BStr(handler
, BADDR(packet
->dp_Arg2
))));
240 case ACTION_EXAMINE_OBJECT
:
242 if(!CmdExamineObject(handler
, BADDR(packet
->dp_Arg1
),
243 BADDR(packet
->dp_Arg2
)))
247 case ACTION_EXAMINE_FH
:
249 if(!CmdExamineFH(handler
, (APTR
)packet
->dp_Arg1
,
250 BADDR(packet
->dp_Arg2
)))
254 case ACTION_EXAMINE_NEXT
:
256 if(!CmdExamineNext(handler
, BADDR(packet
->dp_Arg2
)))
260 case ACTION_EXAMINE_ALL
:
262 if(!CmdExamineAll(handler
, BADDR(packet
->dp_Arg1
),
263 (APTR
)packet
->dp_Arg2
, packet
->dp_Arg3
, packet
->dp_Arg4
,
264 (APTR
)packet
->dp_Arg5
))
268 case ACTION_EXAMINE_ALL_END
:
270 CmdExamineAllEnd(handler
, BADDR(packet
->dp_Arg1
),
271 (APTR
)packet
->dp_Arg2
, packet
->dp_Arg3
, packet
->dp_Arg4
,
272 (APTR
)packet
->dp_Arg5
);
277 if(!CmdInfo(handler
, BADDR(packet
->dp_Arg2
)))
281 case ACTION_DISK_INFO
:
283 if(!CmdInfo(handler
, BADDR(packet
->dp_Arg1
)))
287 case ACTION_SET_PROTECT
:
289 if(!CmdSetProtect(handler
, BADDR(packet
->dp_Arg2
),
290 BStr(handler
, BADDR(packet
->dp_Arg3
)), packet
->dp_Arg4
))
294 case ACTION_SET_COMMENT
:
296 if(!CmdSetComment(handler
, BADDR(packet
->dp_Arg2
),
297 BStr(handler
, BADDR(packet
->dp_Arg3
)),
298 BStr2(handler
, BADDR(packet
->dp_Arg4
))))
302 case ACTION_RENAME_OBJECT
:
304 if(!CmdRenameObject(handler
, BADDR(packet
->dp_Arg1
),
305 BStr(handler
, BADDR(packet
->dp_Arg2
)), BADDR(packet
->dp_Arg3
),
306 BStr2(handler
, BADDR(packet
->dp_Arg4
))))
310 case ACTION_RENAME_DISK
:
312 if(!CmdRenameDisk(handler
, BStr(handler
, BADDR(packet
->dp_Arg1
))))
316 case ACTION_SET_DATE
:
318 if(!CmdSetDate(handler
, BADDR(packet
->dp_Arg2
),
319 BStr(handler
, BADDR(packet
->dp_Arg3
)), (APTR
)packet
->dp_Arg4
))
323 case ACTION_DELETE_OBJECT
:
325 if(!CmdDeleteObject(handler
, BADDR(packet
->dp_Arg1
),
326 BStr(handler
, BADDR(packet
->dp_Arg2
))))
330 case ACTION_CURRENT_VOLUME
:
332 result
= (PINT
)MKBADDR(CmdCurrentVolume(handler
));
335 case ACTION_CHANGE_MODE
:
337 result
= CmdChangeMode(handler
, packet
->dp_Arg1
, BADDR(packet
->dp_Arg2
),
341 case ACTION_MAKE_LINK
:
343 link_target
= (APTR
)packet
->dp_Arg3
;
344 link_type
= packet
->dp_Arg4
;
345 if(link_type
== LINK_HARD
)
346 link_target
= BADDR(link_target
);
347 if(!CmdMakeLink(handler
, BADDR(packet
->dp_Arg1
),
348 BStr(handler
, BADDR(packet
->dp_Arg2
)), link_target
, link_type
))
352 case ACTION_READ_LINK
:
354 result
= CmdReadLink(handler
, BADDR(packet
->dp_Arg1
),
355 (APTR
)packet
->dp_Arg2
, (APTR
)packet
->dp_Arg3
,
359 case ACTION_WRITE_PROTECT
:
361 if(!CmdWriteProtect(handler
, packet
->dp_Arg1
,
362 (ULONG
)packet
->dp_Arg2
))
372 case ACTION_ADD_NOTIFY
:
374 if(!CmdAddNotify(handler
, (APTR
)packet
->dp_Arg1
))
378 case ACTION_REMOVE_NOTIFY
:
380 if(!CmdRemoveNotify(handler
, (APTR
)packet
->dp_Arg1
))
386 SetIoErr(ERROR_ACTION_NOT_KNOWN
);
389 ReplyPacket(proc_port
, packet
, result
, IoErr());
394 CloseLibrary((APTR
)DOSBase
);
396 DeleteHandler(handler
);
401 static struct DosPacket
*GetPacket(struct MsgPort
*port
)
403 struct Message
*message
;
404 struct DosPacket
*packet
;
406 message
= GetMsg(port
);
408 packet
= (struct DosPacket
*)((struct Node
*)message
)->ln_Name
;
417 static VOID
ReplyPacket(struct MsgPort
*proc_port
, struct DosPacket
*packet
,
418 PINT result1
, PINT result2
)
420 struct MsgPort
*port
;
421 struct Message
*message
;
423 port
= packet
->dp_Port
;
424 message
= packet
->dp_Link
;
426 packet
->dp_Port
= proc_port
;
427 packet
->dp_Res1
= result1
;
428 packet
->dp_Res2
= result2
;
430 PutMsg(port
, message
);
435 static TEXT
*BStr(struct Handler
*h
, UBYTE
*b_str
)
439 #ifdef AROS_FAST_BSTR
440 length
= StrSize(b_str
);
441 CopyMem(b_str
, h
->b_buffer
, length
);
445 CopyMem(b_str
+ 1, h
->b_buffer
, length
);
447 *(h
->b_buffer
+ length
) = '\0';
454 static TEXT
*BStr2(struct Handler
*h
, UBYTE
*b_str
)
458 #ifdef AROS_FAST_BSTR
459 length
= StrSize(b_str
);
460 CopyMem(b_str
, h
->b_buffer2
, length
);
464 CopyMem(b_str
+ 1, h
->b_buffer2
, length
);
466 *(h
->b_buffer2
+ length
) = '\0';
473 UBYTE
*MkBStr(struct Handler
*h
, TEXT
*str
)
477 length
= StrLen(str
);
478 #ifdef AROS_FAST_BSTR
479 CopyMem(str
, h
->b_buffer
, length
+ 1);
482 CopyMem(str
, h
->b_buffer
+ 1, length
);
483 *h
->b_buffer
= length
;