From 40705a2a73f9cc00c96db46e2f01384076ac3a55 Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 16 Jun 2026 01:01:39 -0300 Subject: [PATCH] mount: support -f option --- recipes/mount | 2 +- tools/mount/main.c | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/recipes/mount b/recipes/mount index 0a708124..2e68a7ea 100644 --- a/recipes/mount +++ b/recipes/mount @@ -1,5 +1,5 @@ name=mount -revision=1 +revision=2 from_source=mount imagedeps="build-essential" hostdeps="xbinutils xgcc" diff --git a/tools/mount/main.c b/tools/mount/main.c index 98c7de1d..1c9c997c 100644 --- a/tools/mount/main.c +++ b/tools/mount/main.c @@ -14,9 +14,10 @@ struct mtab_list { static const char *argv0; static struct mtab_list *mtab_list; +static bool force = false; void usage(void) { - fprintf(stderr, "%s: usage: %s [-a] [-d device] [-t filesystem] [mountpoint]\n", argv0, argv0); + fprintf(stderr, "%s: usage: %s [-a] [-f] [-d device] [-t filesystem] [mountpoint]\n", argv0, argv0); exit(EXIT_FAILURE); } @@ -25,15 +26,17 @@ static int mount_filesystem(char *device, char *path, char *filesystem, unsigned device = NULL; // check if device already mounted - for (struct mtab_list *it = mtab_list; it; it = it->next) { - if (strcmp(path, it->mntent.mnt_dir) == 0 && strcmp(filesystem, it->mntent.mnt_type) == 0 && strcmp(it->mntent.mnt_fsname, "none") == 0) { - fprintf(stderr, "%s: virtual filesystem %s already mounted at %s\n", argv0, filesystem, path); - return EXIT_SUCCESS; - } + if (!force) { + for (struct mtab_list *it = mtab_list; it; it = it->next) { + if (strcmp(path, it->mntent.mnt_dir) == 0 && strcmp(filesystem, it->mntent.mnt_type) == 0 && strcmp(it->mntent.mnt_fsname, "none") == 0) { + fprintf(stderr, "%s: virtual filesystem %s already mounted at %s\n", argv0, filesystem, path); + return EXIT_SUCCESS; + } - if (device && strcmp(device, it->mntent.mnt_fsname) == 0 && strcmp(it->mntent.mnt_fsname, "none")) { - fprintf(stderr, "%s: %s already mounted at %s\n", argv0, device, path); - return EXIT_SUCCESS; + if (device && strcmp(device, it->mntent.mnt_fsname) == 0 && strcmp(it->mntent.mnt_fsname, "none")) { + fprintf(stderr, "%s: %s already mounted at %s\n", argv0, device, path); + return EXIT_SUCCESS; + } } } @@ -50,7 +53,6 @@ static int mount_filesystem(char *device, char *path, char *filesystem, unsigned if (entry == NULL) return EXIT_FAILURE; - entry->mntent.mnt_fsname = device ? strdup(device) : "none"; entry->mntent.mnt_dir = strdup(path); entry->mntent.mnt_type = strdup(filesystem); @@ -247,6 +249,12 @@ int main(int argc, char *argv[]) { if (strcmp(argv[i], "-a") == 0) { all = true; + continue; + } + + if (strcmp(argv[i], "-f") == 0) { + force = true; + continue; } if (devnext) {