fuse-mt
fuse-mt copied to clipboard
Type discrepancy for permissions
The chmod function passes the mode as a u32, but the perm field of FileAttr is a u16
This is because FUSE passes the mode as a u32, which is because the mode_t in chmod(2) is actually a 32-bit integer on some platforms (Linux at least). Not all the bits have a well-defined meaning, which is why FileAttr only takes a u16, but I guess nothing stops you from doing chmod(path, 0x10000); on Linux.
So I did some experiments, and found something interesting. On Linux, while you can pass any 32-bit value to chmod(), at some level it gets a mask applied and the maximum value fuse_mt sees is 0x8FFF. I'm not sure if this is the kernel or FUSE doing this.
So it might make sense to change the type after all.
Looks like macOS does the same thing; even though it defines mode_t as unsigned short (16 bits), everything is masked to 0x8FFF.