2 Copyright © 1995-2005, 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 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 /*******************************************
46 Descr.: main loop (get packets and answer (or not))
47 Input : proc - our process structure
49 ********************************************/
50 void AFS_work(struct AFSBase
*afsbase
) {
51 struct IOFileSys
*iofs
;
52 struct AfsHandle
*afshandle
;
55 afsbase
->port
.mp_SigBit
= SIGBREAKB_CTRL_F
;
56 afsbase
->port
.mp_Flags
= PA_SIGNAL
;
57 startFlushTimer(afsbase
);
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
;
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
);
88 D(bug("[afs] got command %lu\n",iofs
->IOFS
.io_Command
));
90 afshandle
= (struct AfsHandle
*)iofs
->IOFS
.io_Unit
;
91 switch (iofs
->IOFS
.io_Command
)
95 struct Volume
*volume
;
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
,
106 iofs
->IOFS
.io_Unit
= (struct Unit
*)&volume
->ah
;
108 iofs
->IOFS
.io_Unit
= NULL
;
109 PutMsg(&afsbase
->rport
, &iofs
->IOFS
.io_Message
);
114 struct Volume
*volume
;
115 volume
=((struct AfsHandle
*)iofs
->IOFS
.io_Unit
)->volume
;
116 if (volume
->locklist
!= NULL
)
118 error
= ERROR_OBJECT_IN_USE
;
122 uninitVolume(afsbase
, volume
);
125 iofs
->io_DosError
= error
;
126 PutMsg(&afsbase
->rport
, &iofs
->IOFS
.io_Message
);
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]
136 case FSA_IS_FILESYSTEM
:
137 iofs
->io_Union
.io_IS_FILESYSTEM
.io_IsFilesystem
=TRUE
;
144 iofs
->io_Union
.io_INHIBIT
.io_Inhibit
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
157 iofs
->io_Union
.io_OPEN
.io_Filename
,
158 iofs
->io_Union
.io_OPEN
.io_FileMode
162 closef(afsbase
, afshandle
);
165 iofs
->io_Union
.io_READ
.io_Length
=readf
169 iofs
->io_Union
.io_READ
.io_Buffer
,
170 iofs
->io_Union
.io_READ
.io_Length
174 iofs
->io_Union
.io_WRITE
.io_Length
=writef
178 iofs
->io_Union
.io_WRITE
.io_Buffer
,
179 iofs
->io_Union
.io_WRITE
.io_Length
183 iofs
->io_Union
.io_SEEK
.io_Offset
=seek
187 iofs
->io_Union
.io_SEEK
.io_Offset
,
188 iofs
->io_Union
.io_SEEK
.io_SeekMode
191 case FSA_SET_FILE_SIZE
:
192 D(bug("[afs] set file size nsy\n"));
193 error
=ERROR_ACTION_NOT_KNOWN
;
196 D(bug("[afs] set file mode nsy\n"));
197 error
=ERROR_ACTION_NOT_KNOWN
;
204 iofs
->io_Union
.io_EXAMINE
.io_ead
,
205 iofs
->io_Union
.io_EXAMINE
.io_Size
,
206 iofs
->io_Union
.io_EXAMINE
.io_Mode
,
210 #warning FIXME: Disabled FSA_EXAMINE_ALL support since it seems to have bugs
212 case FSA_EXAMINE_ALL
:
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
224 case FSA_EXAMINE_NEXT
:
229 iofs
->io_Union
.io_EXAMINE_NEXT
.io_fib
233 iofs
->IOFS
.io_Unit
=(struct Unit
*)openfile
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
242 case FSA_CREATE_DIR
:
243 iofs
->IOFS
.io_Unit
=(struct Unit
*)createDir
247 iofs
->io_Union
.io_CREATE_DIR
.io_Filename
,
248 iofs
->io_Union
.io_CREATE_DIR
.io_Protection
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
;
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
;
261 case FSA_READ_SOFTLINK
:
262 D(bug("[afs] read softlinks nsy\n"));
263 error
=ERROR_ACTION_NOT_KNOWN
;
270 iofs
->io_Union
.io_RENAME
.io_Filename
,
271 iofs
->io_Union
.io_RENAME
.io_NewName
274 case FSA_DELETE_OBJECT
:
279 iofs
->io_Union
.io_DELETE_OBJECT
.io_Filename
282 case FSA_SET_COMMENT
:
287 iofs
->io_Union
.io_SET_COMMENT
.io_Filename
,
288 iofs
->io_Union
.io_SET_COMMENT
.io_Comment
291 case FSA_SET_PROTECT
:
296 iofs
->io_Union
.io_SET_PROTECT
.io_Filename
,
297 iofs
->io_Union
.io_SET_PROTECT
.io_Protection
301 D(bug("[afs] set owner nsy\n"));
302 error
=ERROR_ACTION_NOT_KNOWN
;
309 iofs
->io_Union
.io_SET_DATE
.io_Filename
,
310 &iofs
->io_Union
.io_SET_DATE
.io_Date
319 iofs
->io_Union
.io_FORMAT
.io_VolumeName
,
320 iofs
->io_Union
.io_FORMAT
.io_DosType
324 iofs
->io_Union
.io_RELABEL
.io_Result
=relabel
328 iofs
->io_Union
.io_RELABEL
.io_NewName
333 (afshandle
->volume
, iofs
->io_Union
.io_INFO
.io_Info
);
336 D(bug("[afs] unknown fsa %d\n", iofs
->IOFS
.io_Command
));
338 error
=ERROR_ACTION_NOT_KNOWN
;
343 switch (iofs
->IOFS
.io_Command
)
345 case FSA_OPEN
: /* locateObject, findupdate, findinput */
350 case FSA_SET_FILE_SIZE
:
353 #warning FIXME: Disabled FSA_EXAMINE_ALL support
355 case FSA_EXAMINE_ALL
:
357 case FSA_EXAMINE_NEXT
:
359 case FSA_CREATE_DIR
:
360 case FSA_CREATE_HARDLINK
:
361 case FSA_CREATE_SOFTLINK
:
362 case FSA_READ_SOFTLINK
:
364 case FSA_DELETE_OBJECT
:
365 case FSA_SET_COMMENT
:
366 case FSA_SET_PROTECT
:
373 error
= ERROR_NO_DISK
;
376 D(bug("[afs] unknown fsa %d\n", iofs
->IOFS
.io_Command
));
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
);