7 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);
9 require 'syscall.ph'; # for SYS_mknod and SYS_lchown
11 my $tmp_path = "/tmp/fusetest-" . $ENV{LOGNAME};
13 mkdir($tmp_path) || die "can't create $tmp_path: $!";
16 sub fixup { return $tmp_path . shift }
19 my ($file) = fixup(shift);
20 my (@list) = lstat($file);
21 return -$! unless @list;
26 my ($dirname) = fixup(shift);
27 unless(opendir(DIRHANDLE,$dirname)) {
30 my (@files) = readdir(DIRHANDLE);
36 my ($file) = fixup(shift);
38 return -$! unless sysopen(FILE,$file,$mode);
44 my ($file,$bufsize,$off) = @_;
46 my ($handle) = new IO::File;
47 return -ENOENT() unless -e ($file = fixup($file));
48 my ($fsize) = -s $file;
49 return -ENOSYS() unless open($handle,$file);
50 if(seek($handle,$off,SEEK_SET)) {
51 read($handle,$rv,$bufsize);
57 my ($file,$buf,$off) = @_;
59 return -ENOENT() unless -e ($file = fixup($file));
60 my ($fsize) = -s $file;
61 return -ENOSYS() unless open(FILE,'+<',$file);
62 if($rv = seek(FILE,$off,SEEK_SET)) {
63 $rv = print(FILE $buf);
65 $rv = -ENOSYS() unless $rv;
70 sub err { return (-shift || -$!) }
72 sub x_readlink { return readlink(fixup(shift)); }
73 sub x_unlink { return unlink(fixup(shift)) ? 0 : -$!; }
75 sub x_symlink { print "symlink\n"; return symlink(shift,fixup(shift)) ? 0 : -$!; }
78 my ($old) = fixup(shift);
79 my ($new) = fixup(shift);
80 my ($err) = rename($old,$new) ? 0 : -ENOENT();
83 sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! }
85 my ($fn) = fixup(shift);
86 print "nonexistent $fn\n" unless -e $fn;
88 # perl's chown() does not chown symlinks, it chowns the symlink's
89 # target. it fails when the link's target doesn't exist, because
90 # the stat64() syscall fails.
91 # this causes error messages when unpacking symlinks in tarballs.
92 my ($err) = syscall(&SYS_lchown,$fn,$uid,$gid,$fn) ? -$! : 0;
96 my ($fn) = fixup(shift);
98 my ($err) = chmod($mode,$fn) ? 0 : -$!;
101 sub x_truncate { return truncate(fixup(shift),shift) ? 0 : -$! ; }
102 sub x_utime { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; }
104 sub x_mkdir { my ($name, $perm) = @_; return 0 if mkdir(fixup($name),$perm); return -$!; }
105 sub x_rmdir { return 0 if rmdir fixup(shift); return -$!; }
108 # since this is called for ALL files, not just devices, I'll do some checks
109 # and possibly run the real mknod command.
110 my ($file, $modes, $dev) = @_;
111 $file = fixup($file);
113 syscall(&SYS_mknod,$file,$modes,$dev);
118 sub x_statfs {return 255,1000000,500000,1000000,500000,4096}
119 my ($mountpoint) = "";
120 $mountpoint = shift(@ARGV) if @ARGV;
122 mountpoint=>$mountpoint,
123 getattr =>"main::x_getattr",
124 readlink=>"main::x_readlink",
125 getdir =>"main::x_getdir",
126 mknod =>"main::x_mknod",
127 mkdir =>"main::x_mkdir",
128 unlink =>"main::x_unlink",
129 rmdir =>"main::x_rmdir",
130 symlink =>"main::x_symlink",
131 rename =>"main::x_rename",
132 link =>"main::x_link",
133 chmod =>"main::x_chmod",
134 chown =>"main::x_chown",
135 truncate=>"main::x_truncate",
136 utime =>"main::x_utime",
137 open =>"main::x_open",
138 read =>"main::x_read",
139 write =>"main::x_write",
140 statfs =>"main::x_statfs",