diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-11-24 03:11:16 +0100 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-11-24 03:11:16 +0100 |
| commit | 1cb7a6bd1ab40188987feeaeefce021d441819e6 (patch) | |
| tree | e9dd69467be2c240f6ef2e3abb375f8868fac599 | |
| parent | 21e1c5e540da32b89fc4812caad494f0e25c17aa (diff) | |
some progress with userspace
| -rw-r--r-- | kernel/syscalls.c | 4 | ||||
| -rw-r--r-- | userspace/Makefile | 2 | ||||
| -rw-r--r-- | userspace/foolshell.c | 8 | ||||
| -rw-r--r-- | 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<ls;i++) - { - printf("%i %s%c\n",dirs[i].inode, dirs[i].name, ((dirs[i].type==FS_FILE_TYPE_DIR)?'/':' ')); } + } + int ls=readdir(dir,dirs,25); + if(ls==-1) + { + printf("%s: file or directory '%s' not found.\n",argv[0],dir); return 0; + } + + + 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; } |
