filesystem_copy_range_method.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 fs
  7. type CopyRangeMethod int
  8. const (
  9. CopyRangeMethodStandard CopyRangeMethod = iota
  10. CopyRangeMethodIoctl
  11. CopyRangeMethodCopyFileRange
  12. CopyRangeMethodSendFile
  13. CopyRangeMethodDuplicateExtents
  14. CopyRangeMethodAllWithFallback
  15. )
  16. func (o CopyRangeMethod) String() string {
  17. switch o {
  18. case CopyRangeMethodStandard:
  19. return "standard"
  20. case CopyRangeMethodIoctl:
  21. return "ioctl"
  22. case CopyRangeMethodCopyFileRange:
  23. return "copy_file_range"
  24. case CopyRangeMethodSendFile:
  25. return "sendfile"
  26. case CopyRangeMethodDuplicateExtents:
  27. return "duplicate_extents"
  28. case CopyRangeMethodAllWithFallback:
  29. return "all"
  30. default:
  31. return "unknown"
  32. }
  33. }
  34. func (o CopyRangeMethod) MarshalText() ([]byte, error) {
  35. return []byte(o.String()), nil
  36. }
  37. func (o *CopyRangeMethod) UnmarshalText(bs []byte) error {
  38. switch string(bs) {
  39. case "standard":
  40. *o = CopyRangeMethodStandard
  41. case "ioctl":
  42. *o = CopyRangeMethodIoctl
  43. case "copy_file_range":
  44. *o = CopyRangeMethodCopyFileRange
  45. case "sendfile":
  46. *o = CopyRangeMethodSendFile
  47. case "duplicate_extents":
  48. *o = CopyRangeMethodDuplicateExtents
  49. case "all":
  50. *o = CopyRangeMethodAllWithFallback
  51. default:
  52. *o = CopyRangeMethodStandard
  53. }
  54. return nil
  55. }
  56. func (o *CopyRangeMethod) ParseDefault(str string) error {
  57. return o.UnmarshalText([]byte(str))
  58. }