From 1cb7a6bd1ab40188987feeaeefce021d441819e6 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Mon, 24 Nov 2014 03:11:16 +0100 Subject: some progress with userspace --- kernel/syscalls.c | 4 +++- userspace/Makefile | 2 +- userspace/foolshell.c | 8 ++++++-- userspace/ls.c | 46 ++++++++++++++++++++++++++++------------------ 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 941a8e3..590d96e 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -194,6 +194,7 @@ int syscall_execve(char *name, char **argv, char **env) // char *env1="PS1=$ "; char *env2="PATH=/bin"; + char *env3="PWD=/home/miguel"; char environstr[256]; char **oldenviron=env; @@ -203,7 +204,8 @@ int syscall_execve(char *name, char **argv, char **env) { environ[0]=env1; environ[1]=env2; - environ[2]=NULL; + environ[2]=env3; + environ[3]=NULL; } else { diff --git a/userspace/Makefile b/userspace/Makefile index 3327375..3de83ea 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -16,7 +16,7 @@ ext2.img: $(PROGS) echo "hello one" > mnt/home/miguel/test1.txt mkdir -p mnt/bin cp $^ mnt/bin - cp ~/temp/fool-os-stuff/binutils-build-host-foolos/binutils/readelf mnt/bin +# cp ~/temp/fool-os-stuff/binutils-build-host-foolos/binutils/readelf mnt/bin mkdir -p mnt/etc echo "127.0.0.1 localhost" > mnt/etc/hosts sync diff --git a/userspace/foolshell.c b/userspace/foolshell.c index 2a70940..29e8438 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -25,7 +25,7 @@ void hello() void prompt() { - printf("%s",getenv("PS1")); + printf("%s%s",getenv("PWD"),getenv("PS1")); } int main(int argc, char **argv) @@ -105,7 +105,11 @@ int process(char *buf) if(!strcmp(command,"help")) { - puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]', 'env'"); + puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]', 'env' 'cd [dir]'"); + } + else if(!strcmp(command,"cd")) + { + } else if(!strcmp(command,"echo")) { diff --git a/userspace/ls.c b/userspace/ls.c index 5b5034b..4cbcb6d 100644 --- a/userspace/ls.c +++ b/userspace/ls.c @@ -7,28 +7,38 @@ void usage() int main(int argc, char **argv) { - fs_dirent *dirs=malloc(sizeof(fs_dirent)*25); + char *dir; + fs_dirent *dirs=malloc(sizeof(fs_dirent)*25); - if(argc!=2) + if(argc!=2) + { + dir=getenv("PWD"); + } + else + { + if(argv[1][0]=="/")dir=argv[1]; + else { - usage(); - return 0; - } - - char *dir=argv[1]; - int ls=readdir(dir,dirs,25); - if(ls==-1) - { - printf("%s: file or directory '%s' not found.\n",argv[0],dir); - return 0; - } - + char buf[256]; + sprintf(buf,"%s/%s",getenv("PWD"),argv[1]); + dir=buf; - int i; - for(i=0;i