I have read several examples about FUSE(Filesystem in Userspace) from
Big Brother FileSystem: Writing a FUSE Filesystem: a Tutorial
some posts from Stackoverflow.
I know I need to write my own callback functions in the fuse_operations.
Question
How to write mount and unmount by using FUSE?
How to customize my file system?
struct fuse_operations {
int (*getattr) (const char *, struct stat *);
int (*readlink) (const char *, char *, size_t);
int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
int (*mknod) (const char *, mode_t, dev_t);
int (*mkdir) (const char *, mode_t);
int (*unlink) (const char *);
int (*rmdir) (const char *);
int (*symlink) (const char *, const char *);
int (*rename) (const char *, const char *);
int (*link) (const char *, const char *);
int (*chmod) (const char *, mode_t);
int (*chown) (const char *, uid_t, gid_t);
int (*truncate) (const char *, off_t);
int (*utime) (const char *, struct utimbuf *);
int (*open) (const char *, struct fuse_file_info *);
int (*read) (const char *, char *, size_t, off_t, struct fuse_file_info *);
int (*write) (const char *, const char *, size_t, off_t,struct fuse_file_info *);
int (*statfs) (const char *, struct statfs *);
int (*flush) (const char *, struct fuse_file_info *);
int (*release) (const char *, struct fuse_file_info *);
int (*fsync) (const char *, int, struct fuse_file_info *);
int (*setxattr) (const char *, const char *, const char *, size_t, int);
int (*getxattr) (const char *, const char *, char *, size_t);
int (*listxattr) (const char *, char *, size_t);
int (*removexattr) (const char *, const char *);
};
一看这全英文的问题,就不想回答了。英文问题应该去问洋人!
还是简单的说一下,最好的方式就是看
fuse
的example
目录中的例子。1、首先,你要安装好
fuse
库,当前版本应该是3了。2、看
struct fuse_operations
中的函数指针,实现你需要自定义的那些。比如说你需要在mkdir
的时候,同时在新建的目录下创建一个文件,那么你就写一个自定义的mkdir
函数,然后在这个函数里面实现你要做的事情。3、创建一个
struct fuse_operations
对象,然后将你自定义的函数赋值给对应的成员。4、调用
fuse_main
函数,传入第三步创建的对象。fuse_main函数的前两个参数是int argc,char* argv[]
,第一个参数argc指示第二个参数argv数组中元素的个数。还是看代码吧当对
/tmp/myfs
目录进行操作的时候,就会调用你自定义的接口。