Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Tweaks on loopback.pl example #13

Merged
merged 5 commits into from

3 participants

@isync

For me, it didn't work without changes, so I've added tweaks that provide graceful fallbacks for what I encountered as problematic. And some more...

isync added some commits
@isync isync Update examples/loopback.pl
Added ENOTDIR to POSIX exports (was missing).
4a33caa
@isync isync Update examples/loopback.pl
Lchown might not be available on the platform, or it might just not work out-of-the-box, as for me today ("Can't locate loadable object for module Lchown"). Fallback gracefully in these cases.
d688055
@isync isync Update examples/loopback.pl
I might misunderstand usage, but I think, without a path in @ARGV, the script should spit out some usage info, so a user doesn't have to dig into the code for a quick test-drive.
60d8335
@isync isync Update examples/loopback.pl
Unix::Mknod might not be available or might not work - same as for Lchown. Graceful fallback. Is "POSIX::errno();" the right error code?
b9aaa54
@isync isync Update examples/readdir.pl
$file already sanitized in filename_fixup, right?
1469c11
@lstein

isync's patches work for me -- they correct the numerous "fail" messages on CPAN.

@dpavlin dpavlin merged commit fb9114f into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 27, 2013
  1. @isync

    Update examples/loopback.pl

    isync authored
    Added ENOTDIR to POSIX exports (was missing).
  2. @isync

    Update examples/loopback.pl

    isync authored
    Lchown might not be available on the platform, or it might just not work out-of-the-box, as for me today ("Can't locate loadable object for module Lchown"). Fallback gracefully in these cases.
  3. @isync

    Update examples/loopback.pl

    isync authored
    I might misunderstand usage, but I think, without a path in @ARGV, the script should spit out some usage info, so a user doesn't have to dig into the code for a quick test-drive.
Commits on Jan 28, 2013
  1. @isync

    Update examples/loopback.pl

    isync authored
    Unix::Mknod might not be available or might not work - same as for Lchown. Graceful fallback. Is "POSIX::errno();" the right error code?
  2. @isync

    Update examples/readdir.pl

    isync authored
    $file already sanitized in filename_fixup, right?
This page is out of date. Refresh to see the latest.
Showing with 39 additions and 9 deletions.
  1. +39 −7 examples/loopback.pl
  2. +0 −2  examples/readdir.pl
View
46 examples/loopback.pl
@@ -24,14 +24,28 @@
Filesys::Statvfs->import();
};
+my $use_lchown = 0;
+eval {
+ require Lchown;
+ 1;
+} and do {
+ $use_lchown = 1;
+};
+
+my $has_mknod = 0;
+eval {
+ require Unix::Mknod;
+ 1;
+} and do {
+ $has_mknod = 1;
+};
+
use blib;
use Fuse;
use IO::File;
-use POSIX qw(ENOENT ENOSYS EEXIST EPERM O_RDONLY O_RDWR O_APPEND O_CREAT setsid);
+use POSIX qw(ENOTDIR ENOENT ENOSYS EEXIST EPERM O_RDONLY O_RDWR O_APPEND O_CREAT setsid);
use Fcntl qw(S_ISBLK S_ISCHR S_ISFIFO SEEK_SET S_ISREG S_ISFIFO S_IMODE S_ISCHR S_ISBLK S_ISSOCK);
use Getopt::Long;
-use Lchown;
-use Unix::Mknod qw(:all);
my %extraopts = ( 'threaded' => 0, 'debug' => 0 );
my($use_real_statfs, $pidfile);
@@ -121,7 +135,11 @@ sub x_chown {
local $!;
print "nonexistent $fn\n" unless -e $fn;
my ($uid,$gid) = @_;
- lchown($uid, $gid, $fn);
+ if( $use_lchown ){
+ lchown($uid, $gid, $fn);
+ }else{
+ chown($uid, $gid, $fn);
+ }
return -$!;
}
sub x_chmod {
@@ -154,8 +172,12 @@ sub x_mknod {
return $rv ? 0 : -POSIX::errno();
}
elsif (S_ISCHR($modes) || S_ISBLK($modes)) {
- mknod($file, $modes, $dev);
- return -$!;
+ if($has_mknod){
+ Unix::Mknod::mknod($file, $modes, $dev);
+ return -$!;
+ }else{
+ return -POSIX::errno();
+ }
}
# S_ISSOCK maybe should be handled; however, for our test it should
# not really matter.
@@ -195,7 +217,17 @@ sub daemonize {
}
my ($mountpoint) = '';
-$mountpoint = shift(@ARGV) if @ARGV;
+if(@ARGV){
+ $mountpoint = shift(@ARGV)
+}else{
+ print "\n Usage: loopback.pl <mountpoint> [options]
+ \n Options:
+ --debug Turn on debugging (verbose) output
+ --use-threads Use threads
+ --use-real-statfs Use real stat command against /tmp or generic values
+ --pidfile Set pidfile value --pidfile=<numeric-value>\n\n";
+ exit;
+}
if (! -d $mountpoint) {
print STDERR "ERROR: attempted to mount to non-directory\n";
View
2  examples/readdir.pl
@@ -40,8 +40,6 @@ sub filename_fixup {
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}{cont}) : 0;
$size = $files{$file}{size} if exists $files{$file}{size};
Something went wrong with that request. Please try again.