]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: remount does not add entry to mtab file
authorKarel Zak <kzak@redhat.com>
Mon, 27 Aug 2012 17:26:07 +0000 (19:26 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 27 Aug 2012 17:26:07 +0000 (19:26 +0200)
 # mount -n -o ro /dev/sda1 /
 # mount -o remount,rw /dev/sda1 /

For the backward compatibility the command mount(8) should to add a
new entry to the file /etc/mtab on remount if the original entry not
found (because previous mount has been called with -n).

Reported-by: <frinnst> on IRC
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/tab_update.c

index caabd05c201f8ef6b010ef58cf5a04fccaecaa91..4f04c8ecd4cd9ab7f2622035a05ee1cab0e10fcd 100644 (file)
@@ -562,6 +562,17 @@ leave:
        return rc;
 }
 
+static int add_file_entry(struct libmnt_table *tb, struct libmnt_update *upd)
+{
+       struct libmnt_fs *fs = mnt_copy_fs(NULL, upd->fs);
+
+       if (!fs)
+               return -ENOMEM;
+
+       mnt_table_add_fs(tb, fs);
+       return update_table(upd, tb);
+}
+
 static int update_add_entry(struct libmnt_update *upd, struct libmnt_lock *lc)
 {
        struct libmnt_table *tb;
@@ -579,16 +590,8 @@ static int update_add_entry(struct libmnt_update *upd, struct libmnt_lock *lc)
 
        tb = __mnt_new_table_from_file(upd->filename,
                        upd->userspace_only ? MNT_FMT_UTAB : MNT_FMT_MTAB);
-       if (tb) {
-               struct libmnt_fs *fs = mnt_copy_fs(NULL, upd->fs);
-               if (!fs)
-                       rc = -ENOMEM;
-               else {
-                       mnt_table_add_fs(tb, fs);
-                       rc = update_table(upd, tb);
-               }
-       }
-
+       if (tb)
+               rc = add_file_entry(tb, upd);
        if (lc)
                mnt_unlock_file(lc);
 
@@ -621,7 +624,6 @@ static int update_remove_entry(struct libmnt_update *upd, struct libmnt_lock *lc
                        mnt_free_fs(rem);
                }
        }
-
        if (lc)
                mnt_unlock_file(lc);
 
@@ -691,7 +693,8 @@ static int update_modify_options(struct libmnt_update *upd, struct libmnt_lock *
                                rc = mnt_fs_set_options(cur, mnt_fs_get_options(fs));
                        if (!rc)
                                rc = update_table(upd, tb);
-               }
+               } else
+                       rc = add_file_entry(tb, upd);   /* not found, add new */
        }
 
        if (lc)