<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># irix-lib.pl

# supported_filesystems()
# Returns a list of filesystem types on which dumping is supported
sub supported_filesystems
{
local @rv;
push(@rv, "xfs") if (&amp;has_command("xfsdump"));
return @rv;
}

# multiple_directory_support(fs)
# Returns 1 if some filesystem dump supports multiple directories
sub multiple_directory_support
{
return 0;
}

# dump_form(&amp;dump)
sub dump_form
{
# Display destination options
print &amp;ui_table_row(&amp;hlink($text{'dump_dest'}, "dest"),
   &amp;ui_radio("mode", $_[0]-&gt;{'host'} ? 1 : 0,
	[ [ 0, $text{'dump_file'}." ".
	       &amp;ui_textbox("file", $_[0]-&gt;{'file'}, 50).
	       " ".&amp;file_chooser_button("file")."&lt;br&gt;" ],
	  [ 1, &amp;text('dump_host',
		     &amp;ui_textbox("host", $_[0]-&gt;{'host'}, 15),
		     &amp;ui_textbox("huser", $_[0]-&gt;{'huser'}, 8),
		     &amp;ui_textbox("hfile", $_[0]-&gt;{'hfile'}, 20)) ] ]), 3);
}

sub dump_options_form
{
# Display xfs dump options
print &amp;ui_table_row(&amp;hlink($text{'dump_level'},"level"),
		    &amp;ui_select("level", int($_[0]-&gt;{'level'}),
			[ map { [ $_, $text{'dump_level_'.$_} ] }
			      (0 .. 9) ]), 1, $tds);

print &amp;ui_table_row(&amp;hlink($text{'dump_label'},"label"),
		    &amp;ui_textbox("label", $_[0]-&gt;{'label'}, 15),
		    1, $tds);

print &amp;ui_table_row(&amp;hlink($text{'dump_max'},"max"),
    &amp;ui_opt_textbox("max", $_[0]-&gt;{'max'}, 8,
		    $text{'dump_unlimited'})." kB", 1, $tds);

print &amp;ui_table_row(&amp;hlink($text{'dump_attribs'},"attribs"),
		    &amp;ui_yesno_radio("attribs", int($_[0]-&gt;{'attribs'})),
		    1, $tds);

print &amp;ui_table_row(&amp;hlink($text{'dump_over'},"over"),
		    &amp;ui_yesno_radio("over", int($_[0]-&gt;{'over'})),
		    1, $tds);

print &amp;ui_table_row(&amp;hlink($text{'dump_invent'},"invent"),
		    &amp;ui_radio("noinvent", int($_[0]-&gt;{'noinvent'}),
		      [ [ 0, $text{'yes'} ], [ 1, $text{'no'} ] ]),
		    1, $tds);

print &amp;ui_table_row(&amp;hlink($text{'dump_overwrite'},"overwrite"),
	    &amp;ui_yesno_radio("overwrite", int($_[0]-&gt;{'overwrite'})),
	    1, $tds);

print &amp;ui_table_row(&amp;hlink($text{'dump_erase'},"erase"),
		    &amp;ui_yesno_radio("erase", int($_[0]-&gt;{'erase'})),
		    1, $tds);
}

# parse_dump(&amp;dump)
sub parse_dump
{
# Parse common options
if ($in{'mode'} == 0) {
	$in{'file'} =~ /\S/ || &amp;error($text{'dump_efile'});
	$_[0]-&gt;{'file'} = $in{'file'};
	delete($_[0]-&gt;{'host'});
	delete($_[0]-&gt;{'huser'});
	delete($_[0]-&gt;{'hfile'});
	}
else {
	&amp;to_ipaddress($in{'host'}) ||
	    &amp;to_ip6address($in{'host'}) ||
		&amp;error($text{'dump_ehost'});
	$_[0]-&gt;{'host'} = $in{'host'};
	$in{'huser'} =~ /^\S+$/ || &amp;error($text{'dump_ehuser'});
	$_[0]-&gt;{'huser'} = $in{'huser'};
	$in{'hfile'} || &amp;error($text{'dump_ehfile'});
	$_[0]-&gt;{'hfile'} = $in{'hfile'};
	delete($_[0]-&gt;{'file'});
	}

# Parse xfs options
&amp;is_mount_point($in{'dir'}) || &amp;error($text{'dump_emp'});
$in{'label'} =~ /^\S*$/ &amp;&amp; length($in{'label'}) &lt; 256 ||
	&amp;error($text{'dump_elabel2'});
$_[0]-&gt;{'label'} = $in{'label'};
$_[0]-&gt;{'level'} = $in{'level'};
if ($in{'max_def'}) {
	delete($_[0]-&gt;{'max'});
	}
else {
	$in{'max'} =~ /^\d+$/ || &amp;error($text{'dump_emax'});
	$_[0]-&gt;{'max'} = $in{'max'};
	}
$_[0]-&gt;{'noattribs'} = $in{'noattribs'};
$_[0]-&gt;{'over'} = $in{'over'};
$_[0]-&gt;{'noinvent'} = $in{'noinvent'};
$_[0]-&gt;{'overwrite'} = $in{'overwrite'};
$_[0]-&gt;{'erase'} = $in{'erase'};
}

# execute_dump(&amp;dump, filehandle, escape, background-mode, [time])
# Executes a dump and displays the output
sub execute_dump
{
local $fh = $_[1];
local ($cmd, $flag);
if ($_[0]-&gt;{'huser'}) {
	$flag = " -f '$_[0]-&gt;{'huser'}\@$_[0]-&gt;{'host'}:".
		&amp;date_subs($_[0]-&gt;{'hfile'}, $_[4])."'";
	}
elsif ($_[0]-&gt;{'host'}) {
	$flag = " -f '$_[0]-&gt;{'host'}:".&amp;date_subs($_[0]-&gt;{'hfile'}, $_[4])."'";
	}
else {
	$flag = " -f '".&amp;date_subs($_[0]-&gt;{'file'}, $_[4])."'";
	}
$cmd = "xfsdump -l $_[0]-&gt;{'level'}";
$cmd .= $flag;
$cmd .= " -L '$_[0]-&gt;{'label'}'" if ($_[0]-&gt;{'label'});
$cmd .= " -M '$_[0]-&gt;{'label'}'" if ($_[0]-&gt;{'label'});
$cmd .= " -z '$_[0]-&gt;{'max'}'" if ($_[0]-&gt;{'max'});
$cmd .= " -A" if ($_[0]-&gt;{'noattribs'});
$cmd .= " -F" if ($_[0]-&gt;{'over'});
$cmd .= " -J" if ($_[0]-&gt;{'noinvent'});
$cmd .= " -o" if ($_[0]-&gt;{'overwrite'});
$cmd .= " -c \"$_[3] $_[0]-&gt;{'id'}\"" if ($_[3]);
$cmd .= " -E -F" if ($_[0]-&gt;{'erase'});
$cmd .= " $_[0]-&gt;{'extra'}" if ($_[0]-&gt;{'extra'});
$cmd .= " '".&amp;date_subs($_[0]-&gt;{'dir'})."'";

&amp;system_logged("sync");
sleep(1);
&amp;additional_log('exec', undef, $cmd);
&amp;open_execute_command(CMD, "$cmd 2&gt;&amp;1 &lt;/dev/null", 1);
while(&lt;CMD&gt;) {
	if ($_[2]) {
		print $fh &amp;html_escape($_);
		}
	else {
		print $fh $_;
		}
	}
close(CMD);
return $? ? 0 : 1;
}

# dump_dest(&amp;dump)
sub dump_dest
{
if ($_[0]-&gt;{'file'}) {
	return "&lt;tt&gt;".&amp;html_escape($_[0]-&gt;{'file'})."&lt;/tt&gt;";
	}
elsif ($_[0]-&gt;{'huser'}) {
	return "&lt;tt&gt;".&amp;html_escape("$_[0]-&gt;{'huser'}\@$_[0]-&gt;{'host'}:$_[0]-&gt;{'hfile'}")."&lt;/tt&gt;";
	}
else {
	return "&lt;tt&gt;".&amp;html_escape("$_[0]-&gt;{'host'}:$_[0]-&gt;{'hfile'}")."&lt;/tt&gt;";
	}
}

# missing_restore_command(filesystem)
sub missing_restore_command
{
local $cmd = $_[0] eq 'xfs' ? 'xfsrestore' : 'restore';
return &amp;has_command($cmd) ? undef : $cmd;
}

# restore_form(filesystem)
sub restore_form
{
# Restore from
print &amp;ui_table_row(&amp;hlink($text{'restore_src'}, "rsrc"),
   &amp;ui_radio("mode", $_[1]-&gt;{'host'} ? 1 : 0,
	[ [ 0, $text{'dump_file'}." ".
	       &amp;ui_textbox("file", $_[1]-&gt;{'file'}, 50).
	       " ".&amp;file_chooser_button("file")."&lt;br&gt;" ],
	  [ 1, &amp;text('dump_host',
		     &amp;ui_textbox("host", $_[1]-&gt;{'host'}, 15),
		     &amp;ui_textbox("huser", $_[1]-&gt;{'huser'}, 8),
		     &amp;ui_textbox("hfile", $_[1]-&gt;{'hfile'}, 20)) ] ]), 3, $tds);

# Target dir
print &amp;ui_table_row(&amp;hlink($text{'restore_dir'},"rdir"),
	      &amp;ui_textbox("dir", undef, 50)." ".
	      &amp;file_chooser_button("dir", 1), 3, $tds);

# Overwrite
print &amp;ui_table_row(&amp;hlink($text{'restore_over'},"rover"),
	&amp;ui_radio("over", 0, [ [ 0, $text{'restore_over0'} ],
			       [ 1, $text{'restore_over1'} ],
			       [ 2, $text{'restore_over2'} ] ]), 3, $tds);

# Attributes?
print &amp;ui_table_row(&amp;hlink($text{'restore_noattribs'},"rnoattribs"),
	&amp;ui_radio("noattribs", 0, [ [ 0, $text{'yes'} ],
				    [ 1, $text{'no'} ] ]), 1, $tds);

# Label to restore from
print &amp;ui_table_row(&amp;hlink($text{'restore_label'},"rlabel"),
	&amp;ui_textbox("label", undef, 20), 1, $tds);

# Show only
print &amp;ui_table_row(&amp;hlink($text{'restore_test'},"rtest"),
	      &amp;ui_yesno_radio("test", 1), 1, $tds);
}

# parse_restore(filesystem)
# Parses inputs from restore_form() and returns a command to be passed to
# restore_backup()
sub parse_restore
{
local $cmd = "xfsrestore";
$cmd .= " -t" if ($in{'test'});
if ($in{'mode'} == 0) {
	$in{'file'} || &amp;error($text{'restore_efile'});
	$cmd .= " -f '$in{'file'}'";
	}
else {
	&amp;to_ipaddress($in{'host'}) ||
	    &amp;to_ip6address($in{'host'}) ||
		&amp;error($text{'restore_ehost'});
	$in{'huser'} =~ /^\S*$/ || &amp;error($text{'restore_ehuser'});
	$in{'hfile'} || &amp;error($text{'restore_ehfile'});
	if ($in{'huser'}) {
		$cmd .= " -f '$in{'huser'}\@$in{'host'}:$in{'hfile'}'";
		}
	else {
		$cmd .= " -f '$in{'host'}:$in{'hfile'}'";
		}
	}
$cmd .= " -E" if ($in{'over'} == 1);
$cmd .= " -e" if ($in{'over'} == 2);
$cmd .= " -A" if ($in{'noattribs'});
$cmd .= " -L '$in{'label'}'" if ($in{'label'});
$cmd .= " -F";
$cmd .= " $in{'extra'}" if ($in{'extra'});
if (!$in{'test'}) {
	-d $in{'dir'} || &amp;error($text{'restore_edir'});
	$cmd .= " '$in{'dir'}'";
	}
return $cmd;
}

# restore_backup(filesystem, command)
# Restores a backup based on inputs from restore_form(), and displays the results
sub restore_backup
{
&amp;additional_log('exec', undef, $_[1]);
if ($_[0] eq 'xfs') {
	# Just run the backup command
	&amp;open_execute_command(CMD, "$_[1] 2&gt;&amp;1 &lt;/dev/null", 1);
	while(&lt;CMD&gt;) {
		print &amp;html_escape($_);
		}
	close(CMD);
	return $? || undef;
	}
else {
	# Need to supply prompts
	&amp;foreign_require("proc", "proc-lib.pl");
	local ($fh, $fpid) = &amp;foreign_call("proc", "pty_process_exec", "cd '$in{'dir'}' ; $_[1]");
	local $donevolume;
	while(1) {
		local $rv = &amp;wait_for($fh, "(next volume #)", "(set owner.mode for.*\\[yn\\])", "((.*)\\[yn\\])", "(.*\\n)");
		last if ($rv &lt; 0);
		print &amp;html_escape($matches[1]);
		if ($rv == 0) {
			if ($donevolume++) {
				return $text{'restore_evolume'};
				}
			else {
				syswrite($fh, "1\n", 2);
				}
			}
		elsif ($rv == 1) {
			syswrite($fh, "n\n", 2);
			}
		elsif ($rv == 2) {
			return &amp;text('restore_equestion',
				     "&lt;tt&gt;$matches[2]&lt;/tt&gt;");
			}
		}
	close($fh);
	waitpid($fpid, 0);
	return $? || undef;
	}
}

1;

</pre></body></html>