head	1.1;
branch	1.1.1;
access;
symbols
	start:1.1.1.1
	project:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2009.11.02.13.19.54;	author zeon0214;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2009.11.02.13.19.54;	author zeon0214;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Initial revision
@
text
@#! /usr/bin/perl

use strict;
use warnings;
use POSIX;
use Getopt::Long;
use Fcntl 'SEEK_SET';

GetOptions ("h|help" => sub { usage (0); })
  or exit 1;
usage (1) if @@ARGV != 2;

my ($disk, $mb) = @@ARGV;
die "$disk: already exists\n" if -e $disk;
die "\"$mb\" is not a valid size in megabytes\n"
  if $mb <= 0 || $mb > 1024 || $mb !~ /^\d+(\.\d+)?|\.\d+/;

my ($cyl_cnt) = ceil ($mb * 2);
my ($cyl_bytes) = 512 * 16 * 63;
my ($bytes) = $cyl_bytes * $cyl_cnt;

open (DISK, '>', $disk) or die "$disk: create: $!\n";
sysseek (DISK, $bytes - 1, SEEK_SET) or die "$disk: seek: $!\n";
syswrite (DISK, "\0", 1) == 1 or die "$disk: write: $!\n";
close (DISK) or die "$disk: close: $!\n";

sub usage {
    print <<'EOF';
pintos-mkdisk, a utility for creating Pintos virtual disks
Usage: pintos DISKFILE MB
where DISKFILE is the file to use for the disk
  and MB is the disk size in (approximate) megabytes.
Options:
  -h, --help        Display this help message.
EOF
    exit (@@_);
}
@


1.1.1.1
log
@YOO_PJ2
@
text
@@
