exit code if there's a bad signature, because that's a guest error not
a host error. (If we do exit with an error code, it fouls up the
grading process.) Instead, just make sure that the host file(s) we
were supposed to retrieve is unlinked.
- get_scratch_file (defined ($_->[1]) ? $_->[1] : $_->[0]) foreach @gets;
+ # If reading fails, delete that file and all subsequent files.
+ my ($ok) = 1;
+ foreach my $get (@gets) {
+ my ($name) = defined ($get->[1]) ? $get->[1] : $get->[0];
+ $ok &&= get_scratch_file ($name);
+ if (!$ok) {
+ die "$name: unlink: $!\n" if !unlink ($name) && !$!{ENOENT};
+ }
+ }
}
# put_scratch_file($file).
}
# put_scratch_file($file).
# get_scratch_file($file).
#
# Copies from the scratch disk to $file.
# get_scratch_file($file).
#
# Copies from the scratch disk to $file.
+# Returns 1 if successful, 0 on failure.
sub get_scratch_file {
my ($get_file_name) = @_;
my ($disk_handle, $disk_file_name) = open_disk ($disks{SCRATCH});
sub get_scratch_file {
my ($get_file_name) = @_;
my ($disk_handle, $disk_file_name) = open_disk ($disks{SCRATCH});
# the file size.
my ($metadata) = read_fully ($disk_handle, $disk_file_name, 512);
my ($signature, $size) = unpack ("a4 V", $metadata);
# the file size.
my ($metadata) = read_fully ($disk_handle, $disk_file_name, 512);
my ($signature, $size) = unpack ("a4 V", $metadata);
- die "bad signature reading scratch disk--did Pintos run correctly?\n"
- if $signature ne "GET\0";
+ (print STDERR "bad signature on scratch disk--did Pintos run fail?\n"),
+ return 0
+ if $signature ne "GET\0";
# Copy file data.
my ($get_handle);
# Copy file data.
my ($get_handle);
# Skip forward in disk up to beginning of next sector.
read_fully ($disk_handle, $disk_file_name, 512 - $size % 512)
if $size % 512;
# Skip forward in disk up to beginning of next sector.
read_fully ($disk_handle, $disk_file_name, 512 - $size % 512)
if $size % 512;
}
\f
# Prepares the arguments to pass to the Pintos kernel,
}
\f
# Prepares the arguments to pass to the Pintos kernel,