Commit 48305247 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Move all syscall.Syscall calls into syscall.go.

parent b1f87d34
...@@ -31,10 +31,10 @@ MANUAL_GOFILES=api.go \ ...@@ -31,10 +31,10 @@ MANUAL_GOFILES=api.go \
fsops.go \ fsops.go \
readonlyfs.go \ readonlyfs.go \
request.go \ request.go \
syscall.go \
typeprint.go \ typeprint.go \
types.go \ types.go \
version.go \ version.go \
xattr.go \
GOFILES=$(MANUAL_GOFILES) version.gen.go GOFILES=$(MANUAL_GOFILES) version.gen.go
......
...@@ -56,39 +56,6 @@ func splitDuration(dt time.Duration, secs *uint64, nsecs *uint32) { ...@@ -56,39 +56,6 @@ func splitDuration(dt time.Duration, secs *uint64, nsecs *uint32) {
*secs = uint64(ns / 1e9) *secs = uint64(ns / 1e9)
} }
// TODO - expose in Go's syscall package.
func writev(fd int, iovecs *syscall.Iovec, cnt int) (n int, errno int) {
n1, _, e1 := syscall.Syscall(
syscall.SYS_WRITEV,
uintptr(fd), uintptr(unsafe.Pointer(iovecs)), uintptr(cnt))
return int(n1), int(e1)
}
func Writev(fd int, packet [][]byte) (n int, err error) {
iovecs := make([]syscall.Iovec, 0, len(packet))
for _, v := range packet {
if v == nil || len(v) == 0 {
continue
}
vec := syscall.Iovec{
Base: &v[0],
}
vec.SetLen(len(v))
iovecs = append(iovecs, vec)
}
if len(iovecs) == 0 {
return 0, nil
}
n, errno := writev(fd, &iovecs[0], len(iovecs))
if errno != 0 {
err = os.NewSyscallError("writev", syscall.Errno(errno))
}
return n, err
}
func ModeToType(mode uint32) uint32 { func ModeToType(mode uint32) uint32 {
return (mode & 0170000) >> 12 return (mode & 0170000) >> 12
} }
...@@ -105,13 +72,6 @@ func asSlice(ptr unsafe.Pointer, byteCount uintptr) []byte { ...@@ -105,13 +72,6 @@ func asSlice(ptr unsafe.Pointer, byteCount uintptr) []byte {
return *(*[]byte)(unsafe.Pointer(h)) return *(*[]byte)(unsafe.Pointer(h))
} }
func ioctl(fd int, cmd int, arg uintptr) (int, int) {
r0, _, e1 := syscall.Syscall(
syscall.SYS_IOCTL, uintptr(fd), uintptr(cmd), uintptr(arg))
val := int(r0)
errno := int(e1)
return val, errno
}
func Version() string { func Version() string {
if version != nil { if version != nil {
...@@ -140,22 +100,6 @@ func VerboseTest() bool { ...@@ -140,22 +100,6 @@ func VerboseTest() bool {
return flag != nil && flag.Value.String() == "true" return flag != nil && flag.Value.String() == "true"
} }
const AT_FDCWD = -100
func Linkat(fd1 int, n1 string, fd2 int, n2 string) int {
b1 := syscall.StringBytePtr(n1)
b2 := syscall.StringBytePtr(n2)
_, _, errNo := syscall.Syscall6(
syscall.SYS_LINKAT,
uintptr(fd1),
uintptr(unsafe.Pointer(b1)),
uintptr(fd2),
uintptr(unsafe.Pointer(b2)),
0, 0)
return int(errNo)
}
func init() { func init() {
p := syscall.Getpagesize() p := syscall.Getpagesize()
if p != PAGESIZE { if p != PAGESIZE {
......
...@@ -2,14 +2,40 @@ package fuse ...@@ -2,14 +2,40 @@ package fuse
import ( import (
"bytes" "bytes"
"fmt" "os"
"syscall" "syscall"
"unsafe" "unsafe"
) )
var _ = fmt.Print // TODO - move these into Go's syscall package.
// TODO - move this into the Go distribution. func writev(fd int, iovecs *syscall.Iovec, cnt int) (n int, errno int) {
n1, _, e1 := syscall.Syscall(
syscall.SYS_WRITEV,
uintptr(fd), uintptr(unsafe.Pointer(iovecs)), uintptr(cnt))
return int(n1), int(e1)
}
func Writev(fd int, packet [][]byte) (n int, err error) {
iovecs := make([]syscall.Iovec, 0, len(packet))
for _, v := range packet {
if v == nil || len(v) == 0 {
continue
}
vec := syscall.Iovec{
Base: &v[0],
}
vec.SetLen(len(v))
iovecs = append(iovecs, vec)
}
n, errno := writev(fd, &iovecs[0], len(iovecs))
if errno != 0 {
err = os.NewSyscallError("writev", syscall.Errno(errno))
}
return n, err
}
func getxattr(path string, attr string, dest []byte) (sz int, errno int) { func getxattr(path string, attr string, dest []byte) (sz int, errno int) {
pathBs := syscall.StringBytePtr(path) pathBs := syscall.StringBytePtr(path)
...@@ -96,3 +122,27 @@ func Removexattr(path string, attr string) (errno int) { ...@@ -96,3 +122,27 @@ func Removexattr(path string, attr string) (errno int) {
uintptr(unsafe.Pointer(attrbs)), 0) uintptr(unsafe.Pointer(attrbs)), 0)
return int(errNo) return int(errNo)
} }
func ioctl(fd int, cmd int, arg uintptr) (int, int) {
r0, _, e1 := syscall.Syscall(
syscall.SYS_IOCTL, uintptr(fd), uintptr(cmd), uintptr(arg))
val := int(r0)
errno := int(e1)
return val, errno
}
const AT_FDCWD = -100
func Linkat(fd1 int, n1 string, fd2 int, n2 string) int {
b1 := syscall.StringBytePtr(n1)
b2 := syscall.StringBytePtr(n2)
_, _, errNo := syscall.Syscall6(
syscall.SYS_LINKAT,
uintptr(fd1),
uintptr(unsafe.Pointer(b1)),
uintptr(fd2),
uintptr(unsafe.Pointer(b2)),
0, 0)
return int(errNo)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment