Fix missing config.h in buffer.c
[fuse.git] / example / null.c
blobb72cf4d3fb3a310adab08b0f78ab6bf4373503d8
1 /*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
8 gcc -Wall null.c `pkg-config fuse --cflags --libs` -o null
9 */
11 #define FUSE_USE_VERSION 26
13 #include <fuse.h>
14 #include <string.h>
15 #include <unistd.h>
16 #include <time.h>
17 #include <errno.h>
19 static int null_getattr(const char *path, struct stat *stbuf)
21 if(strcmp(path, "/") != 0)
22 return -ENOENT;
24 stbuf->st_mode = S_IFREG | 0644;
25 stbuf->st_nlink = 1;
26 stbuf->st_uid = getuid();
27 stbuf->st_gid = getgid();
28 stbuf->st_size = (1ULL << 32); /* 4G */
29 stbuf->st_blocks = 0;
30 stbuf->st_atime = stbuf->st_mtime = stbuf->st_ctime = time(NULL);
32 return 0;
35 static int null_truncate(const char *path, off_t size)
37 (void) size;
39 if(strcmp(path, "/") != 0)
40 return -ENOENT;
42 return 0;
45 static int null_open(const char *path, struct fuse_file_info *fi)
47 (void) fi;
49 if(strcmp(path, "/") != 0)
50 return -ENOENT;
52 return 0;
55 static int null_read(const char *path, char *buf, size_t size,
56 off_t offset, struct fuse_file_info *fi)
58 (void) buf;
59 (void) offset;
60 (void) fi;
62 if(strcmp(path, "/") != 0)
63 return -ENOENT;
65 if (offset >= (1ULL << 32))
66 return 0;
68 return size;
71 static int null_write(const char *path, const char *buf, size_t size,
72 off_t offset, struct fuse_file_info *fi)
74 (void) buf;
75 (void) offset;
76 (void) fi;
78 if(strcmp(path, "/") != 0)
79 return -ENOENT;
81 return size;
84 static struct fuse_operations null_oper = {
85 .getattr = null_getattr,
86 .truncate = null_truncate,
87 .open = null_open,
88 .read = null_read,
89 .write = null_write,
92 int main(int argc, char *argv[])
94 return fuse_main(argc, argv, &null_oper, NULL);