8 |
use IO::File; |
use IO::File; |
9 |
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); |
10 |
use Fcntl qw(S_ISBLK S_ISCHR S_ISFIFO SEEK_SET); |
use Fcntl qw(S_ISBLK S_ISCHR S_ISFIFO SEEK_SET); |
11 |
require 'syscall.ph'; # for SYS_mknod and SYS_lchown |
my $can_syscall = eval { |
12 |
|
require 'syscall.ph'; # for SYS_mknod and SYS_lchown |
13 |
|
}; |
14 |
|
if (!$can_syscall && open my $fh, '<', '/usr/include/sys/syscall.h') { |
15 |
|
my %sys = do { local $/ = undef; |
16 |
|
<$fh> =~ m/\#define \s+ (\w+) \s+ (\d+)/gxms; |
17 |
|
}; |
18 |
|
close $fh; |
19 |
|
if ($sys{SYS_mknod} && $sys{SYS_lchown}) { |
20 |
|
*SYS_mknod = sub { $sys{SYS_mknod} }; |
21 |
|
*SYS_lchown = sub { $sys{SYS_lchown} }; |
22 |
|
$can_syscall = 1; |
23 |
|
} |
24 |
|
} |
25 |
|
|
26 |
sub fixup { return "/tmp/fusetest-" . $ENV{LOGNAME} . shift } |
sub fixup { return "/tmp/fusetest-" . $ENV{LOGNAME} . shift } |
27 |
|
|
92 |
} |
} |
93 |
sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! } |
sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! } |
94 |
sub x_chown { |
sub x_chown { |
95 |
|
return -ENOSYS() if ! $can_syscall; |
96 |
my ($fn) = fixup(shift); |
my ($fn) = fixup(shift); |
97 |
print "nonexistent $fn\n" unless -e $fn; |
print "nonexistent $fn\n" unless -e $fn; |
98 |
my ($uid,$gid) = @_; |
my ($uid,$gid) = @_; |
116 |
sub x_rmdir { return 0 if rmdir fixup(shift); return -$!; } |
sub x_rmdir { return 0 if rmdir fixup(shift); return -$!; } |
117 |
|
|
118 |
sub x_mknod { |
sub x_mknod { |
119 |
|
return -ENOSYS() if ! $can_syscall; |
120 |
# 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 |
121 |
# and possibly run the real mknod command. |
# and possibly run the real mknod command. |
122 |
my ($file, $modes, $dev) = @_; |
my ($file, $modes, $dev) = @_; |