Merge remote-tracking branch 'origin/fuse_2_9_bugfix'
[fuse.git] / example / null.c
blob1ff19548248f7e90c93f6d47f3197ab18d447548
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.
7 */
9 /** @file
11 * null.c - FUSE: Filesystem in Userspace
13 * \section section_compile compiling this example
15 * gcc -Wall null.c `pkg-config fuse3 --cflags --libs` -o null
17 * \section section_source the complete source
18 * \include null.c
22 #define FUSE_USE_VERSION 30
24 #include <config.h>
26 #include <fuse.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <time.h>
30 #include <errno.h>
32 static int null_getattr(const char *path, struct stat *stbuf)
34 if(strcmp(path, "/") != 0)
35 return -ENOENT;
37 stbuf->st_mode = S_IFREG | 0644;
38 stbuf->st_nlink = 1;
39 stbuf->st_uid = getuid();
40 stbuf->st_gid = getgid();
41 stbuf->st_size = (1ULL << 32); /* 4G */
42 stbuf->st_blocks = 0;
43 stbuf->st_atime = stbuf->st_mtime = stbuf->st_ctime = time(NULL);
45 return 0;
48 static int null_truncate(const char *path, off_t size)
50 (void) size;
52 if(strcmp(path, "/") != 0)
53 return -ENOENT;
55 return 0;
58 static int null_open(const char *path, struct fuse_file_info *fi)
60 (void) fi;
62 if(strcmp(path, "/") != 0)
63 return -ENOENT;
65 return 0;
68 static int null_read(const char *path, char *buf, size_t size,
69 off_t offset, struct fuse_file_info *fi)
71 (void) buf;
72 (void) offset;
73 (void) fi;
75 if(strcmp(path, "/") != 0)
76 return -ENOENT;
78 if (offset >= (1ULL << 32))
79 return 0;
81 return size;
84 static int null_write(const char *path, const char *buf, size_t size,
85 off_t offset, struct fuse_file_info *fi)
87 (void) buf;
88 (void) offset;
89 (void) fi;
91 if(strcmp(path, "/") != 0)
92 return -ENOENT;
94 return size;
97 static struct fuse_operations null_oper = {
98 .getattr = null_getattr,
99 .truncate = null_truncate,
100 .open = null_open,
101 .read = null_read,
102 .write = null_write,
105 int main(int argc, char *argv[])
107 return fuse_main(argc, argv, &null_oper, NULL);