#!/usr/bin/perl
# 
# Create Akai S3000 file system on specified device.
# Copyright (c) 1997, Hiroyuki Ohsaki.
# All rights reserved.
# 
# $Id: akaiformat,v 1.2 1998/09/08 06:37:04 oosaki Exp ohsaki $
# 

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

use Synth::AkaiDisk;
use Getopt::Std;
use File::Basename;
use integer;
use strict;

sub usage {
    my $prog = basename($0);
    die <<EOF
usage: $prog [-f file] [partition-size...]
 -f file  specify Akai disk image (default \$AKAI_DISK)
EOF
}

getopts('f:') || usage;

my $file = $::opt_f || $ENV{AKAI_DISK} || '/dev/mo';

# create empty file if not exist
if (!-e $file) {
    open(FILE, ">$file") || die "$file: $!\n";
    close(FILE);
}

my $disk = new Synth::AkaiDisk($file, 0, 1) || die "new: $file: $!\n";

# default for 217 MB MO disk
@ARGV || push(@ARGV, 60, 60, 60, 37);

my $prog = basename($0);
print qq($prog: format \'$file\'? );
my $answer = <STDIN>;
if ($answer =~ /^y/i) {
    $disk->format(@ARGV) || die "format: $file: $!\n";
}

__END__

=head1 NAME

akaiformat - create a new Akai file system

=head1 SYNOPSIS

  akaiformat [-f file] [partition-size...]

=head1 DESCRIPTION

This manual page documents B<akaiformat>.  This program creates a new
Akai S3000 file system on the specified I<file> with partition sizes
of I<partition-size>.  I<partition-size> is a list of desired
partition sizes in megabyte.  Without I<partition-size>, B<akaiformat>
creates four partitions of 60, 60, 60 and 37 MB, which is suitable for
217 MB MO (Magneto Optical) disks.

Note that the current version of B<akaiformat> does not check the
actual disk size and reports no error if a larger partition size than
the disk capacity is specified.  SO PLEASE MAKE SURE THE TOTAL OF
PARTITION SIZES IS LESS THAN THE ACTUAL DISK CAPACITY.

=head1 OPTIONS

=over 4

=item C<-f> file

Specify the regular file of Akai disk image or the block device file
of Akai HDD/CD-ROM as I<file>.  Usually, this should be the block
device of HDD or CD-ROM such as F</dev/sda>.  If this option is
omitted, the environment variable I<AKAI_DISK> is used as the default
device.  If I<AKAI_DISK> is not defined, F</dev/mo> is assumed.

=back

=head1 EXAMPLES

=over 4

=item Create two partitions of 50 MB

  akaiformat 50 50

=head1 SEE ALSO

akaitools(1), akaiformat(1), akailist(1), akaimkdir(1), akairead(1),
akaiwrite(1), epslist(1), epsread(1), eps2akai(1), wav2akai(1),
any2akai(1), akaiconv(1) 

=head1 AUTHOR

Hiroyuki Ohsaki <ohsaki@lsnl.jp>

=cut
