From a0c0d5c9f433ac8b57df9996686a53e75e1002f9 Mon Sep 17 00:00:00 2001 From: Mark Glines Date: Thu, 18 Apr 2002 14:53:55 +0000 Subject: [PATCH] use fuse_mount_ioslave(), and get rid of that lame argv-rebuilding crap disable threads indefinitely, pending stabilization of the perl threads API loopback.pl: fix open() and mknod() ghettoness --- perl/Fuse.pm | 9 ++++--- perl/Fuse.xs | 62 +++++++++--------------------------------------- perl/loopback.pl | 34 ++++++++++---------------- 3 files changed, 28 insertions(+), 77 deletions(-) diff --git a/perl/Fuse.pm b/perl/Fuse.pm index 5e18483..6a01677 100644 --- a/perl/Fuse.pm +++ b/perl/Fuse.pm @@ -66,10 +66,11 @@ bootstrap Fuse $VERSION; sub main { my (@subs) = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); - my (@names) = qw(getattr readlink getdir mknod mkdir unlink rmdir symlink rename link chmod chown truncate utime open read write statfs); + my (@names) = qw(getattr readlink getdir mknod mkdir unlink rmdir symlink + rename link chmod chown truncate utime open read write statfs); my ($tmp) = 0; my (%mapping) = map { $_ => $tmp++ } (@names); - my (%otherargs) = (debug=>0, unthreaded=>1, mountpoint=>""); + my (%otherargs) = (debug=>0, mountpoint=>""); while(my $name = shift) { my ($subref) = shift; if(exists($otherargs{$name})) { @@ -82,9 +83,7 @@ sub main { $subs[$mapping{$name}] = $subref; } } - print "flag: debug\n" if $otherargs{debug}; - print "flag: unthreaded\n" if $otherargs{unthreaded}; - perl_fuse_main($0,$otherargs{unthreaded},$otherargs{debug},$otherargs{mountpoint},@subs); + perl_fuse_main($otherargs{debug},$otherargs{mountpoint},@subs); } # Autoload methods go after =cut, and are processed by the autosplit program. diff --git a/perl/Fuse.xs b/perl/Fuse.xs index 6e8a5c6..099ec9e 100644 --- a/perl/Fuse.xs +++ b/perl/Fuse.xs @@ -32,7 +32,6 @@ int _PLfuse_getattr(const char *file, struct stat *result) { else rv = -ENOENT; } else { - DEBUGf("populating\n"); result->st_blocks = POPi; result->st_blksize = POPi; result->st_ctime = POPi; @@ -51,7 +50,6 @@ int _PLfuse_getattr(const char *file, struct stat *result) { FREETMPS; LEAVE; PUTBACK; - DEBUGf("getattr end %i %o\n",rv,result->st_mode); return rv; } @@ -540,60 +538,21 @@ void perl_fuse_main(...) PREINIT: struct fuse_operations fops = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; - int i, varnum = 0, nothreads, debug, argc, have_mnt; - char **argv; + int i, fd, varnum = 0, debug, have_mnt; + char *mountpoint; STRLEN n_a; STRLEN l; INIT: - if(items != 22) { + if(items != 20) { fprintf(stderr,"Perl<->C inconsistency or internal error\n"); XSRETURN_UNDEF; } CODE: - /* how annoying. */ - nothreads = SvIV(ST(1)) ? 1 : 0; - debug = SvIV(ST(2)) ? 1 : 0; - have_mnt = strlen(SvPV(ST(3),n_a)) ? 1 : 0; - switch(have_mnt<<2 | debug<<1 | nothreads) { - case 0: /* !nothreads !debug !mnt */ - argv = ((char*[]){NULL}); - argc = 1; - break; - case 1: /* nothreads !debug !mnt */ - argv = ((char*[]){NULL,"-s"}); - argc = 2; - break; - case 2: /* !nothreads debug !mnt */ - argv = ((char*[]){NULL,"-d"}); - argc = 2; - break; - case 3: /* nothreads debug !mnt */ - argv = ((char*[]){NULL,"-s","-d"}); - argc = 3; - break; - case 4: /* !nothreads !debug mnt */ - argv = ((char*[]){NULL,NULL}); - argc = 2; - break; - case 5: /* nothreads !debug mnt */ - argv = ((char*[]){NULL,NULL,"-s"}); - argc = 3; - break; - case 6: /* !nothreads debug mnt */ - argv = ((char*[]){NULL,NULL,"-d"}); - argc = 3; - break; - case 7: /* nothreads debug mnt */ - argv = ((char*[]){NULL,NULL,"-s","-d"}); - argc = 4; - break; - } - argv[0] = SvPV(ST(0),n_a); - if(have_mnt) - argv[1] = SvPV(ST(3),n_a); - printf("%i %i %i\n",nothreads,debug,have_mnt); + debug = SvIV(ST(0)); + mountpoint = SvPV_nolen(ST(1)); + /* FIXME: reevaluate multithreading support when perl6 arrives */ for(i=0;i<18;i++) { - SV *var = ST(i+4); + SV *var = ST(i+2); if((var != &PL_sv_undef) && SvROK(var)) { if(SvTYPE(SvRV(var)) == SVt_PVCV) { void **tmp1 = (void**)&_available_ops, **tmp2 = (void**)&fops; @@ -603,6 +562,7 @@ perl_fuse_main(...) croak("arg is not a code reference!"); } } - printf("pre-main\n"); - fuse_main(argc,argv,&fops); - printf("post-main\n"); + fd = fuse_mount_ioslave(mountpoint); + if(fd < 0) + croak("could not mount fuse filesystem!"); + fuse_loop(fuse_new(fd,debug ? FUSE_DEBUG : 0,&fops)); diff --git a/perl/loopback.pl b/perl/loopback.pl index e58d90a..ac3a7b0 100644 --- a/perl/loopback.pl +++ b/perl/loopback.pl @@ -5,6 +5,7 @@ use Fuse; use IO::File; use POSIX qw(ENOENT ENOSYS EEXIST EPERM O_RDONLY O_RDWR O_APPEND O_CREAT); use Fcntl qw(S_ISBLK S_ISCHR S_ISFIFO); +require 'syscall.ph'; # for SYS_mknod sub debug { print(STDERR join(",",@_),"\n"); @@ -31,10 +32,10 @@ sub x_getdir { sub x_open { my ($file) = fixup(shift); - my ($fd) = POSIX::open($file,@_); - return -ENOSYS() if(!defined($fd)); - return $fd if $fd < 0; - POSIX::close($fd); + my ($mode) = shift; + debug("open",$file,$mode); + return -$! unless sysopen(FILE,$file,$mode); + close(FILE); return 0; } @@ -106,21 +107,12 @@ sub x_mknod { # since this is called for ALL files, not just devices, I'll do some checks # and possibly run the real mknod command. my ($file, $modes, $dev) = @_; - return -EEXIST() if -e ($file = fixup($file)); - return -EPERM() if (system("touch $file 2>/dev/null") >> 8); - if(S_ISBLK($modes) || S_ISCHR($modes) || S_ISFIFO($modes)) { - system("rm -f $file 2>/dev/null"); - my ($chr) = 'c'; - my ($omodes) = sprintf("%o",$modes & 0x1ff); - $chr = 'b' if S_ISBLK($modes); - if(S_ISFIFO($modes)) { - $chr = 'p'; - $dev = ""; - } else { - $dev = (($dev>>8) & 255) . " " . ($dev & 255); - } - system("mknod --mode=$omodes '$file' $chr $dev"); - } + $file = fixup($file); + $! = 0; + debug("mknod",@_); + syscall(&SYS_mknod,$file,$modes); + debug("mknod retval",$!); + return -$!; } # kludge @@ -128,7 +120,6 @@ sub x_statfs {return 255,1000000,500000,1000000,500000,4096} my ($mountpoint) = ""; $mountpoint = shift(@ARGV) if @ARGV; Fuse::main( - unthreaded=>1, mountpoint=>$mountpoint, getattr=>\&x_getattr, readlink=>\&x_readlink, @@ -147,5 +138,6 @@ Fuse::main( open=>\&x_open, read=>\&x_read, write=>\&x_write, - statfs=>\&x_statfs + statfs=>\&x_statfs, + debug=>1 ); -- 2.30.2