aboutsummaryrefslogtreecommitdiff
path: root/os
diff options
context:
space:
mode:
authorJames Barnett <noreply@jamesbarnett.xyz>2019-10-06 18:39:36 +0100
committerJames Barnett <noreply@jamesbarnett.xyz>2019-10-06 18:39:36 +0100
commit29478baf24532391cd94bd08d94cf867dee976e6 (patch)
tree3127ae32572cd262c7283c6223b6e5712a07f91d /os
parente77b371fb0fc4e62fa727a340b2e322fa60ebcff (diff)
downloadtinyOS-29478baf24532391cd94bd08d94cf867dee976e6.tar.xz
tinyOS-29478baf24532391cd94bd08d94cf867dee976e6.zip
Start on ram backed filesystemHEADmaster
Diffstat (limited to 'os')
-rw-r--r--os/commands/commands.h3
-rw-r--r--os/commands/echo.c2
-rw-r--r--os/commands/echo.h1
-rw-r--r--os/commands/files.c20
-rw-r--r--os/filesystem/ramfs.c27
-rw-r--r--os/filesystem/ramfs.h10
-rw-r--r--os/shell/shell.c10
-rw-r--r--os/stdlib/sdtlib.h3
-rw-r--r--os/stdlib/stdlib.c14
9 files changed, 84 insertions, 6 deletions
diff --git a/os/commands/commands.h b/os/commands/commands.h
new file mode 100644
index 0000000..6bc0e7d
--- /dev/null
+++ b/os/commands/commands.h
@@ -0,0 +1,3 @@
+void cmd_cf(char *args);
+void cmd_lf(char *args);
+void cmd_echo(char *args); \ No newline at end of file
diff --git a/os/commands/echo.c b/os/commands/echo.c
index 669003e..4a0bcd3 100644
--- a/os/commands/echo.c
+++ b/os/commands/echo.c
@@ -1,5 +1,5 @@
#include "../../kernel/gpu/text_mode/display.h"
-void echo(char *args) {
+void cmd_echo(char *args) {
scrn_println(args);
} \ No newline at end of file
diff --git a/os/commands/echo.h b/os/commands/echo.h
deleted file mode 100644
index db62a4f..0000000
--- a/os/commands/echo.h
+++ /dev/null
@@ -1 +0,0 @@
-void echo(char *args); \ No newline at end of file
diff --git a/os/commands/files.c b/os/commands/files.c
new file mode 100644
index 0000000..6f23e34
--- /dev/null
+++ b/os/commands/files.c
@@ -0,0 +1,20 @@
+#include "../../kernel/gpu/text_mode/display.h"
+#include "../filesystem/ramfs.h"
+
+void cmd_cf(char *args) {
+ // todo check args, filname length etc
+ ramfs_create_file(args);
+ scrn_print("created file: ");
+ scrn_println(args);
+}
+
+void cmd_lf(char *args) {
+ scrn_println("files:");
+ File_t* files = ramfs_list_files();
+
+ for(int i = 0; i <= ramfs_get_tip_file_idx(); i++) {
+ scrn_print(files[i].name);
+ scrn_print(" ");
+ }
+ scrn_newline();
+}
diff --git a/os/filesystem/ramfs.c b/os/filesystem/ramfs.c
new file mode 100644
index 0000000..0c0fdff
--- /dev/null
+++ b/os/filesystem/ramfs.c
@@ -0,0 +1,27 @@
+#include "ramfs.h"
+#include "../../kernel/gpu/text_mode/display.h"
+
+#include "../stdlib/sdtlib.h"
+
+#define RAMDISK_SIZE 102400 // 100 blocks
+#define BLOCK_SIZE 1024
+#define MAX_FILES 128 // fixed size until mem management done
+
+unsigned char ramdisk[RAMDISK_SIZE];
+
+File_t files[MAX_FILES];
+int tip_file_idx = -1;
+
+File_t* ramfs_list_files() {
+ return files;
+}
+
+int ramfs_get_tip_file_idx() {
+ return tip_file_idx;
+}
+
+File_t ramfs_create_file(unsigned char *filename) {
+ int i = ++tip_file_idx;
+ strcpy(filename, files[i].name);
+ return files[i];
+}
diff --git a/os/filesystem/ramfs.h b/os/filesystem/ramfs.h
new file mode 100644
index 0000000..c0dd147
--- /dev/null
+++ b/os/filesystem/ramfs.h
@@ -0,0 +1,10 @@
+typedef struct
+{
+ char name[128]; // 128 max filename lentgh
+ int start_addr;
+ int end_addr;
+} File_t;
+
+File_t ramfs_create_file(unsigned char * filename);
+File_t* ramfs_list_files();
+int ramfs_get_tip_file_idx(); \ No newline at end of file
diff --git a/os/shell/shell.c b/os/shell/shell.c
index 4fb5488..615c824 100644
--- a/os/shell/shell.c
+++ b/os/shell/shell.c
@@ -1,7 +1,7 @@
#include "../../os/main.h"
#include "../../kernel/gpu/text_mode/display.h"
#include "../stdlib/sdtlib.h"
-#include "../commands/echo.h"
+#include "../commands/commands.h"
#define CMD_BUFFER_SIZE 80
@@ -71,7 +71,13 @@ unsigned char* shell_parse_args() {
void shell_exec_cmd(unsigned char* cmd_name, unsigned char* args) {
// TODO lookup string to funciton pointer
if (strcmp(cmd_name, "echo") == 0) {
- echo(args);
+ cmd_echo(args);
+ }
+ else if(strcmp(cmd_name, "cf") == 0) {
+ cmd_cf(args);
+ }
+ else if(strcmp(cmd_name, "lf") == 0) {
+ cmd_lf(args);
}
else if (strcmp(cmd_name, "") != 0) {
scrn_print(cmd_name);
diff --git a/os/stdlib/sdtlib.h b/os/stdlib/sdtlib.h
index 85073d2..cdb1aff 100644
--- a/os/stdlib/sdtlib.h
+++ b/os/stdlib/sdtlib.h
@@ -1,2 +1,3 @@
char* int_to_str(int i);
-int strcmp(const char *str1, const char *str2); \ No newline at end of file
+int strcmp(const char *str1, const char *str2);
+void strcpy(const char* src, char* dest); \ No newline at end of file
diff --git a/os/stdlib/stdlib.c b/os/stdlib/stdlib.c
index bdb2242..250e9b4 100644
--- a/os/stdlib/stdlib.c
+++ b/os/stdlib/stdlib.c
@@ -23,7 +23,7 @@ char* int_to_str(int i)
int strcmp(const char *str1, const char *str2)
{
- while(*str1){
+ while(*str1) {
if (*str1 != *str2) {
break;
}
@@ -32,4 +32,16 @@ int strcmp(const char *str1, const char *str2)
}
return *(const unsigned char*)str1 - *(const unsigned char*)str2;
+}
+
+void strcpy(const char *src, char * dest) {
+ char *ptr = dest;
+
+ while (*src != '\0') {
+ *dest = *src;
+ dest++;
+ src++;
+ }
+
+ *dest = '\0';
} \ No newline at end of file