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

Rename OsErrorToErrno to ToStatus.

parent ba19bafd
......@@ -101,12 +101,12 @@ func (me *LoopbackFile) Read(input *ReadIn, buffers BufferPool) ([]byte, Status)
if err == io.EOF {
err = nil
}
return slice[:n], OsErrorToErrno(err)
return slice[:n], ToStatus(err)
}
func (me *LoopbackFile) Write(input *WriteIn, data []byte) (uint32, Status) {
n, err := me.File.WriteAt(data, int64(input.Offset))
return uint32(n), OsErrorToErrno(err)
return uint32(n), ToStatus(err)
}
func (me *LoopbackFile) Release() {
......@@ -114,27 +114,27 @@ func (me *LoopbackFile) Release() {
}
func (me *LoopbackFile) Fsync(*FsyncIn) (code Status) {
return OsErrorToErrno(syscall.Fsync(me.File.Fd()))
return ToStatus(syscall.Fsync(me.File.Fd()))
}
func (me *LoopbackFile) Truncate(size uint64) Status {
return OsErrorToErrno(syscall.Ftruncate(me.File.Fd(), int64(size)))
return ToStatus(syscall.Ftruncate(me.File.Fd(), int64(size)))
}
// futimens missing from 6g runtime.
func (me *LoopbackFile) Chmod(mode uint32) Status {
return OsErrorToErrno(me.File.Chmod(mode))
return ToStatus(me.File.Chmod(mode))
}
func (me *LoopbackFile) Chown(uid uint32, gid uint32) Status {
return OsErrorToErrno(me.File.Chown(int(uid), int(gid)))
return ToStatus(me.File.Chown(int(uid), int(gid)))
}
func (me *LoopbackFile) GetAttr() (*os.FileInfo, Status) {
fi, err := me.File.Stat()
if err != nil {
return nil, OsErrorToErrno(err)
return nil, ToStatus(err)
}
return fi, OK
}
......
......@@ -44,7 +44,7 @@ func (me *LoopbackFileSystem) GetAttr(name string, context *Context) (fi *os.Fil
fi, err = os.Lstat(fullPath)
}
if err != nil {
return nil, OsErrorToErrno(err)
return nil, ToStatus(err)
}
return fi, OK
}
......@@ -54,7 +54,7 @@ func (me *LoopbackFileSystem) OpenDir(name string, context *Context) (stream cha
// directories?
f, err := os.Open(me.GetPath(name))
if err != nil {
return nil, OsErrorToErrno(err)
return nil, ToStatus(err)
}
want := 500
output := make(chan DirEntry, want)
......@@ -85,70 +85,70 @@ func (me *LoopbackFileSystem) OpenDir(name string, context *Context) (stream cha
func (me *LoopbackFileSystem) Open(name string, flags uint32, context *Context) (fuseFile File, status Status) {
f, err := os.OpenFile(me.GetPath(name), int(flags), 0)
if err != nil {
return nil, OsErrorToErrno(err)
return nil, ToStatus(err)
}
return &LoopbackFile{File: f}, OK
}
func (me *LoopbackFileSystem) Chmod(path string, mode uint32, context *Context) (code Status) {
err := os.Chmod(me.GetPath(path), mode)
return OsErrorToErrno(err)
return ToStatus(err)
}
func (me *LoopbackFileSystem) Chown(path string, uid uint32, gid uint32, context *Context) (code Status) {
return OsErrorToErrno(os.Chown(me.GetPath(path), int(uid), int(gid)))
return ToStatus(os.Chown(me.GetPath(path), int(uid), int(gid)))
}
func (me *LoopbackFileSystem) Truncate(path string, offset uint64, context *Context) (code Status) {
return OsErrorToErrno(os.Truncate(me.GetPath(path), int64(offset)))
return ToStatus(os.Truncate(me.GetPath(path), int64(offset)))
}
func (me *LoopbackFileSystem) Utimens(path string, AtimeNs uint64, MtimeNs uint64, context *Context) (code Status) {
return OsErrorToErrno(os.Chtimes(me.GetPath(path), int64(AtimeNs), int64(MtimeNs)))
return ToStatus(os.Chtimes(me.GetPath(path), int64(AtimeNs), int64(MtimeNs)))
}
func (me *LoopbackFileSystem) Readlink(name string, context *Context) (out string, code Status) {
f, err := os.Readlink(me.GetPath(name))
return f, OsErrorToErrno(err)
return f, ToStatus(err)
}
func (me *LoopbackFileSystem) Mknod(name string, mode uint32, dev uint32, context *Context) (code Status) {
return OsErrorToErrno(syscall.Mknod(me.GetPath(name), mode, int(dev)))
return ToStatus(syscall.Mknod(me.GetPath(name), mode, int(dev)))
}
func (me *LoopbackFileSystem) Mkdir(path string, mode uint32, context *Context) (code Status) {
return OsErrorToErrno(os.Mkdir(me.GetPath(path), mode))
return ToStatus(os.Mkdir(me.GetPath(path), mode))
}
// Don't use os.Remove, it removes twice (unlink followed by rmdir).
func (me *LoopbackFileSystem) Unlink(name string, context *Context) (code Status) {
return OsErrorToErrno(syscall.Unlink(me.GetPath(name)))
return ToStatus(syscall.Unlink(me.GetPath(name)))
}
func (me *LoopbackFileSystem) Rmdir(name string, context *Context) (code Status) {
return OsErrorToErrno(syscall.Rmdir(me.GetPath(name)))
return ToStatus(syscall.Rmdir(me.GetPath(name)))
}
func (me *LoopbackFileSystem) Symlink(pointedTo string, linkName string, context *Context) (code Status) {
return OsErrorToErrno(os.Symlink(pointedTo, me.GetPath(linkName)))
return ToStatus(os.Symlink(pointedTo, me.GetPath(linkName)))
}
func (me *LoopbackFileSystem) Rename(oldPath string, newPath string, context *Context) (code Status) {
err := os.Rename(me.GetPath(oldPath), me.GetPath(newPath))
return OsErrorToErrno(err)
return ToStatus(err)
}
func (me *LoopbackFileSystem) Link(orig string, newName string, context *Context) (code Status) {
return OsErrorToErrno(os.Link(me.GetPath(orig), me.GetPath(newName)))
return ToStatus(os.Link(me.GetPath(orig), me.GetPath(newName)))
}
func (me *LoopbackFileSystem) Access(name string, mode uint32, context *Context) (code Status) {
return OsErrorToErrno(syscall.Access(me.GetPath(name), mode))
return ToStatus(syscall.Access(me.GetPath(name), mode))
}
func (me *LoopbackFileSystem) Create(path string, flags uint32, mode uint32, context *Context) (fuseFile File, code Status) {
f, err := os.OpenFile(me.GetPath(path), int(flags)|os.O_CREATE, mode)
return &LoopbackFile{File: f}, OsErrorToErrno(err)
return &LoopbackFile{File: f}, ToStatus(err)
}
func (me *LoopbackFileSystem) GetXAttr(name string, attr string, context *Context) ([]byte, Status) {
......
......@@ -129,7 +129,7 @@ func (me *memNode) Create(name string, flags uint32, mode uint32, context *Conte
f, err := os.Create(n.filename())
if err != nil {
return nil, nil, nil, OsErrorToErrno(err)
return nil, nil, nil, ToStatus(err)
}
me.Inode().AddChild(name, n.Inode())
return n.newFile(f), &n.info, n, OK
......@@ -166,7 +166,7 @@ func (me *memNode) newFile(f *os.File) File {
func (me *memNode) Open(flags uint32, context *Context) (file File, code Status) {
f, err := os.OpenFile(me.filename(), int(flags), 0666)
if err != nil {
return nil, OsErrorToErrno(err)
return nil, ToStatus(err)
}
return me.newFile(f), OK
......@@ -184,7 +184,7 @@ func (me *memNode) Truncate(file File, size uint64, context *Context) (code Stat
me.info.Size = int64(size)
err := os.Truncate(me.filename(), int64(size))
me.info.Ctime_ns = time.Nanoseconds()
return OsErrorToErrno(err)
return ToStatus(err)
}
func (me *memNode) Utimens(file File, atime uint64, mtime uint64, context *Context) (code Status) {
......
......@@ -30,8 +30,8 @@ func (code Status) Ok() bool {
return code == OK
}
// Convert os.Error back to Errno based errors.
func OsErrorToErrno(err error) Status {
// Convert error back to Errno based errors.
func ToStatus(err error) Status {
if err != nil {
switch t := err.(type) {
case syscall.Errno:
......@@ -39,9 +39,9 @@ func OsErrorToErrno(err error) Status {
case *os.SyscallError:
return Status(t.Errno.(syscall.Errno))
case *os.PathError:
return OsErrorToErrno(t.Err)
return ToStatus(t.Err)
case *os.LinkError:
return OsErrorToErrno(t.Err)
return ToStatus(t.Err)
default:
log.Println("can't convert error type:", err)
return ENOSYS
......
......@@ -7,20 +7,20 @@ import (
"testing"
)
func TestOsErrorToErrno(t *testing.T) {
errNo := OsErrorToErrno(os.EPERM)
func TestToStatus(t *testing.T) {
errNo := ToStatus(os.EPERM)
if errNo != EPERM {
t.Errorf("Wrong conversion %v != %v", errNo, syscall.EPERM)
}
e := os.NewSyscallError("syscall", syscall.EPERM)
errNo = OsErrorToErrno(e)
errNo = ToStatus(e)
if errNo != EPERM {
t.Errorf("Wrong conversion %v != %v", errNo, syscall.EPERM)
}
e = os.Remove("this-file-surely-does-not-exist")
errNo = OsErrorToErrno(e)
errNo = ToStatus(e)
if errNo != ENOENT {
t.Errorf("Wrong conversion %v != %v", errNo, syscall.ENOENT)
}
......
......@@ -40,7 +40,7 @@ func TestMountRename(t *testing.T) {
t.Fatal("mount should succeed")
}
err := os.Rename(ts.mnt+"/mnt", ts.mnt+"/foobar")
if OsErrorToErrno(err) != EBUSY {
if ToStatus(err) != EBUSY {
t.Fatal("rename mount point should fail with EBUSY:", err)
}
ts.pathFs.Unmount("mnt")
......
......@@ -132,7 +132,7 @@ func (me *MountState) readRequest(req *request) Status {
req.startNs = time.Nanoseconds()
}
req.inputBuf = req.inputBuf[0:n]
return OsErrorToErrno(err)
return ToStatus(err)
}
func (me *MountState) recordStats(req *request) {
......@@ -251,7 +251,7 @@ func (me *MountState) write(req *request) Status {
[][]byte{req.outHeaderBytes, req.flatData})
}
return OsErrorToErrno(err)
return ToStatus(err)
}
func (me *MountState) writeInodeNotify(entry *NotifyInvalInodeOut) Status {
......
......@@ -181,13 +181,13 @@ func TestCreationChecks(t *testing.T) {
CheckSuccess(err)
err = os.Symlink(wd+"/store/foo", wd+"/mnt/config/foo")
code := fuse.OsErrorToErrno(err)
code := fuse.ToStatus(err)
if code != fuse.EBUSY {
t.Error("Should return EBUSY", err)
}
err = os.Symlink(wd+"/store/ws2", wd+"/mnt/config/config")
code = fuse.OsErrorToErrno(err)
code = fuse.ToStatus(err)
if code != fuse.EINVAL {
t.Error("Should return EINVAL", err)
}
......
......@@ -410,7 +410,7 @@ func (me *memNode) Create(name string, flags uint32, mode uint32, context *fuse.
f, err := os.Create(n.backing)
if err != nil {
log.Printf("Backing store error %q: %v", n.backing, err)
return nil, nil, nil, fuse.OsErrorToErrno(err)
return nil, nil, nil, fuse.ToStatus(err)
}
me.Inode().AddChild(name, n.Inode())
me.touch()
......@@ -494,7 +494,7 @@ func (me *memNode) Open(flags uint32, context *fuse.Context) (file fuse.File, co
if me.backing != "" {
f, err := os.OpenFile(me.backing, int(flags), 0666)
if err != nil {
return nil, fuse.OsErrorToErrno(err)
return nil, fuse.ToStatus(err)
}
wr := flags&fuse.O_ANYWRITE != 0
if wr {
......@@ -542,7 +542,7 @@ func (me *memNode) Truncate(file fuse.File, size uint64, context *fuse.Context)
me.info.Size = int64(size)
err := os.Truncate(me.backing, int64(size))
me.touch()
return fuse.OsErrorToErrno(err)
return fuse.ToStatus(err)
}
func (me *memNode) Utimens(file fuse.File, atime uint64, mtime uint64, context *fuse.Context) (code fuse.Status) {
......
......@@ -145,7 +145,7 @@ func TestMemUnionFsChown(t *testing.T) {
writeToFile(ro_fn, "a")
err := os.Chown(m_fn, 0, 0)
code := fuse.OsErrorToErrno(err)
code := fuse.ToStatus(err)
if code != fuse.EPERM {
t.Error("Unexpected error code", code, err)
}
......
......@@ -223,7 +223,7 @@ func TestUnionFsChown(t *testing.T) {
writeToFile(ro_fn, "a")
err := os.Chown(m_fn, 0, 0)
code := fuse.OsErrorToErrno(err)
code := fuse.ToStatus(err)
if code != fuse.EPERM {
t.Error("Unexpected error code", code, err)
}
......
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