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

Implement Linkat() syscall wrapper.

parent 2c888896
......@@ -159,3 +159,18 @@ func VerboseTest() bool {
flag := flag.Lookup("test.v")
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)
}
package fuse
import (
"io/ioutil"
"os"
"testing"
"syscall"
......@@ -24,3 +25,26 @@ func TestOsErrorToErrno(t *testing.T) {
t.Errorf("Wrong conversion %v != %v", errNo, syscall.ENOENT)
}
}
func TestLinkAt(t *testing.T) {
dir, _ := ioutil.TempDir("", "go-fuse")
ioutil.WriteFile(dir + "/a", []byte{42}, 0644)
f, _ := os.Open(dir)
e := Linkat(f.Fd(), "a", f.Fd(), "b")
if e != 0 {
t.Fatalf("Linkat %d", e)
}
f1, err := os.Lstat(dir + "/a")
if err != nil {
t.Fatalf("Lstat a: %v", err)
}
f2, err := os.Lstat(dir + "/b")
if err != nil {
t.Fatalf("Lstat b: %v", err)
}
if f1.Ino != f2.Ino {
t.Fatal("Ino mismatch", f1, f2)
}
}
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