10 local $SIG{'__WARN__'} = \&Carp::cluck;
16 my $fioc_size :shared = 0;
17 use constant FIOC_NAME => 'fioc';
18 my $fioc_buf :shared = '';
19 use constant FIOC_NONE => 0;
20 use constant FIOC_ROOT => 1;
21 use constant FIOC_FILE => 2;
23 require 'asm/ioctl.ph';
25 our %sizeof = ('int' => 4);
26 sub FIOC_GET_SIZE { _IOR(ord 'E', 0, 'int'); }
27 sub FIOC_SET_SIZE { _IOW(ord 'E', 1, 'int'); }
31 print 'called ', (caller(0))[3], "\n";
32 return 0 if $size == $fioc_size;
34 if ($size < $fioc_size) {
35 $fioc_buf = substr($fioc_buf, 0, $size);
38 $fioc_buf .= "\0" x ($size - $fioc_size);
46 print 'called ', (caller(0))[3], "\n";
47 if ($size > $fioc_size) {
48 return fioc_resize($size);
55 print 'called ', (caller(0))[3], "\n";
56 return FIOC_ROOT if $path eq '/';
57 return FIOC_FILE if $path eq '/' . FIOC_NAME;
63 print 'called ', (caller(0))[3], "\n";
64 my @stbuf = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
67 $stbuf[5] = (split(/\s+/, $())[0];
68 $stbuf[8] = $stbuf[9] = time();
70 my $type = fioc_file_type($path);
71 if ($type == FIOC_ROOT) {
72 $stbuf[2] = S_IFDIR | 0755;
75 elsif ($type == FIOC_FILE) {
76 $stbuf[2] = S_IFREG | 0644;
78 $stbuf[7] = $fioc_size;
87 my ($path, $flags, $info) = @_;
88 print 'called ', (caller(0))[3], "\n";
90 if (fioc_file_type($path) != FIOC_NONE) {
97 my ($path, $size, $offset) = @_;
98 print 'called ', (caller(0))[3], "\n";
100 return -&EINVAL if fioc_file_type($path) != FIOC_FILE;
102 if ($offset > $fioc_size) {
106 if ($size > $fioc_size - $offset) {
107 $size - $fioc_size - $offset;
110 return substr($fioc_buf, $offset, $size);
114 my ($path, $data, $offset) = @_;
115 print 'called ', (caller(0))[3], "\n";
118 return -&EINVAL if fioc_file_type($path) != FIOC_FILE;
120 if (fioc_expand($offset + length($data))) {
124 substr($fioc_buf, $offset, length($data), $data);
125 return length($data);
129 my ($path, $size) = @_;
130 print 'called ', (caller(0))[3], "\n";
133 return -&EINVAL if fioc_file_type($path) != FIOC_FILE;
135 return fioc_resize($size);
139 my ($path, $offset) = @_;
140 print 'called ', (caller(0))[3], "\n";
142 return -&EINVAL if fioc_file_type($path) != FIOC_ROOT;
144 return ('.', '..', FIOC_NAME, 0);
148 my ($path, $cmd, $flags, $data) = @_;
149 print 'called ', (caller(0))[3], "\n";
151 return -&EINVAL if fioc_file_type($path) != FIOC_FILE;
153 return -&ENOSYS if $flags & 0x1;
155 if ($cmd == FIOC_GET_SIZE) {
156 return(0, pack('L', $fioc_size));
158 elsif ($cmd == FIOC_SET_SIZE) {
160 fioc_resize(unpack('L', $data));
167 croak("Fuse doesn't have ioctl") unless Fuse::fuse_version() >= 2.8;
170 'mountpoint' => $ARGV[0],
171 'getattr' => 'main::fioc_getattr',
172 'readdir' => 'main::fioc_readdir',
173 'truncate' => 'main::fioc_truncate',
174 'open' => 'main::fioc_open',
175 'read' => 'main::fioc_read',
176 'write' => 'main::fioc_write',
177 'ioctl' => 'main::fioc_ioctl',