blob: 3b8cf5ad042fd48a59ba088daa12eb4caac85d72 [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...
32
33It's not easy. Consider mmap(): if you have a memory file, even after
34closing it, you can read or write the file through memory.
35
36Despite 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
61> one or more of the release calls..
62
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
85 - process forks
86 - 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.
128>
129> 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.
138
139No. Read from a pipe/socket can be short, but read from a file can't.
140
141---------------------------------------------------------------------------
142Subject: protocol error
143
144> I'm having trouble with file writing. I can
145> 'echo something > file' to a file, but
146> '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.
179
180Yes:
181
182fuse_get_context()->uid
183
184
185---------------------------------------------------------------------------
186Subject: 'find' command
187
188
189> I'm having trouble getting the find command to search through fuse
190> directories. What settings do I need in 'getattr'?
191
192use the -noleaf option to find
193(find uses the following parameters to determine whether it should recurse
194into a subdirectory)
195
196nr_links must be >= 3
197size must be > 0
198and must be a directory
199
200so just return those in the getattr for your directories and you wont have
201to use -noleaf.
202
203---------------------------------------------------------------------------
204Subject: File system interactivity
205
206> I need to add interactivity to my user space file system.
207> For example, while executing create(), I need to ask a
208> question to the terminal that issued the request.
209>
210> Is there a way I can achieve this goal?
211
212It would not be possible generally speaking, since it might not be an
213interactive program but rather a daemon, or a GUI program creating the
214file. However you should be able to get the PID for the caller, and
215by looking in /proc you should be able to find the process tty or
216something similar. Perhaps it would be better to redesign your program
217not to have such interactivity anyway, try to use e.g. extended
218attributes of files to set per-file options, or a configuration file
219for your filesystem.
220