-
-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] FileMode::contain函数在判断O_WRONLY时,检测到同时存在O_WRONLY和O_RDONLY #1059
Comments
在bitflags-1.3.2库中,contain代码如下 /// Returns `true` if all of the flags in `other` are contained within `self`.
#[inline]
pub const fn contains(&self, other: Self) -> bool {
(self.bits & other.bits) == other.bits
} 而FileMode 中,这些模式(O_RDONLY、O_WRONLY、O_RDWR)的值是 非互斥的 (self.bits & other.bits) == other.bits 如果 other 是 O_RDONLY,无论 self.bits 的值如何,这个判断始终为 true,因为: self.bits & 0 == 0 即只要 other.bits == 0,条件总是成立。 需要重新设定FileMode中的模式以保证其之间的互斥性 |
FileMode那个是Linux规定的。那看来判断是否O_RDONLY、O_WRONLY、O_RDWR的话,应该是得在file mode里面实现个函数去判断。 判断方法应该是filemode.bits & 0x3 之后,判断跟上面的O_RDONLY、O_WRONLY、O_RDWR是否相等 |
Linux 使用 O_ACCMODE 掩码 来提取文件访问模式 #define O_ACCMODE 0x0003
int access_mode = flags & O_ACCMODE;
if (access_mode == O_RDONLY) {
// Handle read-only
} else if (access_mode == O_WRONLY) {
// Handle write-only
} else if (access_mode == O_RDWR) {
// Handle read-write
} |
该方法已经存在 |
#1060 (comment) |
描述错误
调换Pipe::open中判断O_WRONLY和O_RDONLY的判断顺序之后
请填写您的电脑的信息:
重现步骤
重现行为的步骤:
DragonOS/kernel/src/ipc/pipe.rs
期望行为
两个mode应该是互斥关系,不应该重复判断
其他上下文
#886 (comment)
The text was updated successfully, but these errors were encountered: