- create_disk ($file, $mb * 1008);
- exit 0;
- } elsif ($arg eq 'put') {
- usage () if @ARGV != 1 && @ARGV != 2;
- my ($hostfn, $guestfn) = @ARGV;
- $guestfn = $hostfn if !defined $guestfn;
-
- # Create scratch disk from file.
- die "$hostfn: $!\n" if ! -e $hostfn;
- my ($size) = -s _;
- copy_pad ($hostfn, "scratch.dsk", 512);
-
- # Do copy.
- run_vm ("-ci", $hostfn, $size, "-q");
- exit 0;
- } elsif ($arg eq 'get') {
- usage () if @ARGV != 1 && @ARGV != 2;
- my ($guestfn, $hostfn) = @ARGV;
- $hostfn = $guestfn if !defined $hostfn;
- die "$hostfn: already exists\n" if -e $file;
-
- # Create scratch disk big enough for any file in the filesystem
- # (modulo sparse files).
- die "fs.dsk: $!\n" if ! -e "fs.dsk";
- my ($fs_size) = -s _;
- my ($scratch_size) = -s "scratch.dsk";
- $scratch_size = 0 if !defined $scratch_size;
- create_disk ("scratch.dsk", $fs_size / 1024 + 16)
- if $scratch_size < $fs_size + 16384;
-
- # Do copy.
- run_vm ("-co", $guestfn, "-q");
-
- # Read out scratch disk.
- print "copying $guestfn from scratch.dsk to $hostfn...\n";
- open (SRC, "<scratch.dsk") or die "scratch.dsk: open: $!\n";
- open (DST, ">$hostfn") or die "$hostfn: create: $!\n";
- my ($input);
- read (SRC, $input, 512) == 512 or die "scratch.dsk: read error\n";
- my ($size) = unpack ("%V", $input);
- $size != 0xffffffff or die "$guestfn: too big for scratch.dsk?";
- read (SRC, $src, $size) == $size or die "scratch.dsk: read error\n";
- print DST $src or die "$hostfn: write error\n";
- close (DST);
- close (SRC);
-
- exit 0;
- } elsif ($arg eq 'help' || $arg eq '--help') {
- usage (0);
- } else {
- die "unknown option `$arg'\n";
+sub cmd_option {
+ # Force an end to option processing, as with --.
+ die ("!FINISH");
+}
+
+die "no command specified; use --help for help\n"
+ if @ARGV < 1;
+my ($cmd) = shift @ARGV;
+if ($cmd eq 'run') {
+ run_vm (@ARGV);
+} elsif ($cmd eq 'make-disk') {
+ usage () if @ARGV != 2;
+ my ($file, $mb) = @ARGV;
+ usage () if $mb !~ /^\d+(\.\d+)?|\.\d+$/;
+ die "$file: already exists\n" if -e $file;
+
+ create_disk ($file, int ($mb * 1008));
+} elsif ($cmd eq 'put') {
+ # Take a -f option to combine formatting with putting.
+ my ($format) = 0;
+ if (@ARGV > 0 && $ARGV[0] eq '-f') {
+ shift @ARGV;
+ $format = 1;