/[fuse.before_github]/perl/trunk/examples/example.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /perl/trunk/examples/example.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 19 - (hide annotations)
Tue Dec 27 12:47:00 2005 UTC (18 years, 3 months ago) by dpavlin
File MIME type: text/plain
File size: 2501 byte(s)
Changes from Mark Glines in preparation for 0.07
- Remove the FUSE_DEBUG constant; we never actually implemented
  it to begin with.
- "make test" now uses the version of Fuse you've just built,
  not the one installed in /usr/lib/perl5.
- getattr test now allows blksize to vary between host and fuse
  fs, as this is not a bug.
- Add experimental support for threading.  The following minor
  API changes accommodate this:
- The nonexistent (yet documented) "unthreaded=>1" attribute
  has been replaced with the "threaded=>1" attribute, and this
  time it actually exists.
- Symbolic refs like "main::e_getattr" are now allowed for
  callbacks, because threaded mode needs to share() the
  callbacks, yet perl 5.8.7 does not allow share()ing code
  refs yet.  Direct code-refs are still supported as much
  as possible (currently, non-threaded mode).
- testsuite uses a multithreaded loopback.pl, when available.
- Update docs accordingly.  Update examples accordingly.

1 dpavlin 19 #!/usr/bin/perl -w
2     use strict;
3 mszeredi 4
4     use Fuse;
5     use POSIX qw(ENOENT EISDIR EINVAL);
6    
7     my (%files) = (
8     '.' => {
9     type => 0040,
10     mode => 0755,
11     ctime => time()-1000
12     },
13     a => {
14     cont => "File 'a'.\n",
15     type => 0100,
16     mode => 0755,
17     ctime => time()-2000
18     },
19     b => {
20     cont => "This is file 'b'.\n",
21     type => 0100,
22     mode => 0644,
23     ctime => time()-1000
24     },
25     );
26    
27     sub filename_fixup {
28     my ($file) = shift;
29     $file =~ s,^/,,;
30     $file = '.' unless length($file);
31     return $file;
32     }
33    
34     sub e_getattr {
35     my ($file) = filename_fixup(shift);
36     $file =~ s,^/,,;
37     $file = '.' unless length($file);
38     return -ENOENT() unless exists($files{$file});
39     my ($size) = exists($files{$file}{cont}) ? length($files{$file}{cont}) : 0;
40     my ($modes) = ($files{$file}{type}<<9) + $files{$file}{mode};
41     my ($dev, $ino, $rdev, $blocks, $gid, $uid, $nlink, $blksize) = (0,0,0,1,0,0,1,1024);
42     my ($atime, $ctime, $mtime);
43     $atime = $ctime = $mtime = $files{$file}{ctime};
44     # 2 possible types of return values:
45     #return -ENOENT(); # or any other error you care to
46     #print(join(",",($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)),"\n");
47     return ($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks);
48     }
49    
50     sub e_getdir {
51     # return as many text filenames as you like, followed by the retval.
52     print((scalar keys %files)."\n");
53     return (keys %files),0;
54     }
55    
56     sub e_open {
57     # VFS sanity check; it keeps all the necessary state, not much to do here.
58     my ($file) = filename_fixup(shift);
59     print("open called\n");
60     return -ENOENT() unless exists($files{$file});
61     return -EISDIR() unless exists($files{$file}{cont});
62     print("open ok\n");
63     return 0;
64     }
65    
66     sub e_read {
67     # return an error numeric, or binary/text string. (note: 0 means EOF, "0" will
68     # give a byte (ascii "0") to the reading program)
69     my ($file) = filename_fixup(shift);
70     my ($buf,$off) = @_;
71     return -ENOENT() unless exists($files{$file});
72     return -EINVAL() if $off > length($files{$file}{cont});
73     return 0 if $off == length($files{$file}{cont});
74     return substr($files{$file}{cont},$off,$buf);
75     }
76    
77     sub e_statfs { return 255, 1, 1, 1, 1, 2 }
78    
79     # If you run the script directly, it will run fusermount, which will in turn
80     # re-run this script. Hence the funky semantics.
81     my ($mountpoint) = "";
82     $mountpoint = shift(@ARGV) if @ARGV;
83     Fuse::main(
84     mountpoint=>$mountpoint,
85 dpavlin 19 getattr=>"main::e_getattr",
86     getdir =>"main::e_getdir",
87     open =>"main::e_open",
88     statfs =>"main::e_statfs",
89     read =>"main::e_read",
90     threaded=>0
91 mszeredi 4 );

  ViewVC Help
Powered by ViewVC 1.1.26