From: Karel Zak Date: Mon, 27 Aug 2012 17:26:07 +0000 (+0200) Subject: libmount: remount does not add entry to mtab file X-Git-Tag: v2.22~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c3085df65fe18c9f6077e1903a6ead19a4318d6d;p=thirdparty%2Futil-linux.git libmount: remount does not add entry to mtab file # 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: on IRC Signed-off-by: Karel Zak --- diff --git a/libmount/src/tab_update.c b/libmount/src/tab_update.c index caabd05c20..4f04c8ecd4 100644 --- a/libmount/src/tab_update.c +++ b/libmount/src/tab_update.c @@ -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)