#!/usr/bin/perl
# unSlider 3/5/99

use Getopt::Std;
require 'syscall.ph';

$VERSION=0.1;
getopts("afFnrsvwhVt:o:",\%opts);

$rwflag=0xC0ED0000;

if($opts{h}) {
	exec "perldoc $0";	# pod2usage seems broken
}

if($opts{V}) {
	print "$0: Perl/Linux mount $VERSION\n";
	exit;
}

if($opts{a}) {
	print "$0: fstab related options aren't yet implemented, sorry\n";
	exit 1;
}

if($opts{F}) {
	if($opts{a}) {
		print "$0: -F not yet implemented, sorry\n";
		exit 1;
	} else {
		print "$0: -F only makes sense in conjunction with -a\n";
		exit 1;
	}
}

if($opts{s}) {
	print "$0: mount options aren't yet implemented, sorry\n";
	exit 1;
}

if($opts{r}) {
	$rwflag|=1;
}

if($opts{w}) {
	$rwflag&=0xFFFFFFFE;
}

if(!defined($opts{t}) || $opts{t} eq "auto") {
	print "$0: auto filesystem recognition not yet implemented, sorry\n";
	exit 1;
}

if($opts{o}) {
	print "$0: mount options aren't yet implemented, sorry\n";
	exit 1;
}

if(!defined($device=shift)) {
	print "$0: call your operator if you need help\n";
	exit 1;
}

if(!defined($dir=shift)) {
	print "$0: i dunno how to grep the fstab yet, sorry\n";
	exit 1;
}

if($opts{v}) {
	printf("About to mount %s on %s with rwflag %X and fstype %s\n",
		$device,$dir,$rwflag,$opts{t});
}

if(!$opts{f}) {
	if(syscall(&SYS_mount,$device,$dir,$opts{t},$rwflag,0)!=0) {
		die "$!, died";
	}
} elsif($opts{v}) {
	print "(not really)\n";
}

=pod

=for man
.TH MOUNT 8 "" "March 1999" "Perl/Linux"

=head1 NAME

mount -- associate a mount point with a filesystem

=cut

=head1 OPTIONS

=over 4

=cut

=item -h

Print a usage summary and exit.

=item -V

Print the version number and exit.

=item -f

"Fake" the mount; do everything but the actual mount() system call.

=item -r

Mount read-only.

=item -w

Mount read-write.

=item -t I<foo>

Specify that the filesystem to be mounted is of type foo. Until this version
of mount supports fstab parsing, a B<-t> option is manditory.

=back

=head1 COMPATIBILITY

This command has not been evaluated for standards compliance.
Standards which may apply to this command are unknown.

=head1 BUGS

B<-h> is overly verbose.
"Call your operator if you need help" is overly flippant.

=head1 TODO

fstab parsing
mtab updating
mount options
filesystem autoprobing
auto recognition of nfs paths
loop device support
use fs.h #define's
finish the pod
when called with no arguments, display list of mounts

=head1 AUTHOR

unSlider E<lt>unslider@lisc.orgE<gt>

=head1 COPYRIGHT

(c) 1999 unSlider, all rights reserved.

This program may be distributed under the terms of the Perl Artistic License,
except that should any modifications derived from the public domain be applied
the software shall no longer be considered the Standard Version.

=head1 DISCLAIMER

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
BY USING THIS SOFTWARE YOU ACCEPT SOLE RESPONSIBILITY AND LIABILITY
FOR ALL EFFECTS ARISING FROM ITS USE. IF YOUR GENITALS SHRIVEL AND
FALL OFF, IT'S YOUR PROBLEM.

=head1 HISTORY

0.1

=cut
