• R/O
  • SSH
  • HTTPS

perl-fuse-fv: Commit


Commit MetaInfo

Revision66 (tree)
Zeit2011-05-30 00:00:05
Autortofjw

Log Message

add test module for fuse 2.8 (using file/directory handle)

Ändern Zusammenfassung

Diff

--- Fuse-Class/trunk/test/test28.pm (nonexistent)
+++ Fuse-Class/trunk/test/test28.pm (revision 66)
@@ -0,0 +1,275 @@
1+#
2+# test filesystem for Fuse 2.8
3+# (file operations are done via file/directory handle.)
4+#
5+
6+use strict;
7+use warnings;
8+
9+use Fcntl;
10+
11+package test::test28;
12+
13+use base qw(Fuse::Class);
14+
15+sub new {
16+ my $class = shift;
17+
18+ my $t = 12345;
19+
20+ my $self = {
21+ content => {
22+ '/' => {
23+ attr => [0, 0,
24+ Fcntl::S_IFDIR
25+ | Fcntl::S_IRWXU | Fcntl::S_IRWXG | Fcntl::S_IRWXO,
26+ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
27+ }
28+ },
29+
30+ handle => {
31+ }
32+ };
33+
34+ use Data::Dumper;
35+ print Dumper($self);
36+ return bless $self, $class;
37+}
38+
39+sub issue_handle {
40+ my $self = shift;
41+ my ($path) = @_;
42+
43+ my $i = 0;
44+ while ($self->{handle}->{$i}) {
45+ $i++;
46+ }
47+
48+ $self->{handle}->{$i} = [$path, $self->{content}->{$path}];
49+
50+ return $i;
51+}
52+
53+sub release_handle {
54+ my $self = shift;
55+ my ($fh) = @_;
56+
57+ delete $self->{handle}->{$fh};
58+}
59+
60+sub getattr {
61+ my $self = shift;
62+ my ($path) = @_;
63+
64+ return -2 unless ($self->{content}->{$path});
65+
66+ return @{$self->{content}->{$path}->{attr}};
67+}
68+
69+sub readlink {
70+ my $self = shift;
71+
72+ return '/readlink/result';
73+}
74+
75+sub getdir {
76+ my $self = shift;
77+ my ($path) = @_;
78+
79+ die "this function must not be called.";
80+}
81+
82+sub mknod {
83+ my $self = shift;
84+ my ($path, $mode, $devno) = @_;
85+
86+ return -1 if ($self->{content}->{$path});
87+
88+ my $t = time;
89+
90+ $self->{content}->{$path} = {
91+ attr => [0, 0, $mode, 1,
92+ $>+0, $)+0, $devno, 0, $t, $t, $t,
93+ 4096, 0,
94+ ],
95+ content => '',
96+ };
97+ return 0;
98+}
99+
100+sub mkdir {
101+ my $self = shift;
102+ my ($path, $mode) = @_;
103+
104+ return -1 if ($self->{content}->{$path});
105+
106+ $mode |= Fcntl::S_IFDIR;
107+ my $t = time;
108+
109+ $self->{content}->{$path} = {
110+ attr => [0, 0, $mode, 1,
111+ $>+0, $)+0, 0, 0, $t, $t, $t,
112+ 1, 0,
113+ ],
114+ content => '',
115+ };
116+ return 0;
117+}
118+
119+sub unlink {
120+ my $self = shift;
121+ my ($path) = @_;
122+
123+ delete $self->{content}->{$path};
124+
125+ return 0;
126+}
127+
128+sub rmdir {
129+ my $self = shift;
130+ my ($path) = @_;
131+
132+ my $s = '/';
133+ my $prefix = $path;
134+ $prefix .= $s unless ($prefix =~ /\Q$s\E$/);
135+
136+ my @names = grep { m|^\Q$prefix\E| } keys %{$self->{content}};
137+ unshift(@names, $path);
138+
139+ for my $p (@names) {
140+ delete $self->{content}->{$p};
141+ }
142+
143+ use Data::Dumper;
144+ print STDERR Dumper($self);
145+
146+ return 0;
147+}
148+
149+sub opendir {
150+ my $self = shift;
151+ my ($path) = @_;
152+
153+ return (-2) unless ($self->{content}->{$path});
154+
155+ return (0, $self->issue_handle($path));
156+}
157+
158+sub readdir {
159+ my $self = shift;
160+ my ($path, $offset, $dh) = @_;
161+
162+ return (-2) unless (defined($self->{handle}->{$dh}));
163+
164+ my $s = '/';
165+ my $prefix = $self->{handle}->{$dh}->[0];
166+ $prefix .= $s unless ($prefix =~ /\Q$s\E$/);
167+
168+ my @names =
169+ map { substr($_, length($prefix)) }
170+ sort
171+ grep { m|^\Q$prefix\E[^\Q$s\E]+$| } keys %{$self->{content}};
172+
173+ unshift(@names, '.');
174+
175+ if ($offset < @names) {
176+ return (@names[$offset..$#names], 0);
177+ }
178+
179+ return (0);
180+}
181+
182+sub releasedir {
183+ my $self = shift;
184+ my ($path, $dh) = @_;
185+
186+ if ($self->{handle}->{$dh}) {
187+ $self->release_handle($dh);
188+ return 0;
189+ }
190+
191+ return -2;
192+}
193+
194+sub truncate {
195+ my $self = shift;
196+ my ($path, $offset, $fh) = @_;
197+
198+ return -2 unless (defined($self->{content}->{$path}));
199+
200+ my $data = $self->{content}->{$path}->{content};
201+ return -1 unless (defined($data));
202+
203+ $self->{content}->{$path}->{content} = substr($data, 0, $offset);
204+
205+ return 0;
206+}
207+
208+sub utime {
209+ my $self = shift;
210+ my ($path, $atime, $mtime) = @_;
211+
212+ die "utimens must be called";
213+}
214+
215+sub open {
216+ my $self = shift;
217+ my ($path, $flags, $fileinfo) = @_;
218+
219+ print STDERR "open: $path, $flags\n";
220+ use Data::Dumper;
221+ print STDERR Dumper($fileinfo);
222+
223+ return (-2) unless ($self->{content}->{$path});
224+
225+ return (0, $self->issue_handle($path));
226+}
227+
228+sub write {
229+ my $self = shift;
230+ my ($path, $buffer, $offset, $fh) = @_;
231+
232+ return (-2) unless (defined($self->{handle}->{$fh}));
233+
234+ my $file = $self->{handle}->{$fh}->[1];
235+ my $data = $file->{content};
236+ substr($data, $offset) = $buffer;
237+ $file->{content} = $data;
238+ $file->{attr}->[7] = length($data);
239+
240+ return length($buffer);
241+}
242+
243+sub read {
244+ my $self = shift;
245+ my ($path, $size, $offset, $fh) = @_;
246+
247+ return (-2) unless (defined($self->{handle}->{$fh}));
248+
249+ my $file = $self->{handle}->{$fh}->[1];
250+ my $data = $file->{content};
251+
252+ return substr($data, $offset, $size);
253+}
254+
255+sub statfs {
256+ my $self = shift;
257+
258+ return (255, 50000, 40000, 30000, 20000, 10000);
259+}
260+
261+sub utimens {
262+ my $self = shift;
263+ my ($path, $atime, $mtime) = @_;
264+
265+ return -2 unless ($self->{content}->{$path});
266+
267+ my $attr = $self->{content}->{$path}->{attr};
268+
269+ $attr->[8] = $atime;
270+ $attr->[9] = $mtime;
271+
272+ return 0;
273+}
274+
275+1;
Show on old repository browser