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

memide.c and mkfs.c

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