From f9050b632eb6c110781f6a78619ea42897cff496 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 21 Dec 2023 21:59:54 +0300 Subject: [PATCH] umount add --- TODO | 1 - build.sh | 3 +- include/libmu/parse_mount.h | 7 ---- src/coreutils/cmp/cmp.c | 2 +- src/coreutils/uname/uname.c | 2 +- .../mount/build.sh | 0 .../mount/mount.c | 10 +---- src/sysutils-linux/umount/build.sh | 2 + src/sysutils-linux/umount/umount.c | 40 +++++++++++++++++++ 9 files changed, 47 insertions(+), 20 deletions(-) rename src/{sysutils => sysutils-linux}/mount/build.sh (100%) rename src/{sysutils => sysutils-linux}/mount/mount.c (93%) create mode 100755 src/sysutils-linux/umount/build.sh create mode 100644 src/sysutils-linux/umount/umount.c diff --git a/TODO b/TODO index b8de7e8..1b4f24e 100644 --- a/TODO +++ b/TODO @@ -22,7 +22,6 @@ tar Other: *mount ps - umount sysctl ping ncat diff --git a/build.sh b/build.sh index ee77652..c7f3f1c 100755 --- a/build.sh +++ b/build.sh @@ -12,7 +12,7 @@ if [ -z $CC ]; then fi if [ -z $projects ]; then - projects="console-tools coreutils sysutils sysutils-linux findutils networking miscutils shell loginutils procps" + projects="console-tools coreutils sysutils-linux findutils networking miscutils shell loginutils procps" fi #Compile @@ -25,6 +25,7 @@ for project in $projects; do for i in $p; do cd $PROJECT_DIR/$i echo " * Compile" $i + chmod -v +x build.sh env CC=$CC CFLAGS="$CFLAGS -I$PROJECT_DIR -I$PROJECT_DIR/include/libmu -lm" OUTPUT="-o $PROJECT_DIR"/bin/$(basename $i) ./build.sh cd $PROJECT_DIR done diff --git a/include/libmu/parse_mount.h b/include/libmu/parse_mount.h index 8cb4158..e68ebf9 100644 --- a/include/libmu/parse_mount.h +++ b/include/libmu/parse_mount.h @@ -9,13 +9,6 @@ typedef struct { unsigned int val; } MU_MOUNT_OPTS; -#if defined(__BSD__) -#define MS_RDONLY MNT_RDONLY -#define MS_REMOUNT 0 -#define MS_SYNCHRONOUS MNT_SYNCHRONOUS -#define MS_NODEV MNT_NODEV -#endif - MU_MOUNT_OPTS mu_options[] = { {"defaults", NULL, NULL, 0}, {"ro", "rw", "Read only / Read and write", MS_RDONLY}, diff --git a/src/coreutils/cmp/cmp.c b/src/coreutils/cmp/cmp.c index 0f58cb8..9af5fe6 100644 --- a/src/coreutils/cmp/cmp.c +++ b/src/coreutils/cmp/cmp.c @@ -19,7 +19,7 @@ int compare(FILE *fp1, FILE *fp2) { if (ch1 != ch2) { if (!s_flag) - printf("files differ at byte %lu\n", byte); + printf("files differ at byte %zu\n", byte); return 1; } diff --git a/src/coreutils/uname/uname.c b/src/coreutils/uname/uname.c index 38d9c1a..3eadcc1 100644 --- a/src/coreutils/uname/uname.c +++ b/src/coreutils/uname/uname.c @@ -8,7 +8,7 @@ #define OS_NAME "Android" #elif defined(__linux__) -#define OS_NAME "linux" +#define OS_NAME "Linux" #elif defined(__OpenBSD__) #define OS_NAME "OpenBSD" diff --git a/src/sysutils/mount/build.sh b/src/sysutils-linux/mount/build.sh similarity index 100% rename from src/sysutils/mount/build.sh rename to src/sysutils-linux/mount/build.sh diff --git a/src/sysutils/mount/mount.c b/src/sysutils-linux/mount/mount.c similarity index 93% rename from src/sysutils/mount/mount.c rename to src/sysutils-linux/mount/mount.c index 474cd6a..944ee78 100644 --- a/src/sysutils/mount/mount.c +++ b/src/sysutils-linux/mount/mount.c @@ -8,15 +8,7 @@ #include "config.h" int do_mount(const char *src, const char *dst, const char *fs_type, unsigned long opt) { -#if defined(__linux__) - int ret = mount(src, dst, fs_type, opt, NULL); - -#else - int ret = -1; - -#endif - - if (ret < 0) { + if (mount(src, dst, fs_type, opt, NULL) < 0) { fprintf(stderr, "mount: %s: %s\n", src, strerror(errno)); return 1; } diff --git a/src/sysutils-linux/umount/build.sh b/src/sysutils-linux/umount/build.sh new file mode 100755 index 0000000..3b2db38 --- /dev/null +++ b/src/sysutils-linux/umount/build.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo ./*.c $CFLAGS $OUTPUT | xargs $CC diff --git a/src/sysutils-linux/umount/umount.c b/src/sysutils-linux/umount/umount.c new file mode 100644 index 0000000..3ebfa9d --- /dev/null +++ b/src/sysutils-linux/umount/umount.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) { + unsigned long flag = 0; + + int opt; + while ((opt = getopt(argc, argv, "fl")) != -1) { + switch (opt) { + case 'f': + flag |= MNT_FORCE; + break; + + case 'l': + flag |= MNT_DETACH; + break; + + default: + printf("umount [dst1 dst2...]\n\t[-f Force umount] [-l Lazy umount]\n"); + return 0; + } + } + + argv += optind; + argc -= optind; + + int ret = 0; + for (int i = 0; i < argc; i++) { + if (umount2(argv[i], flag) < 0) { + fprintf(stderr, "umount: %s: %s\n", argv[i], strerror(errno)); + ret = 1; + } + } + + return ret; +}