Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
9cc8199d
提交
9cc8199d
2月 29, 2012
创建
作者:
Nickolai Zeldovich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
openat
上级
bbb74797
隐藏空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
46 行增加
和
25 行删除
+46
-25
fcntl.h
include/fcntl.h
+2
-0
kern_c.h
include/kern_c.h
+1
-1
kernel.hh
include/kernel.hh
+2
-2
syscall.h
include/syscall.h
+1
-1
user.h
include/user.h
+1
-0
bootdata.c
kernel/bootdata.c
+1
-1
exec.cc
kernel/exec.cc
+1
-1
fs.cc
kernel/fs.cc
+6
-6
proc.cc
kernel/proc.cc
+1
-1
sysfile.cc
kernel/sysfile.cc
+23
-11
ulib.c
lib/ulib.c
+6
-0
usys.S
lib/usys.S
+1
-1
没有找到文件。
include/fcntl.h
浏览文件 @
9cc8199d
...
...
@@ -2,3 +2,5 @@
#define O_WRONLY 0x001
#define O_RDWR 0x002
#define O_CREATE 0x200
#define AT_FDCWD -100
include/kern_c.h
浏览文件 @
9cc8199d
...
...
@@ -31,7 +31,7 @@ long sys_kill(int);
long
sys_link
(
const
char
*
,
const
char
*
);
long
sys_mkdir
(
const
char
*
);
long
sys_mknod
(
const
char
*
,
int
,
int
);
long
sys_open
(
const
char
*
,
int
);
long
sys_open
at
(
int
,
const
char
*
,
int
);
long
sys_pipe
(
int
*
);
long
sys_read
(
int
,
char
*
,
int
);
long
sys_sbrk
(
int
);
...
...
include/kernel.hh
浏览文件 @
9cc8199d
...
...
@@ -99,7 +99,7 @@ int filewrite(struct file*, char*, int n);
int
namecmp
(
const
char
*
,
const
char
*
);
struct
inode
*
dirlookup
(
struct
inode
*
,
char
*
);
struct
inode
*
ialloc
(
u32
,
short
);
struct
inode
*
namei
(
const
char
*
);
struct
inode
*
namei
(
inode
*
cwd
,
const
char
*
);
void
iput
(
struct
inode
*
);
struct
inode
*
iget
(
u32
dev
,
u32
inum
);
void
ilock
(
struct
inode
*
,
int
writer
);
...
...
@@ -110,7 +110,7 @@ int readi(struct inode*, char*, u32, u32);
void
stati
(
struct
inode
*
,
struct
stat
*
);
int
writei
(
struct
inode
*
,
char
*
,
u32
,
u32
);
struct
inode
*
idup
(
struct
inode
*
);
struct
inode
*
nameiparent
(
const
char
*
,
char
*
);
struct
inode
*
nameiparent
(
inode
*
cwd
,
const
char
*
,
char
*
);
int
dirlink
(
struct
inode
*
,
const
char
*
,
u32
);
void
dir_init
(
struct
inode
*
dp
);
void
dir_flush
(
struct
inode
*
dp
);
...
...
include/syscall.h
浏览文件 @
9cc8199d
...
...
@@ -8,7 +8,7 @@
#define SYS_close 7
#define SYS_kill 8
#define SYS_exec 9
#define SYS_open
10
#define SYS_open
at
10
#define SYS_mknod 11
#define SYS_unlink 12
#define SYS_fstat 13
...
...
include/user.h
浏览文件 @
9cc8199d
...
...
@@ -30,6 +30,7 @@ void halt(void);
ssize_t
pread
(
int
,
void
*
,
size_t
,
off_t
);
int
async
(
int
,
size_t
,
off_t
,
u32
,
u32
);
int
script
(
void
*
addr
,
u64
len
,
u64
chunk
);
int
openat
(
int
dirfd
,
const
char
*
pathname
,
int
omode
);
// ulib.c
int
stat
(
char
*
,
struct
stat
*
);
...
...
kernel/bootdata.c
浏览文件 @
9cc8199d
...
...
@@ -41,7 +41,7 @@ long (*syscalls[])(u64, u64, u64, u64, u64) = {
SYSCALL
(
link
),
SYSCALL
(
mkdir
),
SYSCALL
(
mknod
),
SYSCALL
(
open
),
SYSCALL
(
open
at
),
SYSCALL
(
pipe
),
SYSCALL
(
read
),
SYSCALL
(
sbrk
),
...
...
kernel/exec.cc
浏览文件 @
9cc8199d
...
...
@@ -153,7 +153,7 @@ exec(const char *path, char **argv)
struct
vmap
*
oldvmap
;
prof_start
(
exec_prof
);
if
((
ip
=
namei
(
path
))
==
0
)
if
((
ip
=
namei
(
myproc
()
->
cwd
,
path
))
==
0
)
return
-
1
;
gc_begin_epoch
();
...
...
kernel/fs.cc
浏览文件 @
9cc8199d
...
...
@@ -745,7 +745,7 @@ skipelem(const char **rpath, char *name)
// If parent != 0, return the inode for the parent and copy the final
// path element into name, which must have room for DIRSIZ bytes.
static
struct
inode
*
namex
(
const
char
*
path
,
int
nameiparent
,
char
*
name
)
namex
(
inode
*
cwd
,
const
char
*
path
,
int
nameiparent
,
char
*
name
)
{
struct
inode
*
ip
,
*
next
;
int
r
;
...
...
@@ -754,7 +754,7 @@ namex(const char *path, int nameiparent, char *name)
if
(
*
path
==
'/'
)
ip
=
iget
(
ROOTDEV
,
ROOTINO
);
else
ip
=
idup
(
myproc
()
->
cwd
);
ip
=
idup
(
cwd
);
while
((
r
=
skipelem
(
&
path
,
name
))
==
1
){
next
=
0
;
...
...
@@ -790,17 +790,17 @@ namex(const char *path, int nameiparent, char *name)
}
struct
inode
*
namei
(
const
char
*
path
)
namei
(
inode
*
cwd
,
const
char
*
path
)
{
char
name
[
DIRSIZ
];
struct
inode
*
r
=
namex
(
path
,
0
,
name
);
struct
inode
*
r
=
namex
(
cwd
,
path
,
0
,
name
);
//cprintf("namei: %s -> %x (%d)\n", path, r, r?r->inum:0);
return
r
;
}
struct
inode
*
nameiparent
(
const
char
*
path
,
char
*
name
)
nameiparent
(
inode
*
cwd
,
const
char
*
path
,
char
*
name
)
{
return
namex
(
path
,
1
,
name
);
return
namex
(
cwd
,
path
,
1
,
name
);
}
kernel/proc.cc
浏览文件 @
9cc8199d
...
...
@@ -101,7 +101,7 @@ forkret(void)
// in which to call cv_sleep().
if
(
myproc
()
->
cwd
==
nullptr
)
{
mtstart
(
forkret
,
myproc
());
myproc
()
->
cwd
=
namei
(
"/"
);
myproc
()
->
cwd
=
namei
(
myproc
()
->
cwd
,
"/"
);
mtstop
(
myproc
());
}
...
...
kernel/sysfile.cc
浏览文件 @
9cc8199d
...
...
@@ -132,7 +132,7 @@ sys_link(const char *old, const char *newn)
if
(
argcheckstr
(
old
)
<
0
||
argcheckstr
(
newn
)
<
0
)
return
-
1
;
if
((
ip
=
namei
(
old
))
==
0
)
if
((
ip
=
namei
(
myproc
()
->
cwd
,
old
))
==
0
)
return
-
1
;
ilock
(
ip
,
1
);
if
(
ip
->
type
==
T_DIR
){
...
...
@@ -143,7 +143,7 @@ sys_link(const char *old, const char *newn)
iupdate
(
ip
);
iunlock
(
ip
);
if
((
dp
=
nameiparent
(
newn
,
name
))
==
0
)
if
((
dp
=
nameiparent
(
myproc
()
->
cwd
,
newn
,
name
))
==
0
)
goto
bad
;
if
(
dp
->
dev
!=
ip
->
dev
||
dirlink
(
dp
,
name
,
ip
->
inum
)
<
0
)
goto
bad
;
...
...
@@ -185,7 +185,7 @@ sys_unlink(const char *path)
if
(
argcheckstr
(
path
)
<
0
)
return
-
1
;
if
((
dp
=
nameiparent
(
path
,
name
))
==
0
)
if
((
dp
=
nameiparent
(
myproc
()
->
cwd
,
path
,
name
))
==
0
)
return
-
1
;
if
(
dp
->
type
!=
T_DIR
)
panic
(
"sys_unlink"
);
...
...
@@ -234,13 +234,13 @@ sys_unlink(const char *path)
}
static
struct
inode
*
create
(
const
char
*
path
,
short
type
,
short
major
,
short
minor
)
create
(
inode
*
cwd
,
const
char
*
path
,
short
type
,
short
major
,
short
minor
)
{
struct
inode
*
ip
,
*
dp
;
char
name
[
DIRSIZ
];
retry:
if
((
dp
=
nameiparent
(
path
,
name
))
==
0
)
if
((
dp
=
nameiparent
(
cwd
,
path
,
name
))
==
0
)
return
0
;
if
(
dp
->
type
!=
T_DIR
)
panic
(
"create"
);
...
...
@@ -284,20 +284,32 @@ create(const char *path, short type, short major, short minor)
}
long
sys_open
(
const
char
*
path
,
int
omode
)
sys_open
at
(
int
dirfd
,
const
char
*
path
,
int
omode
)
{
int
fd
;
struct
file
*
f
;
struct
inode
*
ip
;
struct
inode
*
cwd
;
if
(
dirfd
==
AT_FDCWD
)
{
cwd
=
myproc
()
->
cwd
;
}
else
if
(
dirfd
<
0
||
dirfd
>=
NOFILE
)
{
return
-
1
;
}
else
{
struct
file
*
fdir
=
myproc
()
->
ofile
[
dirfd
];
if
(
fdir
->
type
!=
file
::
FD_INODE
)
return
-
1
;
cwd
=
fdir
->
ip
;
}
if
(
argcheckstr
(
path
)
<
0
)
return
-
1
;
if
(
omode
&
O_CREATE
){
if
((
ip
=
create
(
path
,
T_FILE
,
0
,
0
))
==
0
)
if
((
ip
=
create
(
cwd
,
path
,
T_FILE
,
0
,
0
))
==
0
)
return
-
1
;
}
else
{
retry:
if
((
ip
=
namei
(
path
))
==
0
)
if
((
ip
=
namei
(
cwd
,
path
))
==
0
)
return
-
1
;
ilock
(
ip
,
0
);
if
(
ip
->
type
==
0
)
{
...
...
@@ -335,7 +347,7 @@ sys_mkdir(const char *path)
{
struct
inode
*
ip
;
if
(
argcheckstr
(
path
)
<
0
||
(
ip
=
create
(
path
,
T_DIR
,
0
,
0
))
==
0
)
if
(
argcheckstr
(
path
)
<
0
||
(
ip
=
create
(
myproc
()
->
cwd
,
path
,
T_DIR
,
0
,
0
))
==
0
)
return
-
1
;
iunlockput
(
ip
);
return
0
;
...
...
@@ -348,7 +360,7 @@ sys_mknod(const char *path, int major, int minor)
int
len
;
if
((
len
=
argcheckstr
(
path
))
<
0
||
(
ip
=
create
(
path
,
T_DEV
,
major
,
minor
))
==
0
)
(
ip
=
create
(
myproc
()
->
cwd
,
path
,
T_DEV
,
major
,
minor
))
==
0
)
return
-
1
;
iunlockput
(
ip
);
return
0
;
...
...
@@ -359,7 +371,7 @@ sys_chdir(const char *path)
{
struct
inode
*
ip
;
if
(
argcheckstr
(
path
)
<
0
||
(
ip
=
namei
(
path
))
==
0
)
if
(
argcheckstr
(
path
)
<
0
||
(
ip
=
namei
(
myproc
()
->
cwd
,
path
))
==
0
)
return
-
1
;
ilock
(
ip
,
0
);
if
(
ip
->
type
!=
T_DIR
){
...
...
lib/ulib.c
浏览文件 @
9cc8199d
...
...
@@ -130,3 +130,9 @@ memmove(void *vdst, const void *vsrc, int n)
*
dst
++
=
*
src
++
;
return
vdst
;
}
int
open
(
const
char
*
path
,
int
omode
)
{
return
openat
(
AT_FDCWD
,
path
,
omode
);
}
lib/usys.S
浏览文件 @
9cc8199d
...
...
@@ -25,7 +25,7 @@ SYSCALL(write)
SYSCALL(close)
SYSCALL(kill)
SYSCALL_INT(exec)
SYSCALL(open)
SYSCALL(open
at
)
SYSCALL(mknod)
SYSCALL(unlink)
SYSCALL(fstat)
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论