This commit is contained in:
kaashoek 2006-09-06 01:25:41 +00:00
parent 56ac0d72fc
commit d49a2d5386
3 changed files with 8 additions and 22 deletions

View file

@ -128,8 +128,8 @@ rm : rm.o $(ULIB)
mkfs : mkfs.c fs.h mkfs : mkfs.c fs.h
cc -o mkfs mkfs.c cc -o mkfs mkfs.c
fs.img : mkfs userfs usertests echo cat readme init sh ls mkdir rm fstests fs.img : mkfs userfs usertests echo cat README init sh ls mkdir rm fstests
./mkfs fs.img userfs usertests echo cat readme init sh ls mkdir rm fstests ./mkfs fs.img userfs usertests echo cat README init sh ls mkdir rm fstests
-include *.d -include *.d

21
sh.c
View file

@ -162,37 +162,24 @@ ioredirection(void)
for (i = 0; i < nextnode; i++) { for (i = 0; i < nextnode; i++) {
switch (list[i].token) { switch (list[i].token) {
case '<': case '<':
if (close(0) < 0)
printf(2, "close 0 failed\n");
if ((fd = open(list[i].s, O_RDONLY)) < 0) { if ((fd = open(list[i].s, O_RDONLY)) < 0) {
printf(2, "failed to open %s for read: %d", list[i].s, fd); printf(2, "failed to open %s for read: %d", list[i].s, fd);
return -1; return -1;
} }
if (debug) if (debug)
printf(2, "redirect 0 from %s\n", list[i].s); printf(2, "redirect 0 from %s\n", list[i].s);
close(0);
if ((dfd = dup(fd)) < 0)
printf(2, "dup failed\n");
if (debug)
printf(2, "dup returns %d\n", dfd);
close(fd);
break; break;
case '>': case '>':
if (close(1) < 0)
printf(2, "close 1 failed\n");
if ((fd = open(list[i].s, O_WRONLY|O_CREATE)) < 0) { if ((fd = open(list[i].s, O_WRONLY|O_CREATE)) < 0) {
printf(2, "failed to open %s for write: %d", list[i].s, fd); printf(2, "failed to open %s for write: %d", list[i].s, fd);
exit(); exit();
} }
if (debug) if (debug)
printf(2, "redirect 1 to %s\n", list[i].s); printf(2, "redirect 1 to %s\n", list[i].s);
if (close(1) < 0)
printf(2, "close 1 failed\n");
if ((dfd = dup(fd)) < 0)
printf(2, "dup failed\n");
if (debug)
printf(2, "dup returns %d\n", dfd);
close(fd);
break; break;
} }
} }

5
user.h
View file

@ -1,14 +1,12 @@
// system calls
int fork(void); int fork(void);
int exit(void) __attribute__((noreturn)); int exit(void) __attribute__((noreturn));
int wait(void); int wait(void);
int cons_putc(int);
int pipe(int*); int pipe(int*);
int write(int, void*, int); int write(int, void*, int);
int read(int, void*, int); int read(int, void*, int);
int close(int); int close(int);
int kill(int); int kill(int);
int panic(char*);
int cons_puts(char*);
int exec(char *, char **); int exec(char *, char **);
int open(char *, int); int open(char *, int);
int mknod (char*,short,short,short); int mknod (char*,short,short,short);
@ -21,6 +19,7 @@ int dup(int);
int getpid(); int getpid();
char *sbrk(int); char *sbrk(int);
// ulib.c
int stat(char *, struct stat *stat); int stat(char *, struct stat *stat);
int puts(char*); int puts(char*);
char* strcpy(char*, char*); char* strcpy(char*, char*);