Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
c3e73232
提交
c3e73232
10月 25, 2011
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
64-bitify file.c and friends -- make block units u32.
上级
4ddb84ac
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
84 行增加
和
98 行删除
+84
-98
file.c
file.c
+0
-5
file.h
file.h
+8
-8
fs.c
fs.c
+40
-55
fs.h
fs.h
+8
-14
kernel.h
kernel.h
+5
-0
main.c
main.c
+11
-6
memide.c
memide.c
+10
-8
stat.h
stat.h
+2
-2
没有找到文件。
file.c
浏览文件 @
c3e73232
...
...
@@ -9,11 +9,6 @@
struct
devsw
__attribute__
((
aligned
(
CACHELINE
)))
devsw
[
NDEV
];
void
fileinit
(
void
)
{
}
// Allocate a file structure.
struct
file
*
filealloc
(
void
)
...
...
file.h
浏览文件 @
c3e73232
...
...
@@ -5,18 +5,18 @@ struct file {
char
writable
;
struct
pipe
*
pipe
;
struct
inode
*
ip
;
u
int
off
;
u
32
off
;
};
// in-core file system types
struct
inode
{
u
int
dev
;
// Device number
u
int
inum
;
// Inode number
u
int
gen
;
// Generation number
int
ref
;
// Reference count
int
flags
;
// I_BUSY, I_VALID
u
32
dev
;
// Device number
u
32
inum
;
// Inode number
u
32
gen
;
// Generation number
int
ref
;
// Reference count
int
flags
;
// I_BUSY, I_VALID
int
readbusy
;
struct
condvar
cv
;
struct
spinlock
lock
;
...
...
@@ -27,8 +27,8 @@ struct inode {
short
major
;
short
minor
;
short
nlink
;
u
int
size
;
u
int
addrs
[
NDIRECT
+
1
];
u
32
size
;
u
32
addrs
[
NDIRECT
+
1
];
};
#define I_BUSYR 0x1
...
...
fs.c
浏览文件 @
c3e73232
#include "types.h"
#include "kernel.h"
#include "fs.h"
int
namecmp
(
const
char
*
s
,
const
char
*
t
)
{
return
strncmp
(
s
,
t
,
DIRSIZ
);
}
struct
inode
*
namei
(
char
*
path
)
{
panic
(
"namei"
);
return
NULL
;
}
void
iput
(
struct
inode
*
ip
)
{
panic
(
"iput"
);
}
#if 0
// File system implementation. Four layers:
// + Blocks: allocator for raw disk blocks.
// + Files: inode allocator, reading, writing, metadata.
...
...
@@ -35,10 +11,10 @@ iput(struct inode *ip)
// are in sysfile.c.
#include "types.h"
#include "defs.h"
#include "param.h"
#include "stat.h"
#include "mmu.h"
#include "kernel.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
...
...
@@ -46,6 +22,7 @@ iput(struct inode *ip)
#include "buf.h"
#include "fs.h"
#include "file.h"
#include "cpu.h"
#define min(a, b) ((a) < (b) ? (a) : (b))
static
void
itrunc
(
struct
inode
*
);
...
...
@@ -76,8 +53,8 @@ bzero(int dev, int bno)
// Blocks.
// Allocate a disk block.
static u
int
balloc(u
int
dev)
static
u
32
balloc
(
u
32
dev
)
{
int
b
,
bi
,
m
;
struct
buf
*
bp
;
...
...
@@ -103,11 +80,12 @@ balloc(uint dev)
// Free a disk block.
static
void
bfree(int dev, u
int b
)
bfree
(
int
dev
,
u
64
x
)
{
struct
buf
*
bp
;
struct
superblock
sb
;
int
bi
,
m
;
u32
b
=
x
;
bzero
(
dev
,
b
);
...
...
@@ -157,10 +135,10 @@ bfree(int dev, uint b)
static
struct
ns
*
ins
;
static struct { u
int x __attribute__((aligned (CACHELINE)))
; } icache_free[NCPU];
static
struct
{
u
32
x
__mpalign__
;
}
icache_free
[
NCPU
];
void
i
init
(void)
i
nitinode
(
void
)
{
ins
=
nsalloc
(
0
);
for
(
int
i
=
0
;
i
<
NCPU
;
i
++
)
...
...
@@ -171,7 +149,7 @@ iinit(void)
// Allocate a new inode with the given type on device dev.
// Returns a locked inode.
struct
inode
*
ialloc(u
int
dev, short type)
ialloc
(
u
32
dev
,
short
type
)
{
int
inum
;
struct
buf
*
bp
;
...
...
@@ -261,7 +239,7 @@ ifree(void *arg)
}
struct
inode
*
iget(u
int dev, uint
inum)
iget
(
u
32
dev
,
u32
inum
)
{
struct
inode
*
ip
;
...
...
@@ -291,7 +269,7 @@ iget(uint dev, uint inum)
// Allocate fresh inode cache slot.
retry_evict:
(
void
)
0
;
u
int cur_free = icache_free[cpu
->id].x;
u
32
cur_free
=
icache_free
[
mycpu
()
->
id
].
x
;
if
(
cur_free
==
0
)
{
struct
inode
*
victim
=
ns_enumerate
(
ins
,
evict
,
0
);
if
(
!
victim
)
...
...
@@ -307,7 +285,7 @@ iget(uint dev, uint inum)
ns_remove
(
ins
,
KII
(
victim
->
dev
,
victim
->
inum
),
victim
);
rcu_delayed
(
victim
,
ifree
);
}
else
{
if (!__sync_bool_compare_and_swap(&icache_free[
cpu
->id].x, cur_free, cur_free-1))
if
(
!
__sync_bool_compare_and_swap
(
&
icache_free
[
mycpu
()
->
id
].
x
,
cur_free
,
cur_free
-
1
))
goto
retry_evict
;
}
...
...
@@ -429,7 +407,7 @@ iput(struct inode *ip)
ns_remove
(
ins
,
KII
(
ip
->
dev
,
ip
->
inum
),
ip
);
rcu_delayed
(
ip
,
ifree
);
__sync_fetch_and_add(&icache_free[
cpu
->id].x, 1);
__sync_fetch_and_add
(
&
icache_free
[
mycpu
()
->
id
].
x
,
1
);
return
;
}
release
(
&
ip
->
lock
);
...
...
@@ -454,10 +432,10 @@ iunlockput(struct inode *ip)
// Return the disk block address of the nth block in inode ip.
// If there is no such block, bmap allocates one.
static u
int
bmap(struct inode *ip, u
int
bn)
static
u
32
bmap
(
struct
inode
*
ip
,
u
32
bn
)
{
u
int
addr, *a;
u
32
addr
,
*
a
;
struct
buf
*
bp
;
if
(
bn
<
NDIRECT
){
...
...
@@ -472,7 +450,7 @@ bmap(struct inode *ip, uint bn)
if
((
addr
=
ip
->
addrs
[
NDIRECT
])
==
0
)
ip
->
addrs
[
NDIRECT
]
=
addr
=
balloc
(
ip
->
dev
);
bp
=
bread
(
ip
->
dev
,
addr
,
1
);
a = (u
int
*)bp->data;
a
=
(
u
32
*
)
bp
->
data
;
if
((
addr
=
a
[
bn
])
==
0
){
a
[
bn
]
=
addr
=
balloc
(
ip
->
dev
);
bwrite
(
bp
);
...
...
@@ -492,7 +470,7 @@ itrunc(struct inode *ip)
{
int
i
,
j
;
struct
buf
*
bp
;
u
int
*a;
u
32
*
a
;
for
(
i
=
0
;
i
<
NDIRECT
;
i
++
){
if
(
ip
->
addrs
[
i
]){
...
...
@@ -503,7 +481,7 @@ itrunc(struct inode *ip)
if
(
ip
->
addrs
[
NDIRECT
]){
bp
=
bread
(
ip
->
dev
,
ip
->
addrs
[
NDIRECT
],
0
);
a = (u
int
*)bp->data;
a
=
(
u
32
*
)
bp
->
data
;
for
(
j
=
0
;
j
<
NINDIRECT
;
j
++
){
if
(
a
[
j
])
rcu_delayed2
(
ip
->
dev
,
a
[
j
],
bfree
);
...
...
@@ -531,15 +509,19 @@ stati(struct inode *ip, struct stat *st)
//PAGEBREAK!
// Read data from inode.
int
readi(struct inode *ip, char *dst, u
int off, uint
n)
readi
(
struct
inode
*
ip
,
char
*
dst
,
u
32
off
,
u32
n
)
{
u
int
tot, m;
u
32
tot
,
m
;
struct
buf
*
bp
;
if
(
ip
->
type
==
T_DEV
){
// XXX(sbw)
panic
(
"readi T_DEV"
);
#if 0
if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].read)
return -1;
return devsw[ip->major].read(ip, dst, n);
#endif
}
if
(
off
>
ip
->
size
||
off
+
n
<
off
)
...
...
@@ -559,15 +541,19 @@ readi(struct inode *ip, char *dst, uint off, uint n)
// PAGEBREAK!
// Write data to inode.
int
writei(struct inode *ip, char *src, u
int off, uint
n)
writei
(
struct
inode
*
ip
,
char
*
src
,
u
32
off
,
u32
n
)
{
u
int
tot, m;
u
32
tot
,
m
;
struct
buf
*
bp
;
if
(
ip
->
type
==
T_DEV
){
// XXX(sbw)
panic
(
"writei T_DEV"
);
#if 0
if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].write)
return -1;
return devsw[ip->major].write(ip, src, n);
#endif
}
if
(
off
>
ip
->
size
||
off
+
n
<
off
)
...
...
@@ -608,7 +594,7 @@ dir_init(struct inode *dp)
panic
(
"dir_init not DIR"
);
struct
ns
*
dir
=
nsalloc
(
0
);
for (u
int
off = 0; off < dp->size; off += BSIZE) {
for
(
u
32
off
=
0
;
off
<
dp
->
size
;
off
+=
BSIZE
)
{
struct
buf
*
bp
=
bread
(
dp
->
dev
,
bmap
(
dp
,
off
/
BSIZE
),
0
);
for
(
struct
dirent
*
de
=
(
struct
dirent
*
)
bp
->
data
;
de
<
(
struct
dirent
*
)
(
bp
->
data
+
BSIZE
);
...
...
@@ -616,7 +602,7 @@ dir_init(struct inode *dp)
if
(
de
->
inum
==
0
)
continue
;
ns_insert(dir, KD(de->name), (void*) (u
int
) de->inum);
ns_insert
(
dir
,
KD
(
de
->
name
),
(
void
*
)
(
u
64
)
de
->
inum
);
}
brelse
(
bp
,
0
);
}
...
...
@@ -628,7 +614,7 @@ dir_init(struct inode *dp)
struct
flush_state
{
struct
inode
*
dp
;
u
int
off;
u
32
off
;
};
static
void
*
...
...
@@ -636,7 +622,7 @@ dir_flush_cb(void *key, void *val, void *arg)
{
struct
flush_state
*
fs
=
arg
;
char
*
name
=
key
;
u
int inum = (uint
) val;
u
32
inum
=
(
u64
)
val
;
struct
dirent
de
;
strncpy
(
de
.
name
,
name
,
DIRSIZ
);
...
...
@@ -668,7 +654,7 @@ dirlookup(struct inode *dp, char *name)
dir_init
(
dp
);
void
*
vinum
=
ns_lookup
(
dp
->
dir
,
KD
(
name
));
u
int inum = (uint
) vinum;
u
32
inum
=
(
u64
)
vinum
;
//cprintf("dirlookup: %x (%d): %s -> %d\n", dp, dp->inum, name, inum);
if
(
inum
==
0
)
...
...
@@ -679,15 +665,14 @@ dirlookup(struct inode *dp, char *name)
// Write a new directory entry (name, inum) into the directory dp.
int
dirlink(struct inode *dp, char *name, u
int
inum)
dirlink
(
struct
inode
*
dp
,
char
*
name
,
u
32
inum
)
{
dir_init
(
dp
);
//cprintf("dirlink: %x (%d): %s -> %d\n", dp, dp->inum, name, inum);
return ns_insert(dp->dir, KD(name), (void*)inum);
return
ns_insert
(
dp
->
dir
,
KD
(
name
),
(
void
*
)
(
u64
)
inum
);
}
//PAGEBREAK!
// Paths
// Copy the next path element from path into name.
...
...
@@ -739,7 +724,7 @@ namex(char *path, int nameiparent, char *name)
if
(
*
path
==
'/'
)
ip
=
iget
(
ROOTDEV
,
ROOTINO
);
else
ip = idup(
proc
->cwd);
ip
=
idup
(
myproc
()
->
cwd
);
while
((
path
=
skipelem
(
path
,
name
))
!=
0
){
next
=
0
;
...
...
@@ -788,4 +773,4 @@ nameiparent(char *path, char *name)
{
return
namex
(
path
,
1
,
name
);
}
#endif
fs.h
浏览文件 @
c3e73232
// Directory is a file containing a sequence of dirent structures.
#define DIRSIZ 14
#if 0
// On-disk file system format.
// Both the kernel and user programs use this header file.
...
...
@@ -14,13 +10,13 @@
// File system super block
struct
superblock
{
u
int
size; // Size of file system image (blocks)
u
int
nblocks; // Number of data blocks
u
int
ninodes; // Number of inodes.
u
32
size
;
// Size of file system image (blocks)
u
32
nblocks
;
// Number of data blocks
u
32
ninodes
;
// Number of inodes.
};
#define NDIRECT 11
#define NINDIRECT (BSIZE / sizeof(u
int
))
#define NINDIRECT (BSIZE / sizeof(u
32
))
#define MAXFILE (NDIRECT + NINDIRECT)
// On-disk inode structure
...
...
@@ -30,9 +26,9 @@ struct dinode {
short
major
;
// Major device number (T_DEV only)
short
minor
;
// Minor device number (T_DEV only)
short
nlink
;
// Number of links to inode in file system
u
int size;
// Size of file (bytes)
u
int gen;
// Generation # (to check name cache)
u
int addrs[NDIRECT+1];
// Data block addresses
u
32
size
;
// Size of file (bytes)
u
32
gen
;
// Generation # (to check name cache)
u
32
addrs
[
NDIRECT
+
1
];
// Data block addresses
};
// Inodes per block.
...
...
@@ -51,8 +47,6 @@ struct dinode {
#define DIRSIZ 14
struct
dirent
{
u
short
inum;
u
16
inum
;
char
name
[
DIRSIZ
];
};
#endif
kernel.h
浏览文件 @
c3e73232
...
...
@@ -44,6 +44,11 @@ void snprintf(char *buf, u32 n, char *fmt, ...);
int
namecmp
(
const
char
*
,
const
char
*
);
struct
inode
*
namei
(
char
*
);
void
iput
(
struct
inode
*
);
struct
inode
*
iget
(
u32
dev
,
u32
inum
);
void
ilock
(
struct
inode
*
,
int
writer
);
void
iunlockput
(
struct
inode
*
);
void
iupdate
(
struct
inode
*
);
void
iunlock
(
struct
inode
*
);
// ide.c
void
ideinit
(
void
);
...
...
main.c
浏览文件 @
c3e73232
...
...
@@ -17,6 +17,8 @@ extern void initkalloc(void);
extern
void
initrcu
(
void
);
extern
void
initproc
(
void
);
extern
void
initbio
(
void
);
extern
void
initinode
(
void
);
extern
void
initdisk
(
void
);
extern
void
inituser
(
void
);
static
volatile
int
bstate
;
...
...
@@ -30,9 +32,14 @@ mpboot(void)
initseg
();
initlapic
();
inittls
();
// XXX
// XXX
// XXX
scheduler
();
// start running processes
#if 0
bstate = 1;
panic
(
"mpboot"
);
scheduler(); // start running processes
#endif
}
// Start the non-boot processors.
...
...
@@ -87,12 +94,10 @@ cmain(void)
initrcu
();
// initialize rcu module
initproc
();
// process table
initbio
();
// buffer cache
initinode
();
// inode cache
initdisk
();
// disk
#if 0
fileinit(); // file table
iinit(); // inode cache
ideinit(); // disk
#endif
cprintf
(
"booting others..
\n
"
);
inituser
();
// first user process
bootothers
();
// start other processors
...
...
memide.c
浏览文件 @
c3e73232
...
...
@@ -2,25 +2,27 @@
// Useful for running kernel without scratch disk.
#include "types.h"
#include "defs.h"
#include "param.h"
#include "mmu.h"
#include "kernel.h"
#include "spinlock.h"
#include "queue.h"
#include "condvar.h"
#include "proc.h"
#include "x86.h"
#include "traps.h"
#include "spinlock.h"
#include "buf.h"
extern
u
char
_binary_fs_img_start
[],
_binary_fs_img_size
[];
extern
u
8
_binary_fs_img_start
[],
_binary_fs_img_size
[];
static
int
disksize
;
static
u
char
*
memdisk
;
static
u64
disksize
;
static
u
8
*
memdisk
;
void
i
deinit
(
void
)
i
nitdisk
(
void
)
{
memdisk
=
_binary_fs_img_start
;
disksize
=
(
u
int
)
_binary_fs_img_size
/
512
;
disksize
=
(
u
64
)
_binary_fs_img_size
/
512
;
}
// Interrupt handler.
...
...
@@ -36,7 +38,7 @@ ideintr(void)
void
iderw
(
struct
buf
*
b
)
{
u
char
*
p
;
u
8
*
p
;
if
(
!
(
b
->
flags
&
B_BUSY
))
panic
(
"iderw: buf not busy"
);
...
...
stat.h
浏览文件 @
c3e73232
...
...
@@ -5,7 +5,7 @@
struct
stat
{
short
type
;
// Type of file
int
dev
;
// Device number
u
int
ino
;
// Inode number on device
u
32
ino
;
// Inode number on device
short
nlink
;
// Number of links to file
u
int
size
;
// Size of file in bytes
u
32
size
;
// Size of file in bytes
};
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论