📄 hpux-lib.pl
字号:
elsif ($_[0] eq "swap") { if ($in{swap_dev} == 0) { $in{swap_c} =~ /^[0-9]+$/ || &error("'$in{swap_c}' is not a valid SCSI controller"); $in{swap_t} =~ /^[0-9]+$/ || &error("'$in{swap_t}' is not a valid SCSI target"); $in{swap_d} =~ /^[0-9]+$/ || &error("'$in{swap_d}' is not a valid SCSI unit"); $in{swap_s} =~ /^[0-9]+$/ || &error("'$in{swap_s}' is not a valid SCSI partition"); $dv="/dev/dsk/c$in{swap_c}t$in{swap_t}d$in{swap_d}s$in{swap_s}"; } elsif ($in{swap_dev} == 1) { $in{swap_vg} =~ /^[0-9]+$/ || &error("'$in{swap_vg}' is not a valid Volume Group"); $in{swap_lv} =~ /^\S+$/ || &error("'$in{swap_lv}' is not a valid Logical Volume"); $dv = "/dev/vg$in{swap_vg}/$in{swap_lv}"; } else { $in{swap_path} =~ /^\/\S+$/ || &error("'$in{swap_path}' is not a valid pathname"); $dv = $in{swap_path}; } &fstyp_check($dv, "swap"); return $dv; }elsif ($_[0] eq "cdfs") { # Get the device name if ($in{cdfs_dev} == 0) { $in{cdfs_c} =~ /^[0-9]+$/ || &error("'$in{cdfs_c}' is not a valid SCSI controller"); $in{cdfs_t} =~ /^[0-9]+$/ || &error("'$in{cdfs_t}' is not a valid SCSI target"); $in{cdfs_d} =~ /^[0-9]+$/ || &error("'$in{cdfs_d}' is not a valid SCSI unit"); $dv = "/dev/dsk/c$in{cdfs_c}t$in{cdfs_t}d$in{cdfs_d}"; } else { $in{cdfs_path} =~ /^\/\S+$/ || &error("'$in{cdfs_path}' is not a valid pathname"); $dv = $in{cdfs_path}; } &fstyp_check($dv, "cdfs"); return $dv; }elsif ($_[0] eq "swapfs") { # In order to check the location for the caching filesystem, we need # to check the back filesystem if (!$in{cfs_noback}) { # The back filesystem is manually mounted.. hopefully local($bidx, @mlist, @binfo); $bidx = &get_mounted($in{cfs_backpath}, "*"); if ($bidx < 0) { &error("The back filesystem '$in{cfs_backpath}' is ". "not mounted"); } @mlist = &list_mounted(); @binfo = @{$mlist[$bidx]}; if ($binfo[2] ne $in{cfs_backfstype}) { &error("The back filesystem is '$binfo[2]', not ". "'$in{cfs_backfstype}'"); } } else { # Need to automatically mount the back filesystem.. check # it for sanity first. # But HOW? $in{cfs_src} =~ /^\S+$/ || &error("'$in{cfs_src}' is not a valid cache source"); } return $in{cfs_src}; }elsif ($_[0] eq "autofs") { # An autofs filesystem can be either mounted from the special # -hosts and -xfn maps, or from a normal map. The map can be a file # name (if it starts with /), or an NIS map (if it doesn't) if ($in{autofs_type} == 0) { # Normal map $in{autofs_map} =~ /\S/ || &error("You did not enter an automount map name"); if ($in{autofs_map} =~ /^\// && !(-r $in{autofs_map})) { &error("The map file '$in{autofs_map}' does not exist"); } return $in{autofs_map}; } elsif ($in{autofs_type} == 1) { # Special hosts map (automount all shares from some host) return "-hosts"; } else { # Special FNS map (not sure what this does) return "-xfn"; } }}# fstyp_check(device, type)# Check if some device exists, and contains a filesystem of the given type,# using the fstyp command.sub fstyp_check{local($out, $part, $found);# Check if the device/partition actually existsif ($_[0] =~ /^\/dev\/dsk\/c(.)t(.)d(.)s(.)$/) { # a normal scsi device.. if (!open(DEV, $_[0])) { if ($! =~ /No such file or directory/) { &error("The SCSI target for '$_[0]' does not exist"); } elsif ($! =~ /No such device or address/) { &error("The SCSI target for '$_[0]' does not exist"); } } close(DEV); }elsif ($_[0] =~ /^\/dev\/vg([0-9]+)\/(\S+)$/) { # Logical Volume device.. $out = `lvdisplay -v $_[0] 2>&1`; if ($out =~ /No such file or directory/) { &error("The Logical Volume device for '$_[0]' does not exist"); } }else { # Some other device if (!open(DEV, $_[0])) { if ($! =~ /No such file or directory/) { &error("The device file '$_[0]' does not exist"); } elsif ($! =~ /No such device or address/) { &error("The device for '$_[0]' does not exist"); } } close(DEV); }# Check the filesystem typeif ($_[1] ne "cdfs" && $_[1] ne "swap") { $out = `fstyp $_[0] 2>&1`; if ($out =~ /^([A-z0-9]+)\n$/) { if ($1 eq $_[1]) { return; } else { # Wrong filesystem type &error("The device '$_[0]' is formatted as a ". &fstype_name($1)); } } else { &error("Failed to check filesystem type : $out"); } }}# check_options(type)# 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);delete($options{"defaults"});if ($_[0] eq "nfs") { # NFS has lots of options to parse if ($in{'nfs_ro'}) { # Read-only $options{"ro"} = ""; delete($options{"rw"}); } else { # Read-write $options{"rw"} = ""; delete($options{"ro"}); } if ($in{hfs_nosuid}) { # nosuid $options{"nosuid"} = ""; delete($options{"suid"}); } else { # suid $options{"suid"} = ""; delete($options{"nosuid"}); } delete($options{"soft"}); delete($options{"hard"}); if ($in{nfs_soft}) { $options{"soft"} = ""; } delete($options{"bg"}); delete($options{"fg"}); if ($in{nfs_bg}) { $options{"bg"} = ""; } delete($options{"intr"}); delete($options{"nointr"}); if ($in{nfs_nointr}) { $options{"nointr"} = ""; } delete($options{"devs"}); delete($options{"nodevs"}); if ($in{nfs_nodevs}) { $options{"nodevs"} = ""; } }elsif ($_[0] eq "hfs") { if ($in{hfs_ro}) { # read-only $options{"ro"} = ""; delete($options{"rw"}); } else { # read-write $options{"rw"} = ""; delete($options{"ro"}); } if ($in{hfs_nosuid}) { # nosuid $options{"nosuid"} = ""; delete($options{"suid"}); } else { # suid $options{"suid"} = ""; delete($options{"nosuid"}); } if ($in{hfs_quota}) { # quota $options{"quota"} = ""; } else { # noquota delete($options{"quota"}); } }elsif ($_[0] eq "vxfs") { if ($in{jfs_ro}) { # read-only $options{"ro"} = ""; delete($options{"rw"}); } else { # read-write $options{"rw"} = ""; delete($options{"ro"}); } if ($in{jfs_nosuid}) { # nosuid $options{"nosuid"} = ""; delete($options{"suid"}); } else { # suid $options{"suid"} = ""; delete($options{"nosuid"}); } if ($in{jfs_log}) { # log $options{"log"} = ""; delete($options{"delaylog"}); } else { # delaylog $options{"delaylog"} = ""; delete($options{"log"}); } if ($in{jfs_syncw}) { # datainlog $options{"datainlog"} = ""; delete($options{"nodatainlog"}); } else { # nodatainlog $options{"nodatainlog"} = ""; delete($options{"datainlog"}); } if ($in{jfs_quota}) { # quota $options{"quota"} = ""; } else { # noquota delete($options{"quota"}); } }elsif ($_[0] eq "lofs") { if ($in{lofs_ro}) { # read-only $options{"ro"} = ""; } else { # read-write $options{"defaults"} = ""; } }elsif ($_[0] eq "swap") { $options{"pri"} = $in{swap_pri}; }elsif ($_[0] eq "cdfs") { # read-only $options{"ro"} = ""; if ($in{cdfs_nosuid}) { # nosuid $options{"nosuid"} = ""; delete($options{"suid"}); } else { # suid $options{"suid"} = ""; delete($options{"nosuid"}); } }elsif ($_[0] eq "tmpfs") { # Ram-disk filesystems have only one option delete($options{"size"}); if (!$in{"tmpfs_size_def"}) { $options{"size"} = "$in{tmpfs_size}$in{tmpfs_unit}"; } }elsif ($_[0] eq "swapfs") { # The caching filesystem has lots of options $options{"backfstype"} = $in{"cfs_backfstype"}; delete($options{"backpath"}); if (!$in{"cfs_noback"}) { # A back filesystem was given.. (alreadys checked) $options{"backpath"} = $in{"cfs_backpath"}; } if ($in{"cfs_cachedir"} !~ /^\/\S+/) { &error("'$in{cfs_cachedir}' is not a valid cache directory"); } $options{"cachedir"} = $in{"cfs_cachedir"}; delete($options{"write-around"}); delete($options{"non-shared"}); if ($in{"cfs_wmode"}) { $options{"non-shared"} = ""; } delete($options{"noconst"}); delete($options{"demandconst"}); if ($in{"cfs_con"} == 0) { $options{"noconst"} = ""; } elsif ($in{"cfs_con"} == 2) { $options{"demandconst"} = ""; } delete($options{"ro"}); delete($options{"rw"}); if ($in{"cfs_ro"}) { $options{"ro"} = ""; } delete($options{"suid"}); delete($options{"nosuid"}); if ($in{"cfs_nosuid"}) { $options{"nosuid"} = ""; } }elsif ($_[0] eq "autofs") { # The options for autofs depend on the type of the automounted # filesystem.. $options{"fstype"} = $in{"autofs_fstype"}; return &check_options($options{"fstype"}); }# 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(path, size, units)# Attempt to create a swap file sub create_swap{local($out);$out = `mkfile $_[1]$_[2] $_[0] 2>&1`;if ($?) { unlink($_[0]); return "mkfile failed : $out"; }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, $hostname, $broadcast, @tmp);$hostname = get_system_hostname();$out = `netstat -i 2>&1 | grep $hostname`;if ($out =~ /\s+(\S*)\s+(\S*)\s+(.*)/) { $broadcast = "$2.255.255.255"; @tmp = split(/\./,$broadcast); $broadcast = "@tmp[0].@tmp[1].@tmp[2].@tmp[3]"; return $broadcast; }return "255.255.255.255";}1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -