Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
32630628
提交
32630628
7月 29, 2006
创建
作者:
rtm
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
open()
上级
e46fb46f
隐藏空白字符变更
内嵌
并排
正在显示
17 个修改的文件
包含
89 行增加
和
13 行删除
+89
-13
bio.c
bio.c
+1
-1
console.c
console.c
+1
-1
defs.h
defs.h
+1
-1
fd.c
fd.c
+2
-0
fd.h
fd.h
+2
-1
fs.c
fs.c
+6
-3
ide.c
ide.c
+1
-1
kalloc.c
kalloc.c
+1
-1
main.c
main.c
+2
-0
proc.c
proc.c
+4
-2
proc.h
proc.h
+2
-0
spinlock.c
spinlock.c
+8
-2
spinlock.h
spinlock.h
+1
-0
syscall.c
syscall.c
+39
-0
syscall.h
syscall.h
+1
-0
userfs.c
userfs.c
+16
-0
usys.S
usys.S
+1
-0
没有找到文件。
bio.c
浏览文件 @
32630628
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#include "buf.h"
#include "buf.h"
struct
buf
buf
[
NBUF
];
struct
buf
buf
[
NBUF
];
struct
spinlock
buf_table_lock
;
struct
spinlock
buf_table_lock
=
{
"buf_table"
}
;
struct
buf
*
struct
buf
*
getblk
()
getblk
()
...
...
console.c
浏览文件 @
32630628
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include "defs.h"
#include "defs.h"
#include "spinlock.h"
#include "spinlock.h"
struct
spinlock
console_lock
;
struct
spinlock
console_lock
=
{
"console"
}
;
int
panicked
=
0
;
int
panicked
=
0
;
int
use_console_lock
=
0
;
int
use_console_lock
=
0
;
...
...
defs.h
浏览文件 @
32630628
...
@@ -99,7 +99,7 @@ void brelse(struct buf *);
...
@@ -99,7 +99,7 @@ void brelse(struct buf *);
struct
inode
*
iget
(
uint
dev
,
uint
inum
);
struct
inode
*
iget
(
uint
dev
,
uint
inum
);
void
ilock
(
struct
inode
*
ip
);
void
ilock
(
struct
inode
*
ip
);
void
iunlock
(
struct
inode
*
ip
);
void
iunlock
(
struct
inode
*
ip
);
void
i
in
cref
(
struct
inode
*
ip
);
void
i
de
cref
(
struct
inode
*
ip
);
void
iput
(
struct
inode
*
ip
);
void
iput
(
struct
inode
*
ip
);
struct
inode
*
namei
(
char
*
path
);
struct
inode
*
namei
(
char
*
path
);
int
readi
(
struct
inode
*
ip
,
void
*
xdst
,
uint
off
,
uint
n
);
int
readi
(
struct
inode
*
ip
,
void
*
xdst
,
uint
off
,
uint
n
);
fd.c
浏览文件 @
32630628
...
@@ -86,6 +86,8 @@ fd_close(struct fd *fd)
...
@@ -86,6 +86,8 @@ fd_close(struct fd *fd)
if
(
--
fd
->
ref
==
0
){
if
(
--
fd
->
ref
==
0
){
if
(
fd
->
type
==
FD_PIPE
){
if
(
fd
->
type
==
FD_PIPE
){
pipe_close
(
fd
->
pipe
,
fd
->
writeable
);
pipe_close
(
fd
->
pipe
,
fd
->
writeable
);
}
else
if
(
fd
->
type
==
FD_FILE
){
idecref
(
fd
->
ip
);
}
else
{
}
else
{
panic
(
"fd_close"
);
panic
(
"fd_close"
);
}
}
...
...
fd.h
浏览文件 @
32630628
struct
fd
{
struct
fd
{
enum
{
FD_CLOSED
,
FD_NONE
,
FD_PIPE
}
type
;
enum
{
FD_CLOSED
,
FD_NONE
,
FD_PIPE
,
FD_FILE
}
type
;
int
ref
;
// reference count
int
ref
;
// reference count
char
readable
;
char
readable
;
char
writeable
;
char
writeable
;
struct
pipe
*
pipe
;
struct
pipe
*
pipe
;
struct
inode
*
ip
;
};
};
extern
struct
fd
fds
[
NFD
];
extern
struct
fd
fds
[
NFD
];
fs.c
浏览文件 @
32630628
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
// these are inodes currently in use
// these are inodes currently in use
// an entry is free if count == 0
// an entry is free if count == 0
struct
inode
inode
[
NINODE
];
struct
inode
inode
[
NINODE
];
struct
spinlock
inode_table_lock
;
struct
spinlock
inode_table_lock
=
{
"inode_table"
}
;
uint
rootdev
=
1
;
uint
rootdev
=
1
;
...
@@ -111,11 +111,14 @@ iput(struct inode *ip)
...
@@ -111,11 +111,14 @@ iput(struct inode *ip)
}
}
void
void
i
in
cref
(
struct
inode
*
ip
)
i
de
cref
(
struct
inode
*
ip
)
{
{
acquire
(
&
inode_table_lock
);
acquire
(
&
inode_table_lock
);
ip
->
count
+=
1
;
if
(
ip
->
count
<
1
)
panic
(
"idecref"
);
ip
->
count
-=
1
;
release
(
&
inode_table_lock
);
release
(
&
inode_table_lock
);
}
}
...
...
ide.c
浏览文件 @
32630628
...
@@ -25,7 +25,7 @@ struct ide_request {
...
@@ -25,7 +25,7 @@ struct ide_request {
};
};
struct
ide_request
request
[
NREQUEST
];
struct
ide_request
request
[
NREQUEST
];
int
head
,
tail
;
int
head
,
tail
;
struct
spinlock
ide_lock
;
struct
spinlock
ide_lock
=
{
"ide"
}
;
int
disk_channel
;
int
disk_channel
;
...
...
kalloc.c
浏览文件 @
32630628
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
#include "proc.h"
#include "proc.h"
#include "spinlock.h"
#include "spinlock.h"
struct
spinlock
kalloc_lock
;
struct
spinlock
kalloc_lock
=
{
"kalloc"
}
;
struct
run
{
struct
run
{
struct
run
*
next
;
struct
run
*
next
;
...
...
main.c
浏览文件 @
32630628
...
@@ -95,6 +95,8 @@ mpmain(void)
...
@@ -95,6 +95,8 @@ mpmain(void)
{
{
cprintf
(
"an application processor
\n
"
);
cprintf
(
"an application processor
\n
"
);
idtinit
();
// CPU's idt
idtinit
();
// CPU's idt
if
(
cpu
()
==
0
)
panic
(
"mpmain on cpu 0"
);
lapic_init
(
cpu
());
lapic_init
(
cpu
());
lapic_timerinit
();
lapic_timerinit
();
lapic_enableintr
();
lapic_enableintr
();
...
...
proc.c
浏览文件 @
32630628
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include "defs.h"
#include "defs.h"
#include "spinlock.h"
#include "spinlock.h"
struct
spinlock
proc_table_lock
;
struct
spinlock
proc_table_lock
=
{
"proc_table"
}
;
struct
proc
proc
[
NPROC
];
struct
proc
proc
[
NPROC
];
struct
proc
*
curproc
[
NCPU
];
struct
proc
*
curproc
[
NCPU
];
...
@@ -137,8 +137,10 @@ scheduler(void)
...
@@ -137,8 +137,10 @@ scheduler(void)
cprintf
(
"start scheduler on cpu %d jmpbuf %p
\n
"
,
cpu
(),
&
cpus
[
cpu
()].
jmpbuf
);
cprintf
(
"start scheduler on cpu %d jmpbuf %p
\n
"
,
cpu
(),
&
cpus
[
cpu
()].
jmpbuf
);
cpus
[
cpu
()].
lastproc
=
&
proc
[
0
];
cpus
[
cpu
()].
lastproc
=
&
proc
[
0
];
if
(
cpus
[
cpu
()].
nlock
!=
0
)
if
(
cpus
[
cpu
()].
nlock
!=
0
){
cprintf
(
"la %x lr %x
\n
"
,
cpus
[
cpu
()].
lastacquire
,
cpus
[
cpu
()].
lastrelease
);
panic
(
"holding locks at first entry to scheduler"
);
panic
(
"holding locks at first entry to scheduler"
);
}
for
(;;){
for
(;;){
// Loop over process table looking for process to run.
// Loop over process table looking for process to run.
...
...
proc.h
浏览文件 @
32630628
...
@@ -70,6 +70,8 @@ struct cpu {
...
@@ -70,6 +70,8 @@ struct cpu {
char
mpstack
[
MPSTACK
];
// per-cpu start-up stack, only used to get into main()
char
mpstack
[
MPSTACK
];
// per-cpu start-up stack, only used to get into main()
struct
proc
*
lastproc
;
// last proc scheduled on this cpu (never NULL)
struct
proc
*
lastproc
;
// last proc scheduled on this cpu (never NULL)
int
nlock
;
// # of locks currently held
int
nlock
;
// # of locks currently held
struct
spinlock
*
lastacquire
;
// xxx debug
struct
spinlock
*
lastrelease
;
// xxx debug
};
};
extern
struct
cpu
cpus
[
NCPU
];
extern
struct
cpu
cpus
[
NCPU
];
...
...
spinlock.c
浏览文件 @
32630628
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
// Can't call cprintf from inside these routines,
// Can't call cprintf from inside these routines,
// because cprintf uses them itself.
// because cprintf uses them itself.
#define cprintf dont_use_cprintf
//
#define cprintf dont_use_cprintf
extern
int
use_console_lock
;
extern
int
use_console_lock
;
...
@@ -21,8 +21,12 @@ getcallerpc(void *v)
...
@@ -21,8 +21,12 @@ getcallerpc(void *v)
void
void
acquire
(
struct
spinlock
*
lock
)
acquire
(
struct
spinlock
*
lock
)
{
{
if
(
holding
(
lock
))
if
(
holding
(
lock
)){
extern
use_console_lock
;
use_console_lock
=
0
;
cprintf
(
"lock %s pc %x
\n
"
,
lock
->
name
?
lock
->
name
:
""
,
lock
->
pc
);
panic
(
"acquire"
);
panic
(
"acquire"
);
}
if
(
cpus
[
cpu
()].
nlock
++
==
0
)
if
(
cpus
[
cpu
()].
nlock
++
==
0
)
cli
();
cli
();
...
@@ -31,6 +35,7 @@ acquire(struct spinlock * lock)
...
@@ -31,6 +35,7 @@ acquire(struct spinlock * lock)
cpuid
(
0
,
0
,
0
,
0
,
0
);
// memory barrier
cpuid
(
0
,
0
,
0
,
0
,
0
);
// memory barrier
lock
->
pc
=
getcallerpc
(
&
lock
);
lock
->
pc
=
getcallerpc
(
&
lock
);
lock
->
cpu
=
cpu
();
lock
->
cpu
=
cpu
();
cpus
[
cpu
()].
lastacquire
=
lock
;
}
}
void
void
...
@@ -39,6 +44,7 @@ release(struct spinlock * lock)
...
@@ -39,6 +44,7 @@ release(struct spinlock * lock)
if
(
!
holding
(
lock
))
if
(
!
holding
(
lock
))
panic
(
"release"
);
panic
(
"release"
);
cpus
[
cpu
()].
lastrelease
=
lock
;
cpuid
(
0
,
0
,
0
,
0
,
0
);
// memory barrier
cpuid
(
0
,
0
,
0
,
0
,
0
);
// memory barrier
lock
->
locked
=
0
;
lock
->
locked
=
0
;
if
(
--
cpus
[
cpu
()].
nlock
==
0
)
if
(
--
cpus
[
cpu
()].
nlock
==
0
)
...
...
spinlock.h
浏览文件 @
32630628
struct
spinlock
{
struct
spinlock
{
char
*
name
;
uint
locked
;
uint
locked
;
uint
pc
;
uint
pc
;
int
cpu
;
int
cpu
;
...
...
syscall.c
浏览文件 @
32630628
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
#include "fs.h"
#include "fs.h"
#include "fsvar.h"
#include "fsvar.h"
#include "elf.h"
#include "elf.h"
#include "fd.h"
/*
/*
* User code makes a system call with INT T_SYSCALL.
* User code makes a system call with INT T_SYSCALL.
...
@@ -244,6 +245,41 @@ sys_cons_puts(void)
...
@@ -244,6 +245,41 @@ sys_cons_puts(void)
}
}
int
int
sys_open
(
void
)
{
struct
proc
*
cp
=
curproc
[
cpu
()];
struct
inode
*
ip
;
uint
arg0
,
arg1
;
int
ufd
;
struct
fd
*
fd
;
if
(
fetcharg
(
0
,
&
arg0
)
<
0
||
fetcharg
(
1
,
&
arg1
)
<
0
)
return
-
1
;
if
(
checkstring
(
arg0
)
<
0
)
return
-
1
;
if
((
ip
=
namei
(
cp
->
mem
+
arg0
))
==
0
)
return
-
1
;
if
((
fd
=
fd_alloc
())
==
0
){
iput
(
ip
);
return
-
1
;
}
if
((
ufd
=
fd_ualloc
())
<
0
){
iput
(
ip
);
fd_close
(
fd
);
return
-
1
;
}
iunlock
(
ip
);
fd
->
type
=
FD_FILE
;
fd
->
readable
=
1
;
fd
->
writeable
=
0
;
fd
->
ip
=
ip
;
cp
->
fds
[
ufd
]
=
fd
;
return
ufd
;
}
int
sys_exec
(
void
)
sys_exec
(
void
)
{
{
struct
proc
*
cp
=
curproc
[
cpu
()];
struct
proc
*
cp
=
curproc
[
cpu
()];
...
@@ -467,6 +503,9 @@ syscall(void)
...
@@ -467,6 +503,9 @@ syscall(void)
case
SYS_exec
:
case
SYS_exec
:
ret
=
sys_exec
();
ret
=
sys_exec
();
break
;
break
;
case
SYS_open
:
ret
=
sys_open
();
break
;
default:
default:
cprintf
(
"unknown sys call %d
\n
"
,
num
);
cprintf
(
"unknown sys call %d
\n
"
,
num
);
// XXX fault
// XXX fault
...
...
syscall.h
浏览文件 @
32630628
...
@@ -11,3 +11,4 @@
...
@@ -11,3 +11,4 @@
#define SYS_panic 11
#define SYS_panic 11
#define SYS_cons_puts 12
#define SYS_cons_puts 12
#define SYS_exec 13
#define SYS_exec 13
#define SYS_open 14
userfs.c
浏览文件 @
32630628
...
@@ -8,8 +8,24 @@ char *args[] = { "echo", "hello", "goodbye", 0 };
...
@@ -8,8 +8,24 @@ char *args[] = { "echo", "hello", "goodbye", 0 };
int
int
main
(
void
)
main
(
void
)
{
{
int
fd
;
puts
(
"userfs running
\n
"
);
puts
(
"userfs running
\n
"
);
block
();
block
();
fd
=
open
(
"echo"
,
0
);
if
(
fd
>=
0
){
puts
(
"open echo ok
\n
"
);
close
(
fd
);
}
else
{
puts
(
"open echo failed!
\n
"
);
}
fd
=
open
(
"doesnotexist"
,
0
);
if
(
fd
>=
0
){
puts
(
"open doesnotexist succeeded!
\n
"
);
close
(
fd
);
}
else
{
puts
(
"open doesnotexist failed
\n
"
);
}
exec
(
"echo"
,
args
);
exec
(
"echo"
,
args
);
return
0
;
return
0
;
}
}
usys.S
浏览文件 @
32630628
...
@@ -21,3 +21,4 @@ STUB(kill)
...
@@ -21,3 +21,4 @@ STUB(kill)
STUB(panic)
STUB(panic)
STUB(cons_puts)
STUB(cons_puts)
STUB(exec)
STUB(exec)
STUB(open)
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论