提交 4ddb84ac 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

memide.c and mkfs.c

上级 f568fbd8
......@@ -5,10 +5,10 @@ OBJS = \
condvar.o \
console.o \
fs.o \
ide.o \
lapic.o \
kalloc.o \
main.o \
memide.o \
mp.o \
ns.o \
proc.o \
......@@ -40,9 +40,9 @@ CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 &
ASFLAGS = -m64 -gdwarf-2
LDFLAGS += -m elf_x86_64
kernel: boot.o $(OBJS) initcode bootother
kernel: boot.o $(OBJS) initcode bootother fs.img
$(LD) $(LDFLAGS) -T kernel.ld -z max-page-size=4096 -e start \
-o $@ boot.o $(OBJS) -b binary initcode bootother
-o $@ boot.o $(OBJS) -b binary initcode bootother fs.img
initcode: initcode.S
$(CC) $(CFLAGS) -nostdinc -I. -c initcode.S
......@@ -61,12 +61,18 @@ xv6memfs.img: bootblock kernelmemfs
dd if=bootblock of=xv6memfs.img conv=notrunc
dd if=kernelmemfs of=xv6memfs.img seek=1 conv=notrunc
mkfs: mkfs.c fs.h
gcc -m32 -Werror -Wall -o mkfs mkfs.c
fs.img: mkfs README $(UPROGS)
./mkfs fs.img README $(UPROGS)
-include *.d
.PHONY: clean qemu ud0
clean:
rm -f *.o *.d *.asm *.sym initcode kernel bootother
rm -f *.o *.d *.asm *.sym initcode kernel bootother mkfs fs.img
QEMUOPTS = -smp $(CPUS) -m 512 -nographic
qemu: kernel
......
......@@ -17,35 +17,35 @@ int size = 4096;
int fsfd;
struct superblock sb;
char zeroes[512];
uint freeblock;
uint usedblocks;
uint bitblocks;
uint freeinode = 1;
u32 freeblock;
u32 usedblocks;
u32 bitblocks;
u32 freeinode = 1;
void balloc(int);
void wsect(uint, void*);
void winode(uint, struct dinode*);
void rinode(uint inum, struct dinode *ip);
void rsect(uint sec, void *buf);
uint ialloc(ushort type);
void iappend(uint inum, void *p, int n);
void wsect(u32, void*);
void winode(u32, struct dinode*);
void rinode(u32 inum, struct dinode *ip);
void rsect(u32 sec, void *buf);
u32 ialloc(u16 type);
void iappend(u32 inum, void *p, int n);
// convert to intel byte order
ushort
xshort(ushort x)
u16
xshort(u16 x)
{
ushort y;
uchar *a = (uchar*)&y;
u16 y;
u8 *a = (u8*)&y;
a[0] = x;
a[1] = x >> 8;
return y;
}
uint
xint(uint x)
u32
xint(u32 x)
{
uint y;
uchar *a = (uchar*)&y;
u32 y;
u8 *a = (u8*)&y;
a[0] = x;
a[1] = x >> 8;
a[2] = x >> 16;
......@@ -57,7 +57,7 @@ int
main(int argc, char *argv[])
{
int i, cc, fd;
uint rootino, inum, off;
u32 rootino, inum, off;
struct dirent de;
char buf[512];
struct dinode din;
......@@ -150,7 +150,7 @@ main(int argc, char *argv[])
}
void
wsect(uint sec, void *buf)
wsect(u32 sec, void *buf)
{
if(lseek(fsfd, sec * 512L, 0) != sec * 512L){
perror("lseek");
......@@ -162,17 +162,17 @@ wsect(uint sec, void *buf)
}
}
uint
i2b(uint inum)
u32
i2b(u32 inum)
{
return (inum / IPB) + 2;
}
void
winode(uint inum, struct dinode *ip)
winode(u32 inum, struct dinode *ip)
{
char buf[512];
uint bn;
u32 bn;
struct dinode *dip;
bn = i2b(inum);
......@@ -183,10 +183,10 @@ winode(uint inum, struct dinode *ip)
}
void
rinode(uint inum, struct dinode *ip)
rinode(u32 inum, struct dinode *ip)
{
char buf[512];
uint bn;
u32 bn;
struct dinode *dip;
bn = i2b(inum);
......@@ -196,7 +196,7 @@ rinode(uint inum, struct dinode *ip)
}
void
rsect(uint sec, void *buf)
rsect(u32 sec, void *buf)
{
if(lseek(fsfd, sec * 512L, 0) != sec * 512L){
perror("lseek");
......@@ -208,10 +208,10 @@ rsect(uint sec, void *buf)
}
}
uint
ialloc(ushort type)
u32
ialloc(u16 type)
{
uint inum = freeinode++;
u32 inum = freeinode++;
struct dinode din;
bzero(&din, sizeof(din));
......@@ -226,7 +226,7 @@ ialloc(ushort type)
void
balloc(int used)
{
uchar buf[512];
u8 buf[512];
int i;
printf("balloc: first %d blocks have been allocated\n", used);
......@@ -242,14 +242,14 @@ balloc(int used)
#define min(a, b) ((a) < (b) ? (a) : (b))
void
iappend(uint inum, void *xp, int n)
iappend(u32 inum, void *xp, int n)
{
char *p = (char*)xp;
uint fbn, off, n1;
u32 fbn, off, n1;
struct dinode din;
char buf[512];
uint indirect[NINDIRECT];
uint x;
u32 indirect[NINDIRECT];
u32 x;
rinode(inum, &din);
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论