2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
8 #include <exec/errors.h>
9 #include <exec/resident.h>
10 #include <exec/memory.h>
11 #include <libraries/expansion.h>
12 #include <proto/exec.h>
13 #include <proto/expansion.h>
14 #include <utility/tagitem.h>
15 #include <dos/dosextens.h>
16 #include <dos/filesystem.h>
17 #include <proto/dos.h>
18 #include <aros/libcall.h>
19 #include <aros/symbolsets.h>
20 #if defined(__GNUC__) || defined(__INTEL_COMPILER)
21 #include "nil_handler_gcc.h"
24 #include LC_LIBDEFS_FILE
28 static int OpenDev(LIBBASETYPEPTR nilbase
, struct IOFileSys
*iofs
);
30 static int GM_UNIQUENAME(Init
)(LIBBASETYPEPTR nilbase
)
32 nilbase
->dosbase
=(struct DosLibrary
*)OpenLibrary("dos.library",39);
33 if(nilbase
->dosbase
!=NULL
)
35 if (nilbase
->seglist
==NULL
) /* Are we a ROM module? */
37 struct DeviceNode
*dn
;
38 /* Install NIL: handler into device list
40 * KLUDGE: The mountlists for NIL: should be into dos.library bootstrap routines.
43 if((dn
= AllocMem(sizeof (struct DeviceNode
) + 4 + AROS_BSTR_MEMSIZE4LEN(3),
44 MEMF_CLEAR
|MEMF_PUBLIC
)))
46 struct IOFileSys dummyiofs
;
48 if (OpenDev(nilbase
, &dummyiofs
))
50 BSTR s
= (BSTR
)MKBADDR(((IPTR
)dn
+ sizeof(struct DeviceNode
) + 3) & ~3);
52 nilbase
->device
.dd_Library
.lib_OpenCnt
++;
54 AROS_BSTR_putchar(s
, 0, 'N');
55 AROS_BSTR_putchar(s
, 1, 'I');
56 AROS_BSTR_putchar(s
, 2, 'L');
57 AROS_BSTR_setstrlen(s
, 3);
59 dn
->dn_Type
= DLT_DEVICE
;
60 dn
->dn_Ext
.dn_AROS
.dn_Unit
= dummyiofs
.IOFS
.io_Unit
;
61 dn
->dn_Ext
.dn_AROS
.dn_Device
= dummyiofs
.IOFS
.io_Device
;
62 dn
->dn_Handler
= NULL
;
63 dn
->dn_Startup
= NULL
;
65 dn
->dn_Ext
.dn_AROS
.dn_DevName
= AROS_BSTR_ADDR(dn
->dn_Name
);
67 if (AddDosEntry((struct DosList
*)dn
))
71 FreeMem(dn
, sizeof (struct DeviceNode
));
81 static int GM_UNIQUENAME(Open
)
83 LIBBASETYPEPTR nilbase
,
84 struct IOFileSys
*iofs
,
89 /* Mark Message as recently used. */
90 iofs
->IOFS
.io_Message
.mn_Node
.ln_Type
=NT_REPLYMSG
;
92 if (OpenDev(nilbase
, iofs
))
95 iofs
->IOFS
.io_Error
=IOERR_OPENFAIL
;
100 static int OpenDev(LIBBASETYPEPTR nilbase
, struct IOFileSys
*iofs
)
104 dev
=AllocMem(sizeof(ULONG
),MEMF_PUBLIC
|MEMF_CLEAR
);
107 iofs
->IOFS
.io_Unit
= (struct Unit
*)dev
;
108 iofs
->IOFS
.io_Device
= &nilbase
->device
;
109 iofs
->IOFS
.io_Error
= 0;
114 iofs
->io_DosError
=ERROR_NO_FREE_STORE
;
120 static int GM_UNIQUENAME(Close
)(LIBBASETYPEPTR nilbase
, struct IOFileSys
*iofs
)
124 dev
=(ULONG
*)iofs
->IOFS
.io_Unit
;
127 iofs
->io_DosError
=ERROR_OBJECT_IN_USE
;
131 /* Let any following attemps to use the device crash hard. */
132 FreeMem(dev
,sizeof(ULONG
));
138 ADD2INITLIB(GM_UNIQUENAME(Init
),0)
139 ADD2OPENDEV(GM_UNIQUENAME(Open
),0)
140 ADD2CLOSEDEV(GM_UNIQUENAME(Close
),0)
142 AROS_LH1(void, beginio
,
143 AROS_LHA(struct IOFileSys
*, iofs
, A1
),
144 struct nilbase
*, nilbase
, 5, Nil
)
150 Do everything quick no matter what. This is possible
151 because I never need to Wait().
153 switch(iofs
->IOFS
.io_Command
)
157 /* No names allowed on NIL: */
158 if (iofs
->io_Union
.io_NamedFile
.io_Filename
[0])
160 error
=ERROR_OBJECT_NOT_FOUND
;
164 ++*(ULONG
*)iofs
->IOFS
.io_Unit
;
169 iofs
->io_Union
.io_READ
.io_Length
=0;
176 iofs
->io_Union
.io_SEEK
.io_Offset
= 0;
181 --*(ULONG
*)iofs
->IOFS
.io_Unit
;
185 case FSA_IS_INTERACTIVE
:
186 iofs
->io_Union
.io_IS_INTERACTIVE
.io_IsInteractive
= TRUE
;
188 case FSA_SET_FILE_SIZE
:
190 case FSA_EXAMINE_NEXT
:
191 case FSA_EXAMINE_ALL
:
193 case FSA_CREATE_HARDLINK
:
194 case FSA_CREATE_SOFTLINK
:
196 case FSA_DELETE_OBJECT
:
197 error
= ERROR_NOT_IMPLEMENTED
;
201 error
= ERROR_ACTION_NOT_KNOWN
;
206 iofs
->io_DosError
=error
;
208 /* If the quick bit is not set send the message to the port */
209 if(!(iofs
->IOFS
.io_Flags
&IOF_QUICK
))
210 ReplyMsg(&iofs
->IOFS
.io_Message
);
215 AROS_LH1(LONG
, abortio
,
216 AROS_LHA(struct IOFileSys
*, iofs
, A1
),
217 struct nilbase
*, nilbase
, 6, Nil
)
220 /* Everything already done. */