From 0570601b78d608eddfc2b5ad37d03e66e06ebb60 Mon Sep 17 00:00:00 2001 From: liqi <liqi123@mail.ustc.edu.cn> Date: Sun, 6 Aug 2023 08:40:10 +0800 Subject: [PATCH] fix part of errors --- Makefile | 34 ++++-- include/fs/fs.h | 1 + include/spinlock.h | 3 + kernel/fs/file.c | 30 +++-- kernel/printf.c | 4 +- kernel/ramdisk.c | 6 +- kernel/sysfile.c | 23 +--- kernel/sysproc.c | 40 +++--- kernel/trap.c | 8 +- kernel/vm.c | 2 +- user/cat.c | 6 +- user/echo.c | 6 +- user/find.c | 8 +- user/forktest.c | 6 +- user/grep.c | 6 +- user/grind.c | 18 +-- user/init.c | 16 +-- user/kill.c | 6 +- user/ln.c | 6 +- user/ls.c | 8 +- user/mkdir.c | 6 +- user/mmaptest.c | 297 --------------------------------------------- user/pingpong.c | 5 +- user/primes.c | 6 +- user/printf.c | 6 +- user/rm.c | 6 +- user/sh.c | 7 +- user/sleep.c | 6 +- user/stressfs.c | 8 +- user/sysinfotest.c | 8 +- user/trace.c | 8 +- user/ulib.c | 8 +- user/umalloc.c | 8 +- user/usertests.c | 18 +-- user/wc.c | 6 +- user/xargs.c | 8 +- user/zombie.c | 6 +- 37 files changed, 189 insertions(+), 465 deletions(-) delete mode 100644 user/mmaptest.c diff --git a/Makefile b/Makefile index 614074e..ee85cea 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,6 @@ OBJS = \ $K/swtch.o \ $K/console.o \ $K/sleeplock.o \ - $K/file.o \ $K/kalloc.o\ $K/vm.o\ $K/trap.o\ @@ -33,16 +32,24 @@ OBJS = \ $K/tlbrefill.o\ $K/merror.o\ $K/ramdisk.o\ - $K/bio.o\ - $K/log.o\ - $K/fs.o\ - $K/pipe.o\ $K/exec.o\ $K/syscall.o\ $K/sysproc.o\ $K/sysfile.o\ $K/uservec.o\ $K/exception.o\ + $K/fs/fat32/cluster.c\ + $K/fs/fat32/dirent.c\ + $K/fs/fat32/fat.c\ + $K/fs/fat32/fat32.c\ + $K/fs/bio.o\ + $K/fs/blkdev.o \ + $K/fs/file.o \ + $K/fs/fs.o\ + $K/fs/mount.o \ + $K/fs/pipe.o\ + $K/fs/poll.o \ + $K/fs/rootfs.o \ # $K/mmap.o\ TOOLPREFIX = loongarch64-unknown-linux-gnu- @@ -53,7 +60,7 @@ LD = $(TOOLPREFIX)ld OBJCOPY = $(TOOLPREFIX)objcopy OBJDUMP = $(TOOLPREFIX)objdump -ASFLAGS = -march=loongarch64 -mabi=lp64s +ASFLAGS = -march=loongarch64 -mabi=lp64s -Iinclude/ CFLAGS = -Wall -Werror -O -fno-omit-frame-pointer -ggdb CFLAGS += -MD CFLAGS += -march=loongarch64 -mabi=lp64s @@ -103,9 +110,6 @@ $U/_sh: $U/sh.c $(ULIB) $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $U/_sh $U/sh.o $(ULIB) $(OBJDUMP) -S $U/_sh > $U/sh.asm -mkfs/mkfs: mkfs/mkfs.c $(INC)/fs.h $(INC)/param.h $(INC)/types.h $(INC)/stat.h - gcc -Werror -Wall -I. -o mkfs/mkfs mkfs/mkfs.c - # Prevent deletion of intermediate files, e.g. cat.o, after first build, so # that disk image changes after first build are persistent until clean. More # details: @@ -169,9 +173,15 @@ TPROGS=\ $T/yield\ $T/run-all.sh -fs.img: mkfs/mkfs $(UPROGS) $(TPROGS) - mkfs/mkfs fs.img $(UPROGS) $(TPROGS) - xxd -i fs.img > kernel/ramdisk.h +dst=/mnt +fs.img: + @if [ ! -f "fs.img" ]; then \ + echo "making fs image..."; \ + dd if=/dev/zero of=fs.img bs=512k count=512; \ + mkfs.vfat -F 32 -s 4 fs.img; fi + @sudo mount fs.img $(dst) + @make sdcard dst=$(dst) + @sudo umount $(dst) -include kernel/*.d user/*.d diff --git a/include/fs/fs.h b/include/fs/fs.h index 7e81081..ab4122f 100644 --- a/include/fs/fs.h +++ b/include/fs/fs.h @@ -16,6 +16,7 @@ #include "fs/stat.h" #include "sleeplock.h" #include "mmap.h" +#include "fs/file.h" struct superblock; struct inode; diff --git a/include/spinlock.h b/include/spinlock.h index 4392820..971dfd6 100644 --- a/include/spinlock.h +++ b/include/spinlock.h @@ -1,3 +1,5 @@ +#ifndef __SPINLOCK_H +#define __SPINLOCK_H // Mutual exclusion lock. struct spinlock { uint locked; // Is the lock held? @@ -7,3 +9,4 @@ struct spinlock { struct cpu *cpu; // The cpu holding the lock. }; +#endif \ No newline at end of file diff --git a/kernel/fs/file.c b/kernel/fs/file.c index e0b6217..5c7adbf 100644 --- a/kernel/fs/file.c +++ b/kernel/fs/file.c @@ -9,20 +9,17 @@ #define __module_name__ "file" #include "types.h" -#include "hal/riscv.h" +#include "loongarch.h" #include "param.h" -#include "sync/spinlock.h" -#include "sync/sleeplock.h" +#include "spinlock.h" +#include "sleeplock.h" #include "fs/fs.h" #include "fs/file.h" #include "fs/pipe.h" #include "fs/stat.h" -#include "sched/proc.h" +#include "proc.h" #include "printf.h" -#include "utils/string.h" -#include "mm/vm.h" -#include "mm/kmalloc.h" -#include "utils/debug.h" +#include "string.h" #include "errno.h" @@ -582,3 +579,20 @@ int fcntldup(struct file *f, int fd, int cloexec) return base + fd; } + +int +origin_filestat(struct file *f, uint64 addr) +{ + struct proc *p = myproc(); + struct stat st; + + if(f->type == FD_INODE || f->type == FD_DEVICE){ + ilock(f->ip); + stati(f->ip, &st); + iunlock(f->ip); + if(copyout(p->pagetable, addr, (char *)&st, sizeof(st)) < 0) + return -1; + return 0; + } + return -1; +} \ No newline at end of file diff --git a/kernel/printf.c b/kernel/printf.c index 0380b12..4d9ea14 100644 --- a/kernel/printf.c +++ b/kernel/printf.c @@ -8,8 +8,8 @@ #include "param.h" #include "spinlock.h" #include "sleeplock.h" -#include "fs.h" -#include "file.h" +#include "fs/fs.h" +#include "fs/file.h" #include "memlayout.h" #include "loongarch.h" #include "defs.h" diff --git a/kernel/ramdisk.c b/kernel/ramdisk.c index 4f1ff6f..ddd62cd 100644 --- a/kernel/ramdisk.c +++ b/kernel/ramdisk.c @@ -9,8 +9,8 @@ #include "memlayout.h" #include "spinlock.h" #include "sleeplock.h" -#include "fs.h" -#include "buf.h" +#include "fs/fs.h" +#include "fs/buf.h" #include "ramdisk.h" #define RAMDISK 0x04000000 #define B_DIRTY 0x1 @@ -26,7 +26,7 @@ ramdiskinit(void) void ramdiskrw(struct buf *b,int w) { - uint64 diskaddr = b->blockno * BSIZE; + uint64 diskaddr = b->sectorno * BSIZE; // char *addr = (char *)RAMDISK + diskaddr; char *addr = (char *)fs_img + diskaddr; if(!w && !b->valid) diff --git a/kernel/sysfile.c b/kernel/sysfile.c index 327d27d..8d3ba41 100644 --- a/kernel/sysfile.c +++ b/kernel/sysfile.c @@ -9,12 +9,12 @@ #include "loongarch.h" #include "defs.h" #include "param.h" -#include "stat.h" +#include "fs/stat.h" #include "spinlock.h" #include "proc.h" -#include "fs.h" +#include "fs/fs.h" #include "sleeplock.h" -#include "file.h" +#include "fs/file.h" #include "fcntl.h" #define NULL 0 @@ -43,20 +43,6 @@ static int argfd(int n, int *pfd, struct file **pf) { return 0; } -// Allocate a file descriptor for the given file. -// Takes over file reference from caller on success. -static int fdalloc(struct file *f) { - int fd; - struct proc *p = myproc(); - - for (fd = 0; fd < NOFILE; fd++) { - if (p->ofile[fd] == 0) { - p->ofile[fd] = f; - return fd; - } - } - return -1; -} uint64 sys_dup(void) { struct file *f; @@ -64,7 +50,7 @@ uint64 sys_dup(void) { if (argfd(0, 0, &f) < 0) return -1; - if ((fd = fdalloc(f)) < 0) + if ((fd = fdalloc(f, 0)) < 0) return -1; filedup(f); return fd; @@ -132,6 +118,7 @@ uint64 sys_fstat(void) { return -1; return filestat(f, st); } + uint64 sys_ffstat(void) { struct file *f; uint64 st; // user pointer to struct stat diff --git a/kernel/sysproc.c b/kernel/sysproc.c index 86c1842..29d6f78 100644 --- a/kernel/sysproc.c +++ b/kernel/sysproc.c @@ -9,6 +9,7 @@ #include "sysinfo.h" #include "struct_timespec.h" #include "time.h" +#include "fs/fs.h" @@ -274,23 +275,26 @@ uint64 sys_nanosleep(void) { } +// get absolute cwd string uint64 -sys_getcwd(void){ - uint64 addr; - int len; - if(argaddr(0, &addr) < 0){ - return -1; - } - if(argint(1, &len) < 0){ - return -1; - } - char buf[MAXPATH]; - int max = MAXPATH < len ? MAXPATH:len; - if(getcwd(myproc()->cwd,buf,max) < 0){ - return -1; - } - if(copyout(myproc()->pagetable,addr,buf,max)<0){ - return -1; - } - return addr; +sys_getcwd(void) +{ + uint64 addr; + int size; + if (argaddr(0, &addr) < 0 || argint(1, (int*)&size) < 0) + return -1; + + if (size < 2) + return -1; + + char buf[MAXPATH]; + + int max = MAXPATH < size ? MAXPATH : size; + if ((size = namepath(myproc()->cwd, buf, max)) < 0) + return -1; + struct proc *p = myproc(); + if (copyout(p->pagetable, addr, buf, size) < 0) + return -1; + + return size; } \ No newline at end of file diff --git a/kernel/trap.c b/kernel/trap.c index c35685a..c6e9a21 100644 --- a/kernel/trap.c +++ b/kernel/trap.c @@ -2,11 +2,11 @@ #include "loongarch.h" #include "defs.h" #include "param.h" -#include "fs.h" +#include "fs/fs.h" #include "spinlock.h" #include "sleeplock.h" -#include "file.h" -#include "stat.h" +#include "fs/file.h" +#include "fs/stat.h" #include "proc.h" #include "mmap.h" #include "memlayout.h" @@ -92,7 +92,7 @@ usertrap(void) vp->mapcnt += PGSIZE; //maintain the mapcnt ilock( vp->f->ip ); - readi( vp->f->ip , 1 , addr , addr-vp->addr , PGSIZE); //copy a page of the file from the disk + vp->f->ip->fop->read( vp->f->ip , 1 , addr , addr-vp->addr , PGSIZE); //copy a page of the file from the disk iunlock( vp->f->ip ); } } diff --git a/kernel/vm.c b/kernel/vm.c index c356340..04ed22b 100644 --- a/kernel/vm.c +++ b/kernel/vm.c @@ -4,7 +4,7 @@ #include "elf.h" #include "loongarch.h" #include "defs.h" -#include "fs.h" +#include "fs/fs.h" #include "spinlock.h" #include "proc.h" void diff --git a/user/cat.c b/user/cat.c index 598f005..c67da0b 100644 --- a/user/cat.c +++ b/user/cat.c @@ -1,6 +1,6 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "types.h" +#include "fs/stat.h" +#include "user.h" char buf[512]; diff --git a/user/echo.c b/user/echo.c index 3f19cd7..181fbd6 100644 --- a/user/echo.c +++ b/user/echo.c @@ -1,6 +1,6 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "types.h" +#include "fs/stat.h" +#include "user.h" int main(int argc, char *argv[]) diff --git a/user/find.c b/user/find.c index bd18a26..24fcd87 100644 --- a/user/find.c +++ b/user/find.c @@ -1,7 +1,7 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" -#include "kernel/fs.h" +#include "types.h" +#include "fs/stat.h" +#include "user.h" +#include "fs/fs.h" char * get_name(char *path) diff --git a/user/forktest.c b/user/forktest.c index 384e75f..f2edaff 100644 --- a/user/forktest.c +++ b/user/forktest.c @@ -1,9 +1,9 @@ // Test that fork fails gracefully. // Tiny executable so that the limit can be filling the proc table. -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "types.h" +#include "fs/stat.h" +#include "user.h" #define N 1000 diff --git a/user/grep.c b/user/grep.c index 19882b9..3224eff 100644 --- a/user/grep.c +++ b/user/grep.c @@ -1,8 +1,8 @@ // Simple grep. Only supports ^ . * $ operators. -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "types.h" +#include "fs/stat.h" +#include "user.h" char buf[1024]; int match(char*, char*); diff --git a/user/grind.c b/user/grind.c index f245d75..9d52bf1 100644 --- a/user/grind.c +++ b/user/grind.c @@ -2,15 +2,15 @@ // run random system calls in parallel forever. // -#include "kernel/param.h" -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" -#include "kernel/fs.h" -#include "kernel/fcntl.h" -#include "kernel/syscall.h" -#include "kernel/memlayout.h" -#include "kernel/loongarch.h" +#include "param.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "fs/fs.h" +#include "fcntl.h" +#include "syscall.h" +#include "memlayout.h" +#include "loongarch.h" +#include "user.h" // from FreeBSD. int diff --git a/user/init.c b/user/init.c index 7e7bb8c..036b05d 100644 --- a/user/init.c +++ b/user/init.c @@ -1,13 +1,13 @@ // init: The initial user-level program -#include "kernel/types.h" -#include "kernel/stat.h" -#include "kernel/spinlock.h" -#include "kernel/sleeplock.h" -#include "kernel/fs.h" -#include "kernel/file.h" -#include "user/user.h" -#include "kernel/fcntl.h" +#include "types.h" +#include "fs/stat.h" +#include "spinlock.h" +#include "sleeplock.h" +#include "fs/fs.h" +#include "fs/file.h" +#include "user.h" +#include "fcntl.h" char *argv[] = { "sh", 0 }; diff --git a/user/kill.c b/user/kill.c index 1b0253b..957d3a0 100644 --- a/user/kill.c +++ b/user/kill.c @@ -1,6 +1,6 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "user.h" int main(int argc, char **argv) diff --git a/user/ln.c b/user/ln.c index 1894143..f5c8799 100644 --- a/user/ln.c +++ b/user/ln.c @@ -1,6 +1,6 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "user.h" int main(int argc, char *argv[]) diff --git a/user/ls.c b/user/ls.c index a3d2fac..92016d3 100644 --- a/user/ls.c +++ b/user/ls.c @@ -1,7 +1,7 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" -#include "kernel/fs.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "user.h" +#include "fs/fs.h" char* fmtname(char *path) diff --git a/user/mkdir.c b/user/mkdir.c index c2b31c1..e91afdf 100644 --- a/user/mkdir.c +++ b/user/mkdir.c @@ -1,6 +1,6 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "user.h" int main(int argc, char *argv[]) diff --git a/user/mmaptest.c b/user/mmaptest.c deleted file mode 100644 index 0819622..0000000 --- a/user/mmaptest.c +++ /dev/null @@ -1,297 +0,0 @@ -#include "kernel/param.h" -#include "kernel/fcntl.h" -#include "kernel/types.h" -#include "kernel/stat.h" -#include "kernel/riscv.h" -#include "kernel/fs.h" -#include "user/user.h" - -void mmap_test(); -void fork_test(); -char buf[BSIZE]; - -#define MAP_FAILED ((char *) -1) - -int -main(int argc, char *argv[]) -{ - mmap_test(); - fork_test(); - printf("mmaptest: all tests succeeded\n"); - exit(0); -} - -char *testname = "???"; - -void -err(char *why) -{ - printf("mmaptest: %s failed: %s, pid=%d\n", testname, why, getpid()); - exit(1); -} - -// -// check the content of the two mapped pages. -// -void -_v1(char *p) -{ - int i; - for (i = 0; i < PGSIZE*2; i++) { - if (i < PGSIZE + (PGSIZE/2)) { - if (p[i] != 'A') { - printf("mismatch at %d, wanted 'A', got 0x%x\n", i, p[i]); - err("v1 mismatch (1)"); - } - } else { - if (p[i] != 0) { - printf("mismatch at %d, wanted zero, got 0x%x\n", i, p[i]); - err("v1 mismatch (2)"); - } - } - } -} - -// -// create a file to be mapped, containing -// 1.5 pages of 'A' and half a page of zeros. -// -void -makefile(const char *f) -{ - int i; - int n = PGSIZE/BSIZE; - - unlink(f); - int fd = open(f, O_WRONLY | O_CREATE); - if (fd == -1) - err("open"); - memset(buf, 'A', BSIZE); - // write 1.5 page - for (i = 0; i < n + n/2; i++) { - if (write(fd, buf, BSIZE) != BSIZE) - err("write 0 makefile"); - } - if (close(fd) == -1) - err("close"); -} - -void -mmap_test(void) -{ - int fd; - int i; - const char * const f = "mmap.dur"; - printf("mmap_test starting\n"); - testname = "mmap_test"; - - // - // create a file with known content, map it into memory, check that - // the mapped memory has the same bytes as originally written to the - // file. - // - makefile(f); - if ((fd = open(f, O_RDONLY)) == -1) - err("open"); - - printf("test mmap f\n"); - // - // this call to mmap() asks the kernel to map the content - // of open file fd into the address space. the first - // 0 argument indicates that the kernel should choose the - // virtual address. the second argument indicates how many - // bytes to map. the third argument indicates that the - // mapped memory should be read-only. the fourth argument - // indicates that, if the process modifies the mapped memory, - // that the modifications should not be written back to - // the file nor shared with other processes mapping the - // same file (of course in this case updates are prohibited - // due to PROT_READ). the fifth argument is the file descriptor - // of the file to be mapped. the last argument is the starting - // offset in the file. - // - char *p = mmap(0, PGSIZE*2, PROT_READ, MAP_PRIVATE, fd, 0); - if (p == MAP_FAILED) - err("mmap (1)"); - _v1(p); - if (munmap(p, PGSIZE*2) == -1) - err("munmap (1)"); - - printf("test mmap f: OK\n"); - - printf("test mmap private\n"); - // should be able to map file opened read-only with private writable - // mapping - p = mmap(0, PGSIZE*2, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); - if (p == MAP_FAILED) - err("mmap (2)"); - if (close(fd) == -1) - err("close"); - _v1(p); - for (i = 0; i < PGSIZE*2; i++) - p[i] = 'Z'; - if (munmap(p, PGSIZE*2) == -1) - err("munmap (2)"); - - printf("test mmap private: OK\n"); - - printf("test mmap read-only\n"); - - // check that mmap doesn't allow read/write mapping of a - // file opened read-only. - if ((fd = open(f, O_RDONLY)) == -1) - err("open"); - p = mmap(0, PGSIZE*3, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (p != MAP_FAILED) - err("mmap call should have failed"); - if (close(fd) == -1) - err("close"); - - printf("test mmap read-only: OK\n"); - - printf("test mmap read/write\n"); - - // check that mmap does allow read/write mapping of a - // file opened read/write. - if ((fd = open(f, O_RDWR)) == -1) - err("open"); - p = mmap(0, PGSIZE*3, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (p == MAP_FAILED) - err("mmap (3)"); - if (close(fd) == -1) - err("close"); - - // check that the mapping still works after close(fd). - _v1(p); - - // write the mapped memory. - for (i = 0; i < PGSIZE*2; i++) - p[i] = 'Z'; - - // unmap just the first two of three pages of mapped memory. - if (munmap(p, PGSIZE*2) == -1) - err("munmap (3)"); - - printf("test mmap read/write: OK\n"); - - printf("test mmap dirty\n"); - - // check that the writes to the mapped memory were - // written to the file. - if ((fd = open(f, O_RDWR)) == -1) - err("open"); - for (i = 0; i < PGSIZE + (PGSIZE/2); i++){ - char b; - if (read(fd, &b, 1) != 1) - err("read (1)"); - if (b != 'Z') - err("file does not contain modifications"); - } - if (close(fd) == -1) - err("close"); - - printf("test mmap dirty: OK\n"); - - printf("test not-mapped unmap\n"); - - // unmap the rest of the mapped memory. - if (munmap(p+PGSIZE*2, PGSIZE) == -1) - err("munmap (4)"); - - printf("test not-mapped unmap: OK\n"); - - printf("test mmap two files\n"); - - // - // mmap two files at the same time. - // - int fd1; - if((fd1 = open("mmap1", O_RDWR|O_CREATE)) < 0) - err("open mmap1"); - if(write(fd1, "12345", 5) != 5) - err("write mmap1"); - char *p1 = mmap(0, PGSIZE, PROT_READ, MAP_PRIVATE, fd1, 0); - if(p1 == MAP_FAILED) - err("mmap mmap1"); - close(fd1); - unlink("mmap1"); - - int fd2; - if((fd2 = open("mmap2", O_RDWR|O_CREATE)) < 0) - err("open mmap2"); - if(write(fd2, "67890", 5) != 5) - err("write mmap2"); - char *p2 = mmap(0, PGSIZE, PROT_READ, MAP_PRIVATE, fd2, 0); - if(p2 == MAP_FAILED) - err("mmap mmap2"); - close(fd2); - unlink("mmap2"); - - if(memcmp(p1, "12345", 5) != 0) - err("mmap1 mismatch"); - if(memcmp(p2, "67890", 5) != 0) - err("mmap2 mismatch"); - - munmap(p1, PGSIZE); - if(memcmp(p2, "67890", 5) != 0) - err("mmap2 mismatch (2)"); - munmap(p2, PGSIZE); - - printf("test mmap two files: OK\n"); - - printf("mmap_test: ALL OK\n"); -} - -// -// mmap a file, then fork. -// check that the child sees the mapped file. -// -void -fork_test(void) -{ - int fd; - int pid; - const char * const f = "mmap.dur"; - - printf("fork_test starting\n"); - testname = "fork_test"; - - // mmap the file twice. - makefile(f); - if ((fd = open(f, O_RDONLY)) == -1) - err("open"); - unlink(f); - char *p1 = mmap(0, PGSIZE*2, PROT_READ, MAP_SHARED, fd, 0); - if (p1 == MAP_FAILED) - err("mmap (4)"); - char *p2 = mmap(0, PGSIZE*2, PROT_READ, MAP_SHARED, fd, 0); - if (p2 == MAP_FAILED) - err("mmap (5)"); - - // read just 2nd page. - if(*(p1+PGSIZE) != 'A') - err("fork mismatch (1)"); - - if((pid = fork()) < 0) - err("fork"); - if (pid == 0) { - _v1(p1); - munmap(p1, PGSIZE); // just the first page - exit(0); // tell the parent that the mapping looks OK. - } - - int status = -1; - wait(&status); - - if(status != 0){ - printf("fork_test failed\n"); - exit(1); - } - - // check that the parent's mappings are still there. - _v1(p1); - _v1(p2); - - printf("fork_test OK\n"); -} - diff --git a/user/pingpong.c b/user/pingpong.c index e8c523e..40c30a8 100644 --- a/user/pingpong.c +++ b/user/pingpong.c @@ -1,5 +1,6 @@ -#include "kernel/types.h" -#include "user/user.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "user.h" int main(int argc, char *argv[]) { diff --git a/user/primes.c b/user/primes.c index e1cd7cf..d227fc2 100644 --- a/user/primes.c +++ b/user/primes.c @@ -1,6 +1,6 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "user.h" void run(int *p, int current_num) { diff --git a/user/printf.c b/user/printf.c index 5c5c782..588b825 100644 --- a/user/printf.c +++ b/user/printf.c @@ -1,6 +1,6 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "types.h" +#include "fs/stat.h" +#include "user.h" #include <stdarg.h> diff --git a/user/rm.c b/user/rm.c index 26b8f1f..1116110 100644 --- a/user/rm.c +++ b/user/rm.c @@ -1,6 +1,6 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "user.h" int main(int argc, char *argv[]) diff --git a/user/sh.c b/user/sh.c index 83dd513..f076245 100644 --- a/user/sh.c +++ b/user/sh.c @@ -1,8 +1,9 @@ // Shell. -#include "kernel/types.h" -#include "user/user.h" -#include "kernel/fcntl.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "user.h" +#include "fcntl.h" // Parsed command representation #define EXEC 1 diff --git a/user/sleep.c b/user/sleep.c index 12d1ee5..d807b9e 100644 --- a/user/sleep.c +++ b/user/sleep.c @@ -1,6 +1,6 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "user.h" int main(int argc, char *argv[]) { diff --git a/user/stressfs.c b/user/stressfs.c index 247a7a5..6977738 100644 --- a/user/stressfs.c +++ b/user/stressfs.c @@ -7,10 +7,10 @@ // for (i = 0; i < 40000; i++) // asm volatile(""); -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" -#include "kernel/fs.h" +#include "fs/stat.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "user.h" #include "kernel/fcntl.h" int diff --git a/user/sysinfotest.c b/user/sysinfotest.c index 83d378a..855780d 100644 --- a/user/sysinfotest.c +++ b/user/sysinfotest.c @@ -1,7 +1,7 @@ -#include "kernel/types.h" -#include "kernel/loongarch.h" -#include "kernel/sysinfo.h" -#include "user/user.h" +#include "types.h" +#include "loongarch.h" +#include "sysinfo.h" +#include "user.h" void diff --git a/user/trace.c b/user/trace.c index dd77760..ec7385d 100644 --- a/user/trace.c +++ b/user/trace.c @@ -1,7 +1,7 @@ -#include "kernel/param.h" -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "param.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "user.h" int main(int argc, char *argv[]) diff --git a/user/ulib.c b/user/ulib.c index 462f96a..3bc922f 100644 --- a/user/ulib.c +++ b/user/ulib.c @@ -1,7 +1,7 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "kernel/fcntl.h" -#include "user/user.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "fcntl.h" +#include "user.h" char* strcpy(char *s, const char *t) diff --git a/user/umalloc.c b/user/umalloc.c index 2092a32..290618d 100644 --- a/user/umalloc.c +++ b/user/umalloc.c @@ -1,7 +1,7 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" -#include "kernel/param.h" +#include "types.h" +#include "fs/stat.h" +#include "user.h" +#include "param.h" // Memory allocator by Kernighan and Ritchie, // The C programming Language, 2nd ed. Section 8.7. diff --git a/user/usertests.c b/user/usertests.c index c4c4acd..03688df 100644 --- a/user/usertests.c +++ b/user/usertests.c @@ -1,12 +1,12 @@ -#include "kernel/param.h" -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" -#include "kernel/fs.h" -#include "kernel/fcntl.h" -#include "kernel/syscall.h" -#include "kernel/memlayout.h" -#include "kernel/loongarch.h" +#include "param.h" +#include "fs/types.h" +#include "fs/stat.h" +#include "user.h" +#include "fs/fs.h" +#include "fcntl.h" +#include "syscall.h" +#include "memlayout.h" +#include "loongarch.h" // // Tests xv6 system calls. usertests without arguments runs them all diff --git a/user/wc.c b/user/wc.c index 6a851ca..a2206eb 100644 --- a/user/wc.c +++ b/user/wc.c @@ -1,6 +1,6 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "types.h" +#include "fs/stat.h" +#include "user.h" char buf[512]; diff --git a/user/xargs.c b/user/xargs.c index c699beb..8dc92a0 100644 --- a/user/xargs.c +++ b/user/xargs.c @@ -1,7 +1,7 @@ -#include "kernel/types.h" -#include "kernel/stat.h" -#include "kernel/param.h" -#include "user/user.h" +#include "types.h" +#include "fs/stat.h" +#include "param.h" +#include "user.h" int read_line(char buf[]) { diff --git a/user/zombie.c b/user/zombie.c index 8b89a33..13109f3 100644 --- a/user/zombie.c +++ b/user/zombie.c @@ -1,9 +1,9 @@ // Create a zombie process that // must be reparented at exit. -#include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "types.h" +#include "fs/stat.h" +#include "user.h" int main(void) -- GitLab