mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use loopback types and constants from x/sys/unix to implement pkg/loopback without cgo
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
This commit is contained in:
parent
07b48c9e08
commit
919d08347a
4 changed files with 28 additions and 56 deletions
|
@ -1,4 +1,4 @@
|
||||||
// +build linux,cgo
|
// +build linux
|
||||||
|
|
||||||
package loopback // import "github.com/docker/docker/pkg/loopback"
|
package loopback // import "github.com/docker/docker/pkg/loopback"
|
||||||
|
|
||||||
|
@ -116,10 +116,10 @@ func AttachLoopDevice(sparseName string) (loop *os.File, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the status of the loopback device
|
// Set the status of the loopback device
|
||||||
loopInfo := &loopInfo64{
|
loopInfo := &unix.LoopInfo64{
|
||||||
loFileName: stringToLoopName(loopFile.Name()),
|
File_name: stringToLoopName(loopFile.Name()),
|
||||||
loOffset: 0,
|
Offset: 0,
|
||||||
loFlags: LoFlagsAutoClear,
|
Flags: LoFlagsAutoClear,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioctlLoopSetStatus64(loopFile.Fd(), loopInfo); err != nil {
|
if err := ioctlLoopSetStatus64(loopFile.Fd(), loopInfo); err != nil {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build linux,cgo
|
// +build linux
|
||||||
|
|
||||||
package loopback // import "github.com/docker/docker/pkg/loopback"
|
package loopback // import "github.com/docker/docker/pkg/loopback"
|
||||||
|
|
||||||
|
@ -17,32 +17,32 @@ func ioctlLoopCtlGetFree(fd uintptr) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ioctlLoopSetFd(loopFd, sparseFd uintptr) error {
|
func ioctlLoopSetFd(loopFd, sparseFd uintptr) error {
|
||||||
return unix.IoctlSetInt(int(loopFd), LoopSetFd, int(sparseFd))
|
return unix.IoctlSetInt(int(loopFd), unix.LOOP_SET_FD, int(sparseFd))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ioctlLoopSetStatus64(loopFd uintptr, loopInfo *loopInfo64) error {
|
func ioctlLoopSetStatus64(loopFd uintptr, loopInfo *unix.LoopInfo64) error {
|
||||||
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, LoopSetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
|
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, unix.LOOP_SET_STATUS64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ioctlLoopClrFd(loopFd uintptr) error {
|
func ioctlLoopClrFd(loopFd uintptr) error {
|
||||||
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, LoopClrFd, 0); err != 0 {
|
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, unix.LOOP_CLR_FD, 0); err != 0 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ioctlLoopGetStatus64(loopFd uintptr) (*loopInfo64, error) {
|
func ioctlLoopGetStatus64(loopFd uintptr) (*unix.LoopInfo64, error) {
|
||||||
loopInfo := &loopInfo64{}
|
loopInfo := &unix.LoopInfo64{}
|
||||||
|
|
||||||
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, LoopGetStatus64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
|
if _, _, err := unix.Syscall(unix.SYS_IOCTL, loopFd, unix.LOOP_GET_STATUS64, uintptr(unsafe.Pointer(loopInfo))); err != 0 {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return loopInfo, nil
|
return loopInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ioctlLoopSetCapacity(loopFd uintptr, value int) error {
|
func ioctlLoopSetCapacity(loopFd uintptr, value int) error {
|
||||||
return unix.IoctlSetInt(int(loopFd), LoopSetCapacity, value)
|
return unix.IoctlSetInt(int(loopFd), unix.LOOP_SET_CAPACITY, value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,52 +1,24 @@
|
||||||
// +build linux,cgo
|
// +build linux
|
||||||
|
|
||||||
package loopback // import "github.com/docker/docker/pkg/loopback"
|
package loopback // import "github.com/docker/docker/pkg/loopback"
|
||||||
|
|
||||||
/*
|
import "golang.org/x/sys/unix"
|
||||||
#include <linux/loop.h> // FIXME: present only for defines, maybe we can remove it?
|
|
||||||
|
|
||||||
#ifndef LOOP_CTL_GET_FREE
|
|
||||||
#define LOOP_CTL_GET_FREE 0x4C82
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef LO_FLAGS_PARTSCAN
|
|
||||||
#define LO_FLAGS_PARTSCAN 8
|
|
||||||
#endif
|
|
||||||
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
type loopInfo64 struct {
|
|
||||||
loDevice uint64 /* ioctl r/o */
|
|
||||||
loInode uint64 /* ioctl r/o */
|
|
||||||
loRdevice uint64 /* ioctl r/o */
|
|
||||||
loOffset uint64
|
|
||||||
loSizelimit uint64 /* bytes, 0 == max available */
|
|
||||||
loNumber uint32 /* ioctl r/o */
|
|
||||||
loEncryptType uint32
|
|
||||||
loEncryptKeySize uint32 /* ioctl w/o */
|
|
||||||
loFlags uint32 /* ioctl r/o */
|
|
||||||
loFileName [LoNameSize]uint8
|
|
||||||
loCryptName [LoNameSize]uint8
|
|
||||||
loEncryptKey [LoKeySize]uint8 /* ioctl w/o */
|
|
||||||
loInit [2]uint64
|
|
||||||
}
|
|
||||||
|
|
||||||
// IOCTL consts
|
// IOCTL consts
|
||||||
const (
|
const (
|
||||||
LoopSetFd = C.LOOP_SET_FD
|
LoopSetFd = unix.LOOP_SET_FD
|
||||||
LoopCtlGetFree = C.LOOP_CTL_GET_FREE
|
LoopCtlGetFree = unix.LOOP_CTL_GET_FREE
|
||||||
LoopGetStatus64 = C.LOOP_GET_STATUS64
|
LoopGetStatus64 = unix.LOOP_GET_STATUS64
|
||||||
LoopSetStatus64 = C.LOOP_SET_STATUS64
|
LoopSetStatus64 = unix.LOOP_SET_STATUS64
|
||||||
LoopClrFd = C.LOOP_CLR_FD
|
LoopClrFd = unix.LOOP_CLR_FD
|
||||||
LoopSetCapacity = C.LOOP_SET_CAPACITY
|
LoopSetCapacity = unix.LOOP_SET_CAPACITY
|
||||||
)
|
)
|
||||||
|
|
||||||
// LOOP consts.
|
// LOOP consts.
|
||||||
const (
|
const (
|
||||||
LoFlagsAutoClear = C.LO_FLAGS_AUTOCLEAR
|
LoFlagsAutoClear = unix.LO_FLAGS_AUTOCLEAR
|
||||||
LoFlagsReadOnly = C.LO_FLAGS_READ_ONLY
|
LoFlagsReadOnly = unix.LO_FLAGS_READ_ONLY
|
||||||
LoFlagsPartScan = C.LO_FLAGS_PARTSCAN
|
LoFlagsPartScan = unix.LO_FLAGS_PARTSCAN
|
||||||
LoKeySize = C.LO_KEY_SIZE
|
LoKeySize = unix.LO_KEY_SIZE
|
||||||
LoNameSize = C.LO_NAME_SIZE
|
LoNameSize = unix.LO_NAME_SIZE
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,7 +16,7 @@ func getLoopbackBackingFile(file *os.File) (uint64, uint64, error) {
|
||||||
logrus.Errorf("Error get loopback backing file: %s", err)
|
logrus.Errorf("Error get loopback backing file: %s", err)
|
||||||
return 0, 0, ErrGetLoopbackBackingFile
|
return 0, 0, ErrGetLoopbackBackingFile
|
||||||
}
|
}
|
||||||
return loopInfo.loDevice, loopInfo.loInode, nil
|
return loopInfo.Device, loopInfo.Inode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCapacity reloads the size for the loopback device.
|
// SetCapacity reloads the size for the loopback device.
|
||||||
|
|
Loading…
Add table
Reference in a new issue