diff options
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/Makefile | 1 | ||||
-rw-r--r-- | usr.bin/fetch/Makefile | 6 | ||||
-rw-r--r-- | usr.bin/fetch/fetch.c | 58 | ||||
-rw-r--r-- | usr.bin/kmsg/Makefile | 6 | ||||
-rw-r--r-- | usr.bin/kmsg/kmsg.c | 62 | ||||
-rw-r--r-- | usr.bin/osh/osh.c | 31 |
6 files changed, 158 insertions, 6 deletions
diff --git a/usr.bin/Makefile b/usr.bin/Makefile index 1c973ff..09d593d 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -6,3 +6,4 @@ ARGS = -I$(ROOT)/builddeps LDSCRIPT=$(LDSCRIPT) USRDIR=$(USRDIR) ROOT=$(ROOT) .PHONY: all all: make -C osh/ $(ARGS) + make -C kmsg/ $(ARGS) diff --git a/usr.bin/fetch/Makefile b/usr.bin/fetch/Makefile new file mode 100644 index 0000000..4b08e84 --- /dev/null +++ b/usr.bin/fetch/Makefile @@ -0,0 +1,6 @@ +include user.mk + +CFILES = $(shell find . -name "*.c") + +$(ROOT)/base/usr/bin/fetch: + gcc $(CFILES) -o $@ $(INTERNAL_CFLAGS) diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c new file mode 100644 index 0000000..98b2d3c --- /dev/null +++ b/usr.bin/fetch/fetch.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <unistd.h> +#include <fcntl.h> +#include <string.h> + +#define prcons(FD, STR) write((FD), (STR), strlen((STR))) + +#define ASCII_ART \ + " ____ \n" \ + " | \\__\\ \n" \ + " | /\\ \\ user: root\n" \ + " |/ \\ \\ OS: Hyra/amd64 v"_OSVER"\n" \ + " \\ R. \\ \\ arch: "_OSARCH"\n" \ + " \\ I. \\ \\\n" + + +int +main(void) +{ + int fd; + + fd = open("/dev/console", O_WRONLY); + if (fd < 0) { + return fd; + } + + prcons(fd, ASCII_ART); + close(fd); + return 0; +} diff --git a/usr.bin/kmsg/Makefile b/usr.bin/kmsg/Makefile new file mode 100644 index 0000000..9b76cc2 --- /dev/null +++ b/usr.bin/kmsg/Makefile @@ -0,0 +1,6 @@ +include user.mk + +CFILES = $(shell find . -name "*.c") + +$(ROOT)/base/usr/bin/kmsg: + gcc $(CFILES) -o $@ $(INTERNAL_CFLAGS) diff --git a/usr.bin/kmsg/kmsg.c b/usr.bin/kmsg/kmsg.c new file mode 100644 index 0000000..678ad8c --- /dev/null +++ b/usr.bin/kmsg/kmsg.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> + +int +main(void) +{ + int mfd, cons_fd; + ssize_t retval; + char linebuf[256]; + + if ((mfd = open("/dev/kmsg", O_RDONLY)) < 0) { + return mfd; + } + if ((cons_fd = open("/dev/console", O_WRONLY)) < 0) { + close(mfd); + return cons_fd; + } + + for (;;) { + retval = read(mfd, linebuf, sizeof(linebuf) - 1); + if (retval <= 0) { + break; + } + linebuf[retval] = '\0'; + write(cons_fd, linebuf, strlen(linebuf)); + } + + close(cons_fd); + close(mfd); + return 0; +} diff --git a/usr.bin/osh/osh.c b/usr.bin/osh/osh.c index c45d9c8..583f29a 100644 --- a/usr.bin/osh/osh.c +++ b/usr.bin/osh/osh.c @@ -30,6 +30,7 @@ #include <sys/types.h> #include <sys/cdefs.h> #include <sys/reboot.h> +#include <sys/spawn.h> #include <fcntl.h> #include <stddef.h> #include <unistd.h> @@ -49,6 +50,8 @@ "echo - Print the arguments to the console\n" \ "reboot - Reboot the machine\n" \ "shutdown - Power off the machine\n" \ + "kmsg - Print kernel message buffer\n" \ + "fetch - System information\n" \ "exit - Exit the shell\n" #define PROMPT "[root::osmora]~ " @@ -59,6 +62,7 @@ static int running; struct command { const char *name; + const char *path; void (*func)(int fd, int argc, char *argv[]); }; @@ -165,12 +169,27 @@ getstr(int fd) } } +static void +command_run(struct command *cmd, int fd, int argc, char *argv[]) +{ + if (cmd->func != NULL) { + cmd->func(fd, argc, argv); + return; + } + + if (cmd->path != NULL) { + spawn(cmd->path, SPAWN_WAIT); + } +} + struct command cmds[] = { - {"help", cmd_help}, - {"echo", cmd_echo}, - {"exit", cmd_exit}, - {"reboot", cmd_reboot}, - {"shutdown", cmd_shutdown}, + {"help", NULL, cmd_help}, + {"echo", NULL, cmd_echo}, + {"exit", NULL, cmd_exit}, + {"reboot", NULL, cmd_reboot}, + {"shutdown", NULL, cmd_shutdown}, + {"kmsg", "/usr/bin/kmsg", NULL}, + {"fetch", "/usr/bin/fetch", NULL}, {NULL, NULL} }; @@ -205,7 +224,7 @@ main(void) for (i = 0; cmds[i].name != NULL; i++) { if (strcmp(input, cmds[i].name) == 0) { - cmds[i].func(fd, argc, argv); + command_run(&cmds[i], fd, argc, argv); found = 1; break; } |