-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconv.go
74 lines (68 loc) · 1.43 KB
/
conv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"log"
"os"
"syscall"
"github.com/hanwen/go-fuse/fuse"
"github.com/hugelgupf/p9/linux"
"github.com/hugelgupf/p9/p9"
)
func fuseMode(t p9.QIDType) uint32 {
if (t & p9.TypeDir) == p9.TypeDir {
return fuse.S_IFDIR
}
if (t & p9.TypeRegular) == p9.TypeRegular {
return fuse.S_IFREG
}
if (t & p9.TypeLink) == p9.TypeLink {
return fuse.S_IFLNK
}
if (t & p9.TypeSymlink) == p9.TypeSymlink {
return fuse.S_IFLNK
}
log.Panicf("unsupported QID<->FUSE type: %v", t)
return 0
}
func openFlags(flags uint32) p9.OpenFlags {
accessMode := flags & syscall.O_ACCMODE
switch accessMode {
case syscall.O_RDONLY:
return p9.ReadOnly
case syscall.O_WRONLY:
return p9.WriteOnly
case syscall.O_RDWR:
return p9.ReadWrite
default:
log.Panicf("unsupported access mode: %v", accessMode)
return 0
}
}
func sysErrno(err error) syscall.Errno {
log.Println("ERR:", err)
switch err {
case nil:
return syscall.Errno(0)
case os.ErrPermission:
return syscall.EPERM
case os.ErrExist:
return syscall.EEXIST
case os.ErrNotExist:
return syscall.ENOENT
case os.ErrInvalid:
return syscall.EINVAL
}
switch t := err.(type) {
case linux.Errno:
return syscall.Errno(t)
case syscall.Errno:
return t
case *os.SyscallError:
return t.Err.(syscall.Errno)
case *os.PathError:
return sysErrno(t.Err)
case *os.LinkError:
return sysErrno(t.Err)
}
log.Println("!! unsupported error type:", err)
return syscall.EINVAL
}