You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
1.7 KiB

  1. /*
  2. FUSE: Filesystem in Userspace
  3. Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
  4. This program can be distributed under the terms of the GNU GPL.
  5. See the file COPYING.
  6. gcc -Wall null.c `pkg-config fuse --cflags --libs` -o null
  7. */
  8. #define FUSE_USE_VERSION 26
  9. #include <fuse.h>
  10. #include <string.h>
  11. #include <unistd.h>
  12. #include <time.h>
  13. #include <errno.h>
  14. static int null_getattr(const char *path, struct stat *stbuf)
  15. {
  16. if(strcmp(path, "/") != 0)
  17. return -ENOENT;
  18. stbuf->st_mode = S_IFREG | 0644;
  19. stbuf->st_nlink = 1;
  20. stbuf->st_uid = getuid();
  21. stbuf->st_gid = getgid();
  22. stbuf->st_size = (1ULL << 32); /* 4G */
  23. stbuf->st_blocks = 0;
  24. stbuf->st_atime = stbuf->st_mtime = stbuf->st_ctime = time(NULL);
  25. return 0;
  26. }
  27. static int null_truncate(const char *path, off_t size)
  28. {
  29. (void) size;
  30. if(strcmp(path, "/") != 0)
  31. return -ENOENT;
  32. return 0;
  33. }
  34. static int null_open(const char *path, struct fuse_file_info *fi)
  35. {
  36. (void) fi;
  37. if(strcmp(path, "/") != 0)
  38. return -ENOENT;
  39. return 0;
  40. }
  41. static int null_read(const char *path, char *buf, size_t size,
  42. off_t offset, struct fuse_file_info *fi)
  43. {
  44. (void) buf;
  45. (void) offset;
  46. (void) fi;
  47. if(strcmp(path, "/") != 0)
  48. return -ENOENT;
  49. if (offset >= (1ULL << 32))
  50. return 0;
  51. return size;
  52. }
  53. static int null_write(const char *path, const char *buf, size_t size,
  54. off_t offset, struct fuse_file_info *fi)
  55. {
  56. (void) buf;
  57. (void) offset;
  58. (void) fi;
  59. if(strcmp(path, "/") != 0)
  60. return -ENOENT;
  61. return size;
  62. }
  63. static struct fuse_operations null_oper = {
  64. .getattr = null_getattr,
  65. .truncate = null_truncate,
  66. .open = null_open,
  67. .read = null_read,
  68. .write = null_write,
  69. };
  70. int main(int argc, char *argv[])
  71. {
  72. return fuse_main(argc, argv, &null_oper, NULL);
  73. }