Forgotten changes that should have been part of the r45368 64-bit fix.
[AROS.git] / rom / filesys / fat / notify.c
blobf4e0de4ce1e283ca3ad51dba5d4fb64328136eb7
1 /*
2 * fat.handler - FAT12/16/32 filesystem handler
4 * Copyright © 2006 Marek Szyprowski
5 * Copyright © 2007-2008 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.
10 * $Id$
13 #define AROS_ALMOST_COMPATIBLE
15 #include <exec/types.h>
16 #include <dos/dos.h>
17 #include <dos/notify.h>
18 #include <proto/exec.h>
20 #include "fat_fs.h"
21 #include "fat_protos.h"
23 #define DEBUG DEBUG_NOTIFY
24 #include "debug.h"
26 void SendNotify(struct NotifyRequest *nr) {
27 struct NotifyMessage *nm;
29 D(bug("[fat] notifying for '%s'\n", nr->nr_FullName));
31 /* signals are a doddle */
32 if (nr->nr_Flags & NRF_SEND_SIGNAL) {
33 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));
35 Signal(nr->nr_stuff.nr_Signal.nr_Task, 1 << nr->nr_stuff.nr_Signal.nr_SignalNum);
37 return;
40 /* if message isn't set, then they screwed up, and there's nothing to do */
41 if (!(nr->nr_Flags & NRF_SEND_MESSAGE)) {
42 D(bug("[fat] weird, request doesn't have SIGNAL or MESSAGE bits set, doing nothing\n"));
43 return;
46 /* don't send if we're supposed to wait for them to reply and there's
47 * still messages outstanding */
48 if (nr->nr_Flags & NRF_WAIT_REPLY && nr->nr_MsgCount > 0) {
49 D(bug("[fat] request has WAIT_REPLY set and there are %ld messages outstanding, doing nothing\n", nr->nr_MsgCount));
50 return;
53 /* new message */
54 nr->nr_MsgCount++;
56 D(bug("[fat] request now has %ld messages outstanding\n", nr->nr_MsgCount));
58 /* allocate and build the message */
59 nm = AllocVec(sizeof(struct NotifyMessage), MEMF_PUBLIC | MEMF_CLEAR);
60 nm->nm_ExecMessage.mn_ReplyPort = glob->notifyport;
61 nm->nm_ExecMessage.mn_Length = sizeof(struct NotifyMessage);
62 nm->nm_Class = NOTIFY_CLASS;
63 nm->nm_Code = NOTIFY_CODE;
64 nm->nm_NReq = nr;
66 D(bug("[fat] sending notify message to port 0x%08x\n", nr->nr_stuff.nr_Msg.nr_Port));
68 /* send it */
69 PutMsg(nr->nr_stuff.nr_Msg.nr_Port, (struct Message *) nm);
72 /* send a notification for the file referenced by the passed global lock */
73 void SendNotifyByLock(struct FSSuper *sb, struct GlobalLock *gl) {
74 struct NotifyNode *nn;
76 D(bug("[fat] notifying for lock (%ld/%ld)\n", gl->dir_cluster, gl->dir_entry));
78 ForeachNode(&sb->info->notifies, nn)
79 if (nn->gl == gl)
80 SendNotify(nn->nr);
83 /* send a notification for the file referenced by the passed dir entry */
84 void SendNotifyByDirEntry(struct FSSuper *sb, struct DirEntry *de) {
85 struct NotifyNode *nn;
86 struct DirHandle sdh;
87 struct DirEntry sde;
89 /* Inside the loop we may reuse the dirhandle, so here we explicitly mark it
90 as uninitialised */
91 sdh.ioh.sb = NULL;
93 D(bug("[fat] notifying for dir entry (%ld/%ld)\n", de->cluster, de->index));
95 ForeachNode(&sb->info->notifies, nn)
96 if (nn->gl != NULL) {
97 if (nn->gl->dir_cluster == de->cluster && nn->gl->dir_entry == de->index)
98 SendNotify(nn->nr);
101 else {
102 if (InitDirHandle(sb, 0, &sdh, TRUE) != 0)
103 continue;
105 if (GetDirEntryByPath(&sdh, nn->nr->nr_FullName, strlen(nn->nr->nr_FullName), &sde) != 0)
106 continue;
108 if (sde.cluster == de->cluster && sde.index == de->index)
109 SendNotify(nn->nr);
111 ReleaseDirHandle(&sdh);
115 /* handle returned notify messages */
116 void ProcessNotify(void) {
117 struct NotifyMessage *nm;
119 while ((nm = (struct NotifyMessage *) GetMsg(glob->notifyport)) != NULL)
121 if (nm->nm_Class == NOTIFY_CLASS && nm->nm_Code == NOTIFY_CODE) {
122 nm->nm_NReq->nr_MsgCount--;
123 if (nm->nm_NReq->nr_MsgCount < 0)
124 nm->nm_NReq->nr_MsgCount = 0;
126 D(bug("[fat] received notify message reply, %ld messages outstanding for this request\n", nm->nm_NReq->nr_MsgCount));
128 FreeVec(nm);
131 else
132 D(bug("[fat] non-notify message received, dropping it\n"));