github.com/x-oss-byte/git-lfs@v2.5.2+incompatible/tools/util_linux.go (about) 1 // +build linux,cgo 2 3 package tools 4 5 /* 6 #include <sys/ioctl.h> 7 8 #undef BTRFS_IOCTL_MAGIC 9 #define BTRFS_IOCTL_MAGIC 0x94 10 #undef BTRFS_IOC_CLONE 11 #define BTRFS_IOC_CLONE _IOW (BTRFS_IOCTL_MAGIC, 9, int) 12 */ 13 import "C" 14 15 import ( 16 "io" 17 "os" 18 "syscall" 19 ) 20 21 const ( 22 BtrfsIocClone = C.BTRFS_IOC_CLONE 23 ) 24 25 func CloneFile(writer io.Writer, reader io.Reader) (bool, error) { 26 fdst, fdstFound := writer.(*os.File) 27 fsrc, fsrcFound := reader.(*os.File) 28 if fdstFound && fsrcFound { 29 if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fdst.Fd(), BtrfsIocClone, fsrc.Fd()); err != 0 { 30 return false, err 31 } 32 return true, nil 33 } 34 return false, nil 35 }