2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
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"
22 #include "filehandles1.h"
23 #include "filehandles2.h"
24 #include "filehandles3.h"
28 #include "baseredef.h"
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
;
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 /*******************************************
52 Descr.: main loop (get packets and answer (or not))
53 Input : proc - our process structure
55 ********************************************/
56 void AFS_work(struct AFSBase
*afsbase
) {
57 struct IOFileSys
*iofs
;
58 struct AfsHandle
*afshandle
;
61 afsbase
->port
.mp_SigBit
= SIGBREAKB_CTRL_F
;
62 afsbase
->port
.mp_Flags
= PA_SIGNAL
;
63 afsbase
->timer_flags
= 0;
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
);
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
;
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
;
103 DB2(bug("[afs] got command %lu\n",iofs
->IOFS
.io_Command
));
104 startFlushTimer(afsbase
);
106 afshandle
= (struct AfsHandle
*)iofs
->IOFS
.io_Unit
;
107 switch (iofs
->IOFS
.io_Command
)
111 struct Volume
*volume
;
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
,
122 iofs
->IOFS
.io_Unit
= (struct Unit
*)&volume
->ah
;
124 iofs
->IOFS
.io_Unit
= NULL
;
125 PutMsg(&afsbase
->rport
, &iofs
->IOFS
.io_Message
);
130 struct Volume
*volume
;
131 volume
=((struct AfsHandle
*)iofs
->IOFS
.io_Unit
)->volume
;
132 if (volume
->locklist
!= NULL
)
134 error
= ERROR_OBJECT_IN_USE
;
138 uninitVolume(afsbase
, volume
);
141 iofs
->io_DosError
= error
;
142 PutMsg(&afsbase
->rport
, &iofs
->IOFS
.io_Message
);
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]
152 case FSA_IS_FILESYSTEM
:
153 iofs
->io_Union
.io_IS_FILESYSTEM
.io_IsFilesystem
=TRUE
;
160 iofs
->io_Union
.io_INHIBIT
.io_Inhibit
164 closef(afsbase
, afshandle
);
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
176 iofs
->io_Union
.io_OPEN
.io_Filename
,
177 iofs
->io_Union
.io_OPEN
.io_FileMode
181 iofs
->io_Union
.io_READ
.io_Length
=readf
185 iofs
->io_Union
.io_READ
.io_Buffer
,
186 iofs
->io_Union
.io_READ
.io_Length
190 iofs
->io_Union
.io_WRITE
.io_Length
=writef
194 iofs
->io_Union
.io_WRITE
.io_Buffer
,
195 iofs
->io_Union
.io_WRITE
.io_Length
199 iofs
->io_Union
.io_SEEK
.io_Offset
=seek
203 iofs
->io_Union
.io_SEEK
.io_Offset
,
204 iofs
->io_Union
.io_SEEK
.io_SeekMode
207 case FSA_SET_FILE_SIZE
:
208 iofs
->io_Union
.io_SEEK
.io_Offset
= setFileSize
212 iofs
->io_Union
.io_SEEK
.io_Offset
,
213 iofs
->io_Union
.io_SEEK
.io_SeekMode
217 D(bug("[afs] set file mode nsy\n"));
218 error
=ERROR_ACTION_NOT_KNOWN
;
225 iofs
->io_Union
.io_EXAMINE
.io_ead
,
226 iofs
->io_Union
.io_EXAMINE
.io_Size
,
227 iofs
->io_Union
.io_EXAMINE
.io_Mode
,
231 #warning FIXME: Disabled FSA_EXAMINE_ALL support since it seems to have bugs
233 case FSA_EXAMINE_ALL
:
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
245 case FSA_EXAMINE_NEXT
:
250 iofs
->io_Union
.io_EXAMINE_NEXT
.io_fib
254 iofs
->IOFS
.io_Unit
=(struct Unit
*)openfile
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
263 case FSA_CREATE_DIR
:
264 iofs
->IOFS
.io_Unit
=(struct Unit
*)createDir
268 iofs
->io_Union
.io_CREATE_DIR
.io_Filename
,
269 iofs
->io_Union
.io_CREATE_DIR
.io_Protection
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
;
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
;
282 case FSA_READ_SOFTLINK
:
283 D(bug("[afs] read softlinks nsy\n"));
284 error
=ERROR_ACTION_NOT_KNOWN
;
291 iofs
->io_Union
.io_RENAME
.io_Filename
,
292 iofs
->io_Union
.io_RENAME
.io_NewName
295 case FSA_DELETE_OBJECT
:
300 iofs
->io_Union
.io_DELETE_OBJECT
.io_Filename
303 case FSA_SET_COMMENT
:
308 iofs
->io_Union
.io_SET_COMMENT
.io_Filename
,
309 iofs
->io_Union
.io_SET_COMMENT
.io_Comment
312 case FSA_SET_PROTECT
:
317 iofs
->io_Union
.io_SET_PROTECT
.io_Filename
,
318 iofs
->io_Union
.io_SET_PROTECT
.io_Protection
322 D(bug("[afs] set owner nsy\n"));
323 error
=ERROR_ACTION_NOT_KNOWN
;
330 iofs
->io_Union
.io_SET_DATE
.io_Filename
,
331 &iofs
->io_Union
.io_SET_DATE
.io_Date
340 iofs
->io_Union
.io_FORMAT
.io_VolumeName
,
341 iofs
->io_Union
.io_FORMAT
.io_DosType
345 iofs
->io_Union
.io_RELABEL
.io_Result
=relabel
349 iofs
->io_Union
.io_RELABEL
.io_NewName
354 (afshandle
->volume
, iofs
->io_Union
.io_INFO
.io_Info
);
357 D(bug("[afs] unknown fsa %d\n", iofs
->IOFS
.io_Command
));
359 error
=ERROR_ACTION_NOT_KNOWN
;
364 switch (iofs
->IOFS
.io_Command
)
366 case FSA_OPEN
: /* locateObject, findupdate, findinput */
370 case FSA_SET_FILE_SIZE
:
373 #warning FIXME: Disabled FSA_EXAMINE_ALL support
375 case FSA_EXAMINE_ALL
:
377 case FSA_EXAMINE_NEXT
:
379 case FSA_CREATE_DIR
:
380 case FSA_CREATE_HARDLINK
:
381 case FSA_CREATE_SOFTLINK
:
382 case FSA_READ_SOFTLINK
:
384 case FSA_DELETE_OBJECT
:
385 case FSA_SET_COMMENT
:
386 case FSA_SET_PROTECT
:
393 error
= ERROR_NO_DISK
;
396 D(bug("[afs] unknown fsa %d\n", iofs
->IOFS
.io_Command
));
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
);