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

Fix for weekly.2011-11-18.

parent 2fe2c417
...@@ -114,11 +114,11 @@ func (me *LoopbackFile) Release() { ...@@ -114,11 +114,11 @@ func (me *LoopbackFile) Release() {
} }
func (me *LoopbackFile) Fsync(*FsyncIn) (code Status) { func (me *LoopbackFile) Fsync(*FsyncIn) (code Status) {
return Status(syscall.Fsync(me.File.Fd())) return OsErrorToErrno(syscall.Fsync(me.File.Fd()))
} }
func (me *LoopbackFile) Truncate(size uint64) Status { func (me *LoopbackFile) Truncate(size uint64) Status {
return Status(syscall.Ftruncate(me.File.Fd(), int64(size))) return OsErrorToErrno(syscall.Ftruncate(me.File.Fd(), int64(size)))
} }
// futimens missing from 6g runtime. // futimens missing from 6g runtime.
......
...@@ -158,7 +158,7 @@ func TestFSetAttr(t *testing.T) { ...@@ -158,7 +158,7 @@ func TestFSetAttr(t *testing.T) {
CheckSuccess(err) CheckSuccess(err)
code := syscall.Ftruncate(f.Fd(), 3) code := syscall.Ftruncate(f.Fd(), 3)
if code != 0 { if code != nil {
t.Error("truncate retval", os.NewSyscallError("Ftruncate", code)) t.Error("truncate retval", os.NewSyscallError("Ftruncate", code))
} }
if len(fs.file.data) != 3 { if len(fs.file.data) != 3 {
......
...@@ -113,7 +113,7 @@ func (me *LoopbackFileSystem) Readlink(name string, context *Context) (out strin ...@@ -113,7 +113,7 @@ func (me *LoopbackFileSystem) Readlink(name string, context *Context) (out strin
} }
func (me *LoopbackFileSystem) Mknod(name string, mode uint32, dev uint32, context *Context) (code Status) { func (me *LoopbackFileSystem) Mknod(name string, mode uint32, dev uint32, context *Context) (code Status) {
return Status(syscall.Mknod(me.GetPath(name), mode, int(dev))) return OsErrorToErrno(syscall.Mknod(me.GetPath(name), mode, int(dev)))
} }
func (me *LoopbackFileSystem) Mkdir(path string, mode uint32, context *Context) (code Status) { func (me *LoopbackFileSystem) Mkdir(path string, mode uint32, context *Context) (code Status) {
...@@ -122,11 +122,11 @@ func (me *LoopbackFileSystem) Mkdir(path string, mode uint32, context *Context) ...@@ -122,11 +122,11 @@ func (me *LoopbackFileSystem) Mkdir(path string, mode uint32, context *Context)
// Don't use os.Remove, it removes twice (unlink followed by rmdir). // Don't use os.Remove, it removes twice (unlink followed by rmdir).
func (me *LoopbackFileSystem) Unlink(name string, context *Context) (code Status) { func (me *LoopbackFileSystem) Unlink(name string, context *Context) (code Status) {
return Status(syscall.Unlink(me.GetPath(name))) return OsErrorToErrno(syscall.Unlink(me.GetPath(name)))
} }
func (me *LoopbackFileSystem) Rmdir(name string, context *Context) (code Status) { func (me *LoopbackFileSystem) Rmdir(name string, context *Context) (code Status) {
return Status(syscall.Rmdir(me.GetPath(name))) return OsErrorToErrno(syscall.Rmdir(me.GetPath(name)))
} }
func (me *LoopbackFileSystem) Symlink(pointedTo string, linkName string, context *Context) (code Status) { func (me *LoopbackFileSystem) Symlink(pointedTo string, linkName string, context *Context) (code Status) {
...@@ -143,7 +143,7 @@ func (me *LoopbackFileSystem) Link(orig string, newName string, context *Context ...@@ -143,7 +143,7 @@ func (me *LoopbackFileSystem) Link(orig string, newName string, context *Context
} }
func (me *LoopbackFileSystem) Access(name string, mode uint32, context *Context) (code Status) { func (me *LoopbackFileSystem) Access(name string, mode uint32, context *Context) (code Status) {
return Status(syscall.Access(me.GetPath(name), mode)) return OsErrorToErrno(syscall.Access(me.GetPath(name), mode))
} }
func (me *LoopbackFileSystem) Create(path string, flags uint32, mode uint32, context *Context) (fuseFile File, code Status) { func (me *LoopbackFileSystem) Create(path string, flags uint32, mode uint32, context *Context) (fuseFile File, code Status) {
...@@ -173,9 +173,8 @@ func (me *LoopbackFileSystem) String() string { ...@@ -173,9 +173,8 @@ func (me *LoopbackFileSystem) String() string {
func (me *LoopbackFileSystem) StatFs(name string) *StatfsOut { func (me *LoopbackFileSystem) StatFs(name string) *StatfsOut {
s := syscall.Statfs_t{} s := syscall.Statfs_t{}
errNo := syscall.Statfs(me.GetPath(name), &s) err := syscall.Statfs(me.GetPath(name), &s)
if err == nil {
if errNo == 0 {
return &StatfsOut{ return &StatfsOut{
Kstatfs{ Kstatfs{
Blocks: s.Blocks, Blocks: s.Blocks,
......
...@@ -446,7 +446,7 @@ func TestAccess(t *testing.T) { ...@@ -446,7 +446,7 @@ func TestAccess(t *testing.T) {
err = os.Chmod(me.origFile, 0222) err = os.Chmod(me.origFile, 0222)
CheckSuccess(err) CheckSuccess(err)
errCode = syscall.Access(me.mountFile, W_OK) errCode = syscall.Access(me.mountFile, W_OK)
if errCode != 0 { if errCode != nil {
t.Errorf("Expected no error code for writable. %v", errCode) t.Errorf("Expected no error code for writable. %v", errCode)
} }
} }
...@@ -457,7 +457,7 @@ func TestMknod(t *testing.T) { ...@@ -457,7 +457,7 @@ func TestMknod(t *testing.T) {
t.Log("Testing mknod.") t.Log("Testing mknod.")
errNo := syscall.Mknod(me.mountFile, syscall.S_IFIFO|0777, 0) errNo := syscall.Mknod(me.mountFile, syscall.S_IFIFO|0777, 0)
if errNo != 0 { if errNo != nil {
t.Errorf("Mknod %v", errNo) t.Errorf("Mknod %v", errNo)
} }
fi, _ := os.Lstat(me.origFile) fi, _ := os.Lstat(me.origFile)
...@@ -513,7 +513,7 @@ func TestFSync(t *testing.T) { ...@@ -513,7 +513,7 @@ func TestFSync(t *testing.T) {
// How to really test fsync ? // How to really test fsync ?
errNo := syscall.Fsync(f.Fd()) errNo := syscall.Fsync(f.Fd())
if errNo != 0 { if errNo != nil {
t.Errorf("fsync returned %v", errNo) t.Errorf("fsync returned %v", errNo)
} }
f.Close() f.Close()
...@@ -679,6 +679,8 @@ func clearStatfs(s *syscall.Statfs_t) { ...@@ -679,6 +679,8 @@ func clearStatfs(s *syscall.Statfs_t) {
s.Type = 0 s.Type = 0
s.Fsid = empty.Fsid s.Fsid = empty.Fsid
s.Spare = empty.Spare s.Spare = empty.Spare
// TODO - figure out what this is for.
s.Flags = 0
} }
// This test is racy. If an external process consumes space while this // This test is racy. If an external process consumes space while this
...@@ -690,14 +692,14 @@ func TestStatFs(t *testing.T) { ...@@ -690,14 +692,14 @@ func TestStatFs(t *testing.T) {
empty := syscall.Statfs_t{} empty := syscall.Statfs_t{}
s1 := empty s1 := empty
err := syscall.Statfs(ts.orig, &s1) err := syscall.Statfs(ts.orig, &s1)
if err != 0 { if err != nil {
t.Fatal("statfs orig", err) t.Fatal("statfs orig", err)
} }
s2 := syscall.Statfs_t{} s2 := syscall.Statfs_t{}
err = syscall.Statfs(ts.mnt, &s2) err = syscall.Statfs(ts.mnt, &s2)
if err != 0 { if err != nil {
t.Fatal("statfs mnt", err) t.Fatal("statfs mnt", err)
} }
...@@ -719,7 +721,7 @@ func TestFStatFs(t *testing.T) { ...@@ -719,7 +721,7 @@ func TestFStatFs(t *testing.T) {
empty := syscall.Statfs_t{} empty := syscall.Statfs_t{}
s1 := empty s1 := empty
errno := syscall.Fstatfs(fOrig.Fd(), &s1) errno := syscall.Fstatfs(fOrig.Fd(), &s1)
if errno != 0 { if errno != nil {
t.Fatal("statfs orig", err) t.Fatal("statfs orig", err)
} }
...@@ -729,7 +731,7 @@ func TestFStatFs(t *testing.T) { ...@@ -729,7 +731,7 @@ func TestFStatFs(t *testing.T) {
s2 := empty s2 := empty
errno = syscall.Fstatfs(fMnt.Fd(), &s2) errno = syscall.Fstatfs(fMnt.Fd(), &s2)
if errno != 0 { if errno != nil {
t.Fatal("statfs mnt", err) t.Fatal("statfs mnt", err)
} }
......
...@@ -23,7 +23,7 @@ func (code Status) String() string { ...@@ -23,7 +23,7 @@ func (code Status) String() string {
"NOTIFY_INVAL_ENTRY", "NOTIFY_INVAL_ENTRY",
}[-code] }[-code]
} }
return fmt.Sprintf("%d=%v", int(code), os.Errno(code)) return fmt.Sprintf("%d=%v", int(code), syscall.Errno(code))
} }
func (code Status) Ok() bool { func (code Status) Ok() bool {
...@@ -34,10 +34,10 @@ func (code Status) Ok() bool { ...@@ -34,10 +34,10 @@ func (code Status) Ok() bool {
func OsErrorToErrno(err error) Status { func OsErrorToErrno(err error) Status {
if err != nil { if err != nil {
switch t := err.(type) { switch t := err.(type) {
case os.Errno: case syscall.Errno:
return Status(t) return Status(t)
case *os.SyscallError: case *os.SyscallError:
return Status(t.Errno) return Status(t.Errno.(syscall.Errno))
case *os.PathError: case *os.PathError:
return OsErrorToErrno(t.Err) return OsErrorToErrno(t.Err)
case *os.LinkError: case *os.LinkError:
...@@ -104,7 +104,7 @@ func Writev(fd int, packet [][]byte) (n int, err error) { ...@@ -104,7 +104,7 @@ func Writev(fd int, packet [][]byte) (n int, err error) {
n, errno := writev(fd, &iovecs[0], len(iovecs)) n, errno := writev(fd, &iovecs[0], len(iovecs))
if errno != 0 { if errno != 0 {
err = os.NewSyscallError("writev", errno) err = os.NewSyscallError("writev", syscall.Errno(errno))
} }
return n, err return n, err
} }
......
...@@ -9,19 +9,19 @@ import ( ...@@ -9,19 +9,19 @@ import (
func TestOsErrorToErrno(t *testing.T) { func TestOsErrorToErrno(t *testing.T) {
errNo := OsErrorToErrno(os.EPERM) errNo := OsErrorToErrno(os.EPERM)
if errNo != syscall.EPERM { if errNo != EPERM {
t.Errorf("Wrong conversion %v != %v", errNo, syscall.EPERM) t.Errorf("Wrong conversion %v != %v", errNo, syscall.EPERM)
} }
e := os.NewSyscallError("syscall", syscall.EPERM) e := os.NewSyscallError("syscall", syscall.EPERM)
errNo = OsErrorToErrno(e) errNo = OsErrorToErrno(e)
if errNo != syscall.EPERM { if errNo != EPERM {
t.Errorf("Wrong conversion %v != %v", errNo, syscall.EPERM) t.Errorf("Wrong conversion %v != %v", errNo, syscall.EPERM)
} }
e = os.Remove("this-file-surely-does-not-exist") e = os.Remove("this-file-surely-does-not-exist")
errNo = OsErrorToErrno(e) errNo = OsErrorToErrno(e)
if errNo != syscall.ENOENT { if errNo != ENOENT {
t.Errorf("Wrong conversion %v != %v", errNo, syscall.ENOENT) t.Errorf("Wrong conversion %v != %v", errNo, syscall.ENOENT)
} }
} }
......
...@@ -27,9 +27,10 @@ func Socketpair(network string) (l, r *os.File, err error) { ...@@ -27,9 +27,10 @@ func Socketpair(network string) (l, r *os.File, err error) {
default: default:
log.Panicf("unknown network %q", network) log.Panicf("unknown network %q", network)
} }
fd, errno := syscall.Socketpair(domain, typ, 0) fd, err := syscall.Socketpair(domain, typ, 0)
if errno != 0 { if err != nil {
return nil, nil, os.NewSyscallError("socketpair", errno) return nil, nil, os.NewSyscallError("socketpair",
err.(syscall.Errno))
} }
l = os.NewFile(fd[0], "socketpair-half1") l = os.NewFile(fd[0], "socketpair-half1")
r = os.NewFile(fd[1], "socketpair-half2") r = os.NewFile(fd[1], "socketpair-half2")
...@@ -59,6 +60,7 @@ func mount(mountPoint string, options string) (f *os.File, finalMountPoint strin ...@@ -59,6 +60,7 @@ func mount(mountPoint string, options string) (f *os.File, finalMountPoint strin
cmd := []string{fusermountBinary, mountPoint} cmd := []string{fusermountBinary, mountPoint}
if options != "" { if options != "" {
log.Printf("o %q", options)
cmd = append(cmd, "-o") cmd = append(cmd, "-o")
cmd = append(cmd, options) cmd = append(cmd, options)
} }
...@@ -128,9 +130,9 @@ func getConnection(local *os.File) (f *os.File, err error) { ...@@ -128,9 +130,9 @@ func getConnection(local *os.File) (f *os.File, err error) {
// n, oobn, recvflags, from, errno - todo: error checking. // n, oobn, recvflags, from, errno - todo: error checking.
_, oobn, _, _, _, oobn, _, _,
errno := syscall.Recvmsg( err := syscall.Recvmsg(
local.Fd(), data[:], control[:], 0) local.Fd(), data[:], control[:], 0)
if errno != 0 { if err != nil {
return return
} }
......
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"log" "log"
"os" "os"
"strings" "strings"
"syscall"
"time" "time"
"unsafe" "unsafe"
) )
...@@ -125,7 +124,7 @@ func (me *MountState) newRequest() *request { ...@@ -125,7 +124,7 @@ func (me *MountState) newRequest() *request {
} }
} }
func (me *MountState) readRequest(req *request) error { func (me *MountState) readRequest(req *request) Status {
n, err := me.mountFile.Read(req.inputBuf) n, err := me.mountFile.Read(req.inputBuf)
// If we start timing before the read, we may take into // If we start timing before the read, we may take into
// account waiting for input into the timing. // account waiting for input into the timing.
...@@ -133,7 +132,7 @@ func (me *MountState) readRequest(req *request) error { ...@@ -133,7 +132,7 @@ func (me *MountState) readRequest(req *request) error {
req.startNs = time.Nanoseconds() req.startNs = time.Nanoseconds()
} }
req.inputBuf = req.inputBuf[0:n] req.inputBuf = req.inputBuf[0:n]
return err return OsErrorToErrno(err)
} }
func (me *MountState) recordStats(req *request) { func (me *MountState) recordStats(req *request) {
...@@ -162,21 +161,19 @@ func (me *MountState) Loop() { ...@@ -162,21 +161,19 @@ func (me *MountState) Loop() {
func (me *MountState) loop() { func (me *MountState) loop() {
for { for {
req := me.newRequest() req := me.newRequest()
err := me.readRequest(req) errNo := me.readRequest(req)
if err != nil { if !errNo.Ok() {
errNo := OsErrorToErrno(err)
// Retry. // Retry.
if errNo == syscall.ENOENT { if errNo == ENOENT {
continue continue
} }
if errNo == syscall.ENODEV { if errNo == ENODEV {
// Unmount. // Unmount.
break break
} }
log.Printf("Failed to read from fuse conn: %v", err) log.Printf("Failed to read from fuse conn: %v", errNo)
break break
} }
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"path/filepath" "path/filepath"
"sort" "sort"
"strings" "strings"
"syscall"
) )
// SwitchFileSystem construct the union of a set of filesystems, and // SwitchFileSystem construct the union of a set of filesystems, and
...@@ -136,7 +135,7 @@ func (me *SwitchFileSystem) Rename(oldName string, newName string, context *Cont ...@@ -136,7 +135,7 @@ func (me *SwitchFileSystem) Rename(oldName string, newName string, context *Cont
oldName, fs1 := me.findFileSystem(oldName) oldName, fs1 := me.findFileSystem(oldName)
newName, fs2 := me.findFileSystem(newName) newName, fs2 := me.findFileSystem(newName)
if fs1 != fs2 { if fs1 != fs2 {
return syscall.EXDEV return EXDEV
} }
if fs1 == nil { if fs1 == nil {
return ENOENT return ENOENT
...@@ -148,7 +147,7 @@ func (me *SwitchFileSystem) Link(oldName string, newName string, context *Contex ...@@ -148,7 +147,7 @@ func (me *SwitchFileSystem) Link(oldName string, newName string, context *Contex
oldName, fs1 := me.findFileSystem(oldName) oldName, fs1 := me.findFileSystem(oldName)
newName, fs2 := me.findFileSystem(newName) newName, fs2 := me.findFileSystem(newName)
if fs1 != fs2 { if fs1 != fs2 {
return syscall.EXDEV return EXDEV
} }
if fs1 == nil { if fs1 == nil {
return ENOENT return ENOENT
......
...@@ -53,6 +53,8 @@ const ( ...@@ -53,6 +53,8 @@ const (
ERANGE = Status(syscall.ERANGE) ERANGE = Status(syscall.ERANGE)
EXDEV = Status(syscall.EXDEV) EXDEV = Status(syscall.EXDEV)
EBADF = Status(syscall.EBADF) EBADF = Status(syscall.EBADF)
ENODEV = Status(syscall.ENODEV)
EROFS = Status(syscall.EROFS)
) )
type NotifyCode int type NotifyCode int
......
...@@ -229,7 +229,7 @@ func (me *AutoUnionFs) Symlink(pointedTo string, linkName string, context *fuse. ...@@ -229,7 +229,7 @@ func (me *AutoUnionFs) Symlink(pointedTo string, linkName string, context *fuse.
if comps[0] == _CONFIG { if comps[0] == _CONFIG {
roots := me.getRoots(pointedTo) roots := me.getRoots(pointedTo)
if roots == nil { if roots == nil {
return syscall.ENOTDIR return fuse.Status(syscall.ENOTDIR)
} }
name := comps[1] name := comps[1]
......
...@@ -129,7 +129,7 @@ func (me *UnionFs) isDeleted(name string) (deleted bool, code fuse.Status) { ...@@ -129,7 +129,7 @@ func (me *UnionFs) isDeleted(name string) (deleted bool, code fuse.Status) {
} }
log.Println("error accessing deletion marker:", marker) log.Println("error accessing deletion marker:", marker)
return false, syscall.EROFS return false, fuse.Status(syscall.EROFS)
} }
func (me *UnionFs) createDeletionStore() (code fuse.Status) { func (me *UnionFs) createDeletionStore() (code fuse.Status) {
...@@ -143,7 +143,7 @@ func (me *UnionFs) createDeletionStore() (code fuse.Status) { ...@@ -143,7 +143,7 @@ func (me *UnionFs) createDeletionStore() (code fuse.Status) {
} }
if !code.Ok() || !fi.IsDirectory() { if !code.Ok() || !fi.IsDirectory() {
code = syscall.EROFS code = fuse.Status(syscall.EROFS)
} }
return code return code
...@@ -379,7 +379,7 @@ func (me *UnionFs) Rmdir(path string, context *fuse.Context) (code fuse.Status) ...@@ -379,7 +379,7 @@ func (me *UnionFs) Rmdir(path string, context *fuse.Context) (code fuse.Status)
return r.code return r.code
} }
if !r.attr.IsDirectory() { if !r.attr.IsDirectory() {
return syscall.ENOTDIR return fuse.Status(syscall.ENOTDIR)
} }
stream, code := me.OpenDir(path, context) stream, code := me.OpenDir(path, context)
...@@ -388,7 +388,7 @@ func (me *UnionFs) Rmdir(path string, context *fuse.Context) (code fuse.Status) ...@@ -388,7 +388,7 @@ func (me *UnionFs) Rmdir(path string, context *fuse.Context) (code fuse.Status)
found = true found = true
} }
if found { if found {
return syscall.ENOTEMPTY return fuse.Status(syscall.ENOTEMPTY)
} }
if r.branch > 0 { if r.branch > 0 {
...@@ -416,7 +416,7 @@ func (me *UnionFs) Mkdir(path string, mode uint32, context *fuse.Context) (code ...@@ -416,7 +416,7 @@ func (me *UnionFs) Mkdir(path string, mode uint32, context *fuse.Context) (code
if !deleted { if !deleted {
r := me.getBranch(path) r := me.getBranch(path)
if r.code != fuse.ENOENT { if r.code != fuse.ENOENT {
return syscall.EEXIST return fuse.Status(syscall.EEXIST)
} }
} }
...@@ -761,7 +761,7 @@ func (me *UnionFs) OpenDir(directory string, context *fuse.Context) (stream chan ...@@ -761,7 +761,7 @@ func (me *UnionFs) OpenDir(directory string, context *fuse.Context) (stream chan
if code == fuse.ENOENT { if code == fuse.ENOENT {
deletions = map[string]bool{} deletions = map[string]bool{}
} else { } else {
return nil, syscall.EROFS return nil, fuse.Status(syscall.EROFS)
} }
} }
......
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