2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
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>
18 #include <aros/libcall.h>
19 #include <aros/symbolsets.h>
20 #include <aros/debug.h>
23 #include "afshandler.h"
26 #include LC_LIBDEFS_FILE
28 extern void AFS_work();
30 static int GM_UNIQUENAME(Init
)(LIBBASETYPEPTR afsbase
)
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
);
52 afsbase
->port
.mp_SigTask
= task
;
53 afsbase
->port
.mp_Flags
= PA_IGNORE
;
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
);
71 struct TagItem tags
[] =
73 {TASKTAG_ARG1
, (IPTR
)afsbase
},
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
;
82 task
->tc_SPReg
= (BYTE
*)task
->tc_SPLower
+SP_OFFSET
;
85 if (NewAddTask(task
,AFS_work
,NULL
,tags
) != NULL
)
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
);
102 #include "baseredef.h"
104 static int GM_UNIQUENAME(Open
)
106 LIBBASETYPEPTR afsbase
,
107 struct IOFileSys
*iofs
,
113 struct Volume
*volume
;
116 afsbase
->rport
.mp_SigTask
=FindTask(NULL
);
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
,
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;
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;
150 iofs
->IOFS
.io_Error
= IOERR_OPENFAIL
;
154 static int GM_UNIQUENAME(Expunge
)(LIBBASETYPEPTR afsbase
)
156 #warning "FIXME FIXME FIXME FIXME: Disabled broken expunge code which does not take into account"
157 #warning "that there might be an active time request hanging around. See AFS_work()."
161 CloseDevice((struct IORequest
*)afsbase
->timer_request
);
162 DeleteIORequest((struct IORequest
*)afsbase
->timer_request
);
163 RemTask(afsbase
->port
.mp_SigTask
);
164 FreeMem(((struct Task
*)afsbase
->port
.mp_SigTask
)->tc_SPLower
,AROS_STACKSIZE
);
165 FreeMem(afsbase
->port
.mp_SigTask
, sizeof(struct Task
));
166 CloseLibrary((struct Library
*)IntuitionBase
);
167 CloseLibrary((struct Library
*)DOSBase
);
171 static int GM_UNIQUENAME(Close
)
173 LIBBASETYPEPTR afsbase
,
174 struct IOFileSys
*iofs
177 struct Volume
*volume
;
179 afsbase
->rport
.mp_SigTask
= FindTask(NULL
);
180 /* iofs->IOFS.io_Command = -2;
181 PutMsg(&afsbase->port, &iofs->IOFS.io_Message);
182 WaitPort(&afsbase->rport);
183 (void)GetMsg(&afsbase->rport);
184 if (iofs->io_DosError)
185 return 0; // there is still something to do on this volume
187 volume
= ((struct AfsHandle
*)iofs
->IOFS
.io_Unit
)->volume
;
188 if (!volume
->locklist
)
191 uninitVolume(afsbase
, volume
);
196 iofs
->IOFS
.io_Error
= ERROR_OBJECT_IN_USE
;
201 ADD2INITLIB(GM_UNIQUENAME(Init
),0)
202 ADD2OPENDEV(GM_UNIQUENAME(Open
),0)
203 ADD2CLOSEDEV(GM_UNIQUENAME(Close
),0)
204 ADD2EXPUNGELIB(GM_UNIQUENAME(Expunge
),0)
206 AROS_LH1(void, beginio
,
207 AROS_LHA(struct IOFileSys
*, iofs
, A1
),
208 struct AFSBase
*, afsbase
, 5, Afs
)
211 /* WaitIO will look into this */
212 iofs
->IOFS
.io_Message
.mn_Node
.ln_Type
= NT_MESSAGE
;
213 /* Nothing is done quick */
214 iofs
->IOFS
.io_Flags
&= ~IOF_QUICK
;
215 /* So let the device task do it */
216 PutMsg(&afsbase
->port
, &iofs
->IOFS
.io_Message
);
220 AROS_LH1(LONG
, abortio
,
221 AROS_LHA(struct IOFileSys
*, iofs
, A1
),
222 struct AFSBase
*, afsbase
, 6, Afs
)