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.

46 lines
943 B

  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 LGPLv2.
  5. See the file COPYING.LIB
  6. */
  7. #include "fuse_lowlevel.h"
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <errno.h>
  11. int fuse_session_loop(struct fuse_session *se)
  12. {
  13. int res = 0;
  14. struct fuse_chan *ch = fuse_session_next_chan(se, NULL);
  15. size_t bufsize = fuse_chan_bufsize(ch);
  16. char *buf = (char*)calloc(bufsize,1);
  17. if (!buf) {
  18. fprintf(stderr, "fuse: failed to allocate read buffer\n");
  19. return -1;
  20. }
  21. while (!fuse_session_exited(se)) {
  22. struct fuse_chan *tmpch = ch;
  23. struct fuse_buf fbuf = {
  24. .mem = buf,
  25. .size = bufsize,
  26. };
  27. res = fuse_session_receive_buf(se, &fbuf, &tmpch);
  28. if (res == -EINTR)
  29. continue;
  30. if (res <= 0)
  31. break;
  32. fuse_session_process_buf(se, &fbuf, tmpch);
  33. }
  34. free(buf);
  35. fuse_session_reset(se);
  36. return res < 0 ? -1 : 0;
  37. }