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