Add fix for RT #71271.
[perl-fuse.git] / examples / example.pl
old mode 100644 (file)
new mode 100755 (executable)
index 4a7b971..f25a997
@@ -1,7 +1,10 @@
 #!/usr/bin/perl -w
 use strict;
 
-use Fuse;
+use Data::Dumper;
+
+#use blib;
+use Fuse qw(fuse_get_context);
 use POSIX qw(ENOENT EISDIR EINVAL);
 
 my (%files) = (
@@ -22,6 +25,12 @@ my (%files) = (
                mode => 0644,
                ctime => time()-1000
        },
+       me => {
+               size => 45,
+               type => 0100,
+               mode => 0644,
+               ctime => time()-1000
+       },
 );
 
 sub filename_fixup {
@@ -37,6 +46,7 @@ sub e_getattr {
        $file = '.' unless length($file);
        return -ENOENT() unless exists($files{$file});
        my ($size) = exists($files{$file}{cont}) ? length($files{$file}{cont}) : 0;
+       $size = $files{$file}{size} if exists $files{$file}{size};
        my ($modes) = ($files{$file}{type}<<9) + $files{$file}{mode};
        my ($dev, $ino, $rdev, $blocks, $gid, $uid, $nlink, $blksize) = (0,0,0,1,0,0,1,1024);
        my ($atime, $ctime, $mtime);
@@ -55,20 +65,31 @@ sub e_getdir {
 
 sub e_open {
        # VFS sanity check; it keeps all the necessary state, not much to do here.
-       my ($file) = filename_fixup(shift);
-       print("open called\n");
+    my $file = filename_fixup(shift);
+    my ($flags, $fileinfo) = @_;
+    print("open called $file, $flags, $fileinfo\n");
        return -ENOENT() unless exists($files{$file});
-       return -EISDIR() unless exists($files{$file}{cont});
-       print("open ok\n");
-       return 0;
+       return -EISDIR() if $files{$file}{type} & 0040;
+    
+    my $fh = [ rand() ];
+    
+    print("open ok (handle $fh)\n");
+    return (0, $fh);
 }
 
 sub e_read {
        # return an error numeric, or binary/text string.  (note: 0 means EOF, "0" will
        # give a byte (ascii "0") to the reading program)
        my ($file) = filename_fixup(shift);
-       my ($buf,$off) = @_;
+    my ($buf, $off, $fh) = @_;
+    print "read from $file, $buf \@ $off\n";
+    print "file handle:\n", Dumper($fh);
        return -ENOENT() unless exists($files{$file});
+       if(!exists($files{$file}{cont})) {
+               return -EINVAL() if $off > 0;
+               my $context = fuse_get_context();
+               return sprintf("pid=0x%08x uid=0x%08x gid=0x%08x\n",@$context{'pid','uid','gid'});
+       }
        return -EINVAL() if $off > length($files{$file}{cont});
        return 0 if $off == length($files{$file}{cont});
        return substr($files{$file}{cont},$off,$buf);