2 |
use strict; |
use strict; |
3 |
|
|
4 |
use blib; |
use blib; |
5 |
use Fuse; |
use Fuse qw(fuse_get_context); |
6 |
use POSIX qw(ENOENT EISDIR EINVAL); |
use POSIX qw(ENOENT EISDIR EINVAL); |
7 |
|
|
8 |
my (%files) = ( |
my (%files) = ( |
23 |
mode => 0644, |
mode => 0644, |
24 |
ctime => time()-1000 |
ctime => time()-1000 |
25 |
}, |
}, |
26 |
|
me => { |
27 |
|
size => 45, |
28 |
|
type => 0100, |
29 |
|
mode => 0644, |
30 |
|
ctime => time()-1000 |
31 |
|
}, |
32 |
); |
); |
33 |
|
|
34 |
sub filename_fixup { |
sub filename_fixup { |
44 |
$file = '.' unless length($file); |
$file = '.' unless length($file); |
45 |
return -ENOENT() unless exists($files{$file}); |
return -ENOENT() unless exists($files{$file}); |
46 |
my ($size) = exists($files{$file}{cont}) ? length($files{$file}{cont}) : 0; |
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}; |
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); |
my ($dev, $ino, $rdev, $blocks, $gid, $uid, $nlink, $blksize) = (0,0,0,1,0,0,1,1024); |
50 |
my ($atime, $ctime, $mtime); |
my ($atime, $ctime, $mtime); |
66 |
my ($file) = filename_fixup(shift); |
my ($file) = filename_fixup(shift); |
67 |
print("open called\n"); |
print("open called\n"); |
68 |
return -ENOENT() unless exists($files{$file}); |
return -ENOENT() unless exists($files{$file}); |
69 |
return -EISDIR() unless exists($files{$file}{cont}); |
return -EISDIR() if $files{$file}{type} & 0040; |
70 |
print("open ok\n"); |
print("open ok\n"); |
71 |
return 0; |
return 0; |
72 |
} |
} |
77 |
my ($file) = filename_fixup(shift); |
my ($file) = filename_fixup(shift); |
78 |
my ($buf,$off) = @_; |
my ($buf,$off) = @_; |
79 |
return -ENOENT() unless exists($files{$file}); |
return -ENOENT() unless exists($files{$file}); |
80 |
|
if(!exists($files{$file}{cont})) { |
81 |
|
return -EINVAL() if $off > 0; |
82 |
|
my $context = fuse_get_context(); |
83 |
|
return sprintf("pid=0x%08x uid=0x%08x gid=0x%08x\n",@$context{'pid','uid','gid'}); |
84 |
|
} |
85 |
return -EINVAL() if $off > length($files{$file}{cont}); |
return -EINVAL() if $off > length($files{$file}{cont}); |
86 |
return 0 if $off == length($files{$file}{cont}); |
return 0 if $off == length($files{$file}{cont}); |
87 |
return substr($files{$file}{cont},$off,$buf); |
return substr($files{$file}{cont},$off,$buf); |