mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 23:27:31 -04:00
unix: add IoctlFile{Clone,CloneRange,DedupeRange} on linux
Add wrappers for the FICLONE, FICLONERANGE and FIDEDUPERANGE ioctl operations on linux. See the ioctl_ficlone(2), ioctl_ficlonerange(2) and ioctl_fideduperange(2) man pages for details. Change-Id: If3bad98facc362d4f7524e8d7a128815e9e2f204 Reviewed-on: https://go-review.googlesource.com/c/sys/+/256000 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
e10f822d58
commit
aee5d888a8
@@ -465,6 +465,10 @@ type Fsid C.fsid_t
|
|||||||
|
|
||||||
type Flock_t C.struct_flock
|
type Flock_t C.struct_flock
|
||||||
|
|
||||||
|
type FileCloneRange C.struct_file_clone_range
|
||||||
|
|
||||||
|
type FileDedupeRange C.struct_file_dedupe_range
|
||||||
|
|
||||||
// Filesystem Encryption
|
// Filesystem Encryption
|
||||||
|
|
||||||
type FscryptPolicy C.struct_fscrypt_policy
|
type FscryptPolicy C.struct_fscrypt_policy
|
||||||
|
|||||||
@@ -517,6 +517,7 @@ ccflags="$@"
|
|||||||
$2 ~ /^CP_/ ||
|
$2 ~ /^CP_/ ||
|
||||||
$2 ~ /^CPUSTATES$/ ||
|
$2 ~ /^CPUSTATES$/ ||
|
||||||
$2 ~ /^ALG_/ ||
|
$2 ~ /^ALG_/ ||
|
||||||
|
$2 ~ /^FI(CLONE|DEDUPERANGE)/ ||
|
||||||
$2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE)/ ||
|
$2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE)/ ||
|
||||||
$2 ~ /^FS_IOC_.*(ENCRYPTION|VERITY|[GS]ETFLAGS)/ ||
|
$2 ~ /^FS_IOC_.*(ENCRYPTION|VERITY|[GS]ETFLAGS)/ ||
|
||||||
$2 ~ /^FS_VERITY_/ ||
|
$2 ~ /^FS_VERITY_/ ||
|
||||||
|
|||||||
@@ -112,6 +112,31 @@ func IoctlGetRTCWkAlrm(fd int) (*RTCWkAlrm, error) {
|
|||||||
return &value, err
|
return &value, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IoctlFileClone performs an FICLONERANGE ioctl operation to clone the range of
|
||||||
|
// data conveyed in value to the file associated with the file descriptor
|
||||||
|
// destFd. See the ioctl_ficlonerange(2) man page for details.
|
||||||
|
func IoctlFileCloneRange(destFd int, value *FileCloneRange) error {
|
||||||
|
err := ioctl(destFd, FICLONERANGE, uintptr(unsafe.Pointer(value)))
|
||||||
|
runtime.KeepAlive(value)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IoctlFileClone performs an FICLONE ioctl operation to clone the entire file
|
||||||
|
// associated with the file description srcFd to the file associated with the
|
||||||
|
// file descriptor destFd. See the ioctl_ficlone(2) man page for details.
|
||||||
|
func IoctlFileClone(destFd, srcFd int) error {
|
||||||
|
return ioctl(destFd, FICLONE, uintptr(srcFd))
|
||||||
|
}
|
||||||
|
|
||||||
|
// IoctlFileClone performs an FIDEDUPERANGE ioctl operation to share the range of
|
||||||
|
// data conveyed in value with the file associated with the file descriptor
|
||||||
|
// destFd. See the ioctl_fideduperange(2) man page for details.
|
||||||
|
func IoctlFileDedupeRange(destFd int, value *FileDedupeRange) error {
|
||||||
|
err := ioctl(destFd, FIDEDUPERANGE, uintptr(unsafe.Pointer(value)))
|
||||||
|
runtime.KeepAlive(value)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
//sys Linkat(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error)
|
//sys Linkat(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error)
|
||||||
|
|
||||||
func Link(oldpath string, newpath string) (err error) {
|
func Link(oldpath string, newpath string) (err error) {
|
||||||
|
|||||||
@@ -686,6 +686,7 @@ const (
|
|||||||
FD_CLOEXEC = 0x1
|
FD_CLOEXEC = 0x1
|
||||||
FD_SETSIZE = 0x400
|
FD_SETSIZE = 0x400
|
||||||
FF0 = 0x0
|
FF0 = 0x0
|
||||||
|
FIDEDUPERANGE = 0xc0189436
|
||||||
FSCRYPT_KEY_DESCRIPTOR_SIZE = 0x8
|
FSCRYPT_KEY_DESCRIPTOR_SIZE = 0x8
|
||||||
FSCRYPT_KEY_DESC_PREFIX = "fscrypt:"
|
FSCRYPT_KEY_DESC_PREFIX = "fscrypt:"
|
||||||
FSCRYPT_KEY_DESC_PREFIX_SIZE = 0x8
|
FSCRYPT_KEY_DESC_PREFIX_SIZE = 0x8
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ const (
|
|||||||
EXTPROC = 0x10000
|
EXTPROC = 0x10000
|
||||||
FF1 = 0x8000
|
FF1 = 0x8000
|
||||||
FFDLY = 0x8000
|
FFDLY = 0x8000
|
||||||
|
FICLONE = 0x40049409
|
||||||
|
FICLONERANGE = 0x4020940d
|
||||||
FLUSHO = 0x1000
|
FLUSHO = 0x1000
|
||||||
FP_XSTATE_MAGIC2 = 0x46505845
|
FP_XSTATE_MAGIC2 = 0x46505845
|
||||||
FS_IOC_ENABLE_VERITY = 0x40806685
|
FS_IOC_ENABLE_VERITY = 0x40806685
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ const (
|
|||||||
EXTPROC = 0x10000
|
EXTPROC = 0x10000
|
||||||
FF1 = 0x8000
|
FF1 = 0x8000
|
||||||
FFDLY = 0x8000
|
FFDLY = 0x8000
|
||||||
|
FICLONE = 0x40049409
|
||||||
|
FICLONERANGE = 0x4020940d
|
||||||
FLUSHO = 0x1000
|
FLUSHO = 0x1000
|
||||||
FP_XSTATE_MAGIC2 = 0x46505845
|
FP_XSTATE_MAGIC2 = 0x46505845
|
||||||
FS_IOC_ENABLE_VERITY = 0x40806685
|
FS_IOC_ENABLE_VERITY = 0x40806685
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ const (
|
|||||||
EXTPROC = 0x10000
|
EXTPROC = 0x10000
|
||||||
FF1 = 0x8000
|
FF1 = 0x8000
|
||||||
FFDLY = 0x8000
|
FFDLY = 0x8000
|
||||||
|
FICLONE = 0x40049409
|
||||||
|
FICLONERANGE = 0x4020940d
|
||||||
FLUSHO = 0x1000
|
FLUSHO = 0x1000
|
||||||
FS_IOC_ENABLE_VERITY = 0x40806685
|
FS_IOC_ENABLE_VERITY = 0x40806685
|
||||||
FS_IOC_GETFLAGS = 0x80046601
|
FS_IOC_GETFLAGS = 0x80046601
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ const (
|
|||||||
EXTRA_MAGIC = 0x45585401
|
EXTRA_MAGIC = 0x45585401
|
||||||
FF1 = 0x8000
|
FF1 = 0x8000
|
||||||
FFDLY = 0x8000
|
FFDLY = 0x8000
|
||||||
|
FICLONE = 0x40049409
|
||||||
|
FICLONERANGE = 0x4020940d
|
||||||
FLUSHO = 0x1000
|
FLUSHO = 0x1000
|
||||||
FPSIMD_MAGIC = 0x46508001
|
FPSIMD_MAGIC = 0x46508001
|
||||||
FS_IOC_ENABLE_VERITY = 0x40806685
|
FS_IOC_ENABLE_VERITY = 0x40806685
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ const (
|
|||||||
EXTPROC = 0x10000
|
EXTPROC = 0x10000
|
||||||
FF1 = 0x8000
|
FF1 = 0x8000
|
||||||
FFDLY = 0x8000
|
FFDLY = 0x8000
|
||||||
|
FICLONE = 0x80049409
|
||||||
|
FICLONERANGE = 0x8020940d
|
||||||
FLUSHO = 0x2000
|
FLUSHO = 0x2000
|
||||||
FS_IOC_ENABLE_VERITY = 0x80806685
|
FS_IOC_ENABLE_VERITY = 0x80806685
|
||||||
FS_IOC_GETFLAGS = 0x40046601
|
FS_IOC_GETFLAGS = 0x40046601
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ const (
|
|||||||
EXTPROC = 0x10000
|
EXTPROC = 0x10000
|
||||||
FF1 = 0x8000
|
FF1 = 0x8000
|
||||||
FFDLY = 0x8000
|
FFDLY = 0x8000
|
||||||
|
FICLONE = 0x80049409
|
||||||
|
FICLONERANGE = 0x8020940d
|
||||||
FLUSHO = 0x2000
|
FLUSHO = 0x2000
|
||||||
FS_IOC_ENABLE_VERITY = 0x80806685
|
FS_IOC_ENABLE_VERITY = 0x80806685
|
||||||
FS_IOC_GETFLAGS = 0x40086601
|
FS_IOC_GETFLAGS = 0x40086601
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ const (
|
|||||||
EXTPROC = 0x10000
|
EXTPROC = 0x10000
|
||||||
FF1 = 0x8000
|
FF1 = 0x8000
|
||||||
FFDLY = 0x8000
|
FFDLY = 0x8000
|
||||||
|
FICLONE = 0x80049409
|
||||||
|
FICLONERANGE = 0x8020940d
|
||||||
FLUSHO = 0x2000
|
FLUSHO = 0x2000
|
||||||
FS_IOC_ENABLE_VERITY = 0x80806685
|
FS_IOC_ENABLE_VERITY = 0x80806685
|
||||||
FS_IOC_GETFLAGS = 0x40086601
|
FS_IOC_GETFLAGS = 0x40086601
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ const (
|
|||||||
EXTPROC = 0x10000
|
EXTPROC = 0x10000
|
||||||
FF1 = 0x8000
|
FF1 = 0x8000
|
||||||
FFDLY = 0x8000
|
FFDLY = 0x8000
|
||||||
|
FICLONE = 0x80049409
|
||||||
|
FICLONERANGE = 0x8020940d
|
||||||
FLUSHO = 0x2000
|
FLUSHO = 0x2000
|
||||||
FS_IOC_ENABLE_VERITY = 0x80806685
|
FS_IOC_ENABLE_VERITY = 0x80806685
|
||||||
FS_IOC_GETFLAGS = 0x40046601
|
FS_IOC_GETFLAGS = 0x40046601
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ const (
|
|||||||
EXTPROC = 0x10000000
|
EXTPROC = 0x10000000
|
||||||
FF1 = 0x4000
|
FF1 = 0x4000
|
||||||
FFDLY = 0x4000
|
FFDLY = 0x4000
|
||||||
|
FICLONE = 0x80049409
|
||||||
|
FICLONERANGE = 0x8020940d
|
||||||
FLUSHO = 0x800000
|
FLUSHO = 0x800000
|
||||||
FS_IOC_ENABLE_VERITY = 0x80806685
|
FS_IOC_ENABLE_VERITY = 0x80806685
|
||||||
FS_IOC_GETFLAGS = 0x40086601
|
FS_IOC_GETFLAGS = 0x40086601
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ const (
|
|||||||
EXTPROC = 0x10000000
|
EXTPROC = 0x10000000
|
||||||
FF1 = 0x4000
|
FF1 = 0x4000
|
||||||
FFDLY = 0x4000
|
FFDLY = 0x4000
|
||||||
|
FICLONE = 0x80049409
|
||||||
|
FICLONERANGE = 0x8020940d
|
||||||
FLUSHO = 0x800000
|
FLUSHO = 0x800000
|
||||||
FS_IOC_ENABLE_VERITY = 0x80806685
|
FS_IOC_ENABLE_VERITY = 0x80806685
|
||||||
FS_IOC_GETFLAGS = 0x40086601
|
FS_IOC_GETFLAGS = 0x40086601
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ const (
|
|||||||
EXTPROC = 0x10000
|
EXTPROC = 0x10000
|
||||||
FF1 = 0x8000
|
FF1 = 0x8000
|
||||||
FFDLY = 0x8000
|
FFDLY = 0x8000
|
||||||
|
FICLONE = 0x40049409
|
||||||
|
FICLONERANGE = 0x4020940d
|
||||||
FLUSHO = 0x1000
|
FLUSHO = 0x1000
|
||||||
FS_IOC_ENABLE_VERITY = 0x40806685
|
FS_IOC_ENABLE_VERITY = 0x40806685
|
||||||
FS_IOC_GETFLAGS = 0x80086601
|
FS_IOC_GETFLAGS = 0x80086601
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ const (
|
|||||||
EXTPROC = 0x10000
|
EXTPROC = 0x10000
|
||||||
FF1 = 0x8000
|
FF1 = 0x8000
|
||||||
FFDLY = 0x8000
|
FFDLY = 0x8000
|
||||||
|
FICLONE = 0x40049409
|
||||||
|
FICLONERANGE = 0x4020940d
|
||||||
FLUSHO = 0x1000
|
FLUSHO = 0x1000
|
||||||
FS_IOC_ENABLE_VERITY = 0x40806685
|
FS_IOC_ENABLE_VERITY = 0x40806685
|
||||||
FS_IOC_GETFLAGS = 0x80086601
|
FS_IOC_GETFLAGS = 0x80086601
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ const (
|
|||||||
EXTPROC = 0x10000
|
EXTPROC = 0x10000
|
||||||
FF1 = 0x8000
|
FF1 = 0x8000
|
||||||
FFDLY = 0x8000
|
FFDLY = 0x8000
|
||||||
|
FICLONE = 0x80049409
|
||||||
|
FICLONERANGE = 0x8020940d
|
||||||
FLUSHO = 0x1000
|
FLUSHO = 0x1000
|
||||||
FS_IOC_ENABLE_VERITY = 0x80806685
|
FS_IOC_ENABLE_VERITY = 0x80806685
|
||||||
FS_IOC_GETFLAGS = 0x40086601
|
FS_IOC_GETFLAGS = 0x40086601
|
||||||
|
|||||||
@@ -76,6 +76,21 @@ type Fsid struct {
|
|||||||
Val [2]int32
|
Val [2]int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FileCloneRange struct {
|
||||||
|
Src_fd int64
|
||||||
|
Src_offset uint64
|
||||||
|
Src_length uint64
|
||||||
|
Dest_offset uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
type FileDedupeRange struct {
|
||||||
|
Src_offset uint64
|
||||||
|
Src_length uint64
|
||||||
|
Dest_count uint16
|
||||||
|
Reserved1 uint16
|
||||||
|
Reserved2 uint32
|
||||||
|
}
|
||||||
|
|
||||||
type FscryptPolicy struct {
|
type FscryptPolicy struct {
|
||||||
Version uint8
|
Version uint8
|
||||||
Contents_encryption_mode uint8
|
Contents_encryption_mode uint8
|
||||||
|
|||||||
Reference in New Issue
Block a user