22#define FUSE_USE_VERSION 31
39static struct options {
46 { t, offsetof(struct options, p), 1 }
47static const struct fuse_opt option_spec[] = {
48 OPTION(
"--name=%s", filename),
49 OPTION(
"--contents=%s", contents),
50 OPTION(
"-h", show_help),
51 OPTION(
"--help", show_help),
63static int hello_getattr(
const char *path,
struct stat *stbuf,
69 memset(stbuf, 0,
sizeof(
struct stat));
70 if (strcmp(path,
"/") == 0) {
71 stbuf->st_mode = S_IFDIR | 0755;
73 }
else if (strcmp(path+1, options.filename) == 0) {
74 stbuf->st_mode = S_IFREG | 0444;
76 stbuf->st_size = strlen(options.contents);
83static int hello_readdir(
const char *path,
void *buf,
fuse_fill_dir_t filler,
91 if (strcmp(path,
"/") != 0)
94 filler(buf,
".", NULL, 0, 0);
95 filler(buf,
"..", NULL, 0, 0);
96 filler(buf, options.filename, NULL, 0, 0);
103 if (strcmp(path+1, options.filename) != 0)
106 if ((fi->
flags & O_ACCMODE) != O_RDONLY)
112static int hello_read(
const char *path,
char *buf,
size_t size, off_t
offset,
117 if(strcmp(path+1, options.filename) != 0)
120 len = strlen(options.contents);
124 memcpy(buf, options.contents +
offset, size);
133 .getattr = hello_getattr,
134 .readdir = hello_readdir,
139static void show_help(
const char *progname)
141 printf(
"usage: %s [options] <mountpoint>\n\n", progname);
142 printf(
"File-system specific options:\n"
143 " --name=<s> Name of the \"hello\" file\n"
144 " (default: \"hello\")\n"
145 " --contents=<s> Contents \"hello\" file\n"
146 " (default \"Hello, World!\\n\")\n"
150int main(
int argc,
char *argv[])
158 options.filename = strdup(
"hello");
159 options.contents = strdup(
"Hello World!\n");
170 if (options.show_help) {
173 args.
argv[0][0] =
'\0';
int(* fuse_fill_dir_t)(void *buf, const char *name, const struct stat *stbuf, off_t off, enum fuse_fill_dir_flags flags)
#define fuse_main(argc, argv, op, private_data)
int fuse_opt_add_arg(struct fuse_args *args, const char *arg)
void fuse_opt_free_args(struct fuse_args *args)
int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)
#define FUSE_ARGS_INIT(argc, argv)
void *(* init)(struct fuse_conn_info *conn, struct fuse_config *cfg)