GlusterFS-GFAPI-FFI
view release on metacpan or search on metacpan
lib/GlusterFS/GFAPI/FFI/File.pm view on Meta::CPAN
, $args{length}
, $!));
}
return $retval;
}
sub dup
{
my $self = shift;
my %args = @_;
my $dupfd = GlusterFS::GFAPI::FFI::glfs_dup($self->fd);
if (!defined($dupfd))
{
confess($!);
}
return __PACKAGE__->new(fd => $dupfd, path => $self->originalpath);
}
sub fallocate
{
my $self = shift;
my %args = @_;
my $retval = GlusterFS::GFAPI::FFI::glfs_fallocate($self->fd, $args{mode}, $args{offset}, $args{length});
if ($retval < 0)
{
confess(sprintf('glfs_fallocate(%s, %s, %s, %s) failed: %s'
, $self->fd
, $args{mode} ? sprintf('0%o', $args{mode}) : '0'
, $args{offset}
, $args{length}
, $!));
}
return $retval;
}
sub fchmod
{
my $self = shift;
my %args = @_;
my $retval = GlusterFS::GFAPI::FFI::glfs_fchmod($self->fd, $args{mode});
if ($retval < 0)
{
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 = @_;
my $retval = GlusterFS::GFAPI::FFI::glfs_fdatasync($self->fd);
if ($retval < 0)
{
confess("glfs_fdatasync(${\$self->fd}) failed: $!");
}
return $retval;
}
sub fgetsize
{
my $self = shift;
my %args = @_;
return $self->fstat()->st_size;
}
sub fgetxattr
{
my $self = shift;
my %args = @_;
$args{size} = 0 if (!defined($args{size}));
if ($args{size} == 0)
{
$args{size} = GlusterFS::GFAPI::FFI::glfs_fgetxattr($self->fd, $args{key}, undef, $args{size});
if ($args{size} < 0)
{
confess($!);
}
}
my $buf = "\0" x $args{size};
my $ptr = pack('P', $buf);
my $retval = GlusterFS::GFAPI::FFI::glfs_fgetxattr(
$self->fd,
$args{key},
unpack('L!', $ptr),
$args{size});
if ($retval < 0)
{
confess($!);
}
return substr($buf, 0, $retval);
}
lib/GlusterFS/GFAPI/FFI/File.pm view on Meta::CPAN
=head1 SYNOPSIS
=head1 DESCRIPTION
=head1 ATTRIBUTES
=head2 fd
=head2 originalpath
=head2 mode
=head1 CONSTRUCTOR
=head2 new
=head3 options
=head1 METHODS
=head2 fileno
Return the internal file descriptor (glfd) that is used by the underlying implementation to request I/O operations.
=head2 mode
The I/O mode for the file. If the file was created using the C<Volume->fopen()> function, this will be the value of the mode parameter. This is a read-only attribute.
=head2 name
If the file object was created using C<Volume->fopen()>, the name of the file.
=head2 closed
Bool indicating the current state of the file object. This is a read-only attribute; the C<close()> method changes the value.
=head2 close
Close the file. A closed file cannot be read or written any more.
=head2 discard
This is similar to C<UNMAP> command that is used to return the unused/freed blocks back to the storage system.
In this implementation, fallocate with C<FALLOC_FL_PUNCH_HOLE> is used to eventually release the blocks to the filesystem.
If the brick has been mounted with 'C<-o discard>' option, then the discard request will eventually reach the SCSI storage if the storage device supports C<UNMAP>.
=head2 dup
Return a duplicate of File object. This duplicate File class instance encapsulates a duplicate glfd obtained by invoking C<glfs_dup()>.
=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()>
=head2 fgetxattr
Retrieve the value of the extended attribute identified by key for the file.
=head3 parameters
=over
=item C<key>
Key of extended attribute
=item C<size>
If size is specified as zero, we first determine the size of xattr and then allocate a buffer accordingly.
If size is non-zero, it is assumed the caller knows the size of xattr.
=back
=head3 returns
Value of extended attribute corresponding to key specified.
=head2 flistxattr
Retrieve list of extended attributes for the file.
=head3 parameters
=over
=item C<size>
If size is specified as zero, we first determine the size of list and then allocate a buffer accordingly.
If size is non-zero, it is assumed the caller knows the size of the list.
=back
=head3 returns
List of extended attributes.
=head2 fsetxattr
Set extended attribute of file.
=head3 parameters
=over
( run in 0.576 second using v1.01-cache-2.11-cpan-71847e10f99 )