chmod 中的模式参数?
Mode parameter in chmod?
我想弄清楚 setfmode()
的 mode
参数最终被 chmod()
调用是什么。
当我打印出来并执行类似 chmod +t test.txt
的操作时,“33700”会被打印出来。当我这样做时 chmod +w test.txt
“33252” 被打印出来。
有没有办法查看使用这些数字设置了哪些特定位?
有关权限位的完整说明,请参阅位于 https://www.freebsd.org/doc/handbook/permissions.html 的 FreeBSD 手册页。请注意,权限位的说明是八进制格式。
搜索引擎是你的朋友 - 我搜索 "FreeBSD permission bits" 并立即找到上面的 link 作为第一个返回结果。
来自聊天:
"I'm trying to find out if the user is setting the sticky bit, so in setfmode() I think I'll bitwise AND the mode variable with the sticky bit constant, then check if that equals the sticky bit constant"
粘滞位是八进制的 1000
- 参见 the FreeBSD chmod
man page
要在 C 中以八进制形式写入数字,请在值前面加上 0
,因此假设您的模式值位于名为 mode
的变量中,请执行 (mode & 01000)
。如果该值为零,则不设置粘性位,如果它为非零(即 01000
),则设置粘性位。
马克:“好的,我的支票似乎有效 -
if ((mode & S_ISTXT) == S_ISTXT)
我想弄清楚 setfmode()
的 mode
参数最终被 chmod()
调用是什么。
当我打印出来并执行类似 chmod +t test.txt
的操作时,“33700”会被打印出来。当我这样做时 chmod +w test.txt
“33252” 被打印出来。
有没有办法查看使用这些数字设置了哪些特定位?
有关权限位的完整说明,请参阅位于 https://www.freebsd.org/doc/handbook/permissions.html 的 FreeBSD 手册页。请注意,权限位的说明是八进制格式。
搜索引擎是你的朋友 - 我搜索 "FreeBSD permission bits" 并立即找到上面的 link 作为第一个返回结果。
来自聊天:
"I'm trying to find out if the user is setting the sticky bit, so in setfmode() I think I'll bitwise AND the mode variable with the sticky bit constant, then check if that equals the sticky bit constant"
粘滞位是八进制的 1000
- 参见 the FreeBSD chmod
man page
要在 C 中以八进制形式写入数字,请在值前面加上 0
,因此假设您的模式值位于名为 mode
的变量中,请执行 (mode & 01000)
。如果该值为零,则不设置粘性位,如果它为非零(即 01000
),则设置粘性位。
马克:“好的,我的支票似乎有效 -
if ((mode & S_ISTXT) == S_ISTXT)