in reply to Re: FUSE, fuse_get_context and private = dangling pointer woes
in thread FUSE, fuse_get_context and private = dangling pointer woes

Thank you for taking the time looking into this, despite not using Fuse. I wasn't really expecting someone to go that far to help me! Thank you :)

The Fuse module itself is installed properly and the code works okay (as in, it mounts and you can watch filesystem events happen on the mountpoint due to the 'debug => 1') if you comment out the 'init' line in Fuse::main().

I started by writing a little test as I wasn't sure if non-threaded Fuse would allow me to do this:

$ cat mnt/source > mnt/destination

where "mnt/" is the directory the Fuse filesystem is mounted, which I have in the scripts directory.

This meant implementing getattr, getdir, read, write, truncate and they work without issue (and the above command does work okay). I then tried to add 'init' and this issue cropped up.

I did see Fuse::Simple, but it doesn't allow some things that I want to do (renaming, deleting).

I'm going to put the "fuller" code below for reference (I hope that is okay). Again, it works fine if 'init' is commented out in Fuse::main().

No judging, please! This is just scratchcode to test if I could read/write at the same time :) Shortcuts were taken.

NOTE: This code will sometimes fail to run by spamming this error:

Use of each() on hash after insertion without resetting hash iterator results in undefined behavior, Perl interpreter: 0x14ae010 at /usr/lib/perl5/core_perl/Data/Dumper.pm line 222.

This is part of this "init" bug! You either have to rerun it until it starts correctly, or comment out/replace line #49 with simpler print.

#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use Fcntl ':mode'; use Fuse; use POSIX qw(ENOENT ENOSYS); Fuse::main ( debug => 1, mountpoint => 'mnt', getattr => sub { fuse('getattr', @_); }, getdir => sub { fuse('getdir', @_); }, init => sub { fuse('init', @_); }, read => sub { fuse('read', @_); }, truncate => sub { fuse('truncate', @_); }, write => sub { fuse('write', @_); }, ); sub fuse { my $function = shift; my $callback_for = { getattr => \&fuse_getattr, getdir => \&fuse_getdir, init => \&fuse_init, read => \&fuse_read, truncate => \&fuse_truncate, write => \&fuse_write, }; if (exists $callback_for->{$function}) { return $callback_for->{$function} -> (@_); } else { return -(ENOSYS); } die; } sub fuse_getattr { my $path = shift; my $context = Fuse::fuse_get_context(); print Dumper ($context), "\n"; my $stat = undef; if ($path eq '/') { my $mode = S_IFDIR | S_IRUSR | S_IXUSR; $stat = [ 0, # dev 0, # inode $mode, # mode 1, # nlink $context->{uid}, # uid $context->{gid}, # gid 0, # rdev 0, # size 0, # atime 0, # mtime 0, # ctime 4096, # blksie 0, # blocks ]; } elsif ($path eq '/save') { my $mode = S_IFREG | S_IRUSR; $stat = [ 0, # dev 0, # inode $mode, # mode 1, # nlink $context->{uid}, # uid $context->{gid}, # gid 0, # rdev 1_024_000, # size 0, # atime 0, # mtime 0, # ctime 4096, # blksie 1, # blocks ]; } elsif ($path eq '/load') { my $mode = S_IFREG | S_IWUSR; $stat = [ 0, # dev 0, # inode $mode, # mode 1, # nlink $context->{uid}, # uid $context->{gid}, # gid 0, # rdev 0, # size 0, # atime 0, # mtime 0, # ctime 4096, # blksie 0, # blocks ]; } if (defined $stat) { return @{$stat}; } else { return -(ENOENT); } die; } sub fuse_getdir { my $path = shift; if ($path eq '/') { return '.', '..', 'load', 'save', 0; } return -(ENOENT); } sub fuse_init { print Dumper [@_], "\n"; return 'PRIVDAT'; } sub fuse_read { my $path = shift; if ($path eq '/save') { return 1 x 4096; } return -(ENOENT); } sub fuse_truncate { my $path = shift; if ($path eq '/load') { return 0; } return -(ENOENT); } sub fuse_write { print Dumper (@_), "\n"; return length $_[1]; return -(ENOENT); }

As you can see, the functions are kind-of-wrapped already..

Replies are listed 'Best First'.
Re^3: FUSE, fuse_get_context and private = dangling pointer woes
by thanos1983 (Parson) on Oct 11, 2014 at 01:31 UTC

    Hello CandyAngel,

    First of all sorry for the late reply I got busy with something else and I just found a few hours to spend with this script.

    I am afraid that I can not be much of assistance with your problem. No matter what I tried I was not able to make my sample script to work.

    I keep getting this error:

    unique: 71, opcode: RELEASEDIR (29), nodeid: 1, insize: 64, pid: 0 unique: 71, success, outsize: 16 unique: 72, opcode: LOOKUP (1), nodeid: 1, insize: 52, pid: 26177 LOOKUP /autorun.inf unique: 72, error: -38 (Function not implemented), outsize: 16

    Where it gets stack, for some unknown reason to me. I tried anything that could come to my mind but so far I did not find a solution to this problem.

    But I found some example codes, that might give a few ideas to experiment with or play around with your code. Take a look here dpavlin/perl-fuse if you have not done it yet.

    This is a sample of my code that I was trying to make it work, just in case that can help you by any means.

    #!/usr/bin/perl use Fuse; use strict; use warnings; use threads::shared; use Fuse "fuse_get_context"; use POSIX "ENOENT"; my (%files) = ( 'thanos' => { type => 0040, mode => 0755, ctime => time()-1000 } ); sub filename_fixup { my ($file) = shift; $file =~ s,^/,,; $file = '.' unless length($file); return $file; } sub e_getattr { my ($file) = filename_fixup(shift); $file =~ s,^/,,; $file = '.' unless length($file); return -ENOENT() unless exists($files{$file}); my ($size) = exists($files{$file}{cont}) ? length($files{$file}{co +nt}) : 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); $atime = $ctime = $mtime = $files{$file}{ctime}; # 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,$at +ime,$mtime,$ctime,$blksize,$blocks)),"\n"); return ($dev,$ino,$modes,$nlink,$uid,$gid,$rdev,$size,$atime,$mtim +e,$ctime,$blksize,$blocks); } sub e_getdir { # return as many text filenames as you like, followed by the retva +l. print((scalar keys %files)."\n"); return (keys %files),0; } my $mountpoint = ""; $mountpoint = $ARGV[1] or die "You forgot to provide the mountpoint!\n +"; #$mountpoint = shift(@ARGV) if @ARGV; croak("Fuse doesn't have ioctl") unless Fuse::fuse_version() >= 2.8; Fuse::main( debug => 1, mountpoint => $mountpoint, mountopts => "", # if 'user_allow_other' in /etc/fuse.conf as per + the FUSE documention threaded => 0, getattr => "main::e_getattr", #getdir => "main::e_getdir", #open => "main::e_open", #statfs => "main::e_statfs", #read => "main::e_read", );

    Just in case that you faced the same problem with me and you found a solution, let me know how you worked your way out of it. Any way, I hope by now you have solved your problems alternatively I am sure the examples will give you a few hints. Best of luck with your script.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

      What are you doing to get your error? I don't get it when I run it.

      Unfortunately, neither your script nor any examples at dpavlin/perl-fuse use the 'init' callback, so there is no demonstration of how to use it. I may be using it incorrectly but.. I doubt it, because it works on the first call of fuse_get_context().

      I may see if I can get in contact with the author and direct them here. I've had a look but I don't see any unit tests for it either, which might explain why the issue has been missed.

      In the meantime, I think I shall just use the wrapping method as most of it is coded (longhandedly, bleh!) anyway..

      Once again, thank you for your time and efforts to help!

        Hello Anonymous Monk,

        Let me show you a complete error output, maybe you can see something that I am missing.

        Debug:

        The script is the one that I posted above, the only modification is this:

        my $mountpoint = "/home/thanos/test_fuse"; #$mountpoint = $ARGV[1] or die "You forgot to provide the mountpoint!\ +n";

        I am running on:

        Linux OS 3.13.0-38-generic #65-Ubuntu SMP Thu Oct 9 11:36:50 UTC 2014 +x86_64 x86_64 x86_64 GNU/Linux

        Perl Version:

        This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-li +nux-gnu-thread-multi

        Hope this gives more information in possible representation of error. If you have any possible thoughts on how to get over this error please let me know. Thanks in advance.

        Seeking for Perl wisdom...on the process of learning...not there...yet!