Search code examples
fuselibgit2

fuse: is it possible to save information between calls?


I am working on a fuse-based FS. It can be used to publish (RO) a branch/revision/tag from git (with tracking.... you move a branch, the FS gets refreshed)... early stages of development, just in case.... and I use libgit2.

https://github.com/eantoranz/gitmod

I was thinking that in the process of filling up the content of a file I could get multiple calls to .read if the file is big enough. At the moment, I am not using any caching so, for every request that is made, I open up the object that is being requested and then fill up the buffer. There are multiple problems with this approach:

  • I would need to open the same object multiple times and get the content in memory for every one of those calls.
  • Also, a branch might change while I am still getting calls to .read and if the file has changed, I won't be able to notice it and content won't be consistent.

If I were able to hold the object that I am using for reading between calls to .read then I would not need to open the object multiple times and at least the content of the file will be consistent even if outdated (next time the file is attempted to be read will get the right content).... so. I checked in https://libfuse.github.io/doxygen/structfuse__file__info.html and I don't think there's anything like a (void *) in there that I could use to hold information between the calls. I see that there's fh but it's an id, not really what I need.

Are there other tricks available in fuse to achieve this?


Solution

  • You should use the open call to store your context in fi->fh (file handle). It's an int64 you can cast to whatever, a void * alternative.

    https://github.com/libfuse/libfuse/blob/master/example/passthrough.c#L293