From 95450710a8b8290a110686d78c2357d3920bcda5 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Wed, 22 Oct 2014 14:06:04 +0200 Subject: working on filesys and readdir syscall --- Makefile | 2 ++ asm/int_syscall_handler.asm | 8 ++++++++ fs/ext2.c | 6 +++--- fs/fs.c | 40 +++++++++++++++++----------------------- fs/fs.h | 19 +++++++++++++++++++ kernel/mouse.c | 1 + kernel/syscalls.c | 6 ++++++ userspace/foolshell.c | 15 ++++++++++++++- userspace/syscalls.c | 28 ++++++++++++++++++++++++++++ 9 files changed, 98 insertions(+), 27 deletions(-) create mode 100644 fs/fs.h diff --git a/Makefile b/Makefile index 04d468d..7c8cc91 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/fs/ext2.c b/fs/ext2.c index 90897e9..bc83f55 100644 --- a/fs/ext2.c +++ b/fs/ext2.c @@ -1,8 +1,7 @@ // ext2 minidriver // based on osdev wiki article: http://wiki.osdev.org/Ext2 -#include -#include +#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(""); } - +*/ diff --git a/fs/fs.c b/fs/fs.c index a213861..85e04ca 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -1,32 +1,26 @@ // abstraction layer for filesystems #include - -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; } diff --git a/fs/fs.h b/fs/fs.h new file mode 100644 index 0000000..68675f0 --- /dev/null +++ b/fs/fs.h @@ -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 #include #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")) { @@ -140,6 +141,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 #include +#include +#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"); -- cgit v1.2.3