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.

70 lines
2.1 KiB

  1. /*
  2. Copyright (c) 2019, 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. #include "errno.hpp"
  15. #include "fileinfo.hpp"
  16. #include "fs_copy_file_range.hpp"
  17. #include "fuse.h"
  18. #include <stdio.h>
  19. namespace l
  20. {
  21. static
  22. ssize_t
  23. copy_file_range(const int fd_in_,
  24. off_t offset_in_,
  25. const int fd_out_,
  26. off_t offset_out_,
  27. size_t size_,
  28. int flags_)
  29. {
  30. ssize_t rv;
  31. rv = fs::copy_file_range(fd_in_,
  32. &offset_in_,
  33. fd_out_,
  34. &offset_out_,
  35. size_,
  36. flags_);
  37. return ((rv == -1) ? -errno : rv);
  38. }
  39. }
  40. namespace FUSE
  41. {
  42. ssize_t
  43. copy_file_range(const fuse_file_info_t *ffi_in_,
  44. off_t offset_in_,
  45. const fuse_file_info_t *ffi_out_,
  46. off_t offset_out_,
  47. size_t size_,
  48. int flags_)
  49. {
  50. FileInfo *fi_in = reinterpret_cast<FileInfo*>(ffi_in_->fh);
  51. FileInfo *fi_out = reinterpret_cast<FileInfo*>(ffi_out_->fh);
  52. return l::copy_file_range(fi_in->fd,
  53. offset_in_,
  54. fi_out->fd,
  55. offset_out_,
  56. size_,
  57. flags_);
  58. }
  59. }