【问题标题】:Permission override after stat is called调用 stat 后的权限覆盖
【发布时间】:2018-12-26 22:16:24
【问题描述】:

您好,我正在使用 FUSE 编写“net raid fs”。

所以当系统调用getattr 被调用时,我将它发送到服务器,服务器正在调用stat(path, stbuf) 系统调用并且它设置stbuf 应该做的。之后,我将这个stbuf 返回给客户端(使用套接字连接),客户端处理它,一切正常。

但问题是:我希望stbuf->st_mode(AKA 权限)始终为 0777,所以我正在做stbuf->st_mode = 0777;,然后将这个struct 发送给客户端(就像我在上面所做的那样)。并且程序类型冻结(服务器 [或客户端] 停止正确接收系统调用)。

怎么办?

【问题讨论】:

标签: c permissions system-calls fuse stat


【解决方案1】:

st_mode 成员不仅包括权限,还包括文件类型(目录、fifo、设备特殊文件等)。如果您只是将0777 分配给它,您将删除类型信息。您应该只覆盖权限位。

stbuf->mode |= 0777;

来自文档:

 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 */

【讨论】:

  • 但是每个类别不是只有 3 位吗?不是我的 DV。
  • 我从文档中添加了一段摘录,显示它还包含包含文件类型的 S_IFMT 字段。
猜你喜欢
  • 2020-12-02
  • 1970-01-01
  • 2019-08-24
  • 2018-12-21
  • 2021-03-16
  • 1970-01-01
  • 1970-01-01
  • 2021-01-14
  • 1970-01-01
相关资源
最近更新 更多