diff --git a/.gitignore b/.gitignore index f1f0b20e..1b768bc8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ bootloader/stage1.bin bootloader/stage2.bin initrd/boot initrd/bin/* +initrd/etc hdd/boot hdd/bin/* hdd/etc/hostname diff --git a/kernel/fs/pipe.c b/kernel/fs/pipe.c index 820e16b6..1c289908 100644 --- a/kernel/fs/pipe.c +++ b/kernel/fs/pipe.c @@ -24,6 +24,11 @@ static inline size_t pipe_unread(pipe_device_t * pipe) { } } +size_t pipe_size(fs_node_t * node) { + pipe_device_t * pipe = (pipe_device_t *)node->inode; + return pipe_unread(pipe); +} + static inline size_t pipe_available(pipe_device_t * pipe) { if (pipe->read_ptr == pipe->write_ptr) { return pipe->size - 1; diff --git a/kernel/include/pipe.h b/kernel/include/pipe.h index 47cb65bd..1166cef2 100644 --- a/kernel/include/pipe.h +++ b/kernel/include/pipe.h @@ -18,5 +18,6 @@ typedef struct _pipe_device { } pipe_device_t; fs_node_t * make_pipe(size_t size); +size_t pipe_size(fs_node_t * node); #endif diff --git a/kernel/sys/syscall.c b/kernel/sys/syscall.c index 2dd6ed94..00c01b95 100644 --- a/kernel/sys/syscall.c +++ b/kernel/sys/syscall.c @@ -100,7 +100,7 @@ static int write(int fd, char * ptr, int len) { static int wait(int child) { if (child < 1) { - kprintf("lol nope\n"); + kprintf("[debug] Process %d requested group wait, which we can not do!\n", getpid()); return 0; } process_t * volatile child_task = process_from_pid(child); @@ -122,8 +122,13 @@ static int wait(int child) { } static int open(const char * file, int flags, int mode) { + kprintf("[debug] open(%s, 0x%x, 0x%x)\n", file, flags, mode); + validate((void *)file); fs_node_t * node = kopen((char *)file, 0); + if (!node && (mode & 0x600)) { + /* Um, make one */ + } if (!node) { return -1; } @@ -242,6 +247,11 @@ static int stat(int fd, uint32_t st) { f->st_rdev = 0; f->st_size = fn->length; + if (fn->flags & FS_PIPE) { + /* Pipes have dynamic sizes */ + f->st_size = pipe_size(fn); + } + return 0; } diff --git a/userspace/esh.c b/userspace/esh.c index 2d890161..e224814b 100644 --- a/userspace/esh.c +++ b/userspace/esh.c @@ -142,10 +142,7 @@ int main(int argc, char ** argv) { char * cmd = malloc(sizeof(char) * 1024); draw_prompt(last_ret); -#if 0 fgets(cmd, 1024, stdin); -#endif - readline(cmd, 1024); cmd[strlen(cmd)-1] = '\0'; char *p, *tokens[512], *last; int i = 0; diff --git a/userspace/login.c b/userspace/login.c index 5f5107ce..b7e29dc9 100644 --- a/userspace/login.c +++ b/userspace/login.c @@ -110,11 +110,14 @@ int main(int argc, char ** argv) { fprintf(stdout, "%s login: ", _hostname); fflush(stdout); - readline(username, 1024, 1); + fgets(username, 1024, stdin); + username[strlen(username)-1] = '\0'; - fprintf(stdout, "password: "); + fprintf(stdout, "password: \033[1001z"); fflush(stdout); - readline(password, 1024, 0); + fgets(password, 1024, stdin); + password[strlen(password)-1] = '\0'; + fprintf(stdout, "\033[1002z\n"); int uid = checkUserPass(username, password); diff --git a/userspace/terminal.c b/userspace/terminal.c index 379ce02a..846e3e9b 100644 --- a/userspace/terminal.c +++ b/userspace/terminal.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include FT_FREETYPE_H #include FT_CACHE_H @@ -175,12 +176,14 @@ ansi_put( { if (argc > 0) { int arg = atoi(argv[0]); - switch (argc) { + switch (arg) { case 1001: /* Local Echo Off */ + state.local_echo = 0; break; case 1002: /* Local Echo On */ + state.local_echo = 1; break; default: break; @@ -2903,13 +2906,13 @@ int main(int argc, char ** argv) { #endif int ofd = syscall_mkpipe(); - //int ifd = syscall_mkpipe(); + int ifd = syscall_mkpipe(); int pid = getpid(); uint32_t f = fork(); if (getpid() != pid) { - //syscall_dup2(ifd, 0); + syscall_dup2(ifd, 0); syscall_dup2(ofd, 1); syscall_dup2(ofd, 2); char * tokens[] = {"/bin/login",NULL}; @@ -2918,9 +2921,25 @@ int main(int argc, char ** argv) { } else { char buf[1024]; while (1) { - int r = read(ofd, buf, 1024); - for (uint32_t i = 0; i < r; ++i) { - ansi_put(buf[i]); + struct stat _stat; + fstat(0, &_stat); + if (_stat.st_size) { + int r = read(0, buf, min(_stat.st_size, 1024)); + for (uint32_t i = 0; i < r; ++i) { + if (state.local_echo) { + ansi_put(buf[i]); + } + char b[1]; + b[0] = buf[i]; + write(ifd, b, 1); + } + } + fstat(ofd, &_stat); + if (_stat.st_size) { + int r = read(ofd, buf, min(_stat.st_size, 1024)); + for (uint32_t i = 0; i < r; ++i) { + ansi_put(buf[i]); + } } } return 0; diff --git a/userspace/test-fs.c b/userspace/test-fs.c new file mode 100644 index 00000000..7926e71a --- /dev/null +++ b/userspace/test-fs.c @@ -0,0 +1,17 @@ +/* vim:tabstop=4 shiftwidth=4 noexpandtab + * + * File System Test Suite + */ +#include +#include +#include + +int main(int argc, char ** argv) { + printf("= Begin File System Testing =\n"); + + int fd = creat("/test.log", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + + printf("File descriptor generator: %d\n", fd); + + return 0; +}