Handle hostnames with upper-case letters
[webmin.git] / mount / solaris-lib.pl
1 # solaris-lib.pl
2 # Filesystem functions for Solaris (works for me on 2.5)
3
4 $smbmount = &has_command("rumba") ? "rumba" :
5             &has_command("shlight") ? "shlight" : undef;
6
7 # Return information about a filesystem, in the form:
8 #  directory, device, type, options, fsck_order, mount_at_boot
9 # If a field is unused or ignored, a - appears instead of the value.
10 # Swap-filesystems (devices or files mounted for VM) have a type of 'swap',
11 # and 'swap' in the directory field
12 sub list_mounts
13 {
14 return @list_mounts_cache if (@list_mounts_cache);
15 local(@rv, @p, $_, $i); $i = 0;
16
17 # List normal filesystem mounts
18 open(FSTAB, $config{fstab_file});
19 while(<FSTAB>) {
20         chop; s/#.*$//g;
21         if (!/\S/) { next; }
22         @p = split(/\s+/, $_);
23         if ($p[3] eq "swap") { $p[2] = "swap"; }
24         if ($p[3] eq "proc") { $p[0] = "proc"; }
25         $rv[$i++] = [ $p[2], $p[0], $p[3], $p[6], $p[4], $p[5] ];
26         }
27 close(FSTAB);
28
29 # List automount points
30 open(AUTOTAB, $config{autofs_file});
31 while(<AUTOTAB>) {
32         chop; s/#.*$//g;
33         if (!/\S/ || /^[+\-]/) { next; }
34         @p = split(/\s+/, $_);
35         if ($p[2] eq "") { $p[2] = "-"; }
36         else { $p[2] =~ s/^-//g; }
37         $rv[$i++] = [ $p[0], $p[1], "autofs", $p[2], "-", "yes" ];
38         }
39 close(AUTOTAB);
40
41 @list_mounts_cache = @rv;
42 return @rv;
43 }
44
45
46 # create_mount(directory, device, type, options, fsck_order, mount_at_boot)
47 # Add a new entry to the fstab file, and return the index of the new entry
48 sub create_mount
49 {
50 local($len, @mlist, $fcsk, $dir);
51 if ($_[2] eq "autofs") {
52         # An autofs mount.. add to /etc/auto_master
53         $len = grep { $_->[2] eq "autofs" } (&list_mounts());
54         &open_tempfile(AUTOTAB, ">> $config{autofs_file}");
55         &print_tempfile(AUTOTAB, "$_[0] $_[1]",($_[3] eq "-" ? "" : " -$_[3]"),"\n");
56         &close_tempfile(AUTOTAB);
57         }
58 else {
59         # Add to the fstab file
60         $len = grep { $_->[2] ne "autofs" } (&list_mounts());
61         &open_tempfile(FSTAB, ">> $config{fstab_file}");
62         if ($_[2] eq "ufs" || $_[2] eq "s5fs") {
63                 ($fsck = $_[1]) =~ s/\/dsk\//\/rdsk\//g;
64                 }
65         else { $fsck = "-"; }
66         if ($_[2] eq "swap") { $dir = "-"; }
67         else { $dir = $_[0]; }
68         &print_tempfile(FSTAB, "$_[1]  $fsck  $dir  $_[2]  $_[4]  $_[5]  $_[3]\n");
69         &close_tempfile(FSTAB);
70         }
71 undef(@list_mounts_cache);
72 return $len;
73 }
74
75
76 # delete_mount(index)
77 # Delete some mount from the table
78 sub delete_mount
79 {
80 local(@fstab, $i, $line, $_);
81 open(FSTAB, $config{fstab_file});
82 @fstab = <FSTAB>;
83 close(FSTAB);
84 $i = 0;
85
86 &open_tempfile(FSTAB, "> $config{fstab_file}");
87 foreach (@fstab) {
88         chop; ($line = $_) =~ s/#.*$//g;
89         if ($line =~ /\S/ && $i++ == $_[0]) {
90                 # found the line not to include
91                 }
92         else { &print_tempfile(FSTAB, $_,"\n"); }
93         }
94 &close_tempfile(FSTAB);
95
96 open(AUTOTAB, $config{autofs_file});
97 @autotab = <AUTOTAB>;
98 close(AUTOTAB);
99 &open_tempfile(AUTOTAB, "> $config{autofs_file}");
100 foreach (@autotab) {
101         chop; ($line = $_) =~ s/#.*$//g;
102         if ($line =~ /\S/ && $line !~ /^[+\-]/ && $i++ == $_[0]) {
103                 # found line not to include..
104                 }
105         else { &print_tempfile(AUTOTAB, $_,"\n"); }
106         }
107 &close_tempfile(AUTOTAB);
108 undef(@list_mounts_cache);
109 }
110
111
112 # change_mount(num, directory, device, type, options, fsck_order, mount_at_boot)
113 # Change an existing permanent mount
114 sub change_mount
115 {
116 local(@fstab, @autotab, $i, $line, $fsck, $dir, $_);
117 $i = 0;
118
119 open(FSTAB, $config{fstab_file});
120 @fstab = <FSTAB>;
121 close(FSTAB);
122 &open_tempfile(FSTAB, "> $config{fstab_file}");
123 foreach (@fstab) {
124         chop; ($line = $_) =~ s/#.*$//g;
125         if ($line =~ /\S/ && $i++ == $_[0]) {
126                 # Found the line to replace
127                 if ($_[3] eq "ufs" || $_[3] eq "s5fs") {
128                         ($fsck = $_[2]) =~ s/\/dsk\//\/rdsk\//g;
129                         }
130                 else { $fsck = "-"; }
131                 if ($_[3] eq "swap") { $dir = "-"; }
132                 else { $dir = $_[1]; }
133                 &print_tempfile(FSTAB, "$_[2]  $fsck  $dir  $_[3]  $_[5]  $_[6]  $_[4]\n");
134                 }
135         else { &print_tempfile(FSTAB, $_,"\n"); }
136         }
137 &close_tempfile(FSTAB);
138
139 open(AUTOTAB, $config{autofs_file});
140 @autotab = <AUTOTAB>;
141 close(AUTOTAB);
142 &open_tempfile(AUTOTAB, "> $config{autofs_file}");
143 foreach (@autotab) {
144         chop; ($line = $_) =~ s/#.*$//g;
145         if ($line =~ /\S/ && $line !~ /^[+\-]/ && $i++ == $_[0]) {
146                 # Found the line to replace
147                 &print_tempfile(AUTOTAB, "$_[1]  $_[2]  ",
148                                 ($_[4] eq "-" ? "" : "-$_[4]"),"\n");
149                 }
150         else { &print_tempfile(AUTOTAB, $_,"\n"); }
151         }
152 &close_tempfile(AUTOTAB);
153 undef(@list_mounts_cache);
154 }
155
156
157 # list_mounted()
158 # Return a list of all the currently mounted filesystems and swap files.
159 # The list is in the form:
160 #  directory device type options
161 # For swap files, the directory will be 'swap'
162 sub list_mounted
163 {
164 return @list_mounted_cache if (@list_mounted_cache);
165 local(@rv, @p, $_, $i, $r);
166 &open_execute_command(SWAP, "swap -l 2>/dev/null", 1, 1);
167 while(<SWAP>) {
168         if (/^(\/\S+)\s+/) { push(@rv, [ "swap", $1, "swap", "-" ]); }
169         }
170 close(SWAP);
171 &open_tempfile(MNTTAB, "/etc/mnttab");
172 while(<MNTTAB>) {
173         s/#.*$//g; if (!/\S/) { next; }
174         @p = split(/\s+/, $_);
175         if ($p[0] =~ /:vold/) { next; }
176         if ($p[0] =~ /^(rumba|shlight)-(\d+)$/) {
177                 # rumba smb mount
178                 local($args, $ps); $p[3] = "pid=$2";
179                 $ps = (-x "/usr/ucb/ps") ? "/usr/ucb/ps auwwwwx $2"
180                                          : "ps -o args -f $2";
181                 &backquote_command($ps, 1) =~ /(rumba|shlight)\s+\/\/([^\/]+)\/(.*\S)\s+(\/\S+)(.*)/ || next;
182                 $serv = $2; $shar = $3; $p[2] = "rumba"; $args = $5;
183                 if ($args =~ /\s+-s\s+(\S+)/ && $1 ne $serv) {
184                         $p[0] = "\\\\$1\\$shar";
185                         $p[3] .= ",machinename=$serv";
186                         }
187                 else { $p[0] = "\\\\$serv\\$shar"; }
188                 if ($args =~ /\s+-c\s+(\S+)/) { $p[3] .= ",clientname=$1"; }
189                 if ($args =~ /\s+-U\s+(\S+)/) { $p[3] .= ",username=$1"; }
190                 if ($args =~ /\s+-u\s+(\S+)/) { $p[3] .= ",uid=$1"; }
191                 if ($args =~ /\s+-g\s+(\S+)/) { $p[3] .= ",gid=$1"; }
192                 if ($args =~ /\s+-f\s+(\S+)/) { $p[3] .= ",fmode=$1"; }
193                 if ($args =~ /\s+-d\s+(\S+)/) { $p[3] .= ",dmode=$1"; }
194                 if ($args =~ /\s+-C/) { $p[3] .= ",noupper"; }
195                 if ($args =~ /\s+-P\s+(\S+)/) { $p[3] .= ",password=$1"; }
196                 if ($args =~ /\s+-S/) { $p[3] .= ",readwrite"; }
197                 if ($args =~ /\s+-w/) { $p[3] .= ",readonly"; }
198                 if ($args =~ /\s+-e/) { $p[3] .= ",attr"; }
199                 }
200         else { $p[3] = join(',' , (grep {!/^dev=/} split(/,/ , $p[3]))); }
201         push(@rv, [ $p[1], $p[0], $p[2], $p[3] ]);
202         }
203 &close_tempfile(MNTTAB);
204 foreach $r (@rv) {
205         if ($r->[2] eq "cachefs" && $r->[1] =~ /\.cfs_mnt_points/) {
206                 # Oh no.. a caching filesystem mount. Fiddle things so that
207                 # it looks right.
208                 for($i=0; $i<@rv; $i++) {
209                         if ($rv[$i]->[0] eq $r->[1]) {
210                                 # Found the automatically mounted entry. lose it
211                                 $r->[1] = $rv[$i]->[1];
212                                 splice(@rv, $i, 1);
213                                 last;
214                                 }
215                         }
216                 }
217         }
218 @list_mounted_cache = @rv;
219 return @rv;
220 }
221
222
223 # mount_dir(directory, device, type, options)
224 # Mount a new directory from some device, with some options. Returns 0 if ok,
225 # or an error string if failed. If the directory is 'swap', then mount as
226 # virtual memory.
227 sub mount_dir
228 {
229 local($out, $opts);
230 if ($_[0] eq "swap") {
231         # Adding a swap device
232         $out = &backquote_logged("swap -a $_[1] 2>&1");
233         if ($?) { return $out; }
234         }
235 else {
236         # Mounting a directory
237         if ($_[2] eq "cachefs") {
238                 # Mounting a caching filesystem.. need to create cache first
239                 local(%options);
240                 &parse_options("cachefs", $_[3]);
241                 if (!(-r "$options{cachedir}/.cfs_resource")) {
242                         # The cache directory does not exist.. set it up
243                         if (-d $options{cachedir} &&
244                             !rmdir($options{"cachedir"})) {
245                                 return &text('solaris_ecacheexists',
246                                              $options{'cachedir'});
247                                 }
248                         $out = &backquote_logged("cfsadmin -c $options{cachedir} 2>&1");
249                         if ($?) { return $out; }
250                         }
251                 }
252         if ($_[2] eq "rumba") {
253                 # call 'rumba' to mount
254                 local(%options, $shortname, $shar, $opts, $rv);
255                 &parse_options("rumba", $_[3]);
256                 $shortname = &get_system_hostname();
257                 if ($shortname =~ /^([^\.]+)\.(.+)$/) { $shortname = $1; }
258                 $_[1] =~ /^\\\\(.+)\\(.+)$/;
259                 $shar = "//".($options{machinename} ?$options{machinename} :$1).
260                         "/$2";
261                 $opts = ("-s $1 ").
262                  (defined($options{'clientname'}) ?
263                         "-c $options{'clientname'} " : "-c $shortname ").
264                  (defined($options{'username'}) ?
265                         "-U $options{'username'} " : "").
266                  (defined($options{'uid'}) ? "-u $options{'uid'} " : "").
267                  (defined($options{'gid'}) ? "-g $options{'gid'} " : "").
268                  (defined($options{'fmode'}) ? "-f $options{'fmode'} " : "").
269                  (defined($options{'dmode'}) ? "-d $options{'dmode'} " : "").
270                  (defined($options{'noupper'}) ? "-C " : "").
271                  (defined($options{'password'}) ?
272                         "-P $options{'password'} " : "-n ").
273                  (defined($options{'readwrite'}) ? "-S " : "").
274                  (defined($options{'readonly'}) ? "-w " : "").
275                  (defined($options{'attr'}) ? "-e " : "");
276                 local $rtemp = &transname();
277                 $rv = &system_logged("rumba \"$shar\" $_[0] $opts >$rtemp 2>&1 </dev/null");
278                 $out = `cat $rtemp`; unlink($rtemp);
279                 if ($rv) { return "<pre>$out</pre> : rumba \"$shar\" $_[0] $opts"; }
280                 }
281         else {
282                 $opts = $_[3] eq "-" ? "" : "-o \"$_[3]\"";
283                 $out = &backquote_logged("mount -F $_[2] $opts -- $_[1] $_[0] 2>&1");
284                 if ($?) { return $out; }
285                 }
286         }
287 undef(@list_mounted_cache);
288 return 0;
289 }
290
291
292 # unmount_dir(directory, device, type)
293 # Unmount a directory (or swap device) that is currently mounted. Returns 0 if
294 # ok, or an error string if failed
295 sub unmount_dir
296 {
297 if ($_[0] eq "swap") {
298         $out = &backquote_logged("swap -d $_[1] 2>&1");
299         }
300 elsif ($_[2] eq "rumba") {
301         # kill the process (if nobody is in the directory)
302         $dir = $_[0];
303         if (&backquote_command("fuser -c $_[0] 2>/dev/null", 1) =~ /\d/) {
304                 return &text('solaris_ebusy', $_[0]);
305                 }
306         if (&backquote_command("cat /etc/mnttab", 1) =~
307             /(rumba|shlight)-(\d+)\s+$dir\s+nfs/) {
308                 &kill_logged('TERM', $2) || return $text{'solaris_ekill'};
309                 }
310         else {
311                 return $text{'solaris_epid'};
312                 }
313         sleep(1);
314         }
315 else {
316         $out = &backquote_logged("umount $_[0] 2>&1");
317         }
318 undef(@list_mounted_cache);
319 if ($?) { return $out; }
320 return 0;
321 }
322
323
324 # disk_space(type, directory)
325 # Returns the amount of total and free space for some filesystem, or an
326 # empty array if not appropriate.
327 sub disk_space
328 {
329 if (&get_mounted($_[1], "*") < 0) { return (); }
330 if ($_[0] eq "fd" || $_[0] eq "proc" || $_[0] eq "swap" || $_[0] eq "autofs") {
331         return ();
332         }
333 if (&backquote_command("df -k ".quotemeta($_[1]), 1) =~
334     /Mounted on\n\S+\s+(\S+)\s+(\S+)\s+(\S+)/) {
335         if ($1 == 0) {
336                 # Size is sometimes zero on Solaris? Fake it..
337                 return ($2+$3, $3);
338                 }
339         else {
340                 return ($1, $3);
341                 }
342         }
343 return ( );
344 }
345
346
347 # list_fstypes()
348 # Returns an array of all the supported filesystem types. If a filesystem is
349 # found that is not one of the supported types, generate_location() and
350 # generate_options() will not be called for it.
351 sub list_fstypes
352 {
353 local @fs = ("ufs", "nfs", "hsfs", "pcfs", "lofs", "cachefs",
354              "swap", "tmpfs", "autofs");
355 if (&running_in_zone()) {
356         # Only the filesystems are available in zones
357         @fs = ( "tmpfs", "autofs", "nfs" );
358         }
359 push(@fs, $smbmount) if ($smbmount);
360 push(@fs, "udfs") if ($gconfig{'os_version'} >= 8);
361 push(@fs, "xmemfs") if ($gconfig{'os_version'} >= 8 &&
362                         $gconfig{'os_version'} <= 10);
363 return @fs;
364 }
365
366
367 # fstype_name(type)
368 # Given a short filesystem type, return a human-readable name for it
369 sub fstype_name
370 {
371 local(%fsmap);
372 %fsmap = ("ufs","Solaris Unix Filesystem",
373           "nfs","Network Filesystem",
374           "hsfs","ISO9660 CD-ROM",
375           "pcfs","MS-DOS Filesystem",
376           "lofs","Loopback Filesystem",
377           "cachefs","Caching Filesystem",
378           "swap","Virtual Memory",
379           "tmpfs","RAM Disk",
380           "xmemfs","Large RAM Disk",
381           "autofs","Automounter Filesystem",
382           "proc","Process Image Filesystem",
383           "fd","File Descriptor Filesystem",
384           "mntfs","Filesystems List",
385           "udfs","DVD Filesystem",
386           "rumba","Windows Networking Filesystem");
387 return $config{long_fstypes} && $fsmap{$_[0]} ? $fsmap{$_[0]} : uc($_[0]);
388 }
389
390
391 # mount_modes(type)
392 # Given a filesystem type, returns 4 numbers that determine how the file
393 # system can be mounted, and whether it can be fsck'd
394 sub mount_modes
395 {
396 if ($_[0] eq "ufs" || $_[0] eq "cachefs" || $_[0] eq "s5fs") {
397         return (2, 1, 1, 0);
398         }
399 elsif ($_[0] eq "rumba") { return (0, 1, 0, 0); }
400 else { return (2, 1, 0, 0); }
401 }
402
403
404 # multiple_mount(type)
405 # Returns 1 if filesystems of this type can be mounted multiple times, 0 if not
406 sub multiple_mount
407 {
408 return ($_[0] eq "nfs" || $_[0] eq "tmpfs" || $_[0] eq "cachefs" ||
409         $_[0] eq "autofs" || $_[0] eq "lofs" || $_[0] eq "rumba" || $_[0] eq "xmemfs");
410 }
411
412
413 # generate_location(type, location)
414 # Output HTML for editing the mount location of some filesystem.
415 sub generate_location
416 {
417 if ($_[0] eq "nfs") {
418         # NFS mount from some host and directory
419         if ($_[1] =~ /^nfs:/) { $nfsmode = 2; }
420         elsif (!$_[1] || $_[1] =~ /^([A-z0-9\-\.]+):([^,]+)$/) {
421                 $nfsmode = 0; $nfshost = $1; $nfspath = $2;
422                 }
423         else { $nfsmode = 1; }
424         if ($gconfig{'os_version'} >= 2.6) {
425                 # Solaris 2.6 can list multiple NFS servers in mount
426                 print "<tr> <td><b>$text{'solaris_nsource'}</b></td>\n";
427                 printf "<td><input type=radio name=nfs_serv value=0 %s>\n",
428                         $nfsmode == 0 ? "checked" : "";
429                 print "<b>$text{'solaris_nhost'}</b></td>\n";
430                 print "<td><input name=nfs_host size=20 value=\"$nfshost\">\n";
431                 &nfs_server_chooser_button("nfs_host");
432                 print "&nbsp;<b>$text{'solaris_ndir'}</b>\n";
433                 print "<input name=nfs_dir size=20 value=\"$nfspath\">\n";
434                 &nfs_export_chooser_button("nfs_host", "nfs_dir");
435                 print "</td> </tr>\n";
436
437                 print "<tr> <td></td>\n";
438                 printf "<td><input type=radio name=nfs_serv value=1 %s>\n",
439                         $nfsmode == 1 ? "checked" : "";
440                 print "<b>$text{'solaris_nmult'}</b></td>\n";
441                 printf "<td><input name=nfs_list size=40 value=\"%s\">\n",
442                         $nfsmode == 1 ? $_[1] : "";
443                 print "</td> </tr>\n";
444
445                 if ($gconfig{'os_version'} >= 7) {
446                         print "<tr> <td></td> <td>\n";
447                         printf "<input type=radio name=nfs_serv value=2 %s>\n",
448                                 $nfsmode == 2 ? "checked" : "";
449                         print "<b>$text{'solaris_webnfs'}</b></td> <td>\n";
450                         printf "<input name=nfs_url size=40 value=\"%s\">\n",
451                                 $nfsmode == 2 ? $_[1] : "";
452                         print "</td> </tr>\n";
453                         }
454                 }
455         else {
456                 print "<tr> <td><b>$text{'solaris_nhost'}</b></td>\n";
457                 print "<td><input name=nfs_host size=20 value=\"$nfshost\">\n";
458                 &nfs_server_chooser_button("nfs_host");
459                 print "</td>\n";
460                 print "<td><b>$text{'solaris_ndir'}</b></td>\n";
461                 print "<td><input name=nfs_dir size=20 value=\"$nfspath\">\n";
462                 &nfs_export_chooser_button("nfs_host", "nfs_dir");
463                 print "</td> </tr>\n";
464                 }
465         }
466 elsif ($_[0] eq "tmpfs" || $_[0] eq "xmemfs") {
467         # Location is irrelevant for tmpfs and xmemfs filesystems
468         }
469 elsif ($_[0] eq "ufs") {
470         # Mounted from a normal disk, raid (MD) device or from
471         # somewhere else
472         print "<tr> <td valign=top><b>$text{'solaris_ufs'}</b></td>\n";
473         print "<td colspan=3>\n";
474         &foreign_require("format");
475
476         if ($_[1] =~ /^\/dev\/dsk\/c([0-9]+)t([0-9]+)d([0-9]+)s([0-9]+)$/ ||
477             $_[1] =~ /^\/dev\/dsk\/c([0-9]+)d([0-9]+)s([0-9]+)$/) {
478                 $ufs_dev = 0;
479                 }
480         elsif ($_[1] eq "") {
481                 $ufs_dev = 0;
482                 }
483         elsif ($_[1] =~ /^\/dev\/md\/dsk\/d([0-9]+)$/) {
484                 $ufs_dev = 1;
485                 }
486         else {
487                 $ufs_dev = 2;
488                 }
489
490         local $found;
491         local $sel = &format::partition_select("ufs_disk", $_[1], 0,
492                                                $ufs_dev ? \$found : undef);
493         printf "<input type=radio name=ufs_dev value=0 %s> %s : %s<br>\n",
494                 $ufs_dev == 0 ? "checked" : "", $text{'solaris_scsi'}, $sel;
495
496         printf "<input type=radio name=ufs_dev value=1 %s> %s :\n",
497                 $ufs_dev == 1 ? "checked" : "",
498                 $text{'solaris_raid'};
499         printf "%s <input name=ufs_md size=3 value=\"%s\"><br>\n",
500                 $text{'solaris_unit'},
501                  $_[1] =~ /^\/dev\/md\/dsk\/d([0-9]+)$/ ? $1 : "";
502
503         printf "<input type=radio name=ufs_dev value=2 %s> %s :\n",
504                 $ufs_dev == 2 ? "checked" : "", $text{'solaris_otherdev'};
505         printf "<input name=ufs_path size=20 value=\"%s\"><br>\n",
506                 $ufs_dev == 2 ? $_[1] : "";
507         print "</td> </tr>\n";
508         }
509 elsif ($_[0] eq "swap") {
510         # Swapping to a disk partition or a file
511         print "<tr> <td valign=top><b>$text{'solaris_swapfile'}</b></td>\n";
512         print "<td colspan=3>\n";
513         &foreign_require("format");
514
515         if ($_[1] =~ /^\/dev\/dsk\/c([0-9]+)t([0-9]+)d([0-9]+)s([0-9]+)$/ ||
516             $_[1] =~ /^\/dev\/dsk\/c([0-9]+)d([0-9]+)s([0-9]+)$/) {
517                 $swap_dev = 0;
518                 }
519         elsif ($_[1] eq "") {
520                 $swap_dev = 0;
521                 }
522         else {
523                 $swap_dev = 1;
524                 }
525
526         local $found;
527         local $sel = &format::partition_select("swap_disk", $_[1], 0,
528                                                $swap_dev ? \$found : undef);
529         printf "<input type=radio name=swap_dev value=0 %s> %s : %s<br>\n",
530                 $swap_dev == 0 ? "checked" : "", $text{'solaris_scsi'}, $sel;
531
532         printf "<input type=radio name=swap_dev value=1 %s> %s :\n",
533                 $swap_dev == 1 ? "checked" : "", $text{'solaris_file'};
534         printf "<input name=swap_path size=20 value=\"%s\"><br>\n",
535                 $swap_dev == 1 ? $_[1] : "";
536         print "</td> </tr>\n";
537         }
538 elsif ($_[0] eq "hsfs" || $_[0] eq "udfs") {
539         # Mounting a SCSI cdrom or DVD
540         if ($_[0] eq "hsfs") {
541                 print "<tr> <td valign=top><b>$text{'solaris_cdrom'}</b></td>\n";
542                 }
543         else {
544                 print "<tr> <td valign=top><b>$text{'solaris_dvd'}</b></td>\n";
545                 }
546         print "<td colspan=3>\n";
547         if ($_[1] =~ /^\/dev\/dsk\/c([0-9]+)t([0-9]+)d([0-9]+)s([0-9]+)$/) {
548                 $hsfs_dev = 0;
549                 $scsi_c = $1; $scsi_t = $2; $scsi_d = $3; $scsi_s = $4;
550                 }
551         elsif ($_[1] eq "") {
552                 $hsfs_dev = 0;
553                 $scsi_c = 0; $scsi_t = 6; $scsi_d = 0; $scsi_s = 0;
554                 }
555         else {
556                 $hsfs_dev = 2; $scsi_path = $_[1];
557                 }
558         printf "<input type=radio name=ufs_dev value=0 %s> $text{'solaris_scsi'}:\n",
559                 $hsfs_dev == 0 ? "checked" : "";
560         print "$text{'solaris_ctrlr'} <input name=ufs_c size=3 value=\"$scsi_c\">\n";
561         print "$text{'solaris_target'} <input name=ufs_t size=3 value=\"$scsi_t\">\n";
562         print "$text{'solaris_unit'} <input name=ufs_d size=3 value=\"$scsi_d\">\n";
563         print "$text{'solaris_part'} <input name=ufs_s size=3 value=\"$scsi_s\"><br>\n";
564
565         printf "<input type=radio name=ufs_dev value=2 %s> $text{'solaris_otherdev'}:\n",
566                 $hsfs_dev == 2 ? "checked" : "";
567         print "<input name=ufs_path size=20 value=\"$scsi_path\"><br>\n";
568         print "</td> </tr>\n";
569         }
570 elsif ($_[0] eq "pcfs") {
571         # Mounting a SCSI msdos filesystem
572         print "<tr> <td valign=top><b>$text{'solaris_msdos'}</b></td>\n";
573         print "<td colspan=3>\n";
574         &foreign_require("format");
575
576         if ($_[1] =~ /^\/dev\/dsk\/c([0-9]+)t([0-9]+)d([0-9]+)s([0-9]+)$/ ||
577             $_[1] =~ /^\/dev\/dsk\/c([0-9]+)d([0-9]+)s([0-9]+)$/) {
578                 $pcfs_dev = 0;
579                 }
580         elsif ($_[1] eq "") {
581                 $pcfs_dev = 0;
582                 }
583         else {
584                 $pcfs_dev = 2;
585                 }
586
587         local $found;
588         local $sel = &format::partition_select("ufs_disk", $_[1], 0,
589                                                $pcfs_dev ? \$found : undef);
590         printf "<input type=radio name=ufs_dev value=0 %s> %s : %s<br>\n",
591                 $pcfs_dev == 0 ? "checked" : "", $text{'solaris_scsi'}, $sel;
592
593         printf "<input type=radio name=ufs_dev value=2 %s> %s :\n",
594                 $pcfs_dev == 2 ? "checked" : "", $text{'solaris_file'};
595         printf "<input name=ufs_path size=20 value=\"%s\"><br>\n",
596                 $pcfs_dev == 2 ? $_[1] : "";
597         print "</td> </tr>\n";
598         }
599 elsif ($_[0] eq "lofs") {
600         # Mounting some directory to another location
601         print "<tr> <td><b>$text{'solaris_orig'}</b></td>\n";
602         print "<td><input name=lofs_src size=30 value=\"$_[1]\">\n";
603         print &file_chooser_button("lofs_src", 1);
604         print "</td> </tr>\n";
605         }
606 elsif ($_[0] eq "cachefs") {
607         # Mounting a cached filesystem of some type.. need a location for
608         # the source of the mount
609         print "<tr> <td><b>$text{'solaris_cache'}</b></td>\n";
610         print "<td><input name=cfs_src size=20 value=\"$_[1]\"></td> </tr>\n";
611         }
612 elsif ($_[0] eq "autofs") {
613         # An automounter entry.. can be -hosts, -xfn or from some mapping
614         print "<tr> <td valign=top><b>$text{'solaris_automap'}</b></td>\n";
615         printf "<td><input type=radio name=autofs_type value=0 %s>\n",
616                 $_[1] eq "-hosts" || $_[1] eq "-xfn" ? "" : "checked";
617         printf "Use map <input name=autofs_map size=20 value=\"%s\"><br>\n",
618                 $_[1] eq "-hosts" || $_[1] eq "-xfn" ? "" : $_[1];
619         printf "<input type=radio name=autofs_type value=1 %s>\n",
620                 $_[1] eq "-hosts" ? "checked" : "";
621         print "$text{'solaris_autohosts'}<br>\n";
622         printf "<input type=radio name=autofs_type value=2 %s>\n",
623                 $_[1] eq "-xfn" ? "checked" : "";
624         print "$text{'solaris_autoxfn'}</td> </tr>\n";
625         }
626 elsif ($_[0] eq "rumba") {
627         # Windows filesystem
628         $_[1] =~ /^\\\\(.*)\\(.*)$/;
629         print "<tr> <td><b>$text{'solaris_server'}</b></td>\n";
630         print "<td><input name=rumba_server value=\"$1\" size=20>\n";
631         &smb_server_chooser_button("rumba_server");
632         print "</td>\n";
633         print "<td><b>$text{'solaris_share'}</b></td>\n";
634         print "<td><input name=rumba_share value=\"$2\" size=20>\n";
635         &smb_share_chooser_button("rumba_server", "rumba_share");
636         print "</td> </tr>\n";
637         }
638 }
639
640
641 # generate_options(type, newmount)
642 # Output HTML for editing mount options for a partilcar filesystem 
643 # under this OS
644 sub generate_options
645 {
646 if ($_[0] eq "nfs") {
647         # Solaris NFS has many options, not all of which are editable here
648         print "<tr> <td><b>$text{'solaris_ro'}</b></td>\n";
649         printf "<td nowrap><input type=radio name=nfs_ro value=1 %s> $text{'yes'}\n",
650                 defined($options{"ro"}) ? "checked" : "";
651         printf "<input type=radio name=nfs_ro value=0 %s> $text{'no'}</td>\n",
652                 defined($options{"ro"}) ? "" : "checked";
653
654         print "<td><b>$text{'solaris_nosuid'}</b></td>\n";
655         printf "<td nowrap><input type=radio name=nfs_nosuid value=1 %s> $text{'yes'}\n",
656                 defined($options{"nosuid"}) ? "checked" : "";
657         printf "<input type=radio name=nfs_nosuid value=0 %s> $text{'no'}</td> </tr>\n",
658                 defined($options{"nosuid"}) ? "" : "checked";
659
660         print "<tr> <td><b>$text{'solaris_grpid'}</b></td>\n";
661         printf "<td nowrap><input type=radio name=nfs_grpid value=0 %s> $text{'yes'}\n",
662                 defined($options{"grpid"}) ? "" : "checked";
663         printf "<input type=radio name=nfs_grpid value=1 %s> $text{'no'}</td>\n",
664                 defined($options{"grpid"}) ? "checked" : "";
665
666         print "<td><b>$text{'solaris_soft'}</b></td>\n";
667         printf "<td nowrap><input type=radio name=nfs_soft value=1 %s> $text{'yes'}\n",
668                 defined($options{"soft"}) ? "checked" : "";
669         printf "<input type=radio name=nfs_soft value=0 %s> $text{'no'}</td> </tr>\n",
670                 defined($options{"soft"}) ? "" : "checked";
671
672         print "<tr> <td><b>$text{'solaris_bg'}</b></td>\n";
673         printf "<td nowrap><input type=radio name=nfs_bg value=1 %s> $text{'yes'}\n",
674                 defined($options{"bg"}) ? "checked" : "";
675         printf "<input type=radio name=nfs_bg value=0 %s> $text{'no'}</td>\n",
676                 defined($options{"bg"}) ? "" : "checked";
677
678         print "<td><b>$text{'solaris_quota'}</b></td>\n";
679         printf "<td nowrap><input type=radio name=nfs_quota value=1 %s> $text{'yes'}\n",
680                 defined($options{"quota"}) ? "checked" : "";
681         printf "<input type=radio name=nfs_quota value=0 %s> $text{'no'}</td> </tr>\n",
682                 defined($options{"quota"}) ? "" : "checked";
683
684         print "<tr> <td><b>$text{'solaris_nointr'}</b></td>\n";
685         printf "<td nowrap><input type=radio name=nfs_nointr value=0 %s> $text{'yes'}\n",
686                 defined($options{"nointr"}) ? "" : "checked";
687         printf "<input type=radio name=nfs_nointr value=1 %s> $text{'no'}</td>\n",
688                 defined($options{"nointr"}) ? "checked" : "";
689
690         print "<td><b>$text{'solaris_nfsver'}</b></td>\n";
691         printf "<td nowrap><input type=radio name=nfs_vers_def value=1 %s> $text{'solaris_highest'}\n",
692                 defined($options{"vers"}) ? "" : "checked";
693         printf "<input type=radio name=nfs_vers_def value=0 %s>\n",
694                 defined($options{"vers"}) ? "checked" : "";
695         print "<input size=2 name=nfs_vers value=$options{vers}></td> </tr>\n";
696
697         print "<tr> <td><b>$text{'solaris_proto'}</b></td>\n";
698         print "<td nowrap><select name=proto>\n";
699         printf "<option value=\"\" %s> $text{'default'}\n",
700                 defined($options{"proto"}) ? "" : "selected";
701         &open_tempfile(NETCONFIG, "/etc/netconfig");
702         while(<NETCONFIG>) {
703                 if (!/^([A-z0-9\_\-]+)\s/) { next; }
704                 printf "<option value=\"$1\" %s> $1\n",
705                         $options{"proto"} eq $1 ? "selected" : "";
706                 }
707         &close_tempfile(NETCONFIG);
708         print "</select></td>\n";
709
710         print "<td><b>$text{'solaris_port'}</b></td>\n";
711         printf "<td nowrap><input type=radio name=nfs_port_def value=1 %s> $text{'default'}\n",
712                 defined($options{"port"}) ? "" : "checked";
713         printf "<input type=radio name=nfs_port_def value=0 %s>\n",
714                 defined($options{"port"}) ? "checked" : "";
715         print "<input size=5 name=nfs_port value=$options{port}></td> </tr>\n";
716
717         print "<tr> <td><b>$text{'solaris_timeo'}</b></td>\n";
718         printf "<td nowrap><input type=radio name=nfs_timeo_def value=1 %s> $text{'default'}\n",
719                 defined($options{"timeo"}) ? "" : "checked";
720         printf "<input type=radio name=nfs_timeo_def value=0 %s>\n",
721                 defined($options{"timeo"}) ? "checked" : "";
722         printf "<input size=5 name=nfs_timeo value=$options{timeo}></td>\n";
723
724         print "<td><b>$text{'solaris_retrans'}</b></td>\n";
725         printf "<td nowrap><input type=radio name=nfs_retrans_def value=1 %s> $text{'default'}\n",
726                 defined($options{"retrans"}) ? "" : "checked";
727         printf "<input type=radio name=nfs_retrans_def value=0 %s>\n",
728                 defined($options{"retrans"}) ? "checked" : "";
729         print "<input size=5 name=nfs_retrans value=$options{retrans}></td> </tr>\n";
730
731         print "<tr> <td><b>$text{'solaris_auth'}</b></td>\n";
732         $nfs_auth = $options{'sec'} ? $options{'sec'} :
733                     defined($options{"secure"}) ? "dh" :
734                     defined($options{"kerberos"}) ? "krb" : "";
735         print "<td><select name=nfs_auth>\n";
736         printf "<option value=\"\" %s> $text{'solaris_none'}\n",
737                 $nfs_auth eq "" ? "selected" : "";
738         printf "<option value=dh %s> $text{'solaris_des'}\n",
739                 $nfs_auth eq "dh" ? "selected" : "";
740         printf "<option value=krb %s> $text{'solaris_krb'}\n",
741                 $nfs_auth eq "krb" ? "selected" : "";
742         print "</select></td>\n";
743
744         if ($gconfig{'os_version'} >= 7) {
745                 print "<td><b>$text{'solaris_public'}</b></td> <td>\n";
746                 printf "<input type=radio name=nfs_public value=1 %s> $text{'yes'}\n",
747                         defined($options{'public'}) ? "checked" : "";
748                 printf "<input type=radio name=nfs_public value=0 %s> $text{'no'}\n",
749                         defined($options{'public'}) ? "" : "checked";
750                 print "</td>\n";
751                 }
752         print "</tr>\n";
753         }
754 if ($_[0] eq "ufs") {
755         # Solaris UFS also has many options, not all of which are here
756         print "<tr> <td><b>$text{'solaris_ro'}</b></td>\n";
757         printf "<td nowrap><input type=radio name=ufs_ro value=1 %s> $text{'yes'}\n",
758                 defined($options{"ro"}) ? "checked" : "";
759         printf "<input type=radio name=ufs_ro value=0 %s> $text{'no'}</td>\n",
760                 defined($options{"ro"}) ? "" : "checked";
761
762         print "<td><b>$text{'solaris_nosuid'}</b></td>\n";
763         printf "<td nowrap><input type=radio name=ufs_nosuid value=1 %s> $text{'yes'}\n",
764                 defined($options{"nosuid"}) ? "checked" : "";
765         printf "<input type=radio name=ufs_nosuid value=0 %s> $text{'no'}</td> </tr>\n",
766                 defined($options{"nosuid"}) ? "" : "checked";
767
768         print "<tr> <td><b>$text{'solaris_nointr'}</b></td>\n";
769         printf "<td nowrap><input type=radio name=ufs_nointr value=0 %s> $text{'yes'}\n",
770                 defined($options{"nointr"}) ? "" : "checked";
771         printf "<input type=radio name=ufs_nointr value=1 %s> $text{'no'}</td>\n",
772                 defined($options{"nointr"}) ? "checked" : "";
773
774         print "<td><b>$text{'solaris_quotab'}</b></td>\n";
775         printf "<td nowrap><input type=radio name=ufs_quota value=1 %s> $text{'yes'}\n",
776                 defined($options{"quota"}) || defined($options{"rq"}) ?
777                         "checked" : "";
778         printf "<input type=radio name=ufs_quota value=0 %s> $text{'no'}</td> </tr>\n",
779                 defined($options{"quota"}) || defined($options{"rq"}) ?
780                         "" : "checked";
781
782         print "<tr> <td><b>$text{'solaris_onerror'}</b></td>\n";
783         print "<td><select name=ufs_onerror>\n";
784         foreach ('panic', 'lock', 'umount', 'repair') {
785                 next if ($_ eq "repair" && $gconfig{'os_version'} >= 10);
786                 printf "<option value=\"$_\" %s> $_\n",
787                  $options{onerror} eq $_ ||
788                  !defined($options{onerror}) && $_ eq "panic" ? "selected" : "";
789                 }
790         print "</select></td>\n";
791
792         if ($gconfig{'os_version'} >= 7) {
793                 print "<td><b>$text{'solaris_noatime'}</b></td> <td>\n";
794                 if ($gconfig{'os_version'} >= 8) {
795                         printf "<input type=radio name=ufs_noatime value=0 %s> $text{'solaris_immed'}\n",
796                                 defined($options{'nodfratime'}) ? "checked" : "";
797                         printf "<input type=radio name=ufs_noatime value=1 %s> $text{'solaris_defer'}\n",
798                                 !defined($options{'nodfratime'}) &&
799                                 !defined($options{'noatime'}) ? "checked" : "";
800                         printf "<input type=radio name=ufs_noatime value=2 %s> $text{'no'}</td> </tr>\n",
801                                 defined($options{'noatime'}) ? "checked" : "";
802                         }
803                 else {
804                         printf "<input type=radio name=ufs_noatime value=0 %s> $text{'yes'}\n",
805                                 defined($options{'noatime'}) ? "" : "checked";
806                         printf "<input type=radio name=ufs_noatime value=1 %s> $text{'no'}</td> </tr>\n",
807                                 defined($options{'noatime'}) ? "checked" : "";
808                         }
809
810                 print "<tr> <td><b>$text{'solaris_force'}</b></td> <td>\n";
811                 printf "<input type=radio name=ufs_force value=1 %s> $text{'yes'}\n",
812                         defined($options{'forcedirectio'}) ? "checked" : "";
813                 printf "<input type=radio name=ufs_force value=0 %s> $text{'no'}</td>\n",
814                         defined($options{'forcedirectio'}) ? "" : "checked";
815
816                 print "<td><b>$text{'solaris_nolarge'}</td> <td>\n";
817                 printf "<input type=radio name=ufs_nolarge value=0 %s> $text{'yes'}\n",
818                         defined($options{'nolargefiles'}) ? "" : "checked";
819                 printf "<input type=radio name=ufs_nolarge value=1 %s> $text{'no'}</td> </tr>\n",
820                         defined($options{'nolargefiles'}) ? "checked" : "";
821
822                 print "<tr> <td><b>$text{'solaris_logging'}</td> <td>\n";
823                 printf "<input type=radio name=ufs_logging value=1 %s> $text{'yes'}\n",
824                         defined($options{'logging'}) ? "checked" : "";
825                 printf "<input type=radio name=ufs_logging value=0 %s> $text{'no'}</td> </tr>\n",
826                         defined($options{'logging'}) ? "" : "checked";
827                 }
828         else {
829                 print "<td><b>$text{'solaris_toosoon'}</b></td>\n";
830                 $options{toosoon} =~ /([0-9]+)([A-z])/;
831                 print "<td nowrap><input size=5 name=ufs_toosoon_time value='$1'>\n";
832                 print "<select name=ufs_toosoon_units>\n";
833                 foreach $u ('s', 'm', 'h', 'd', 'w', 'y') {
834                         printf "<option value=%s %s> %s\n",
835                                 $u, $2 eq $u ? "selected" : "", $text{"solaris_time_$u"};
836                         }
837                 print "</select></td> </tr>\n";
838                 }
839         }
840 if ($_[0] eq "hsfs") {
841         # Solaris hsfs is used for CDROMs
842         print "<tr> <td><b>$text{'solaris_nrr'}</b></td>\n";
843         printf "<td nowrap><input type=radio name=hsfs_nrr value=1 %s> $text{'yes'}\n",
844                 defined($options{"nrr"}) ? "checked" : "";
845         printf "<input type=radio name=hsfs_nrr value=0 %s> $text{'no'}</td>\n",
846                 defined($options{"nrr"}) ? "" : "checked";
847
848         print "<td><b>$text{'solaris_notraildot'}</b></td>\n";
849         printf "<td nowrap><input type=radio name=hsfs_notraildot value=1 %s> $text{'yes'}\n",
850                 defined($options{"notraildot"}) ? "checked" : "";
851         printf "<input type=radio name=hsfs_notraildot value=0 %s> $text{'no'}</td> </tr>\n",
852                 defined($options{"notraildot"}) ? "" : "checked";
853
854         print "<tr> <td><b>$text{'solaris_nomaplcase'}</b></td>\n";
855         printf "<td nowrap><input type=radio name=hsfs_nomaplcase value=0 %s> $text{'yes'}\n",
856                 defined($options{"nomaplcase"}) ? "" : "checked";
857         printf "<input type=radio name=hsfs_nomaplcase value=1 %s> $text{'no'}</td>\n",
858                 defined($options{"nomaplcase"}) ? "checked" : "";
859
860         print "<td><b>$text{'solaris_nosuid'}</b></td>\n";
861         printf"<td nowrap><input type=radio name=hsfs_nosuid value=1 %s> $text{'yes'}\n",
862                 defined($options{"nosuid"}) ? "checked" : "";
863         printf "<input type=radio name=hsfs_nosuid value=0 %s> $text{'no'}</td> </tr>\n",
864                 defined($options{"nosuid"}) ? "" : "checked";
865         }
866 if ($_[0] eq "pcfs") {
867         # Solaris pcfs for for FAT filesystems. It doesn't have many options
868         print "<tr> <td width=25%><b>$text{'solaris_ro'}</b></td> <td width=25%>\n";
869         printf "<input type=radio name=pcfs_ro value=1 %s> $text{'yes'}\n",
870                 defined($options{"ro"}) ? "checked" : "";
871         printf "<input type=radio name=pcfs_ro value=0 %s> $text{'no'}</td>\n",
872                 defined($options{"ro"}) ? "" : "checked";
873
874         if ($gconfig{'os_version'} >= 7) {
875                 print "<td><b>$text{'solaris_foldcase'}</b></td> <td>\n";
876                 printf "<input type=radio name=pcfs_foldcase value=1 %s> $text{'yes'}\n",
877                         defined($options{'foldcase'}) ? "checked" : "";
878                 printf "<input type=radio name=pcfs_foldcase value=0 %s> $text{'no'}</td>\n",
879                         defined($options{'foldcase'}) ? "" : "checked";
880                 }
881         else {
882                 print "<td colspan=2></td> </tr>\n";
883                 }
884         }
885 if ($_[0] eq "lofs") {
886         # LOFS is a loopback filesystem
887         print "<tr> <td><b>$text{'solaris_ro'}</b></td>\n";
888         printf "<td nowrap><input type=radio name=ufs_ro value=1 %s> $text{'yes'}\n",
889                 defined($options{"ro"}) ? "checked" : "";
890         printf "<input type=radio name=ufs_ro value=0 %s> $text{'no'}</td>\n",
891                 defined($options{"ro"}) ? "" : "checked";
892
893         print "<td><b>$text{'solaris_nosuid'}</b></td>\n";
894         printf "<td nowrap><input type=radio name=ufs_nosuid value=1 %s> $text{'yes'}\n",
895                 defined($options{"nosuid"}) ? "checked" : "";
896         printf "<input type=radio name=ufs_nosuid value=0 %s> $text{'no'}</td> </tr>\n",
897                 defined($options{"nosuid"}) ? "" : "checked";
898         }
899 if ($_[0] eq "tmpfs") {
900         # Solaris tmpfs (virtual memory) filesystem.
901         print "<tr> <td><b>$text{'solaris_size'}</b>&nbsp;&nbsp;&nbsp;</td>\n";
902         printf"<td><input type=radio name=tmpfs_size_def value=1 %s> $text{'solaris_max'}\n",
903                 defined($options{"size"}) ? "" : "checked";
904         printf"&nbsp;&nbsp;<input type=radio name=tmpfs_size_def value=0 %s>\n",
905                 defined($options{"size"}) ? "checked" : "";
906         ($tmpsz = $options{size}) =~ s/[A-z]+$//g;
907         print "<input name=tmpfs_size size=6 value=\"$tmpsz\">\n";
908         print "<select name=tmpfs_unit>\n";
909         printf "<option value=m %s> MB\n",
910                 $options{"size"} =~ /m$/ ? "selected" : "";
911         printf "<option value=k %s> kB\n",
912                 $options{"size"} =~ /k$/ ? "selected" : "";
913         printf "<option value=b %s> bytes\n",
914                 $options{"size"} !~ /(k|m)$/ ? "selected" : "";
915         print "</select></td>\n";
916
917         print "<td><b>$text{'solaris_nosuid'}</b></td> <td nowrap>\n";
918         printf "<input type=radio name=tmpfs_nosuid value=1 %s> $text{'yes'}\n",
919                 defined($options{"nosuid"}) ? "checked" : "";
920         printf "<input type=radio name=tmpfs_nosuid value=0 %s> $text{'no'}</td>\n",
921                 defined($options{"nosuid"}) ? "" : "checked";
922         print "</tr>\n";
923         }
924 if ($_[0] eq "swap") {
925         # Solaris swap has no options
926         print "<tr> <td><i>$text{'solaris_noopts'}</i></td> </tr>\n";
927         }
928 if ($_[0] eq "cachefs") {
929         # The caching filesystem has lots of options.. cachefs mounts can
930         # be of an existing 'manually' mounted back filesystem, or of a
931         # back-filesystem that has been automatically mounted by the cache.
932         # The user should never see the automatic mountings made by cachefs.
933         print "<tr> <td><b>$text{'solaris_backfs'}</b></td>\n";
934         print "<td nowrap><select name=cfs_backfstype>\n";
935         if (!defined($options{backfstype})) { $options{backfstype} = "nfs"; }
936         foreach (&list_fstypes()) {
937                 if ($_ eq "cachefs") { next; }
938                 printf "<option value=\"$_\" %s>$_\n",
939                         $_ eq $options{backfstype} ? "selected" : "";
940                 }
941         print "</select></td>\n";
942
943         print "<td><b>$text{'solaris_backpath'}</b></td>\n";
944         printf"<td nowrap><input type=radio name=cfs_noback value=1 %s> $text{'solaris_auto'}\n",
945                 defined($options{"backpath"}) ? "" : "checked";
946         printf "<input type=radio name=cfs_noback value=0 %s>\n",
947                 defined($options{"backpath"}) ? "checked" : "";
948         print "<input size=10 name=cfs_backpath value=\"$options{backpath}\"></td> </tr>\n";
949
950         print "<tr> <td><b>$text{'solaris_cachedir'}</b></td>\n";
951         printf "<td nowrap><input size=10 name=cfs_cachedir value=\"%s\"></td>\n",
952                 defined($options{"cachedir"}) ? $options{"cachedir"} : "/cache";
953
954         print "<td><b>$text{'solaris_wmode'}</b></td>\n";
955         printf"<td nowrap><input type=radio name=cfs_wmode value=0 %s> $text{'solaris_waround'}\n",
956                 defined($options{"non-shared"}) ? "" : "checked";
957         printf "<input type=radio name=cfs_wmode value=1 %s> $text{'solaris_nshared'}\n",
958                 defined($options{"non-shared"}) ? "checked" : "";
959         print "</td> </tr>\n";
960
961         print "<tr> <td><b>$text{'solaris_con'}</b></td>\n";
962         print "<td><select name=cfs_con>\n";
963         print "<option value=1> $text{'solaris_period'}\n";
964         printf "<option value=0 %s> $text{'solaris_never'}\n",
965                 defined($options{"noconst"}) ? "selected" : "";
966         printf "<option value=2 %s> $text{'solaris_demand'}\n",
967                 defined($options{"demandconst"}) ? "selected" : "";
968         print "</select></td>\n";
969
970         print "<td><b>$text{'solaris_local'}</b></td>\n";
971         printf "<td nowrap><input type=radio name=cfs_local value=1 %s> $text{'yes'}\n",
972                 defined($options{"local-access"}) ? "checked" : "";
973         printf "<input type=radio name=cfs_local value=0 %s> $text{'no'}</td> </tr>\n",
974                 defined($options{"local-access"}) ? "" : "checked";
975
976         print "<tr> <td><b>$text{'solaris_ro'}</b></td>\n";
977         printf "<td nowrap><input type=radio name=cfs_ro value=1 %s> $text{'yes'}\n",
978                 defined($options{"ro"}) ? "checked" : "";
979         printf "<input type=radio name=cfs_ro value=0 %s> $text{'no'}</td>\n",
980                 defined($options{"ro"}) ? "" : "checked";
981
982         print "<td><b>$text{'solaris_nosuid'}</b></td>\n";
983         printf "<td nowrap><input type=radio name=cfs_nosuid value=1 %s> $text{'yes'}\n",
984                 defined($options{"nosuid"}) ? "checked" : "";
985         printf "<input type=radio name=cfs_nosuid value=0 %s> $text{'no'}</td> </tr>\n",
986                 defined($options{"nosuid"}) ? "" : "checked";
987         }
988 if ($_[0] eq "autofs") {
989         # Autofs has lots of options, depending on the type of file
990         # system being automounted.. the fstype options determines this
991         local($fstype);
992         $fstype = $options{fstype} eq "" ? "nfs" : $options{fstype};
993         if ($gconfig{'os_version'} >= 2.6) {
994                 print "<tr> <td><b>$text{'solaris_nobrowse'}</b></td> <td>\n";
995                 printf "<input type=radio name=auto_nobrowse value=0 %s> $text{'yes'}\n",
996                         defined($options{'nobrowse'}) ? "" : "checked";
997                 printf "<input type=radio name=auto_nobrowse value=1 %s> $text{'no'}\n",
998                         defined($options{'nobrowse'}) ? "checked" : "";
999                 print "</td> <td colspan=2></td> </tr>\n";
1000                 }
1001         &generate_options($fstype);
1002         print "<input type=hidden name=autofs_fstype value=\"$fstype\">\n";
1003         }
1004 if ($_[0] eq "rumba") {
1005         # SMB filesystems have a few options..
1006         print "<tr> <td><b>$text{'solaris_mname'}</b></td>\n";
1007         printf "<td><input type=radio name=rumba_mname_def value=1 %s> $text{'solaris_auto'}\n",
1008                 defined($options{"machinename"}) ? "" : "checked";
1009         printf "<input type=radio name=rumba_mname_def value=0 %s>\n",
1010                 defined($options{"machinename"}) ? "checked" : "";
1011         print "<input size=10 name=rumba_mname value=\"$options{machinename}\"></td>\n";
1012
1013         print "<td><b>$text{'solaris_cname'}</b></td>\n";
1014         printf "<td><input type=radio name=rumba_cname_def value=1 %s> $text{'solaris_auto'}\n",
1015                 defined($options{"clientname"}) ? "" : "checked";
1016         printf "<input type=radio name=rumba_cname_def value=0 %s>\n",
1017                 defined($options{"clientname"}) ? "checked" : "";
1018         print "<input size=10 name=rumba_cname value=\"$options{clientname}\"></td> </tr>\n";
1019
1020         print "<tr> <td><b>$text{'solaris_username'}</b></td>\n";
1021         print "<td><input name=rumba_username size=15 value=\"$options{username}\"></td>\n";
1022
1023         print "<td><b>$text{'solaris_password'}</b></td>\n";
1024         print "<td><input type=password name=rumba_password size=15 value=\"$options{password}\"></td> </tr>\n";
1025
1026         print "<tr> <td><b>$text{'solaris_uid'}</b></td>\n";
1027         printf "<td><input name=rumba_uid size=8 value=\"%s\">\n",
1028                 defined($options{'uid'}) ? getpwuid($options{'uid'}) : "";
1029         print &user_chooser_button("rumba_uid", 0),"</td>\n";
1030
1031         print "<td><b>$text{'solaris_gid'}</b></td>\n";
1032         printf "<td><input name=rumba_gid size=8 value=\"%s\">\n",
1033                 defined($options{'gid'}) ? getgrgid($options{'gid'}) : "";
1034         print &group_chooser_button("rumba_gid", 0),"</td>\n";
1035
1036         print "<tr> <td><b>$text{'solaris_fmode'}</b></td>\n";
1037         printf "<td><input name=rumba_fmode size=5 value=\"%s\"></td>\n",
1038                 defined($options{fmode}) ? $options{fmode} : "755";
1039
1040         print "<td><b>$text{'solaris_dmode'}</b></td>\n";
1041         printf "<td><input name=rumba_dmode size=5 value=\"%s\"></td> </tr>\n",
1042                 defined($options{dmode}) ? $options{dmode} : "755";
1043
1044         print "<tr> <td><b>$text{'solaris_readwrite'}</b></td>\n";
1045         printf"<td nowrap><input type=radio name=rumba_readwrite value=1 %s> $text{'yes'}\n",
1046                 defined($options{"readwrite"}) ? "checked" : "";
1047         printf "<input type=radio name=rumba_readwrite value=0 %s> $text{'no'}</td>\n",
1048                 defined($options{"readwrite"}) ? "" : "checked";
1049
1050         print "<td><b>$text{'solaris_readonly'}</b></td>\n";
1051         printf"<td nowrap><input type=radio name=rumba_readonly value=1 %s> $text{'yes'}\n",
1052                 defined($options{"readonly"}) ? "checked" : "";
1053         printf "<input type=radio name=rumba_readonly value=0 %s> $text{'no'}</td> </tr>\n",
1054                 defined($options{"readonly"}) ? "" : "checked";
1055
1056         print "<tr> <td><b>$text{'solaris_noupper'}</b></td>\n";
1057         printf"<td nowrap><input type=radio name=rumba_noupper value=0 %s> $text{'yes'}\n",
1058                 defined($options{"noupper"}) ? "" : "checked";
1059         printf "<input type=radio name=rumba_noupper value=1 %s> $text{'no'}</td>\n",
1060                 defined($options{"noupper"}) ? "checked" : "";
1061
1062         print "<td><b>$text{'solaris_attr'}</b></td>\n";
1063         printf"<td nowrap><input type=radio name=rumba_attr value=1 %s> $text{'yes'}\n",
1064                 defined($options{"attr"}) ? "checked" : "";
1065         printf "<input type=radio name=rumba_attr value=0 %s> $text{'no'}</td> </tr>\n",
1066                 defined($options{"attr"}) ? "" : "checked";
1067         }
1068 if ($_[0] eq "udfs") {
1069         # Solaris udfs is used for DVDs
1070         print "<tr> <td><b>$text{'solaris_ro'}</b></td>\n";
1071         printf "<td nowrap><input type=radio name=udfs_ro value=1 %s> $text{'yes'}\n",
1072                 defined($options{"ro"}) ? "checked" : "";
1073         printf "<input type=radio name=udfs_ro value=0 %s> $text{'no'}</td>\n",
1074                 defined($options{"ro"}) ? "" : "checked";
1075
1076         print "<td><b>$text{'solaris_nosuid'}</b></td>\n";
1077         printf "<td nowrap><input type=radio name=udfs_nosuid value=1 %s> $text{'yes'}\n",
1078                 defined($options{"nosuid"}) ? "checked" : "";
1079         printf "<input type=radio name=udfs_nosuid value=0 %s> $text{'no'}</td> </tr>\n",
1080                 defined($options{"nosuid"}) ? "" : "checked";
1081         }
1082 if ($_[0] eq "xmemfs") {
1083         # Solaris xmemfs (virtual memory) filesystem.
1084         print "<tr> <td><b>$text{'solaris_size'}</b>&nbsp;&nbsp;&nbsp;</td>\n";
1085         printf"<td><input type=radio name=xmemfs_size_def value=1 %s> $text{'solaris_max'}\n",
1086                 defined($options{"size"}) ? "" : "checked";
1087         printf"&nbsp;&nbsp;<input type=radio name=xmemfs_size_def value=0 %s>\n",
1088                 defined($options{"size"}) ? "checked" : "";
1089         ($tmpsz = $options{size}) =~ s/[A-z]+$//g;
1090         print "<input name=xmemfs_size size=6 value=\"$tmpsz\">\n";
1091         print "<select name=xmemfs_unit>\n";
1092         printf "<option value=m %s> MB\n",
1093                 $options{"size"} =~ /m$/ ? "selected" : "";
1094         printf "<option value=k %s> kB\n",
1095                 $options{"size"} =~ /k$/ ? "selected" : "";
1096         printf "<option value=b %s> bytes\n",
1097                 $options{"size"} !~ /(k|m)$/ ? "selected" : "";
1098         print "</select></td>\n";
1099
1100         print "<td><b>$text{'solaris_largebsize'}</b></td>\n";
1101         printf "<td nowrap><input type=radio name=xmemfs_largebsize value=1 %s> $text{'yes'}\n",
1102                 defined($options{"largebsize"}) ? "checked" : "";
1103         printf "<input type=radio name=xmemfs_largebsize value=0 %s> $text{'no'}</td> </tr>\n",
1104                 defined($options{"largebsize"}) ? "" : "checked";
1105         }
1106 }
1107
1108
1109 # check_location(type)
1110 # Parse and check inputs from %in, calling &error() if something is wrong.
1111 # Returns the location string for storing in the fstab file
1112 sub check_location
1113 {
1114 if ($_[0] eq "nfs") {
1115         local($out, $temp, $mout, $dirlist);
1116
1117         if ($in{'nfs_serv'} == 1) {
1118                 # multiple servers listed.. assume the user has a brain
1119                 return $in{'nfs_list'};
1120                 }
1121         elsif ($in{'nfs_serv'} == 2) {
1122                 # NFS url.. check syntax
1123                 if ($in{'nfs_url'} !~ /^nfs:\/\/([^\/ ]+)(\/([^\/ ]*))?$/) {
1124                         &error(&text('solaris_eurl', $in{'nfs_url'}));
1125                         }
1126                 return $in{'nfs_url'};
1127                 }
1128
1129         # Use dfshares to see if the host exists and is up
1130         if ($in{nfs_host} !~ /^\S+$/) {
1131                 &error(&text('solaris_ehost', $in{'nfs_host'}));
1132                 }
1133         $out = &backquote_command("dfshares '$in{nfs_host}' 2>&1");
1134         if ($out =~ /Unknown host/) {
1135                 &error(&text('solaris_ehost2', $in{'nfs_host'}));
1136                 }
1137         elsif ($out =~ /Timed out/) {
1138                 &error(&text('solaris_edown', $in{'nfs_host'}));
1139                 }
1140         elsif ($out =~ /Program not registered/) {
1141                 &error(&text('solaris_enfs', $in{'nfs_host'}));
1142                 }
1143
1144         # Try a test mount to see if filesystem is available
1145         foreach (split(/\n/, $out)) {
1146                 if (/^\s*([^ :]+):(\/\S+)\s+/) { $dirlist .= "$2\n"; }
1147                 }
1148         if ($in{nfs_dir} !~ /^\S+$/) {
1149                 &error(&text('solaris_enfsdir', $in{'nfs_dir'},
1150                              $in{'nfs_host'}, "<pre>$dirlist</pre>"));
1151                 }
1152         $temp = &transname();
1153         &make_dir($temp, 0755);
1154         $mout = &backquote_command("mount $in{nfs_host}:$in{nfs_dir} $temp 2>&1");
1155         if ($mout =~ /No such file or directory/) {
1156                 rmdir($temp);
1157                 &error(&text('solaris_enfsdir', $in{'nfs_dir'},
1158                              $in{'nfs_host'}, "<pre>$dirlist</pre>"));
1159                 }
1160         elsif ($mout =~ /Permission denied/) {
1161                 rmdir($temp);
1162                 &error(&text('solaris_enfsperm', $in{'nfs_dir'}, $in{'nfs_host'}));
1163                 }
1164         elsif ($?) {
1165                 rmdir($temp);
1166                 &error(&text('solaris_enfsmount', "<tt>$mout</tt>"));
1167                 }
1168         # It worked! unmount
1169         &execute_command("umount $temp");
1170         &unlink_file($temp);
1171         return "$in{nfs_host}:$in{nfs_dir}";
1172         }
1173 elsif ($_[0] eq "ufs" || $_[0] eq "pcfs") {
1174         # Get the device name
1175         if ($in{ufs_dev} == 0) {
1176                 $dv = $in{'ufs_disk'};
1177                 }
1178         elsif ($in{ufs_dev} == 1) {
1179                 $in{ufs_md} =~ /^[0-9]+$/ ||
1180                         &error(&text('solaris_eraid', $in{'ufs_md'}));
1181                 $dv = "/dev/md/dsk/d$in{ufs_md}";
1182                 }
1183         else {
1184                 $in{ufs_path} =~ /^\/\S+$/ ||
1185                         &error(&text('solaris_epath', $in{'ufs_path'}));
1186                 $dv = $in{ufs_path};
1187                 }
1188
1189         &fstyp_check($dv, $_[0]);
1190         return $dv;
1191         }
1192 elsif ($_[0] eq "hsfs" || $_[0] eq "udfs") {
1193         # Get the device name
1194         if ($in{ufs_dev} == 0) {
1195                 $in{ufs_c} =~ /^[0-9]+$/ ||
1196                         &error(&text('solaris_ectrlr', $in{'ufs_c'}));
1197                 $in{ufs_t} =~ /^[0-9]+$/ ||
1198                         &error(&text('solaris_etarget', $in{'ufs_t'}));
1199                 $in{ufs_d} =~ /^[0-9]+$/ ||
1200                         &error(&text('solaris_eunit', $in{'ufs_d'}));
1201                 $in{ufs_s} =~ /^[0-9]+$/ ||
1202                         &error(&text('solaris_epart', $in{'ufs_s'}));
1203                 $dv = "/dev/dsk/c$in{ufs_c}t$in{ufs_t}d$in{ufs_d}s$in{ufs_s}";
1204                 }
1205         else {
1206                 $in{ufs_path} =~ /^\/\S+$/ ||
1207                         &error(&text('solaris_epath', $in{'ufs_path'}));
1208                 $dv = $in{ufs_path};
1209                 }
1210
1211         return $dv;
1212         }
1213 elsif ($_[0] eq "lofs") {
1214         # Get and check the original directory
1215         $dv = $in{'lofs_src'};
1216         if (!(-r $dv)) { &error(&text('solaris_eexist', $dv)); }
1217         if (!(-d $dv)) { &error(&text('solaris_edir', $dv)); }
1218         return $dv;
1219         }
1220 elsif ($_[0] eq "swap") {
1221         if ($in{swap_dev} == 0) {
1222                 $dv = $in{'swap_disk'};
1223                 }
1224         else { $dv = $in{swap_path}; }
1225
1226         if (!open(SWAPFILE, $dv)) {
1227                 if ($! =~ /No such file/ && $in{swap_dev}) {
1228                         if ($dv !~ /^\/dev/) {
1229                                 &swap_form($dv);
1230                                 }
1231                         else {
1232                                 &error(&text('solaris_eswapfile', $dv));
1233                                 }
1234                         }
1235                 elsif ($! =~ /No such file/) {
1236                         &error(&text('solaris_etarget', $in{'swap_t'}));
1237                         }
1238                 elsif ($! =~ /No such device or address/) {
1239                         &error(&text('solaris_epart', $in{'swap_s'}));
1240                         }
1241                 else {
1242                         &error(&text('solaris_eopen', $dv, $!));
1243                         }
1244                 }
1245         close(SWAPFILE);
1246         return $dv;
1247         }
1248 elsif ($_[0] eq "tmpfs") {
1249         # Ram-disk filesystems have no location
1250         return "swap";
1251         }
1252 elsif ($_[0] eq "xmemfs") {
1253         # Large ram-disk filesystems have no location
1254         return "xmem";
1255         }
1256 elsif ($_[0] eq "cachefs") {
1257         # In order to check the location for the caching filesystem, we need
1258         # to check the back filesystem
1259         if (!$in{cfs_noback}) {
1260                 # The back filesystem is manually mounted.. hopefully
1261                 local($bidx, @mlist, @binfo);
1262                 $bidx = &get_mounted($in{cfs_backpath}, "*");
1263                 if ($bidx < 0) {
1264                         &error(&text('solaris_ebackfs', $in{'cfs_backpath'}));
1265                         }
1266                 @mlist = &list_mounted();
1267                 @binfo = @{$mlist[$bidx]};
1268                 if ($binfo[2] ne $in{cfs_backfstype}) {
1269                         &error(&text('solaris_ebacktype', $binfo[2], $in{'cfs_backfstype'}));
1270                         }
1271                 }
1272         else {
1273                 # Need to automatically mount the back filesystem.. check
1274                 # it for sanity first.
1275                 # But HOW?
1276                 $in{cfs_src} =~ /^\S+$/ ||
1277                         &error(&text('solaris_ecsrc', $in{'cfs_src'}));
1278                 }
1279         return $in{cfs_src};
1280         }
1281 elsif ($_[0] eq "autofs") {
1282         # An autofs filesystem can be either mounted from the special
1283         # -hosts and -xfn maps, or from a normal map. The map can be a file
1284         # name (if it starts with /), or an NIS map (if it doesn't)
1285         if ($in{autofs_type} == 0) {
1286                 # Normal map
1287                 $in{autofs_map} =~ /\S/ ||
1288                         &error($text{'solaris_eautomap'});
1289                 if ($in{autofs_map} =~ /^\// && !(-r $in{autofs_map})) {
1290                         &error(&text('solaris_eautofile', $in{'autofs_map'}));
1291                         }
1292                 return $in{autofs_map};
1293                 }
1294         elsif ($in{autofs_type} == 1) {
1295                 # Special hosts map (automount all shares from some host)
1296                 return "-hosts";
1297                 }
1298         else {
1299                 # Special FNS map (not sure what this does)
1300                 return "-xfn";
1301                 }
1302         }
1303 elsif ($_[0] eq "rumba") {
1304         # Cannot check much here..
1305         return "\\\\$in{rumba_server}\\$in{rumba_share}";
1306         }
1307 }
1308
1309
1310 # fstyp_check(device, type)
1311 # Check if some device exists, and contains a filesystem of the given type,
1312 # using the fstyp command.
1313 sub fstyp_check
1314 {
1315 local($out, $part, $found);
1316
1317 # Check if the device/partition actually exists
1318 if ($_[0] =~ /^\/dev\/dsk\/c(.)t(.)d(.)s(.)$/) {
1319         # mounting a normal scsi device..
1320         $out = &backquote_command("prtvtoc -h $_[0] 2>&1");
1321         if ($out =~ /No such file or directory|No such device or address/) {
1322                 &error(&text('solaris_etarget2', $_[0]));
1323                 }
1324         $part = $4;
1325         foreach (split(/\n/, $out)) {
1326                 /^\s+([0-9]+)\s+([0-9]+)/;
1327                 if ($1 == $part) {
1328                         $found = 1; last;
1329                         }
1330                 }
1331         if (!$found) {
1332                 &error(&text('solaris_epart2', $_[0]));
1333                 }
1334         }
1335 elsif ($_[0] =~ /^\/dev\/md\/dsk\/d(.)$/) {
1336         # mounting a multi-disk (raid) device..
1337         $out = &backquote_command("prtvtoc -h $_[0] 2>&1");
1338         if ($out =~ /No such file or directory|No such device or address/) {
1339                 &error(&text('solaris_eraid2', $_[0]));
1340                 }
1341         if ($out !~ /\S/) {
1342                 &error(&text('solaris_enopart', $_[0]));
1343                 }
1344         }
1345 else {
1346         # Some other device
1347         if (!open(DEV, $_[0])) {
1348                 if ($! =~ /No such file or directory/) {
1349                         &error(&text('solaris_edevfile', $_[0]));
1350                         }
1351                 elsif ($! =~ /No such device or address/) {
1352                         &error(&text('solaris_edevice', $_[0]));
1353                         }
1354                 }
1355         close(DEV);
1356         }
1357
1358 # Check the filesystem type
1359 $out = &backquote_command("fstyp $_[0] 2>&1");
1360 if ($out =~ /^([A-Za-z0-9]+)\n$/) {
1361         if ($1 eq $_[1]) { return; }
1362         else {
1363                 # Wrong filesystem type
1364                 &error(&text('solaris_efstyp', $_[0], &fstype_name($1)));
1365                 }
1366         }
1367 else {
1368         &error(&text('solaris_efstyp2', $out));
1369         }
1370 }
1371
1372
1373 # check_options(type)
1374 # Read options for some filesystem from %in, and use them to update the
1375 # %options array. Options handled by the user interface will be set or
1376 # removed, while unknown options will be left untouched.
1377 sub check_options
1378 {
1379 local($k, @rv);
1380 if ($_[0] eq "nfs") {
1381         # NFS has lots of options to parse
1382         if ($in{'nfs_ro'}) {
1383                 # Read-only
1384                 $options{"ro"} = ""; delete($options{"rw"});
1385                 }
1386         else {
1387                 # Read-write
1388                 $options{"rw"} = ""; delete($options{"ro"});
1389                 }
1390
1391         delete($options{'quota'}); delete($options{'noquota'});
1392         if ($in{'nfs_quota'}) { $options{'quota'} = ""; }
1393
1394         delete($options{"nosuid"}); delete($options{"suid"});
1395         if ($in{nfs_nosuid}) { $options{"nosuid"} = ""; }
1396
1397         delete($options{"grpid"});
1398         if ($in{nfs_grpid}) { $options{"grpid"} = ""; }
1399
1400         delete($options{"soft"}); delete($options{"hard"});
1401         if ($in{nfs_soft}) { $options{"soft"} = ""; }
1402
1403         delete($options{"bg"}); delete($options{"fg"});
1404         if ($in{nfs_bg}) { $options{"bg"} = ""; }
1405
1406         delete($options{"intr"}); delete($options{"nointr"});
1407         if ($in{nfs_nointr}) { $options{"nointr"} = ""; }
1408
1409         delete($options{"vers"});
1410         if (!$in{nfs_vers_def}) { $options{"vers"} = $in{nfs_vers}; }
1411
1412         delete($options{"proto"});
1413         if ($in{nfs_proto} ne "") { $options{"proto"} = $in{nfs_proto}; }
1414
1415         delete($options{"port"});
1416         if (!$in{nfs_port_def}) { $options{"port"} = $in{nfs_port}; }
1417
1418         delete($options{"timeo"});
1419         if (!$in{nfs_timeo_def}) { $options{"timeo"} = $in{nfs_timeo}; }
1420
1421         delete($options{"secure"}); delete($options{"kerberos"});
1422         delete($options{"sec"});
1423         if ($gconfig{'os_version'} >= 2.6) {
1424                 if ($in{'nfs_auth'}) { $options{'sec'} = $in{'nfs_auth'}; }
1425                 }
1426         else {
1427                 if ($in{'nfs_auth'} eq "dh") { $options{"secure"} = ""; }
1428                 elsif ($in{'nfs_auth'} eq "krb") { $options{"kerberos"} = ""; }
1429                 }
1430
1431         if ($gconfig{'os_version'} >= 7) {
1432                 delete($options{'public'});
1433                 $options{'public'} = "" if ($in{'nfs_public'});
1434                 }
1435         }
1436 elsif ($_[0] eq "ufs") {
1437         # UFS also has lots of options..
1438         if ($in{ufs_ro}) {
1439                 # read-only (and thus no quota)
1440                 $options{"ro"} = ""; delete($options{"rw"});
1441                 delete($options{"rq"}); delete($options{"quota"});
1442                 }
1443         elsif ($in{ufs_quota}) {
1444                 # read-write, with quota
1445                 delete($options{"ro"}); $options{"rw"} = "";
1446                 $options{"quota"} = "";
1447                 }
1448         else {
1449                 # read-write, without quota
1450                 delete($options{"ro"}); $options{"rw"} = "";
1451                 delete($options{"quota"});
1452                 }
1453
1454         delete($options{"nosuid"});
1455         if ($in{ufs_nosuid}) { $options{"nosuid"} = ""; }
1456
1457         delete($options{"intr"}); delete($options{"nointr"});
1458         if ($in{ufs_nointr}) { $options{"nointr"} = ""; }
1459
1460         delete($options{"onerror"});
1461         if ($in{ufs_onerror} ne "panic") {
1462                 $options{"onerror"} = $in{ufs_onerror};
1463                 }
1464
1465         if ($gconfig{'os_version'} >= 7) {
1466                 if ($gconfig{'os_version'} >= 8) {
1467                         delete($options{'noatime'});
1468                         delete($options{'dfratime'}); delete($options{'nodfratime'});
1469                         if ($in{'ufs_noatime'} == 0) { $options{'nodfratime'} = ""; }
1470                         elsif ($in{'ufs_noatime'} == 2) { $options{'noatime'} = ""; }
1471                         }
1472                 else {
1473                         delete($options{'noatime'});
1474                         $options{'noatime'} = "" if ($in{'ufs_noatime'});
1475                         }
1476
1477                 delete($options{'forcedirectio'});
1478                 delete($options{'noforcedirectio'});
1479                 $options{'forcedirectio'} = "" if ($in{'ufs_force'});
1480
1481                 delete($options{'nolargefiles'});delete($options{'largefiles'});
1482                 $options{'nolargefiles'} = "" if ($in{'ufs_nolarge'});
1483
1484                 delete($options{'logging'}); delete($options{'nologging'});
1485                 $options{'logging'} = "" if ($in{'ufs_logging'});
1486                 }
1487         else {
1488                 delete($options{"toosoon"});
1489                 if ($in{ufs_toosoon_time}) {
1490                         $options{"toosoon"} = $in{ufs_toosoon_time}.
1491                                               $in{ufs_toosoon_units};
1492                         }
1493                 }
1494         }
1495 elsif ($_[0] eq "lofs") {
1496         # LOFS has a few options
1497         if ($in{'nfs_ro'}) {
1498                 # Read-only
1499                 $options{"ro"} = ""; delete($options{"rw"});
1500                 }
1501         else {
1502                 # Read-write
1503                 $options{"rw"} = ""; delete($options{"ro"});
1504                 }
1505
1506         delete($options{"nosuid"});
1507         if ($in{ufs_nosuid}) { $options{"nosuid"} = ""; }
1508         }
1509 elsif ($_[0] eq "swap") {
1510         # Swap has no options to parse
1511         }
1512 elsif ($_[0] eq "pcfs") {
1513         # PCFS has only 2 options
1514         delete($options{'ro'}); delete($options{'rw'});
1515         $options{'ro'} = "" if ($in{'pcfs_ro'});
1516
1517         delete($options{'foldcase'}); delete($options{'nofoldcase'});
1518         $options{'foldcase'} = "" if ($in{'pcfs_foldcase'});
1519         }
1520 elsif ($_[0] eq "hsfs") {
1521         # Options for ISO-9660 filesystems
1522         delete($options{'nrr'});
1523         $options{'nrr'} = "" if ($in{'hsfs_nrr'});
1524
1525         delete($options{"notraildot"});
1526         $options{"notraildot"} = "" if ($in{'hsfs_notraildot'});
1527
1528         delete($options{'nomaplcase'});
1529         $options{'nomaplcase'} = "" if ($in{'hsfs_nomaplcase'});
1530
1531         delete($options{'nosuid'});
1532         $options{'nosuid'} = "" if ($in{'hsfs_nosuid'});
1533         }
1534 elsif ($_[0] eq "tmpfs") {
1535         # Ram-disk filesystems have only two options
1536         delete($options{"size"});
1537         if (!$in{"tmpfs_size_def"}) {
1538                 $options{"size"} = "$in{tmpfs_size}$in{tmpfs_unit}";
1539                 }
1540
1541         delete($options{"nosuid"});
1542         if ($in{'tmpfs_nosuid'}) { $options{"nosuid"} = ""; }
1543         }
1544 elsif ($_[0] eq "xmemfs") {
1545         # Large ram-disk filesystems have only two options
1546         delete($options{"size"});
1547         if (!$in{"xmemfs_size_def"}) {
1548                 $options{"size"} = "$in{xmemfs_size}$in{xmemfs_unit}";
1549                 }
1550
1551         delete($options{"largebsize"});
1552         if ($in{'xmemfs_largebsize'}) { $options{"largebsize"} = ""; }
1553
1554         delete($options{'rw'});
1555         }
1556 elsif ($_[0] eq "cachefs") {
1557         # The caching filesystem has lots of options
1558         $options{"backfstype"} = $in{"cfs_backfstype"};
1559
1560         delete($options{"backpath"});
1561         if (!$in{"cfs_noback"}) {
1562                 # A back filesystem was given..  (alreadys checked)
1563                 $options{"backpath"} = $in{"cfs_backpath"};
1564                 }
1565
1566         if ($in{"cfs_cachedir"} !~ /^\/\S+/) {
1567                 &error(&text('solaris_ecachedir', $in{'cfs_cachedir'}));
1568                 }
1569         $options{"cachedir"} = $in{"cfs_cachedir"};
1570
1571         delete($options{"write-around"}); delete($options{"non-shared"});
1572         if ($in{"cfs_wmode"}) {
1573                 $options{"non-shared"} = "";
1574                 }
1575
1576         delete($options{"noconst"}); delete($options{"demandconst"});
1577         if ($in{"cfs_con"} == 0) { $options{"noconst"} = ""; }
1578         elsif ($in{"cfs_con"} == 2) { $options{"demandconst"} = ""; }
1579
1580         delete($options{"ro"}); delete($options{"rw"});
1581         if ($in{"cfs_ro"}) { $options{"ro"} = ""; }
1582
1583         delete($options{"suid"}); delete($options{"nosuid"});
1584         if ($in{"cfs_nosuid"}) { $options{"nosuid"} = ""; }
1585         }
1586 elsif ($_[0] eq "autofs") {
1587         # The options for autofs depend on the type of the automounted
1588         # filesystem.. 
1589         $options{"fstype"} = $in{"autofs_fstype"};
1590         if ($gconfig{'os_version'} >= 2.6) {
1591                 delete($options{'nobrowse'}); delete($options{'browse'});
1592                 $options{'nobrowse'} = "" if ($in{'auto_nobrowse'});
1593                 }
1594         return &check_options($options{"fstype"});
1595         }
1596 elsif ($_[0] eq "rumba") {
1597         # Options for smb filesystems..
1598         delete($options{machinename});
1599         if (!$in{rumba_mname_def}) { $options{machinename} = $in{rumba_mname}; }
1600
1601         delete($options{clientname});
1602         if (!$in{rumba_cname_def}) { $options{clientname} = $in{rumba_cname}; }
1603
1604         delete($options{username});
1605         if ($in{rumba_username}) { $options{username} = $in{rumba_username}; }
1606
1607         delete($options{password});
1608         if ($in{rumba_password}) { $options{password} = $in{rumba_password}; }
1609
1610         delete($options{uid});
1611         if ($in{rumba_uid} ne "") { $options{uid} = getpwnam($in{rumba_uid}); }
1612
1613         delete($options{gid});
1614         if ($in{rumba_gid} ne "") { $options{gid} = getgrnam($in{rumba_gid}); }
1615
1616         delete($options{fmode});
1617         if ($in{rumba_fmode} !~ /^[0-7]{3}$/) {
1618                 &error(&text('solaris_efmode', $in{'rumba_fmode'}));
1619                 }
1620         elsif ($in{rumba_fmode} ne "755") { $options{fmode} = $in{rumba_fmode}; }
1621
1622         delete($options{dmode});
1623         if ($in{rumba_dmode} !~ /^[0-7]{3}$/) {
1624                 &error(&text('solaris_edmode', $in{'rumba_dmode'}));
1625                 }
1626         elsif ($in{rumba_dmode} ne "755") { $options{dmode} = $in{rumba_dmode}; }
1627
1628         delete($options{'readwrite'});
1629         if ($in{'rumba_readwrite'}) { $options{'readwrite'} = ""; }
1630
1631         delete($options{'readonly'});
1632         if ($in{'rumba_readonly'}) { $options{'readonly'} = ""; }
1633
1634         delete($options{'attr'});
1635         if ($in{'rumba_attr'}) { $options{'attr'} = ""; }
1636
1637         delete($options{'noupper'});
1638         if ($in{'rumba_noupper'}) { $options{'noupper'} = ""; }
1639         }
1640 elsif ($_[0] eq "udfs") {
1641         # The DVD filesystem has only 2 options
1642         delete($options{'ro'}); delete($options{'rw'});
1643         $options{'ro'} = "" if ($in{'udfs_ro'});
1644
1645         delete($options{"nosuid"});
1646         if ($in{'udfs_nosuid'}) { $options{"nosuid"} = ""; }
1647         }
1648
1649 # Return options string
1650 foreach $k (keys %options) {
1651         if ($options{$k} eq "") { push(@rv, $k); }
1652         else { push(@rv, "$k=$options{$k}"); }
1653         }
1654 return @rv ? join(',' , @rv) : "-";
1655 }
1656
1657
1658 # create_swap(path, size, units)
1659 # Attempt to create a swap file 
1660 sub create_swap
1661 {
1662 local($out);
1663 $out = &backquote_logged("mkfile $_[1]$_[2] $_[0] 2>&1");
1664 if ($?) {
1665         &unlink_file($_[0]);
1666         return "mkfile failed : $out";
1667         }
1668 return 0;
1669 }
1670
1671
1672 # exports_list(host, dirarray, clientarray)
1673 # Fills the directory and client array references with exports from some
1674 # host. Returns an error string if something went wrong
1675 sub exports_list
1676 {
1677 local($dref, $cref, $out, $_);
1678 $dref = $_[1]; $cref = $_[2];
1679 $out = &backquote_command("showmount -e ".quotemeta($_[0])." 2>&1", 1);
1680 if ($?) { return $out; }
1681 foreach (split(/\n/, $out)) {
1682         if (/^(\/\S*)\s+(.*)$/) {
1683                 push(@$dref, $1); push(@$cref, $2);
1684                 }
1685         }
1686 return undef;
1687 }
1688
1689 # broadcast_addr()
1690 # Returns a useable broadcast address for finding NFS servers
1691 sub broadcast_addr
1692 {
1693 local($out);
1694 $out = &backquote_command("ifconfig -a 2>&1", 1);
1695 if ($out =~ /broadcast\s+(\S+)/) { return $1; }
1696 return "255.255.255.255";
1697 }
1698
1699 # device_name(device)
1700 # Converts a device name to a human-readable form
1701 sub device_name
1702 {
1703 return $_[0] =~ /\/dev\/dsk\/c(\d+)t(\d+)d(\d+)s(\d+)$/ ?
1704         &text('solaris_scsidev', "$1", "$2", "$3", "$4") :
1705        $_[0] =~ /^\/dev\/md\/dsk\/d([0-9]+)$/ ?
1706         &text('solaris_mddev', "$1") :
1707        $_[0] =~ /^\/dev\/dsk\/c(\d+)d(\d+)s(\d+)$/ ?
1708         &text('solaris_idedev', "$1", "$2", "$3") :
1709        $_[0] eq "-hosts" ?
1710         $text{'solaris_autohosts'} :
1711        $_[0] eq "-xfn" ?
1712         $text{'solaris_autoxfn'} :
1713         $_[0];
1714 }
1715
1716 sub files_to_lock
1717 {
1718 return ( $config{'fstab_file'}, $config{'autofs_file'} );
1719 }
1720
1721 1;