-
Notifications
You must be signed in to change notification settings - Fork 12
/
Options.ycp
120 lines (102 loc) · 4.4 KB
/
Options.ycp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{
module "Nfs::Options";
textdomain "nfs";
/**
* Checks the nfs options for /etc/fstab:
* nonempty, comma separated list of foo,nofoo,bar=baz (see nfs(5))
* @param options options
* @return a translated string with error message, emtpy string if ok
*/
global define string validate (string options) {
// To translators: error popup
if (size (options) == 0) return _("Empty option strings are not allowed.");
if (options == "defaults") return "";
list<string> option_list = splitstring (options, ",");
// The options should be kept synced with the code that handles them,
// which is not an easy task, as there are many places:
// - util-linux.rpm
// man 8 mount
// https://git.kernel.org/?p=utils/util-linux/util-linux.git;a=history;f=libmount/src/optmap.c
// - nfs-client.rpm (nfs-utils.src.rpm)
// man 5 nfs
// http://git.linux-nfs.org/?p=steved/nfs-utils.git;a=history;f=utils/mount/nfsmount.c
// - kernel: fs/nfs/super.c
// http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=history;f=fs/nfs/super.c
// Note that minorversion in particular is mentioned only in the kernel
// but not in nfs-utils. WTF.
// these can be negated by "no"
list<string> non_value = ["bg", "fg", "soft", "hard", "intr", "posix", "cto", "ac", "acl",
"lock", "tcp", "udp", "rdirplus",
// these are common for all fs types
"atime", "auto", "dev", "exec", "group", "owner",
"suid", "user", "users"];
// these cannot be negated
// they are not nfs specific BTW
list non_value1 = ["defaults", "async", "sync", "dirsync", "ro", "rw",
"remount", "bind", "rbind", "_netdev", ];
list with_value = ["rsize", "wsize", "timeo", "retrans", "acregmin", "acregmax",
"acdirmin", "acdirmin", "acdirmax", "actimeo", "retry", "namlen",
"port", "proto", "clientaddr", "mountport", "mounthost",
"mountprog", "mountvers", "nfsprog", "nfsvers", "vers", "minorversion",
"sec" ];
integer i = 0;
string current_option = "";
// first fiter out non value options and its nooptions forms (see nfs(5))
option_list = filter (string e, option_list, ``(!contains (non_value, e)));
non_value = maplist (string e, non_value, ``(sformat ("no%1", e)));
option_list = filter (string e, option_list, ``(!contains (non_value, e)));
option_list = filter (string e, option_list, ``(!contains (non_value1, e)));
while (i < size (option_list))
{
string opt = option_list[i]:"";
list<string> value = splitstring (opt, "=");
string v0 = value[0]:"";
string v1 = value[1]:"";
// FIXME: this also triggers for "intr=bogus"
// To translators: error popup
if (!contains (with_value, v0)) return sformat (_("Unknown option: %1"), v0);
// To translators: error popup
if (size (value) != 2) return sformat (_("Invalid option: %1"), opt);
// To translators: error popup
if (v1 == "") return sformat (_("Empty value for option: %1"), v0);
i = i + 1;
}
return "";
}
/**
FIXME: factor out get_nfs4(vfstype, options) (depending on n::o)!
* @param options fstab option string
* @return is version >= 4.1 enabled
*/
global boolean get_nfs41(string options) {
list<string> option_list = splitstring (options, ",");
const string ENABLED = "minorversion=1";
return contains(option_list, ENABLED);
}
/**
* Add or remove minorversion=1 according to nfs41.
* FIXME vfstype=nfs4 is deprecated in favor of nfsvers=4 (aka vers=4)
* @param options fstab option string
* @param nfs41 is version >= 4.1 enabled
* @return new fstab option string
*/
global define string set_nfs41(string options, boolean nfs41) {
// don't mutate the string unnecessarily
if (get_nfs41(options) == nfs41) {
return options;
}
const string ENABLED = "minorversion=1";
const string DISABLED = "minorversion=0";
if (options == "defaults") { options = ""; }
list<string> option_list = splitstring(options, ",");
option_list = filter(string opt, option_list, ``( opt != ENABLED ));
option_list = filter(string opt, option_list, ``( opt != DISABLED ));
if (nfs41) {
option_list = add(option_list, ENABLED);
}
options = mergestring(option_list, ",");
if (options == "") { options = "defaults"; }
return options;
}
/*EOF*/
}