Loading include/client/gkfs_libc.hpp +280 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,286 @@ struct __dirstream { char data[1] __attribute__((aligned(__alignof__(void*)))); }; // Originally its 0, but C++ does not permit it //------------------------- File I/O Operations ------------------------------// int open(const char* path, int flags, ...); int open64(const char* path, int flags, ...); int openat(int dirfd, const char* path, int flags, ...); int openat64(int dirfd, const char* path, int flags, ...); // Note: Implemented via openat in source int creat(const char* path, mode_t mode); int close(int fd); int close_range(unsigned int low, unsigned int high, int flags); ssize_t read(int fd, void* buf, size_t nbyte); ssize_t write(int fd, const void* buf, size_t nbyte); ssize_t pread(int fd, void* buf, size_t count, off_t offset); ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset); ssize_t pread64(int fd, void* buf, size_t count, off64_t offset); ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset); ssize_t readv(int fd, const struct iovec* iov, int iovcnt); ssize_t writev(int fd, const struct iovec* iov, int iovcnt); ssize_t preadv(int fd, const struct iovec* iov, int iovcnt, off_t offset); ssize_t pwritev(int fd, const struct iovec* iov, int iovcnt, off_t offset); ssize_t preadv2(int fd, const struct iovec* iov, int iovcnt, off_t offset, int flags); ssize_t pwritev2(int fd, const struct iovec* iov, int iovcnt, off_t offset, int flags); off_t lseek(int fd, off_t offset, int whence); off64_t lseek64(int fd, off64_t offset, int whence); int ftruncate(int fd, off_t length); int fsync(int fd); int flock(int fd, int operation); //------------------------- Stat / Metadata Operations //-------------------------// int stat(const char* path, struct stat* buf); int stat64(const char* path, struct stat64* buf); // Note: Source uses __xstat64 symbol int lstat(const char* path, struct stat* st); int lstat64(const char* path, struct stat64* buf); int fstat(int fd, struct stat* buf); int fstat64(int fd, struct stat64* buf); int fstatat(int dfd, const char* path, struct stat* buf, int flags); int fstatat64(int dfd, const char* path, struct stat64* buf, int flags); int statx(int dirfd, const char* path, int flags, unsigned int mask, struct statx* statxbuf); int __xstat(int ver, const char* path, struct stat* buf); int __xstat64(int ver, const char* path, struct stat64* buf); int __lxstat(int ver, const char* path, struct stat* buf); int __lxstat64(int ver, const char* path, struct stat64* buf); int __fxstat(int ver, int fd, struct stat* buf); int __fxstatat(int ver, int dfd, const char* path, struct stat* buf, int flags); int __fxstat64(int ver, int fd, struct stat64* buf); //------------------------- Directory Operations -----------------------------// int mkdir(const char* path, mode_t mode); int mkdirat(int dirfd, const char* path, mode_t mode); int rmdir(const char* path); DIR* opendir(const char* dirname); DIR* opendir64(const char* dirname); DIR* fdopendir(int fd); // For scandir filter and compar function pointer types typedef int (*scandir_filter_func_t)(const struct dirent*); typedef int (*scandir_compar_func_t)(const struct dirent**, const struct dirent**); // Note: Original source uses `typeof` (GNU extension) for filter/compar in // scandir. Using standard function pointer typedefs here for better // portability. struct dirent* readdir(DIR* dirp); struct dirent64* readdir64(DIR* dirp); int closedir(DIR* dirp); void seekdir(DIR* dirp, long loc); long telldir(DIR* dirp); void rewinddir(DIR* dirstream); int scandir(const char* dirname, struct dirent*** namelist, scandir_filter_func_t filter, scandir_compar_func_t compar); //------------------------- Path Operations ----------------------------------// int remove(const char* path); int unlink(const char* path); int rename(const char* oldpath, const char* newpath); int renameat(int olddirfd, const char* oldpath, int newdirfd, const char* newpath); int renameat2(int olddirfd, const char* oldpath, int newdirfd, const char* newpath, unsigned int flags); int symlink(const char* target_path, const char* link_path); // POSIX: target, linkpath int symlinkat(const char* target_path, int newdirfd, const char* link_path); #ifdef HAS_SYMLINKS ssize_t readlink(const char* path, char* buf, size_t bufsize); ssize_t readlinkat(int dfd, const char* path, char* buf, size_t bufsize); #endif char* realpath(const char* path, char* resolved_path); char* __realpath_chk(const char* path, char* resolved_path, size_t resolved_len); // GNU Fortify Source variant int access(const char* path, int mode); int faccessat(int dfd, const char* path, int mode, int flags); int chdir(const char* path); int fchdir(int fd); char* getcwd(char* buffer, size_t size); //------------------------- Permissions --------------------------------------// int chmod(const char* path, mode_t mode); int fchmod(int fd, mode_t mode); int fchmodat(int dfd, const char* path, mode_t mode, int flags); int chown(const char* path, uid_t owner, gid_t group); int fchown(int fd, uid_t owner, gid_t group); //------------------------- Process and Descriptor Management //------------------// int dup(int fd); int dup2(int oldfd, int newfd); int dup3(int oldfd, int newfd, int flags); int fcntl(int fd, int cmd, ...); #ifdef GKFS_ENABLE_UNUSED_FUNCTIONS void exit(int status); // Note: This function does not return. int pipe(int pipefd[2]); #endif //------------------------- C Standard I/O (FILE*) ---------------------------// FILE* fopen(const char* path, const char* mode); FILE* fdopen(int fd, const char* mode); FILE* freopen64(const char* path, const char* mode, FILE* stream); // Note: Source uses "freopen" symbol int fclose(FILE* stream); size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream); size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream); int fseek(FILE* stream, long int offset, int whence); long ftell(FILE* stream); void rewind(FILE* stream); int feof(FILE* stream); void clearerr(FILE* stream); int fputs(const char* str, FILE* stream); char* fgets(char* str, int n, FILE* stream); int fflush(FILE* stream); //------------------------- AIO Operations -----------------------------------// int aio_read(struct aiocb* aiocbp); int aio_write(struct aiocb* aiocbp); int aio_error(const struct aiocb* aiocbp); ssize_t aio_return(struct aiocb* aiocbp); //------------------------- Miscellaneous / Unsorted //---------------------------// int mkstemp(char* templates); #ifdef GKFS_ENABLE_UNUSED_FUNCTIONS int futimes(int fd, const struct timeval tv[2]); int utimes(const char* path, const struct timeval tv[2]); ssize_t listxattr(const char* path, char* list, size_t size); ssize_t llistxattr(const char* path, char* list, size_t size); ssize_t flistxattr(int fd, char* list, size_t size); #endif //========================= C++ ABI Interceptions //==============================// // Intercepting C++ std::filesystem::remove_all // The mangled name can vary with compiler/STL version. // This specific name _ZNSt10filesystem10remove_allERKNS_7__cxx114pathE // is for a GCC/libstdc++ compiled version of std::filesystem::remove_all(const // std::filesystem::path&) To be link-time intercepted, it needs to be declared // extern "C". int _ZNSt10filesystem10remove_allERKNS_7__cxx114pathE( const std::filesystem::path& p); #ifdef __cplusplus } #endif src/client/gkfs_libc.cpp +0 −5 Original line number Diff line number Diff line Loading @@ -519,7 +519,6 @@ DLSYM_WRAPPER(int, statx, (dirfd, path, flags, mask, buf), "statx") DLSYM_WRAPPER(int, xstat64, (int ver, const char* path, struct stat64* buf), (ver, path, buf), "__xstat64") #ifdef GKFS_ENABLE_UNUSED_FUNCTIONS // __xstat variants DLSYM_WRAPPER(int, lxstat64, (int ver, const char* path, struct stat64* buf), (ver, path, buf), "__lxstat64") DLSYM_WRAPPER(int, __lxstat, (int ver, const char* path, struct stat* buf), Loading @@ -531,7 +530,6 @@ DLSYM_WRAPPER(int, fxstat64, (int ver, int fd, struct stat64* buf), DLSYM_WRAPPER(int, fxstatat, (int ver, int dfd, const char* path, struct stat* buf, int flags), (ver, dfd, path, buf, flags), "__fxstatat") #endif // Directory Operations DLSYM_WRAPPER(int, mkdir, (const char* path, mode_t mode), (path, mode), Loading Loading @@ -1173,8 +1171,6 @@ statx(int dirfd, const char* path, int flags, unsigned int mask, GKFS_FALLBACK(statx, dirfd, path, flags, mask, statxbuf); } #ifdef GKFS_ENABLE_UNUSED_FUNCTIONS // __xstat style functions (versioned) int __xstat(int ver, const char* path, struct stat* buf) { Loading Loading @@ -1339,7 +1335,6 @@ version // the versioned one. So, __fxstatat64 would need its own DLSYM_WRAPPER // targeting "__fxstatat64" if it exists. For now, keeping as per what was // explicitly in the original for __* variants. #endif // GKFS_ENABLE_UNUSED_FUNCTIONS //------------------------- Directory Operations -----------------------------// Loading Loading
include/client/gkfs_libc.hpp +280 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,286 @@ struct __dirstream { char data[1] __attribute__((aligned(__alignof__(void*)))); }; // Originally its 0, but C++ does not permit it //------------------------- File I/O Operations ------------------------------// int open(const char* path, int flags, ...); int open64(const char* path, int flags, ...); int openat(int dirfd, const char* path, int flags, ...); int openat64(int dirfd, const char* path, int flags, ...); // Note: Implemented via openat in source int creat(const char* path, mode_t mode); int close(int fd); int close_range(unsigned int low, unsigned int high, int flags); ssize_t read(int fd, void* buf, size_t nbyte); ssize_t write(int fd, const void* buf, size_t nbyte); ssize_t pread(int fd, void* buf, size_t count, off_t offset); ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset); ssize_t pread64(int fd, void* buf, size_t count, off64_t offset); ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset); ssize_t readv(int fd, const struct iovec* iov, int iovcnt); ssize_t writev(int fd, const struct iovec* iov, int iovcnt); ssize_t preadv(int fd, const struct iovec* iov, int iovcnt, off_t offset); ssize_t pwritev(int fd, const struct iovec* iov, int iovcnt, off_t offset); ssize_t preadv2(int fd, const struct iovec* iov, int iovcnt, off_t offset, int flags); ssize_t pwritev2(int fd, const struct iovec* iov, int iovcnt, off_t offset, int flags); off_t lseek(int fd, off_t offset, int whence); off64_t lseek64(int fd, off64_t offset, int whence); int ftruncate(int fd, off_t length); int fsync(int fd); int flock(int fd, int operation); //------------------------- Stat / Metadata Operations //-------------------------// int stat(const char* path, struct stat* buf); int stat64(const char* path, struct stat64* buf); // Note: Source uses __xstat64 symbol int lstat(const char* path, struct stat* st); int lstat64(const char* path, struct stat64* buf); int fstat(int fd, struct stat* buf); int fstat64(int fd, struct stat64* buf); int fstatat(int dfd, const char* path, struct stat* buf, int flags); int fstatat64(int dfd, const char* path, struct stat64* buf, int flags); int statx(int dirfd, const char* path, int flags, unsigned int mask, struct statx* statxbuf); int __xstat(int ver, const char* path, struct stat* buf); int __xstat64(int ver, const char* path, struct stat64* buf); int __lxstat(int ver, const char* path, struct stat* buf); int __lxstat64(int ver, const char* path, struct stat64* buf); int __fxstat(int ver, int fd, struct stat* buf); int __fxstatat(int ver, int dfd, const char* path, struct stat* buf, int flags); int __fxstat64(int ver, int fd, struct stat64* buf); //------------------------- Directory Operations -----------------------------// int mkdir(const char* path, mode_t mode); int mkdirat(int dirfd, const char* path, mode_t mode); int rmdir(const char* path); DIR* opendir(const char* dirname); DIR* opendir64(const char* dirname); DIR* fdopendir(int fd); // For scandir filter and compar function pointer types typedef int (*scandir_filter_func_t)(const struct dirent*); typedef int (*scandir_compar_func_t)(const struct dirent**, const struct dirent**); // Note: Original source uses `typeof` (GNU extension) for filter/compar in // scandir. Using standard function pointer typedefs here for better // portability. struct dirent* readdir(DIR* dirp); struct dirent64* readdir64(DIR* dirp); int closedir(DIR* dirp); void seekdir(DIR* dirp, long loc); long telldir(DIR* dirp); void rewinddir(DIR* dirstream); int scandir(const char* dirname, struct dirent*** namelist, scandir_filter_func_t filter, scandir_compar_func_t compar); //------------------------- Path Operations ----------------------------------// int remove(const char* path); int unlink(const char* path); int rename(const char* oldpath, const char* newpath); int renameat(int olddirfd, const char* oldpath, int newdirfd, const char* newpath); int renameat2(int olddirfd, const char* oldpath, int newdirfd, const char* newpath, unsigned int flags); int symlink(const char* target_path, const char* link_path); // POSIX: target, linkpath int symlinkat(const char* target_path, int newdirfd, const char* link_path); #ifdef HAS_SYMLINKS ssize_t readlink(const char* path, char* buf, size_t bufsize); ssize_t readlinkat(int dfd, const char* path, char* buf, size_t bufsize); #endif char* realpath(const char* path, char* resolved_path); char* __realpath_chk(const char* path, char* resolved_path, size_t resolved_len); // GNU Fortify Source variant int access(const char* path, int mode); int faccessat(int dfd, const char* path, int mode, int flags); int chdir(const char* path); int fchdir(int fd); char* getcwd(char* buffer, size_t size); //------------------------- Permissions --------------------------------------// int chmod(const char* path, mode_t mode); int fchmod(int fd, mode_t mode); int fchmodat(int dfd, const char* path, mode_t mode, int flags); int chown(const char* path, uid_t owner, gid_t group); int fchown(int fd, uid_t owner, gid_t group); //------------------------- Process and Descriptor Management //------------------// int dup(int fd); int dup2(int oldfd, int newfd); int dup3(int oldfd, int newfd, int flags); int fcntl(int fd, int cmd, ...); #ifdef GKFS_ENABLE_UNUSED_FUNCTIONS void exit(int status); // Note: This function does not return. int pipe(int pipefd[2]); #endif //------------------------- C Standard I/O (FILE*) ---------------------------// FILE* fopen(const char* path, const char* mode); FILE* fdopen(int fd, const char* mode); FILE* freopen64(const char* path, const char* mode, FILE* stream); // Note: Source uses "freopen" symbol int fclose(FILE* stream); size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream); size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream); int fseek(FILE* stream, long int offset, int whence); long ftell(FILE* stream); void rewind(FILE* stream); int feof(FILE* stream); void clearerr(FILE* stream); int fputs(const char* str, FILE* stream); char* fgets(char* str, int n, FILE* stream); int fflush(FILE* stream); //------------------------- AIO Operations -----------------------------------// int aio_read(struct aiocb* aiocbp); int aio_write(struct aiocb* aiocbp); int aio_error(const struct aiocb* aiocbp); ssize_t aio_return(struct aiocb* aiocbp); //------------------------- Miscellaneous / Unsorted //---------------------------// int mkstemp(char* templates); #ifdef GKFS_ENABLE_UNUSED_FUNCTIONS int futimes(int fd, const struct timeval tv[2]); int utimes(const char* path, const struct timeval tv[2]); ssize_t listxattr(const char* path, char* list, size_t size); ssize_t llistxattr(const char* path, char* list, size_t size); ssize_t flistxattr(int fd, char* list, size_t size); #endif //========================= C++ ABI Interceptions //==============================// // Intercepting C++ std::filesystem::remove_all // The mangled name can vary with compiler/STL version. // This specific name _ZNSt10filesystem10remove_allERKNS_7__cxx114pathE // is for a GCC/libstdc++ compiled version of std::filesystem::remove_all(const // std::filesystem::path&) To be link-time intercepted, it needs to be declared // extern "C". int _ZNSt10filesystem10remove_allERKNS_7__cxx114pathE( const std::filesystem::path& p); #ifdef __cplusplus } #endif
src/client/gkfs_libc.cpp +0 −5 Original line number Diff line number Diff line Loading @@ -519,7 +519,6 @@ DLSYM_WRAPPER(int, statx, (dirfd, path, flags, mask, buf), "statx") DLSYM_WRAPPER(int, xstat64, (int ver, const char* path, struct stat64* buf), (ver, path, buf), "__xstat64") #ifdef GKFS_ENABLE_UNUSED_FUNCTIONS // __xstat variants DLSYM_WRAPPER(int, lxstat64, (int ver, const char* path, struct stat64* buf), (ver, path, buf), "__lxstat64") DLSYM_WRAPPER(int, __lxstat, (int ver, const char* path, struct stat* buf), Loading @@ -531,7 +530,6 @@ DLSYM_WRAPPER(int, fxstat64, (int ver, int fd, struct stat64* buf), DLSYM_WRAPPER(int, fxstatat, (int ver, int dfd, const char* path, struct stat* buf, int flags), (ver, dfd, path, buf, flags), "__fxstatat") #endif // Directory Operations DLSYM_WRAPPER(int, mkdir, (const char* path, mode_t mode), (path, mode), Loading Loading @@ -1173,8 +1171,6 @@ statx(int dirfd, const char* path, int flags, unsigned int mask, GKFS_FALLBACK(statx, dirfd, path, flags, mask, statxbuf); } #ifdef GKFS_ENABLE_UNUSED_FUNCTIONS // __xstat style functions (versioned) int __xstat(int ver, const char* path, struct stat* buf) { Loading Loading @@ -1339,7 +1335,6 @@ version // the versioned one. So, __fxstatat64 would need its own DLSYM_WRAPPER // targeting "__fxstatat64" if it exists. For now, keeping as per what was // explicitly in the original for __* variants. #endif // GKFS_ENABLE_UNUSED_FUNCTIONS //------------------------- Directory Operations -----------------------------// Loading