-
Notifications
You must be signed in to change notification settings - Fork 27
/
mountoptions.go
97 lines (91 loc) · 1.86 KB
/
mountoptions.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"errors"
"strconv"
"strings"
)
type MountOptions struct {
AllowRoot bool
AllowOther bool
DefaultPermissions bool
NoDefaultPermissions bool
ReadOnly bool
ReadWrite bool
ReadWriteDirOps bool
Uid uint32
Gid uint32
Mode uint32
Cookie string
Password string
Username string
AsyncRead bool
NonEmpty bool
MaxConns uint32
MaxIdleConns uint32
SabreDavPartialUpdate bool
}
func parseUInt32(v string, base int, name string, loc *uint32) (err error) {
n, err := strconv.ParseUint(v , base, 32)
if err == nil {
*loc = uint32(n)
}
return
}
func parseMountOptions(n string, sloppy bool) (mo MountOptions, err error) {
if n == "" {
return
}
for _, kv := range strings.Split(n, ",") {
a := strings.SplitN(kv, "=", 2)
v := ""
if len(a) > 1 {
v = a[1]
}
switch a[0] {
case "allow_root":
mo.AllowRoot = true
case "allow_other":
mo.AllowOther = true
case "default_permissions":
mo.DefaultPermissions = true
case "no_default_permissions":
mo.NoDefaultPermissions = true
case "ro":
mo.ReadOnly = true
case "rw":
mo.ReadWrite = true
case "rwdirops":
mo.ReadWriteDirOps = true
case "uid":
err = parseUInt32(v, 10, "uid", &mo.Uid)
case "gid":
err = parseUInt32(v, 10, "gid", &mo.Gid)
case "mode":
err = parseUInt32(v, 8, "mode", &mo.Mode)
case "cookie":
mo.Cookie = v
case "password":
mo.Password = v
case "username":
mo.Username = v
case "async_read":
mo.AsyncRead = true
case "nonempty":
mo.NonEmpty = true
case "maxconns":
err = parseUInt32(v, 10, "maxconns", &mo.MaxConns)
case "maxidleconns":
err = parseUInt32(v, 10, "maxidleconns", &mo.MaxIdleConns)
case "sabredav_partialupdate":
mo.SabreDavPartialUpdate = true
default:
if !sloppy {
err = errors.New(a[0] + ": unknown option")
}
}
if err != nil {
return
}
}
return
}