added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / devs / afs / arosdevice.c
blob364d0067fdcfef29ac07951be5c22017774a88b8
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #ifndef DEBUG
7 #define DEBUG 1
8 #endif
10 #include <proto/exec.h>
12 #include <exec/errors.h>
13 #include <exec/memory.h>
14 #include <exec/resident.h>
15 #include <exec/types.h>
16 #include <dos/dos.h>
18 #include <aros/libcall.h>
19 #include <aros/symbolsets.h>
20 #include <aros/debug.h>
22 #include "os.h"
23 #include "afshandler.h"
24 #include "volumes.h"
26 #include LC_LIBDEFS_FILE
28 extern void AFS_work();
30 static int GM_UNIQUENAME(Init)(LIBBASETYPEPTR afsbase)
32 struct Task *task;
33 APTR stack;
35 afsbase->dosbase = (struct DosLibrary *)OpenLibrary("dos.library",39);
36 if (afsbase->dosbase != NULL)
38 afsbase->intuitionbase = (struct IntuitionBase *)OpenLibrary("intuition.library",39);
39 if (afsbase->intuitionbase != NULL)
41 NEWLIST(&afsbase->device_list);
42 NEWLIST(&afsbase->port.mp_MsgList);
43 afsbase->port.mp_Node.ln_Type = NT_MSGPORT;
44 afsbase->port.mp_SigBit = SIGBREAKB_CTRL_F;
45 NEWLIST(&afsbase->rport.mp_MsgList);
46 afsbase->rport.mp_Node.ln_Type = NT_MSGPORT;
47 afsbase->rport.mp_Flags = PA_SIGNAL;
48 afsbase->rport.mp_SigBit = SIGB_SINGLE;
49 task = (struct Task *)AllocMem(sizeof(struct Task), MEMF_PUBLIC | MEMF_CLEAR);
50 if (task != NULL)
52 afsbase->port.mp_SigTask = task;
53 afsbase->port.mp_Flags = PA_IGNORE;
55 /* Open timer */
56 afsbase->timer_request = (struct timerequest *)
57 CreateIORequest(&afsbase->port,
58 sizeof(struct timerequest));
59 if (afsbase->timer_request != NULL)
61 if (OpenDevice("timer.device", UNIT_VBLANK,
62 (APTR)afsbase->timer_request, 0) == 0)
64 /* Create handler task */
65 NEWLIST(&task->tc_MemEntry);
66 task->tc_Node.ln_Type = NT_TASK;
67 task->tc_Node.ln_Name = "afs.handler task";
68 stack = AllocMem(AROS_STACKSIZE, MEMF_PUBLIC);
69 if (stack != NULL)
71 struct TagItem tags[] =
73 {TASKTAG_ARG1, (IPTR)afsbase},
74 {TAG_DONE }
77 task->tc_SPLower = stack;
78 task->tc_SPUpper = (BYTE *)stack+AROS_STACKSIZE;
79 #if AROS_STACK_GROWS_DOWNWARDS
80 task->tc_SPReg = (BYTE *)task->tc_SPUpper-SP_OFFSET;
81 #else
82 task->tc_SPReg = (BYTE *)task->tc_SPLower+SP_OFFSET;
83 #endif
85 if (NewAddTask(task,AFS_work,NULL,tags) != NULL)
86 return TRUE;
87 FreeMem(stack, AROS_STACKSIZE);
89 CloseDevice((struct IORequest *)afsbase->timer_request);
91 DeleteIORequest((struct IORequest *)afsbase->timer_request);
93 FreeMem(task, sizeof(struct Task));
95 CloseLibrary((struct Library *)afsbase->intuitionbase);
97 CloseLibrary((struct Library *)afsbase->dosbase);
99 return FALSE;
102 #include "baseredef.h"
104 static int GM_UNIQUENAME(Open)
106 LIBBASETYPEPTR afsbase,
107 struct IOFileSys *iofs,
108 ULONG unitnum,
109 ULONG flags
112 #if 0
113 struct Volume *volume;
114 #endif
116 afsbase->rport.mp_SigTask=FindTask(NULL);
117 #if 0
118 volume = initVolume
120 afsbase,
121 iofs->IOFS.io_Device,
122 iofs->io_Union.io_OpenDevice.io_DeviceName,
123 iofs->io_Union.io_OpenDevice.io_Unit,
124 (struct DosEnvec *)iofs->io_Union.io_OpenDevice.io_Environ,
125 &iofs->io_DosError
127 if (volume != NULL)
129 AddTail(&afsbase->device_list, &volume->ln);
130 iofs->IOFS.io_Unit = (struct Unit *)(&volume->ah);
131 iofs->IOFS.io_Device = &afsbase->device;
132 afsbase->device.dd_Library.lib_Flags &= ~LIBF_DELEXP;
133 iofs->IOFS.io_Error = 0;
135 return;
137 #else
138 iofs->IOFS.io_Command = -1;
139 PutMsg(&afsbase->port, &iofs->IOFS.io_Message);
140 WaitPort(&afsbase->rport);
141 (void)GetMsg(&afsbase->rport);
142 if (iofs->IOFS.io_Unit != NULL)
144 AddTail(&afsbase->device_list, &(((struct AfsHandle *)iofs->IOFS.io_Unit)->volume->ln));
145 iofs->IOFS.io_Device = &afsbase->device;
146 iofs->IOFS.io_Error = 0;
147 return TRUE;
149 #endif
150 iofs->IOFS.io_Error = IOERR_OPENFAIL;
151 return FALSE;
154 static int GM_UNIQUENAME(Expunge)(LIBBASETYPEPTR afsbase)
156 CloseDevice((struct IORequest *)afsbase->timer_request);
157 DeleteIORequest((struct IORequest *)afsbase->timer_request);
158 RemTask(afsbase->port.mp_SigTask);
159 FreeMem(((struct Task *)afsbase->port.mp_SigTask)->tc_SPLower,AROS_STACKSIZE);
160 FreeMem(afsbase->port.mp_SigTask, sizeof(struct Task));
161 CloseLibrary((struct Library *)IntuitionBase);
162 CloseLibrary((struct Library *)DOSBase);
163 return TRUE;
166 static int GM_UNIQUENAME(Close)
168 LIBBASETYPEPTR afsbase,
169 struct IOFileSys *iofs
172 struct Volume *volume;
174 afsbase->rport.mp_SigTask = FindTask(NULL);
175 /* iofs->IOFS.io_Command = -2;
176 PutMsg(&afsbase->port, &iofs->IOFS.io_Message);
177 WaitPort(&afsbase->rport);
178 (void)GetMsg(&afsbase->rport);
179 if (iofs->io_DosError)
180 return 0; // there is still something to do on this volume
182 volume = ((struct AfsHandle *)iofs->IOFS.io_Unit)->volume;
183 if (!volume->locklist)
185 Remove(&volume->ln);
186 uninitVolume(afsbase, volume);
187 return TRUE;
189 else
191 iofs->IOFS.io_Error = ERROR_OBJECT_IN_USE;
192 return FALSE;
196 ADD2INITLIB(GM_UNIQUENAME(Init),0)
197 ADD2OPENDEV(GM_UNIQUENAME(Open),0)
198 ADD2CLOSEDEV(GM_UNIQUENAME(Close),0)
199 ADD2EXPUNGELIB(GM_UNIQUENAME(Expunge),0)
201 AROS_LH1(void, beginio,
202 AROS_LHA(struct IOFileSys *, iofs, A1),
203 struct AFSBase *, afsbase, 5, Afs)
205 AROS_LIBFUNC_INIT
206 /* WaitIO will look into this */
207 iofs->IOFS.io_Message.mn_Node.ln_Type = NT_MESSAGE;
208 /* Nothing is done quick */
209 iofs->IOFS.io_Flags &= ~IOF_QUICK;
210 /* So let the device task do it */
211 PutMsg(&afsbase->port, &iofs->IOFS.io_Message);
212 AROS_LIBFUNC_EXIT
215 AROS_LH1(LONG, abortio,
216 AROS_LHA(struct IOFileSys *, iofs, A1),
217 struct AFSBase *, afsbase, 6, Afs)
219 AROS_LIBFUNC_INIT
220 return 0;
221 AROS_LIBFUNC_EXIT