summaryrefslogtreecommitdiff
path: root/src/kernel/main2.c
diff options
context:
space:
mode:
authorBenji Dial <Benji3.141@gmail.com>2020-08-13 23:59:14 -0400
committerBenji Dial <Benji3.141@gmail.com>2020-08-13 23:59:14 -0400
commit7ff724fe8f709440da9c730fdb8dcbaa4f989ed5 (patch)
treee7f768ff56798bef3edc166a30e9cb8d7f25bd1e /src/kernel/main2.c
parent2ddbeb9f7214f6d3feef651eba83e6a9d120a743 (diff)
downloadportland-os-7ff724fe8f709440da9c730fdb8dcbaa4f989ed5.tar.gz
FAT16 directory enumeration, making many functions static, new 'log' functions to wrap vga and serial
Diffstat (limited to 'src/kernel/main2.c')
-rw-r--r--src/kernel/main2.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/kernel/main2.c b/src/kernel/main2.c
new file mode 100644
index 0000000..2b85592
--- /dev/null
+++ b/src/kernel/main2.c
@@ -0,0 +1,59 @@
+#include <stdint.h>
+#include "drive.h"
+#include "util.h"
+#include "log.h"
+
+static char nbuf2[11];
+
+static char path_builder[200] = "";
+static uint8_t path_builder_len = 0;
+
+static char indent_builder[20] = " ";
+static uint8_t indent_builder_len = 2;
+
+void tree(struct drive *d) {
+ struct directory_content_info infos[100];
+ uint8_t n_infos = d->enumerate_dir(d, path_builder, infos, 100);
+
+ if (!n_infos) {
+ logsz(indent_builder);
+ logsz("(empty)\n");
+ return;
+ }
+
+ for (uint8_t i = 0; i < n_infos; ++i) {
+ logsz(indent_builder);
+ logsz(infos[i].name);
+
+ if (infos[i].is_dir) {
+ logsz(":\n");
+
+ indent_builder[indent_builder_len] = ' ';
+ indent_builder[indent_builder_len + 1] = ' ';
+ indent_builder[indent_builder_len + 2] = '\0';
+ indent_builder_len += 2;
+
+ uint8_t name_length = 0;
+ while (infos[i].name[name_length])
+ ++name_length;
+
+ memcpy(path_builder + path_builder_len, infos[i].name, name_length + 1);
+ path_builder_len += name_length;
+
+ tree(d);
+
+ path_builder_len -= name_length;
+ path_builder[path_builder_len] = '\0';
+
+ indent_builder_len -= 2;
+ indent_builder[indent_builder_len] = '\0';
+ }
+
+ else {
+ u32_dec(infos[i].size, nbuf2);
+ logsz(" (");
+ logsz(nbuf2);
+ logsz(" bytes)\n");
+ }
+ }
+} \ No newline at end of file