2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU GPL.
8 gcc -Wall `pkg-config fuse --cflags --libs` hello.c -o hello
11 #define FUSE_USE_VERSION 26
19 static const char *hello_str
= "Hello World!\n";
20 static const char *hello_path
= "/hello";
22 static int hello_getattr(const char *path
, struct stat
*stbuf
)
26 memset(stbuf
, 0, sizeof(struct stat
));
27 if (strcmp(path
, "/") == 0) {
28 stbuf
->st_mode
= S_IFDIR
| 0755;
30 } else if (strcmp(path
, hello_path
) == 0) {
31 stbuf
->st_mode
= S_IFREG
| 0444;
33 stbuf
->st_size
= strlen(hello_str
);
40 static int hello_readdir(const char *path
, void *buf
, fuse_fill_dir_t filler
,
41 off_t offset
, struct fuse_file_info
*fi
)
46 if (strcmp(path
, "/") != 0)
49 filler(buf
, ".", NULL
, 0);
50 filler(buf
, "..", NULL
, 0);
51 filler(buf
, hello_path
+ 1, NULL
, 0);
56 static int hello_open(const char *path
, struct fuse_file_info
*fi
)
58 if (strcmp(path
, hello_path
) != 0)
61 if ((fi
->flags
& 3) != O_RDONLY
)
67 static int hello_read(const char *path
, char *buf
, size_t size
, off_t offset
,
68 struct fuse_file_info
*fi
)
72 if(strcmp(path
, hello_path
) != 0)
75 len
= strlen(hello_str
);
77 if (offset
+ size
> len
)
79 memcpy(buf
, hello_str
+ offset
, size
);
86 static struct fuse_operations hello_oper
= {
87 .getattr
= hello_getattr
,
88 .readdir
= hello_readdir
,
93 int main(int argc
, char *argv
[])
95 return fuse_main(argc
, argv
, &hello_oper
, NULL
);