4

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.

Casey Rodarmor
  • 14,878
  • 5
  • 30
  • 33
  • 1
    @Tsyvarev in fact FUSE is the right answer, as it does provide the needed information. The OP has already posted the correct answer and we use this approach in one of our products as well. – Eugene Mayevski 'Callback May 19 '16 at 19:03
  • @EugeneMayevski'EldoSCorp: Oh, I forgot about passing additional info with request to FUSE. Incorrect comment has been removed. Thanks for pointing that. – Tsyvarev May 19 '16 at 20:08

1 Answers1

4

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.

Casey Rodarmor
  • 14,878
  • 5
  • 30
  • 33