Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | 149f607 | 2005-01-10 12:29:28 +0000 | [diff] [blame] | 3 | Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu> |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 4 | |
| 5 | This program can be distributed under the terms of the GNU GPL. |
| 6 | See the file COPYING. |
| 7 | */ |
| 8 | |
| 9 | #include <fuse.h> |
Miklos Szeredi | 074b4b9 | 2002-01-11 08:25:52 +0000 | [diff] [blame] | 10 | #include <string.h> |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 11 | #include <unistd.h> |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 12 | #include <time.h> |
Miklos Szeredi | cc8c975 | 2001-11-21 10:03:39 +0000 | [diff] [blame] | 13 | #include <errno.h> |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 14 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 15 | static int null_getattr(const char *path, struct stat *stbuf) |
| 16 | { |
| 17 | if(strcmp(path, "/") != 0) |
| 18 | return -ENOENT; |
Miklos Szeredi | e518374 | 2005-02-02 11:14:04 +0000 | [diff] [blame] | 19 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 20 | stbuf->st_mode = S_IFREG | 0644; |
| 21 | stbuf->st_nlink = 1; |
| 22 | stbuf->st_uid = getuid(); |
| 23 | stbuf->st_gid = getgid(); |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 24 | stbuf->st_size = (1ULL << 32); /* 4G */ |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 25 | stbuf->st_blocks = 0; |
| 26 | stbuf->st_atime = stbuf->st_mtime = stbuf->st_ctime = time(NULL); |
| 27 | |
| 28 | return 0; |
| 29 | } |
| 30 | |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 31 | static int null_truncate(const char *path, off_t size) |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 32 | { |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 33 | (void) size; |
| 34 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 35 | if(strcmp(path, "/") != 0) |
| 36 | return -ENOENT; |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 41 | static int null_open(const char *path, struct fuse_file_info *fi) |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 42 | { |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 43 | (void) fi; |
| 44 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 45 | if(strcmp(path, "/") != 0) |
| 46 | return -ENOENT; |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 51 | static int null_read(const char *path, char *buf, size_t size, |
| 52 | off_t offset, struct fuse_file_info *fi) |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 53 | { |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 54 | (void) buf; |
| 55 | (void) offset; |
| 56 | (void) fi; |
| 57 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 58 | if(strcmp(path, "/") != 0) |
| 59 | return -ENOENT; |
| 60 | |
| 61 | return size; |
| 62 | } |
| 63 | |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 64 | static int null_write(const char *path, const char *buf, size_t size, |
| 65 | off_t offset, struct fuse_file_info *fi) |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 66 | { |
Miklos Szeredi | f6e0ec6 | 2005-08-03 09:11:06 +0000 | [diff] [blame] | 67 | (void) buf; |
| 68 | (void) offset; |
| 69 | (void) fi; |
| 70 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 71 | if(strcmp(path, "/") != 0) |
| 72 | return -ENOENT; |
| 73 | |
| 74 | return size; |
| 75 | } |
| 76 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 77 | static struct fuse_operations null_oper = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 78 | .getattr = null_getattr, |
| 79 | .truncate = null_truncate, |
| 80 | .open = null_open, |
| 81 | .read = null_read, |
| 82 | .write = null_write, |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 85 | int main(int argc, char *argv[]) |
| 86 | { |
Miklos Szeredi | 5dc8a80 | 2004-10-21 09:35:10 +0000 | [diff] [blame] | 87 | return fuse_main(argc, argv, &null_oper); |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 88 | } |