mirror of
https://github.com/dennwc/btrfs
synced 2025-01-09 08:39:23 +00:00
SetFlags and SetCompression
This commit is contained in:
parent
43632657e8
commit
41809caf7d
30
btrfs.go
30
btrfs.go
@ -11,6 +11,8 @@ import (
|
||||
|
||||
const SuperMagic = 0x9123683E
|
||||
|
||||
const xattrPrefix = "btrfs."
|
||||
|
||||
func Open(path string, ro bool) (*FS, error) {
|
||||
if ok, err := IsSubVolume(path); err != nil {
|
||||
return nil, err
|
||||
@ -152,6 +154,10 @@ func (f *FS) GetFlags() (SubvolFlags, error) {
|
||||
return iocSubvolGetflags(f.f)
|
||||
}
|
||||
|
||||
func (f *FS) SetFlags(flags SubvolFlags) error {
|
||||
return iocSubvolSetflags(f.f, flags)
|
||||
}
|
||||
|
||||
func (f *FS) Sync() (err error) {
|
||||
if err = ioctl.Do(f.f, _BTRFS_IOC_START_SYNC, nil); err != nil {
|
||||
return
|
||||
@ -194,3 +200,27 @@ func (f *FS) Receive(r io.Reader) error {
|
||||
func (f *FS) ReceiveTo(r io.Reader, mount string) error {
|
||||
return Receive(r, filepath.Join(f.f.Name(), mount))
|
||||
}
|
||||
|
||||
type Compression string
|
||||
|
||||
const (
|
||||
CompressionNone = Compression("")
|
||||
LZO = Compression("lzo")
|
||||
ZLIB = Compression("zlib")
|
||||
)
|
||||
|
||||
func SetCompression(path string, v Compression) error {
|
||||
var value []byte
|
||||
if v != CompressionNone {
|
||||
var err error
|
||||
value, err = syscall.ByteSliceFromString(string(v))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err := syscall.Setxattr(path, xattrPrefix+"compression", value, 0)
|
||||
if err != nil {
|
||||
return &os.PathError{Op: "setxattr", Path: path, Err: err}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -695,8 +695,9 @@ func iocSubvolGetflags(f *os.File) (out SubvolFlags, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func iocSubvolSetflags(f *os.File, out *uint64) error {
|
||||
return ioctl.Do(f, _BTRFS_IOC_SUBVOL_SETFLAGS, out)
|
||||
func iocSubvolSetflags(f *os.File, flags SubvolFlags) error {
|
||||
v := uint64(flags)
|
||||
return ioctl.Do(f, _BTRFS_IOC_SUBVOL_SETFLAGS, &v)
|
||||
}
|
||||
|
||||
func iocScrub(f *os.File, out *btrfs_ioctl_scrub_args) error {
|
||||
|
Loading…
Reference in New Issue
Block a user