return NULL;
}
+/*
+ * Checks if source filesystem superblock is already ro-mounted. Note that we
+ * care about FS superblock as VFS node is irrelevant here.
+ */
+static int is_source_already_rdonly(struct libmnt_context *cxt)
+{
+ struct libmnt_fs *fs = get_already_mounted_source(cxt);
+ const char *opts = fs ? mnt_fs_get_fs_options(fs) : NULL;
+
+ return opts && mnt_optstr_get_option(opts, "ro", NULL, NULL) == 0;
+}
+
/**
* mnt_context_finalize_mount:
* @cxt: context
rc = mnt_context_update_tabs(cxt);
/*
- * Read-only device; try mount filesystem read-only
+ * Read-only device or already read-only mounted FS.
+ * Try mount the filesystem read-only.
*/
if ((rc == -EROFS && !mnt_context_syscall_called(cxt)) /* before syscall; rdonly loopdev */
|| mnt_context_get_syscall_errno(cxt) == EROFS /* syscall failed with EROFS */
- || mnt_context_get_syscall_errno(cxt) == EACCES) /* syscall failed with EACCES */
+ || mnt_context_get_syscall_errno(cxt) == EACCES /* syscall failed with EACCES */
+ || (mnt_context_get_syscall_errno(cxt) == EBUSY /* already ro-mounted FS */
+ && is_source_already_rdonly(cxt)))
{
unsigned long mflags = 0;
* Libmount success && syscall success.
*/
if (buf && mnt_context_forced_rdonly(cxt))
- snprintf(buf, bufsz, _("WARNING: device write-protected, mounted read-only"));
+ snprintf(buf, bufsz, _("WARNING: source write-protected, mounted read-only"));
return MNT_EX_SUCCESS;
}
Verbose mode.
.TP
.BR \-w , " \-\-rw" , " \-\-read\-write"
-Mount the filesystem read/write. The read-write is kernel default. A synonym is
+Mount the filesystem read/write. The read-write is kernel default and
+.BR mount (8)
+default is to try read-only if the previous mount syscall with read-write flags
+on write-protected devices of filesystems failed.
+.sp
+A synonym is
.BR "\-o rw" .
-Note that specify \fB\-w\fR on command line forces \fBmount\fR command
-to never try read-only mount on write-protected devices. The default is
-try read-only if the previous mount syscall with read-write flags failed.
+Note that specify \fB\-w\fR on command line forces \fBmount\fR command to never
+try read-only mount on write-protected devices or already mounted read-only
+filesystems.
.TP
.BR \-V , " \-\-version"
Display version information and exit.