Skip to content

Commit ad372d7

Browse files
committed
fscache: implement an FSCache-aware is_mount_point()
When FSCache is active, we can cache the reparse tag and use it directly to determine whether a path refers to an NTFS junction, without any additional, costly I/O. Note: this change only makes a difference with the next commit, which will make use of the FSCache in `git clean` (contingent on `core.fscache` set, of course). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent e8ad7a1 commit ad372d7

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

compat/mingw.c

+2
Original file line numberDiff line numberDiff line change
@@ -2737,6 +2737,8 @@ pid_t waitpid(pid_t pid, int *status, int options)
27372737
return -1;
27382738
}
27392739

2740+
int (*win32_is_mount_point)(struct strbuf *path) = mingw_is_mount_point;
2741+
27402742
int mingw_is_mount_point(struct strbuf *path)
27412743
{
27422744
WIN32_FIND_DATAW findbuf = { 0 };

compat/mingw.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ static inline void convert_slashes(char *path)
471471
}
472472
struct strbuf;
473473
int mingw_is_mount_point(struct strbuf *path);
474-
#define is_mount_point mingw_is_mount_point
474+
extern int (*win32_is_mount_point)(struct strbuf *path);
475+
#define is_mount_point win32_is_mount_point
475476
#define CAN_UNLINK_MOUNT_POINTS 1
476477
#define PATH_SEP ';'
477478
char *mingw_query_user_email(void);

compat/win32/fscache.c

+35
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ int fscache_enable(size_t initial_size)
467467
/* redirect opendir and lstat to the fscache implementations */
468468
opendir = fscache_opendir;
469469
lstat = fscache_lstat;
470+
win32_is_mount_point = fscache_is_mount_point;
470471
}
471472
initialized++;
472473
LeaveCriticalSection(&fscache_cs);
@@ -527,6 +528,7 @@ void fscache_disable(void)
527528
/* reset opendir and lstat to the original implementations */
528529
opendir = dirent_opendir;
529530
lstat = mingw_lstat;
531+
win32_is_mount_point = mingw_is_mount_point;
530532
}
531533
LeaveCriticalSection(&fscache_cs);
532534

@@ -597,6 +599,39 @@ int fscache_lstat(const char *filename, struct stat *st)
597599
return 0;
598600
}
599601

602+
/*
603+
* is_mount_point() replacement, uses cache if enabled, otherwise falls
604+
* back to mingw_is_mount_point().
605+
*/
606+
int fscache_is_mount_point(struct strbuf *path)
607+
{
608+
int dirlen, base, len;
609+
struct heap_fsentry key[2];
610+
struct fsentry *fse;
611+
struct fscache *cache = fscache_getcache();
612+
613+
if (!cache || !do_fscache_enabled(cache, path->buf))
614+
return mingw_is_mount_point(path);
615+
616+
cache->lstat_requests++;
617+
/* split path into path + name */
618+
len = path->len;
619+
if (len && is_dir_sep(path->buf[len - 1]))
620+
len--;
621+
base = len;
622+
while (base && !is_dir_sep(path->buf[base - 1]))
623+
base--;
624+
dirlen = base ? base - 1 : 0;
625+
626+
/* lookup entry for path + name in cache */
627+
fsentry_init(&key[0].u.ent, NULL, path->buf, dirlen);
628+
fsentry_init(&key[1].u.ent, &key[0].u.ent, path->buf + base, len - base);
629+
fse = fscache_get(cache, &key[1].u.ent);
630+
if (!fse)
631+
return mingw_is_mount_point(path);
632+
return fse->reparse_tag == IO_REPARSE_TAG_MOUNT_POINT;
633+
}
634+
600635
typedef struct fscache_DIR {
601636
struct DIR base_dir; /* extend base struct DIR */
602637
struct fsentry *pfsentry;

compat/win32/fscache.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void fscache_flush(void);
2222

2323
DIR *fscache_opendir(const char *dir);
2424
int fscache_lstat(const char *file_name, struct stat *buf);
25+
int fscache_is_mount_point(struct strbuf *path);
2526

2627
/* opaque fscache structure */
2728
struct fscache;

0 commit comments

Comments
 (0)