diff --git a/toolchain/patches/newlib/toaru/bits/dirent.h b/toolchain/patches/newlib/toaru/bits/dirent.h new file mode 100644 index 00000000..d9cace06 --- /dev/null +++ b/toolchain/patches/newlib/toaru/bits/dirent.h @@ -0,0 +1,18 @@ +#ifndef DIRENT_H + +struct dirent { + uint32_t d_ino; + char d_name[256]; +}; + + +typedef struct DIR { + int fd; + int cur_entry; +} DIR; + +DIR * opendir (const char * dirname); +int closedir (DIR * dir); +struct dirent * readdir (DIR * dirp); + +#endif diff --git a/toolchain/patches/newlib/toaru/sys/dirent.h b/toolchain/patches/newlib/toaru/sys/dirent.h index 0fef9e0e..1d985c9b 100644 --- a/toolchain/patches/newlib/toaru/sys/dirent.h +++ b/toolchain/patches/newlib/toaru/sys/dirent.h @@ -1,58 +1 @@ -/* libc/sys/toaru/sys/dirent.h - Directory entry as returned by readdir */ - -/* Written 2000 by Werner Almesberger */ -/* Hacked, and broken by Kevin Lange */ - - -#ifndef _SYS_DIRENT_H -#define _SYS_DIRENT_H - -#include #include -#define _LIBC 1 -#define NOT_IN_libc 1 -#include -#undef _LIBC - -#define HAVE_NO_D_NAMLEN /* no struct dirent->d_namlen */ - -#define MAXNAMLEN 255 /* sizeof(struct dirent.d_name)-1 */ - - -typedef struct { - int dd_fd; /* directory file */ - int dd_loc; /* position in buffer */ - int dd_seek; - char *dd_buf; /* buffer */ - int dd_len; /* buffer length */ - int dd_size; /* amount of data in buffer */ - _LOCK_RECURSIVE_T dd_lock; -} DIR; - - -#define __dirfd(dir) (dir)->dd_fd - -/* --- redundant --- */ - -DIR *opendir(const char *); -struct dirent *readdir(DIR *); -void rewinddir(DIR *); -int closedir(DIR *); - -/* internal prototype */ -void _seekdir(DIR *dir, long offset); -DIR *_opendir(const char *); - -#ifndef _POSIX_SOURCE -long telldir (DIR *); -void seekdir (DIR *, off_t loc); - -int scandir (const char *__dir, - struct dirent ***__namelist, - int (*select) (const struct dirent *), - int (*compar) (const struct dirent **, const struct dirent **)); - -int alphasort (const struct dirent **__a, const struct dirent **__b); -#endif /* _POSIX_SOURCE */ - -#endif diff --git a/toolchain/patches/newlib/toaru/syscalls.c b/toolchain/patches/newlib/toaru/syscalls.c index 871be2d9..2c34a225 100644 --- a/toolchain/patches/newlib/toaru/syscalls.c +++ b/toolchain/patches/newlib/toaru/syscalls.c @@ -16,6 +16,7 @@ #include #include "syscall.h" +#include DEFN_SYSCALL1(exit, 0, int); DEFN_SYSCALL1(print, 1, const char *); @@ -65,6 +66,7 @@ DEFN_SYSCALL2(system_function, 43, int, char **); // --- Process Control --- int _exit(int val){ + printf("exit(%d)\n", val); return syscall_exit(val); } @@ -73,6 +75,12 @@ int execve(char *name, char **argv, char **env) { } int execvp(const char *file, char *const argv[]) { + fprintf(stderr, "execvp(%s,...);\n", file); + return syscall_execve(file,argv, NULL); +} + +int execv(const char * file, char *const argv[]) { + fprintf(stderr, "execv(%s,...);\n", file); return syscall_execve(file,argv, NULL); } @@ -310,13 +318,53 @@ char *getlogin(void) { } int dup2(int oldfd, int newfd) { + fprintf(stderr, "dup2(%d,%d);\n", oldfd, newfd); return syscall_dup2(oldfd, newfd); } unsigned int alarm(unsigned int seconds) { + fprintf(stderr, "alarm(%s);\n", seconds); return 0; } clock_t times(struct tms *buf) { + fprintf(stderr, "times(...)\n"); + return -1; +} + +DIR * opendir (const char * dirname) { + int fd = open(dirname, O_RDONLY); + if (fd == -1) { + return NULL; + } + + DIR * dir = malloc(sizeof(DIR)); + dir->fd = fd; + dir->cur_entry = -1; + return dir; +} + +int closedir (DIR * dir) { + if (dir && (dir->fd != -1)) { + return close(dir->fd); + } else { + return -1; + } +} + +struct dirent * readdir (DIR * dirp) { + static struct dirent ent; + + int ret = syscall_readdir(dirp->fd, ++dirp->cur_entry, &ent); + if (ret != 0) { + memset(&ent, 0, sizeof(struct dirent)); + return NULL; + } + + return &ent; +} + +long sysconf(int name) { + fprintf(stderr, "sysconf(%d);\n", name); return -1; } diff --git a/userspace/ls.c b/userspace/ls.c index 3a6e3abf..13a9f645 100644 --- a/userspace/ls.c +++ b/userspace/ls.c @@ -14,6 +14,7 @@ #include #include #include +#include #define MIN_COL_SPACING 2 @@ -198,49 +199,6 @@ int max (int a, int b) { } /* Should be kept in sync with 'struct dirent' in kernel/include/fs.h */ -struct dirent { - uint32_t inode; - char name[256]; -}; - - -typedef struct DIR { - int fd; - int cur_entry; -} DIR; - -DIR * opendir (const char * dirname) { - int fd = open(dirname, O_RDONLY); - if (fd == -1) { - return NULL; - } - - DIR * dir = malloc(sizeof(DIR)); - dir->fd = fd; - dir->cur_entry = -1; - return dir; -} - -int closedir (DIR * dir) { - if (dir && (dir->fd != -1)) { - return close(dir->fd); - } else { - return -1; - } -} - -struct dirent * readdir (DIR * dirp) { - static struct dirent ent; - - int ret = syscall_readdir(dirp->fd, ++dirp->cur_entry, &ent); - if (ret != 0) { - memset(&ent, 0, sizeof(struct dirent)); - return NULL; - } - - return &ent; -} - // TODO: This thing is broken! Oh fuck! /* int readdir_r (DIR *restrict dirp, @@ -273,7 +231,7 @@ int readdir_r (DIR *restrict dirp, int entcmp (const void * c1, const void * c2) { struct dirent * d1 = *(struct dirent **)c1; struct dirent * d2 = *(struct dirent **)c2; - return strcmp(d1->name, d2->name); + return strcmp(d1->d_name, d2->d_name); } void print_entry (const char * filename, const char * srcpath, int colwidth) { @@ -353,7 +311,7 @@ int main (int argc, char * argv[]) { struct dirent * ent = readdir(dirp); while (ent != NULL) { - if (show_hidden || (ent->name[0] != '.')) { + if (show_hidden || (ent->d_name[0] != '.')) { struct dirent * entcpy = malloc(sizeof(struct dirent)); memcpy(entcpy, ent, sizeof(struct dirent)); list_insert(ents_list, (void *)entcpy); @@ -378,7 +336,7 @@ int main (int argc, char * argv[]) { /* Determine the gridding dimensions */ int ent_max_len = 0; for (int i = 0; i < numents; i++) { - ent_max_len = max(ent_max_len, strlen(ents_array[i]->name)); + ent_max_len = max(ent_max_len, strlen(ents_array[i]->d_name)); } int term_width = DEFAULT_TERM_WIDTH; // For now, we assume 128 @@ -401,11 +359,11 @@ int main (int argc, char * argv[]) { for (int i = 0; i < numents;) { // Print columns on this row - print_entry(ents_array[i++]->name, p, ent_max_len); + print_entry(ents_array[i++]->d_name, p, ent_max_len); for (int j = 0; (i < numents) && (j < (cols-1)); j++) { printf(" "); - print_entry(ents_array[i++]->name, p, ent_max_len); + print_entry(ents_array[i++]->d_name, p, ent_max_len); } printf("\n");