summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2020-09-13 22:59:42 -0400
committerBenji Dial <benji6283@gmail.com>2020-09-13 22:59:42 -0400
commit20853582d5385d12421433d21910e783caa00764 (patch)
tree446bbd18353cfe0897d293a822458b7960a3645e /src/user
parent44d29a33df81ac07163d5146a9e43a0c4fb80af0 (diff)
downloadportland-os-20853582d5385d12421433d21910e783caa00764.tar.gz
dirinfo command
Diffstat (limited to 'src/user')
-rw-r--r--src/user/dirinfo/dirinfo.c49
-rw-r--r--src/user/include/pland/syscall.h13
-rw-r--r--src/user/knob/entry.asm2
3 files changed, 62 insertions, 2 deletions
diff --git a/src/user/dirinfo/dirinfo.c b/src/user/dirinfo/dirinfo.c
new file mode 100644
index 0000000..7484eb8
--- /dev/null
+++ b/src/user/dirinfo/dirinfo.c
@@ -0,0 +1,49 @@
+#include <pland/syscall.h>
+#include <knob/format.h>
+#include <knob/file.h>
+#include <knob/user.h>
+
+#define MAX_DIR_ENTRIES 20
+
+void main(const char *arg) {
+ uint8_t dn;
+ const char *path = remove_prefix(arg, &dn);
+
+ tell_user_sz("Directory info for ");
+ tell_user_sz(*arg ? arg : "drive root");
+ tell_user_sz("\n");
+
+ _dir_info_entry infos[MAX_DIR_ENTRIES];
+ uint8_t count = _enumerate_dir(dn, path, infos, MAX_DIR_ENTRIES);
+ tell_user_sz(
+ count == MAX_DIR_ENTRIES
+ ? "Truncated to 20 entries.\n\n"
+ : "\n"
+ );
+
+ uint32_t total_size = 0;
+
+ if (!count)
+ tell_user_sz("(none)\n");
+
+ for (uint8_t i = 0; i < count; ++i) {
+ tell_user_sz(infos[i].name);
+ tell_user_sz(": ");
+ if (infos[i].is_dir)
+ tell_user_sz("dir");
+ else {
+ char nbuf[11];
+ itosz(infos[i].size, nbuf);
+ tell_user_sz(nbuf);
+ tell_user_sz(" bytes");
+ total_size += infos[i].size;
+ }
+ tell_user_sz("\n");
+ }
+
+ tell_user_sz("\nTotal size without subdirectories: ");
+ char nbuf[11];
+ itosz(total_size, nbuf);
+ tell_user_sz(nbuf);
+ tell_user_sz(" bytes\n");
+} \ No newline at end of file
diff --git a/src/user/include/pland/syscall.h b/src/user/include/pland/syscall.h
index 75383fc..e16a7fb 100644
--- a/src/user/include/pland/syscall.h
+++ b/src/user/include/pland/syscall.h
@@ -45,9 +45,16 @@ enum _scn {
_SCN_GET_KEY,
_SCN_ALLOCATE_RAM,
_SCN_MEMORY_INFO,
- _SCN_WAIT_FOR_TASK
+ _SCN_WAIT_FOR_TASK,
+ _SCN_ENUMERATE_DIR
};
+typedef struct {
+ bool is_dir;
+ char name[100];
+ uint32_t size;
+} _dir_info_entry;
+
static inline uint32_t _sc0(enum _scn eax) {
volatile uint32_t out;
asm (
@@ -166,4 +173,8 @@ static inline void _wait_for_task(_process_handle_t handle) {
_sc1(_SCN_WAIT_FOR_TASK, handle);
}
+static inline uint32_t _enumerate_dir(_drive_number_t drive_number, const char *path, _dir_info_entry *buffer, uint32_t max_count) {
+ return _sc4(_SCN_ENUMERATE_DIR, drive_number, (uint32_t)path, (uint32_t)buffer, max_count);
+}
+
#endif \ No newline at end of file
diff --git a/src/user/knob/entry.asm b/src/user/knob/entry.asm
index acf6f5f..e9548d4 100644
--- a/src/user/knob/entry.asm
+++ b/src/user/knob/entry.asm
@@ -19,5 +19,5 @@ _entry:
jmp main
section .stack nobits alloc noexec write align=16
-resb 1024
+resb 4096
stack: \ No newline at end of file