2 # Common functions for managing exports files
10 # Return a list of all the directories currently being exported
14 open(EXP, $config{exports_file});
18 /(\/\S*)\s*/; push(@rv, $1);
25 # get_exports(directory)
26 # Return an array containing the following for some directory
31 open(EXP, $config{exports_file});
35 if (/(\/\S*)\s+-(.*)/ && $1 eq $_[0]) {
36 # found matching exports with options
40 elsif (/(\/\S*)\s+-(.*)/ && $1 eq $_[0]) {
41 # found matching exports with options
51 # create_export(directory, options)
52 # Add a new exports to the exports file
55 &open_tempfile(EXP, ">> $config{exports_file}");
56 &print_tempfile(EXP, "$_[0] ");
57 if ($_[1]) { &print_tempfile(EXP, "-$_[1]\n"); };
62 # modify_export(old_directory, directory, options)
63 # Modify an existing exports
67 open(EXP, $config{exports_file});
70 &open_tempfile(EXP, "> $config{exports_file}");
72 chop; ($line = $_) =~ s/#.*//g;
73 if ($line =~ /(\/\S+)\s*/ && $1 eq $_[0]) {
74 # found exports to change..
76 &print_tempfile(EXP, "$_[1] ");
77 if ($_[2]) { &print_tempfile(EXP, "-$_[2]\n"); };
80 # leave this line alone
81 &print_tempfile(EXP, "$_\n");
88 # delete_export(directory)
89 # Delete the export for a particular directory
93 open(EXP, $config{exports_file});
96 &open_tempfile(EXP, "> $config{exports_file}");
98 chop; ($line = $_) =~ s/#.*//g;
99 if ($line !~ /(\/\S+)\s*/ || $1 ne $_[0]) {
100 # Leave this line alone
101 &print_tempfile(EXP, "$_\n");
104 &close_tempfile(EXP);
108 # parse_options(string)
109 # Parse a mount options string like rw=foo,nosuid,... into the associative
110 # array %options. Parts with no value are given an empty string as the value
115 foreach $opt (split(/,/, $_[0])) {
116 if ($opt =~ /^([^=]+)=(.*)$/) {
126 # Returns a list of options from the %options array, in the form used in
131 foreach $k (keys %options) {
132 if ($options{$k} eq "") {
136 push(@list, "$k=$options{$k}");
139 return join(',', @list);