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..


In reply to Re^2: FUSE, fuse_get_context and private = dangling pointer woes by CandyAngel
in thread FUSE, fuse_get_context and private = dangling pointer woes by CandyAngel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.