mount: with -w, do not fall back to read-only mounts

function                                             old     new   delta
mount_it_now                                         364     358      -6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2021-08-23 02:30:13 +02:00
parent 922b58b3e4
commit dbdf9e0ab1

View File

@ -713,10 +713,12 @@ static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filtero
errno = 0; errno = 0;
rc = verbose_mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type, rc = verbose_mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type,
vfsflags, filteropts); vfsflags, filteropts);
if (rc == 0)
goto mtab; // success
// If mount failed, try // mount failed, try helper program
// helper program mount.<mnt_type> // mount.<mnt_type>
if (HELPERS_ALLOWED && rc && mp->mnt_type) { if (HELPERS_ALLOWED && mp->mnt_type) {
char *args[8]; char *args[8];
int errno_save = errno; int errno_save = errno;
args[0] = xasprintf("mount.%s", mp->mnt_type); args[0] = xasprintf("mount.%s", mp->mnt_type);
@ -734,13 +736,19 @@ static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filtero
args[rc] = NULL; args[rc] = NULL;
rc = spawn_and_wait(args); rc = spawn_and_wait(args);
free(args[0]); free(args[0]);
if (!rc) if (rc == 0)
break; goto mtab; // success
errno = errno_save; errno = errno_save;
} }
if (!rc || (vfsflags & MS_RDONLY) || (errno != EACCES && errno != EROFS)) // Should we retry read-only mount?
break; if (vfsflags & MS_RDONLY)
break; // no, already was tried
if (option_mask32 & OPT_w)
break; // no, "mount -w" never falls back to RO
if (errno != EACCES && errno != EROFS)
break; // no, error isn't hinting that RO may work
if (!(vfsflags & MS_SILENT)) if (!(vfsflags & MS_SILENT))
bb_error_msg("%s is write-protected, mounting read-only", bb_error_msg("%s is write-protected, mounting read-only",
mp->mnt_fsname); mp->mnt_fsname);