Commit 5c9096d6 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Hide Writev syscall, remove Linkat syscall.

parent 3d0731da
// +build linux
package fuse
import (
"io/ioutil"
"os"
"syscall"
"testing"
)
func TestLinkAt(t *testing.T) {
dir, _ := ioutil.TempDir("", "go-fuse-misc_test")
ioutil.WriteFile(dir+"/a", []byte{42}, 0644)
f, _ := os.Open(dir)
e := Linkat(int(f.Fd()), "a", int(f.Fd()), "b")
if e != 0 {
t.Fatalf("Linkat %d", e)
}
var s1, s2 syscall.Stat_t
err := syscall.Lstat(dir+"/a", &s1)
if err != nil {
t.Fatalf("Lstat a: %v", err)
}
err = syscall.Lstat(dir+"/b", &s2)
if err != nil {
t.Fatalf("Lstat b: %v", err)
}
if s1.Ino != s2.Ino {
t.Fatal("Ino mismatch", s1, s2)
}
}
...@@ -17,7 +17,7 @@ func (ms *MountState) systemWrite(req *request, header []byte) Status { ...@@ -17,7 +17,7 @@ func (ms *MountState) systemWrite(req *request, header []byte) Status {
header = req.serializeHeader(len(req.flatData)) header = req.serializeHeader(len(req.flatData))
} }
_, err := Writev(int(ms.mountFd), [][]byte{header, req.flatData}) _, err := writev(int(ms.mountFd), [][]byte{header, req.flatData})
if req.readResult != nil { if req.readResult != nil {
req.readResult.Done() req.readResult.Done()
} }
......
...@@ -27,7 +27,7 @@ func (ms *MountState) systemWrite(req *request, header []byte) Status { ...@@ -27,7 +27,7 @@ func (ms *MountState) systemWrite(req *request, header []byte) Status {
header = req.serializeHeader(len(req.flatData)) header = req.serializeHeader(len(req.flatData))
} }
_, err := Writev(ms.mountFd, [][]byte{header, req.flatData}) _, err := writev(ms.mountFd, [][]byte{header, req.flatData})
if req.readResult != nil { if req.readResult != nil {
req.readResult.Done() req.readResult.Done()
} }
......
...@@ -9,14 +9,14 @@ import ( ...@@ -9,14 +9,14 @@ import (
// TODO - move these into Go's syscall package. // TODO - move these into Go's syscall package.
func writev(fd int, iovecs *syscall.Iovec, cnt int) (n int, errno int) { func sys_writev(fd int, iovecs *syscall.Iovec, cnt int) (n int, errno int) {
n1, _, e1 := syscall.Syscall( n1, _, e1 := syscall.Syscall(
syscall.SYS_WRITEV, syscall.SYS_WRITEV,
uintptr(fd), uintptr(unsafe.Pointer(iovecs)), uintptr(cnt)) uintptr(fd), uintptr(unsafe.Pointer(iovecs)), uintptr(cnt))
return int(n1), int(e1) return int(n1), int(e1)
} }
func Writev(fd int, packet [][]byte) (n int, err error) { func writev(fd int, packet [][]byte) (n int, err error) {
iovecs := make([]syscall.Iovec, 0, len(packet)) iovecs := make([]syscall.Iovec, 0, len(packet))
for _, v := range packet { for _, v := range packet {
...@@ -30,7 +30,7 @@ func Writev(fd int, packet [][]byte) (n int, err error) { ...@@ -30,7 +30,7 @@ func Writev(fd int, packet [][]byte) (n int, err error) {
iovecs = append(iovecs, vec) iovecs = append(iovecs, vec)
} }
n, errno := writev(fd, &iovecs[0], len(iovecs)) n, errno := sys_writev(fd, &iovecs[0], len(iovecs))
if errno != 0 { if errno != 0 {
err = os.NewSyscallError("writev", syscall.Errno(errno)) err = os.NewSyscallError("writev", syscall.Errno(errno))
} }
......
...@@ -8,14 +8,14 @@ import ( ...@@ -8,14 +8,14 @@ import (
// TODO - move these into Go's syscall package. // TODO - move these into Go's syscall package.
func writev(fd int, iovecs *syscall.Iovec, cnt int) (n int, errno int) { func sys_writev(fd int, iovecs *syscall.Iovec, cnt int) (n int, errno int) {
n1, _, e1 := syscall.Syscall( n1, _, e1 := syscall.Syscall(
syscall.SYS_WRITEV, syscall.SYS_WRITEV,
uintptr(fd), uintptr(unsafe.Pointer(iovecs)), uintptr(cnt)) uintptr(fd), uintptr(unsafe.Pointer(iovecs)), uintptr(cnt))
return int(n1), int(e1) return int(n1), int(e1)
} }
func Writev(fd int, packet [][]byte) (n int, err error) { func writev(fd int, packet [][]byte) (n int, err error) {
iovecs := make([]syscall.Iovec, 0, len(packet)) iovecs := make([]syscall.Iovec, 0, len(packet))
for _, v := range packet { for _, v := range packet {
...@@ -29,25 +29,9 @@ func Writev(fd int, packet [][]byte) (n int, err error) { ...@@ -29,25 +29,9 @@ func Writev(fd int, packet [][]byte) (n int, err error) {
iovecs = append(iovecs, vec) iovecs = append(iovecs, vec)
} }
n, errno := writev(fd, &iovecs[0], len(iovecs)) n, errno := sys_writev(fd, &iovecs[0], len(iovecs))
if errno != 0 { if errno != 0 {
err = os.NewSyscallError("writev", syscall.Errno(errno)) err = os.NewSyscallError("writev", syscall.Errno(errno))
} }
return n, err return n, err
} }
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