Top |
struct libmnt_monitor * | mnt_new_monitor () |
void | mnt_ref_monitor () |
void | mnt_unref_monitor () |
int | mnt_monitor_enable_userspace () |
int | mnt_monitor_enable_kernel () |
int | mnt_monitor_get_fd () |
int | mnt_monitor_close_fd () |
int | mnt_monitor_next_change () |
int | mnt_monitor_event_cleanup () |
int | mnt_monitor_wait () |
For example monitor VFS (/proc/self/mountinfo) for changes:
1 2 3 4 5 6 7 8 9 10 11 |
const char *filename; struct libmount_monitor *mn = mnt_new_monitor(); mnt_monitor_enable_kernel(mn, TRUE)); printf("waiting for changes...\n"); while (mnt_monitor_wait(mn, -1) > 0) { while (mnt_monitor_next_change(mn, &filename, NULL) == 0) printf(" %s: change detected\n", filename); } mnt_unref_monitor(mn); |
struct libmnt_monitor *
mnt_new_monitor (void
);
The initial refcount is 1, and needs to be decremented to release the resources of the filesystem.
void
mnt_unref_monitor (struct libmnt_monitor *mn
);
Decrements the reference counter, on zero the mn
is automatically
deallocated.
int mnt_monitor_enable_userspace (struct libmnt_monitor *mn
,int enable
,const char *filename
);
Enables or disables userspace monitoring. If the userspace monitor does not exist and enable=1 then allocates new resources necessary for the monitor.
If the top-level monitor has been already created (by mnt_monitor_get_fd()
or mnt_monitor_wait()
) then it's updated according to enable
.
The filename
is used only the first time when you enable the monitor. It's
impossible to have more than one userspace monitor. The recommended is to
use NULL as filename.
The userspace monitor is unsupported for systems with classic regular /etc/mtab file.
Return: 0 on success and <0 on error
int mnt_monitor_enable_kernel (struct libmnt_monitor *mn
,int enable
);
Enables or disables kernel VFS monitoring. If the monitor does not exist and enable=1 then allocates new resources necessary for the monitor.
If the top-level monitor has been already created (by mnt_monitor_get_fd()
or mnt_monitor_wait()
) then it's updated according to enable
.
Return: 0 on success and <0 on error
int
mnt_monitor_get_fd (struct libmnt_monitor *mn
);
The file descriptor is associated with all monitored files and it's usable
for example for epoll. You have to call mnt_monitor_event_cleanup()
or
mnt_monitor_next_change()
after each event.
int
mnt_monitor_close_fd (struct libmnt_monitor *mn
);
Close monitor file descriptor. This is usually unnecessary, because
mnt_unref_monitor()
cleanups all.
The function is necessary only if you want to reset monitor setting. The
next mnt_monitor_get_fd()
or mnt_monitor_wait()
will use newly initialized
monitor. This restart is unnecessary for mnt_monitor_enable_*() functions.
int mnt_monitor_next_change (struct libmnt_monitor *mn
,const char **filename
,int *type
);
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.
int
mnt_monitor_event_cleanup (struct libmnt_monitor *mn
);
This function cleanups (drain) internal buffers. It's necessary to call
this function after event if you do not call mnt_monitor_next_change()
.
int mnt_monitor_wait (struct libmnt_monitor *mn
,int timeout
);
Waits for the next change, after the event it's recommended to use
mnt_monitor_next_change()
to get more details about the change and to
avoid false positive events.