7 local $SIG{'__WARN__'} = \&Carp::cluck;
15 use constant FIOC_NAME => 'fioc';
17 use constant FIOC_NONE => 0;
18 use constant FIOC_ROOT => 1;
19 use constant FIOC_FILE => 2;
21 require 'asm/ioctl.ph';
23 our %sizeof = ('int' => 4);
24 sub FIOC_GET_SIZE { _IOR(ord 'E', 0, 'int'); }
25 sub FIOC_SET_SIZE { _IOW(ord 'E', 1, 'int'); }
29 print 'called ', (caller(0))[3], "\n";
30 return 0 if $size == $fioc_size;
32 if ($size < $fioc_size) {
33 $fioc_buf = substr($fioc_buf, 0, $size);
36 $fioc_buf .= "\0" x ($size - $fioc_size);
44 print 'called ', (caller(0))[3], "\n";
45 if ($size > $fioc_size) {
46 return fioc_resize($size);
53 print 'called ', (caller(0))[3], "\n";
54 return FIOC_ROOT if $path eq '/';
55 return FIOC_FILE if $path eq '/' . FIOC_NAME;
61 print 'called ', (caller(0))[3], "\n";
62 my @stbuf = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
65 $stbuf[5] = (split(/\s+/, $())[0];
66 $stbuf[8] = $stbuf[9] = time();
68 my $type = fioc_file_type($path);
69 if ($type == FIOC_ROOT) {
70 $stbuf[2] = S_IFDIR | 0755;
73 elsif ($type == FIOC_FILE) {
74 $stbuf[2] = S_IFREG | 0644;
76 $stbuf[7] = $fioc_size;
85 my ($path, $flags, $info) = @_;
86 print 'called ', (caller(0))[3], "\n";
88 if (fioc_file_type($path) != FIOC_NONE) {
95 my ($path, $size, $offset) = @_;
96 print 'called ', (caller(0))[3], "\n";
98 return -&EINVAL if fioc_file_type($path) != FIOC_FILE;
100 if ($offset > $fioc_size) {
104 if ($size > $fioc_size - $offset) {
105 $size - $fioc_size - $offset;
108 return substr($fioc_buf, $offset, $size);
112 my ($path, $data, $offset) = @_;
113 print 'called ', (caller(0))[3], "\n";
115 return -&EINVAL if fioc_file_type($path) != FIOC_FILE;
117 if (fioc_expand($offset + length($data))) {
121 substr($fioc_buf, $offset, length($data), $data);
122 return length($data);
126 my ($path, $size) = @_;
127 print 'called ', (caller(0))[3], "\n";
129 return -&EINVAL if fioc_file_type($path) != FIOC_FILE;
131 return fioc_resize($size);
135 my ($path, $offset) = @_;
136 print 'called ', (caller(0))[3], "\n";
138 return -&EINVAL if fioc_file_type($path) != FIOC_ROOT;
140 return ('.', '..', FIOC_NAME, 0);
144 my ($path, $cmd, $flags, $data) = @_;
145 print 'called ', (caller(0))[3], "\n";
146 $cmd = unpack('L', pack('l', $cmd));
148 print("fioc_ioctl(): path is \"$path\", cmd is $cmd, flags is $flags\n");
149 return -&EINVAL if fioc_file_type($path) != FIOC_FILE;
151 return -&ENOSYS if $flags & 0x1;
153 if ($cmd == FIOC_GET_SIZE) {
154 print "handling FIOC_GET_SIZE\n";
155 return(0, pack('L', $fioc_size));
157 elsif ($cmd == FIOC_SET_SIZE) {
158 print "handling FIOC_SET_SIZE\n";
159 fioc_resize(unpack('L', $data));
166 croak("Fuse doesn't have ioctl") unless Fuse::fuse_version() >= 2.8;
169 'mountpoint' => $ARGV[0],
170 'getattr' => 'main::fioc_getattr',
171 'readdir' => 'main::fioc_readdir',
172 'truncate' => 'main::fioc_truncate',
173 'open' => 'main::fioc_open',
174 'read' => 'main::fioc_read',
175 'write' => 'main::fioc_write',
176 'ioctl' => 'main::fioc_ioctl');