copyrangemethod.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright (C) 2020 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package config
  7. import "github.com/syncthing/syncthing/lib/fs"
  8. type CopyRangeMethod int32
  9. const (
  10. CopyRangeMethodStandard CopyRangeMethod = 0
  11. CopyRangeMethodIoctl CopyRangeMethod = 1
  12. CopyRangeMethodCopyFileRange CopyRangeMethod = 2
  13. CopyRangeMethodSendFile CopyRangeMethod = 3
  14. CopyRangeMethodDuplicateExtents CopyRangeMethod = 4
  15. CopyRangeMethodAllWithFallback CopyRangeMethod = 5
  16. )
  17. func (o CopyRangeMethod) String() string {
  18. switch o {
  19. case CopyRangeMethodStandard:
  20. return "standard"
  21. case CopyRangeMethodIoctl:
  22. return "ioctl"
  23. case CopyRangeMethodCopyFileRange:
  24. return "copy_file_range"
  25. case CopyRangeMethodSendFile:
  26. return "sendfile"
  27. case CopyRangeMethodDuplicateExtents:
  28. return "duplicate_extents"
  29. case CopyRangeMethodAllWithFallback:
  30. return "all"
  31. default:
  32. return "unknown"
  33. }
  34. }
  35. func (o CopyRangeMethod) ToFS() fs.CopyRangeMethod {
  36. switch o {
  37. case CopyRangeMethodStandard:
  38. return fs.CopyRangeMethodStandard
  39. case CopyRangeMethodIoctl:
  40. return fs.CopyRangeMethodIoctl
  41. case CopyRangeMethodCopyFileRange:
  42. return fs.CopyRangeMethodCopyFileRange
  43. case CopyRangeMethodSendFile:
  44. return fs.CopyRangeMethodSendFile
  45. case CopyRangeMethodDuplicateExtents:
  46. return fs.CopyRangeMethodDuplicateExtents
  47. case CopyRangeMethodAllWithFallback:
  48. return fs.CopyRangeMethodAllWithFallback
  49. default:
  50. return fs.CopyRangeMethodStandard
  51. }
  52. }
  53. func (o CopyRangeMethod) MarshalText() ([]byte, error) {
  54. return []byte(o.String()), nil
  55. }
  56. func (o *CopyRangeMethod) UnmarshalText(bs []byte) error {
  57. switch string(bs) {
  58. case "standard":
  59. *o = CopyRangeMethodStandard
  60. case "ioctl":
  61. *o = CopyRangeMethodIoctl
  62. case "copy_file_range":
  63. *o = CopyRangeMethodCopyFileRange
  64. case "sendfile":
  65. *o = CopyRangeMethodSendFile
  66. case "duplicate_extents":
  67. *o = CopyRangeMethodDuplicateExtents
  68. case "all":
  69. *o = CopyRangeMethodAllWithFallback
  70. default:
  71. *o = CopyRangeMethodStandard
  72. }
  73. return nil
  74. }
  75. func (o *CopyRangeMethod) ParseDefault(str string) error {
  76. return o.UnmarshalText([]byte(str))
  77. }