Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* > /dev/null 2>&1
- gcc $0 -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=25 -lfuse -o null_fs "$@"
- exit
- */
- #include <fuse.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <fcntl.h>
- static int dev_null_fd;
- static char *troll;
- static int null_getattr(const char *path, struct stat *stbuf)
- {
- memset(stbuf, 0, sizeof(struct stat));
- if(strcmp(path, "/") == 0)
- {
- stbuf->st_mode = S_IFDIR | 0777;
- stbuf->st_nlink = 2;
- return 0;
- }
- if(strcmp(path, troll) == 0)
- {
- stbuf->st_mode = S_IFREG | 0777;
- stbuf->st_nlink = 1;
- return 0;
- }
- return -ENOENT;
- }
- static int null_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
- off_t offset, struct fuse_file_info *fi)
- {
- if(strcmp(path, "/") != 0)
- {
- return -ENOENT;
- }
- filler(buf, ".", NULL, 0);
- filler(buf, "..", NULL, 0);
- return 0;
- }
- static int null_open(const char *path, struct fuse_file_info *fi)
- {
- return 0;
- }
- static int null_read(const char *path, char *buf, size_t size, off_t offset,
- struct fuse_file_info *fi)
- {
- return read(dev_null_fd, buf, size);
- }
- static int null_write(const char *path, const char *buf, size_t size, off_t offset,
- struct fuse_file_info *fi)
- {
- return size;
- }
- static int null_create(const char *path, mode_t mode, struct fuse_file_info *fi)
- {
- free(troll);
- troll = strdup(path);
- return 0;
- }
- static struct fuse_operations null_oper = {
- .getattr = null_getattr,
- .readdir = null_readdir,
- .open = null_open,
- .read = null_read,
- .write = null_write,
- .create = null_create
- };
- int main(int argc, char *argv[])
- {
- troll = strdup("");
- dev_null_fd = open("/dev/null",O_RDWR);
- return fuse_main(argc, argv, &null_oper);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement