fuse
changeset 12 46a3e65e850f
parent 5 bef1e4dd8e85
child 15 f218b05f1da4
equal deleted inserted replaced
11:675ef249d116 12:46a3e65e850f
     4 use strict;
     4 use strict;
     5 use warnings;
     5 use warnings;
     6 use autodie qw(:all);
     6 use autodie qw(:all);
     7 use Getopt::Long;
     7 use Getopt::Long;
     8 use Fuse;
     8 use Fuse;
     9 
     9 use POSIX qw(setpgid);
    10 my $opt_debug = 0;
    10 use Pod::Usage;
    11 
    11 use Hash::Util qw(lock_keys);
    12 GetOptions("debug!" => \$opt_debug)
    12 use File::Basename;
    13 	and @ARGV == 2
    13 
    14 	or die "Bad Usage\n";
    14 my %o = (
    15 
    15     debug => undef,
    16 my $src = shift;
    16     detach => 1,
    17 my $mp = shift;
    17 ); lock_keys %o;
    18 
    18 
    19 $fs::DATA = "$src/data";
    19 use constant ME => basename $0;
    20 $fs::IDX = "$src/idx";
    20 
    21 
    21 MAIN: {
    22 Fuse::main(mountpoint => $mp,
    22 
    23     debug => $opt_debug,
    23     GetOptions(
    24     getattr => "fs::getattr",
    24 	"d|debug!" => \$o{debug},
    25     getdir => "fs::getdir",
    25 	"detach!" => \$o{detach},
    26     open => "fs::openfile",
    26 	"h|help" => sub { pod2usage(-verbose => 1, -exit => 0) },
    27     read => "fs::readbuffer",
    27 	"m|man" =>  sub { pod2usage(-verbose => 2, -exit => 0,
    28     write => "fs::writebuffer",
    28 		-noperlpod => system("perldoc -V 1>/dev/null 2>&1")) },
    29     );
    29 	) and @ARGV == 2 or pod2usage;
    30 
    30 
       
    31     my ($src, $mp) = @ARGV;
       
    32 
       
    33     $fs::DATA = "$src/data";
       
    34     $fs::IDX = "$src/idx";
       
    35 
       
    36     die ME.": $fs::DATA: $!" if not -d $fs::DATA;
       
    37     die ME.": $fs::IDX: $!" if not -d $fs::IDX;
       
    38 
       
    39     if (!$o{debug} and $o{detach}) {
       
    40 	fork() and exit;
       
    41 	$0 = "FUSE $src $mp";
       
    42 	open(STDOUT => ">/dev/null");
       
    43 	open(STDIN => "/dev/null");
       
    44 
       
    45 	setpgid($$ => $$);
       
    46     }
       
    47 
       
    48 
       
    49     Fuse::main(mountpoint => $mp,
       
    50 	debug => $o{debug} // 0,
       
    51 	getattr => "fs::getattr",
       
    52 	getdir => "fs::getdir",
       
    53 	open => "fs::openfile",
       
    54 	read => "fs::readbuffer",
       
    55 	write => "fs::writebuffer",
       
    56 	);
       
    57 
       
    58 }
    31 
    59 
    32 { package fs;
    60 { package fs;
    33   use strict;
    61   use strict;
    34   use warnings;
    62   use warnings;
    35   use POSIX qw(:errno_h); 
    63   use POSIX qw(:errno_h); 
   177 	}
   205 	}
   178 	return %meta;
   206 	return %meta;
   179     }
   207     }
   180 
   208 
   181 }
   209 }
       
   210 
       
   211 __END__
       
   212 
       
   213 =head1 NAME
       
   214 
       
   215     fuse - the fuse mount helper for imagers backups
       
   216 
       
   217 =head1 SYNOPSIS
       
   218 
       
   219     fuse [options] {src} {mount point}
       
   220 
       
   221 =head1 DESCRIPTION
       
   222 
       
   223 B<fuse> mounts the src directory (containing F<data/> and F<idx/>
       
   224 directories) the the specified mount point.
       
   225 
       
   226 =head1 OPTIONS
       
   227 
       
   228 =over 4
       
   229 
       
   230 =item B<-d>|B<--debug>
       
   231 
       
   232 Enables debugging output from B<Fuse>. When using this option,
       
   233 B<Fuse> does not detach from the terminal. (default: off)
       
   234 
       
   235 =item B<-->I<[no]>B<detach> 
       
   236 
       
   237 Detach or don't detach from the terminal. (default: detach)
       
   238 
       
   239 =item B<-h>|B<--help>
       
   240 
       
   241 =item B<-m>|B<--man>
       
   242 
       
   243 The common help and man options.
       
   244 
       
   245 =back
       
   246 
       
   247 =cut