提交 71fbc8bc 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Build file.c and pipe.c.

上级 2d5c99ba
...@@ -4,6 +4,7 @@ OBJS = \ ...@@ -4,6 +4,7 @@ OBJS = \
cga.o \ cga.o \
condvar.o \ condvar.o \
console.o \ console.o \
file.o \
fs.o \ fs.o \
lapic.o \ lapic.o \
kalloc.o \ kalloc.o \
...@@ -11,6 +12,7 @@ OBJS = \ ...@@ -11,6 +12,7 @@ OBJS = \
memide.o \ memide.o \
mp.o \ mp.o \
ns.o \ ns.o \
pipe.o \
proc.o \ proc.o \
rcu.o \ rcu.o \
spinlock.o \ spinlock.o \
...@@ -76,9 +78,9 @@ clean: ...@@ -76,9 +78,9 @@ clean:
QEMUOPTS = -smp $(CPUS) -m 512 -nographic QEMUOPTS = -smp $(CPUS) -m 512 -nographic
qemu: kernel qemu: kernel
$(QEMU) $(QEMUOPTS) -kernel kernel -d int $(QEMU) $(QEMUOPTS) -kernel kernel
gdb: kernel gdb: kernel
$(QEMU) $(QEMUOPTS) -kernel kernel -d int -S -s $(QEMU) $(QEMUOPTS) -kernel kernel -S -s
ud0: kernel ud0: kernel
rsync -avP kernel amsterdam.csail.mit.edu:/tftpboot/ud0/kernel.xv6 rsync -avP kernel amsterdam.csail.mit.edu:/tftpboot/ud0/kernel.xv6
#include "types.h" #include "types.h"
#include "defs.h"
#include "param.h" #include "param.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.h" #include "condvar.h"
#include "kernel.h"
#include "fs.h" #include "fs.h"
#include "file.h" #include "file.h"
#include "stat.h" #include "stat.h"
......
...@@ -18,8 +18,11 @@ struct condvar; ...@@ -18,8 +18,11 @@ struct condvar;
struct context; struct context;
struct vmnode; struct vmnode;
struct inode; struct inode;
struct file;
struct stat;
struct proc; struct proc;
struct vmap; struct vmap;
struct pipe;
// bio.c // bio.c
void binit(void); void binit(void);
...@@ -40,6 +43,15 @@ void cprintf(const char*, ...); ...@@ -40,6 +43,15 @@ void cprintf(const char*, ...);
void panic(const char*) __attribute__((noreturn)); void panic(const char*) __attribute__((noreturn));
void snprintf(char *buf, u32 n, char *fmt, ...); void snprintf(char *buf, u32 n, char *fmt, ...);
// file.c
struct file* filealloc(void);
void fileclose(struct file*);
struct file* filedup(struct file*);
void fileinit(void);
int fileread(struct file*, char*, int n);
int filestat(struct file*, struct stat*);
int filewrite(struct file*, char*, int n);
// fs.c // fs.c
int namecmp(const char*, const char*); int namecmp(const char*, const char*);
struct inode* namei(char*); struct inode* namei(char*);
...@@ -49,6 +61,9 @@ void ilock(struct inode*, int writer); ...@@ -49,6 +61,9 @@ void ilock(struct inode*, int writer);
void iunlockput(struct inode*); void iunlockput(struct inode*);
void iupdate(struct inode*); void iupdate(struct inode*);
void iunlock(struct inode*); void iunlock(struct inode*);
int readi(struct inode*, char*, u32, u32);
void stati(struct inode*, struct stat*);
int writei(struct inode*, char*, u32, u32);
// ide.c // ide.c
void ideinit(void); void ideinit(void);
...@@ -65,6 +80,7 @@ void kmfree(void*); ...@@ -65,6 +80,7 @@ void kmfree(void*);
// lapic.c // lapic.c
int cpunum(void); int cpunum(void);
void lapicstartap(u8, u32 addr); void lapicstartap(u8, u32 addr);
void lapiceoi(void);
// mp.c // mp.c
extern int ncpu; extern int ncpu;
...@@ -114,6 +130,12 @@ void* ns_remove(struct ns *ns, struct nskey key, void *val); // remove ...@@ -114,6 +130,12 @@ void* ns_remove(struct ns *ns, struct nskey key, void *val); // remove
void* ns_enumerate(struct ns *ns, void *(*f)(void *, void *, void *), void *arg); void* ns_enumerate(struct ns *ns, void *(*f)(void *, void *, void *), void *arg);
void* ns_enumerate_key(struct ns *ns, struct nskey key, void *(*f)(void *, void *), void *arg); void* ns_enumerate_key(struct ns *ns, struct nskey key, void *(*f)(void *, void *), void *arg);
// pipe.c
int pipealloc(struct file**, struct file**);
void pipeclose(struct pipe*, int);
int piperead(struct pipe*, char*, int);
int pipewrite(struct pipe*, char*, int);
// proc.c // proc.c
void addrun(struct proc *); void addrun(struct proc *);
struct proc* copyproc(struct proc*); struct proc* copyproc(struct proc*);
...@@ -180,3 +202,4 @@ int copyout(struct vmap *, uptr, void*, u64); ...@@ -180,3 +202,4 @@ int copyout(struct vmap *, uptr, void*, u64);
void vmn_free(struct vmnode *); void vmn_free(struct vmnode *);
void switchuvm(struct proc*); void switchuvm(struct proc*);
void switchkvm(void); void switchkvm(void);
int pagefault(struct vmap *, uptr, u32);
#include "types.h" #include "types.h"
#include "defs.h"
#include "param.h" #include "param.h"
#include "mmu.h" #include "mmu.h"
#include "kernel.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.h" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.h" #include "proc.h"
#include "fs.h" #include "fs.h"
#include "file.h" #include "file.h"
#include "cpu.h"
#define PIPESIZE 512 #define PIPESIZE 512
...@@ -15,8 +16,8 @@ struct pipe { ...@@ -15,8 +16,8 @@ struct pipe {
struct spinlock lock; struct spinlock lock;
struct condvar cv; struct condvar cv;
char data[PIPESIZE]; char data[PIPESIZE];
uint nread; // number of bytes read u32 nread; // number of bytes read
uint nwrite; // number of bytes written u32 nwrite; // number of bytes written
int readopen; // read fd is still open int readopen; // read fd is still open
int writeopen; // write fd is still open int writeopen; // write fd is still open
}; };
...@@ -85,7 +86,7 @@ pipewrite(struct pipe *p, char *addr, int n) ...@@ -85,7 +86,7 @@ pipewrite(struct pipe *p, char *addr, int n)
acquire(&p->lock); acquire(&p->lock);
for(i = 0; i < n; i++){ for(i = 0; i < n; i++){
while(p->nwrite == p->nread + PIPESIZE){ //DOC: pipewrite-full while(p->nwrite == p->nread + PIPESIZE){ //DOC: pipewrite-full
if(p->readopen == 0 || proc->killed){ if(p->readopen == 0 || myproc()->killed){
release(&p->lock); release(&p->lock);
return -1; return -1;
} }
...@@ -106,7 +107,7 @@ piperead(struct pipe *p, char *addr, int n) ...@@ -106,7 +107,7 @@ piperead(struct pipe *p, char *addr, int n)
acquire(&p->lock); acquire(&p->lock);
while(p->nread == p->nwrite && p->writeopen){ //DOC: pipe-empty while(p->nread == p->nwrite && p->writeopen){ //DOC: pipe-empty
if(proc->killed){ if(myproc()->killed){
release(&p->lock); release(&p->lock);
return -1; return -1;
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论