--- perl/trunk/examples/loopback_t.pl 2005/12/27 14:49:31 20 +++ perl-llin/examples/loopback_t.pl 2007/11/15 09:32:08 112 @@ -3,11 +3,25 @@ use threads; use threads::shared; +use blib; use Fuse; use IO::File; use POSIX qw(ENOENT ENOSYS EEXIST EPERM O_RDONLY O_RDWR O_APPEND O_CREAT); use Fcntl qw(S_ISBLK S_ISCHR S_ISFIFO SEEK_SET); -require 'syscall.ph'; # for SYS_mknod and SYS_lchown +my $can_syscall = eval { + require 'syscall.ph'; # for SYS_mknod and SYS_lchown +}; +if (!$can_syscall && open my $fh, '<', '/usr/include/sys/syscall.h') { + my %sys = do { local $/ = undef; + <$fh> =~ m/\#define \s+ (\w+) \s+ (\d+)/gxms; + }; + close $fh; + if ($sys{SYS_mknod} && $sys{SYS_lchown}) { + *SYS_mknod = sub { $sys{SYS_mknod} }; + *SYS_lchown = sub { $sys{SYS_lchown} }; + $can_syscall = 1; + } +} sub fixup { return "/tmp/fusetest-" . $ENV{LOGNAME} . shift } @@ -78,6 +92,7 @@ } sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! } sub x_chown { + return -ENOSYS() if ! $can_syscall; my ($fn) = fixup(shift); print "nonexistent $fn\n" unless -e $fn; my ($uid,$gid) = @_; @@ -101,6 +116,7 @@ sub x_rmdir { return 0 if rmdir fixup(shift); return -$!; } sub x_mknod { + return -ENOSYS() if ! $can_syscall; # since this is called for ALL files, not just devices, I'll do some checks # and possibly run the real mknod command. my ($file, $modes, $dev) = @_;