2 # Common functions for exports file
4 BEGIN { push(@INC, ".."); };
8 %access = &get_module_acl();
10 # parse_options($options, \%options)
11 # Parse a mount options string like rw=foo,nosuid,... into a associative
12 # options array. Parts with no value are given an empty string as the value
13 # usefull for HPUX and DFS - perhaps for linux, too
17 foreach $opt (split(/,/, $_[0])) {
18 if ($opt =~ /^([^=]+)=(.*)$/) {
28 # join_options(\%options)
29 # Returns a list of options from a options array, in the form used in
31 # usefull for HPUX and DFS - perhaps for linux, too
36 foreach $k (keys %$o) {
37 if ($_[0]->{$k} eq "") {
41 push(@list, "$k=$_[0]->{$k}");
44 return join(',', @list);
47 # create_export(&export)
50 open(EXP, ">>$config{'exports_file'}");
51 print EXP &make_exports_line($_[0]),"\n";
56 # modify_export(&export, &old)
59 local @exps = &list_exports();
60 local @same = grep { $_->{'line'} eq $_[1]->{'line'} } @exps;
61 local $lref = &read_file_lines($config{'exports_file'});
62 if ($_[0]->{'dir'} eq $_[1]->{'dir'} &&
63 $_[0]->{'active'} == $_[1]->{'active'} || @same == 1) {
64 # directory not changed, or on a line of it's own
65 splice(@same, &indexof($_[1],@same), 1, $_[0]);
66 splice(@$lref, $_[1]->{'line'}, $_[1]->{'eline'}-$_[1]->{'line'}+1,
67 &make_exports_line(@same));
70 # move to a line of it's own
71 splice(@same, &indexof($_[1],@same), 1);
72 splice(@$lref, $_[1]->{'line'}, $_[1]->{'eline'}-$_[1]->{'line'}+1,
73 &make_exports_line(@same));
74 push(@$lref, &make_exports_line($_[0]));
80 # delete_export(&export)
81 # Delete an existing export
84 local @exps = &list_exports();
85 local @same = grep { $_ ne $_[0] && $_->{'line'} eq $_[0]->{'line'} } @exps;
86 local $lref = &read_file_lines($config{'exports_file'});
88 # other exports on the same line.. cannot totally delete
89 splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'}-$_[0]->{'line'}+1,
90 &make_exports_line(@same));
91 map { $_->{'line'} = $_->{'eline'} = $_[0]->{'line'} } @same;
95 splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'}-$_[0]->{'line'}+1);
97 @list_exports_cache = grep { $_ ne $_[0] } @list_exports_cache;
102 # check_hosts(option, hostlist)
103 # Die if any of the listed hosts does not exist
104 # or no hosts listed for specified option
107 local @h = split(/\s+/, $_[1]);
110 &error(&text('save_enohost', $_[0]));
114 if (!&to_ipaddress($_)) { &error(&text('save_ehost', $_, $_[0])); }
120 return !&has_command("rpc.nfsd") && !&has_command("nfsd") &&
121 !&has_command("rpc.knfsd") ? 0 : 1;