add full file release api

This commit is contained in:
Ben McClelland
2019-01-01 10:29:49 -08:00
parent a723568378
commit 18655fbd12
+18
View File
@@ -9,6 +9,7 @@ package scoutfs
import (
"bytes"
"encoding/binary"
"math"
"os"
"unsafe"
)
@@ -196,3 +197,20 @@ func OpenByID(dirfd *os.File, ino uint64, flags int, name string) (*os.File, err
return os.NewFile(fd, name), nil
}
// ReleaseFile marks file offline and frees associated extents
func ReleaseFile(path string, version uint64) error {
f, err := os.OpenFile(path, os.O_WRONLY, 0)
if err != nil {
return err
}
defer f.Close()
r := IocRelease{
Count: math.MaxUint64,
DataVersion: version,
}
_, err = scoutfsctl(f.Fd(), IOCRELEASE, uintptr(unsafe.Pointer(&r)))
return err
}