Search code examples
cpermissionssystem-callsfusestat

Permission override after stat is called


Hi I'm writing "net raid fs" with FUSE.

So when syscall getattr is called, I'm sending it to server, server is calling stat(path, stbuf) syscall and it sets stbuf as it should do. After that I'm returning this stbuf to client (with socket connection) and client handles it and everything is working okay.

But here is the problem: I want stbuf->st_mode (AKA permissions) always to be 0777, so I'm doing stbuf->st_mode = 0777; and after that sending this struct to client (as I did above). And program kind of freezes (server [or client] stops receiving syscalls properly).

What to do?


Solution

  • The st_mode member includes more than just the permissions, it also includes the file type (directory, fifo, device special file, etc.). If you simply assign 0777 to it, you'll remove the type information. You should just overwrite the permission bits.

    stbuf->mode |= 0777;
    

    From the documentation:

     The status information word st_mode has the following bits:
    
     #define S_IFMT 0170000           /* type of file */
     #define        S_IFIFO  0010000  /* named pipe (fifo) */
     #define        S_IFCHR  0020000  /* character special */
     #define        S_IFDIR  0040000  /* directory */
     #define        S_IFBLK  0060000  /* block special */
     #define        S_IFREG  0100000  /* regular */
     #define        S_IFLNK  0120000  /* symbolic link */
     #define        S_IFSOCK 0140000  /* socket */
     #define        S_IFWHT  0160000  /* whiteout */
     #define S_ISUID 0004000  /* set user id on execution */
     #define S_ISGID 0002000  /* set group id on execution */
     #define S_ISVTX 0001000  /* save swapped text even after use */
     #define S_IRUSR 0000400  /* read permission, owner */
     #define S_IWUSR 0000200  /* write permission, owner */
     #define S_IXUSR 0000100  /* execute/search permission, owner */