3 use POSIX qw(ENOENT EISDIR EINVAL);
12 namespace||'/'||name||' ['||oid||']' as filename,
13 length(template) as size,
14 iseditable as writable
25 my $connect = "DBI:Pg:dbname=webgui";
27 my $dbh = DBI->connect($connect,"","") || die $DBI::errstr;
29 print STDERR "$sql_filenames\n";
31 my $sth_filenames = $dbh->prepare($sql_filenames) || die $dbh->errstr();
32 $sth_filenames->execute() || die $sth_filenames->errstr();
34 my $sth_content = $dbh->prepare($sql_content) || die $dbh->errstr();
36 print "#",join(",",@{ $sth_filenames->{NAME} }),"\n";
38 my $ctime_start = time();
46 # cont => "File 'a'.\n",
48 # ctime => time()-2000
54 while (my $row = $sth_filenames->fetchrow_hashref() ) {
55 $files{$row->{'filename'}} = {
56 size => $row->{'size'},
57 mode => $row->{'writable'} ? 0644 : 0444,
58 id => $row->{'id'} || 99,
62 foreach (split(m!/!, $row->{'filename'})) {
63 # first, entry is assumed to be file
84 print scalar (keys %dirs), " dirs:",join(" ",keys %dirs),"\n";
89 $file = '.' unless length($file);
94 my ($file) = filename_fixup(shift);
96 $file = '.' unless length($file);
97 return -ENOENT() unless exists($files{$file});
98 my ($size) = $files{$file}{size} || 1;
99 my ($dev, $ino, $rdev, $blocks, $gid, $uid, $nlink, $blksize) = (0,0,0,1,0,0,1,1024);
100 my ($atime, $ctime, $mtime);
101 $atime = $ctime = $mtime = $files{$file}{ctime} || $ctime_start;
103 my ($modes) = (($files{$file}{type} || 0100)<<9) + $files{$file}{mode};
105 # 2 possible types of return values:
106 #return -ENOENT(); # or any other error you care to
107 #print(join(",",($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)),"\n");
108 return ($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks);
112 my ($dirname) = shift;
114 # return as many text filenames as you like, followed by the retval.
115 print((scalar keys %files)." files total\n");
117 foreach (keys %files) {
119 $f =~ s/^\E$dirname\Q//;
122 $out{$f}++ if (/^\E$dirname\Q/ && $f =~ /^[^\/]+$/);
124 $out{$f}++ if ($f =~ /^[^\/]+$/);
126 print "f: $_ -> $f\n";
129 $out{'no files? bug?'}++;
131 print scalar keys %out," files found for '$dirname': ",keys %out,"\n";
132 return (keys %out),0;
136 # VFS sanity check; it keeps all the necessary state, not much to do here.
137 my ($file) = filename_fixup(shift);
138 return -ENOENT() unless exists($files{$file});
139 return -EISDIR() unless exists($files{$file}{id});
140 if (!exists($files{$file}{cont})) {
141 $sth_content->execute($files{$file}{id});
142 $files{$file}{cont} = $sth_content->fetchrow_array;
144 print "open '$file' ",length($files{$file}{cont})," bytes\n";
149 # return an error numeric, or binary/text string.
150 # (note: 0 means EOF, "0" will give a byte (ascii "0")
151 # to the reading program)
152 my ($file) = filename_fixup(shift);
155 return -ENOENT() unless exists($files{$file});
157 my $len = length($files{$file}{cont});
159 print "read '$file' [$len bytes] offset $off length $buf\n";
161 return -EINVAL() if ($off > $len);
162 return 0 if ($off == $len);
164 $buf = $len-$off if ($off+$buf > $len);
166 return substr($files{$file}{cont},$off,$buf);
169 sub e_statfs { return 255, 1, 1, 1, 1, 2 }
171 # If you run the script directly, it will run fusermount, which will in turn
172 # re-run this script. Hence the funky semantics.
173 my ($mountpoint) = "";
174 $mountpoint = shift(@ARGV) if @ARGV;
176 mountpoint=>$mountpoint,
177 getattr=>\&e_getattr,