return res;
}
+/*
+ * Returns mountinfo FS entry of context source patch if the source is already
+ * mounted. This function is used for "already mounted" message or to get FS of
+ * re-used loop device.
+ */
+static struct libmnt_fs *get_already_mounted_source(struct libmnt_context *cxt)
+{
+ const char *src;
+ struct libmnt_table *tb;
+
+ assert(cxt);
+
+ src = mnt_fs_get_srcpath(cxt->fs);
+
+ if (src && mnt_context_get_mtab(cxt, &tb) == 0) {
+ struct libmnt_iter itr;
+ struct libmnt_fs *fs;
+
+ mnt_reset_iter(&itr, MNT_ITER_FORWARD);
+ while (mnt_table_next_fs(tb, &itr, &fs) == 0) {
+ const char *s = mnt_fs_get_srcpath(fs),
+ *t = mnt_fs_get_target(fs);
+
+ if (t && s && mnt_fs_streq_srcpath(fs, src))
+ return fs;
+ }
+ }
+ return NULL;
+}
+
/**
* mnt_context_finalize_mount:
* @cxt: context
break;
case EBUSY:
- {
- struct libmnt_table *tb;
-
if (!buf)
break;
if (mflags & MS_REMOUNT) {
snprintf(buf, bufsz, _("mount point is busy"));
break;
}
- if (src && mnt_context_get_mtab(cxt, &tb) == 0) {
- struct libmnt_iter itr;
- struct libmnt_fs *fs;
-
- mnt_reset_iter(&itr, MNT_ITER_FORWARD);
- while (mnt_table_next_fs(tb, &itr, &fs) == 0) {
- const char *s = mnt_fs_get_srcpath(fs),
- *t = mnt_fs_get_target(fs);
-
- if (t && s && mnt_fs_streq_srcpath(fs, src)) {
- snprintf(buf, bufsz, _("%s already mounted on %s"), s, t);
- break;
- }
- }
+ if (src) {
+ struct libmnt_fs *fs = get_already_mounted_source(cxt);
+
+ if (fs && mnt_fs_get_target(fs))
+ snprintf(buf, bufsz, _("%s already mounted on %s"),
+ src, mnt_fs_get_target(fs));
}
if (!*buf)
snprintf(buf, bufsz, _("%s already mounted or mount point busy"), src);
break;
- }
case ENOENT:
if (tgt && lstat(tgt, &st)) {
if (buf)