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

Build file.c and pipe.c.

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