diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | asm/int_syscall_handler.asm | 8 | ||||
| -rw-r--r-- | fs/ext2.c | 6 | ||||
| -rw-r--r-- | fs/fs.c | 40 | ||||
| -rw-r--r-- | fs/fs.h | 19 | ||||
| -rw-r--r-- | kernel/mouse.c | 1 | ||||
| -rw-r--r-- | kernel/syscalls.c | 6 | ||||
| -rw-r--r-- | userspace/foolshell.c | 15 | ||||
| -rw-r--r-- | userspace/syscalls.c | 28 |
9 files changed, 98 insertions, 27 deletions
@@ -36,6 +36,8 @@ CFLAGS+= -Wno-implicit-function-declaration SOURCES=$(wildcard ./kernel/*.c) SOURCES+=$(wildcard ./lib/*/*.c) +SOURCES+=$(wildcard ./fs/*.c) + ASMSOURCES=$(wildcard ./asm/*.asm) #kernel object files diff --git a/asm/int_syscall_handler.asm b/asm/int_syscall_handler.asm index 550ebb3..c36b9b5 100644 --- a/asm/int_syscall_handler.asm +++ b/asm/int_syscall_handler.asm @@ -5,6 +5,7 @@ global int_syscall_handler [extern syscall_write] [extern syscall_read] +[extern syscall_readdir] [bits 32] int_syscall_handler: @@ -27,6 +28,9 @@ int_syscall_handler: cmp eax, 62 je call_read + cmp eax, 63 + je call_readdir + done: mov ebx,eax @@ -63,6 +67,10 @@ call_write: call syscall_write jmp done +call_readdir: + call syscall_readdir + jmp done + call_read: mov al, 0x20 ;Port number AND command number to Acknowledge IRQ @@ -1,8 +1,7 @@ // ext2 minidriver // based on osdev wiki article: http://wiki.osdev.org/Ext2 -#include <stdint.h> -#include <stdio.h> +#include "lib/int/stdint.h" typedef struct ext2_superblock_struct { @@ -97,6 +96,7 @@ typedef struct ext2_inode_struct + /* int main() { ext2_superblock super; @@ -191,6 +191,6 @@ int main() puts(""); } - +*/ @@ -1,32 +1,26 @@ // abstraction layer for filesystems #include <lib/int/stdint.h> - -enum FS_FILE_TYPE{ - - FS_FILE_TYPE_DIR = 1, - FS_FILE_TYPE_FILE = 2 -}; - -typedef struct fs_file_struct -{ - int type; - char name[256]; - -}fs_file; - -int fs_list(char *path, fs_file *list); -{ - -} - -int fs_read(char *path, uint8_t *buf) +#include "fs.h" +// +// returns number of entries in the directory specified by name. +// fills 0-max into *dirs +int fs_readdir(const char *name,fs_dirent *dirs,int max) { + int testdata=5; -} + int inodes[]={13,14,15,16,17}; + char names[][256]={"dupa","test","drei","vier","funf"}; + char type[]={2,2,1,2,1}; -int fs_mount(char *dev, char *dir) -{ + for(int i=0;i<5;i++) + { + dirs[i].inode=inodes[i]; + for(int j=0;j<256;j++) + dirs[i].name[j]=names[i][j]; + dirs[i].type=type[i]; + } + return 5; } @@ -0,0 +1,19 @@ +#ifndef FOOLOS_FS +#define FOOLOS_FS + +enum FS_FILE_TYPE{ + + FS_FILE_TYPE_DIR = 1, + FS_FILE_TYPE_FILE = 2 +}; + +typedef struct fs_dirent_struct +{ + uint32_t inode; + uint32_t offset; + uint16_t length; + uint8_t type; + char name[256]; +}fs_dirent; + +#endif diff --git a/kernel/mouse.c b/kernel/mouse.c index 84b9c84..610baa8 100644 --- a/kernel/mouse.c +++ b/kernel/mouse.c @@ -67,6 +67,7 @@ void mouse_log() if(mouse_byte[0]&0x80||mouse_byte[0]&0x40)return; //skip packet on overflow if(!(mouse_byte[0]&0x8))panic(FOOLOS_MODULE_NAME,"mouse packets out of sync!?"); // this bit is always 1, otherwise panic! + // if(mouse_byte[1]>127){ diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 1eca490..5ddd4c8 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -1,6 +1,7 @@ #define FOOLOS_MODULE_NAME "syscalls" #include "lib/logger/log.h" #include "lib/bool/bool.h" +#include "fs/fs.h" // int syscall_write(int file, char *buf, int len) @@ -34,6 +35,11 @@ int syscall_read(int file, char *buf, int len) } + +int syscall_readdir(const char *name,fs_dirent *dirs,int max) +{ + return fs_readdir(name,dirs,max); +} // int example_syscall(int x,int y) diff --git a/userspace/foolshell.c b/userspace/foolshell.c index 173b0b2..15f26e3 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <string.h> #include "syscalls.c" +#include "../fs/fs.h" void hello() { puts( @@ -85,7 +86,7 @@ int process(char *buf) if(!strcmp(command,"HELP")) { - puts("foolshell: supported built-in commands: HELP, ECHO, TIME, MEM, PROC, TASKS, ALLOC, READ, SYSCALL."); + puts("foolshell: supported built-in commands: HELP, ECHO, TIME, MEM, PROC, TASKS, ALLOC, LS, SYSCALL."); } else if(!strcmp(command,"TIME")) { @@ -141,6 +142,18 @@ int process(char *buf) printf("system call returned %i\n",ebx); } + else if(!strcmp(command,"LS")) + { + + fs_dirent dirs[5]; + int ls=readdir("/dupa",&dirs,5); + int i; + for(i=0;i<ls;i++) + { + printf("%i %s%c\n",dirs[i].inode, dirs[i].name, ((dirs[i].type==2)?'/':' ')); + } + + } else if(!strcmp(command,"ECHO")) { diff --git a/userspace/syscalls.c b/userspace/syscalls.c index f4e77a1..f92541c 100644 --- a/userspace/syscalls.c +++ b/userspace/syscalls.c @@ -3,6 +3,8 @@ #include <sys/stat.h> #include <string.h> +#include <stdint.h> +#include "../fs/fs.h" static int preread; static int alloc; @@ -68,6 +70,32 @@ int read(int file, char *ptr, int len) return ebx; } +int readdir(const char *name,fs_dirent *dirs,int max) +{ + + int ebx; // WILL Hold return value; + + asm("pusha"); + + // select syscall + asm("mov $63,%eax"); + + // pass params + asm("mov %0,%%edx"::"m"(name)); + asm("mov %0,%%ecx"::"m"(dirs)); + asm("mov %0,%%ebx"::"m"(max)); + + // interrrupt + asm("int $0x80"); + + // get return value + asm("mov %%ebx, %0": "=b" (ebx)); + + asm("popa"); + + return ebx; +} + int open(const char *name, int flags, int mode) { // easywrite("syscall: open\n"); |
