6 |
use IO::File; |
use IO::File; |
7 |
use POSIX qw(ENOENT ENOSYS EEXIST EPERM O_RDONLY O_RDWR O_APPEND O_CREAT); |
use POSIX qw(ENOENT ENOSYS EEXIST EPERM O_RDONLY O_RDWR O_APPEND O_CREAT); |
8 |
use Fcntl qw(S_ISBLK S_ISCHR S_ISFIFO SEEK_SET); |
use Fcntl qw(S_ISBLK S_ISCHR S_ISFIFO SEEK_SET); |
9 |
require 'syscall.ph'; # for SYS_mknod and SYS_lchown |
my $can_syscall = eval { |
10 |
|
require 'syscall.ph'; # for SYS_mknod and SYS_lchown |
11 |
|
}; |
12 |
|
if (!$can_syscall && open my $fh, '<', '/usr/include/sys/syscall.h') { |
13 |
|
local $/ = undef; |
14 |
|
my %sys = do { local $/ = undef; |
15 |
|
<$fh> =~ m/\#define \s+ (\w+) \s+ (\d+)/gxms; |
16 |
|
}; |
17 |
|
close $fh; |
18 |
|
if ($sys{SYS_mknod} && $sys{SYS_lchown}) { |
19 |
|
*SYS_mknod = sub { $sys{SYS_mknod} }; |
20 |
|
*SYS_lchown = sub { $sys{SYS_lchown} }; |
21 |
|
$can_syscall = 1; |
22 |
|
} |
23 |
|
} |
24 |
|
|
25 |
my $tmp_path = "/tmp/fusetest-" . $ENV{LOGNAME}; |
my $tmp = -d '/private' ? '/private/tmp' : '/tmp'; |
26 |
|
my $tmp_path = "$tmp/fusetest-" . $ENV{LOGNAME}; |
27 |
if (! -e $tmp_path) { |
if (! -e $tmp_path) { |
28 |
mkdir($tmp_path) || die "can't create $tmp_path: $!"; |
mkdir($tmp_path) || die "can't create $tmp_path: $!"; |
29 |
} |
} |
30 |
|
|
31 |
sub fixup { return $tmp_path . shift } |
sub fixup { print STDERR "fixup $_[0] from @{[caller]}\n"; |
32 |
|
my ($path) = @_; |
33 |
|
return $tmp_path if $path eq '/'; |
34 |
|
return $tmp_path . $path; |
35 |
|
} |
36 |
|
|
37 |
sub x_getattr { |
sub x_getattr { |
38 |
my ($file) = fixup(shift); |
my ($file) = fixup(shift); |
101 |
} |
} |
102 |
sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! } |
sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! } |
103 |
sub x_chown { |
sub x_chown { |
104 |
|
return -ENOSYS() if ! $can_syscall; |
105 |
my ($fn) = fixup(shift); |
my ($fn) = fixup(shift); |
106 |
print "nonexistent $fn\n" unless -e $fn; |
print "nonexistent $fn\n" unless -e $fn; |
107 |
my ($uid,$gid) = @_; |
my ($uid,$gid) = @_; |
125 |
sub x_rmdir { return 0 if rmdir fixup(shift); return -$!; } |
sub x_rmdir { return 0 if rmdir fixup(shift); return -$!; } |
126 |
|
|
127 |
sub x_mknod { |
sub x_mknod { |
128 |
|
return -ENOSYS() if ! $can_syscall; |
129 |
# since this is called for ALL files, not just devices, I'll do some checks |
# since this is called for ALL files, not just devices, I'll do some checks |
130 |
# and possibly run the real mknod command. |
# and possibly run the real mknod command. |
131 |
my ($file, $modes, $dev) = @_; |
my ($file, $modes, $dev) = @_; |