Search code examples
linuxlinux-kernelfilesystemsfuse

What API will allow me to implement a linux filesystem which is aware of which process is accessing it?


I would like to implement a linux filesystem, either with FUSE or as a kernel module, which is aware of the process which is looking at it so that it can tailor the contents of the filesystem to the accessing process.

A concrete example of this kind of behavior is in /proc/self which is a symlink to /proc/PID, where PID is the current processes PID.

Is there a FUSE or kernel API that will allow me to do this?

The implementation for /proc/self is here:

https://github.com/torvalds/linux/blob/v4.3/fs/proc/self.c

It uses all sorts of internal kernel juju, so perhaps FUSE is out of the question.


Solution

  • The helpful folks on the fuse-devel mailing list pointed me towards an answer:

    fuse_req_ctx() in fuse_lowlevel.h returns a fuse_ctx struct for the current request, which contains the thread id, group id, and user id.