| 1 | package btrfsscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.12 bytes/" |
| 5 | "osscip-go gomod github.com/golang/go/src go1.12 os/" |
| 6 | "syscallscip-go gomod github.com/golang/go/src go1.12 syscall/" |
| 7 | ) |
| 8 | |
| 9 | const ( |
| 10 | xattrPrefixscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/xattrPrefix. = "btrfs." |
| 11 | xattrCompressionscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/xattrCompression. = xattrPrefixscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/xattrPrefix. + "compression" |
| 12 | ) |
| 13 | |
| 14 | type Compressionscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/Compression# string |
| 15 | |
| 16 | const ( |
| 17 | CompressionNonescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/CompressionNone. = Compressionscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/Compression#("") |
| 18 | LZOscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/LZO. = Compressionscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/Compression#("lzo") |
| 19 | ZLIBscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/ZLIB. = Compressionscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/Compression#("zlib") |
| 20 | ) |
| 21 | |
| 22 | func SetCompressionscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/SetCompression().(path string, v Compressionscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/Compression#) error { |
| 23 | var value []byte |
| 24 | if v != CompressionNonescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/CompressionNone. { |
| 25 | var err error |
| 26 | value, err = syscallscip-go gomod github.com/golang/go/src go1.12 syscall/.ByteSliceFromStringscip-go gomod github.com/golang/go/src go1.12 syscall/ByteSliceFromString().(string(v)) |
| 27 | if err != nil { |
| 28 | return err |
| 29 | } |
| 30 | } |
| 31 | err := syscallscip-go gomod github.com/golang/go/src go1.12 syscall/.Setxattrscip-go gomod github.com/golang/go/src go1.12 syscall/Setxattr().(path, xattrCompressionscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/xattrCompression., value, 0) |
| 32 | if err != nil { |
| 33 | return &osscip-go gomod github.com/golang/go/src go1.12 os/.PathErrorscip-go gomod github.com/golang/go/src go1.12 os/PathError#{Opscip-go gomod github.com/golang/go/src go1.12 `io/fs`/PathError#Op.: "setxattr", Pathscip-go gomod github.com/golang/go/src go1.12 `io/fs`/PathError#Path.: path, Errscip-go gomod github.com/golang/go/src go1.12 `io/fs`/PathError#Err.: err} |
| 34 | } |
| 35 | return nil |
| 36 | } |
| 37 | |
| 38 | func GetCompressionscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/GetCompression().(path string) (Compressionscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/Compression#, error) { |
| 39 | var buf []byte |
| 40 | for { |
| 41 | sz, err := syscallscip-go gomod github.com/golang/go/src go1.12 syscall/.Getxattrscip-go gomod github.com/golang/go/src go1.12 syscall/Getxattr().(path, xattrCompressionscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/xattrCompression., nil) |
| 42 | if err == syscallscip-go gomod github.com/golang/go/src go1.12 syscall/.ENODATAscip-go gomod github.com/golang/go/src go1.12 syscall/ENODATA. || sz == 0 { |
| 43 | return CompressionNonescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/CompressionNone., nil |
| 44 | } else if err != nil { |
| 45 | return CompressionNonescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/CompressionNone., &osscip-go gomod github.com/golang/go/src go1.12 os/.PathErrorscip-go gomod github.com/golang/go/src go1.12 os/PathError#{Opscip-go gomod github.com/golang/go/src go1.12 `io/fs`/PathError#Op.: "getxattr", Pathscip-go gomod github.com/golang/go/src go1.12 `io/fs`/PathError#Path.: path, Errscip-go gomod github.com/golang/go/src go1.12 `io/fs`/PathError#Err.: err} |
| 46 | } |
| 47 | if cap(buf) < sz { |
| 48 | buf = make([]byte, sz) |
| 49 | } else { |
| 50 | buf = buf[:sz] |
| 51 | } |
| 52 | sz, err = syscallscip-go gomod github.com/golang/go/src go1.12 syscall/.Getxattrscip-go gomod github.com/golang/go/src go1.12 syscall/Getxattr().(path, xattrCompressionscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/xattrCompression., buf) |
| 53 | if err == syscallscip-go gomod github.com/golang/go/src go1.12 syscall/.ENODATAscip-go gomod github.com/golang/go/src go1.12 syscall/ENODATA. { |
| 54 | return CompressionNonescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/CompressionNone., nil |
| 55 | } else if err == syscallscip-go gomod github.com/golang/go/src go1.12 syscall/.ERANGEscip-go gomod github.com/golang/go/src go1.12 syscall/ERANGE. { |
| 56 | // xattr changed by someone else, and is larger than our current buffer |
| 57 | continue |
| 58 | } else if err != nil { |
| 59 | return CompressionNonescip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/CompressionNone., &osscip-go gomod github.com/golang/go/src go1.12 os/.PathErrorscip-go gomod github.com/golang/go/src go1.12 os/PathError#{Opscip-go gomod github.com/golang/go/src go1.12 `io/fs`/PathError#Op.: "getxattr", Pathscip-go gomod github.com/golang/go/src go1.12 `io/fs`/PathError#Path.: path, Errscip-go gomod github.com/golang/go/src go1.12 `io/fs`/PathError#Err.: err} |
| 60 | } |
| 61 | buf = buf[:sz] |
| 62 | break |
| 63 | } |
| 64 | buf = bytesscip-go gomod github.com/golang/go/src go1.12 bytes/.TrimSuffixscip-go gomod github.com/golang/go/src go1.12 bytes/TrimSuffix().(buf, []byte{0}) |
| 65 | return Compressionscip-go gomod github.com/dennwc/btrfs . `github.com/dennwc/btrfs`/Compression#(buf), nil |
| 66 | } |