[PATCH v2] mount: mount--move with mtab support fix
Roman Borisov
ext-roman.borisov at nokia.com
Tue Feb 22 11:51:26 UTC 2011
added new update_mtab_entry() function to update /etc/mtab when new mounted
entry is created by mount--move. In such case update_mtab_entry() is used in
mount.c/mount_it_now() function instead of addmntent().
fixes: http://lists.busybox.net/pipermail/busybox/2011-January/074510.html
v2: added #if ENABLE_FEATURE_MTAB_SUPPORT in functions declarations;
added ENABLE_FEATURE_CLEAN_UP condition check for cleaning
Signed-off-by: Roman Borisov <ext-roman.borisov at nokia.com>
---
include/libbb.h | 3 ++
libbb/mtab.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
util-linux/mount.c | 6 +++-
3 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/include/libbb.h b/include/libbb.h
index 587a5f9..7cbe0a1 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1099,7 +1099,10 @@ extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC;
extern int match_fstype(const struct mntent *mt, const char *fstypes) FAST_FUNC;
extern struct mntent *find_mount_point(const char *name, int subdir_too) FAST_FUNC;
#endif
+#if ENABLE_FEATURE_MTAB_SUPPORT
extern void erase_mtab(const char * name) FAST_FUNC;
+extern void update_mtab_entry(const struct mntent *mp) FAST_FUNC;
+#endif
extern unsigned int tty_baud_to_value(speed_t speed) FAST_FUNC;
extern speed_t tty_value_to_baud(unsigned int value) FAST_FUNC;
#if ENABLE_DESKTOP
diff --git a/libbb/mtab.c b/libbb/mtab.c
index 22bff64..3af9379 100644
--- a/libbb/mtab.c
+++ b/libbb/mtab.c
@@ -52,4 +52,58 @@ void FAST_FUNC erase_mtab(const char *name)
} else if (errno != EROFS)
bb_perror_msg(bb_path_mtab_file);
}
+
+/*
+update_mtab_entry() is used to update entry in case of mount--move.
+we are looking for existing entries mnt_dir which is equal to mnt_fsname of
+input mntent and replace it by new one.
+*/
+void FAST_FUNC update_mtab_entry(const struct mntent *mp)
+{
+ struct mntent *entries, *m;
+ int i, count;
+ FILE *mountTable;
+
+ mountTable = setmntent(bb_path_mtab_file, "r");
+ if (!mountTable) {
+ bb_perror_msg(bb_path_mtab_file);
+ return;
+ }
+
+ entries = NULL;
+ count = 0;
+ while ((m = getmntent(mountTable)) != 0) {
+ entries = xrealloc_vector(entries, 3, count);
+ entries[count].mnt_fsname = xstrdup(m->mnt_fsname);
+ entries[count].mnt_dir = xstrdup(m->mnt_dir);
+ entries[count].mnt_type = xstrdup(m->mnt_type);
+ entries[count].mnt_opts = xstrdup(m->mnt_opts);
+ entries[count].mnt_freq = m->mnt_freq;
+ entries[count].mnt_passno = m->mnt_passno;
+ count++;
+ }
+ endmntent(mountTable);
+
+ mountTable = setmntent(bb_path_mtab_file, "w");
+ if (mountTable) {
+ for (i = 0; i < count; i++) {
+ if (strcmp(entries[i].mnt_dir, mp->mnt_fsname) != 0)
+ addmntent(mountTable, &entries[i]);
+ else
+ addmntent(mountTable, mp);
+ }
+ endmntent(mountTable);
+ } else if (errno != EROFS)
+ bb_perror_msg(bb_path_mtab_file);
+
+ if (ENABLE_FEATURE_CLEAN_UP) {
+ for (i = 0; i < count; i++) {
+ free(entries[i].mnt_fsname);
+ free(entries[i].mnt_dir);
+ free(entries[i].mnt_type);
+ free(entries[i].mnt_opts);
+ }
+ }
+}
#endif
+
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 0f213bb..c0c828b 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -524,8 +524,10 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts)
mp->mnt_freq = mp->mnt_passno = 0;
// Write and close.
-
- addmntent(mountTable, mp);
+ if (vfsflags & MS_MOVE)
+ update_mtab_entry(mp);
+ else
+ addmntent(mountTable, mp);
endmntent(mountTable);
if (ENABLE_FEATURE_CLEAN_UP) {
free(mp->mnt_dir);
--
1.7.0.4
More information about the busybox
mailing list