From: Dobrica Pavlinusic Date: Sat, 20 Jan 2007 12:21:12 +0000 (+0000) Subject: Changes from Marc to implement fuse_get_context(): X-Git-Tag: 0.09_1 X-Git-Url: http://git.rot13.org/?p=perl-fuse.git;a=commitdiff_plain;h=88267f8843a5f05f43c47784c57e15b4284fe6e5 Changes from Marc to implement fuse_get_context(): * an XS function to get the data * a mention of it in Fuse.pm so it can be exported properly * a pretty ugly hack to example.pl, which is how I tested it. git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/fuse/perl-llin@108 6e4b0b00-1209-0410-87b2-b275959b5705 --- diff --git a/Fuse.pm b/Fuse.pm index 37fd364..5b2459f 100644 --- a/Fuse.pm +++ b/Fuse.pm @@ -21,14 +21,14 @@ our @ISA = qw(Exporter DynaLoader); # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK # will save memory. our %EXPORT_TAGS = ( - 'all' => [ qw(XATTR_CREATE XATTR_REPLACE) ], + 'all' => [ qw(XATTR_CREATE XATTR_REPLACE fuse_get_context) ], 'xattr' => [ qw(XATTR_CREATE XATTR_REPLACE) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = (); -our $VERSION = '0.08'; +our $VERSION = '0.09_1'; sub AUTOLOAD { # This AUTOLOAD is used to 'autoload' constants from the constant() diff --git a/Fuse.xs b/Fuse.xs index e6c293b..9e1d671 100644 --- a/Fuse.xs +++ b/Fuse.xs @@ -813,6 +813,24 @@ removexattr: _PLfuse_removexattr, MODULE = Fuse PACKAGE = Fuse PROTOTYPES: DISABLE +SV* +fuse_get_context() + PREINIT: + struct fuse_context *fc; + CODE: + fc = fuse_get_context(); + if(fc) { + HV *hash = newHV(); + hv_store(hash, "uid", 3, newSViv(fc->uid), 0); + hv_store(hash, "gid", 3, newSViv(fc->gid), 0); + hv_store(hash, "pid", 3, newSViv(fc->pid), 0); + RETVAL = newRV_noinc((SV*)hash); + } else { + XSRETURN_UNDEF; + } + OUTPUT: + RETVAL + void perl_fuse_main(...) PREINIT: diff --git a/examples/example.pl b/examples/example.pl index a01ae5b..ed7ce57 100644 --- a/examples/example.pl +++ b/examples/example.pl @@ -2,7 +2,7 @@ use strict; use blib; -use Fuse; +use Fuse qw(fuse_get_context); use POSIX qw(ENOENT EISDIR EINVAL); my (%files) = ( @@ -23,6 +23,12 @@ my (%files) = ( mode => 0644, ctime => time()-1000 }, + me => { + size => 45, + type => 0100, + mode => 0644, + ctime => time()-1000 + }, ); sub filename_fixup { @@ -38,6 +44,7 @@ sub e_getattr { $file = '.' unless length($file); return -ENOENT() unless exists($files{$file}); my ($size) = exists($files{$file}{cont}) ? length($files{$file}{cont}) : 0; + $size = $files{$file}{size} if exists $files{$file}{size}; my ($modes) = ($files{$file}{type}<<9) + $files{$file}{mode}; my ($dev, $ino, $rdev, $blocks, $gid, $uid, $nlink, $blksize) = (0,0,0,1,0,0,1,1024); my ($atime, $ctime, $mtime); @@ -59,7 +66,7 @@ sub e_open { my ($file) = filename_fixup(shift); print("open called\n"); return -ENOENT() unless exists($files{$file}); - return -EISDIR() unless exists($files{$file}{cont}); + return -EISDIR() if $files{$file}{type} & 0040; print("open ok\n"); return 0; } @@ -70,6 +77,11 @@ sub e_read { my ($file) = filename_fixup(shift); my ($buf,$off) = @_; return -ENOENT() unless exists($files{$file}); + if(!exists($files{$file}{cont})) { + return -EINVAL() if $off > 0; + my $context = fuse_get_context(); + return sprintf("pid=0x%08x uid=0x%08x gid=0x%08x\n",@$context{'pid','uid','gid'}); + } return -EINVAL() if $off > length($files{$file}{cont}); return 0 if $off == length($files{$file}{cont}); return substr($files{$file}{cont},$off,$buf);