Search code examples
fuse

Acquire fuse_file_info in FUSE's truncate()


Is it possible to acquire the struct fuse_file_info* fi in the function truncate()? Why is it not there in the first place?

int truncate(const char* path, off_t size)

I'm storing my file descriptor in the file handler, fh, of the fuse_file_info structure. The function open() appears to be called beforehand so that structure is created for the file. The description of fh is: "File handle. May be filled in by filesystem in open(). Available in all other file operations".

(As a last resort I'm thinking of having a structure to store this information, saved into a hash map, and then use the file handler to store the key. This would allow me to search the structure, using the path, in order to find the respective file descriptor.)

Note: I'm actually using jnr-fuse but since it mimics libfuse I'm not asking specifically for it; what works for one should (sort of) work for the other.


Solution

  • Why is it not there in the first place?

    Because of implementation of truncate in the Linux kernel. You can see signature here.