From 16083d4462b9a57ec1e1fc81cea73da9479982a5 Mon Sep 17 00:00:00 2001 From: kaashoek Date: Sun, 20 Aug 2006 03:08:54 +0000 Subject: [PATCH] removed block system call renumber system calls (run gmake clean!) skeleton for dup system call --- defs.h | 1 + fd.c | 6 ++++++ syscall.c | 61 ++++++++++++++++++------------------------------------- syscall.h | 28 ++++++++++++------------- user.h | 2 +- userfs.c | 2 -- usys.S | 2 +- 7 files changed, 43 insertions(+), 59 deletions(-) diff --git a/defs.h b/defs.h index 2928428..18ff4f1 100644 --- a/defs.h +++ b/defs.h @@ -94,6 +94,7 @@ int fd_read(struct fd *fd, char *addr, int n); int fd_write(struct fd *fd, char *addr, int n); int fd_stat(struct fd *fd, struct stat *); void fd_incref(struct fd *fd); +int fd_dup(struct fd *fd); // ide.c void ide_init(void); diff --git a/fd.c b/fd.c index e61cab2..7de4d55 100644 --- a/fd.c +++ b/fd.c @@ -149,3 +149,9 @@ fd_incref(struct fd *fd) fd->ref++; release(&fd_table_lock); } + +int +fd_dup(struct fd *fd) +{ + return -1; +} diff --git a/syscall.c b/syscall.c index 31b6189..5b857bd 100644 --- a/syscall.c +++ b/syscall.c @@ -398,6 +398,23 @@ sys_fstat(void) return r; } +int +sys_dup(void) +{ + struct proc *cp = curproc[cpu()]; + uint fd; + int r; + + if(fetcharg(0, &fd) < 0) + return -1; + if(fd < 0 || fd >= NOFILE) + return -1; + if(cp->fds[fd] == 0) + return -1; + r = fd_dup (cp->fds[fd]); + return r; +} + int sys_link(void) { @@ -543,44 +560,6 @@ sys_exec(void) return 0; } -int -sys_block(void) -{ - int i, j; - struct buf *b; - struct inode *ip; - - for (i = 0; i < 2; i++) { - cprintf ("issue read\n"); - b = bread(1, i); - - cprintf("disk 1 sector %d: ", i); - for (j = 0; j < 4; j++) - cprintf("%x ", b->data[j] & 0xff); - cprintf("\n"); - - brelse(b); - } - - ip = iget(1, 1); - cprintf("iget 1: %d %d %d %d %d %d %d %d\n", - ip->dev, ip->inum, ip->count, ip->busy, - ip->type, ip->nlink, ip->size, ip->addrs[0]); - iput(ip); - - ip = namei(".././//./../usertests", NAMEI_LOOKUP, 0); - if(ip){ - cprintf("namei(usertests): %d %d %d %d %d %d %d %d\n", - ip->dev, ip->inum, ip->count, ip->busy, - ip->type, ip->nlink, ip->size, ip->addrs[0]); - iput(ip); - } else { - cprintf("namei(usertests) failed\n"); - } - - return 0; -} - void syscall(void) { @@ -610,9 +589,6 @@ syscall(void) case SYS_close: ret = sys_close(); break; - case SYS_block: - ret = sys_block(); - break; case SYS_kill: ret = sys_kill(); break; @@ -640,6 +616,9 @@ syscall(void) case SYS_chdir: ret = sys_chdir(); break; + case SYS_dup: + ret = sys_dup(); + break; default: cprintf("unknown sys call %d\n", num); // XXX fault diff --git a/syscall.h b/syscall.h index 2209cf2..c89d5a3 100644 --- a/syscall.h +++ b/syscall.h @@ -1,18 +1,18 @@ #define SYS_fork 1 #define SYS_exit 2 #define SYS_wait 3 -#define SYS_pipe 5 -#define SYS_write 6 -#define SYS_read 7 -#define SYS_close 8 -#define SYS_block 9 -#define SYS_kill 10 -#define SYS_exec 13 -#define SYS_open 14 -#define SYS_mknod 15 -#define SYS_unlink 16 -#define SYS_fstat 17 -#define SYS_link 18 -#define SYS_mkdir 19 -#define SYS_chdir 20 +#define SYS_pipe 4 +#define SYS_write 5 +#define SYS_read 6 +#define SYS_close 7 +#define SYS_kill 9 +#define SYS_exec 10 +#define SYS_open 11 +#define SYS_mknod 12 +#define SYS_unlink 13 +#define SYS_fstat 14 +#define SYS_link 15 +#define SYS_mkdir 16 +#define SYS_chdir 17 +#define SYS_dup 18 diff --git a/user.h b/user.h index 27f2cfb..26d984c 100644 --- a/user.h +++ b/user.h @@ -6,7 +6,6 @@ int pipe(int*); int write(int, void*, int); int read(int, void*, int); int close(int); -int block(void); int kill(int); int panic(char*); int cons_puts(char*); @@ -18,6 +17,7 @@ int fstat (int fd, struct stat *stat); int link(char *, char *); int mkdir(char *); int chdir(char *); +int dup(int); int stat(char *, struct stat *stat); int puts(char*); diff --git a/userfs.c b/userfs.c index 5d0c859..25dfaf5 100644 --- a/userfs.c +++ b/userfs.c @@ -20,8 +20,6 @@ main(void) printf(stdout, "userfs is running\n"); - block(); - fd = open("echo", 0); if(fd >= 0){ printf(stdout, "open echo ok\n"); diff --git a/usys.S b/usys.S index 16d84e7..c7a162c 100644 --- a/usys.S +++ b/usys.S @@ -15,7 +15,6 @@ STUB(pipe) STUB(read) STUB(write) STUB(close) -STUB(block) STUB(kill) STUB(exec) STUB(open) @@ -25,3 +24,4 @@ STUB(fstat) STUB(link) STUB(mkdir) STUB(chdir) +STUB(dup)