/[fuse.before_github]/perl-llin/examples/loopback.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /perl-llin/examples/loopback.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 111 by dpavlin, Mon Jan 2 20:31:19 2006 UTC revision 112 by dpavlin, Thu Nov 15 09:32:08 2007 UTC
# Line 6  use Fuse; Line 6  use Fuse;
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);
# Line 82  sub x_rename { Line 101  sub x_rename {
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) = @_;
# Line 105  sub x_mkdir { my ($name, $perm) = @_; re Line 125  sub x_mkdir { my ($name, $perm) = @_; re
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) = @_;

Legend:
Removed from v.111  
changed lines
  Added in v.112

  ViewVC Help
Powered by ViewVC 1.1.26