7 local $SIG{'__WARN__'} = \&Carp::cluck;
14 use constant FIOC_NAME => 'fioc';
16 use constant FIOC_NONE => 0;
17 use constant FIOC_ROOT => 1;
18 use constant FIOC_FILE => 2;
20 require 'asm/ioctl.ph';
22 our %sizeof = ('int' => 4);
23 sub FIOC_GET_SIZE { _IOR(ord 'E', 0, 'int'); }
24 sub FIOC_SET_SIZE { _IOW(ord 'E', 1, 'int'); }
28 print 'called ', (caller(0))[3], "\n";
29 return 0 if $size == $fioc_size;
31 if ($size < $fioc_size) {
32 $fioc_buf = substr($fioc_buf, 0, $size);
35 $fioc_buf .= "\0" x ($size - $fioc_size);
43 print 'called ', (caller(0))[3], "\n";
44 if ($size > $fioc_size) {
45 return fioc_resize($size);
52 print 'called ', (caller(0))[3], "\n";
53 return FIOC_ROOT if $path eq '/';
54 return FIOC_FILE if $path eq '/' . FIOC_NAME;
60 print 'called ', (caller(0))[3], "\n";
61 my @stbuf = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
64 $stbuf[5] = (split(/\s+/, $())[0];
65 $stbuf[8] = $stbuf[9] = time();
67 my $type = fioc_file_type($path);
68 if ($type == FIOC_ROOT) {
69 $stbuf[2] = S_IFDIR | 0755;
72 elsif ($type == FIOC_FILE) {
73 $stbuf[2] = S_IFREG | 0644;
75 $stbuf[7] = $fioc_size;
84 my ($path, $flags, $info) = @_;
85 print 'called ', (caller(0))[3], "\n";
87 if (fioc_file_type($path) != FIOC_NONE) {
94 my ($path, $size, $offset) = @_;
95 print 'called ', (caller(0))[3], "\n";
97 return -&EINVAL if fioc_file_type($path) != FIOC_FILE;
99 if ($offset > $fioc_size) {
103 if ($size > $fioc_size - $offset) {
104 $size - $fioc_size - $offset;
107 return substr($fioc_buf, $offset, $size);
111 my ($path, $data, $offset) = @_;
112 print 'called ', (caller(0))[3], "\n";
114 return -&EINVAL if fioc_file_type($path) != FIOC_FILE;
116 if (fioc_expand($offset + length($data))) {
120 substr($fioc_buf, $offset, length($data), $data);
121 return length($data);
125 my ($path, $size) = @_;
126 print 'called ', (caller(0))[3], "\n";
128 return -&EINVAL if fioc_file_type($path) != FIOC_FILE;
130 return fioc_resize($size);
134 my ($path, $offset) = @_;
135 print 'called ', (caller(0))[3], "\n";
137 return -&EINVAL if fioc_file_type($path) != FIOC_ROOT;
139 return ('.', '..', FIOC_NAME, 0);
143 my ($path, $cmd, $flags, $data) = @_;
144 print 'called ', (caller(0))[3], "\n";
145 $cmd = unpack('L', pack('l', $cmd));
147 return -&EINVAL if fioc_file_type($path) != FIOC_FILE;
149 return -&ENOSYS if $flags & 0x1;
151 if ($cmd == FIOC_GET_SIZE) {
152 return(0, pack('L', $fioc_size));
154 elsif ($cmd == FIOC_SET_SIZE) {
155 fioc_resize(unpack('L', $data));
162 croak("Fuse doesn't have ioctl") unless Fuse::fuse_version() >= 2.8;
165 'mountpoint' => $ARGV[0],
166 'getattr' => 'main::fioc_getattr',
167 'readdir' => 'main::fioc_readdir',
168 'truncate' => 'main::fioc_truncate',
169 'open' => 'main::fioc_open',
170 'read' => 'main::fioc_read',
171 'write' => 'main::fioc_write',
172 'ioctl' => 'main::fioc_ioctl');