From e0e9611fd60e9647a6c272add22ec8a3c214f40e Mon Sep 17 00:00:00 2001 From: Ramon Nou Date: Fri, 16 May 2025 11:59:17 +0200 Subject: [PATCH 1/2] mkdir and symlinkat --- src/client/gkfs_libc.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/client/gkfs_libc.cpp b/src/client/gkfs_libc.cpp index a25294234..257793662 100644 --- a/src/client/gkfs_libc.cpp +++ b/src/client/gkfs_libc.cpp @@ -570,6 +570,9 @@ DLSYM_WRAPPER(int, renameat2, (olddirfd, oldpath, newdirfd, newpath, flags), "renameat2") DLSYM_WRAPPER(int, symlink, (const char* path1, const char* path2), (path1, path2), "symlink") +DLSYM_WRAPPER(int, symlinkat, + (const char* path1, int newdirfd, const char* path2), + (path1, newdirfd, path2), "symlinkat") DLSYM_WRAPPER(ssize_t, readlink, (const char* path, char* buf, size_t bufsize), (path, buf, bufsize), "readlink") DLSYM_WRAPPER(ssize_t, readlinkat, @@ -1350,7 +1353,12 @@ mkdir(const char* path, mode_t mode) { switch(resolve_gkfs_path(AT_FDCWD, path, resolved)) { case PathStatus::Internal: DEBUG_INFO("[GKFS] mkdir(path='{}')", resolved); - return gkfs::syscall::gkfs_create(resolved, mode | S_IFDIR); + auto ret = gkfs::syscall::gkfs_create(resolved, mode | S_IFDIR); + DEBUG_INFO("[GKFS] mkdir(path='{}') {} --- {}", resolved, ret, + errno); + if(ret < 0 and errno == EEXIST) + return 0; + return ret; case PathStatus::Error: return -1; default: // External @@ -1848,6 +1856,33 @@ symlink(const char* path1, const char* path2) { GKFS_FALLBACK(symlink, path1, path2); } +// symlinkat +int +symlinkat(const char* path1, int newdirfd, const char* path2) { + gkfs_init_routine_placeholder(); + if(CTX->interception_enabled()) { + std::string resolved; + if(resolve_gkfs_path(AT_FDCWD, path1, resolved) == + PathStatus::Internal) { + DEBUG_INFO("[GKFS] path 1 internal {}", resolved); + std::string resolved2; + if(resolve_gkfs_path(newdirfd, path2, resolved2) == + PathStatus::Internal) { + DEBUG_INFO("[GKFS] path 2 internal {}", resolved2); +#ifdef HAS_SYMLINKS + // In Gekko we invert the parameters. + return gkfs::syscall::gkfs_mk_symlink(resolved2, resolved); +#else + DEBUG_INFO("[GKFS] symlinks not supported/compiled"); + errno = ENOTSUP; + return -1; +#endif + } + } + } + GKFS_FALLBACK(symlinkat, path1, newdirfd, path2); +} + #ifdef HAS_SYMLINKS ssize_t readlink(const char* path, char* buf, size_t bufsize) { -- GitLab From 30d8e9bfed30932eb9a0bf6f30d2e1dc5cce7aa6 Mon Sep 17 00:00:00 2001 From: Ramon Nou Date: Fri, 16 May 2025 12:15:19 +0200 Subject: [PATCH 2/2] mkdir bugfix --- src/client/gkfs_libc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client/gkfs_libc.cpp b/src/client/gkfs_libc.cpp index 257793662..9403efd4a 100644 --- a/src/client/gkfs_libc.cpp +++ b/src/client/gkfs_libc.cpp @@ -1351,7 +1351,7 @@ mkdir(const char* path, mode_t mode) { if(CTX->interception_enabled()) { std::string resolved; switch(resolve_gkfs_path(AT_FDCWD, path, resolved)) { - case PathStatus::Internal: + case PathStatus::Internal: { DEBUG_INFO("[GKFS] mkdir(path='{}')", resolved); auto ret = gkfs::syscall::gkfs_create(resolved, mode | S_IFDIR); DEBUG_INFO("[GKFS] mkdir(path='{}') {} --- {}", resolved, ret, @@ -1359,6 +1359,7 @@ mkdir(const char* path, mode_t mode) { if(ret < 0 and errno == EEXIST) return 0; return ret; + } case PathStatus::Error: return -1; default: // External -- GitLab