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 CloseDevice((struct IORequest
*)afsbase
->timer_request
);
157 DeleteIORequest((struct IORequest
*)afsbase
->timer_request
);
158 RemTask(afsbase
->port
.mp_SigTask
);
159 FreeMem(((struct Task
*)afsbase
->port
.mp_SigTask
)->tc_SPLower
,AROS_STACKSIZE
);
160 FreeMem(afsbase
->port
.mp_SigTask
, sizeof(struct Task
));
161 CloseLibrary((struct Library
*)IntuitionBase
);
162 CloseLibrary((struct Library
*)DOSBase
);
166 static int GM_UNIQUENAME(Close
)
168 LIBBASETYPEPTR afsbase
,
169 struct IOFileSys
*iofs
172 struct Volume
*volume
;
174 afsbase
->rport
.mp_SigTask
= FindTask(NULL
);
175 /* iofs->IOFS.io_Command = -2;
176 PutMsg(&afsbase->port, &iofs->IOFS.io_Message);
177 WaitPort(&afsbase->rport);
178 (void)GetMsg(&afsbase->rport);
179 if (iofs->io_DosError)
180 return 0; // there is still something to do on this volume
182 volume
= ((struct AfsHandle
*)iofs
->IOFS
.io_Unit
)->volume
;
183 if (!volume
->locklist
)
186 uninitVolume(afsbase
, volume
);
191 iofs
->IOFS
.io_Error
= ERROR_OBJECT_IN_USE
;
196 ADD2INITLIB(GM_UNIQUENAME(Init
),0)
197 ADD2OPENDEV(GM_UNIQUENAME(Open
),0)
198 ADD2CLOSEDEV(GM_UNIQUENAME(Close
),0)
199 ADD2EXPUNGELIB(GM_UNIQUENAME(Expunge
),0)
201 AROS_LH1(void, beginio
,
202 AROS_LHA(struct IOFileSys
*, iofs
, A1
),
203 struct AFSBase
*, afsbase
, 5, Afs
)
206 /* WaitIO will look into this */
207 iofs
->IOFS
.io_Message
.mn_Node
.ln_Type
= NT_MESSAGE
;
208 /* Nothing is done quick */
209 iofs
->IOFS
.io_Flags
&= ~IOF_QUICK
;
210 /* So let the device task do it */
211 PutMsg(&afsbase
->port
, &iofs
->IOFS
.io_Message
);
215 AROS_LH1(LONG
, abortio
,
216 AROS_LHA(struct IOFileSys
*, iofs
, A1
),
217 struct AFSBase
*, afsbase
, 6, Afs
)