2 # Common functions for managing dfstab files
4 BEGIN { push(@INC, ".."); };
7 %access = &get_module_acl();
10 if ($config{'fstypes_file'} && open(TYPES, $config{'fstypes_file'})) {
11 if (<TYPES> =~ /^(\S+)/) {
16 %access = &get_module_acl();
19 # Returns a list of structures containing share details
24 open(DFS, $config{'dfstab_file'});
27 if (/^\s*\S*share\s+(.*)/) {
29 local $share = { 'line' => $lnum,
30 'index' => scalar(@rv) };
32 while($line =~ /\\$/) {
39 $share->{'eline'} = $lnum;
40 if ($line =~ /\s(\/\S+)/) {
43 if ($line =~ /-d\s+"([^"]+)"/) { $share->{'desc'} = $1; }
44 elsif ($line =~ /-d\s+(\S+)/) { $share->{'desc'} = $1; }
45 if ($line =~ /-o\s+"([^"]+)"/) { $share->{'opts'} = $1; }
46 elsif ($line =~ /-o\s+(\S+)/) { $share->{'opts'} = $1; }
47 if ($line =~ /\s-F\s+(\S+)/) { $share->{'type'} = $1; }
48 else { $share->{'type'} = $default_type; }
57 # create_share(&share)
58 # Add a new share to the dfstab file
61 &open_tempfile(DFS, ">> $config{dfstab_file}");
62 &print_tempfile(DFS, &share_line($_[0]),"\n");
66 # modify_share(&share)
67 # Modify an existing share
70 local $lref = &read_file_lines($config{'dfstab_file'});
71 splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1,
80 $s .= " -d \"$_[0]->{'desc'}\"" if ($_[0]->{'desc'});
81 $s .= " -o $_[0]->{'opts'}" if ($_[0]->{'opts'});
82 $s .= " -F $_[0]->{'type'}" if ($_[0]->{'type'} &&
83 $_[0]->{'type'} ne $default_type);
84 $s .= " $_[0]->{'dir'}";
88 # delete_share(&share)
89 # Delete the share for a particular directory
92 local $lref = &read_file_lines($config{'dfstab_file'});
93 splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1);
97 # parse_options(string)
98 # Parse a mount options string like rw=foo,nosuid,... into the associative
99 # array %options. Parts with no value are given an empty string as the value
104 foreach $opt (split(/,/, $_[0])) {
105 if ($opt =~ /^([^=]+)=(.*)$/) {
115 # join_options([&options])
116 # Returns a list of options from the %options array, in the form used in
120 local $o = $_[0] ? $_[0] : \%options;
122 foreach $k (keys %$o) {
123 if ($o->{$k} eq "") {
127 push(@list, "$k=$o->{$k}");
130 return join(',', @list);
133 # apply_configuration()
134 # Apply the NFS configuration, returning undef on success or an error message
136 sub apply_configuration
138 local $temp = &transname();
139 &system_logged("$config{unshare_all_command} >/dev/null 2>&1");
140 &system_logged("$config{share_all_command} >/dev/null 2>$temp");
141 local $why = `/bin/cat $temp`;