Advertisement
steverobinson

FUSE example

Oct 31st, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #define FUSE_USE_VERSION 26
  2.  
  3. #include <fuse.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <errno.h>
  7. #include <fcntl.h>
  8.  
  9. static const char *hello_str = "Hello World!\n";
  10. static const char *hello_path = "/hello";
  11.  
  12. static int hello_getattr(const char *path, struct stat *stbuf)
  13. {
  14. int res = 0;
  15. memset(stbuf, 0, sizeof(struct stat));
  16. if(strcmp(path, "/") == 0) {
  17. stbuf->st_mode = S_IFDIR | 0755;
  18. stbuf->st_nlink = 2;
  19. }
  20. else if(strcmp(path, hello_path) == 0) {
  21. stbuf->st_mode = S_IFREG | 0444;
  22. stbuf->st_nlink = 1;
  23. stbuf->st_size = strlen(hello_str);
  24. }
  25. else
  26. res = -ENOENT;
  27.  
  28. return res;
  29. }
  30.  
  31. static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
  32. off_t offset, struct fuse_file_info *fi)
  33. {
  34. (void) offset;
  35. (void) fi;
  36.  
  37. if(strcmp(path, "/") != 0)
  38. return -ENOENT;
  39.  
  40. filler(buf, ".", NULL, 0);
  41. filler(buf, "..", NULL, 0);
  42. filler(buf, hello_path 1, NULL, 0);
  43.  
  44. return 0;
  45. }
  46.  
  47. static int hello_open(const char *path, struct fuse_file_info *fi)
  48. {
  49. if(strcmp(path, hello_path) != 0)
  50. return -ENOENT;
  51.  
  52. if((fi->flags
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement