k9core

Unnamed repository
Log | Files | Refs | LICENSE

commit a8ae0f14c05f133da22030def1625a78a2f92473
parent b653b7599a92fff8aac70ef75b8243b402a897ee
Author: qorg11 <qorg@vxempire.xyz>
Date:   Sat, 22 Aug 2020 09:49:46 +0200

moved non coreutils programs to a nonuserland folder since they are
not userland programs

Diffstat:
Asrc/nouserland/mount.c | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/nouserland/umount.c | 28++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/src/nouserland/mount.c b/src/nouserland/mount.c @@ -0,0 +1,45 @@ +#include <stdio.h> +#include <sys/mount.h> +#include <unistd.h> +#include <getopt.h> +#include <errno.h> +#include <string.h> + +/* Do NOT use this unironically for now, this only supports ext4, and + * you cannot specify another filesystem unless you change the source + * code. */ + +/* Update: now this supports filetype with -t flag. But I still don't + * recommend it to mounting something that it's not extx + */ + +int +main(int argc, char *argv[]) { + int c = getopt(argc, argv,"t:"); + if(argc < 2) + { + printf("./mount source destination\n"); + return 1; + } + + if(getuid() != 0) + { + fprintf(stderr,"Only root can run this\n"); + return 1; + } + char filesystem[10] = "ext4"; + int source = 1; + int destination = 2; + if(c == 't') + { + strcpy(filesystem,optarg); + source++; + destination++; + } + int fd = mount(argv[source],argv[destination],filesystem,0,NULL); + if(fd == -1) + { + fprintf(stderr,"error mounting: %i = %s\n",errno,strerror(errno)); + } + return 0; +} diff --git a/src/nouserland/umount.c b/src/nouserland/umount.c @@ -0,0 +1,28 @@ +#include <stdio.h> +#include <sys/mount.h> +#include <errno.h> +#include <getopt.h> +#include <string.h> + +int +main(int argc, char *argv[]) +{ + int c = getopt(argc, argv, "f"); + int options = 0; /* No options by default */ + int destination = 1; + if(c == 'f') + { + options = MNT_FORCE; + destination++; + } + if(argc == 1) + { + printf("give a directory\n"); + return 1; + } + int fd = umount2(argv[destination],options); + if(fd == -1) + { + fprintf(stderr,"error umounting: %i = %s\n",errno,strerror(errno)); + } +}