aboutsummaryrefslogtreecommitdiff
path: root/kernel/include/test/kshell/io.h
diff options
context:
space:
mode:
authornthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
committernthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
commitc63f340d90800895f007de64b7d2d14624263331 (patch)
tree2c0849fa597dd6da831c8707b6f2603403778d7b /kernel/include/test/kshell/io.h
Created student weenix repository
Diffstat (limited to 'kernel/include/test/kshell/io.h')
-rw-r--r--kernel/include/test/kshell/io.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/kernel/include/test/kshell/io.h b/kernel/include/test/kshell/io.h
new file mode 100644
index 0000000..72ac92a
--- /dev/null
+++ b/kernel/include/test/kshell/io.h
@@ -0,0 +1,61 @@
+#pragma once
+
+#include "test/kshell/kshell.h"
+
+/*
+ * When writing a kernel shell command, make sure to use the following
+ * I/O functions.
+ *
+ * Before VFS is not enabled, the kernel shell will use functions from
+ * chardev.h to get a pointer the the chardev_t struct for the TTY.
+ *
+ * When VFS is enabled, the kernel shell will use the functions from
+ * vfs_syscall.h to open and close the TTY and perform I/O operations
+ * on the TTY.
+ *
+ * If you use the functions below, this process will be completely
+ * transparent.
+ */
+
+/**
+ * Replacement for do_write.
+ *
+ * @param ksh the kshell to write to
+ * @param buf the buffer to write out to the kshell
+ * @param nbytes the maximum number of bytes to write
+ * @return number of bytes written on sucess and <0 on error
+ */
+long kshell_write(kshell_t *ksh, const void *buf, size_t nbytes);
+
+/**
+ * Replacement for do_read.
+ *
+ * @param ksh the kshell to read from
+ * @param buf the buffer to store data read from the kshell
+ * @param nbytes the maximum number of bytes to read
+ * @param number of bytes read on success and <0 on error
+ */
+long kshell_read(kshell_t *ksh, void *buf, size_t nbytes);
+
+/* Unless an error occurs, guarantees that all of buf will be
+ * written */
+/**
+ * Writes a specified number of bytes from a buffer to the
+ * kshell. Unlike kshell_write, this function guarantees it will write
+ * out the desired number of bytes.
+ *
+ * @param ksh the kshell to write to
+ * @param buf the buffer to write out to the kshell
+ * @param nbytes the number of bytes to write
+ * @return number of bytes written on success and <0 on error
+ */
+long kshell_write_all(kshell_t *ksh, void *buf, size_t nbytes);
+
+/* Replacement for printf */
+/**
+ * Write output to a kshell according to a format string.
+ *
+ * @param ksh the kshell to write to
+ * @param fmt the format string
+ */
+void kprintf(kshell_t *ksh, const char *fmt, ...);