3 # fioclient.pl: A Perl version of the fioclient IOCTL client example from
4 # the FUSE distribution.
10 local $SIG{'__WARN__'} = \&Carp::cluck;
16 require 'asm/ioctl.ph';
18 our %sizeof = ('size_t' => length(pack('L!')));
19 sub FIOC_GET_SIZE { _IOR(ord 'E', 0, 'size_t'); }
20 sub FIOC_SET_SIZE { _IOW(ord 'E', 1, 'size_t'); }
24 Usage: fioclient.pl FIOC_FILE COMMAND
27 s [SIZE] : get size if SIZE is omitted, set size otherwise
28 r SIZE [OFF] : read SIZE bytes @ OFF (default 0) and output to stdout
29 w SIZE [OFF] : write SIZE bytes @ OFF (default 0) from stdin
36 usage() if scalar(@ARGV) < 2;
38 open(my $file, '+<', $ARGV[0]) or usage();
40 if ($ARGV[1] eq 's') {
41 if (!defined $ARGV[2]) {
43 my $rv = ioctl($file, FIOC_GET_SIZE, $size);
44 if (!defined($rv) || $rv != 0) {
47 printf("\%u\n", unpack('L!', $size));
50 my $rv = ioctl($file, FIOC_SET_SIZE, pack('L!', $ARGV[2]));
51 if (!defined($rv) || $rv != 0) {
56 elsif ($ARGV[1] eq 'r' || $ARGV[1] eq 'w') {
57 usage() unless defined $ARGV[2];
60 if (defined $ARGV[3]) {
63 seek($file, SEEK_SET, $off);
64 if ($ARGV[1] eq 'r') {
65 read($file, my $data, $size);
69 read(STDIN, my $data, $size);