/usr/share/doc/libfuse-perl/examples/fioclient.pl is in libfuse-perl 0.16.1-1+b3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #!/usr/bin/env perl
# fioclient.pl: A Perl version of the fioclient IOCTL client example from
# the FUSE distribution.
use strict;
no strict qw(refs);
use Carp;
local $SIG{'__WARN__'} = \&Carp::cluck;
use Fcntl qw(:mode);
use Errno qw(:POSIX);
use POSIX;
if ($^O eq 'linux') {
require 'linux/ioctl.ph';
}
else {
require 'sys/ioccom.ph';
}
our %sizeof = ('size_t' => length(pack('L!')));
sub FIOC_GET_SIZE { _IOR(ord 'E', 0, 'size_t'); }
sub FIOC_SET_SIZE { _IOW(ord 'E', 1, 'size_t'); }
sub usage {
print <<'_EOT_';
Usage: fioclient.pl FIOC_FILE COMMAND
COMMANDS
s [SIZE] : get size if SIZE is omitted, set size otherwise
r SIZE [OFF] : read SIZE bytes @ OFF (default 0) and output to stdout
w SIZE [OFF] : write SIZE bytes @ OFF (default 0) from stdin
_EOT_
exit(1);
}
usage() if scalar(@ARGV) < 2;
open(my $file, '+<', $ARGV[0]) or usage();
if ($ARGV[1] eq 's') {
if (!defined $ARGV[2]) {
my $size;
my $rv = ioctl($file, FIOC_GET_SIZE, $size);
if (!defined($rv) || $rv != 0) {
croak($!);
}
printf("\%u\n", unpack('L!', $size));
}
else {
my $rv = ioctl($file, FIOC_SET_SIZE, pack('L!', $ARGV[2]));
if (!defined($rv) || $rv != 0) {
croak($!);
}
}
}
elsif ($ARGV[1] eq 'r' || $ARGV[1] eq 'w') {
usage() unless defined $ARGV[2];
my $size = $ARGV[2];
my $off = 0;
if (defined $ARGV[3]) {
$off = $ARGV[3];
}
seek($file, SEEK_SET, $off);
if ($ARGV[1] eq 'r') {
read($file, my $data, $size);
print $data;
}
else {
read(STDIN, my $data, $size);
print $file $data;
}
}
else {
usage();
}
close($file);
|