blob: 826bbf4a6aa0fad384426e49da1f352159642772 [file] [log] [blame]
Miklos Szeredia2c5e562004-10-19 22:01:21 +00001Here are some good questions and answers in no particular order.
2
3---------------------------------------------------------------------------
4Subject: FUSE vs. LUFS
5
6
7> Can you explain me what are the differences between this two modules
8> and why did you start a new project?
9
10Well looking at the release dates on SF, the first release of FUSE is
11almost a year older than that of LUFS. But we probably weren't awere
12of each others project for quite some time.
13
14The main difference between them is that in LUFS the filesystem is a
15shared object (.so) which is loaded by lufsmount, and in FUSE the
16filesystem is a separate executable, which uses the fuse library. The
17actual API is very similar, and I've written a translator, that can
18load LUFS modules and run them using the FUSE kernel module (see the
19lufis package on the FUSE page).
20
21Another difference is that LUFS does some caching of directories and
22file attributes. FUSE does not do this, so it provides a 'thinner'
23interface.
24
25---------------------------------------------------------------------------
26Subject: close() not in struct fuse_operations
27
28
29> Is there a reason for 'close' not being one of the
30> fuse_operations? I'd need to know when files are
31> closed...
Miklos Szeredie5183742005-02-02 11:14:04 +000032
Miklos Szeredia2c5e562004-10-19 22:01:21 +000033It's not easy. Consider mmap(): if you have a memory file, even after
Miklos Szeredie5183742005-02-02 11:14:04 +000034closing it, you can read or write the file through memory.
35
Miklos Szeredia2c5e562004-10-19 22:01:21 +000036Despite this there are close()-like operations: flush and release.
37Flush gets called on each close() and release gets called when there
38are no more uses of a file, including memory mappings.
39
40---------------------------------------------------------------------------
41Subject: overlapping open/release states
42
43
44> I'm using a fairly current CVS version of Fuse, and have noticed
45> overlapping open / release calls for a file. In other words a file
46> is opened multiple times and receives multiple release calls. Is
47> this expected?
48
49It has always been like this. The open / release calls correspond to
50actual file opens / releases. The release is called when there are no
51more refernces to the file, i.e. on the last close() or munmap().
52
53> This isn't what I expected. Do I need to keep track of how many
54> open() calls were made to a file and expect that many release() calls?
55
56Yes. You can also keep track of the number of files opened for
57writing for example, and use that information for finally flushing
58dirty data of a file.
59
60> So it appears that there may even be additional file operations after
Miklos Szeredie5183742005-02-02 11:14:04 +000061> one or more of the release calls..
Miklos Szeredia2c5e562004-10-19 22:01:21 +000062
63That is expected also. It would be a bug if there were reads/writes
64after the last release, or if the number of releases didn't match the
65number of opens.
66
67> I've solved this in my code by counting the number of open / release
68> calls and only dropping information when the last expected release
69> is received. But I thought I'd point this out in case, as it was
70> unexpected behavior..
71
72---------------------------------------------------------------------------
73Subject: return value from release()
74
75
76> Hmm. So it doesn't matter what I return from my release function? I
77> understand there is not an exact 1:1 relationship between close() and
78> release, but I had hoped that a error return from release would be
79> carried up as an error return from close().
80
81In release() the error value is ignored, and not every close will
82cause a release. Consider this:
83
84 - process opens a file
Miklos Szeredie5183742005-02-02 11:14:04 +000085 - process forks
Miklos Szeredia2c5e562004-10-19 22:01:21 +000086 - parent closes the file
87 - child closes the file
88
89The file will only be released on the second close, i.e. when all
90references to the file are closed. Also memory mapping a file creates
91a reference to the file, that is released when the memory is unmapped.
92
93There is a flush() operation that is called on every close(), through
94which the filesystem can return an error.
95
96Note: there can be read/write operations even after the last flush()
97but before a release().
98
99---------------------------------------------------------------------------
100Subject: FUSE lacks ioctl support
101
102
103> I'll try to add ioctl support to FUSE, but I am quite new to it, so I
104> would apreciate any suggestions.
105
106It's not clear to me how would you use ioctls since they are
107meaningless on normal files, and on device files the filesystem
108implementation usually does not care about the ioctl operations. And
109even if you manage to hack fuse to intercept device ioctls, you
110wouldn't be able to do anything with them, because they contain
111arbitrarily structured data (not length/value as in the case of read
112or write).
113
114[...]
115
116Using getxattr() and setxattr() is much cleaner than ioctl(), and is
117actually supported in fuse-2.0.
118
119---------------------------------------------------------------------------
120Subject: Short reads
121
122
123> Now for the problem case: I cat the 256k file, the kernel issues a
124> read with length 65536 and offset 0. My program returns only 10
125> bytes. What I expected to see was the kernel to then issue a read for
126> length 65536 and offset 10. Instead what I saw in the result was the
127> 10 bytes I returned, followed by 65526 zero bytes.
Miklos Szeredie5183742005-02-02 11:14:04 +0000128>
Miklos Szeredia2c5e562004-10-19 22:01:21 +0000129> Is this the intended behavior?
130
131Yes. You can easily program around it with a for-loop in your read
132function.
133
134> Does this simplify things significantly? If it isn't much of a
135> difference, I'd like to suggest doing it the other way: many people
136> (like me) implement their fuse read function in terms of read(), and
137> read() can return early.
Miklos Szeredie5183742005-02-02 11:14:04 +0000138
139No. Read from a pipe/socket can be short, but read from a file can't.
Miklos Szeredia2c5e562004-10-19 22:01:21 +0000140
141---------------------------------------------------------------------------
142Subject: protocol error
143
Miklos Szeredie5183742005-02-02 11:14:04 +0000144> I'm having trouble with file writing. I can
145> 'echo something > file' to a file, but
Miklos Szeredia2c5e562004-10-19 22:01:21 +0000146> 'cp file something' or 'cat something > file'
147> gives a protocol error.
148
149Two possible reasons for this are:
150
1511) A mismatch between the library version and the kernel module
152version.
153
1542) The write() operation returns less than the 'size' parameter.
155Short writes are generally not allowed (as in case of read()). The
156exception is if the 'direct_io' mount option is used.
157
158---------------------------------------------------------------------------
159Subject: FUSE naming
160
161
162> There are a million other projects with the same name. Why did you
163> call it 'FUSE'?
164
165Because I'm an imbecile. The lesson is that a common term is not a
166good project name. A somewhat strange story comes to my mind: I was
167contacted by Philip Kendall shortly after releasing FUSE, blaming me
168for choosing the same name as his ZX Spectrum emulator (Fuse). We
169have known each other from earlier times, since I have also written a
170ZX Spectrum emulator (Spectemu).
171
172---------------------------------------------------------------------------
173Subject: Uid/gid/pid
174
175
176> Is there any easy way to know the uid of a reader? For example, let's
177> say I wanted to create a file that contained 'foo' for uid 1, but
178> 'bar' for uid 2.
Miklos Szeredie5183742005-02-02 11:14:04 +0000179
180Yes:
181
Miklos Szeredia2c5e562004-10-19 22:01:21 +0000182fuse_get_context()->uid
183
184
185---------------------------------------------------------------------------
Miklos Szeredie5183742005-02-02 11:14:04 +0000186Subject: 'find' command
Miklos Szeredia2c5e562004-10-19 22:01:21 +0000187
188
189> I'm having trouble getting the find command to search through fuse
190> directories. What settings do I need in 'getattr'?
191
Miklos Szeredi4322e172005-08-02 09:53:51 +0000192The 'st_nlink' member must be set correctly for directories to make
193'find' work. If it's not set correctly the '-noleaf' option of find
194can be used to make it ignore the hard link count (see 'man find').
Miklos Szeredia2c5e562004-10-19 22:01:21 +0000195
Miklos Szeredi4322e172005-08-02 09:53:51 +0000196The correct value of 'st_nlink' for directories is NSUB + 2. Where
197NSUB is the number of subdirectories. NOTE: regular-file/symlink/etc
198entries _do not_ count into NSUB, only directories.
Miklos Szeredia2c5e562004-10-19 22:01:21 +0000199
Miklos Szeredi4322e172005-08-02 09:53:51 +0000200If calculating NSUB is hard, the filesystem can set st_nlink to 1 for
201directories, and find will still work. This is not documented
202behavior of find, and it's not clear whether this is intended or just
203by accident. The NTFS filesysem uses this for example, so it's
204unlikely that this find "feature" will go away.
Miklos Szeredia2c5e562004-10-19 22:01:21 +0000205
206---------------------------------------------------------------------------
207Subject: File system interactivity
208
209> I need to add interactivity to my user space file system.
210> For example, while executing create(), I need to ask a
211> question to the terminal that issued the request.
212>
213> Is there a way I can achieve this goal?
Miklos Szeredie5183742005-02-02 11:14:04 +0000214
Miklos Szeredia2c5e562004-10-19 22:01:21 +0000215It would not be possible generally speaking, since it might not be an
216interactive program but rather a daemon, or a GUI program creating the
217file. However you should be able to get the PID for the caller, and
218by looking in /proc you should be able to find the process tty or
219something similar. Perhaps it would be better to redesign your program
220not to have such interactivity anyway, try to use e.g. extended
221attributes of files to set per-file options, or a configuration file
222for your filesystem.
Miklos Szeredie5183742005-02-02 11:14:04 +0000223