【发布时间】:2018-11-18 14:23:59
【问题描述】:
在 xv6 中处理文件时,我可以看到一个名为 Omode 的整数变量。它是什么?它可以有什么价值?
例如,这是来自 Xv6 的开放系统调用:
int sys_open(void)
{
char *path;
int fd, omode;
struct file *f;
struct inode *ip;
if (argstr(0, &path) < 0 || argint(1, &omode) < 0)
return -1;
begin_op();
if (omode & O_CREATE) {
ip = create(path, T_FILE, 0, 0);
if (ip == 0) {
end_op();
return -1;
}
} else {
if ((ip = namei(path)) == 0) {
end_op();
return -1;
}
ilock(ip);
if (ip->type == T_DIR && omode != O_RDONLY) {
iunlockput(ip);
end_op();
return -1;
}
}
if ((f = filealloc()) == 0 || (fd = fdalloc(f)) < 0) {
if (f)
fileclose(f);
iunlockput(ip);
end_op();
return -1;
}
iunlock(ip);
end_op();
f->type = FD_INODE;
f->ip = ip;
f->off = 0;
f->readable = !(omode & O_WRONLY);
f->writable = (omode & O_WRONLY) || (omode & O_RDWR);
return fd;
}
它似乎可能是 O_WRONLY、O_RDWR 或 O_CREATE。这些值代表什么?
【问题讨论】:
-
“打开模式”?参见例如the POSIX
openreference.