Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://stackoverflow.com/questions/78986903/fuse3-inability-to-create-inode-based-virtual-file-system
- #define FUSE_USE_VERSION 31
- #include <fuse3/fuse.h>
- #include <stdio.h>
- #include <string.h>
- #include <dirent.h>
- #include <errno.h>
- static void *xmp_init(struct fuse_conn_info *conn, struct fuse_config *cfg) {
- // From passthrough example
- cfg->use_ino = 1;
- cfg->entry_timeout = 0;
- cfg->attr_timeout = 0;
- cfg->negative_timeout = 0;
- // // From hello.c example
- // cfg->kernel_cache = 1;
- // cfg->readdir_ino = 1;
- // cfg->remember = -1;
- return NULL;
- }
- static int xmp_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi) {
- (void) fi;
- int res;
- // NOTE: Why it doesn't read the inode of "/hello.txt" ???
- // (it prints ERROR for that file too if you `ls`)
- // the only thing I want, is to read the inode, nothing more.
- res = lstat(path, stbuf);
- if (res == -1){
- printf("\033[91mERROR: getattr %lu %s\033[0m\n", stbuf->st_ino, path); // stbuf->st_ino just in case it returns -1 but fills the inode
- return -errno;
- }
- printf("getattr %lu = %s\n", stbuf->st_ino, path);
- return 0;
- }
- static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi, enum fuse_readdir_flags flags) {
- if (strcmp(path, "/") != 0)
- return -ENOENT;
- printf("readdir: %s\n", path );
- filler(buf, ".", NULL, 0, 0);
- filler(buf, "..", NULL, 0, 0);
- struct stat st;
- memset(&st, 0, sizeof(st));
- st.st_ino = 5; // NOTE: WHY INODE IS NOT SET ???????
- st.st_mode = S_IFREG | 0444;
- filler(buf, "hello.txt", &st, 0, 0); // maybe use "..., FUSE_FILL_DIR_PLUS);"
- // // passthrough.c
- // DIR *dp;
- // struct dirent *de;
- // (void) offset;
- // (void) fi;
- // (void) flags;
- // dp = opendir(path);
- // if (dp == NULL)
- // return -errno;
- //
- // while ((de = readdir(dp)) != NULL) {
- // b++;
- // struct stat st;
- // memset(&st, 0, sizeof(st));
- // st.st_ino = de->d_ino;
- // st.st_mode = de->d_type << 12;
- // // printf("%lu : %lu = %s\n", de->d_ino, b, de->d_name );
- // char buf[100];
- // snprintf(buf, 100, "name_%lu", b);
- // if (filler(buf, buf, &st, 0, 0))
- // break;
- // }
- // closedir(dp);
- return 0;
- }
- static struct fuse_operations xmp_oper = {
- .init = xmp_init,
- .getattr = xmp_getattr,
- .readdir = xmp_readdir,
- };
- int main(int argc, char *argv[]) {
- // umask(0);
- return fuse_main(argc, argv, &xmp_oper, NULL);
- }
Advertisement
Comments
-
- https://stackoverflow.com/questions/78986903/fuse3-inability-to-create-inode-based-virtual-file-system
Add Comment
Please, Sign In to add comment