Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / devs / nil_handler / nil_handler.c
blob52df3a2aec36475a391fdad2040a887c817104b2
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang:
7 */
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
23 #include <string.h>
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
32 * can be expunged
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;
65 dn->dn_Name = s;
66 dn->dn_Ext.dn_AROS.dn_DevName = AROS_BSTR_ADDR(dn->dn_Name);
68 if (AddDosEntry((struct DosList *)dn))
69 return TRUE;
72 FreeMem(dn, sizeof (struct DeviceNode));
76 else
77 return TRUE;
80 return FALSE;
83 static int GM_UNIQUENAME(Open)
85 LIBBASETYPEPTR nilbase,
86 struct IOFileSys *iofs,
87 ULONG unitnum,
88 ULONG flags
91 /* Mark Message as recently used. */
92 iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
94 if (OpenDev(nilbase, iofs))
95 return TRUE;
97 iofs->IOFS.io_Error=IOERR_OPENFAIL;
99 return FALSE;
102 static int OpenDev(LIBBASETYPEPTR nilbase, struct IOFileSys *iofs)
104 ULONG *dev;
106 dev=AllocMem(sizeof(ULONG),MEMF_PUBLIC|MEMF_CLEAR);
107 if(dev!=NULL)
109 iofs->IOFS.io_Unit = (struct Unit *)dev;
110 iofs->IOFS.io_Device = (struct Device *)nilbase;
111 iofs->IOFS.io_Error = 0;
112 return TRUE;
114 else
116 iofs->io_DosError=ERROR_NO_FREE_STORE;
117 return FALSE;
122 static int GM_UNIQUENAME(Close)(LIBBASETYPEPTR nilbase, struct IOFileSys *iofs)
124 ULONG *dev;
126 dev=(ULONG *)iofs->IOFS.io_Unit;
127 if(*dev)
129 iofs->io_DosError=ERROR_OBJECT_IN_USE;
130 return FALSE;
133 /* Let any following attemps to use the device crash hard. */
134 FreeMem(dev,sizeof(ULONG));
135 iofs->io_DosError=0;
137 return TRUE;
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)
148 AROS_LIBFUNC_INIT
149 LONG error=0;
152 Do everything quick no matter what. This is possible
153 because I never need to Wait().
155 switch(iofs->IOFS.io_Command)
157 case FSA_OPEN:
158 case FSA_OPEN_FILE:
159 /* No names allowed on NIL: */
160 if (iofs->io_Union.io_NamedFile.io_Filename[0])
162 error=ERROR_OBJECT_NOT_FOUND;
163 break;
165 Forbid();
166 ++*(ULONG *)iofs->IOFS.io_Unit;
167 Permit();
168 break;
170 case FSA_READ:
171 iofs->io_Union.io_READ.io_Length=0;
172 break;
174 case FSA_WRITE:
175 break;
177 case FSA_SEEK:
178 iofs->io_Union.io_SEEK.io_Offset = 0;
179 break;
181 case FSA_CLOSE:
182 Forbid();
183 --*(ULONG *)iofs->IOFS.io_Unit;
184 Permit();
185 break;
187 case FSA_IS_INTERACTIVE:
188 iofs->io_Union.io_IS_INTERACTIVE.io_IsInteractive = TRUE;
189 break;
190 case FSA_SET_FILE_SIZE:
191 case FSA_EXAMINE:
192 case FSA_EXAMINE_NEXT:
193 case FSA_EXAMINE_ALL:
194 case FSA_CREATE_DIR:
195 case FSA_CREATE_HARDLINK:
196 case FSA_CREATE_SOFTLINK:
197 case FSA_RENAME:
198 case FSA_DELETE_OBJECT:
199 error = ERROR_NOT_IMPLEMENTED;
200 break;
202 default:
203 error = ERROR_ACTION_NOT_KNOWN;
204 break;
207 /* Set error code */
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);
214 AROS_LIBFUNC_EXIT
217 AROS_LH1(LONG, abortio,
218 AROS_LHA(struct IOFileSys *, iofs, A1),
219 struct nilbase *, nilbase, 6, Nil)
221 AROS_LIBFUNC_INIT
222 /* Everything already done. */
223 return 0;
224 AROS_LIBFUNC_EXIT