diff --git a/tools/linuxfs/preload/dircache.c b/tools/linuxfs/preload/dircache.c index 01a5d7275..a752a7999 100644 --- a/tools/linuxfs/preload/dircache.c +++ b/tools/linuxfs/preload/dircache.c @@ -166,10 +166,21 @@ static void remove_name(struct listing *l, const char *name) { l->names[i] = l->names[--l->count]; } +static int in_scope(const char *path); + +/* A change the cache can't place (a relative path): no listing can be trusted after it. */ +static void forget_all(void) { + if (!in_scope("/mnt/droiddeck-sd")) return; + pthread_mutex_lock(&lock); + for (int i = 0; i < DIRCACHE_SLOTS; i++) drop(&listings[i]); + pthread_mutex_unlock(&lock); +} + /* The client's own change to a directory, applied to its listing when one is cached. */ static void note(const char *path, int added, unsigned char type) { char parent[DIRCACHE_PATH_MAX]; const char *base; + if (path != NULL && path[0] != '/') { forget_all(); return; } if (!in_scope(path) || !split(path, parent, &base)) return; pthread_mutex_lock(&lock); struct listing *l = find(parent, now_ns()); @@ -404,12 +415,6 @@ MUTATE(unlink, (const char *p), (p), p, note(p, 0, DT_REG)) MUTATE(rmdir, (const char *p), (p), p, note(p, 0, DT_DIR)) MUTATE(rename, (const char *a, const char *b), (a, b), a, { note(a, 0, DT_DIR); note(b, 0, DT_DIR); note(b, 1, DT_UNKNOWN); }) -/* Calls relative to a directory descriptor: the cache can't tell which listing changed. */ -static void forget_all(void) { - pthread_mutex_lock(&lock); - for (int i = 0; i < DIRCACHE_SLOTS; i++) drop(&listings[i]); - pthread_mutex_unlock(&lock); -} #define MUTATE_AT(name, sig, args) \ int name sig { \ diff --git a/tools/linuxfs/preload/opens.c b/tools/linuxfs/preload/opens.c index 92317de1b..93cabf99d 100644 --- a/tools/linuxfs/preload/opens.c +++ b/tools/linuxfs/preload/opens.c @@ -107,7 +107,7 @@ int openat(int dirfd, const char *path, int flags, ...) { bl_meta_log("openat", dirfd, path, flags, t0, fd, errno); if (retry_without_noatime(fd, flags)) fd = real_openat(dirfd, path, flags & ~O_NOATIME, mode); if (fd < 0 && bl_writable_retry(dirfd, path, flags)) fd = real_openat(dirfd, path, flags & ~O_NOATIME, mode); - if (fd >= 0 && (flags & O_CREAT) && (dirfd == AT_FDCWD || (path && path[0] == '/'))) bl_dircache_created(path); + if (fd >= 0 && (flags & O_CREAT)) bl_dircache_created(path); return fd; }