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.

61 lines
1.5 KiB

  1. /*
  2. Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. #if FALLOCATE
  15. #include <fuse.h>
  16. #include "errno.hpp"
  17. #include "fileinfo.hpp"
  18. #include "fs_fallocate.hpp"
  19. static
  20. int
  21. _fallocate(const int fd,
  22. const int mode,
  23. const off_t offset,
  24. const off_t len)
  25. {
  26. int rv;
  27. rv = fs::fallocate(fd,mode,offset,len);
  28. return ((rv == -1) ? -errno : 0);
  29. }
  30. namespace mergerfs
  31. {
  32. namespace fuse
  33. {
  34. int
  35. fallocate(const char *fusepath,
  36. int mode,
  37. off_t offset,
  38. off_t len,
  39. fuse_file_info *ffi)
  40. {
  41. FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
  42. return _fallocate(fi->fd,
  43. mode,
  44. offset,
  45. len);
  46. }
  47. }
  48. }
  49. #endif