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/destinationwhere "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 | |
by Anonymous Monk on Oct 11, 2014 at 02:01 UTC | |
by thanos1983 (Parson) on Oct 11, 2014 at 10:57 UTC | |
by CandyAngel (Initiate) on Oct 13, 2014 at 23:50 UTC |