Improvements in getattr and statfs: du will not return meaningful values and
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 27 Nov 2004 14:02:18 +0000 (14:02 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 27 Nov 2004 14:02:18 +0000 (14:02 +0000)
df will return something which is not as wrong as it was (but, still not
correct).

Fuse::DBI will not try to load kernel module using sudo, and try to umount
using sudo umount if fusermount -u fails (as it happends with current CVS
version of fuse).

New webgui test target in Makefile which work as test on my local machine
(and hopefully on any with webgui default installation).

git-svn-id: svn://svn.rot13.org/fuse_dbi/trunk@51 17f4e80c-d0e0-0310-8903-bfc3ae804c12

DBI.pm
Makefile.PL

diff --git a/DBI.pm b/DBI.pm
index c360e3c..24d9d8c 100755 (executable)
--- a/DBI.pm
+++ b/DBI.pm
@@ -132,6 +132,11 @@ sub mount {
 
        print Dumper($arg);
 
+       unless ($self->fuse_module_loaded) {
+               print STDERR "no fuse module loaded. Trying sudo modprobe fuse!\n";
+               system "sudo modprobe fuse" || die "can't modprobe fuse using sudo!\n";
+       }
+
        carp "mount needs 'dsn' to connect to (e.g. dsn => 'DBI:Pg:dbname=test')" unless ($arg->{'dsn'});
        carp "mount needs 'mount' as mountpoint" unless ($arg->{'mount'});
 
@@ -242,7 +247,9 @@ sub umount {
        my $self = shift;
 
        if ($self->{'mount'} && $self->is_mounted) {
-               system "fusermount -u ".$self->{'mount'}." 2>&1 >/dev/null" || return 0;
+               system "fusermount -u ".$self->{'mount'}." 2>&1 >/dev/null" ||
+                       system "sudo umount ".$self->{'mount'} ||
+                       return 0;
                return 1;
        }
 
@@ -290,7 +297,6 @@ sub fuse_module_loaded {
 }
 
 my %files;
-my %dirs;
 
 sub read_filenames {
        my $self = shift;
@@ -330,7 +336,6 @@ sub read_filenames {
                        # first, entry is assumed to be file
                        if ($d) {
                                $files{$d} = {
-                                               size => $dirs{$d}++,
                                                mode => 0755,
                                                type => 0040
                                };
@@ -348,7 +353,7 @@ sub read_filenames {
                }
        }
 
-       print "found ",scalar(keys %files)-scalar(keys %dirs)," files, ",scalar(keys %dirs), " dirs\n";
+       print "found ",scalar(keys %files)," files\n";
 }
 
 
@@ -364,8 +369,8 @@ sub e_getattr {
        $file =~ s,^/,,;
        $file = '.' unless length($file);
        return -ENOENT() unless exists($files{$file});
-       my ($size) = $files{$file}{size} || 1;
-       my ($dev, $ino, $rdev, $blocks, $gid, $uid, $nlink, $blksize) = (0,0,0,1,0,0,1,1024);
+       my ($size) = $files{$file}{size} || 1024;
+       my ($dev, $ino, $rdev, $blocks, $gid, $uid, $nlink, $blksize) = (0,0,0,int(($size+1023)/1024),0,0,1,1024);
        my ($atime, $ctime, $mtime);
        $atime = $ctime = $mtime = $files{$file}{ctime} || $ctime_start;
 
@@ -373,7 +378,7 @@ sub e_getattr {
 
        # 2 possible types of return values:
        #return -ENOENT(); # or any other error you care to
-       #print(join(",",($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)),"\n");
+       print "getattr($file) ",join(",",($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)),"\n";
        return ($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks);
 }
 
@@ -538,17 +543,37 @@ sub e_utime {
        return 0;
 }
 
-sub e_statfs { return 255, 1, 1, 1, 1, 2 }
+sub e_statfs {
+
+       my $size = 0;
+       my $inodes = 0;
+
+       foreach my $f (keys %files) {
+               if ($f !~ /(^|\/)\.\.?$/) {
+                       $size += $files{$f}{size} || 0;
+                       $inodes++;
+               }
+               print "$inodes: $f [$size]\n";
+       }
+
+       $size = int(($size+1023)/1024);
+
+       my @ret = (255, $inodes+1000, $inodes, $size, $size-10, 1024);
+
+       print "statfs: ",join(",",@ret),"\n";
+
+       return @ret;
+}
 
 sub e_unlink {
        my $file = filename_fixup(shift);
 
-       if (exists( $dirs{$file} )) {
-               print "unlink '$file' will re-read template names\n";
-               print Dumper($fuse_self);
-               $$fuse_self->{'read_filenames'}->();
-               return 0;
-       } elsif (exists( $files{$file} )) {
+#      if (exists( $dirs{$file} )) {
+#              print "unlink '$file' will re-read template names\n";
+#              print Dumper($fuse_self);
+#              $$fuse_self->{'read_filenames'}->();
+#              return 0;
+       if (exists( $files{$file} )) {
                print "unlink '$file' will invalidate cache\n";
                read_content($file,$files{$file}{id});
                return 0;
index 618db21..d14f2c6 100644 (file)
@@ -31,5 +31,9 @@ html: DBI.pm
 changelog:
        svn update && svn -v log > Changes
 
+webgui: all
+       sudo umount /mnt2 || echo -n
+       ./examples/webgui.pl /data/WebGUI/etc/WebGUI.conf /mnt2
+
 MAKE_MORE
 }