|
From: Hans B. <han...@gm...> - 2012-03-05 20:11:24
|
On 2012-03-05 8:25, Matt Turner wrote: > On 5 March 2012 18:25, Hans Beckerus <han...@gm... > <mailto:han...@gm...>> wrote: > > Is it possible that someone could elaborate on what to return from > read > calls? > If direct_io=0, my understanding is that a read should always > return the > exact number of requested bytes. > But what is confusing me is the case when offset+size exceeds the file > size? Is it still required to return the number of requested bytes but > pad buffer with zeros or is it ok to return only the size actually > read > until EOF without padding? > Also, if the read request offset is equal or greater than the file > size, > should I simply return 0 to indicate EOF? > > > Importantly the return value of read() and the number of *valid* bytes > written into buf should be equal. read() should return the number of > bytes successfully read. If offset + size exceeds the length of the > file then read() should return the number of bytes it was able to > satisfy. That much of buf should be filled with the data; the rest can > be left uninitialised or zero'd or something. > > read() can also chose not to return all the bytes asked for because of > an error or because it simply doesn't want to perform an expensive > operation yet. Again, just be sure to indicate this with the return > value. Good userspace code should notice this and re-request those bytes. > > In the general case, read() will be able to return all the bytes > requested, and hence should return count. > > I used to assume that offset would always be < file size, and asserted > this in my filesystem. However you do see the odd request with offset > >= file size. I've found that just returning 0 works fine. The read() > man page implies this with "zero indicates end of file". > > matt Thanks. All that makes sense. But then, do we actually need to handle the direct_io=1 case specifically? According to FUSE API reference when direct_io=1 the return from read should be equal to the system call read(). For normal case that should be ok with a common implementation. But I am a bit worried about the error cases? If the return should match the system call, then a call to fuse read() should return -1 and set errno instead of returning -errno ? Hans |