-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodes.go
65 lines (60 loc) · 1.33 KB
/
modes.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
package ninep
import (
"strings"
)
// 9p Stat mode flags for file meta-information.
const (
ModeDir = 0x80000000
ModeAppend = 0x40000000
ModeExcl = 0x20000000
ModeMount = 0x10000000
ModeAuth = 0x08000000
ModeTmp = 0x04000000
)
// 9P2000.u extensions to 9p Stat mode flags.
const (
ModeUnixDev = 0x00800000
ModeSymlink = 0x00400000
ModeNamedPipe = 0x00200000
ModeSocket = 0x00100000
)
// The read, write and execute bits are stored in the three least
// significant octets of Stat.Mode, for user, group and others.
const (
ModeUserRead = 0400
ModeUserWrite = 0200
ModeUserExec = 0100
ModeGroupRead = 0040
ModeGroupWrite = 0020
ModeGroupExec = 0010
ModeOtherRead = 0004
ModeOtherWrite = 0002
ModeOtherExec = 0001
)
// ModeString builds a "ls" style mode string for the given mode value.
// For example, ModeString(0744) == "-rwxr--r--".
func ModeString(mode uint32) string {
b := strings.Builder{}
for _, s := range []struct {
mask uint32
symbol byte
}{
{ModeDir, 'd'},
{ModeUserRead, 'r'},
{ModeUserWrite, 'w'},
{ModeUserExec, 'x'},
{ModeGroupRead, 'r'},
{ModeGroupWrite, 'w'},
{ModeGroupExec, 'x'},
{ModeOtherRead, 'r'},
{ModeOtherWrite, 'w'},
{ModeOtherExec, 'x'},
} {
if mode&s.mask != 0 {
b.WriteByte(s.symbol)
} else {
b.WriteByte('-')
}
}
return b.String()
}