2
FUSE: Filesystem in Userspace
3
Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
5
This program can be distributed under the terms of the GNU GPL.
15
static const char *hello_str = "Hello World!\n";
16
static const char *hello_path = "/hello";
18
static int hello_getattr(const char *path, struct stat *stbuf)
22
memset(stbuf, 0, sizeof(struct stat));
23
if(strcmp(path, "/") == 0) {
24
stbuf->st_mode = S_IFDIR | 0755;
27
else if(strcmp(path, hello_path) == 0) {
28
stbuf->st_mode = S_IFREG | 0444;
30
stbuf->st_size = strlen(hello_str);
38
static int hello_getdir(const char *path, fuse_dirh_t h, fuse_dirfil_t filler)
40
if(strcmp(path, "/") != 0)
44
filler(h, "..", 0, 0);
45
filler(h, hello_path + 1, 0, 0);
50
static int hello_open(const char *path, struct fuse_file_info *fi)
52
if(strcmp(path, hello_path) != 0)
55
if((fi->flags & 3) != O_RDONLY)
61
static int hello_read(const char *path, char *buf, size_t size, off_t offset,
62
struct fuse_file_info *fi)
66
if(strcmp(path, hello_path) != 0)
69
len = strlen(hello_str);
71
if (offset + size > len)
73
memcpy(buf, hello_str + offset, size);
80
static struct fuse_operations hello_oper = {
81
.getattr = hello_getattr,
82
.getdir = hello_getdir,
87
int main(int argc, char *argv[])
89
return fuse_main(argc, argv, &hello_oper);