3 use POSIX qw(ENOENT EISDIR EINVAL);
12 namespace||'/'||name||' ['||templateid||']' 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 print("open called\n");
139 return -ENOENT() unless exists($files{$file});
140 return -EISDIR() unless exists($files{$file}{id});
141 if (!exists($files{$file}{cont})) {
142 $sth_content->execute($files{$file}{id});
143 ($files{$file}{cont}) = $sth_content->fetchrow_array;
150 # return an error numeric, or binary/text string. (note: 0 means EOF, "0" will
151 # give a byte (ascii "0") to the reading program)
152 my ($file) = filename_fixup(shift);
154 return -ENOENT() unless exists($files{$file});
155 return -EINVAL() if $off > length($files{$file}{cont});
156 return 0 if $off == length($files{$file}{cont});
157 return substr($files{$file}{cont},$off,$buf);
160 sub e_statfs { return 255, 1, 1, 1, 1, 2 }
162 # If you run the script directly, it will run fusermount, which will in turn
163 # re-run this script. Hence the funky semantics.
164 my ($mountpoint) = "";
165 $mountpoint = shift(@ARGV) if @ARGV;
167 mountpoint=>$mountpoint,
168 getattr=>\&e_getattr,