2 Copyright © 1995-2008, 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>
21 #include LC_LIBDEFS_FILE
25 static int OpenDev(LIBBASETYPEPTR nilbase
, struct IOFileSys
*iofs
);
27 static int GM_UNIQUENAME(Init
)(LIBBASETYPEPTR nilbase
)
30 * Modules compiled with noexpunge always have seglist == NULL
31 * The seglist is not kept as it is not needed because the module never
33 if (GM_SEGLIST_FIELD(nilbase)==NULL) /* Are we a ROM module? * /
36 struct DeviceNode
*dn
;
37 /* Install NIL: handler into device list
39 * KLUDGE: The mountlists for NIL: should be into dos.library bootstrap routines.
42 if((dn
= AllocMem(sizeof (struct DeviceNode
) + 4 + AROS_BSTR_MEMSIZE4LEN(3),
43 MEMF_CLEAR
|MEMF_PUBLIC
)
47 struct IOFileSys dummyiofs
;
49 if (OpenDev(nilbase
, &dummyiofs
))
51 BSTR s
= (BSTR
)MKBADDR(((IPTR
)dn
+ sizeof(struct DeviceNode
) + 3) & ~3);
53 ((struct Library
*)nilbase
)->lib_OpenCnt
++;
55 AROS_BSTR_putchar(s
, 0, 'N');
56 AROS_BSTR_putchar(s
, 1, 'I');
57 AROS_BSTR_putchar(s
, 2, 'L');
58 AROS_BSTR_setstrlen(s
, 3);
60 dn
->dn_Type
= DLT_DEVICE
;
61 dn
->dn_Ext
.dn_AROS
.dn_Unit
= dummyiofs
.IOFS
.io_Unit
;
62 dn
->dn_Ext
.dn_AROS
.dn_Device
= dummyiofs
.IOFS
.io_Device
;
63 dn
->dn_Handler
= NULL
;
64 dn
->dn_Startup
= NULL
;
66 dn
->dn_Ext
.dn_AROS
.dn_DevName
= AROS_BSTR_ADDR(dn
->dn_Name
);
68 if (AddDosEntry((struct DosList
*)dn
))
72 FreeMem(dn
, sizeof (struct DeviceNode
));
83 static int GM_UNIQUENAME(Open
)
85 LIBBASETYPEPTR nilbase
,
86 struct IOFileSys
*iofs
,
91 /* Mark Message as recently used. */
92 iofs
->IOFS
.io_Message
.mn_Node
.ln_Type
=NT_REPLYMSG
;
94 if (OpenDev(nilbase
, iofs
))
97 iofs
->IOFS
.io_Error
=IOERR_OPENFAIL
;
102 static int OpenDev(LIBBASETYPEPTR nilbase
, struct IOFileSys
*iofs
)
106 dev
=AllocMem(sizeof(ULONG
),MEMF_PUBLIC
|MEMF_CLEAR
);
109 iofs
->IOFS
.io_Unit
= (struct Unit
*)dev
;
110 iofs
->IOFS
.io_Device
= (struct Device
*)nilbase
;
111 iofs
->IOFS
.io_Error
= 0;
116 iofs
->io_DosError
=ERROR_NO_FREE_STORE
;
122 static int GM_UNIQUENAME(Close
)(LIBBASETYPEPTR nilbase
, struct IOFileSys
*iofs
)
126 dev
=(ULONG
*)iofs
->IOFS
.io_Unit
;
129 iofs
->io_DosError
=ERROR_OBJECT_IN_USE
;
133 /* Let any following attemps to use the device crash hard. */
134 FreeMem(dev
,sizeof(ULONG
));
140 ADD2INITLIB(GM_UNIQUENAME(Init
),0)
141 ADD2OPENDEV(GM_UNIQUENAME(Open
),0)
142 ADD2CLOSEDEV(GM_UNIQUENAME(Close
),0)
144 AROS_LH1(void, beginio
,
145 AROS_LHA(struct IOFileSys
*, iofs
, A1
),
146 struct nilbase
*, nilbase
, 5, Nil
)
152 Do everything quick no matter what. This is possible
153 because I never need to Wait().
155 switch(iofs
->IOFS
.io_Command
)
159 /* No names allowed on NIL: */
160 if (iofs
->io_Union
.io_NamedFile
.io_Filename
[0])
162 error
=ERROR_OBJECT_NOT_FOUND
;
166 ++*(ULONG
*)iofs
->IOFS
.io_Unit
;
171 iofs
->io_Union
.io_READ
.io_Length
=0;
178 iofs
->io_Union
.io_SEEK
.io_Offset
= 0;
183 --*(ULONG
*)iofs
->IOFS
.io_Unit
;
187 case FSA_IS_INTERACTIVE
:
188 iofs
->io_Union
.io_IS_INTERACTIVE
.io_IsInteractive
= TRUE
;
190 case FSA_SET_FILE_SIZE
:
192 case FSA_EXAMINE_NEXT
:
193 case FSA_EXAMINE_ALL
:
195 case FSA_CREATE_HARDLINK
:
196 case FSA_CREATE_SOFTLINK
:
198 case FSA_DELETE_OBJECT
:
199 error
= ERROR_NOT_IMPLEMENTED
;
203 error
= ERROR_ACTION_NOT_KNOWN
;
208 iofs
->io_DosError
=error
;
210 /* If the quick bit is not set send the message to the port */
211 if(!(iofs
->IOFS
.io_Flags
&IOF_QUICK
))
212 ReplyMsg(&iofs
->IOFS
.io_Message
);
217 AROS_LH1(LONG
, abortio
,
218 AROS_LHA(struct IOFileSys
*, iofs
, A1
),
219 struct nilbase
*, nilbase
, 6, Nil
)
222 /* Everything already done. */