首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有libfuse和文件所有权的自定义文件系统

具有libfuse和文件所有权的自定义文件系统
EN

Stack Overflow用户
提问于 2019-10-31 15:13:27
回答 1查看 235关注 0票数 0

用户创建文件时,会调用create回调:

代码语言:javascript
复制
int (*create) (const char *, mode_t, struct fuse_file_info *);

有关详细信息https://github.com/libfuse/libfuse/blob/74596e2929c9b9b065f90d04ab7a2232652c64c4/include/fuse.h#L609,请参阅链接

但是在哪里没有关于哪个用户想要创建文件的信息,这意味着文件将始终与运行fuse进程的所有者用户一起创建。

例如,我以根用户身份启动fuse进程,但从我的用户创建文件:

代码语言:javascript
复制
$ echo $USERNAME
 myuser
$ echo 'f' > f
$ ll
$ ll
total 4,0K
-rw-r--r-- 1 root root
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-31 18:11:46

您可以使用全局fuse上下文获取调用用户的uid和gid:

代码语言:javascript
复制
        struct fuse_context *cxt = fuse_get_context();
        if (cxt)
            uid = cxt->uid;
            gid = cxt->gid;

来自fuse.h

代码语言:javascript
复制
/** Extra context that may be needed by some filesystems
 *
 * The uid, gid and pid fields are not filled in case of a writepage
 * operation.
 */
struct fuse_context {
    /** Pointer to the fuse object */
    struct fuse *fuse;

    /** User ID of the calling process */
    uid_t uid;

    /** Group ID of the calling process */
    gid_t gid;

    /** Process ID of the calling thread */
    pid_t pid;

    /** Private filesystem data */
    void *private_data;

    /** Umask of the calling process */
    mode_t umask;
};
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58638429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档