📄 irix-lib.pl
字号:
# irix-lib.pl# Filesystem functions for IRIX# Return information about a filesystem, in the form:# directory, device, type, options, fsck_order, mount_at_boot# If a field is unused or ignored, a - appears instead of the value.# Swap-filesystems (devices or files mounted for VM) have a type of 'swap',# and 'swap' in the directory fieldsub list_mounts{local(@rv, @p, $_, $i); $i = 0;open(FSTAB, $config{'fstab_file'});while(<FSTAB>) { chop; s/#.*$//g; if (!/\S/) { next; } @p = split(/\s+/, $_); if ($p[3] eq "swap") { $p[2] = "swap"; } $rv[$i++] = [ $p[1], $p[0], $p[2], $p[3], $p[5], 1 ]; }close(FSTAB);return @rv;}# create_mount(directory, device, type, options, fsck_order, mount_at_boot)# Add a new entry to the fstab file, and return the index of the new entrysub create_mount{local($len, @mlist, $fcsk, $dir);if ($_[2] eq "autofs") { # An autofs mount.. add to /etc/auto_master $len = grep { $_->[2] eq "autofs" } (&list_mounts()); open(AUTOTAB, ">> $config{autofs_file}"); print AUTOTAB "$_[0] $_[1]",($_[3] eq "-" ? "" : " -$_[3]"),"\n"; close(AUTOTAB); }else { # Add to the fstab file $len = grep { $_->[2] ne "autofs" } (&list_mounts()); open(FSTAB, ">> $config{fstab_file}"); if ($_[2] eq "ufs" || $_[2] eq "s5fs") { ($fsck = $_[1]) =~ s/\/dsk\//\/rdsk\//g; } else { $fsck = "-"; } if ($_[2] eq "swap") { $dir = "-"; } else { $dir = $_[0]; } print FSTAB "$_[1] $fsck $dir $_[2] $_[4] $_[5] $_[3]\n"; close(FSTAB); }return $len;}# delete_mount(index)# Delete some mount from the tablesub delete_mount{local(@fstab, $i, $line, $_);open(FSTAB, $config{fstab_file});@fstab = <FSTAB>;close(FSTAB);$i = 0;open(FSTAB, "> $config{fstab_file}");foreach (@fstab) { chop; ($line = $_) =~ s/#.*$//g; if ($line =~ /\S/ && $i++ == $_[0]) { # found the line not to include } else { print FSTAB $_,"\n"; } }close(FSTAB);open(AUTOTAB, $config{autofs_file});@autotab = <AUTOTAB>;close(AUTOTAB);open(AUTOTAB, "> $config{autofs_file}");foreach (@autotab) { chop; ($line = $_) =~ s/#.*$//g; if ($line =~ /\S/ && $line !~ /^[+\-]/ && $i++ == $_[0]) { # found line not to include.. } else { print AUTOTAB $_,"\n"; } }close(AUTOTAB);}# change_mount(num, directory, device, type, options, fsck_order, mount_at_boot)# Change an existing permanent mountsub change_mount{local(@fstab, @autotab, $i, $line, $fsck, $dir, $_);$i = 0;open(FSTAB, $config{fstab_file});@fstab = <FSTAB>;close(FSTAB);open(FSTAB, "> $config{fstab_file}");foreach (@fstab) { chop; ($line = $_) =~ s/#.*$//g; if ($line =~ /\S/ && $i++ == $_[0]) { # Found the line to replace if ($_[3] eq "ufs" || $_[3] eq "s5fs") { ($fsck = $_[2]) =~ s/\/dsk\//\/rdsk\//g; } else { $fsck = "-"; } if ($_[3] eq "swap") { $dir = "-"; } else { $dir = $_[1]; } print FSTAB "$_[2] $fsck $dir $_[3] $_[5] $_[6] $_[4]\n"; } else { print FSTAB $_,"\n"; } }close(FSTAB);open(AUTOTAB, $config{autofs_file});@autotab = <AUTOTAB>;close(AUTOTAB);open(AUTOTAB, "> $config{autofs_file}");foreach (@autotab) { chop; ($line = $_) =~ s/#.*$//g; if ($line =~ /\S/ && $line !~ /^[+\-]/ && $i++ == $_[0]) { # Found the line to replace print AUTOTAB "$_[1] $_[2] ", ($_[4] eq "-" ? "" : "-$_[4]"),"\n"; } else { print AUTOTAB $_,"\n"; } }close(AUTOTAB);}# list_mounted()# Return a list of all the currently mounted filesystems and swap files.# The list is in the form:# directory device type options# For swap files, the directory will be 'swap'sub list_mounted{local(@rv, @p, $_, $i, $r);foreach (split(/\n/, `cat /etc/mtab`)) { s/#.*$//g; if (!/\S/) { next; } @p = split(/\s+/, $_); push(@rv, [ $p[1], $p[0], $p[2], $p[3] ]); }return @rv;}# mount_dir(directory, device, type, options)# Mount a new directory from some device, with some options. Returns 0 if ok,# or an error string if failed. If the directory is 'swap', then mount as# virtual memory.sub mount_dir{local($out, $opts);if ($_[0] eq "swap") { # Adding a swap device $out = `swap -a $_[1] 2>&1`; if ($?) { return $out; } }else { # Mounting a directory if ($_[2] eq "cachefs") { # Mounting a caching filesystem.. need to create cache first local(%options); &parse_options("cachefs", $_[3]); if (!(-r "$options{cachedir}/.cfs_resource")) { # The cache directory does not exist.. set it up if (-d $options{cachedir} && !rmdir($options{"cachedir"})) { return "The directory $options{cachedir} ". "already exists. Delete it"; } $out = `cfsadmin -c $options{cachedir} 2>&1`; if ($?) { return $out; } } } if ($_[2] eq "rumba") { # call 'rumba' to mount local(%options, $shortname, $shar, $opts, $rv); &parse_options("rumba", $_[3]); $shortname = hostname(); if ($shortname =~ /^([^\.]+)\.(.+)$/) { $shortname = $1; } $_[1] =~ /^\\\\(.+)\\(.+)$/; $shar = "//".($options{machinename} ?$options{machinename} :$1). "/$2"; $opts = ("-s $1 "). (defined($options{'clientname'}) ? "-c $options{'clientname'} " : "-c $shortname "). (defined($options{'username'}) ? "-U $options{'username'} " : ""). (defined($options{'uid'}) ? "-u $options{'uid'} " : ""). (defined($options{'gid'}) ? "-g $options{'gid'} " : ""). (defined($options{'fmode'}) ? "-f $options{'fmode'} " : ""). (defined($options{'dmode'}) ? "-d $options{'dmode'} " : ""). (defined($options{'noupper'}) ? "-C " : ""). (defined($options{'password'}) ? "-P $options{'password'} " : "-n "). (defined($options{'readwrite'}) ? "-S " : ""). (defined($options{'readonly'}) ? "-w " : ""). (defined($options{'attr'}) ? "-e " : ""); $rv = system("rumba \"$shar\" $_[0] $opts >/tmp/$$.rumba 2>&1 </dev/null"); $out = `cat /tmp/$$.rumba`; unlink("/tmp/$$.rumba"); if ($rv) { return "<pre>$out</pre> : rumba \"$shar\" $_[0] $opts"; } } else { $opts = $_[3] eq "-" ? "" : "-o \"$_[3]\""; $out = `mount -F $_[2] $opts -- $_[1] $_[0] 2>&1`; if ($?) { return $out; } } }return 0;}# unmount_dir(directory, device, type)# Unmount a directory (or swap device) that is currently mounted. Returns 0 if# ok, or an error string if failedsub unmount_dir{if ($_[0] eq "swap") { $out = `swap -d $_[1] 2>&1`; }elsif ($_[2] eq "rumba") { # kill the process (if nobody is in the directory) $dir = $_[0]; if (`fuser -c $_[0] 2>/dev/null` =~ /\d/) { return "$_[0] is busy"; } if (`cat /etc/mnttab` =~ /rumba-(\d+)\s+$dir\s+nfs/) { kill('TERM', $1) || return "Failed to kill rumba"; } else { return "Failed to find rumba pid"; } sleep(1); }else { $out = `umount $_[0] 2>&1`; }if ($?) { return $out; }return 0;}# disk_space(type, directory)# Returns the amount of total and free space for some filesystem, or an# empty array if not appropriate.sub disk_space{if (&get_mounted($_[1], "*") < 0) { return (); }if ($_[0] eq "fd" || $_[0] eq "proc" || $_[0] eq "swap" || $_[0] eq "autofs") { return (); }`df -k $_[1]` =~ /Mounted on\n\S+\s+(\S+)\s+\S+\s+(\S+)/;return ($1, $2);}# list_fstypes()# Returns an array of all the supported filesystem types. If a filesystem is# found that is not one of the supported types, generate_location() and# generate_options() will not be called for it.sub list_fstypes{return ("ufs", "nfs", "hsfs", "pcfs", "lofs", "cachefs", "swap", "tmpfs", "autofs");}# fstype_name(type)# Given a short filesystem type, return a human-readable name for itsub fstype_name{local(%fsmap);%fsmap = ("ufs","Solaris Unix Filesystem", "nfs","Network Filesystem", "hsfs","ISO9660 CD-ROM", "pcfs","MS-DOS Filesystem", "lofs","Loopback Filesystem", "cachefs","Caching Filesystem", "swap","Virtual Memory", "tmpfs","Ram Disk", "autofs","Automounter Filesystem", "proc","Process Image Filesystem", "fd","File Descriptor Filesystem", "rumba","Windows Networking Filesystem");return $config{long_fstypes} && $fsmap{$_[0]} ? $fsmap{$_[0]} : uc($_[0]);}# mount_modes(type)# Given a filesystem type, returns 4 numbers that determine how the file# system can be mounted, and whether it can be fsck'dsub mount_modes{if ($_[0] eq "ufs" || $_[0] eq "cachefs" || $_[0] eq "s5fs") { return (2, 1, 1, 0); }elsif ($_[0] eq "rumba") { return (0, 1, 0, 0); }else { return (2, 1, 0, 0); }}# multiple_mount(type)# Returns 1 if filesystems of this type can be mounted multiple times, 0 if notsub multiple_mount{return ($_[0] eq "nfs" || $_[0] eq "tmpfs" || $_[0] eq "cachefs" || $_[0] eq "autofs" || $_[0] eq "lofs" || $_[0] eq "rumba");}# generate_location(type, location)# Output HTML for editing the mount location of some filesystem.sub generate_location{if ($_[0] eq "nfs") { # NFS mount from some host and directory if ($_[1] =~ /^nfs:/) { $nfsmode = 2; } elsif (!$_[1] || $_[1] =~ /^([A-z0-9\-\.]+):([^,]+)$/) { $nfsmode = 0; $nfshost = $1; $nfspath = $2; } else { $nfsmode = 1; } if ($gconfig{'os_version'} >= 2.6) { # Solaris 2.6 can list multiple NFS servers in mount print "<tr> <td><b>NFS Source</b></td>\n"; printf "<td><input type=radio name=nfs_serv value=0 %s>\n", $nfsmode == 0 ? "checked" : ""; print "<b>NFS Hostname</b></td>\n"; print "<td><input name=nfs_host size=20 value=\"$nfshost\">\n"; &nfs_server_chooser_button("nfs_host"); print " <b>NFS Directory</b>\n"; print "<input name=nfs_dir size=20 value=\"$nfspath\">\n"; &nfs_export_chooser_button("nfs_host", "nfs_dir"); print "</td> </tr>\n"; print "<tr> <td></td>\n"; printf "<td><input type=radio name=nfs_serv value=1 %s>\n", $nfsmode == 1 ? "checked" : ""; print "<b>Multiple NFS Servers</b></td>\n"; printf "<td><input name=nfs_list size=40 value=\"%s\">\n", $nfsmode == 1 ? $_[1] : ""; print "</td> </tr>\n"; if ($gconfig{'os_version'} >= 7) { print "<tr> <td></td> <td>\n"; printf "<input type=radio name=nfs_serv value=2 %s>\n", $nfsmode == 2 ? "checked" : ""; print "<b>WebNFS URL</b></td> <td>\n"; printf "<input name=nfs_url size=40 value=\"%s\">\n", $nfsmode == 2 ? $_[1] : ""; print "</td> </tr>\n"; } } else { print "<tr> <td><b>NFS Hostname</b></td>\n"; print "<td><input name=nfs_host size=20 value=\"$nfshost\">\n"; &nfs_server_chooser_button("nfs_host"); print "</td>\n"; print "<td><b>NFS Directory</b></td>\n"; print "<td><input name=nfs_dir size=20 value=\"$nfspath\">\n"; &nfs_export_chooser_button("nfs_host", "nfs_dir"); print "</td> </tr>\n"; } }elsif ($_[0] eq "tmpfs") { # Location is irrelevant for tmpfs filesystems
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -