Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
f9a06440
提交
f9a06440
7月 11, 2009
创建
作者:
Russ Cox
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rearrangements and cleanup for text
上级
2de1c550
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
102 行增加
和
107 行删除
+102
-107
fs.c
fs.c
+50
-49
initcode.S
initcode.S
+1
-1
kalloc.c
kalloc.c
+18
-22
sysfile.c
sysfile.c
+33
-35
没有找到文件。
fs.c
浏览文件 @
f9a06440
...
@@ -141,6 +141,53 @@ iinit(void)
...
@@ -141,6 +141,53 @@ iinit(void)
initlock
(
&
icache
.
lock
,
"icache"
);
initlock
(
&
icache
.
lock
,
"icache"
);
}
}
static
struct
inode
*
iget
(
uint
dev
,
uint
inum
);
//PAGEBREAK!
// Allocate a new inode with the given type on device dev.
struct
inode
*
ialloc
(
uint
dev
,
short
type
)
{
int
inum
;
struct
buf
*
bp
;
struct
dinode
*
dip
;
struct
superblock
sb
;
readsb
(
dev
,
&
sb
);
for
(
inum
=
1
;
inum
<
sb
.
ninodes
;
inum
++
){
// loop over inode blocks
bp
=
bread
(
dev
,
IBLOCK
(
inum
));
dip
=
(
struct
dinode
*
)
bp
->
data
+
inum
%
IPB
;
if
(
dip
->
type
==
0
){
// a free inode
memset
(
dip
,
0
,
sizeof
(
*
dip
));
dip
->
type
=
type
;
bwrite
(
bp
);
// mark it allocated on the disk
brelse
(
bp
);
return
iget
(
dev
,
inum
);
}
brelse
(
bp
);
}
panic
(
"ialloc: no inodes"
);
}
// Copy inode, which has changed, from memory to disk.
void
iupdate
(
struct
inode
*
ip
)
{
struct
buf
*
bp
;
struct
dinode
*
dip
;
bp
=
bread
(
ip
->
dev
,
IBLOCK
(
ip
->
inum
));
dip
=
(
struct
dinode
*
)
bp
->
data
+
ip
->
inum
%
IPB
;
dip
->
type
=
ip
->
type
;
dip
->
major
=
ip
->
major
;
dip
->
minor
=
ip
->
minor
;
dip
->
nlink
=
ip
->
nlink
;
dip
->
size
=
ip
->
size
;
memmove
(
dip
->
addrs
,
ip
->
addrs
,
sizeof
(
ip
->
addrs
));
bwrite
(
bp
);
brelse
(
bp
);
}
// Find the inode with number inum on device dev
// Find the inode with number inum on device dev
// and return the in-memory copy.
// and return the in-memory copy.
static
struct
inode
*
static
struct
inode
*
...
@@ -263,51 +310,6 @@ iunlockput(struct inode *ip)
...
@@ -263,51 +310,6 @@ iunlockput(struct inode *ip)
}
}
//PAGEBREAK!
//PAGEBREAK!
// Allocate a new inode with the given type on device dev.
struct
inode
*
ialloc
(
uint
dev
,
short
type
)
{
int
inum
;
struct
buf
*
bp
;
struct
dinode
*
dip
;
struct
superblock
sb
;
readsb
(
dev
,
&
sb
);
for
(
inum
=
1
;
inum
<
sb
.
ninodes
;
inum
++
){
// loop over inode blocks
bp
=
bread
(
dev
,
IBLOCK
(
inum
));
dip
=
(
struct
dinode
*
)
bp
->
data
+
inum
%
IPB
;
if
(
dip
->
type
==
0
){
// a free inode
memset
(
dip
,
0
,
sizeof
(
*
dip
));
dip
->
type
=
type
;
bwrite
(
bp
);
// mark it allocated on the disk
brelse
(
bp
);
return
iget
(
dev
,
inum
);
}
brelse
(
bp
);
}
panic
(
"ialloc: no inodes"
);
}
// Copy inode, which has changed, from memory to disk.
void
iupdate
(
struct
inode
*
ip
)
{
struct
buf
*
bp
;
struct
dinode
*
dip
;
bp
=
bread
(
ip
->
dev
,
IBLOCK
(
ip
->
inum
));
dip
=
(
struct
dinode
*
)
bp
->
data
+
ip
->
inum
%
IPB
;
dip
->
type
=
ip
->
type
;
dip
->
major
=
ip
->
major
;
dip
->
minor
=
ip
->
minor
;
dip
->
nlink
=
ip
->
nlink
;
dip
->
size
=
ip
->
size
;
memmove
(
dip
->
addrs
,
ip
->
addrs
,
sizeof
(
ip
->
addrs
));
bwrite
(
bp
);
brelse
(
bp
);
}
//PAGEBREAK!
// Inode contents
// Inode contents
//
//
// The contents (data) associated with each inode is stored
// The contents (data) associated with each inode is stored
...
@@ -336,7 +338,6 @@ bmap(struct inode *ip, uint bn)
...
@@ -336,7 +338,6 @@ bmap(struct inode *ip, uint bn)
ip
->
addrs
[
NDIRECT
]
=
addr
=
balloc
(
ip
->
dev
);
ip
->
addrs
[
NDIRECT
]
=
addr
=
balloc
(
ip
->
dev
);
bp
=
bread
(
ip
->
dev
,
addr
);
bp
=
bread
(
ip
->
dev
,
addr
);
a
=
(
uint
*
)
bp
->
data
;
a
=
(
uint
*
)
bp
->
data
;
if
((
addr
=
a
[
bn
])
==
0
){
if
((
addr
=
a
[
bn
])
==
0
){
a
[
bn
]
=
addr
=
balloc
(
ip
->
dev
);
a
[
bn
]
=
addr
=
balloc
(
ip
->
dev
);
bwrite
(
bp
);
bwrite
(
bp
);
...
@@ -571,7 +572,7 @@ skipelem(char *path, char *name)
...
@@ -571,7 +572,7 @@ skipelem(char *path, char *name)
// If parent != 0, return the inode for the parent and copy the final
// If parent != 0, return the inode for the parent and copy the final
// path element into name, which must have room for DIRSIZ bytes.
// path element into name, which must have room for DIRSIZ bytes.
static
struct
inode
*
static
struct
inode
*
namex
(
char
*
path
,
int
parent
,
char
*
name
)
namex
(
char
*
path
,
int
namei
parent
,
char
*
name
)
{
{
struct
inode
*
ip
,
*
next
;
struct
inode
*
ip
,
*
next
;
...
@@ -586,7 +587,7 @@ namex(char *path, int parent, char *name)
...
@@ -586,7 +587,7 @@ namex(char *path, int parent, char *name)
iunlockput
(
ip
);
iunlockput
(
ip
);
return
0
;
return
0
;
}
}
if
(
parent
&&
*
path
==
'\0'
){
if
(
namei
parent
&&
*
path
==
'\0'
){
// Stop one level early.
// Stop one level early.
iunlock
(
ip
);
iunlock
(
ip
);
return
ip
;
return
ip
;
...
@@ -598,7 +599,7 @@ namex(char *path, int parent, char *name)
...
@@ -598,7 +599,7 @@ namex(char *path, int parent, char *name)
iunlockput
(
ip
);
iunlockput
(
ip
);
ip
=
next
;
ip
=
next
;
}
}
if
(
parent
){
if
(
namei
parent
){
iput
(
ip
);
iput
(
ip
);
return
0
;
return
0
;
}
}
...
...
initcode.S
浏览文件 @
f9a06440
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
start:
start:
pushl $argv
pushl $argv
pushl $init
pushl $init
pushl $0
pushl $0
// where caller pc would be
movl $SYS_exec, %eax
movl $SYS_exec, %eax
int $T_SYSCALL
int $T_SYSCALL
...
...
kalloc.c
浏览文件 @
f9a06440
...
@@ -22,21 +22,20 @@ struct {
...
@@ -22,21 +22,20 @@ struct {
// Initialize free list of physical pages.
// Initialize free list of physical pages.
// This code cheats by just considering one megabyte of
// This code cheats by just considering one megabyte of
// pages after
_
end. Real systems would determine the
// pages after end. Real systems would determine the
// amount of memory available in the system and use it all.
// amount of memory available in the system and use it all.
void
void
kinit
(
void
)
kinit
(
void
)
{
{
extern
int
end
;
extern
char
end
[]
;
uint
mem
;
uint
len
;
char
*
start
;
char
*
p
;
initlock
(
&
kmem
.
lock
,
"kmem"
);
initlock
(
&
kmem
.
lock
,
"kmem"
);
start
=
(
char
*
)
&
end
;
p
=
(
char
*
)(((
uint
)
end
+
PAGE
)
&
~
(
PAGE
-
1
));
start
=
(
char
*
)
(((
uint
)
start
+
PAGE
)
&
~
(
PAGE
-
1
));
len
=
256
*
PAGE
;
// assume computer has 256 pages of RAM, 1 MB
mem
=
256
;
// assume computer has 256 pages of RAM
cprintf
(
"mem = %d
\n
"
,
len
);
cprintf
(
"mem = %d
\n
"
,
mem
*
PAGE
);
kfree
(
p
,
len
);
kfree
(
start
,
mem
*
PAGE
);
}
}
// Free the len bytes of memory pointed at by v,
// Free the len bytes of memory pointed at by v,
...
@@ -61,13 +60,7 @@ kfree(char *v, int len)
...
@@ -61,13 +60,7 @@ kfree(char *v, int len)
rend
=
(
struct
run
*
)((
char
*
)
r
+
r
->
len
);
rend
=
(
struct
run
*
)((
char
*
)
r
+
r
->
len
);
if
(
r
<=
p
&&
p
<
rend
)
if
(
r
<=
p
&&
p
<
rend
)
panic
(
"freeing free page"
);
panic
(
"freeing free page"
);
if
(
pend
==
r
){
// p next to r: replace r with p
if
(
rend
==
p
){
// r before p: expand r to include p
p
->
len
=
len
+
r
->
len
;
p
->
next
=
r
->
next
;
*
rp
=
p
;
goto
out
;
}
if
(
rend
==
p
){
// r next to p: replace p with r
r
->
len
+=
len
;
r
->
len
+=
len
;
if
(
r
->
next
&&
r
->
next
==
pend
){
// r now next to r->next?
if
(
r
->
next
&&
r
->
next
==
pend
){
// r now next to r->next?
r
->
len
+=
r
->
next
->
len
;
r
->
len
+=
r
->
next
->
len
;
...
@@ -75,6 +68,12 @@ kfree(char *v, int len)
...
@@ -75,6 +68,12 @@ kfree(char *v, int len)
}
}
goto
out
;
goto
out
;
}
}
if
(
pend
==
r
){
// p before r: expand p to include, replace r
p
->
len
=
len
+
r
->
len
;
p
->
next
=
r
->
next
;
*
rp
=
p
;
goto
out
;
}
}
}
// Insert p before r in list.
// Insert p before r in list.
p
->
len
=
len
;
p
->
len
=
len
;
...
@@ -99,14 +98,11 @@ kalloc(int n)
...
@@ -99,14 +98,11 @@ kalloc(int n)
acquire
(
&
kmem
.
lock
);
acquire
(
&
kmem
.
lock
);
for
(
rp
=&
kmem
.
freelist
;
(
r
=*
rp
)
!=
0
;
rp
=&
r
->
next
){
for
(
rp
=&
kmem
.
freelist
;
(
r
=*
rp
)
!=
0
;
rp
=&
r
->
next
){
if
(
r
->
len
==
n
){
if
(
r
->
len
>=
n
){
*
rp
=
r
->
next
;
release
(
&
kmem
.
lock
);
return
(
char
*
)
r
;
}
if
(
r
->
len
>
n
){
r
->
len
-=
n
;
r
->
len
-=
n
;
p
=
(
char
*
)
r
+
r
->
len
;
p
=
(
char
*
)
r
+
r
->
len
;
if
(
r
->
len
==
0
)
*
rp
=
r
->
next
;
release
(
&
kmem
.
lock
);
release
(
&
kmem
.
lock
);
return
p
;
return
p
;
}
}
...
...
sysfile.c
浏览文件 @
f9a06440
...
@@ -45,6 +45,20 @@ fdalloc(struct file *f)
...
@@ -45,6 +45,20 @@ fdalloc(struct file *f)
}
}
int
int
sys_dup
(
void
)
{
struct
file
*
f
;
int
fd
;
if
(
argfd
(
0
,
0
,
&
f
)
<
0
)
return
-
1
;
if
((
fd
=
fdalloc
(
f
))
<
0
)
return
-
1
;
filedup
(
f
);
return
fd
;
}
int
sys_read
(
void
)
sys_read
(
void
)
{
{
struct
file
*
f
;
struct
file
*
f
;
...
@@ -69,20 +83,6 @@ sys_write(void)
...
@@ -69,20 +83,6 @@ sys_write(void)
}
}
int
int
sys_dup
(
void
)
{
struct
file
*
f
;
int
fd
;
if
(
argfd
(
0
,
0
,
&
f
)
<
0
)
return
-
1
;
if
((
fd
=
fdalloc
(
f
))
<
0
)
return
-
1
;
filedup
(
f
);
return
fd
;
}
int
sys_close
(
void
)
sys_close
(
void
)
{
{
int
fd
;
int
fd
;
...
@@ -225,17 +225,15 @@ create(char *path, short type, short major, short minor)
...
@@ -225,17 +225,15 @@ create(char *path, short type, short major, short minor)
if
((
ip
=
dirlookup
(
dp
,
name
,
&
off
))
!=
0
){
if
((
ip
=
dirlookup
(
dp
,
name
,
&
off
))
!=
0
){
iunlockput
(
dp
);
iunlockput
(
dp
);
ilock
(
ip
);
ilock
(
ip
);
if
(
ip
->
type
!=
type
||
type
!=
T_FILE
){
if
(
type
==
T_FILE
&&
ip
->
type
==
T_FILE
)
iunlockput
(
ip
);
return
ip
;
return
0
;
iunlockput
(
ip
);
}
return
ip
;
}
if
((
ip
=
ialloc
(
dp
->
dev
,
type
))
==
0
){
iunlockput
(
dp
);
return
0
;
return
0
;
}
}
if
((
ip
=
ialloc
(
dp
->
dev
,
type
))
==
0
)
panic
(
"create: ialloc"
);
ilock
(
ip
);
ilock
(
ip
);
ip
->
major
=
major
;
ip
->
major
=
major
;
ip
->
minor
=
minor
;
ip
->
minor
=
minor
;
...
@@ -299,6 +297,18 @@ sys_open(void)
...
@@ -299,6 +297,18 @@ sys_open(void)
}
}
int
int
sys_mkdir
(
void
)
{
char
*
path
;
struct
inode
*
ip
;
if
(
argstr
(
0
,
&
path
)
<
0
||
(
ip
=
create
(
path
,
T_DIR
,
0
,
0
))
==
0
)
return
-
1
;
iunlockput
(
ip
);
return
0
;
}
int
sys_mknod
(
void
)
sys_mknod
(
void
)
{
{
struct
inode
*
ip
;
struct
inode
*
ip
;
...
@@ -316,18 +326,6 @@ sys_mknod(void)
...
@@ -316,18 +326,6 @@ sys_mknod(void)
}
}
int
int
sys_mkdir
(
void
)
{
char
*
path
;
struct
inode
*
ip
;
if
(
argstr
(
0
,
&
path
)
<
0
||
(
ip
=
create
(
path
,
T_DIR
,
0
,
0
))
==
0
)
return
-
1
;
iunlockput
(
ip
);
return
0
;
}
int
sys_chdir
(
void
)
sys_chdir
(
void
)
{
{
char
*
path
;
char
*
path
;
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论