diff options
Diffstat (limited to 'userspace')
| -rw-r--r-- | userspace/Makefile | 2 | ||||
| -rw-r--r-- | userspace/ls.c | 28 | ||||
| -rw-r--r-- | userspace/shell.c | 34 |
3 files changed, 39 insertions, 25 deletions
diff --git a/userspace/Makefile b/userspace/Makefile index 74ced40..d66afd2 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -1,7 +1,7 @@ CC=i686-foolos-gcc CFLAGS=-w -PROGS=shell simple brainfuck add checker +PROGS=shell simple brainfuck add checker ls ext2.img: $(PROGS) dd if=/dev/zero of=ext2.img bs=512 count=5000 diff --git a/userspace/ls.c b/userspace/ls.c new file mode 100644 index 0000000..50c733b --- /dev/null +++ b/userspace/ls.c @@ -0,0 +1,28 @@ +#include "../fs/fs.h" + +void usage() +{ + puts("ls [inode_nr]"); +} + +int main(int argc, char **argv) +{ + fs_dirent *dirs=malloc(sizeof(fs_dirent)*25); + + if(argc!=2) + { + usage(); + return 0; + } + + int ls=readdir(atoi(argv[1]),dirs,25); + + + int i; + for(i=0;i<ls;i++) + { + printf("%i %s%c\n",dirs[i].inode, dirs[i].name, ((dirs[i].type==FS_FILE_TYPE_DIR)?'/':' ')); + } + + return 0; +} diff --git a/userspace/shell.c b/userspace/shell.c index 06a03d2..83f1e6f 100644 --- a/userspace/shell.c +++ b/userspace/shell.c @@ -2,15 +2,16 @@ #include <stdint.h> #include <string.h> -#include "../fs/fs.h" -void hello() { +void hello() +{ puts( "Welcome to FoolShell v0.1" ); } -void prompt() { +void prompt() +{ printf( "$ " ); @@ -87,20 +88,7 @@ int process(char *buf) if(!strcmp(command,"help")) { - puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'ls [inode_nr]', exec [inode_nr],'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]'"); - } - else if(!strcmp(command,"ls")) - { - fs_dirent *dirs=malloc(sizeof(fs_dirent)*25); - - int ls=readdir(atoi(token[1]),dirs,25); - - int i; - for(i=0;i<ls;i++) - { - printf("foolshell: %i %s%c\n",dirs[i].inode, dirs[i].name, ((dirs[i].type==FS_FILE_TYPE_DIR)?'/':' ')); - } - + puts("foolshell: supported built-in commands: 'help', 'echo [string]', exec [inode_nr],'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]'"); } else if(!strcmp(command,"exec")) { @@ -109,37 +97,35 @@ int process(char *buf) } else if(!strcmp(command,"echo")) { - printf("foolshell: \"%s\"\n",token[1]); + printf("\"%s\"\n",token[1]); } else if(!strcmp(command,"malloc")) { uint8_t *mall=malloc(atoi(token[1])); - printf("foolshell: allocated %d bytes at 0x%08X (%i).\n",atoi(token[1]),mall,mall); + printf("allocated %d bytes at 0x%08X (%i).\n",atoi(token[1]),mall,mall); } else if(!strcmp(command,"free")) { free(atoi(token[1])); - printf("foolshell: called free(0x%08X).\n",atoi(token[1])); + printf("called free(0x%08X).\n",atoi(token[1])); } else if(!strcmp(command,"getenv")) { - printf("foolshell: %s = %s \n",token[1],getenv(token[1])); + printf("%s = %s \n",token[1],getenv(token[1])); } else if(!strcmp(command,"putenv")) { char buf[256]; sprintf(buf,"%s=%s",token[1],token[2]); putenv(buf); - printf("foolshell: %s = %s \n",token[1],getenv(token[1])); + printf("set: %s = %s \n",token[1],getenv(token[1])); } else { puts("foolshell: command not found"); } - - // } |
