【问题标题】:FUSE lib passthrough.c example. Where is it mirrors my / exactly?FUSE lib passthrough.c 示例。它在哪里反映了我的 / 究竟是什么?
【发布时间】:2018-06-02 09:17:30
【问题描述】:

我是 FUSE 和 c 和 FS 的新手,我正在搞乱 libfuse 包中给出的 passthrough FS 示例。任何人都可以提示在代码中命令 FUSE 镜像我的根目录的位置吗?因为我发现了两个基本函数 - *xmp_init() 和 main() - 非常简洁。

他们在这里:

static void *xmp_init(struct fuse_conn_info *conn,
              struct fuse_config *cfg)
{
    (void) conn;
    cfg->use_ino = 1;
    cfg->entry_timeout = 0;
    cfg->attr_timeout = 0;
    cfg->negative_timeout = 0;

    return NULL;
}

int main(int argc, char *argv[])
{
    umask(0);
    return fuse_main(argc, argv, &xmp_oper, NULL);
}

而其他功能只是 libfuse 接口的实现......东西。我需要制作自己的残缺FS,我需要修改passthrough.c,以便安装的FS成为一张白纸,我可以使用已实现的功能并管理文件和东西。

【问题讨论】:

    标签: c linux filesystems fuse


    【解决方案1】:

    尝试阅读示例中任何熔断器操作的实现,您将看到它。没有一个地方可以隐藏有关根文件系统镜像的特定细节。

    例如,让我们检查getattr fuse operation,它类似于stat(2) 系统调用,并期望(通过指针)返回给定文件的统计结构。

    当在fuse文件系统中访问某个文件时,首先调用实现gettattr操作的函数,这使得该操作的实现成为强制性的。

    看着the implementation in the example

    static int xmp_getattr(const char *path, struct stat *stbuf,
               struct fuse_file_info *fi)
    {
        (void) fi;
        int res;
    
        res = lstat(path, stbuf);
        if (res == -1)
            return -errno;
    
        return 0;
    }
    

    我们看到这段代码所做的只是用相同的参数调用lstat(2)

    所以当你像这样挂载这个示例文件系统时:

    $ ./passthrough /tmp/example
    

    然后尝试在那里列出文件:

    $ ls /tmp/example/
    

    fuselib 将使用路径 "/" 调用 xmp_getattr(),因为您正在访问 fuse 文件系统的根目录。然后xmp_getattr() 中的代码将只为类似的事情调用普通系统调用,以便根文件系统在/tmp/example 挂载点中看起来镜像。

    【讨论】:

      【解决方案2】:

      marbu 的回答是正确的。我只会澄清传递给xmp_getattr() et.al 的路径参数。是相对于挂载点的,因此/tmp/example/ 变成了/。如果您愿意,您可以使用 -g 标志编译 passthrough 并在安装后附加 gdb 以检查参数。

      【讨论】:

        猜你喜欢
        • 2022-01-26
        • 2020-09-29
        • 1970-01-01
        • 1970-01-01
        • 2013-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-18
        相关资源
        最近更新 更多