protocol.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package fuse
  2. import (
  3. "fmt"
  4. )
  5. // Protocol is a FUSE protocol version number.
  6. type Protocol struct {
  7. Major uint32
  8. Minor uint32
  9. }
  10. func (p Protocol) String() string {
  11. return fmt.Sprintf("%d.%d", p.Major, p.Minor)
  12. }
  13. // LT returns whether a is less than b.
  14. func (a Protocol) LT(b Protocol) bool {
  15. return a.Major < b.Major ||
  16. (a.Major == b.Major && a.Minor < b.Minor)
  17. }
  18. // GE returns whether a is greater than or equal to b.
  19. func (a Protocol) GE(b Protocol) bool {
  20. return a.Major > b.Major ||
  21. (a.Major == b.Major && a.Minor >= b.Minor)
  22. }
  23. func (a Protocol) is79() bool {
  24. return a.GE(Protocol{7, 9})
  25. }
  26. // HasAttrBlockSize returns whether Attr.BlockSize is respected by the
  27. // kernel.
  28. func (a Protocol) HasAttrBlockSize() bool {
  29. return a.is79()
  30. }
  31. // HasReadWriteFlags returns whether ReadRequest/WriteRequest
  32. // fields Flags and FileFlags are valid.
  33. func (a Protocol) HasReadWriteFlags() bool {
  34. return a.is79()
  35. }
  36. // HasGetattrFlags returns whether GetattrRequest field Flags is
  37. // valid.
  38. func (a Protocol) HasGetattrFlags() bool {
  39. return a.is79()
  40. }
  41. func (a Protocol) is710() bool {
  42. return a.GE(Protocol{7, 10})
  43. }
  44. // HasOpenNonSeekable returns whether OpenResponse field Flags flag
  45. // OpenNonSeekable is supported.
  46. func (a Protocol) HasOpenNonSeekable() bool {
  47. return a.is710()
  48. }
  49. func (a Protocol) is712() bool {
  50. return a.GE(Protocol{7, 12})
  51. }
  52. // HasUmask returns whether CreateRequest/MkdirRequest/MknodRequest
  53. // field Umask is valid.
  54. func (a Protocol) HasUmask() bool {
  55. return a.is712()
  56. }
  57. // HasInvalidate returns whether InvalidateNode/InvalidateEntry are
  58. // supported.
  59. func (a Protocol) HasInvalidate() bool {
  60. return a.is712()
  61. }