From 545c5f85c38de8ddb8c026bf3b76658c8d8f3d6b Mon Sep 17 00:00:00 2001 From: WlodekM Date: Sat, 15 Feb 2025 10:51:57 +0200 Subject: fix some stuff; add some coreutils --- buildkernel.sh | 2 +- progs/hello/hello.c | 8 ++++++++ progs/mkdir/mkdir.c | 17 +++++++++++++++++ progs/mount/mount.c | 25 +++++++++++++++++++++++++ progs/tty/tty.c | 10 ++++++++++ sbin/fdmaker/fdmaker.c | 2 +- sbin/init/init.c | 1 + 7 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 progs/hello/hello.c create mode 100644 progs/mkdir/mkdir.c create mode 100644 progs/mount/mount.c create mode 100644 progs/tty/tty.c diff --git a/buildkernel.sh b/buildkernel.sh index f0f397e..09ceead 100755 --- a/buildkernel.sh +++ b/buildkernel.sh @@ -4,6 +4,6 @@ INITPATH=$PWD/init.cpio cd init find . | cpio -o -H newc > ../init.cpio cd ../kernel -make isoimage FDARGS="initrd=/init.cpio" FDINITRD=$INITPATH -j 4 +make isoimage FDARGS="initrd=/init.cpio" FDINITRD=$INITPATH -j 6 qemu-system-x86_64 -cdrom ./arch/x86/boot/image.iso #-s -S cd .. \ No newline at end of file diff --git a/progs/hello/hello.c b/progs/hello/hello.c new file mode 100644 index 0000000..e11e06e --- /dev/null +++ b/progs/hello/hello.c @@ -0,0 +1,8 @@ +#include +#include + +__attribute__((force_align_arg_pointer)) +int main() { + write(1, ":3\n", 3); + exit(0); +} \ No newline at end of file diff --git a/progs/mkdir/mkdir.c b/progs/mkdir/mkdir.c new file mode 100644 index 0000000..cbf5cdf --- /dev/null +++ b/progs/mkdir/mkdir.c @@ -0,0 +1,17 @@ +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + if (!argv[1]) { + write(1, "you IDIOT, you forgot to include the file name, MORON\n", 55); + exit(1); + } + struct stat st = {0}; + + if (stat(argv[1], &st) == -1) { + mkdir(argv[1], 0700); + } + exit(0); +} \ No newline at end of file diff --git a/progs/mount/mount.c b/progs/mount/mount.c new file mode 100644 index 0000000..296dd42 --- /dev/null +++ b/progs/mount/mount.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + if (argc != 4) { + fprintf(stderr, "usag: %s \n", argv[0]); + return EXIT_FAILURE; + } + + const char *source = argv[1]; + const char *target = argv[2]; + const char *fstype = argv[3]; + + if (mount(source, target, fstype, 0, NULL) == -1) { + fprintf(stderr, "mount failed: %s\n", strerror(errno)); + return EXIT_FAILURE; + } + + printf("Mounted %s on %s with type %s\n", source, target, fstype); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/progs/tty/tty.c b/progs/tty/tty.c new file mode 100644 index 0000000..d906121 --- /dev/null +++ b/progs/tty/tty.c @@ -0,0 +1,10 @@ +#include +#include + +__attribute__((force_align_arg_pointer)) +int main() { + char *tty = ttyname(1); + write(1, tty, sizeof(tty)); + write(1, "\n", 1); + exit(0); +} \ No newline at end of file diff --git a/sbin/fdmaker/fdmaker.c b/sbin/fdmaker/fdmaker.c index 6dcc299..7591147 100644 --- a/sbin/fdmaker/fdmaker.c +++ b/sbin/fdmaker/fdmaker.c @@ -16,7 +16,7 @@ int main() { // >open /dev/tty1 // >look inside - // >bits + // >Failed to open /dev/tty1 int fd = open("/dev/tty1", O_RDWR); if (fd == -1) { write(2, "Failed to open /dev/tty1\n", 26); diff --git a/sbin/init/init.c b/sbin/init/init.c index 0e8f6cf..56df6a6 100644 --- a/sbin/init/init.c +++ b/sbin/init/init.c @@ -11,6 +11,7 @@ int main() { // } else { // execve("/sbin/", 0, 0) // } + // make tty1 execve("/sbin/fdmaker", 0, 0); } else { -- cgit 1.4.1-2-gfad0