Skip to content

Commit c1a762d

Browse files
add mount detection
1 parent aa8b956 commit c1a762d

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

plugins/medialib/linux/fsmonitor.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ typedef struct node {
4040

4141
struct ddb_fsmonitor_s {
4242
int fd;
43+
int mountinfo_wd;
44+
4345
dispatch_queue_t queue;
4446
dispatch_source_t readSource;
4547

@@ -110,6 +112,23 @@ add_recursive(ddb_fsmonitor_t *m, const char *path) {
110112
closedir(d);
111113
}
112114

115+
static void
116+
handle_mount_change(ddb_fsmonitor_t *m) {
117+
// Re-add all known paths.
118+
// We duplicate the list first to avoid mutation issues.
119+
node_t *n = m->nodes;
120+
121+
while (n) {
122+
add_recursive(m, n->path);
123+
n = n->next;
124+
}
125+
126+
// Notify user once
127+
if (m->cb)
128+
m->cb(m->userdata);
129+
}
130+
131+
113132
static void
114133
handle_events(ddb_fsmonitor_t *m) {
115134
char buf[8192];
@@ -122,6 +141,13 @@ handle_events(ddb_fsmonitor_t *m) {
122141
struct inotify_event *ev =
123142
(struct inotify_event *)&buf[i];
124143

144+
// Mountinfo detection
145+
if (ev->wd == m->mountinfo_wd) {
146+
handle_mount_change(m);
147+
i += sizeof(struct inotify_event) + ev->len;
148+
continue;
149+
}
150+
125151
node_t *node = node_find(m, ev->wd);
126152

127153
// New directory → add watch
@@ -152,6 +178,7 @@ handle_events(ddb_fsmonitor_t *m) {
152178
}
153179
}
154180

181+
155182
ddb_fsmonitor_t *
156183
ddb_fsmonitor_create(const char **paths,
157184
size_t count,
@@ -161,6 +188,14 @@ ddb_fsmonitor_create(const char **paths,
161188
ddb_fsmonitor_t *m = calloc(1, sizeof(*m));
162189

163190
m->fd = inotify_init1(IN_NONBLOCK);
191+
192+
m->fd = inotify_init1(IN_NONBLOCK);
193+
m->mountinfo_wd = inotify_add_watch(
194+
m->fd,
195+
"/proc/self/mountinfo",
196+
IN_MODIFY
197+
);
198+
164199
m->queue = dispatch_queue_create("ddb.fsmonitor", 0);
165200
m->cb = cb;
166201
m->userdata = userdata;

0 commit comments

Comments
 (0)