|
NAMEFuse::Simple - Simple way to write filesystems in Perl using FUSESYNOPSISuse Fuse::Simple qw(accessor main); my $var = "this is a variable you can modify. write to me!\n"; my $filesystem = { foo => "this is the contents of a file called foo\n", subdir => { "foo" => "this foo is in a subdir called subdir\n", "blah" => "this blah is in a subdir called subdir\n", }, "blah" => \ "subdir/blah", # scalar refs are symlinks "magic" => sub { return "42\n" }, # will be called to get value "var" => accessor(\$var), # read and write this variable "var2" => accessor(\$var), # and the same variable "var.b" => accessor(\ my $tmp), # and an anonymous var }; main( "mountpoint" => "/mnt", # actually optional "debug" => 0, # for debugging Fuse::Simple. optional "fuse_debug" => 0, # for debugging FUSE itself. optional "threaded" => 0, # optional "/" => $filesystem, # required :-) ); DESCRIPTIONFuse lets you write filesystems in Perl. Fuse::Simple makes this REALLY Simple, as you just need a hash for your root directory, containing strings for files, more hashes for subdirs, or functions to be called for magical functionality a bit like /proc.IMPORT TAGSFuse::Simple exports nothing by default, but individual functions can be exported, or any ofthe following tags:
MAIN FUNCTION
UTIL FUNCTIONSThese might be useful for people writing their own filesystems
FUSE FILESYSTEM FUNCTIONSThese can be overridden if you really want to get at the guts of the filesystem, but if you really wanted to get that dirty, you probably wouldn't be using Fuse::Simple, would you?
CODEREF FILES / ACCESSORScoderefs in the filesystem tree will be called (with no args) whenever they're read, and should return some contents (usually a string, but see below).They will be called with new contents and an offset if there's something to be written to them, and can return almost anything, which will be ignored unless it's an fserr(). It's also called with an empty string and an offset if it's to be truncated, and can return almost anything, which will be ignored unless it's an fserr(). sub mysub { my ($contents, $off) = @_; if (defined $contents) { # we are writing to this file } else { # we are to return the contents } } my $fs = { "magic" => \&mysub, }; Will be called like: cat /mnt/magic mysub(); # the file is being read echo "123" > /mnt/magic mysub("123\n", 0); # the file is being written : > /mnt/magic mysub("", 0); # the file is being truncated You can return a string, which is the contents of the file. You can return an fserr() for an error. You can return a hashref (your sub will look like a directory!) You can return a scalar ref (your sub will look like a symlink), etc. You can even return another coderef, which will be called with the same args. If your program die()s, you'll return ESTALE "Stale file handle". If you die(fserr(E2BIG)), you'll return that specified error. If you die(nocache("An error message\n")) you'll actually not return an error, but return a file containing that error message. It would be rather disgusting to suggest that you could also die { "README" => "Contents\n" } to return a directory, so I won't :-) Now... This isn't actually the whole story. An "ls" command will also "read" your "file", because it needs to know the length. To avoid calling your routines TOO often, the result will be cached on the first "getdir()" type operation, and then returned when you REALLY read it. The cache will then be cleared so, for example: ls /mnt/ # mysub(""); ls /mnt/magic # return cached copy ls -Fal /mnt/magic # return cached copy cat /mnt/magic # return cached copy, but clear cache cat /mnt/magic # mysub(""); and clear cache ls /mnt/magic # mysub(""); ls /mnt/magic # return cached copy echo foo >/mnt/magic # mysub("foo",0); ls /mnt/magic # mysub(""); ls /mnt/magic # return cached copy EXAMPLESsee L</SYNOPSIS> NOTESMost things apart from coderefs can't be written, and nothing can be renamed, chown()ed, deleted, etc. This is not considered a bug, but I reserve the right to add something clever in a later release :-)BUGSaccessor() is a bit thick, doesn't handle seeks, multi-block writes, etc.Please report any bugs or feature requests to <bug-fuse-simple at rt.cpan.org>, or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Fuse-Simple>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. SUPPORTAfter installing, you can find documentation for this module with the perldoc command.perldoc Fuse::Simple You can also look for information at:
ACKNOWLEDGEMENTSMany thanks to: Mark Glines, for the Fuse Perl module upon which this is based. Dobrica Pavlinusic, for maintaining it. Miklos Szeredi et al for the underlying FUSE itself.SEE ALSOFuse, by Mark Glines, <mark@glines.org>The FUSE documentation at <http://fuse.sourceforge.net/> <http://noseynick.org/> AUTHOR"Nosey" Nick Waterman of Nilex <perl@noseynick.org> <http://noseynick.org/>COPYRIGHT AND LICENSE(C) Copyright 2006 "Nosey" Nick Waterman of Nilex. All wrongs righted. All rights reserved.This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module.
Visit the GSP FreeBSD Man Page Interface. |