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.

101 lines
3.4 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. package mount
  2. import (
  3. "github.com/hanwen/go-fuse/v2/fuse"
  4. )
  5. /**
  6. * Open a file
  7. *
  8. * Open flags are available in fi->flags. The following rules
  9. * apply.
  10. *
  11. * - Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be
  12. * filtered out / handled by the kernel.
  13. *
  14. * - Access modes (O_RDONLY, O_WRONLY, O_RDWR) should be used
  15. * by the filesystem to check if the operation is
  16. * permitted. If the ``-o default_permissions`` mount
  17. * option is given, this check is already done by the
  18. * kernel before calling open() and may thus be omitted by
  19. * the filesystem.
  20. *
  21. * - When writeback caching is enabled, the kernel may send
  22. * read requests even for files opened with O_WRONLY. The
  23. * filesystem should be prepared to handle this.
  24. *
  25. * - When writeback caching is disabled, the filesystem is
  26. * expected to properly handle the O_APPEND flag and ensure
  27. * that each write is appending to the end of the file.
  28. *
  29. * - When writeback caching is enabled, the kernel will
  30. * handle O_APPEND. However, unless all changes to the file
  31. * come through the kernel this will not work reliably. The
  32. * filesystem should thus either ignore the O_APPEND flag
  33. * (and let the kernel handle it), or return an error
  34. * (indicating that reliably O_APPEND is not available).
  35. *
  36. * Filesystem may store an arbitrary file handle (pointer,
  37. * index, etc) in fi->fh, and use this in other all other file
  38. * operations (read, write, flush, release, fsync).
  39. *
  40. * Filesystem may also implement stateless file I/O and not store
  41. * anything in fi->fh.
  42. *
  43. * There are also some flags (direct_io, keep_cache) which the
  44. * filesystem may set in fi, to change the way the file is opened.
  45. * See fuse_file_info structure in <fuse_common.h> for more details.
  46. *
  47. * If this request is answered with an error code of ENOSYS
  48. * and FUSE_CAP_NO_OPEN_SUPPORT is set in
  49. * `fuse_conn_info.capable`, this is treated as success and
  50. * future calls to open and release will also succeed without being
  51. * sent to the filesystem process.
  52. *
  53. * Valid replies:
  54. * fuse_reply_open
  55. * fuse_reply_err
  56. *
  57. * @param req request handle
  58. * @param ino the inode number
  59. * @param fi file information
  60. */
  61. func (wfs *WFS) Open(cancel <-chan struct{}, in *fuse.OpenIn, out *fuse.OpenOut) (status fuse.Status) {
  62. var fileHandle *FileHandle
  63. fileHandle, status = wfs.AcquireHandle(in.NodeId, in.Flags, in.Uid, in.Gid)
  64. if status == fuse.OK {
  65. out.Fh = uint64(fileHandle.fh)
  66. out.OpenFlags = in.Flags
  67. // TODO https://github.com/libfuse/libfuse/blob/master/include/fuse_common.h#L64
  68. }
  69. return status
  70. }
  71. /**
  72. * Release an open file
  73. *
  74. * Release is called when there are no more references to an open
  75. * file: all file descriptors are closed and all memory mappings
  76. * are unmapped.
  77. *
  78. * For every open call there will be exactly one release call (unless
  79. * the filesystem is force-unmounted).
  80. *
  81. * The filesystem may reply with an error, but error values are
  82. * not returned to close() or munmap() which triggered the
  83. * release.
  84. *
  85. * fi->fh will contain the value set by the open method, or will
  86. * be undefined if the open method didn't set any value.
  87. * fi->flags will contain the same flags as for open.
  88. *
  89. * Valid replies:
  90. * fuse_reply_err
  91. *
  92. * @param req request handle
  93. * @param ino the inode number
  94. * @param fi file information
  95. */
  96. func (wfs *WFS) Release(cancel <-chan struct{}, in *fuse.ReleaseIn) {
  97. wfs.ReleaseHandle(FileHandleId(in.Fh))
  98. }