7 use Fuse qw(fuse_get_context);
8 use POSIX qw(ENOENT EISDIR EINVAL);
17 cont => "File 'a'.\n",
23 cont => "This is file 'b'.\n",
39 $file = '.' unless length($file);
44 my ($file) = filename_fixup(shift);
46 $file = '.' unless length($file);
47 return -ENOENT() unless exists($files{$file});
48 my ($size) = exists($files{$file}{cont}) ? length($files{$file}{cont}) : 0;
49 $size = $files{$file}{size} if exists $files{$file}{size};
50 my ($modes) = ($files{$file}{type}<<9) + $files{$file}{mode};
51 my ($dev, $ino, $rdev, $blocks, $gid, $uid, $nlink, $blksize) = (0,0,0,1,0,0,1,1024);
52 my ($atime, $ctime, $mtime);
53 $atime = $ctime = $mtime = $files{$file}{ctime};
54 # 2 possible types of return values:
55 #return -ENOENT(); # or any other error you care to
56 #print(join(",",($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)),"\n");
57 return ($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks);
61 # return as many text filenames as you like, followed by the retval.
62 print((scalar keys %files)."\n");
63 return (keys %files),0;
67 # VFS sanity check; it keeps all the necessary state, not much to do here.
68 my $file = filename_fixup(shift);
69 my ($flags, $fileinfo) = @_;
70 print("open called $file, $flags, $fileinfo\n");
71 return -ENOENT() unless exists($files{$file});
72 return -EISDIR() if $files{$file}{type} & 0040;
76 print("open ok (handle $fh)\n");
81 # return an error numeric, or binary/text string. (note: 0 means EOF, "0" will
82 # give a byte (ascii "0") to the reading program)
83 my ($file) = filename_fixup(shift);
84 my ($buf, $off, $fh) = @_;
85 print "read from $file, $buf \@ $off\n";
86 print "file handle:\n", Dumper($fh);
87 return -ENOENT() unless exists($files{$file});
88 if(!exists($files{$file}{cont})) {
89 return -EINVAL() if $off > 0;
90 my $context = fuse_get_context();
91 return sprintf("pid=0x%08x uid=0x%08x gid=0x%08x\n",@$context{'pid','uid','gid'});
93 return -EINVAL() if $off > length($files{$file}{cont});
94 return 0 if $off == length($files{$file}{cont});
95 return substr($files{$file}{cont},$off,$buf);
98 sub e_statfs { return 255, 1, 1, 1, 1, 2 }
100 # If you run the script directly, it will run fusermount, which will in turn
101 # re-run this script. Hence the funky semantics.
102 my ($mountpoint) = "";
103 $mountpoint = shift(@ARGV) if @ARGV;
105 mountpoint=>$mountpoint,
106 getattr=>"main::e_getattr",
107 getdir =>"main::e_getdir",
108 open =>"main::e_open",
109 statfs =>"main::e_statfs",
110 read =>"main::e_read",