Guest User

Untitled

a guest
Jan 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. // g++ -Wall main.cpp `pkg-config fuse --cflags --libs` -o hello
  2.  
  3. #define FUSE_USE_VERSION 26
  4.  
  5. #include <fuse.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <errno.h>
  9. #include <fcntl.h>
  10. #include <unistd.h>
  11. #include <stdio.h>
  12.  
  13. static char *path;
  14. static int savefd;
  15.  
  16. static int getattr(const char *path, struct stat *stbuf)
  17. {
  18. int res;
  19. char rPath[1024];
  20.  
  21. strcpy(rPath, "."); strcat(rPath, path);
  22.  
  23. res = lstat(rPath, stbuf); // Mac stuck here
  24. return (res == -1 ? -errno : 0);
  25. }
  26.  
  27. static void* loggedFS_init(struct fuse_conn_info* info)
  28. {
  29. fchdir(savefd); close(savefd); return NULL;
  30. }
  31.  
  32. int main(int argc, char *argv[])
  33. {
  34. struct fuse_operations oper;
  35.  
  36. bzero(&oper, sizeof(fuse_operations));
  37. oper.init = loggedFS_init;
  38. oper.getattr = getattr;
  39.  
  40. path = strdup(argv[argc - 1]);
  41. printf("chdir to %sn", path);
  42. chdir(path);
  43. savefd = open(".", 0);
  44.  
  45. return fuse_main(argc, argv, &oper, NULL);
  46. }
  47.  
  48. int fstatat(int dirfd, const char *pathname, struct stat *buf,
  49. int flags);
Add Comment
Please, Sign In to add comment