From 8fcfebe3f911690d0613c3705b684fd9d7d7f569 Mon Sep 17 00:00:00 2001 From: fedir Date: Wed, 20 Nov 2024 10:32:33 +0100 Subject: [PATCH] Implemented getattr and source_stat. Now filesystem implements getattr through source_stat, which is a wrapper for an fstatat with `dirfd == handle.root_path`. --- sources/main.c | 28 ++++++++++++++++++++++++++++ sources/sourcefs.c | 9 ++++++++- sources/sourcefs.h | 9 +++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/sources/main.c b/sources/main.c index 133f13d..a625b69 100644 --- a/sources/main.c +++ b/sources/main.c @@ -20,8 +20,36 @@ static void *icfs_init(struct fuse_conn_info *conn, struct fuse_config *cfg) { return NULL; } +static int icfs_getattr(const char *path, struct stat *stbuf, + struct fuse_file_info *fi) { + + int statret = source_stat(path, stbuf); + + //(void)fi; + + /* + int res = 0; + + memset(stbuf, 0, sizeof(struct stat)); + if (strcmp(path, "/") == 0) { + stbuf->st_mode = S_IFDIR | 0755; + stbuf->st_nlink = 2; + } else if (strcmp(path + 1, options.filename) == 0) { + stbuf->st_mode = S_IFREG | 0444; + stbuf->st_nlink = 1; + stbuf->st_size = strlen(options.contents); + } else + res = -ENOENT; + + */ + // return res; + + return statret; +} + static const struct fuse_operations icfs_oper = { .init = icfs_init, + .getattr = icfs_getattr, }; int main(int argc, char *argv[]) { diff --git a/sources/sourcefs.c b/sources/sourcefs.c index 0d26955..41a625d 100644 --- a/sources/sourcefs.c +++ b/sources/sourcefs.c @@ -1,8 +1,9 @@ #define _GNU_SOURCE #include "sourcefs.h" - #include +#include +#include static struct source_files_handle { int root_fd; @@ -19,3 +20,9 @@ int source_init(const char *root_path) { return 0; } + +// Currently this literally is a fstatat wrapper. +int source_stat(const char *restrict pathname, struct stat *restrict statbuf) { + int statret = fstatat(handle.root_fd, pathname, statbuf, 0); + return statret; +} diff --git a/sources/sourcefs.h b/sources/sourcefs.h index e5ff4dc..4b1a0e8 100644 --- a/sources/sourcefs.h +++ b/sources/sourcefs.h @@ -3,6 +3,8 @@ #ifndef SOURCEFS_H #define SOURCEFS_H +#include + /** * Initializes the source file handling. * @@ -11,4 +13,11 @@ */ int source_init(const char *root_path); +/** + * `stat()`, but for source files. + * + * @see `stat()` + */ +int source_stat(const char *restrict pathname, struct stat *restrict statbuf); + #endif // !SOURCEFS_H