Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
13ae8808
提交
13ae8808
5月 31, 2009
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tidy fs.c; bmap callers always expected allocation
上级
f12551b5
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
15 行增加
和
24 行删除
+15
-24
fs.c
fs.c
+15
-24
没有找到文件。
fs.c
浏览文件 @
13ae8808
...
...
@@ -316,38 +316,28 @@ iupdate(struct inode *ip)
// listed in the block ip->addrs[INDIRECT].
// Return the disk block address of the nth block in inode ip.
// If there is no such block,
alloc controls whether one is allocated
.
// If there is no such block,
bmap allocates one
.
static
uint
bmap
(
struct
inode
*
ip
,
uint
bn
,
int
alloc
)
bmap
(
struct
inode
*
ip
,
uint
bn
)
{
uint
addr
,
*
a
;
struct
buf
*
bp
;
if
(
bn
<
NDIRECT
){
if
((
addr
=
ip
->
addrs
[
bn
])
==
0
){
if
(
!
alloc
)
return
-
1
;
if
((
addr
=
ip
->
addrs
[
bn
])
==
0
)
ip
->
addrs
[
bn
]
=
addr
=
balloc
(
ip
->
dev
);
}
return
addr
;
}
bn
-=
NDIRECT
;
if
(
bn
<
NINDIRECT
){
// Load indirect block, allocating if necessary.
if
((
addr
=
ip
->
addrs
[
NDIRECT
])
==
0
){
if
(
!
alloc
)
return
-
1
;
if
((
addr
=
ip
->
addrs
[
NDIRECT
])
==
0
)
ip
->
addrs
[
NDIRECT
]
=
addr
=
balloc
(
ip
->
dev
);
}
bp
=
bread
(
ip
->
dev
,
addr
);
a
=
(
uint
*
)
bp
->
data
;
if
((
addr
=
a
[
bn
])
==
0
){
if
(
!
alloc
){
brelse
(
bp
);
return
-
1
;
}
a
[
bn
]
=
addr
=
balloc
(
ip
->
dev
);
bwrite
(
bp
);
}
...
...
@@ -422,7 +412,7 @@ readi(struct inode *ip, char *dst, uint off, uint n)
n
=
ip
->
size
-
off
;
for
(
tot
=
0
;
tot
<
n
;
tot
+=
m
,
off
+=
m
,
dst
+=
m
){
bp
=
bread
(
ip
->
dev
,
bmap
(
ip
,
off
/
BSIZE
,
0
));
bp
=
bread
(
ip
->
dev
,
bmap
(
ip
,
off
/
BSIZE
));
m
=
min
(
n
-
tot
,
BSIZE
-
off
%
BSIZE
);
memmove
(
dst
,
bp
->
data
+
off
%
BSIZE
,
m
);
brelse
(
bp
);
...
...
@@ -444,13 +434,13 @@ writei(struct inode *ip, char *src, uint off, uint n)
return
devsw
[
ip
->
major
].
write
(
ip
,
src
,
n
);
}
if
(
off
+
n
<
off
)
if
(
off
>
ip
->
size
||
off
+
n
<
off
)
return
-
1
;
if
(
off
+
n
>
MAXFILE
*
BSIZE
)
n
=
MAXFILE
*
BSIZE
-
off
;
for
(
tot
=
0
;
tot
<
n
;
tot
+=
m
,
off
+=
m
,
src
+=
m
){
bp
=
bread
(
ip
->
dev
,
bmap
(
ip
,
off
/
BSIZE
,
1
));
bp
=
bread
(
ip
->
dev
,
bmap
(
ip
,
off
/
BSIZE
));
m
=
min
(
n
-
tot
,
BSIZE
-
off
%
BSIZE
);
memmove
(
bp
->
data
+
off
%
BSIZE
,
src
,
m
);
bwrite
(
bp
);
...
...
@@ -487,7 +477,7 @@ dirlookup(struct inode *dp, char *name, uint *poff)
panic
(
"dirlookup not DIR"
);
for
(
off
=
0
;
off
<
dp
->
size
;
off
+=
BSIZE
){
bp
=
bread
(
dp
->
dev
,
bmap
(
dp
,
off
/
BSIZE
,
0
));
bp
=
bread
(
dp
->
dev
,
bmap
(
dp
,
off
/
BSIZE
));
for
(
de
=
(
struct
dirent
*
)
bp
->
data
;
de
<
(
struct
dirent
*
)(
bp
->
data
+
BSIZE
);
de
++
){
...
...
@@ -507,9 +497,9 @@ dirlookup(struct inode *dp, char *name, uint *poff)
return
0
;
}
// Write a new directory entry (name, in
o
) into the directory dp.
// Write a new directory entry (name, in
um
) into the directory dp.
int
dirlink
(
struct
inode
*
dp
,
char
*
name
,
uint
in
o
)
dirlink
(
struct
inode
*
dp
,
char
*
name
,
uint
in
um
)
{
int
off
;
struct
dirent
de
;
...
...
@@ -530,7 +520,7 @@ dirlink(struct inode *dp, char *name, uint ino)
}
strncpy
(
de
.
name
,
name
,
DIRSIZ
);
de
.
inum
=
in
o
;
de
.
inum
=
in
um
;
if
(
writei
(
dp
,
(
char
*
)
&
de
,
off
,
sizeof
(
de
))
!=
sizeof
(
de
))
panic
(
"dirlink"
);
...
...
@@ -549,6 +539,7 @@ dirlink(struct inode *dp, char *name, uint ino)
// Examples:
// skipelem("a/bb/c", name) = "bb/c", setting name = "a"
// skipelem("///a//bb", name) = "bb", setting name = "a"
// skipelem("a", name) = "", setting name = "a"
// skipelem("", name) = skipelem("////", name) = 0
//
static
char
*
...
...
@@ -580,7 +571,7 @@ skipelem(char *path, 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
*
_namei
(
char
*
path
,
int
parent
,
char
*
name
)
namex
(
char
*
path
,
int
parent
,
char
*
name
)
{
struct
inode
*
ip
,
*
next
;
...
...
@@ -618,11 +609,11 @@ struct inode*
namei
(
char
*
path
)
{
char
name
[
DIRSIZ
];
return
_namei
(
path
,
0
,
name
);
return
namex
(
path
,
0
,
name
);
}
struct
inode
*
nameiparent
(
char
*
path
,
char
*
name
)
{
return
_namei
(
path
,
1
,
name
);
return
namex
(
path
,
1
,
name
);
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论