s3/smbd: update some more DEBUG macros in smbd_smb2_create_send
[nivanova/samba-autobuild/.git] / source3 / smbd / notify_inotify.c
index 88a54eca99532656488bde47afa37870c199d757..74855a9f6f9eedf8642b42dbe34e95b67e29f086 100644 (file)
@@ -57,6 +57,60 @@ struct inotify_watch_context {
 };
 
 
+/*
+  map from a change notify mask to a inotify mask. Remove any bits
+  which we can handle
+*/
+static const struct {
+       uint32_t notify_mask;
+       uint32_t inotify_mask;
+} inotify_mapping[] = {
+       {FILE_NOTIFY_CHANGE_FILE_NAME,   IN_CREATE|IN_DELETE|IN_MOVED_FROM|IN_MOVED_TO},
+       {FILE_NOTIFY_CHANGE_DIR_NAME,    IN_CREATE|IN_DELETE|IN_MOVED_FROM|IN_MOVED_TO},
+       {FILE_NOTIFY_CHANGE_ATTRIBUTES,  IN_ATTRIB|IN_MOVED_TO|IN_MOVED_FROM|IN_MODIFY},
+       {FILE_NOTIFY_CHANGE_LAST_WRITE,  IN_ATTRIB},
+       {FILE_NOTIFY_CHANGE_LAST_ACCESS, IN_ATTRIB},
+       {FILE_NOTIFY_CHANGE_EA,          IN_ATTRIB},
+       {FILE_NOTIFY_CHANGE_SECURITY,    IN_ATTRIB}
+};
+
+static uint32_t inotify_map(uint32_t *filter)
+{
+       int i;
+       uint32_t out=0;
+       for (i=0;i<ARRAY_SIZE(inotify_mapping);i++) {
+               if (inotify_mapping[i].notify_mask & *filter) {
+                       out |= inotify_mapping[i].inotify_mask;
+                       *filter &= ~inotify_mapping[i].notify_mask;
+               }
+       }
+       return out;
+}
+
+/*
+ * Map inotify mask back to filter. This returns all filters that
+ * could have created the inotify watch.
+ */
+static uint32_t inotify_map_mask_to_filter(uint32_t mask)
+{
+       int i;
+       uint32_t filter = 0;
+
+       for (i = 0; i < ARRAY_SIZE(inotify_mapping); i++) {
+               if (inotify_mapping[i].inotify_mask & mask) {
+                       filter |= inotify_mapping[i].notify_mask;
+               }
+       }
+
+       if (mask & IN_ISDIR) {
+               filter &= ~FILE_NOTIFY_CHANGE_FILE_NAME;
+       } else {
+               filter &= ~FILE_NOTIFY_CHANGE_DIR_NAME;
+       }
+
+       return filter;
+}
+
 /*
   destroy the inotify private context
 */
@@ -123,6 +177,7 @@ static void inotify_dispatch(struct inotify_private *in,
 {
        struct inotify_watch_context *w, *next;
        struct notify_event ne;
+       uint32_t filter;
 
        DEBUG(10, ("inotify_dispatch called with mask=%x, name=[%s]\n",
                   e->mask, e->len ? e->name : ""));
@@ -157,15 +212,17 @@ static void inotify_dispatch(struct inotify_private *in,
        }
        ne.path = e->name;
 
-       DEBUG(10, ("inotify_dispatch: ne.action = %d, ne.path = %s\n",
-                  ne.action, ne.path));
+       filter = inotify_map_mask_to_filter(e->mask);
+
+       DBG_DEBUG("ne.action = %d, ne.path = %s, filter = %d\n",
+                 ne.action, ne.path, filter);
 
        /* find any watches that have this watch descriptor */
        for (w=in->watches;w;w=next) {
                next = w->next;
                if (w->wd == e->wd && filter_match(w, e)) {
                        ne.dir = w->path;
-                       w->callback(in->ctx, w->private_data, &ne, UINT32_MAX);
+                       w->callback(in->ctx, w->private_data, &ne, filter);
                }
        }
 
@@ -187,7 +244,7 @@ static void inotify_dispatch(struct inotify_private *in,
                            !(w->filter & FILE_NOTIFY_CHANGE_CREATION)) {
                                ne.dir = w->path;
                                w->callback(in->ctx, w->private_data, &ne,
-                                           UINT32_MAX);
+                                           filter);
                        }
                }
        }
@@ -288,37 +345,6 @@ static int inotify_setup(struct sys_notify_context *ctx)
        return 0;
 }
 
-
-/*
-  map from a change notify mask to a inotify mask. Remove any bits
-  which we can handle
-*/
-static const struct {
-       uint32_t notify_mask;
-       uint32_t inotify_mask;
-} inotify_mapping[] = {
-       {FILE_NOTIFY_CHANGE_FILE_NAME,   IN_CREATE|IN_DELETE|IN_MOVED_FROM|IN_MOVED_TO},
-       {FILE_NOTIFY_CHANGE_DIR_NAME,    IN_CREATE|IN_DELETE|IN_MOVED_FROM|IN_MOVED_TO},
-       {FILE_NOTIFY_CHANGE_ATTRIBUTES,  IN_ATTRIB|IN_MOVED_TO|IN_MOVED_FROM|IN_MODIFY},
-       {FILE_NOTIFY_CHANGE_LAST_WRITE,  IN_ATTRIB},
-       {FILE_NOTIFY_CHANGE_LAST_ACCESS, IN_ATTRIB},
-       {FILE_NOTIFY_CHANGE_EA,          IN_ATTRIB},
-       {FILE_NOTIFY_CHANGE_SECURITY,    IN_ATTRIB}
-};
-
-static uint32_t inotify_map(uint32_t *filter)
-{
-       int i;
-       uint32_t out=0;
-       for (i=0;i<ARRAY_SIZE(inotify_mapping);i++) {
-               if (inotify_mapping[i].notify_mask & *filter) {
-                       out |= inotify_mapping[i].inotify_mask;
-                       *filter &= ~inotify_mapping[i].notify_mask;
-               }
-       }
-       return out;
-}
-
 /*
   destroy a watch
 */