Use continuity fs package

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff
2018-02-07 12:40:52 -05:00
parent f12ba2407e
commit c776b6d8d9
63 changed files with 175 additions and 1126 deletions

View File

@@ -1,15 +0,0 @@
package devices
// from /usr/include/sys/types.h
func getmajor(dev int32) uint64 {
return (uint64(dev) >> 24) & 0xff
}
func getminor(dev int32) uint64 {
return uint64(dev) & 0xffffff
}
func makedev(major int, minor int) int {
return ((major << 24) | minor)
}

View File

@@ -1,23 +0,0 @@
// +build solaris,!cgo
//
// Implementing the functions below requires cgo support. Non-cgo stubs
// versions are defined below to enable cross-compilation of source code
// that depends on these functions, but the resultant cross-compiled
// binaries cannot actually be used. If the stub function(s) below are
// actually invoked they will cause the calling process to exit.
//
package devices
func getmajor(dev uint64) uint64 {
panic("getmajor() support requires cgo.")
}
func getminor(dev uint64) uint64 {
panic("getminor() support requires cgo.")
}
func makedev(major int, minor int) int {
panic("makedev() support requires cgo.")
}

View File

@@ -1,15 +0,0 @@
package devices
// from /usr/include/sys/types.h
func getmajor(dev uint32) uint64 {
return (uint64(dev) >> 24) & 0xff
}
func getminor(dev uint32) uint64 {
return uint64(dev) & 0xffffff
}
func makedev(major int, minor int) int {
return ((major << 24) | minor)
}

View File

@@ -1,15 +0,0 @@
package devices
// from /usr/include/linux/kdev_t.h
func getmajor(dev uint64) uint64 {
return dev >> 8
}
func getminor(dev uint64) uint64 {
return dev & 0xff
}
func makedev(major int, minor int) int {
return ((major << 8) | minor)
}

View File

@@ -1,18 +0,0 @@
// +build cgo
package devices
//#include <sys/mkdev.h>
import "C"
func getmajor(dev uint64) uint64 {
return uint64(C.major(C.dev_t(dev)))
}
func getminor(dev uint64) uint64 {
return uint64(C.minor(C.dev_t(dev)))
}
func makedev(major int, minor int) int {
return int(C.makedev(C.major_t(major), C.minor_t(minor)))
}

View File

@@ -6,6 +6,8 @@ import (
"fmt"
"os"
"syscall"
"golang.org/x/sys/unix"
)
func DeviceInfo(fi os.FileInfo) (uint64, uint64, error) {
@@ -14,42 +16,43 @@ func DeviceInfo(fi os.FileInfo) (uint64, uint64, error) {
return 0, 0, fmt.Errorf("cannot extract device from os.FileInfo")
}
return getmajor(sys.Rdev), getminor(sys.Rdev), nil
dev := uint64(sys.Rdev)
return uint64(unix.Major(dev)), uint64(unix.Minor(dev)), nil
}
// mknod provides a shortcut for syscall.Mknod
func Mknod(p string, mode os.FileMode, maj, min int) error {
var (
m = syscallMode(mode.Perm())
dev int
dev uint64
)
if mode&os.ModeDevice != 0 {
dev = makedev(maj, min)
dev = unix.Mkdev(uint32(maj), uint32(min))
if mode&os.ModeCharDevice != 0 {
m |= syscall.S_IFCHR
m |= unix.S_IFCHR
} else {
m |= syscall.S_IFBLK
m |= unix.S_IFBLK
}
} else if mode&os.ModeNamedPipe != 0 {
m |= syscall.S_IFIFO
m |= unix.S_IFIFO
}
return syscall.Mknod(p, m, dev)
return unix.Mknod(p, m, int(dev))
}
// syscallMode returns the syscall-specific mode bits from Go's portable mode bits.
func syscallMode(i os.FileMode) (o uint32) {
o |= uint32(i.Perm())
if i&os.ModeSetuid != 0 {
o |= syscall.S_ISUID
o |= unix.S_ISUID
}
if i&os.ModeSetgid != 0 {
o |= syscall.S_ISGID
o |= unix.S_ISGID
}
if i&os.ModeSticky != 0 {
o |= syscall.S_ISVTX
o |= unix.S_ISVTX
}
return
}