6 use POSIX qw(ENOENT ENOSYS EEXIST EPERM O_RDONLY O_RDWR O_APPEND O_CREAT);
7 use Fcntl qw(S_ISBLK S_ISCHR S_ISFIFO SEEK_SET);
8 require 'syscall.ph'; # for SYS_mknod and SYS_lchown
10 sub fixup { return "/tmp/fusetest-" . $ENV{LOGNAME} . shift }
13 my ($file) = fixup(shift);
14 my (@list) = lstat($file);
15 return -$! unless @list;
20 my ($dirname) = fixup(shift);
21 unless(opendir(DIRHANDLE,$dirname)) {
24 my (@files) = readdir(DIRHANDLE);
30 my ($file) = fixup(shift);
32 return -$! unless sysopen(FILE,$file,$mode);
38 my ($file,$bufsize,$off) = @_;
40 my ($handle) = new IO::File;
41 return -ENOENT() unless -e ($file = fixup($file));
42 my ($fsize) = -s $file;
43 return -ENOSYS() unless open($handle,$file);
44 if(seek($handle,$off,SEEK_SET)) {
45 read($handle,$rv,$bufsize);
51 my ($file,$buf,$off) = @_;
53 return -ENOENT() unless -e ($file = fixup($file));
54 my ($fsize) = -s $file;
55 return -ENOSYS() unless open(FILE,'+<',$file);
56 if($rv = seek(FILE,$off,SEEK_SET)) {
57 $rv = print(FILE $buf);
59 $rv = -ENOSYS() unless $rv;
64 sub err { return (-shift || -$!) }
66 sub x_readlink { return readlink(fixup(shift) ); }
67 sub x_unlink { return unlink(fixup(shift)) ? 0 : -$!; }
68 sub x_rmdir { return err(rmdir(fixup(shift)) ); }
70 sub x_symlink { print "symlink\n"; return symlink(shift,fixup(shift)) ? 0 : -$!; }
73 my ($old) = fixup(shift);
74 my ($new) = fixup(shift);
75 my ($err) = rename($old,$new) ? 0 : -ENOENT();
78 sub x_link { return link(fixup(shift),fixup(shift)) ? 0 : -$! }
80 my ($fn) = fixup(shift);
81 print "nonexistent $fn\n" unless -e $fn;
83 # perl's chown() does not chown symlinks, it chowns the symlink's
84 # target. it fails when the link's target doesn't exist, because
85 # the stat64() syscall fails.
86 # this causes error messages when unpacking symlinks in tarballs.
87 my ($err) = syscall(&SYS_lchown,$fn,$uid,$gid,$fn) ? -$! : 0;
91 my ($fn) = fixup(shift);
93 my ($err) = chmod($mode,$fn) ? 0 : -$!;
96 sub x_truncate { return truncate(fixup(shift),shift) ? 0 : -$! ; }
97 sub x_utime { return utime($_[1],$_[2],fixup($_[0])) ? 0:-$!; }
99 sub x_mkdir { my ($name, $perm) = @_; return 0 if mkdir(fixup($name),$perm); return -$!; }
100 sub x_rmdir { return 0 if rmdir fixup(shift); return -$!; }
103 # since this is called for ALL files, not just devices, I'll do some checks
104 # and possibly run the real mknod command.
105 my ($file, $modes, $dev) = @_;
106 $file = fixup($file);
108 syscall(&SYS_mknod,$file,$modes,$dev);
113 sub x_statfs {return 255,1000000,500000,1000000,500000,4096}
114 my ($mountpoint) = "";
115 $mountpoint = shift(@ARGV) if @ARGV;
117 mountpoint=>$mountpoint,
118 getattr=>\&x_getattr,
119 readlink=>\&x_readlink,
125 symlink=>\&x_symlink,
130 truncate=>\&x_truncate,