Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
9e698c58
提交
9e698c58
10月 13, 2006
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Symbolic link implementation (in symlinks branch).
上级
f8ac6396
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
105 行增加
和
9 行删除
+105
-9
Makefile
Makefile
+6
-2
defs.h
defs.h
+1
-0
fs.c
fs.c
+53
-7
fs.h
fs.h
+1
-0
ln.c
ln.c
+25
-0
rm.c
rm.c
+1
-0
syscall.c
syscall.c
+4
-0
syscall.h
syscall.h
+1
-0
sysfile.c
sysfile.c
+10
-0
user.h
user.h
+2
-0
usys.S
usys.S
+1
-0
没有找到文件。
Makefile
浏览文件 @
9e698c58
...
@@ -98,11 +98,15 @@ _rm : rm.o $(ULIB)
...
@@ -98,11 +98,15 @@ _rm : rm.o $(ULIB)
$(LD)
-N
-e
main
-Ttext
0
-o
_rm rm.o
$(ULIB)
$(LD)
-N
-e
main
-Ttext
0
-o
_rm rm.o
$(ULIB)
$(OBJDUMP)
-S
_rm
>
rm.asm
$(OBJDUMP)
-S
_rm
>
rm.asm
_ln
:
ln.o $(ULIB)
$(LD)
-N
-e
main
-Ttext
0
-o
_ln ln.o
$(ULIB)
$(OBJDUMP)
-S
_ln
>
ln.asm
mkfs
:
mkfs.c fs.h
mkfs
:
mkfs.c fs.h
cc
-o
mkfs mkfs.c
cc
-o
mkfs mkfs.c
fs.img
:
mkfs usertests _echo _cat README _init _sh _ls _mkdir _rm
fs.img
:
mkfs usertests _echo _cat README _init _sh _ls _mkdir _rm
_ln
./mkfs fs.img usertests _echo _cat README _init _sh _ls _mkdir _rm
./mkfs fs.img usertests _echo _cat README _init _sh _ls _mkdir _rm
_ln
-include
*.d
-include
*.d
...
...
defs.h
浏览文件 @
9e698c58
...
@@ -135,6 +135,7 @@ int readi(struct inode*, char*, uint, uint);
...
@@ -135,6 +135,7 @@ int readi(struct inode*, char*, uint, uint);
int
writei
(
struct
inode
*
,
char
*
,
uint
,
uint
);
int
writei
(
struct
inode
*
,
char
*
,
uint
,
uint
);
struct
inode
*
mknod
(
char
*
,
short
,
short
,
short
);
struct
inode
*
mknod
(
char
*
,
short
,
short
,
short
);
struct
inode
*
mknod1
(
struct
inode
*
,
char
*
,
short
,
short
,
short
);
struct
inode
*
mknod1
(
struct
inode
*
,
char
*
,
short
,
short
,
short
);
int
symlink
(
char
*
,
char
*
);
int
unlink
(
char
*
);
int
unlink
(
char
*
);
void
iupdate
(
struct
inode
*
);
void
iupdate
(
struct
inode
*
);
int
link
(
char
*
,
char
*
);
int
link
(
char
*
,
char
*
);
fs.c
浏览文件 @
9e698c58
...
@@ -442,7 +442,7 @@ writei(struct inode *ip, char *addr, uint off, uint n)
...
@@ -442,7 +442,7 @@ writei(struct inode *ip, char *addr, uint off, uint n)
if
(
ip
->
major
<
0
||
ip
->
major
>=
NDEV
||
!
devsw
[
ip
->
major
].
write
)
if
(
ip
->
major
<
0
||
ip
->
major
>=
NDEV
||
!
devsw
[
ip
->
major
].
write
)
return
-
1
;
return
-
1
;
return
devsw
[
ip
->
major
].
write
(
ip
->
minor
,
addr
,
n
);
return
devsw
[
ip
->
major
].
write
(
ip
->
minor
,
addr
,
n
);
}
else
if
(
ip
->
type
==
T_FILE
||
ip
->
type
==
T_DIR
)
{
}
else
if
(
ip
->
type
==
T_FILE
||
ip
->
type
==
T_DIR
||
ip
->
type
==
T_SYMLINK
)
{
struct
buf
*
bp
;
struct
buf
*
bp
;
int
r
=
0
;
int
r
=
0
;
int
m
;
int
m
;
...
@@ -493,14 +493,16 @@ namei(char *path, int mode, uint *ret_off,
...
@@ -493,14 +493,16 @@ namei(char *path, int mode, uint *ret_off,
char
**
ret_last
,
struct
inode
**
ret_ip
)
char
**
ret_last
,
struct
inode
**
ret_ip
)
{
{
struct
inode
*
dp
;
struct
inode
*
dp
;
char
link
[
64
];
struct
proc
*
p
=
curproc
[
cpu
()];
struct
proc
*
p
=
curproc
[
cpu
()];
char
*
cp
=
path
,
*
cp1
;
char
*
cp
,
*
cp1
;
uint
off
,
dev
;
uint
off
,
dev
;
struct
buf
*
bp
;
struct
buf
*
bp
;
struct
dirent
*
ep
;
struct
dirent
*
ep
;
int
i
,
l
,
atend
;
int
i
,
l
,
atend
,
n
,
nlink
;
uint
ninum
;
uint
ninum
;
again:
if
(
ret_off
)
if
(
ret_off
)
*
ret_off
=
0xffffffff
;
*
ret_off
=
0xffffffff
;
if
(
ret_last
)
if
(
ret_last
)
...
@@ -508,6 +510,7 @@ namei(char *path, int mode, uint *ret_off,
...
@@ -508,6 +510,7 @@ namei(char *path, int mode, uint *ret_off,
if
(
ret_ip
)
if
(
ret_ip
)
*
ret_ip
=
0
;
*
ret_ip
=
0
;
cp
=
path
;
if
(
*
cp
==
'/'
)
if
(
*
cp
==
'/'
)
dp
=
iget
(
rootdev
,
1
);
dp
=
iget
(
rootdev
,
1
);
else
{
else
{
...
@@ -516,13 +519,29 @@ namei(char *path, int mode, uint *ret_off,
...
@@ -516,13 +519,29 @@ namei(char *path, int mode, uint *ret_off,
ilock
(
dp
);
ilock
(
dp
);
}
}
nlink
=
0
;
for
(;;){
for
(;;){
while
(
*
cp
==
'/'
)
while
(
*
cp
==
'/'
)
cp
++
;
cp
++
;
if
(
*
cp
==
'\0'
){
if
(
*
cp
==
'\0'
){
if
(
mode
==
NAMEI_LOOKUP
)
if
(
mode
==
NAMEI_LOOKUP
){
if
(
dp
->
type
==
T_SYMLINK
){
if
((
n
=
readi
(
dp
,
link
,
0
,
sizeof
link
-
1
))
<=
0
){
iput
(
dp
);
return
0
;
}
link
[
n
]
=
0
;
path
=
link
;
iput
(
dp
);
if
(
++
nlink
>
10
){
cprintf
(
"symlink max depth: %s
\n
"
,
path
);
return
0
;
}
goto
again
;
}
return
dp
;
return
dp
;
}
if
(
mode
==
NAMEI_CREATE
&&
ret_ip
){
if
(
mode
==
NAMEI_CREATE
&&
ret_ip
){
*
ret_ip
=
dp
;
*
ret_ip
=
dp
;
return
0
;
return
0
;
...
@@ -698,12 +717,12 @@ unlink(char *cp)
...
@@ -698,12 +717,12 @@ unlink(char *cp)
// Create the path new as a link to the same inode as old.
// Create the path new as a link to the same inode as old.
int
int
link
(
char
*
name1
,
char
*
name2
)
link
(
char
*
old
,
char
*
new
)
{
{
struct
inode
*
ip
,
*
dp
;
struct
inode
*
ip
,
*
dp
;
char
*
last
;
char
*
last
;
if
((
ip
=
namei
(
name1
,
NAMEI_LOOKUP
,
0
,
0
,
0
))
==
0
)
if
((
ip
=
namei
(
old
,
NAMEI_LOOKUP
,
0
,
0
,
0
))
==
0
)
return
-
1
;
return
-
1
;
if
(
ip
->
type
==
T_DIR
){
if
(
ip
->
type
==
T_DIR
){
iput
(
ip
);
iput
(
ip
);
...
@@ -712,7 +731,7 @@ link(char *name1, char *name2)
...
@@ -712,7 +731,7 @@ link(char *name1, char *name2)
iunlock
(
ip
);
iunlock
(
ip
);
if
((
dp
=
namei
(
n
ame2
,
NAMEI_CREATE
,
0
,
&
last
,
0
))
==
0
)
{
if
((
dp
=
namei
(
n
ew
,
NAMEI_CREATE
,
0
,
&
last
,
0
))
==
0
)
{
idecref
(
ip
);
idecref
(
ip
);
return
-
1
;
return
-
1
;
}
}
...
@@ -732,3 +751,30 @@ link(char *name1, char *name2)
...
@@ -732,3 +751,30 @@ link(char *name1, char *name2)
return
0
;
return
0
;
}
}
int
strlen
(
char
*
s
)
{
int
n
=
0
;
while
(
*
s
++
!=
0
)
n
++
;
return
n
;
}
// Create the path new as a symlink to old.
int
symlink
(
char
*
old
,
char
*
new
)
{
struct
inode
*
ip
,
*
dp
;
char
*
last
;
if
((
dp
=
namei
(
new
,
NAMEI_CREATE
,
0
,
&
last
,
0
))
==
0
)
return
-
1
;
ip
=
mknod1
(
dp
,
last
,
T_SYMLINK
,
0
,
0
);
iput
(
dp
);
if
(
ip
==
0
)
return
-
1
;
writei
(
ip
,
old
,
0
,
strlen
(
old
));
iput
(
ip
);
return
0
;
}
fs.h
浏览文件 @
9e698c58
...
@@ -33,6 +33,7 @@ struct dinode {
...
@@ -33,6 +33,7 @@ struct dinode {
#define T_DIR 1 // Directory
#define T_DIR 1 // Directory
#define T_FILE 2 // File
#define T_FILE 2 // File
#define T_DEV 3 // Special device
#define T_DEV 3 // Special device
#define T_SYMLINK 4 // Symbolic link
// Inodes per block.
// Inodes per block.
#define IPB (BSIZE / sizeof(struct dinode))
#define IPB (BSIZE / sizeof(struct dinode))
...
...
ln.c
0 → 100644
浏览文件 @
9e698c58
#include "types.h"
#include "user.h"
int
main
(
int
argc
,
char
*
argv
[])
{
int
(
*
ln
)(
char
*
,
char
*
);
ln
=
link
;
if
(
argc
>
1
&&
strcmp
(
argv
[
1
],
"-s"
)
==
0
){
ln
=
symlink
;
argc
--
;
argv
++
;
}
if
(
argc
!=
3
){
printf
(
2
,
"usage: ln [-s] old new (%d)
\n
"
,
argc
);
exit
();
}
if
(
ln
(
argv
[
1
],
argv
[
2
])
<
0
){
printf
(
2
,
"%s failed
\n
"
,
ln
==
symlink
?
"symlink"
:
"link"
);
exit
();
}
exit
();
}
rm.c
浏览文件 @
9e698c58
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include "stat.h"
#include "stat.h"
#include "user.h"
#include "user.h"
int
main
(
int
argc
,
char
*
argv
[])
main
(
int
argc
,
char
*
argv
[])
{
{
int
i
;
int
i
;
...
...
syscall.c
浏览文件 @
9e698c58
...
@@ -104,6 +104,7 @@ extern int sys_open(void);
...
@@ -104,6 +104,7 @@ extern int sys_open(void);
extern
int
sys_pipe
(
void
);
extern
int
sys_pipe
(
void
);
extern
int
sys_read
(
void
);
extern
int
sys_read
(
void
);
extern
int
sys_sbrk
(
void
);
extern
int
sys_sbrk
(
void
);
extern
int
sys_symlink
(
void
);
extern
int
sys_unlink
(
void
);
extern
int
sys_unlink
(
void
);
extern
int
sys_wait
(
void
);
extern
int
sys_wait
(
void
);
extern
int
sys_write
(
void
);
extern
int
sys_write
(
void
);
...
@@ -158,6 +159,9 @@ syscall(void)
...
@@ -158,6 +159,9 @@ syscall(void)
case
SYS_link
:
case
SYS_link
:
ret
=
sys_link
();
ret
=
sys_link
();
break
;
break
;
case
SYS_symlink
:
ret
=
sys_symlink
();
break
;
case
SYS_mkdir
:
case
SYS_mkdir
:
ret
=
sys_mkdir
();
ret
=
sys_mkdir
();
break
;
break
;
...
...
syscall.h
浏览文件 @
9e698c58
...
@@ -18,3 +18,4 @@
...
@@ -18,3 +18,4 @@
#define SYS_dup 17
#define SYS_dup 17
#define SYS_getpid 18
#define SYS_getpid 18
#define SYS_sbrk 19
#define SYS_sbrk 19
#define SYS_symlink 20
sysfile.c
浏览文件 @
9e698c58
...
@@ -313,6 +313,16 @@ sys_link(void)
...
@@ -313,6 +313,16 @@ sys_link(void)
}
}
int
int
sys_symlink
(
void
)
{
char
*
old
,
*
new
;
if
(
argstr
(
0
,
&
old
)
<
0
||
argstr
(
1
,
&
new
)
<
0
)
return
-
1
;
return
symlink
(
old
,
new
);
}
int
sys_exec
(
void
)
sys_exec
(
void
)
{
{
struct
proc
*
cp
=
curproc
[
cpu
()];
struct
proc
*
cp
=
curproc
[
cpu
()];
...
...
user.h
浏览文件 @
9e698c58
...
@@ -11,8 +11,10 @@ int exec(char*, char**);
...
@@ -11,8 +11,10 @@ int exec(char*, char**);
int
open
(
char
*
,
int
);
int
open
(
char
*
,
int
);
int
mknod
(
char
*
,
short
,
short
,
short
);
int
mknod
(
char
*
,
short
,
short
,
short
);
int
unlink
(
char
*
);
int
unlink
(
char
*
);
struct
stat
;
int
fstat
(
int
fd
,
struct
stat
*
);
int
fstat
(
int
fd
,
struct
stat
*
);
int
link
(
char
*
,
char
*
);
int
link
(
char
*
,
char
*
);
int
symlink
(
char
*
,
char
*
);
int
mkdir
(
char
*
);
int
mkdir
(
char
*
);
int
chdir
(
char
*
);
int
chdir
(
char
*
);
int
dup
(
int
);
int
dup
(
int
);
...
...
usys.S
浏览文件 @
9e698c58
...
@@ -27,3 +27,4 @@ STUB(chdir)
...
@@ -27,3 +27,4 @@ STUB(chdir)
STUB(dup)
STUB(dup)
STUB(getpid)
STUB(getpid)
STUB(sbrk)
STUB(sbrk)
STUB(symlink)
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论