-
Notifications
You must be signed in to change notification settings - Fork 0
/
pintos-set-cmdline
executable file
·42 lines (33 loc) · 1.25 KB
/
pintos-set-cmdline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /usr/bin/perl -w
use strict;
use Fcntl 'SEEK_SET';
# Read Pintos.pm from the same directory as this program.
BEGIN { my $self = $0; $self =~ s%/+[^/]*$%%; require "$self/Pintos.pm"; }
# Get command-line arguments.
usage (0) if @ARGV == 1 && $ARGV[0] eq '--help';
usage (1) if @ARGV < 2 || $ARGV[1] ne '--';
my ($disk, undef, @kernel_args) = @ARGV;
# Open disk.
my ($handle);
open ($handle, '+<', $disk) or die "$disk: open: $!\n";
# Check that it's a partitioned disk with a Pintos loader.
my ($buffer) = read_fully ($handle, $disk, 512);
unpack ("x510 v", $buffer) == 0xaa55 or die "$disk: not a partitioned disk\n";
$buffer =~ /Pintos/ or die "$disk: does not contain Pintos loader\n";
# Write the command line.
our ($LOADER_SIZE);
sysseek ($handle, $LOADER_SIZE, SEEK_SET) == $LOADER_SIZE
or die "$disk: seek: $!\n";
write_fully ($handle, $disk, make_kernel_command_line (@kernel_args));
# Close disk.
close ($handle) or die "$disk: close: $!\n";
exit 0;
sub usage {
print <<'EOF';
pintos-set-cmdline, a utility for changing the command line in Pintos disks
Usage: pintos-set-cmdline DISK -- [ARGUMENT...]
where DISK is a bootable disk containing a Pintos loader
and each ARGUMENT is inserted into the command line written to DISK.
EOF
exit ($_[0]);
}