added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / devs / afs / main.c
blob47d41d3dc089f9271a6f7500a2f6d1cfb5e4fa3e
1 /*
2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #ifndef DEBUG
7 #define DEBUG 0
8 #endif
10 #include <proto/dos.h>
11 #include <proto/exec.h>
13 #include <dos/filesystem.h>
14 #include <intuition/intuitionbase.h>
16 #include <aros/macros.h>
17 #include <aros/debug.h>
19 #include "afshandler.h"
20 #include "cache.h"
21 #include "error.h"
22 #include "filehandles1.h"
23 #include "filehandles2.h"
24 #include "filehandles3.h"
25 #include "misc.h"
26 #include "volumes.h"
28 #include "baseredef.h"
30 ULONG error;
32 static VOID startFlushTimer(struct AFSBase *afsbase)
34 struct timerequest *request;
36 /* Set up delay for next flush */
37 request = afsbase->timer_request;
38 request->tr_node.io_Command = TR_ADDREQUEST;
39 request->tr_time.tv_secs = 1;
40 request->tr_time.tv_micro = 0;
41 SendIO((struct IORequest *)afsbase->timer_request);
44 /*******************************************
45 Name : AFS_work
46 Descr.: main loop (get packets and answer (or not))
47 Input : proc - our process structure
48 Output: -
49 ********************************************/
50 void AFS_work(struct AFSBase *afsbase) {
51 struct IOFileSys *iofs;
52 struct AfsHandle *afshandle;
53 LONG retval;
55 afsbase->port.mp_SigBit = SIGBREAKB_CTRL_F;
56 afsbase->port.mp_Flags = PA_SIGNAL;
57 startFlushTimer(afsbase);
58 for (;;) {
59 while ((iofs=(struct IOFileSys *)GetMsg(&afsbase->port))!=NULL)
61 /* Flush dirty blocks on all volumes */
62 if (iofs->IOFS.io_Message.mn_Node.ln_Type == NT_REPLYMSG)
64 struct Volume *volume, *tail;
65 struct BlockCache *blockbuffer;
67 D(bug("[afs] Flush alarm rang.\n"));
68 volume = (struct Volume *)afsbase->device_list.lh_Head;
69 tail = (struct Volume *)&afsbase->device_list.lh_Tail;
70 while(volume != tail)
72 if ((volume->dostype == 0x444f5300) && mediumPresent(&volume->ioh))
74 flushCache(afsbase, volume);
75 blockbuffer = getBlock(afsbase, volume, volume->rootblock);
76 if ((blockbuffer->flags & BCF_WRITE) != 0)
78 writeBlock(afsbase, volume, blockbuffer, -1);
79 blockbuffer->flags &= ~BCF_WRITE;
82 volume = (struct Volume *)volume->ln.ln_Succ;
84 startFlushTimer(afsbase);
86 else
88 D(bug("[afs] got command %lu\n",iofs->IOFS.io_Command));
89 error=0;
90 afshandle = (struct AfsHandle *)iofs->IOFS.io_Unit;
91 switch (iofs->IOFS.io_Command)
93 case (UWORD)-1 :
95 struct Volume *volume;
96 volume = initVolume
98 afsbase,
99 iofs->IOFS.io_Device,
100 iofs->io_Union.io_OpenDevice.io_DeviceName,
101 iofs->io_Union.io_OpenDevice.io_Unit,
102 (struct DosEnvec *)iofs->io_Union.io_OpenDevice.io_Environ,
103 &iofs->io_DosError
105 if (volume != NULL)
106 iofs->IOFS.io_Unit = (struct Unit *)&volume->ah;
107 else
108 iofs->IOFS.io_Unit = NULL;
109 PutMsg(&afsbase->rport, &iofs->IOFS.io_Message);
111 continue;
112 case (UWORD)-2 :
114 struct Volume *volume;
115 volume=((struct AfsHandle *)iofs->IOFS.io_Unit)->volume;
116 if (volume->locklist != NULL)
118 error = ERROR_OBJECT_IN_USE;
120 else
122 uninitVolume(afsbase, volume);
123 error=0;
125 iofs->io_DosError = error;
126 PutMsg(&afsbase->rport, &iofs->IOFS.io_Message);
128 continue;
129 case FSA_SAME_LOCK :
130 iofs->io_Union.io_SAME_LOCK.io_Same=sameLock
132 iofs->io_Union.io_SAME_LOCK.io_Lock[0],
133 iofs->io_Union.io_SAME_LOCK.io_Lock[1]
135 break;
136 case FSA_IS_FILESYSTEM :
137 iofs->io_Union.io_IS_FILESYSTEM.io_IsFilesystem=TRUE;
138 break;
139 case FSA_INHIBIT :
140 error=inhibit
142 afsbase,
143 afshandle->volume,
144 iofs->io_Union.io_INHIBIT.io_Inhibit
146 break;
147 default:
148 if (mediumPresent(&afshandle->volume->ioh))
150 switch (iofs->IOFS.io_Command)
152 case FSA_OPEN : //locateObject, findupdate, findinput
153 iofs->IOFS.io_Unit=(struct Unit *)openf
155 afsbase,
156 afshandle,
157 iofs->io_Union.io_OPEN.io_Filename,
158 iofs->io_Union.io_OPEN.io_FileMode
160 break;
161 case FSA_CLOSE :
162 closef(afsbase, afshandle);
163 break;
164 case FSA_READ :
165 iofs->io_Union.io_READ.io_Length=readf
167 afsbase,
168 afshandle,
169 iofs->io_Union.io_READ.io_Buffer,
170 iofs->io_Union.io_READ.io_Length
172 break;
173 case FSA_WRITE :
174 iofs->io_Union.io_WRITE.io_Length=writef
176 afsbase,
177 afshandle,
178 iofs->io_Union.io_WRITE.io_Buffer,
179 iofs->io_Union.io_WRITE.io_Length
181 break;
182 case FSA_SEEK :
183 iofs->io_Union.io_SEEK.io_Offset=seek
185 afsbase,
186 afshandle,
187 iofs->io_Union.io_SEEK.io_Offset,
188 iofs->io_Union.io_SEEK.io_SeekMode
190 break;
191 case FSA_SET_FILE_SIZE :
192 D(bug("[afs] set file size nsy\n"));
193 error=ERROR_ACTION_NOT_KNOWN;
194 break;
195 case FSA_FILE_MODE :
196 D(bug("[afs] set file mode nsy\n"));
197 error=ERROR_ACTION_NOT_KNOWN;
198 break;
199 case FSA_EXAMINE :
200 error=examine
202 afsbase,
203 afshandle,
204 iofs->io_Union.io_EXAMINE.io_ead,
205 iofs->io_Union.io_EXAMINE.io_Size,
206 iofs->io_Union.io_EXAMINE.io_Mode,
207 &iofs->io_DirPos
209 break;
210 #warning FIXME: Disabled FSA_EXAMINE_ALL support since it seems to have bugs
211 #if 0
212 case FSA_EXAMINE_ALL :
213 error=examineAll
215 afsbase,
216 afshandle,
217 iofs->io_Union.io_EXAMINE_ALL.io_ead,
218 iofs->io_Union.io_EXAMINE_ALL.io_eac,
219 iofs->io_Union.io_EXAMINE_ALL.io_Size,
220 iofs->io_Union.io_EXAMINE_ALL.io_Mode
222 break;
223 #endif
224 case FSA_EXAMINE_NEXT :
225 error=examineNext
227 afsbase,
228 afshandle,
229 iofs->io_Union.io_EXAMINE_NEXT.io_fib
231 break;
232 case FSA_OPEN_FILE :
233 iofs->IOFS.io_Unit=(struct Unit *)openfile
235 afsbase,
236 afshandle,
237 iofs->io_Union.io_OPEN_FILE.io_Filename,
238 iofs->io_Union.io_OPEN_FILE.io_FileMode,
239 iofs->io_Union.io_OPEN_FILE.io_Protection
241 break;
242 case FSA_CREATE_DIR :
243 iofs->IOFS.io_Unit=(struct Unit *)createDir
245 afsbase,
246 afshandle,
247 iofs->io_Union.io_CREATE_DIR.io_Filename,
248 iofs->io_Union.io_CREATE_DIR.io_Protection
250 break;
251 case FSA_CREATE_HARDLINK :
252 D(bug("[afs] create hardlinks nsy\n"));
253 iofs->IOFS.io_Unit=0;
254 error=ERROR_ACTION_NOT_KNOWN;
255 break;
256 case FSA_CREATE_SOFTLINK :
257 D(bug("[afs] create softlinks nsy\n"));
258 iofs->IOFS.io_Unit=0;
259 error=ERROR_ACTION_NOT_KNOWN;
260 break;
261 case FSA_READ_SOFTLINK :
262 D(bug("[afs] read softlinks nsy\n"));
263 error=ERROR_ACTION_NOT_KNOWN;
264 break;
265 case FSA_RENAME :
266 error=renameObject
268 afsbase,
269 afshandle,
270 iofs->io_Union.io_RENAME.io_Filename,
271 iofs->io_Union.io_RENAME.io_NewName
273 break;
274 case FSA_DELETE_OBJECT :
275 error=deleteObject
277 afsbase,
278 afshandle,
279 iofs->io_Union.io_DELETE_OBJECT.io_Filename
281 break;
282 case FSA_SET_COMMENT :
283 error=setComment
285 afsbase,
286 afshandle,
287 iofs->io_Union.io_SET_COMMENT.io_Filename,
288 iofs->io_Union.io_SET_COMMENT.io_Comment
290 break;
291 case FSA_SET_PROTECT :
292 error=setProtect
294 afsbase,
295 afshandle,
296 iofs->io_Union.io_SET_PROTECT.io_Filename,
297 iofs->io_Union.io_SET_PROTECT.io_Protection
299 break;
300 case FSA_SET_OWNER :
301 D(bug("[afs] set owner nsy\n"));
302 error=ERROR_ACTION_NOT_KNOWN;
303 break;
304 case FSA_SET_DATE :
305 error=setDate
307 afsbase,
308 afshandle,
309 iofs->io_Union.io_SET_DATE.io_Filename,
310 &iofs->io_Union.io_SET_DATE.io_Date
312 break;
313 /* morecache */
314 case FSA_FORMAT :
315 error=format
317 afsbase,
318 afshandle->volume,
319 iofs->io_Union.io_FORMAT.io_VolumeName,
320 iofs->io_Union.io_FORMAT.io_DosType
322 break;
323 case FSA_RELABEL :
324 iofs->io_Union.io_RELABEL.io_Result=relabel
326 afsbase,
327 afshandle->volume,
328 iofs->io_Union.io_RELABEL.io_NewName
330 break;
331 case FSA_DISK_INFO :
332 error=getDiskInfo
333 (afshandle->volume, iofs->io_Union.io_INFO.io_Info);
334 break;
335 default :
336 D(bug("[afs] unknown fsa %d\n", iofs->IOFS.io_Command));
337 retval=DOSFALSE;
338 error=ERROR_ACTION_NOT_KNOWN;
341 else
343 switch (iofs->IOFS.io_Command)
345 case FSA_OPEN : /* locateObject, findupdate, findinput */
346 case FSA_CLOSE :
347 case FSA_READ :
348 case FSA_WRITE :
349 case FSA_SEEK :
350 case FSA_SET_FILE_SIZE :
351 case FSA_FILE_MODE :
352 case FSA_EXAMINE :
353 #warning FIXME: Disabled FSA_EXAMINE_ALL support
354 #if 0
355 case FSA_EXAMINE_ALL :
356 #endif
357 case FSA_EXAMINE_NEXT :
358 case FSA_OPEN_FILE :
359 case FSA_CREATE_DIR :
360 case FSA_CREATE_HARDLINK :
361 case FSA_CREATE_SOFTLINK :
362 case FSA_READ_SOFTLINK :
363 case FSA_RENAME :
364 case FSA_DELETE_OBJECT :
365 case FSA_SET_COMMENT :
366 case FSA_SET_PROTECT :
367 case FSA_SET_OWNER :
368 case FSA_SET_DATE :
369 case FSA_FORMAT :
370 case FSA_RELABEL :
371 case FSA_DISK_INFO :
372 retval= DOSFALSE;
373 error = ERROR_NO_DISK;
374 break;
375 default :
376 D(bug("[afs] unknown fsa %d\n", iofs->IOFS.io_Command));
377 retval= DOSFALSE;
378 error = ERROR_ACTION_NOT_KNOWN;
382 D(checkCache(afsbase, afshandle->volume));
383 iofs->io_DosError = error;
384 ReplyMsg(&iofs->IOFS.io_Message);
387 checkDeviceFlags(afsbase);
388 Wait(1<<afsbase->port.mp_SigBit);