Reapplication of sonic's patches originally done in r29201 and r29210:
[tangerine.git] / rom / devs / filesys / afs / main.c
blob8f00ec645d587d3aae193222c8595fa7de229ade
1 /*
2 Copyright © 1995-2008, 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 if (afsbase->timer_flags & TIMER_ACTIVE) {
38 afsbase->timer_flags |= TIMER_RESTART;
39 } else {
40 D(bug("[afs] Starting timer\n"));
41 request = afsbase->timer_request;
42 request->tr_node.io_Command = TR_ADDREQUEST;
43 request->tr_time.tv_secs = 1;
44 request->tr_time.tv_micro = 0;
45 SendIO((struct IORequest *)afsbase->timer_request);
46 afsbase->timer_flags = TIMER_ACTIVE;
50 /*******************************************
51 Name : AFS_work
52 Descr.: main loop (get packets and answer (or not))
53 Input : proc - our process structure
54 Output: -
55 ********************************************/
56 void AFS_work(struct AFSBase *afsbase) {
57 struct IOFileSys *iofs;
58 struct AfsHandle *afshandle;
59 LONG retval;
61 afsbase->port.mp_SigBit = SIGBREAKB_CTRL_F;
62 afsbase->port.mp_Flags = PA_SIGNAL;
63 afsbase->timer_flags = 0;
64 for (;;) {
65 while ((iofs=(struct IOFileSys *)GetMsg(&afsbase->port))!=NULL)
67 /* Flush dirty blocks on all volumes */
68 if (iofs->IOFS.io_Message.mn_Node.ln_Type == NT_REPLYMSG)
70 afsbase->timer_flags &= ~TIMER_ACTIVE;
71 if (afsbase->timer_flags & TIMER_RESTART)
72 startFlushTimer(afsbase);
73 else {
74 struct Volume *volume, *tail;
75 struct BlockCache *blockbuffer;
77 D(bug("[afs] Flush alarm rang.\n"));
78 volume = (struct Volume *)afsbase->device_list.lh_Head;
79 tail = (struct Volume *)&afsbase->device_list.lh_Tail;
80 while(volume != tail)
82 if ((volume->dostype == 0x444f5300) && mediumPresent(&volume->ioh))
84 flushCache(afsbase, volume);
85 blockbuffer = getBlock(afsbase, volume, volume->rootblock);
86 if ((blockbuffer->flags & BCF_WRITE) != 0)
88 writeBlock(afsbase, volume, blockbuffer, -1);
89 blockbuffer->flags &= ~BCF_WRITE;
91 if (volume->ioh.flags & IOHF_MOTOR_OFF) {
92 D(bug("[afs 0x%08lX] turning off motor\n", volume));
93 motorOff(afsbase, &volume->ioh);
94 volume->ioh.flags &= ~IOHF_MOTOR_OFF;
97 volume = (struct Volume *)volume->ln.ln_Succ;
101 else
103 DB2(bug("[afs] got command %lu\n",iofs->IOFS.io_Command));
104 startFlushTimer(afsbase);
105 error=0;
106 afshandle = (struct AfsHandle *)iofs->IOFS.io_Unit;
107 switch (iofs->IOFS.io_Command)
109 case (UWORD)-1 :
111 struct Volume *volume;
112 volume = initVolume
114 afsbase,
115 iofs->IOFS.io_Device,
116 iofs->io_Union.io_OpenDevice.io_DeviceName,
117 iofs->io_Union.io_OpenDevice.io_Unit,
118 (struct DosEnvec *)iofs->io_Union.io_OpenDevice.io_Environ,
119 &iofs->io_DosError
121 if (volume != NULL)
122 iofs->IOFS.io_Unit = (struct Unit *)&volume->ah;
123 else
124 iofs->IOFS.io_Unit = NULL;
125 PutMsg(&afsbase->rport, &iofs->IOFS.io_Message);
127 continue;
128 case (UWORD)-2 :
130 struct Volume *volume;
131 volume=((struct AfsHandle *)iofs->IOFS.io_Unit)->volume;
132 if (volume->locklist != NULL)
134 error = ERROR_OBJECT_IN_USE;
136 else
138 uninitVolume(afsbase, volume);
139 error=0;
141 iofs->io_DosError = error;
142 PutMsg(&afsbase->rport, &iofs->IOFS.io_Message);
144 continue;
145 case FSA_SAME_LOCK :
146 iofs->io_Union.io_SAME_LOCK.io_Same=sameLock
148 iofs->io_Union.io_SAME_LOCK.io_Lock[0],
149 iofs->io_Union.io_SAME_LOCK.io_Lock[1]
151 break;
152 case FSA_IS_FILESYSTEM :
153 iofs->io_Union.io_IS_FILESYSTEM.io_IsFilesystem=TRUE;
154 break;
155 case FSA_INHIBIT :
156 error=inhibit
158 afsbase,
159 afshandle->volume,
160 iofs->io_Union.io_INHIBIT.io_Inhibit
162 break;
163 case FSA_CLOSE :
164 closef(afsbase, afshandle);
165 break;
166 default:
167 if (mediumPresent(&afshandle->volume->ioh))
169 switch (iofs->IOFS.io_Command)
171 case FSA_OPEN : //locateObject, findupdate, findinput
172 iofs->IOFS.io_Unit=(struct Unit *)openf
174 afsbase,
175 afshandle,
176 iofs->io_Union.io_OPEN.io_Filename,
177 iofs->io_Union.io_OPEN.io_FileMode
179 break;
180 case FSA_READ :
181 iofs->io_Union.io_READ.io_Length=readf
183 afsbase,
184 afshandle,
185 iofs->io_Union.io_READ.io_Buffer,
186 iofs->io_Union.io_READ.io_Length
188 break;
189 case FSA_WRITE :
190 iofs->io_Union.io_WRITE.io_Length=writef
192 afsbase,
193 afshandle,
194 iofs->io_Union.io_WRITE.io_Buffer,
195 iofs->io_Union.io_WRITE.io_Length
197 break;
198 case FSA_SEEK :
199 iofs->io_Union.io_SEEK.io_Offset=seek
201 afsbase,
202 afshandle,
203 iofs->io_Union.io_SEEK.io_Offset,
204 iofs->io_Union.io_SEEK.io_SeekMode
206 break;
207 case FSA_SET_FILE_SIZE :
208 iofs->io_Union.io_SEEK.io_Offset = setFileSize
210 afsbase,
211 afshandle,
212 iofs->io_Union.io_SEEK.io_Offset,
213 iofs->io_Union.io_SEEK.io_SeekMode
215 break;
216 case FSA_FILE_MODE :
217 D(bug("[afs] set file mode nsy\n"));
218 error=ERROR_ACTION_NOT_KNOWN;
219 break;
220 case FSA_EXAMINE :
221 error=examine
223 afsbase,
224 afshandle,
225 iofs->io_Union.io_EXAMINE.io_ead,
226 iofs->io_Union.io_EXAMINE.io_Size,
227 iofs->io_Union.io_EXAMINE.io_Mode,
228 &iofs->io_DirPos
230 break;
231 #warning FIXME: Disabled FSA_EXAMINE_ALL support since it seems to have bugs
232 #if 0
233 case FSA_EXAMINE_ALL :
234 error=examineAll
236 afsbase,
237 afshandle,
238 iofs->io_Union.io_EXAMINE_ALL.io_ead,
239 iofs->io_Union.io_EXAMINE_ALL.io_eac,
240 iofs->io_Union.io_EXAMINE_ALL.io_Size,
241 iofs->io_Union.io_EXAMINE_ALL.io_Mode
243 break;
244 #endif
245 case FSA_EXAMINE_NEXT :
246 error=examineNext
248 afsbase,
249 afshandle,
250 iofs->io_Union.io_EXAMINE_NEXT.io_fib
252 break;
253 case FSA_OPEN_FILE :
254 iofs->IOFS.io_Unit=(struct Unit *)openfile
256 afsbase,
257 afshandle,
258 iofs->io_Union.io_OPEN_FILE.io_Filename,
259 iofs->io_Union.io_OPEN_FILE.io_FileMode,
260 iofs->io_Union.io_OPEN_FILE.io_Protection
262 break;
263 case FSA_CREATE_DIR :
264 iofs->IOFS.io_Unit=(struct Unit *)createDir
266 afsbase,
267 afshandle,
268 iofs->io_Union.io_CREATE_DIR.io_Filename,
269 iofs->io_Union.io_CREATE_DIR.io_Protection
271 break;
272 case FSA_CREATE_HARDLINK :
273 D(bug("[afs] create hardlinks nsy\n"));
274 iofs->IOFS.io_Unit=0;
275 error=ERROR_ACTION_NOT_KNOWN;
276 break;
277 case FSA_CREATE_SOFTLINK :
278 D(bug("[afs] create softlinks nsy\n"));
279 iofs->IOFS.io_Unit=0;
280 error=ERROR_ACTION_NOT_KNOWN;
281 break;
282 case FSA_READ_SOFTLINK :
283 D(bug("[afs] read softlinks nsy\n"));
284 error=ERROR_ACTION_NOT_KNOWN;
285 break;
286 case FSA_RENAME :
287 error=renameObject
289 afsbase,
290 afshandle,
291 iofs->io_Union.io_RENAME.io_Filename,
292 iofs->io_Union.io_RENAME.io_NewName
294 break;
295 case FSA_DELETE_OBJECT :
296 error=deleteObject
298 afsbase,
299 afshandle,
300 iofs->io_Union.io_DELETE_OBJECT.io_Filename
302 break;
303 case FSA_SET_COMMENT :
304 error=setComment
306 afsbase,
307 afshandle,
308 iofs->io_Union.io_SET_COMMENT.io_Filename,
309 iofs->io_Union.io_SET_COMMENT.io_Comment
311 break;
312 case FSA_SET_PROTECT :
313 error=setProtect
315 afsbase,
316 afshandle,
317 iofs->io_Union.io_SET_PROTECT.io_Filename,
318 iofs->io_Union.io_SET_PROTECT.io_Protection
320 break;
321 case FSA_SET_OWNER :
322 D(bug("[afs] set owner nsy\n"));
323 error=ERROR_ACTION_NOT_KNOWN;
324 break;
325 case FSA_SET_DATE :
326 error=setDate
328 afsbase,
329 afshandle,
330 iofs->io_Union.io_SET_DATE.io_Filename,
331 &iofs->io_Union.io_SET_DATE.io_Date
333 break;
334 /* morecache */
335 case FSA_FORMAT :
336 error=format
338 afsbase,
339 afshandle->volume,
340 iofs->io_Union.io_FORMAT.io_VolumeName,
341 iofs->io_Union.io_FORMAT.io_DosType
343 break;
344 case FSA_RELABEL :
345 iofs->io_Union.io_RELABEL.io_Result=relabel
347 afsbase,
348 afshandle->volume,
349 iofs->io_Union.io_RELABEL.io_NewName
351 break;
352 case FSA_DISK_INFO :
353 error=getDiskInfo
354 (afshandle->volume, iofs->io_Union.io_INFO.io_Info);
355 break;
356 default :
357 D(bug("[afs] unknown fsa %d\n", iofs->IOFS.io_Command));
358 retval=DOSFALSE;
359 error=ERROR_ACTION_NOT_KNOWN;
362 else
364 switch (iofs->IOFS.io_Command)
366 case FSA_OPEN : /* locateObject, findupdate, findinput */
367 case FSA_READ :
368 case FSA_WRITE :
369 case FSA_SEEK :
370 case FSA_SET_FILE_SIZE :
371 case FSA_FILE_MODE :
372 case FSA_EXAMINE :
373 #warning FIXME: Disabled FSA_EXAMINE_ALL support
374 #if 0
375 case FSA_EXAMINE_ALL :
376 #endif
377 case FSA_EXAMINE_NEXT :
378 case FSA_OPEN_FILE :
379 case FSA_CREATE_DIR :
380 case FSA_CREATE_HARDLINK :
381 case FSA_CREATE_SOFTLINK :
382 case FSA_READ_SOFTLINK :
383 case FSA_RENAME :
384 case FSA_DELETE_OBJECT :
385 case FSA_SET_COMMENT :
386 case FSA_SET_PROTECT :
387 case FSA_SET_OWNER :
388 case FSA_SET_DATE :
389 case FSA_FORMAT :
390 case FSA_RELABEL :
391 case FSA_DISK_INFO :
392 retval= DOSFALSE;
393 error = ERROR_NO_DISK;
394 break;
395 default :
396 D(bug("[afs] unknown fsa %d\n", iofs->IOFS.io_Command));
397 retval= DOSFALSE;
398 error = ERROR_ACTION_NOT_KNOWN;
402 D(checkCache(afsbase, afshandle->volume));
403 iofs->io_DosError = error;
404 ReplyMsg(&iofs->IOFS.io_Message);
407 checkDeviceFlags(afsbase);
408 Wait(1<<afsbase->port.mp_SigBit);