weedfs_file_io.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. fileHandle, code := wfs.AcquireHandle(in.NodeId, in.Uid, in.Gid)
  63. if code == fuse.OK {
  64. out.Fh = uint64(fileHandle.fh)
  65. // TODO https://github.com/libfuse/libfuse/blob/master/include/fuse_common.h#L64
  66. }
  67. return code
  68. }
  69. /**
  70. * Release an open file
  71. *
  72. * Release is called when there are no more references to an open
  73. * file: all file descriptors are closed and all memory mappings
  74. * are unmapped.
  75. *
  76. * For every open call there will be exactly one release call (unless
  77. * the filesystem is force-unmounted).
  78. *
  79. * The filesystem may reply with an error, but error values are
  80. * not returned to close() or munmap() which triggered the
  81. * release.
  82. *
  83. * fi->fh will contain the value set by the open method, or will
  84. * be undefined if the open method didn't set any value.
  85. * fi->flags will contain the same flags as for open.
  86. *
  87. * Valid replies:
  88. * fuse_reply_err
  89. *
  90. * @param req request handle
  91. * @param ino the inode number
  92. * @param fi file information
  93. */
  94. func (wfs *WFS) Release(cancel <-chan struct{}, in *fuse.ReleaseIn) {
  95. wfs.ReleaseHandle(FileHandleId(in.Fh))
  96. }