Fuse-TagLayer

 view release on metacpan or  search on metacpan

lib/Fuse/TagLayer.pm  view on Meta::CPAN

		my ($modes) = (0040<<9) + 0775;
		my ($dev, $ino, $rdev, $blocks, $uid, $gid, $nlink, $blksize) = (0,0,0,1,$self->{uid},$self->{gid},1,1024);
		my $size = 0;
		$blocks = $size;
		my ($atime, $ctime, $mtime);
		$atime = $ctime = $mtime = $self->{db_epoch};

		return ($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks);
	}
	return -ENOENT(); # never
}

sub real_open {
	my ($path,$mode) = @_;

	## find which file exactly is meant here
	my $file = file_by_tagpath($path);

	return -ENOSYS() if !$file;
	return -ENOENT() unless -e $file;

	my $fh;
	sysopen($fh,$file,$mode) or return -$!;

	return (0, $fh);
}

sub real_read {
	my ($path,$bufsize,$off,$fh) = @_;

	my $rv = -ENOSYS();

	if(seek($fh,$off,SEEK_SET)) {
		read($fh,$rv,$bufsize);
	}

	return $rv;
}

sub real_release {
	my ($path,$mode,$fh) = @_;

	close($fh) or return -$!;

	return 0;
}

sub virt_statfs { return 255, 1, 1, 1, 1, 2 }

sub umount {
	db_disconnect();
}


1;

__END__

=head1 NAME

Fuse::TagLayer - A read-only tag-filesystem overlay for hierarchical filesystems

=head1 SYNOPSIS

  use Fuse::TagLayer;
  my $ftl = Fuse::PerlSSH::FS->new(
	realdir		=> '/some/local/path',
	mountpoint	=> '/some/local/mountpoint',
	debug		=> 2,
  );
  $ftl->mount();

The bundled L<taglayer> mounting script uses this module here, I<Fuse::TagLayer>,
as its backend. On mount, it scans a specified dir for tags and mounts them as
the TagLayer filesystem at the mountpoint, by default /path/to/specified-dir/+tags.

  taglayer <real directory> [<tag directory mountpoint>]

=head1 DESCRIPTION

Fuse::TagLayer offers all the tags found in one subdir/volume as a tag-based file-system
at the mountpoint you specify, currently read-only. This is in addition to the real
filesystem which is considered to be 'canonical' - with the tag-file-system being
just another "layer" to access these files (thus the name).

=head2 How it works

Fuse::TagLayer, on mount, scans a specified dir-path and gathers all the tags found
in the files' "user.tags" extended-attribute. These xattr-tags are supplemented
by "tags" derrived from what could be called "directory fragments". That means,
a path like "/Path/to/file" is interpreted as being the tags "Path" and "to" (dropping
the filename as source for tags for now). All these tags then are inserted into
a database backend (SQLite or a pure Perl one) and the db is used to expose a tag-based
file system at the mountpoint.

=head1 METHODS

Right now, the module offers some OO-ish methods, and some plain functions. The
mounting script uses the below OO methods new(), mount() and umount(). But note
the quirk that $self is stored in a global I<our> variable, to mediate between the
OO API and the Fuse-style functions.

=head2 new()

=head2 mount()

=head2 umount()

=head1 FUNCTIONS

A growing list of functions that match the FUSE bindings, some prefixed by "virt_"
and some by "real_". The latter faciliating the loopback/ pass-through to the real
filesystem:

  virt_readdir()
  virt_getattr()
  real_getattr()
  real_open()
  real_read()
  real_release()



( run in 0.525 second using v1.01-cache-2.11-cpan-2398b32b56e )