copyrangemethod.go 1.3 KB

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