From: Michael Tremer Date: Mon, 12 Dec 2022 18:06:26 +0000 (+0000) Subject: mount: Fix bind-mounting read-only shares X-Git-Tag: 0.9.29~424 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=976fbbc8f15bd9a18f6ddc0e05e4619244208eed;p=pakfire.git mount: Fix bind-mounting read-only shares Fixes: #12968 Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/mount.c b/src/libpakfire/mount.c index c00bc658f..72ba4ac57 100644 --- a/src/libpakfire/mount.c +++ b/src/libpakfire/mount.c @@ -421,6 +421,18 @@ int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int return 1; } + // The Linux kernel seems to be quite funny when trying to bind-mount something + // as read-only and requires us to mount the source first, and then remount it + // again using MS_RDONLY. + if (flags & MS_RDONLY) { + r = pakfire_mount(pakfire, src, mountpoint, NULL, MS_BIND|MS_REC, NULL); + if (r) + return r; + + // Add the remount flag + flags |= MS_REMOUNT; + } + // Perform mount - return pakfire_mount(pakfire, src, mountpoint, NULL, flags|MS_REC|MS_BIND, NULL); + return pakfire_mount(pakfire, src, mountpoint, NULL, flags|MS_BIND|MS_REC, NULL); }