📄 freebsd-lib.pl
字号:
printf "<input name=ufs_groupquota_file size=30 value=\"%s\">\n", $options{'groupquota'}; print "</td> </tr>\n"; }elsif ($_[0] eq "nfs") { # NFS filesystems have lots more options print "<tr> <td><b>Retry mounts in background?</b></td>\n"; printf "<td nowrap><input type=radio name=nfs_b value=1 %s> Yes\n", defined($options{"-b"}) ? "checked" : ""; printf "<input type=radio name=nfs_b value=0 %s> No</td>\n", defined($options{"-b"}) ? "" : "checked"; print "<td><b>Return error on timeouts?</b></td>\n"; printf "<td nowrap><input type=radio name=nfs_s value=1 %s> Yes\n", defined($options{"-s"}) ? "checked" : ""; printf "<input type=radio name=nfs_s value=0 %s> No</td> </tr>\n", defined($options{"-s"}) ? "" : "checked"; print "<tr> <td><b>Timeout</b></td>\n"; printf "<td nowrap><input type=radio name=nfs_t_def value=1 %s> Default\n", defined($options{"-t"}) ? "" : "checked"; printf "<input type=radio name=nfs_t_def value=0 %s>\n", defined($options{"-t"}) ? "checked" : ""; printf "<input size=5 name=nfs_t value=\"$options{'-t'}\"></td>\n"; print "<td><b>Number of Retransmissions</b></td>\n"; printf "<td nowrap><input type=radio name=nfs_x_def value=1 %s> Default\n", defined($options{"-x"}) ? "" : "checked"; printf "<input type=radio name=nfs_x_def value=0 %s>\n", defined($options{"-x"}) ? "checked" : ""; print "<input size=5 name=nfs_x value=\"$options{'-x'}\"></td> </tr>\n"; print "<tr> <td><b>NFS version</b></td> <td nowrap>\n"; local $v = defined($options{"-2"}) ? 2 : defined($options{"-3"}) ? 3 : 0; printf "<input type=radio name=nfs_ver value=0 %s> Auto\n", $v ? "" : "checked"; printf "<input type=radio name=nfs_ver value=2 %s> V2\n", $v == 2 ? "checked" : ""; printf "<input type=radio name=nfs_ver value=3 %s> V3</td>\n", $v == 3 ? "checked" : ""; print "<td><b>Mount retries</b></td>\n"; printf "<td nowrap><input type=radio name=nfs_r_def value=1 %s> Default\n", defined($options{"-R"}) ? "" : "checked"; printf "<input type=radio name=nfs_r_def value=0 %s>\n", defined($options{"-R"}) ? "checked" : ""; print "<input size=5 name=nfs_r value=\"$options{'-R'}\"></td> </tr>\n"; print "<tr> <td><b>Read-ahead blocks</b></td>\n"; printf "<td nowrap><input type=radio name=nfs_a_def value=1 %s> Default\n", defined($options{"-a"}) ? "" : "checked"; printf "<input type=radio name=nfs_a_def value=0 %s>\n", defined($options{"-a"}) ? "checked" : ""; print "<input size=5 name=nfs_a value=\"$options{'-a'}\"></td> </tr>\n"; print "<tr> <td><b>RPC Protocol</b></td>\n"; printf "<td nowrap><input type=radio name=nfs_t2 value=1 %s> TCP\n", defined($options{"-T"}) ? "checked" : ""; printf "<input type=radio name=nfs_t2 value=0 %s> UDP</td> </tr>\n", defined($options{"-T"}) ? "" : "checked"; }elsif ($_[0] eq "msdos"){ # MS-DOS filesystems options deal with filling in # missing unix functionality print "<tr> <td><b>User files are owned by</b></td>\n"; printf "<td><input name=msdos_u size=8 value=\"%s\">\n", defined($options{"-u"}) ? getpwuid($options{"-u"}) : ""; print &user_chooser_button("msdos_u", 0),"</td>\n"; print "<td><b>Group files are owned by</b></td>\n"; printf "<td><input name=msdos_g size=8 value=\"%s\">\n", defined($options{"-g"}) ? getgrgid($options{"-g"}) : ""; print &group_chooser_button("msdos_g", 0),"</td>\n"; print "<tr> <td><b>File permissions mask</b></td>\n"; printf "<td><input type=radio name=msdos_m_def value=1 %s> Default\n", defined($options{"-m"}) ? "" : "checked"; printf "<input type=radio name=msdos_m_def value=0 %s>\n", defined($options{"-m"}) ? "checked" : ""; print "<input size=5 name=msdos_m value=\"$options{'-m'}\"></td>\n"; }elsif ($_[0] eq "cd9660") { # CDROM filesystem print "<tr> <td><b>Ignore Unix Attributes?</b></td>\n"; printf "<td><input type=radio name=cd9660_r value=1 %s> Yes\n", defined($options{"-r"}) ? "checked" : ""; printf "<input type=radio name=cd9660_r value=0 %s> No</td>\n", defined($options{"-r"}) ? "" : "checked"; print "<td><b>Show version numbers?</b></td>\n"; printf "<td><input type=radio name=cd9660_g value=1 %s> Yes\n", defined($options{"-g"}) ? "checked" : ""; printf "<input type=radio name=cd9660_g value=0 %s> No</td> </tr>\n", defined($options{"-g"}) ? "" : "checked"; print "<tr> <td><b>Use extended attributes?</b></td>\n"; printf "<td><input type=radio name=cd9660_e value=1 %s> Yes\n", defined($options{"-e"}) ? "checked" : ""; printf "<input type=radio name=cd9660_e value=0 %s> No</td> </tr>\n", defined($options{"-e"}) ? "" : "checked"; }elsif ($_[0] eq "ntfs") { # Windows NT filesystem print "<tr> <td><b>Display MSDOS 8.3 filenames?</b></td>\n"; printf "<td><input type=radio name=ntfs_a value=1 %s> Yes\n", defined($options{"-a"}) ? "checked" : ""; printf "<input type=radio name=ntfs_a value=0 %s> No</td>\n", defined($options{"-a"}) ? "" : "checked"; print "<td><b>Case sensitive filenames?</b></td>\n"; printf "<td><input type=radio name=ntfs_i value=0 %s> Yes\n", defined($options{"-i"}) ? "" : "checked"; printf "<input type=radio name=ntfs_i value=1 %s> No</td> </tr>\n", defined($options{"-i"}) ? "checked" : ""; print "<tr> <td><b>User files are owned by</b></td>\n"; printf "<td><input type=radio name=ntfs_u_def value=1 %s> Default\n", defined($options{"-u"}) ? "" : "checked"; printf "<input type=radio name=ntfs_u_def value=0 %s>\n", defined($options{"-u"}) ? "checked" : ""; printf "<input name=ntfs_u size=8 value='%s'> %s</td>\n", defined($options{"-u"}) ? scalar(getpwuid($options{"-u"})) : "", &user_chooser_button("ntfs_u"); print "<td><b>Group files are owned by</b></td>\n"; printf "<td><input type=radio name=ntfs_g_def value=1 %s> Default\n", defined($options{"-u"}) ? "" : "checked"; printf "<input type=radio name=ntfs_g_def value=0 %s>\n", defined($options{"-u"}) ? "checked" : ""; printf "<input name=ntfs_g size=8 value='%s'> %s</td> </tr>\n", defined($options{"-g"}) ? scalar(getgrgid($options{"-g"})) : "", &group_chooser_button("ntfs_g"); }elsif ($_[0] eq "swap") { # Swap has no options.. print "<tr> <td><i>No Options Available</i></td> </tr>\n"; }}# check_location(type)# Parse and check inputs from %in, calling &error() if something is wrong.# Returns the location string for storing in the fstab filesub check_location{if ($_[0] eq "nfs") { local($out, $temp, $mout, $dirlist); # Use ping and showmount to see if the host exists and is up if ($in{nfs_host} !~ /^\S+$/) { &error("'$in{nfs_host}' is not a valid hostname"); } $out = `ping -c 1 '$in{nfs_host}' 2>&1`; if ($out =~ /unknown host/i) { &error("The host '$in{nfs_host}' does not exist"); } elsif ($out =~ /100\% packet loss/) { &error("The host '$in{nfs_host}' is down"); } $out = `showmount -e '$in{nfs_host}' 2>&1`; if ($out =~ /Unable to receive/) { &error("The host '$in{nfs_host}' does not support NFS"); } elsif ($?) { &error("Failed to get mount list : $out"); } # Validate directory name foreach (split(/\n/, $out)) { if (/^(\/\S+)/) { $dirlist .= "$1\n"; } } if ($in{nfs_dir} !~ /^\/\S+$/) { &error("'$in{nfs_dir}' is not a valid directory name. The ". "available directories on $in{nfs_host} are:". "<pre>$dirlist</pre>"); } # Try a test mount to see if filesystem is available $temp = &tempname(); mkdir($temp, 0755); $mout = `mount $in{nfs_host}:$in{nfs_dir} $temp 2>&1`; if ($mout =~ /No such file or directory/) { rmdir($temp); &error("The directory '$in{nfs_dir}' does not exist on the ". "host $in{nfs_host}. The available directories are:". "<pre>$dirlist</pre>"); } elsif ($mout =~ /Permission denied/) { rmdir($temp); &error("This host is not allowed to mount the directory ". "$in{nfs_dir} from $in{nfs_host}"); } elsif ($?) { rmdir($temp); &error("NFS Error - $mout"); } # It worked! unmount `umount $temp`; rmdir($temp); return "$in{nfs_host}:$in{nfs_dir}"; }else { # This is some kind of disk-based filesystem.. get the device name if ($in{'disk_dev'} == 0) { $in{'ide_t'} =~ /^\d+$/ || &error("'$in{ide_t}' is not a valid device number"); $in{'ide_s'} =~ /^\d+$/ || &error("'$in{ide_s}' is not a valid slice number"); $in{'ide_p'} =~ /^[a-z]*$/ || &error("'$in{ide_p}' is not a valid partition letter"); $dv = "/dev/wd$in{ide_t}s$in{ide_s}$in{ide_p}"; } elsif ($in{'disk_dev'} == 1) { $in{'scsi_t'} =~ /^\d+$/ || &error("'$in{scsi_t}' is not a valid device number"); $in{'scsi_s'} =~ /^\d+$/ || &error("'$in{scsi_s}' is not a valid slice number"); $in{'scsi_p'} =~ /^[a-z]*$/ || &error("'$in{scsi_p}' is not a valid partition letter"); $dv = "/dev/sd$in{scsi_t}s$in{scsi_s}$in{scsi_p}"; } else { $dv = $in{'dev_path'}; } # If the device entered is a symlink, follow it if ($dvlink = readlink($dv)) { if ($dvlink =~ /^\//) { $dv = $dvlink; } else { $dv =~ /^(.*\/)[^\/]+$/; $dv = $1.$dvlink; } } # Check if the device actually exists and uses the right filesystem (-r $dv) || &error("The device file '$dv' does not exist"); return $dv; }}# check_options(type, device, directory)# Read options for some filesystem from %in, and use them to update the# %options array. Options handled by the user interface will be set or# removed, while unknown options will be left untouched.sub check_options{local($k, @rv);# Parse the common options first..if ($_[0] ne "swap") { delete($options{"ro"}); delete($options{"rw"}); delete($options{"rdonly"}); if ($in{'bsd_ro'}) { $options{'ro'} = ''; } else { $options{'rw'} = ""; } delete($options{"sync"}); delete($options{"async"}); if ($in{'bsd_sync'}) { $options{'sync'} = ''; } delete($options{'nodev'}); if ($in{'bsd_nodev'}) { $options{'nodev'} = ''; } delete($options{'noexec'}); if ($in{'bsd_noexec'}) { $options{'noexec'} = ''; } delete($options{'nosuid'}); if ($in{'bsd_nosuid'}) { $options{'nosuid'} = ''; } delete($options{'noatime'}); if ($in{'bsd_noatime'}) { $options{'noatime'} = ''; } if ($uname_release =~ /^3\./) { delete($options{'nosymfollow'}); $options{'nosymfollow'} = '' if ($in{'bsd_nosymfollow'}); delete($options{'suiddir'}); $options{'suiddir'} = '' if ($in{'bsd_suiddir'}); } }else { # Swap always has the sw option $options{'sw'} = ""; }if ($_[0] eq "ufs") { # Parse UFS quota options delete($options{'userquota'}) if ($in{'ufs_userquota'} == 0); $options{'userquota'} = "" if ($in{'ufs_userquota'} == 1); $options{'userquota'} = $in{'ufs_groupquota_file'} if ($in{'ufs_userquota'} == 2); delete($options{'groupquota'}) if ($in{'ufs_groupquota'} == 0); $options{'groupquota'} = "" if ($in{'ufs_groupquota'} == 1); $options{'groupquota'} = $in{'ufs_groupquota_file'} if ($in{'ufs_groupquota'} == 2); }elsif ($_[0] eq "nfs") { # NFS has a few specific options.. delete($options{'-b'}); $options{'-b'} = "" if ($in{'nfs_b'}); delete($options{'-s'}); $options{'-s'} = "" if ($in{'nfs_s'}); delete($options{'-t'}); $options{'-t'} = $in{'nfs_t'} if (!$in{'nfs_t_def'}); delete($options{'-x'}); $options{'-x'} = $in{'nfs_x'} if (!$in{'nfs_x_def'}); delete($options{'-2'}); delete($options{'-3'}); $options{'-2'} = "" if ($in{'nfs_ver'} == 2); $options{'-3'} = "" if ($in{'nfs_ver'} == 3); delete($options{'-R'}); $options{'-R'} = $in{'nfs_r'} if (!$in{'nfs_r_def'}); delete($options{'-a'}); $options{'-a'} = $in{'nfs_a'} if (!$in{'nfs_a_def'}); delete($options{'-T'}); $options{'-T'} = "" if ($in{'nfs_t2'}); }elsif ($_[0] eq "msdos") { # MSDOS options for file ownership/perms delete($options{"-u"}); delete($options{"-g"}); if ($in{'msdos_u'} ne "") { $options{'-u'} = getpwnam($in{'msdos_u'}); } if ($in{'msdos_g'} ne "") { $options{'-g'} = getgrnam($in{'msdos_g'}); } delete($options{"-m"}); if (!$in{'msdos_m_def'}) { $in{'msdos_m'} =~ /^[0-7]{3}$/ || &error("'$in{'msdos_m'}' is not a valid octal mask"); $options{'-m'} = $in{'msdos_m'}; } }elsif ($_[0] eq "cd9660") { # Options for iso9660 cd-roms delete($options{'-r'}); $options{'-r'} = "" if ($in{'cd9660_r'}); delete($options{'-g'}); $options{'-g'} = "" if ($in{'cd9660_g'}); delete($options{'-e'}); $options{'-e'} = "" if ($in{'cd9660_e'}); }elsif ($_[0] eq "ntfs") { delete($options{"-u"}); delete($options{"-g"}); if ($in{'ntfs_u'} ne "") { $options{'-u'} = getpwnam($in{'ntfs_u'}); } if ($in{'ntfs_g'} ne "") { $options{'-g'} = getgrnam($in{'ntfs_g'}); } delete($options{"-a"}); $options{"-a"} = '' if ($in{'ntfs_a'}); delete($options{"-i"}); $options{"-i"} = '' if ($in{'ntfs_i'}); }# Return options stringforeach $k (keys %options) { if ($options{$k} eq "") { push(@rv, $k); } else { push(@rv, "$k=$options{$k}"); } }return @rv ? join(',' , @rv) : "-";}# create_swap(file, size, units)# Calls dd and mkswap to setup a swap filesub create_swap{local($out, $bl);$bl = $_[1] * ($_[2] eq "m" ? 1024 : 1);$out = `dd if=/dev/zero of=$_[0] bs=1024 count=$bl 2>&1`;if ($?) { return "dd failed : $out"; }$out = `mkswap $_[0] $bl 2>&1`;if ($?) { return "mkswap failed : $out"; }system("sync >/dev/null 2>&1");return 0;}# exports_list(host, dirarray, clientarray)# Fills the directory and client array references with exports from some# host. Returns an error string if something went wrongsub exports_list{local($dref, $cref, $out, $_);$dref = $_[1]; $cref = $_[2];$out = `showmount -e $_[0] 2>&1`;if ($?) { return $out; }foreach (split(/\n/, $out)) { if (/^(\/\S*)\s+(.*)$/) { push(@$dref, $1); push(@$cref, $2); } }return undef;}# broadcast_addr()# Returns a useable broadcast address for finding NFS serverssub broadcast_addr{local($out);$out = `ifconfig -a 2>&1`;if ($out =~ /broadcast\s+(\S+)\s+/) { return $1; }return "255.255.255.255";}1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -