diff --git a/src/bin/ls/main.c b/src/bin/ls/main.c index 167139a..95fa34c 100755 --- a/src/bin/ls/main.c +++ b/src/bin/ls/main.c @@ -24,7 +24,35 @@ #include #include +//UbixFS Directory Entry +struct directoryEntry { + uLong startCluster; //Starting Cluster Of File + uLong size; //Size Of File + uLong creationDate; //Date Created + uLong lastModified; //Date Last Modified + uLong uid; //UID Of Owner + uLong gid; //GID Of Owner + uShort attributes; //Files Attributes + uShort permissions; //Files Permissions + char fileName[256]; //File Name + }; + int main() { - printf("pwd init shell ls\n"); + int i = 0x0; + FILE *fd; + struct directoryEntry *dirEntry = (struct directoryEntry *)malloc(4096); + if (!(fd = fopen("/","r"))) { + printf("Error Reading Directory\n"); + exit(1); + } + printf("data: [%i]\n",dirEntry); + fread(dirEntry,4096,1,fd); + printf("data: [%i]\n",dirEntry); + printf("Test: [%s]\n",dirEntry->fileName); + /* + for (i=0;i<(4096/sizeof(struct directoryEntry));i++) { + printf("FileName: [%s]\n",dirEntry[i].fileName); + } + */ exit(1); } diff --git a/src/lib/libc/include/stdio.h b/src/lib/libc/include/stdio.h index 1cf3bbd..4b05046 100755 --- a/src/lib/libc/include/stdio.h +++ b/src/lib/libc/include/stdio.h @@ -24,12 +24,13 @@ #ifndef _STDIO_H #define _STDIO_H +#include #include /* Type Definitions */ -typedef struct fileDescriptorTable { - unsigned short fd; +typedef struct fileDescriptor { + uLong fd; } FILE; /* Definitions */ @@ -53,5 +54,6 @@ //New Functions Listed From Here On Till I'm Done Writing A libc int sprintf(char *string, const char *format, ...); char *gets(char *string); +size_t fread(void *pointer,size_t size,size_t count, FILE *stream); #endif \ No newline at end of file diff --git a/src/lib/libc/stdio/Makefile b/src/lib/libc/stdio/Makefile index c32a6c4..52467b7 100755 --- a/src/lib/libc/stdio/Makefile +++ b/src/lib/libc/stdio/Makefile @@ -15,7 +15,7 @@ REMOVE = rm -f #Objects -OBJS = printf.o vsprintf.o fd.o vfprintf.o fopen.o fwrite.o fgetc.o sprintf.o gets.o +OBJS = printf.o vsprintf.o fd.o vfprintf.o fopen.o fread.o fwrite.o fgetc.o sprintf.o gets.o #Output OUTPUT = libc.so diff --git a/src/lib/libc/stdio/fopen.c b/src/lib/libc/stdio/fopen.c index 14cd557..73070b6 100755 --- a/src/lib/libc/stdio/fopen.c +++ b/src/lib/libc/stdio/fopen.c @@ -22,8 +22,16 @@ **************************************************************************************/ #include +#include FILE *fopen(const char *file,const char *mode) { - FILE *fp = 0x0; + FILE *fp = malloc(sizeof(FILE)); + fp->fd = -1; + printf("fp->fd: [%i]\n",fp->fd); + asm( + "int %0\n" + : : "i" (0x80),"a" (8),"b" (file),"c" (mode),"d" (fp) + ); + printf("fp->fd: [%i]\n",fp->fd); return(fp); } \ No newline at end of file diff --git a/src/lib/libc/stdio/fread.c b/src/lib/libc/stdio/fread.c new file mode 100755 index 0000000..9e2e1f0 --- /dev/null +++ b/src/lib/libc/stdio/fread.c @@ -0,0 +1,32 @@ +/************************************************************************************** + Copyright (c) 2002 The UbixOS Project + All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors +in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its +contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +**************************************************************************************/ + +#include + +size_t fread(void *pointer,size_t size,size_t count, FILE *stream) { + asm( + "int %0\n" + : : "i" (0x80),"a" (9),"b" (pointer),"c" (size),"d" (stream) + ); + return(count); + } \ No newline at end of file diff --git a/src/sys/include/ubixfs/file.h b/src/sys/include/ubixfs/file.h index e3d36aa..d0a9ddd 100755 --- a/src/sys/include/ubixfs/file.h +++ b/src/sys/include/ubixfs/file.h @@ -32,7 +32,7 @@ #define fdRead 3 #define fdEof 4 -typedef struct fileDescriptorStruct { +typedef struct kernelFileDescriptorStruct { struct fileDescriptorStruct *next; uShort status; uShort mode; @@ -44,6 +44,10 @@ uChar buffer[512]; } fileDescriptor; +typedef struct userFileDescriptorStruct { + uLong fd; + } userFileDescriptor; + extern fileDescriptor *fdTable; extern fileDescriptor *lastFd; diff --git a/src/sys/include/ubixos/syscalls.h b/src/sys/include/ubixos/syscalls.h index 096181d..58be1b3 100755 --- a/src/sys/include/ubixos/syscalls.h +++ b/src/sys/include/ubixos/syscalls.h @@ -32,12 +32,14 @@ void sysFgetc(); void sysCheckPid(); void sysGetFreePage(); +void sysFopen(); +void sysFread(); typedef void (*functionPTR)(); functionPTR systemCalls[] = { sysFwrite,sysGetpid,sysExit,sysExec,sysFork,sysFgetc,sysCheckPid, - sysGetFreePage, + sysGetFreePage,sysFopen,sysFread, }; int totalCalls = sizeof(systemCalls)/sizeof(functionPTR); diff --git a/src/sys/ubixfs/file.c b/src/sys/ubixfs/file.c index 9c4fc2c..2899e3b 100755 --- a/src/sys/ubixfs/file.c +++ b/src/sys/ubixfs/file.c @@ -172,4 +172,40 @@ } //Return NULL If FD Is Not Found return(0x0); + } + +/************************************************************************ + +Function: void sysFopen(); +Description: Opens A File Descriptor For A User Task +Notes: + +************************************************************************/ +void sysFopen() { + char *file = 0x0,*flags = 0x0; + userFileDescriptor *userFd = 0x0; + fileDescriptor *tmpFd = 0x0; + asm("":"=b" (file),"=c" (flags),"=d" (userFd)); + asm("sti"); + userFd->fd = (uLong)fopen(file,flags); + tmpFd = userFd->fd; + kprintf("[%i][%i][%i][%s]\n",tmpFd,userFd->fd,tmpFd->size,tmpFd->fileName); + //Return + return; + } + +void sysFread() { + int i = 0x0; + char *data = 0x0; + uLong *size = 0x0; + userFileDescriptor *userFd = 0x0; + fileDescriptor *tmpFd = 0x0; + asm("":"=b" (data),"=c" (size),"=d" (userFd)); + tmpFd = userFd->fd; +// kprintf("[%i]Size: [%i][%i][%s]\n",data,size,tmpFd->size,tmpFd->fileName); + for (i=0;i