You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

file_handle.go 2.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //go:build linux || (darwin && amd64)
  2. package fuse
  3. import (
  4. "context"
  5. "io"
  6. "syscall"
  7. fusefs "github.com/hanwen/go-fuse/v2/fs"
  8. "github.com/hanwen/go-fuse/v2/fuse"
  9. )
  10. // 作为本模块的FileHandle与fusefs.FileHandle的桥梁,用于实现fusefs.FileHandle接口
  11. type fileHandle struct {
  12. hd FileHandle
  13. }
  14. func newFileHandle(hd FileHandle) *fileHandle {
  15. return &fileHandle{
  16. hd: hd,
  17. }
  18. }
  19. // Read data from a file. The data should be returned as
  20. // ReadResult, which may be constructed from the incoming
  21. // `dest` buffer.
  22. func (f *fileHandle) Read(ctx context.Context, dest []byte, off int64) (res fuse.ReadResult, errno syscall.Errno) {
  23. var n int
  24. var err error
  25. n, err = f.hd.ReadAt(dest, off)
  26. if err == io.EOF {
  27. err = nil
  28. }
  29. return fuse.ReadResultData(dest[:n]), translateError(err)
  30. }
  31. var _ fusefs.FileReader = (*fileHandle)(nil)
  32. // Write the data into the file handle at given offset. After
  33. // returning, the data will be reused and may not referenced.
  34. func (f *fileHandle) Write(ctx context.Context, data []byte, off int64) (written uint32, errno syscall.Errno) {
  35. var n int
  36. var err error
  37. n, err = f.hd.WriteAt(data, off)
  38. return uint32(n), translateError(err)
  39. }
  40. var _ fusefs.FileWriter = (*fileHandle)(nil)
  41. // Flush is called for the close(2) call on a file descriptor. In case
  42. // of a descriptor that was duplicated using dup(2), it may be called
  43. // more than once for the same fileHandle.
  44. func (f *fileHandle) Flush(ctx context.Context) syscall.Errno {
  45. return translateError(f.hd.Close())
  46. }
  47. var _ fusefs.FileFlusher = (*fileHandle)(nil)
  48. // Release is called to before a fileHandle is forgotten. The
  49. // kernel ignores the return value of this method,
  50. // so any cleanup that requires specific synchronization or
  51. // could fail with I/O errors should happen in Flush instead.
  52. func (f *fileHandle) Release(ctx context.Context) syscall.Errno {
  53. return translateError(f.hd.Release())
  54. }
  55. var _ fusefs.FileReleaser = (*fileHandle)(nil)
  56. // Fsync is a signal to ensure writes to the Inode are flushed
  57. // to stable storage.
  58. func (f *fileHandle) Fsync(ctx context.Context, flags uint32) (errno syscall.Errno) {
  59. return translateError(f.hd.Sync())
  60. }
  61. var _ fusefs.FileFsyncer = (*fileHandle)(nil)

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。