用户创建文件时,会调用create回调:
int (*create) (const char *, mode_t, struct fuse_file_info *);有关详细信息https://github.com/libfuse/libfuse/blob/74596e2929c9b9b065f90d04ab7a2232652c64c4/include/fuse.h#L609,请参阅链接
但是在哪里没有关于哪个用户想要创建文件的信息,这意味着文件将始终与运行fuse进程的所有者用户一起创建。
例如,我以根用户身份启动fuse进程,但从我的用户创建文件:
$ echo $USERNAME
myuser
$ echo 'f' > f
$ ll
$ ll
total 4,0K
-rw-r--r-- 1 root root发布于 2019-10-31 18:11:46
您可以使用全局fuse上下文获取调用用户的uid和gid:
struct fuse_context *cxt = fuse_get_context();
if (cxt)
uid = cxt->uid;
gid = cxt->gid;来自fuse.h
/** 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;
};https://stackoverflow.com/questions/58638429
复制相似问题