5 use Fuse qw(fuse_get_context);
6 use POSIX qw(ENOENT EISDIR EINVAL);
15 cont => "File 'a'.\n",
21 cont => "This is file 'b'.\n",
37 $file = '.' unless length($file);
42 my ($file) = filename_fixup(shift);
44 $file = '.' unless length($file);
45 return -ENOENT() unless exists($files{$file});
46 my ($size) = exists($files{$file}{cont}) ? length($files{$file}{cont}) : 0;
47 $size = $files{$file}{size} if exists $files{$file}{size};
48 my ($modes) = ($files{$file}{type}<<9) + $files{$file}{mode};
49 my ($dev, $ino, $rdev, $blocks, $gid, $uid, $nlink, $blksize) = (0,0,0,1,0,0,1,1024);
50 my ($atime, $ctime, $mtime);
51 $atime = $ctime = $mtime = $files{$file}{ctime};
52 # 2 possible types of return values:
53 #return -ENOENT(); # or any other error you care to
54 #print(join(",",($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)),"\n");
55 return ($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks);
59 my ($path,$offset) = @_;
60 print "readdir $path $offset\n";
62 my $last = $offset + $stridelen;
64 if ($last > $#a) { $last = $#a; }
65 my @ents = map { [ $_, $a[$_] ] } $offset .. $last;
66 return @ents, $offset < $#a ? 0 : -ENOENT();
70 # VFS sanity check; it keeps all the necessary state, not much to do here.
71 my ($file) = filename_fixup(shift);
72 print("open called\n");
73 return -ENOENT() unless exists($files{$file});
74 return -EISDIR() if $files{$file}{type} & 0040;
80 # return an error numeric, or binary/text string. (note: 0 means EOF, "0" will
81 # give a byte (ascii "0") to the reading program)
82 my ($file) = filename_fixup(shift);
84 return -ENOENT() unless exists($files{$file});
85 if(!exists($files{$file}{cont})) {
86 return -EINVAL() if $off > 0;
87 my $context = fuse_get_context();
88 return sprintf("pid=0x%08x uid=0x%08x gid=0x%08x\n",@$context{'pid','uid','gid'});
90 return -EINVAL() if $off > length($files{$file}{cont});
91 return 0 if $off == length($files{$file}{cont});
92 return substr($files{$file}{cont},$off,$buf);
95 sub e_statfs { return 255, 1, 1, 1, 1, 2 }
97 # If you run the script directly, it will run fusermount, which will in turn
98 # re-run this script. Hence the funky semantics.
99 my ($mountpoint) = "";
100 $mountpoint = shift(@ARGV) if @ARGV;
102 mountpoint=>$mountpoint,
103 getattr=>"main::e_getattr",
104 # getdir =>"main::e_getdir",
105 readdir=>"main::e_readdir",
106 open =>"main::e_open",
107 statfs =>"main::e_statfs",
108 read =>"main::e_read",