Search code examples
cfuse

How to keep track of working directory in FUSE


So I am implementing a filesystem FUSE. I would like to know in which directory I am located when calling a function (specifically "mkdir"). Is there a way to know that? Or a way to keep track of directories when the user uses the "cd" command? The "getcwd" function always returns the root directory.


Solution

  • The libfuse deamon is operating as root, and not in the context of the user operating on the mounted filesystem. This is why getcwd in your fuse code always returns the root directory. However, you do have access to some of the calling user's attributes, in particular their PID number, with fuse_get_context()->pid (see linux how to intercept unauthorized process access to the file,base with FUSE( cryfs or gocryptfs ))

    Using the PID you can fetch the user's current directory by calling readlink() on /proc/$pid/cwd (see https://unix.stackexchange.com/questions/509420/get-working-directory-of-logged-in-users)