summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fs/ext2.c2
-rw-r--r--kernel/kernel.c1
-rw-r--r--kernel/syscalls.c2
-rw-r--r--userspace/Makefile3
-rw-r--r--userspace/foolshell.c90
-rw-r--r--userspace/ls.c24
6 files changed, 95 insertions, 27 deletions
diff --git a/fs/ext2.c b/fs/ext2.c
index 4db858f..82755de 100644
--- a/fs/ext2.c
+++ b/fs/ext2.c
@@ -281,6 +281,8 @@ int ext2_filename_to_inode_traverse(uint8_t *ram, char *path,int inode_start)
}
int ext2_filename_to_inode(uint8_t *ram, char *path)
{
+
+ if(true==strcmp(path,"/",0))return 2; // root is inode 2 by definition
char buf[256];
for(int i=0;i<256;i++)
{
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 684b70d..828f663 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -105,6 +105,7 @@ void kernel_main(uint32_t initial_stack, int mp)
// load and run foolshell
// we will come back into the kernel only on interrupts...
+ asm("mov $0x05bff,%esp"); // set stack pointer
syscall_execve("/bin/foolshell",0,0);
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 590d96e..e4d31b5 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -392,7 +392,6 @@ uint32_t syscall_sbrk(int incr, int none1, int none2)
int syscall_exit(int ret, char **env, int none2)
{
- asm("mov $0x07bff,%esp"); // set stack pointer
#ifdef LOG_SYSCALLS
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"exit (ret=%d) (env=0x%08X)", ret, env);
#endif
@@ -404,6 +403,7 @@ int syscall_exit(int ret, char **env, int none2)
i++;
}
+ asm("mov $0x05bff,%esp"); // set stack pointer
static char *argv[]={"shell","--silent",NULL};
syscall_execve("/bin/foolshell",argv,env); // start shell
}
diff --git a/userspace/Makefile b/userspace/Makefile
index 3de83ea..63310bf 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -1,10 +1,11 @@
CC=i686-foolos-gcc
CFLAGS=
+CFLAGS+=-I..
CFLAGS+=-w
CFLAGS+=-std=gnu11
-PROGS=foolshell simple brainfuck add checker ls clear
+PROGS=foolshell ls simple brainfuck add checker clear
ext2.img: $(PROGS)
dd if=/dev/zero of=ext2.img bs=512 count=5000
diff --git a/userspace/foolshell.c b/userspace/foolshell.c
index 29e8438..faa46be 100644
--- a/userspace/foolshell.c
+++ b/userspace/foolshell.c
@@ -10,17 +10,20 @@ void hello()
// ascci art: http://patorjk.com/software/taag/#p=testall&f=Cards&t=Fool%20OS
puts(
- " ______ __ ____ _____ \n"
- " / ____/___ ____ / / / __ \\/ ___/ \n"
- " / /_ / __ \\/ __ \\/ / / / / /\\__ \\ \n"
- " / __/ / /_/ / /_/ / / / /_/ /___/ / \n"
- " /_/ \\____/\\____/_/ \\____//____/ \n"
- " \n"
- "Welcome to FoolShell v0.2 (Compiled on " __DATE__ " at " __TIME__ "\n"
- "--------------------------------------------------------------------\n\n"
- "type 'help' anytime to show shell built-ins\n"
- "or execute user programms that are in the '/bin' directory (e.g. ls)\n"
+ " ______ __ ____ _____ \n"
+ " / ____/___ ____ / / / __ \\/ ___/ \n"
+ " / /_ / __ \\/ __ \\/ / / / / /\\__ \\ \n"
+ " / __/ / /_/ / /_/ / / / /_/ /___/ / \n"
+ " /_/ \\____/\\____/_/ \\____//____/ \n"
+ " \n"
+ "Welcome to FoolShell v0.3 (Compiled on " __DATE__ " at " __TIME__ "\n"
+ "------------------------------------------------------------------\n\n"
+ "Please type 'help' anytime, to show shell \"built-ins\" or execute \n"
+ "user programms that are in you $PATH directory by simply typing \n"
+ "their filenames.\n"
);
+
+ printf("Your $PATH is currently set to: %s\n\n",getenv("PATH"));
}
void prompt()
@@ -105,10 +108,68 @@ 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' 'cd [dir]'");
+ puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv/setenv [var] [val]', 'env' 'cd [dir]'");
}
else if(!strcmp(command,"cd"))
{
+ char *dir=getenv("PWD");
+
+ char buf[256];
+
+ if(token[1][0]!='/')
+ {
+ sprintf(buf,"%s%s%s",dir,dir[0]=='/'&&dir[1]==0?"":"/",token[1]);
+ }
+ else
+ {
+ sprintf(buf,"%s",token[1]);
+ }
+
+ char token[10];
+
+ //adjust pwd (resolve '..' and '.')
+//// printf("adjusting pwd: '%s'\n",buf);
+ int left=1;
+ int right=0;
+
+ do{
+
+ int t=0;
+ do
+ {
+ right++;
+ token[t]=buf[right];
+
+ t++;
+ }
+ while(buf[right]!=0&&buf[right]!='/');
+ token[t-1]=0;
+
+// printf("path token: '%s'\n",token);
+
+
+
+ if(!strcmp(token,".."))
+ {
+ left--;
+ while(buf[left]!='/')left--;
+ }
+ else if(!strcmp(token,"."))
+ {
+ }
+ else
+ {
+ int i=0;
+ if(left!=1)buf[left++]='/';
+ do{buf[left++]=token[i++];}while(token[i]!=0);
+
+ }
+
+ }while(buf[right]!=0);
+ buf[left]=0;
+// printf("adjusted: '%s'\n",buf);
+
+ setenv("PWD",buf,1);
}
else if(!strcmp(command,"echo"))
@@ -128,14 +189,14 @@ int process(char *buf)
}
else if(!strcmp(command,"getenv"))
{
- printf("(0x%08X) put: %s = %s(0x%08X) \n",environ,token[1],getenv(token[1]),getenv(token[1]));
+ printf("(0x%08X) get: '%s' = '%s'(0x%08X) \n",environ,token[1],getenv(token[1]),getenv(token[1]));
}
- else if(!strcmp(command,"putenv"))
+ else if(!strcmp(command,"putenv")||!strcmp(command,"setenv"))
{
char buf[256];
sprintf(buf,"%s=%s",token[1],token[2]);
putenv(buf);
- printf("(0x%08X) set: %s = %s \n",environ,token[1],getenv(token[1]));
+ printf("(0x%08X) set: '%s' = '%s' \n",environ,token[1],getenv(token[1]));
}
else if(!strcmp(command,"env"))
{
@@ -152,6 +213,7 @@ int process(char *buf)
execve(token[0],token,0);
char buf[256];
sprintf(buf,"/bin/%s",token[0]);
+ asm("mov $0x05bff,%esp"); // set stack pointer
execve(buf,token,environ);
puts("foolshell: command not found");
}
diff --git a/userspace/ls.c b/userspace/ls.c
index 4cbcb6d..1cbb065 100644
--- a/userspace/ls.c
+++ b/userspace/ls.c
@@ -1,28 +1,30 @@
-#include "../fs/fs.h"
+#include "fs/fs.h"
void usage()
{
puts("ls [inode_nr]");
}
+
+
int main(int argc, char **argv)
{
- char *dir;
+
fs_dirent *dirs=malloc(sizeof(fs_dirent)*25);
+ char *dir=getenv("PWD");
+// printf("PWD = %s\n",dir);
- if(argc!=2)
- {
- dir=getenv("PWD");
- }
- else
+ if(argc==2)
{
- if(argv[1][0]=="/")dir=argv[1];
- else
+ if(argv[1][0]!='/')
{
char buf[256];
- sprintf(buf,"%s/%s",getenv("PWD"),argv[1]);
+ sprintf(buf,"%s/%s",dir,argv[1]);
dir=buf;
-
+ }
+ else
+ {
+ dir=argv[1];
}
}