2 * fat.handler - FAT12/16/32 filesystem handler
4 * Copyright © 2006 Marek Szyprowski
5 * Copyright © 2007 The AROS Development Team
7 * This program is free software; you can redistribute it and/or modify it
8 * under the same terms as AROS itself.
13 #include <exec/types.h>
15 #include <dos/notify.h>
16 #include <proto/exec.h>
19 #include "fat_protos.h"
21 #define DEBUG DEBUG_NOTIFY
22 #include <aros/debug.h>
24 void SendNotify(struct NotifyRequest
*nr
) {
25 struct NotifyMessage
*nm
;
27 D(bug("[fat] notifying for '%s'\n", nr
->nr_FullName
));
29 /* signals are a doddle */
30 if (nr
->nr_Flags
& NRF_SEND_SIGNAL
) {
31 D(bug("[fat] sending signal %ld to task 0x%08x\n", nr
->nr_stuff
.nr_Signal
.nr_SignalNum
, nr
->nr_stuff
.nr_Signal
.nr_Task
));
33 Signal(nr
->nr_stuff
.nr_Signal
.nr_Task
, 1 << nr
->nr_stuff
.nr_Signal
.nr_SignalNum
);
38 /* if message isn't set, then they screwed up, and there's nothing to do */
39 if (!(nr
->nr_Flags
& NRF_SEND_MESSAGE
)) {
40 D(bug("[fat] weird, request doesn't have SIGNAL or MESSAGE bits set, doing nothing\n"));
44 /* don't send if we're supposed to wait for them to reply and there's
45 * still messages outstanding */
46 if (nr
->nr_Flags
& NRF_WAIT_REPLY
&& nr
->nr_MsgCount
> 0) {
47 D(bug("[fat] request has WAIT_REPLY set and there are %ld messages outstanding, doing nothing\n", nr
->nr_MsgCount
));
54 D(bug("[fat] request now has %ld messages outstanding\n", nr
->nr_MsgCount
));
56 /* allocate and build the message */
57 nm
= AllocVec(sizeof(struct NotifyMessage
), MEMF_PUBLIC
| MEMF_CLEAR
);
58 nm
->nm_ExecMessage
.mn_ReplyPort
= glob
->notifyport
;
59 nm
->nm_ExecMessage
.mn_Length
= sizeof(struct NotifyMessage
);
60 nm
->nm_Class
= NOTIFY_CLASS
;
61 nm
->nm_Code
= NOTIFY_CODE
;
64 D(bug("[fat] sending notify message to port 0x%08x\n", nr
->nr_stuff
.nr_Msg
.nr_Port
));
67 PutMsg(nr
->nr_stuff
.nr_Msg
.nr_Port
, (struct Message
*) nm
);
70 /* send a notification for the file referenced by the passed global lock */
71 void SendNotifyByLock(struct FSSuper
*sb
, struct GlobalLock
*gl
) {
72 struct NotifyNode
*nn
;
74 D(bug("[fat] notifying for lock (%ld/%ld)\n", gl
->dir_cluster
, gl
->dir_entry
));
76 ForeachNode(&sb
->notifies
, nn
)
81 /* send a notification for the file referenced by the passed dir entry */
82 void SendNotifyByDirEntry(struct FSSuper
*sb
, struct DirEntry
*de
) {
83 struct NotifyNode
*nn
;
87 D(bug("[fat] notifying for dir entry (%ld/%ld)\n", de
->cluster
, de
->index
));
89 ForeachNode(&sb
->notifies
, nn
)
91 if (nn
->gl
->dir_cluster
== de
->cluster
&& nn
->gl
->dir_entry
== de
->index
)
96 if (InitDirHandle(sb
, 0, &sdh
) != 0)
99 if (GetDirEntryByPath(&sdh
, nn
->nr
->nr_FullName
, strlen(nn
->nr
->nr_FullName
), &sde
) != 0)
102 if (sde
.cluster
== de
->cluster
&& sde
.index
== de
->index
)
105 ReleaseDirHandle(&sdh
);
109 /* handle returned notify messages */
110 void ProcessNotify(void) {
111 struct NotifyMessage
*nm
;
113 while ((nm
= (struct NotifyMessage
*) GetMsg(glob
->notifyport
)) != NULL
)
115 if (nm
->nm_Class
== NOTIFY_CLASS
&& nm
->nm_Code
== NOTIFY_CODE
) {
116 nm
->nm_NReq
->nr_MsgCount
--;
117 if (nm
->nm_NReq
->nr_MsgCount
< 0)
118 nm
->nm_NReq
->nr_MsgCount
= 0;
120 D(bug("[fat] received notify message reply, %ld messages outstanding for this request\n", nm
->nm_NReq
->nr_MsgCount
));
126 D(bug("[fat] non-notify message received, dropping it\n"));