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),
 
   63        conn->
want &= ~FUSE_CAP_ASYNC_READ;
 
   68static int hello_getattr(
const char *path, 
struct stat *stbuf,
 
   74        memset(stbuf, 0, 
sizeof(
struct stat));
 
   75        if (strcmp(path, 
"/") == 0) {
 
   76                stbuf->st_mode = S_IFDIR | 0755;
 
   78        } 
else if (strcmp(path+1, options.filename) == 0) {
 
   79                stbuf->st_mode = S_IFREG | 0444;
 
   81                stbuf->st_size = strlen(options.contents);
 
   88static int hello_readdir(
const char *path, 
void *buf, 
fuse_fill_dir_t filler,
 
   96        if (strcmp(path, 
"/") != 0)
 
  108        if (strcmp(path+1, options.filename) != 0)
 
  111        if ((fi->
flags & O_ACCMODE) != O_RDONLY)
 
  117static int hello_read(
const char *path, 
char *buf, 
size_t size, off_t 
offset,
 
  122        if(strcmp(path+1, options.filename) != 0)
 
  125        len = strlen(options.contents);
 
  129                memcpy(buf, options.contents + 
offset, size);
 
  138        .getattr        = hello_getattr,
 
  139        .readdir        = hello_readdir,
 
  144static void show_help(
const char *progname)
 
  146        printf(
"usage: %s [options] <mountpoint>\n\n", progname);
 
  147        printf(
"File-system specific options:\n" 
  148               "    --name=<s>          Name of the \"hello\" file\n" 
  149               "                        (default: \"hello\")\n" 
  150               "    --contents=<s>      Contents \"hello\" file\n" 
  151               "                        (default \"Hello, World!\\n\")\n" 
  155int main(
int argc, 
char *argv[])
 
  163        options.filename = strdup(
"hello");
 
  164        options.contents = strdup(
"Hello World!\n");
 
  175        if (options.show_help) {
 
  178                args.
argv[0][0] = 
'\0';
 
  181        ret = fuse_main(args.
argc, args.
argv, &hello_oper, NULL);
 
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_CAP_ASYNC_READ
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)