当用户创建文件时,将调用create回调:
int (*create) (const char *, mode_t, struct fuse_file_info *);
有关详细信息,请参阅链接https://github.com/libfuse/libfuse/blob/74596e2929c9b9b065f90d04ab7a2232652c64c4/include/fuse.h#L609
但并没有关于用户想要创建文件的信息,这意味着文件将始终由融合进程运行的所有者用户创建。
例如,我以root身份启动了fuse进程,但从我的用户创建了文件:
$ echo $USERNAME
myuser
$ echo 'f' > f
$ ll
$ ll
total 4,0K
-rw-r--r-- 1 root root
您可以使用全局fuse上下文获取调用用户的uid和gid:
struct fuse_context *cxt = fuse_get_context();
if (cxt)
uid = cxt->uid;
gid = cxt->gid;
来自保险丝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;
};