* @filename: returns changed file (optional argument)
* @type: returns MNT_MONITOR_TYPE_* (optional argument)
*
- * The function does not wait and it's designed to provide details about changes.
- * It's always recommended to use this function to avoid false positives.
+ * The function does not wait and is designed to provide details about changes.
+ * It is always recommended to use this function to avoid false positives.
+ *
+ * This function iterates over a list of unprocessed events. When an event is returned
+ * by this function, it is marked as processed. If you need details about the last
+ * processed event, use the mnt_monitor_event_* functions.
*
* Returns: 0 on success, 1 no change, <0 on error
*/
if (!mn || mn->fd < 0)
return -EINVAL;
+ mn->last = NULL;
+
me = get_active(mn);
if (!me) {
rc = read_epoll_events(mn, 0, &me); /* try without timeout */
}
me->active = 0;
+ mn->last = me;
if (filename)
*filename = me->path;
return rc < 0 ? rc : 0;
}
+/**
+ * mnt_monitor_event_next_fs:
+ * @mn: monitor
+ * @fs: filesystem
+ *
+ * Fill in details about the next filesystem associated with the last event
+ * (as returned by mnt_monitor_next_change()). If the event does not provide
+ * details, it returns -ENOTSUP.
+ *
+ * <informalexample>
+ * <programlisting>
+ * while (mnt_monitor_next_change(mn, NULL, &type) == 0) {
+ * if (type == MNT_MONITOR_TYPE_FANOTIFY) {
+ * while (mnt_monitor_event_next_fs(mn, fs) == 0) {
+ * printf("ID=%ju\n", mnt_fs_get_uniq_id(fs));
+ * }
+ * }
+ * }
+ * </programlisting>
+ * </informalexample>
+ *
+ * Returns: 0 on success, 1 no more data, <0 on error
+ *
+ * Since: 2.42
+ */
+int mnt_monitor_event_next_fs(struct libmnt_monitor *mn, struct libmnt_fs *fs)
+{
+ if (!mn || !fs)
+ return -EINVAL;
+ if (!mn->last)
+ return 1;
+ if (!mn->last->opers->op_next_fs)
+ return -ENOTSUP;
+
+ return mn->last->opers->op_next_fs(mn, mn->last, fs);
+}
+
#ifdef TEST_PROGRAM
static struct libmnt_monitor *create_test_monitor(int argc, char *argv[])
int fd; /* public monitor file descriptor */
struct list_head ents;
+ struct monitor_entry *last; /* last active returned by mnt_monitor_next_change() */
bool kernel_veiled;
};
int (*op_close_fd)(struct libmnt_monitor *, struct monitor_entry *);
int (*op_free_data)(struct monitor_entry *);
int (*op_process_event)(struct libmnt_monitor *, struct monitor_entry *);
+ int (*op_next_fs)(struct libmnt_monitor *, struct monitor_entry *, struct libmnt_fs *);
};
int monitor_modify_epoll(struct libmnt_monitor *mn, struct monitor_entry *me, int enable);