add SetAttrMore ioctl

This commit is contained in:
Ben McClelland
2019-06-04 14:18:39 -07:00
parent cfc1aed13a
commit 19775d4511
2 changed files with 68 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ import (
"encoding/binary"
"math"
"os"
"time"
"unsafe"
)
@@ -165,6 +166,37 @@ func FStatMore(f *os.File) (Stat, error) {
return s, nil
}
// SetAttrMore sets special scoutfs attributes
func SetAttrMore(path string, version, size, flags uint64, ctime time.Time) error {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
return FSetAttrMore(f, version, size, flags, ctime)
}
// FSetAttrMore sets special scoutfs attributes for file handle
func FSetAttrMore(f *os.File, version, size, flags uint64, ctime time.Time) error {
var nsec int32
if ctime.UnixNano() == int64(int32(ctime.UnixNano())) {
nsec = int32(ctime.UnixNano())
}
s := setattrMore{
dataVersion: version,
iSize: size,
flags: flags,
ctime: scoutfsTimespec{
sec: ctime.Unix(),
nsec: nsec,
},
}
_, err := scoutfsctl(f.Fd(), IOCSETATTRMORE, uintptr(unsafe.Pointer(&s)))
return err
}
// InoToPath converts an inode number to a path in the filesystem
// An open file within scoutfs is supplied for ioctls
// (usually just the base mount point directory)

View File

@@ -27,6 +27,8 @@ const (
IOCSTATMORE = 0x40307307
// IOCDATAWAITING scoutfs ioctl
IOCDATAWAITING = 0x40227309
// IOCSETATTRMORE scoutfs ioctl
IOCSETATTRMORE = 0x4024730a
// QUERYINODESMETASEQ find inodes by metadata sequence
QUERYINODESMETASEQ = '\u0000'
@@ -301,3 +303,37 @@ type dataWaiting struct {
entries uintptr
count uint16
}
/* pahole for scoutfs_timespec
struct scoutfs_timespec {
__le64 sec; // 0 8
__le32 nsec; // 8 4
// size: 12, cachelines: 1, members: 2
// last cacheline: 12 bytes
};
*/
type scoutfsTimespec struct {
sec int64
nsec int32
}
/* pahole for scoutfs_ioctl_setattr_more
struct scoutfs_ioctl_setattr_more {
__u64 data_version; // 0 8
__u64 i_size; // 8 8
__u64 flags; // 16 8
struct scoutfs_timespec ctime; // 24 12
// size: 36, cachelines: 1, members: 4
// last cacheline: 36 bytes
};
*/
type setattrMore struct {
dataVersion uint64
iSize uint64
flags uint64
ctime scoutfsTimespec
}