21#define FUSE_USE_VERSION 31 
   38static struct options {
 
   44#define OPTION(t, p) { t, offsetof(struct options, p), 1 } 
   45static const struct fuse_opt option_spec[] = {
 
   46        OPTION(
"--name=%s", filename), OPTION(
"--contents=%s", contents),
 
   47        OPTION(
"-h", show_help), OPTION(
"--help", show_help), 
FUSE_OPT_END 
   57        conn->
want &= ~FUSE_CAP_ASYNC_READ;
 
   62static int hello_getattr(
const char *path, 
struct stat *stbuf,
 
   68        memset(stbuf, 0, 
sizeof(
struct stat));
 
   69        if (strcmp(path, 
"/") == 0) {
 
   70                stbuf->st_mode = S_IFDIR | 0755;
 
   72        } 
else if (strcmp(path + 1, options.filename) == 0) {
 
   73                stbuf->st_mode = S_IFREG | 0444;
 
   75                stbuf->st_size = strlen(options.contents);
 
   82static int hello_readdir(
const char *path, 
void *buf, 
fuse_fill_dir_t filler,
 
   90        if (strcmp(path, 
"/") != 0)
 
  102        if (strcmp(path + 1, options.filename) != 0)
 
  105        if ((fi->
flags & O_ACCMODE) != O_RDONLY)
 
  111static int hello_read(
const char *path, 
char *buf, 
size_t size, off_t 
offset,
 
  116        if (strcmp(path + 1, options.filename) != 0)
 
  119        len = strlen(options.contents);
 
  123                memcpy(buf, options.contents + 
offset, size);
 
  132        .getattr = hello_getattr,
 
  133        .readdir = hello_readdir,
 
  138static void show_help(
const char *progname)
 
  140        printf(
"usage: %s [options] <mountpoint>\n\n", progname);
 
  141        printf(
"File-system specific options:\n" 
  142               "    --name=<s>          Name of the \"hello\" file\n" 
  143               "                        (default: \"hello\")\n" 
  144               "    --contents=<s>      Contents \"hello\" file\n" 
  145               "                        (default \"Hello, World!\\n\")\n" 
  149int main(
int argc, 
char *argv[])
 
  158        options.filename = strdup(
"hello");
 
  159        options.contents = strdup(
"Hello World!\n");
 
  171        if (options.show_help) {
 
  174                args.
argv[0][0] = 
'\0';
 
  177        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)