Added -Wno-pointer-sign to reduce number of warnings when building AHI.
[AROS.git] / workbench / fs / ntfs / notify.c
blobd1e8842d46059e6b6287b431a9dad6be40e9b763
1 /*
2 * ntfs.handler - New Technology FileSystem handler
4 * Copyright © 2012 The AROS Development Team
6 * This program is free software; you can redistribute it and/or modify it
7 * under the same terms as AROS itself.
9 * $Id $
12 #define AROS_ALMOST_COMPATIBLE
14 #include <exec/types.h>
15 #include <dos/dos.h>
16 #include <dos/notify.h>
17 #include <proto/exec.h>
19 #include "ntfs_fs.h"
20 #include "ntfs_protos.h"
22 #include "debug.h"
24 void SendNotify(struct NotifyRequest *nr)
26 struct NotifyMessage *nm;
28 D(bug("[NTFS] notifying for '%s'\n", nr->nr_FullName));
30 /* signals are a doddle */
31 if (nr->nr_Flags & NRF_SEND_SIGNAL) {
32 D(bug("[NTFS] sending signal %ld to task 0x%08x\n", nr->nr_stuff.nr_Signal.nr_SignalNum, nr->nr_stuff.nr_Signal.nr_Task));
34 Signal(nr->nr_stuff.nr_Signal.nr_Task, 1 << nr->nr_stuff.nr_Signal.nr_SignalNum);
36 return;
39 /* if message isn't set, then they screwed up, and there's nothing to do */
40 if (!(nr->nr_Flags & NRF_SEND_MESSAGE)) {
41 D(bug("[NTFS] weird, request doesn't have SIGNAL or MESSAGE bits set, doing nothing\n"));
42 return;
45 /* don't send if we're supposed to wait for them to reply and there's
46 * still messages outstanding */
47 if (nr->nr_Flags & NRF_WAIT_REPLY && nr->nr_MsgCount > 0) {
48 D(bug("[NTFS] request has WAIT_REPLY set and there are %ld messages outstanding, doing nothing\n", nr->nr_MsgCount));
49 return;
52 /* new message */
53 nr->nr_MsgCount++;
55 D(bug("[NTFS] request now has %ld messages outstanding\n", nr->nr_MsgCount));
57 /* allocate and build the message */
58 nm = AllocVec(sizeof(struct NotifyMessage), MEMF_PUBLIC | MEMF_CLEAR);
59 nm->nm_ExecMessage.mn_ReplyPort = glob->notifyport;
60 nm->nm_ExecMessage.mn_Length = sizeof(struct NotifyMessage);
61 nm->nm_Class = NOTIFY_CLASS;
62 nm->nm_Code = NOTIFY_CODE;
63 nm->nm_NReq = nr;
65 D(bug("[NTFS] sending notify message to port 0x%08x\n", nr->nr_stuff.nr_Msg.nr_Port));
67 /* send it */
68 PutMsg(nr->nr_stuff.nr_Msg.nr_Port, (struct Message *) nm);
71 /* send a notification for the file referenced by the passed global lock */
72 void SendNotifyByLock(struct FSData *sb, struct GlobalLock *gl)
74 struct NotifyNode *nn;
76 D(bug("[NTFS] 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 FSData *sb, struct DirEntry *de)
86 struct NotifyNode *nn;
87 struct DirHandle sdh;
88 struct DirEntry sde;
90 /* Inside the loop we may reuse the dirhandle, so here we explicitly mark it
91 as uninitialised */
92 sdh.ioh.data = NULL;
94 D(bug("[NTFS] notifying for dir entry (%ld/%ld)\n", de->cluster, de->no));
96 ForeachNode(&sb->info->notifies, nn)
97 if (nn->gl != NULL) {
98 if (nn->gl->dir_cluster == de->cluster && nn->gl->dir_entry == de->no)
99 SendNotify(nn->nr);
102 else {
103 if (InitDirHandle(sb, &sdh, TRUE) != 0)
104 continue;
106 if (GetDirEntryByPath(&sdh, nn->nr->nr_FullName, strlen(nn->nr->nr_FullName), &sde) != 0)
107 continue;
109 if (sde.cluster == de->cluster && sde.no == de->no)
110 SendNotify(nn->nr);
112 ReleaseDirHandle(&sdh);
116 /* handle returned notify messages */
117 void ProcessNotify(void)
119 struct NotifyMessage *nm;
121 while ((nm = (struct NotifyMessage *) GetMsg(glob->notifyport)) != NULL)
123 if (nm->nm_Class == NOTIFY_CLASS && nm->nm_Code == NOTIFY_CODE) {
124 nm->nm_NReq->nr_MsgCount--;
125 if (nm->nm_NReq->nr_MsgCount < 0)
126 nm->nm_NReq->nr_MsgCount = 0;
128 D(bug("[NTFS] received notify message reply, %ld messages outstanding for this request\n", nm->nm_NReq->nr_MsgCount));
130 FreeVec(nm);
133 else
134 D(bug("[NTFS] non-notify message received, dropping it\n"));