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.

72 lines
1.7 KiB

9 months ago
9 months ago
  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. #include "config.hpp"
  15. #include "errno.hpp"
  16. #include "fileinfo.hpp"
  17. #include "fs_close.hpp"
  18. #include "fs_fadvise.hpp"
  19. #include "ugid.hpp"
  20. #include "fuse.h"
  21. #include <string>
  22. namespace l
  23. {
  24. static
  25. int
  26. release(FileInfo *fi_,
  27. const bool dropcacheonclose_)
  28. {
  29. // according to Feh of nocache calling it once doesn't always work
  30. // https://github.com/Feh/nocache
  31. if(dropcacheonclose_)
  32. {
  33. fs::fadvise_dontneed(fi_->fd);
  34. fs::fadvise_dontneed(fi_->fd);
  35. }
  36. if(fi_->backing_id)
  37. {
  38. const fuse_context *fc;
  39. const ugid::SetRootGuard ugid;
  40. fc = fuse_get_context();
  41. fuse_passthrough_close(fc,fi_->backing_id);
  42. }
  43. fs::close(fi_->fd);
  44. delete fi_;
  45. return 0;
  46. }
  47. }
  48. namespace FUSE
  49. {
  50. int
  51. release(const fuse_file_info_t *ffi_)
  52. {
  53. Config::Read cfg;
  54. FileInfo *fi = reinterpret_cast<FileInfo*>(ffi_->fh);
  55. return l::release(fi,cfg->dropcacheonclose);
  56. }
  57. }