问题
I'm using FUSE to create an overlay filesystem, where directories are augmented with virtual entities. I am setting the file size of these entities to 0, because I have no way of knowing -- ahead of reading them, which is particularly expensive in my case -- what they should be.
However, there seems to be an obvious optimisation taking place, insofar as zero-length files don't incur any read
call (only open
and release
).
My question therefore is simply, what should I set the file size to? I know symlinks have a size of their filename length; would this work, given it's not a symlink? Otherwise, the best I can do is provide a lower bound for the size... If read
only has a file descriptor, chunk size and offset, presumably it reads 'til EOF rather than whatever stat
can tell it.
回答1:
The file size must be correct. A lot of code depends on this information, you can't simply omit it.
That means you need to figure out an efficient way to cache/precalculate this information.
Have a look at the sources of cmdfs which runs a command on all files in the filesystem. Linux Magazine has an overview article.
来源:https://stackoverflow.com/questions/31940468/file-size-of-virtual-file