+ if ( ! $snaptable || ! defined $restoreto ) {
+ print "Usage: snaprestore \"restore to slot\" \"snaptable\" \"tableno\"\n";
+ return;
+ }
+
+ if ( ! -f $snaptable ) {
+ print "Table $snaptable doesn't exist\n";
+ return;
+ }
+
+ my $table = ReadSnapShotTable($snaptable);
+ $key = FindSnapInTable($table, $restoreto);
+ if ( ! defined $table->{0} || ! defined $key ) {
+ PrintSnapShotTable($table);
+ print "No current or $restoreto slot in this table\n";
+ return;
+ }
+
+ my $currentindex = $table->{0};
+ if ( $table->{$key} == $currentindex ) {
+ print "You should not restore to the current snapshot\n";
+ return;
+ }
+
+ # swap the entries for 0 and $restoreto
+ my $tmp = $table->{$key};
+ $table->{$key} = $table->{0};
+ $table->{0} = $tmp;
+ PrintSnapShotTable($table);
+
+ # write it back
+ WriteSnapShotTable($snaptable, $table);
+
+ # set it in the kernel
+ SnapSetTable($tableno, $snaptable);
+
+ # ready for the ioctl