+ } else {
+ die "fsys $tf ?";
+ }
+
+ $fsidstr= $pcstr.$atf;
+ $fsidstr =~ s/[,+]/+$&/g;
+ $fsidstr =~ s#/#,#g;
+ $fsidfile= "/var/lib/chiark-backup/incstamp,$fsidstr";
+
+ $dev = $atf =~ s,^(.*)\:,, ? $1 : '';
+
+ if (!length $pcstr) {
+ stat $atf or die "stat $atf: $!";
+ -d _ or die "not a dir: $atf";
+ }
+
+ undef %dopt;
+ foreach $dopt (split /\,/,$dopts) {
+ if (grep { $dopt eq $_ } qw(gz noinc)) {
+ $dopt{$dopt}= 'y';
+ } elsif (grep { $dopt eq $_ } qw(snap)) {
+ $dopt{$dopt}= $dopt;
+ } elsif ($dopt =~ m/\=/ && grep { $` eq $_ } qw(gz snap)) {
+ $dopt{$`}= $';
+ } elsif (length $dopt) {
+ die "unknown option $dopt (in $dopts $tf)";
+ }
+ }
+
+ my ($gzo);
+ foreach $gzo (qw(gz gzi)) {
+ if ($dopt{$gzo} eq 'y') {
+ $$gzo= '1';
+ } elsif ($dopt{$gzo} =~ m/^\d$/) {
+ $$gzo= $dopt{$gzo};
+ } elsif (defined $dopt{$gzo}) {
+ die "$tf bad $gzo";
+ } else {
+ $$gzo= '';
+ }
+ }
+
+ if (length $dopt{'snap'}) {
+ length $dev or die "$pcstr:$atf no device but needed for snap";
+ }
+}
+
+sub execute ($) {
+ pboth(" $_[0]\n");
+ system $_[0]; $? and die "$_[0] $?";
+}
+
+sub prepfsys () {
+ $dev_print= $dev;
+ $atf_print= $atf;
+
+ if (length $dopt{'snap'}) {
+
+ system('snap-drop'); $? and die $?;
+
+ $snapscripts= '/etc/chiark-backup/snap';
+ $snapbase= "$rstr $snapscripts/$dopt{'snap'}";
+ $snapargs= "/var/lib/chiark-backup";
+
+ $snapsnap= "$snapbase snap $snapargs $dev $atf";
+ $snapdrop= "$snapbase drop $snapargs";
+
+ open SD, ">snap-drop.new" or die $!;
+ print SD $snapdrop,"\n" or die $!;
+ close SD or die $!;
+ rename "snap-drop.new","snap-drop" or die $!;
+
+ execute($snapsnap);
+
+ $dev_nosnap= $dev;
+ $atf_nosnap= $atf;
+ $dev= "/var/lib/chiark-backup/snap-device";
+ $atf= "/var/lib/chiark-backup/snap-mount";
+ }
+}
+
+sub finfsys () {
+ if (length $dopt{'snap'}) {
+ system('snap-drop'); $? and die $?;