GlusterFS-GFAPI-FFI
view release on metacpan or search on metacpan
lib/GlusterFS/GFAPI/FFI.pm view on Meta::CPAN
$FFI->attach(glfs_readdir_r => ['glfs_fd_t', 'Dirent', 'opaque*'] => 'int');
$FFI->attach(glfs_readdirplus_r => ['glfs_fd_t', 'Stat', 'Dirent', 'opaque*'] => 'int');
$FFI->attach(glfs_readdir => ['glfs_fd_t'] => 'Dirent');
$FFI->attach(glfs_readdirplus => ['glfs_fd_t', 'Stat'] => 'Dirent');
$FFI->attach(glfs_telldir => ['glfs_fd_t'] => 'long');
$FFI->attach(glfs_seekdir => ['glfs_fd_t', 'long'] => 'long');
$FFI->attach(glfs_closedir => ['glfs_fd_t'] => 'int');
$FFI->attach(glfs_statvfs => ['glfs_t', 'string', 'Statvfs'], => 'int');
$FFI->attach(glfs_chmod => ['glfs_t', 'string', 'mode_t'] => 'int');
$FFI->attach(glfs_fchmod => ['glfs_fd_t', 'mode_t'] => 'int');
$FFI->attach(glfs_chown => ['glfs_t', 'string', 'uid_t', 'gid_t'] => 'int');
$FFI->attach(glfs_lchown => ['glfs_t', 'string', 'uid_t', 'gid_t'] => 'int');
$FFI->attach(glfs_fchown => ['glfs_fd_t', 'uid_t', 'gid_t'] => 'int');
$FFI->attach(glfs_utimens => ['glfs_t', 'string', 'Timespecs'] => 'int');
$FFI->attach(glfs_lutimens => ['glfs_t', 'string', 'Timespecs'] => 'int');
$FFI->attach(glfs_futimens => ['glfs_fd_t', 'Timespecs'] => 'int');
$FFI->attach(glfs_getxattr => ['glfs_t', 'string', 'string', 'opaque', 'size_t'] => 'ssize_t');
$FFI->attach(glfs_lgetxattr => ['glfs_t', 'string', 'string', 'opaque', 'size_t'] => 'ssize_t');
$FFI->attach(glfs_fgetxattr => ['glfs_fd_t', 'string', 'opaque', 'size_t'] => 'ssize_t');
$FFI->attach(glfs_listxattr => ['glfs_t', 'string', 'opaque', 'size_t'] => 'ssize_t');
$FFI->attach(glfs_llistxattr => ['glfs_t', 'string', 'opaque', 'size_t'] => 'ssize_t');
$FFI->attach(glfs_flistxattr => ['glfs_fd_t', 'opaque', 'size_t'] => 'ssize_t');
$FFI->attach(glfs_setxattr => ['glfs_t', 'string', 'string', 'opaque', 'size_t', 'int'] => 'int');
lib/GlusterFS/GFAPI/FFI.pm view on Meta::CPAN
$retval = glfs_statvfs($fs, $path, $statvfs);
=head2 C<glfs_chmod($fs, $path, $mode)>
$retval = glfs_chmod($fs, $path, $mode);
=head2 C<glfs_fchmod($fd, $mode)>
$retval = glfs_fchmod($fd, $mode);
=head2 C<glfs_chown($fs, $path, $uid, $gid)>
$retval = glfs_chown($fs, $path, $uid, $gid);
=head2 C<glfs_lchown($fs, $path, $uid, $gid)>
$retval = glfs_lchown($fs, $path, $uid, $gid);
=head2 C<glfs_fchown($fd, $uid, $gid)>
$retval = glfs_fchown($fd, $uid, $gid);
=head2 C<glfs_utimens($fs, $path, $timespecs)>
$retval = glfs_utimens($fs, $path, $timespecs);
=head2 C<glfs_ltimens($fs, $path, $timespecs)>
$retval = glfs_ltimens($fs, $path, $timespecs);
=head2 C<glfs_ftimens($fd, $timespecs)>
lib/GlusterFS/GFAPI/FFI/File.pm view on Meta::CPAN
{
confess(sprintf("glfs_fchmod(%s, %s) failed: %s"
, $self->fd
, $args{mode} ? sprintf('0%o', $args{mode}) : '0'
, $!));
}
return $retval;
}
sub fchown
{
my $self = shift;
my %args = @_;
my $retval = GlusterFS::GFAPI::FFI::glfs_fchown($self->fd, $args{uid}, $args{gid});
if ($retval < 0)
{
confess("glfs_fchown(${\$self->fd}, $args{uid}, $args{gid}) failed: $!");
}
return $retval;
}
sub fdatasync
{
my $self = shift;
my %args = @_;
lib/GlusterFS/GFAPI/FFI/File.pm view on Meta::CPAN
=head2 fallocate
This is a Linux-specific sys call, unlike posix_fallocate()
Allows the caller to directly manipulate the allocated disk space for the file for the byte range starting at offset and continuing for length bytes.
=head2 fchmod
Change this file's mode
=head2 fchown
Change this file's owner and group id
=head2 fdatasync
Flush buffer cache pages pertaining to data, but not the ones pertaining to metadata.
=head2 fgetsize
Return the size of a file, as reported by C<fstat()>
lib/GlusterFS/GFAPI/FFI/Volume.pm view on Meta::CPAN
sprintf('glfs_chmod(%s, %s, %s) failed: %s'
, $self->fs // 'undef'
, $args{path} // 'undef'
, $args{mode} ? sprintf('0%o', $args{mode}) : 'undef'
, $!));
}
return $retval;
}
sub chown
{
my $self = shift;
my %args = @_;
my $retval = GlusterFS::GFAPI::FFI::glfs_chown(
$self->fs,
$args{path},
$args{uid},
$args{gid});
if ($retval < 0)
{
confess(
sprintf('glfs_chown(%s, %s, %s, %s) failed: %s'
, $self->fs // 'undef'
, $args{path} // 'undef'
, $args{uid} // 'undef'
, $args{gid} // 'undef'
, $!));
}
return $retval;
}
lib/GlusterFS/GFAPI/FFI/Volume.pm view on Meta::CPAN
=item C<path>
the item to be modified
=item C<mode>
new mode
=back
=head2 C<chown>
Change owner and group id of path
=head3 parameters
=over
=item C<path>
the path to be modified
diag("error: $!") if ($retval);
my $perm = $stat->st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
cmp_ok($perm, '==', 0644, ' mode : ' . sprintf('%o', $perm));
};
my ($login, $pass, $uid, $gid) = getpwuid($<);
# chown
subtest 'chown' => sub
{
my $retval = GlusterFS::GFAPI::FFI::glfs_chown($fs, "/$fname", $uid, $gid);
ok($retval == 0, sprintf('glfs_chown(): %d', $retval));
diag("error: $!") if ($retval);
};
# lchown
subtest 'lchown' => sub
{
my $retval = GlusterFS::GFAPI::FFI::glfs_lchown($fs, "/$fname", $uid, $gid);
ok($retval == 0, sprintf('glfs_lchown(): %d', $retval));
diag("error: $!") if ($retval);
};
# fchown
subtest 'fchown' => sub
{
my $retval = GlusterFS::GFAPI::FFI::glfs_fchown($fd, $uid, $gid);
ok($retval == 0, sprintf('glfs_fchown(): %d', $retval));
diag("error: $!") if ($retval);
};
# fallocate
subtest 'fallocate' => sub
{
my $retval = GlusterFS::GFAPI::FFI::glfs_fallocate($fd, 0, 0, 1024);
ok($retval == 0, sprintf('glfs_fallocate(): %d', $retval));
t/lib/TestFile.pm view on Meta::CPAN
${GlusterFS::GFAPI::FFI::}{glfs_fchmod} = $mock_glfs_fchmod;
throws_ok {
$self->{fd}->fchmod(mode => 0600);
} qr/glfs_fchmod\(${\$self->{fd}->fd}, 0600\) failed/;
${GlusterFS::GFAPI::FFI::}{glfs_fchmod} = $glfs_fchmod;
}
sub test_fchown_success : Test
{
my $self = shift;
my $mock_glfs_fchown = sub {
return 0;
};
no warnings 'redefine';
my $glfs_fchown = \&GlusterFS::GFAPI::FFI::glfs_fchown;
${GlusterFS::GFAPI::FFI::}{glfs_fchown} = $mock_glfs_fchown;
ok(!$self->{fd}->fchown(uid => 9, gid => 11)
, '$f->fchown(uid => 9, gid => 11) is returned with 0');
${GlusterFS::GFAPI::FFI::}{glfs_fchown} = $glfs_fchown;
}
sub test_fchown_exception : Test
{
my $self = shift;
my $mock_glfs_fchown = sub {
return -1;
};
no warnings 'redefine';
my $glfs_fchown = \&GlusterFS::GFAPI::FFI::glfs_fchown;
${GlusterFS::GFAPI::FFI::}{glfs_fchown} = $mock_glfs_fchown;
throws_ok {
$self->{fd}->fchown(uid => 9, gid => 11);
} qr/glfs_fchown\(${\$self->{fd}->fd}, 9, 11\) failed/;
${GlusterFS::GFAPI::FFI::}{glfs_fchown} = $glfs_fchown;
}
sub test_dup : Test(3)
{
my $self = shift;
my $mock_glfs_dup = sub {
return 2;
};
t/lib/TestVolume.pm view on Meta::CPAN
${GlusterFS::GFAPI::FFI::}{glfs_chmod} = $mock_chmod;
throws_ok {
$self->{vol}->chmod(path => 'file.txt', mode => 0600);
} qr/glfs_chmod\(${\$self->_mock_glfs_new()}, file.txt, 0600\) failed/;
${GlusterFS::GFAPI::FFI::}{glfs_chmod} = $glfs_chmod;
}
sub test_chown_success : Test
{
my $self = shift;
my $mock_chown = sub
{
return 0;
};
my $glfs_chown = \&GlusterFS::GFAPI::FFI::glfs_chown;
no warnings 'redefine';
${GlusterFS::GFAPI::FFI::}{glfs_chown} = $mock_chown;
ok($self->{vol}->chown(path => 'file.txt', uid => 9, gid => 11) == 0
, '$vol->chown has returned with 0');
${GlusterFS::GFAPI::FFI::}{glfs_chown} = $glfs_chown;
}
sub test_chown_fail_exception : Test
{
my $self = shift;
my $mock_chown = sub
{
return -1;
};
my $glfs_chown = \&GlusterFS::GFAPI::FFI::glfs_chown;
no warnings 'redefine';
${GlusterFS::GFAPI::FFI::}{glfs_chown} = $mock_chown;
throws_ok {
$self->{vol}->chown(path => 'file.txt', uid => 9, gid => 11);
} qr/glfs_chown\(${\$self->_mock_glfs_new()}, file\.txt, 9, 11\) failed/;
${GlusterFS::GFAPI::FFI::}{glfs_chown} = $glfs_chown;
}
sub test_creat_success : Test(2)
{
my $self = shift;
my %mock_info = (
call_count => 0,
args => [],
);
( run in 0.985 second using v1.01-cache-2.11-cpan-71847e10f99 )