Fuse-Class
view release on metacpan or search on metacpan
test/fuse28.pm view on Meta::CPAN
my $t = time;
my $self = {
# ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
# $atime,$mtime,$ctime,$blksize,$blocks)
attr => [0, $last_ino++, 0, 1, $>+0, $)+0, 0, 0,
$t, $t, $t, 1024, 0],
};
$self->{attr}->[8] = $t;
$self->{attr}->[9] = $t;
$self->{attr}->[10] = $t;
bless $self, $class;
}
sub attr {
my $self = shift;
return @{$self->{attr}};
}
sub chmod {
my $self = shift;
my ($modes) = @_;
my $attr = $self->{attr}->[2] & ~(07777);
$self->{attr}->[2] = $attr | $modes;
return 0;
}
sub utimens {
my $self = shift;
my ($atime, $mtime) = @_;
my $attr = $self->{attr};
$attr->[8] = $atime if ($atime >= 0);
$attr->[9] = $mtime if ($mtime >= 0);
return 0;
}
sub chown {
my $self = shift;
my ($uid, $gid) = @_;
$self->{attr}->[4] = $uid if ($uid >= 0);
$self->{attr}->[5] = $gid if ($gid >= 0);
return 0;
}
#
# Directory
#
package test::fuse28::Directory;
use Fcntl qw(:mode);
use base qw(test::fuse28::Entity);
use Scalar::Util qw(weaken);
sub new {
my $class = shift;
my $parent = shift;
my $self = $class->SUPER::new;
$self->{attr}->[2] = S_IFDIR | S_IRWXU;
if (!defined($parent)) {
$self->{parent} = $self;
}
else {
$self->{parent} = $parent;
}
$self->{children} = {};
# avoid cyclic reference
weaken($self->{parent});
bless $self, $class;
}
sub parent {
my $self = shift;
return $self->{parent};
}
sub entity {
my $self = shift;
my $name = shift;
return $self if ($name eq '.');
return $self->parent if ($name eq '..');
return $self->{children}->{$name};
}
sub readdir {
my $self = shift;
return ('..', '.', keys %{$self->{children}});
}
sub mknod {
my $self = shift;
my ($name, $mode, $devno) = @_;
my $umask = 0;
$umask |= S_IRUSR if ($mode & 0400);
$umask |= S_IWUSR if ($mode & 0200);
$umask |= S_IXUSR if ($mode & 0100);
$umask |= S_IRGRP if ($mode & 0040);
$umask |= S_IWGRP if ($mode & 0020);
$umask |= S_IXGRP if ($mode & 0010);
$umask |= S_IROTH if ($mode & 0004);
$umask |= S_IWOTH if ($mode & 0002);
$umask |= S_IXOTH if ($mode & 0001);
if (S_ISREG($mode)) {
my $newfile = test::fuse28::File->new;
my $attr = S_IFREG | $umask;
$newfile->{attr}->[2] = $attr;
$self->{children}->{$name} = $newfile;
return 0;
}
if (S_ISDIR($mode)) {
return $self->mkdir($name, $mode);
}
if (S_ISLNK($mode)) {
return -1;
}
if (S_ISBLK($mode)) {
return -1;
}
if (S_ISCHR($mode)) {
return -1;
}
if (S_ISFIFO($mode)) {
test/fuse28.pm view on Meta::CPAN
my ($name, $existing) = @_;
my $link = test::fuse28::Symlink->new($existing);
my $attr = S_IFLNK | 0777;
$link->{attr}->[2] = $attr;
$self->{children}->{$name} = $link;
return 0;
}
#
# Normal File
#
package test::fuse28::File;
use base qw(test::fuse28::Entity);
sub new {
my $class = shift;
my $self = $class->SUPER::new;
$self->{content} = '';
bless $self, $class;
}
sub write {
my $self = shift;
my ($buffer, $offset) = @_;
substr($self->{content}, $offset) = $buffer;
$self->{attr}->[7] = length($self->{content});
$self->{attr}->[12] = int(($self->{attr}->[7] + $self->{attr}->[11] - 1) / $self->{attr}->[11]);
return length($buffer);
}
sub read {
my $self = shift;
my ($size, $offset) = @_;
return substr($self->{content}, $offset, $size);
}
sub truncate {
my $self = shift;
my ($offset) = @_;
$self->{content} = substr($self->{content}, 0, $offset);
$self->{attr}->[7] = length($self->{content});
return 0;
}
#
# Symlink
#
package test::fuse28::Symlink;
use base qw(test::fuse28::Entity);
use Scalar::Util qw(weaken);
sub new {
my $class = shift;
my ($existing) = @_;
my $self = $class->SUPER::new;
$self->{link} = $existing;
bless $self, $class;
}
sub readlink {
my $self = shift;
return $self->{link};
}
1;
( run in 1.335 second using v1.01-cache-2.11-cpan-39bf76dae61 )