diff options
author | Roman Borisov <ext-roman.borisov@nokia.com> | 2011-02-28 05:06:01 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-02-28 05:06:01 +0100 |
commit | c8dc01dc8030a697cd3ee47da6381066d3142265 (patch) | |
tree | 970b139c7e39d29725b440efe39382a97c0b2a85 /util-linux | |
parent | 251962f20737c5138c7d33e90c68dfca856361e1 (diff) | |
download | busybox-w32-c8dc01dc8030a697cd3ee47da6381066d3142265.tar.gz busybox-w32-c8dc01dc8030a697cd3ee47da6381066d3142265.tar.bz2 busybox-w32-c8dc01dc8030a697cd3ee47da6381066d3142265.zip |
mount: update /etc/mtab properly on mount --move
Signed-off-by: Roman Borisov <ext-roman.borisov@nokia.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/mount.c | 76 |
1 files changed, 67 insertions, 9 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index 0baa74c7c..0127f1958 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -279,6 +279,61 @@ enum { GETMNTENT_BUFSIZE = COMMON_BUFSIZE - offsetof(struct globals, getmntent_b | |||
279 | #define fslist (G.fslist ) | 279 | #define fslist (G.fslist ) |
280 | #define getmntent_buf (G.getmntent_buf ) | 280 | #define getmntent_buf (G.getmntent_buf ) |
281 | 281 | ||
282 | #if ENABLE_FEATURE_MTAB_SUPPORT | ||
283 | /* | ||
284 | * update_mtab_entry_on_move() is used to update entry in case of mount --move. | ||
285 | * we are looking for existing entries mnt_dir which is equal to mnt_fsname of | ||
286 | * input mntent and replace it by new one. | ||
287 | */ | ||
288 | static void FAST_FUNC update_mtab_entry_on_move(const struct mntent *mp) | ||
289 | { | ||
290 | struct mntent *entries, *m; | ||
291 | int i, count; | ||
292 | FILE *mountTable; | ||
293 | |||
294 | mountTable = setmntent(bb_path_mtab_file, "r"); | ||
295 | if (!mountTable) { | ||
296 | bb_perror_msg(bb_path_mtab_file); | ||
297 | return; | ||
298 | } | ||
299 | |||
300 | entries = NULL; | ||
301 | count = 0; | ||
302 | while ((m = getmntent(mountTable)) != NULL) { | ||
303 | entries = xrealloc_vector(entries, 3, count); | ||
304 | entries[count].mnt_fsname = xstrdup(m->mnt_fsname); | ||
305 | entries[count].mnt_dir = xstrdup(m->mnt_dir); | ||
306 | entries[count].mnt_type = xstrdup(m->mnt_type); | ||
307 | entries[count].mnt_opts = xstrdup(m->mnt_opts); | ||
308 | entries[count].mnt_freq = m->mnt_freq; | ||
309 | entries[count].mnt_passno = m->mnt_passno; | ||
310 | count++; | ||
311 | } | ||
312 | endmntent(mountTable); | ||
313 | |||
314 | mountTable = setmntent(bb_path_mtab_file, "w"); | ||
315 | if (mountTable) { | ||
316 | for (i = 0; i < count; i++) { | ||
317 | if (strcmp(entries[i].mnt_dir, mp->mnt_fsname) != 0) | ||
318 | addmntent(mountTable, &entries[i]); | ||
319 | else | ||
320 | addmntent(mountTable, mp); | ||
321 | } | ||
322 | endmntent(mountTable); | ||
323 | } else if (errno != EROFS) | ||
324 | bb_perror_msg(bb_path_mtab_file); | ||
325 | |||
326 | if (ENABLE_FEATURE_CLEAN_UP) { | ||
327 | for (i = 0; i < count; i++) { | ||
328 | free(entries[i].mnt_fsname); | ||
329 | free(entries[i].mnt_dir); | ||
330 | free(entries[i].mnt_type); | ||
331 | free(entries[i].mnt_opts); | ||
332 | } | ||
333 | free(entries); | ||
334 | } | ||
335 | } | ||
336 | #endif | ||
282 | 337 | ||
283 | #if ENABLE_FEATURE_MOUNT_VERBOSE | 338 | #if ENABLE_FEATURE_MOUNT_VERBOSE |
284 | static int verbose_mount(const char *source, const char *target, | 339 | static int verbose_mount(const char *source, const char *target, |
@@ -496,12 +551,11 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts) | |||
496 | int i; | 551 | int i; |
497 | 552 | ||
498 | if (!mountTable) { | 553 | if (!mountTable) { |
499 | bb_error_msg("no %s", bb_path_mtab_file); | 554 | bb_perror_msg(bb_path_mtab_file); |
500 | goto ret; | 555 | goto ret; |
501 | } | 556 | } |
502 | 557 | ||
503 | // Add vfs string flags | 558 | // Add vfs string flags |
504 | |||
505 | for (i = 0; mount_options[i] != MS_REMOUNT; i++) { | 559 | for (i = 0; mount_options[i] != MS_REMOUNT; i++) { |
506 | if (mount_options[i] > 0 && (mount_options[i] & vfsflags)) | 560 | if (mount_options[i] > 0 && (mount_options[i] & vfsflags)) |
507 | append_mount_options(&(mp->mnt_opts), option_str); | 561 | append_mount_options(&(mp->mnt_opts), option_str); |
@@ -509,24 +563,28 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts) | |||
509 | } | 563 | } |
510 | 564 | ||
511 | // Remove trailing / (if any) from directory we mounted on | 565 | // Remove trailing / (if any) from directory we mounted on |
512 | |||
513 | i = strlen(mp->mnt_dir) - 1; | 566 | i = strlen(mp->mnt_dir) - 1; |
514 | if (i > 0 && mp->mnt_dir[i] == '/') mp->mnt_dir[i] = '\0'; | 567 | while (i > 0 && mp->mnt_dir[i] == '/') |
568 | mp->mnt_dir[i] = '\0'; | ||
515 | 569 | ||
516 | // Convert to canonical pathnames as needed | 570 | // Convert to canonical pathnames as needed |
517 | |||
518 | mp->mnt_dir = bb_simplify_path(mp->mnt_dir); | 571 | mp->mnt_dir = bb_simplify_path(mp->mnt_dir); |
519 | fsname = 0; | 572 | fsname = NULL; |
520 | if (!mp->mnt_type || !*mp->mnt_type) { // bind mount | 573 | if (!mp->mnt_type || !*mp->mnt_type) { // bind mount |
521 | mp->mnt_fsname = fsname = bb_simplify_path(mp->mnt_fsname); | 574 | mp->mnt_fsname = fsname = bb_simplify_path(mp->mnt_fsname); |
522 | mp->mnt_type = (char*)"bind"; | 575 | mp->mnt_type = (char*)"bind"; |
523 | } | 576 | } |
524 | mp->mnt_freq = mp->mnt_passno = 0; | 577 | mp->mnt_freq = mp->mnt_passno = 0; |
525 | 578 | ||
526 | // Write and close. | 579 | // Write and close |
527 | 580 | #if ENABLE_FEATURE_MTAB_SUPPORT | |
528 | addmntent(mountTable, mp); | 581 | if (vfsflags & MS_MOVE) |
582 | update_mtab_entry_on_move(mp); | ||
583 | else | ||
584 | #endif | ||
585 | addmntent(mountTable, mp); | ||
529 | endmntent(mountTable); | 586 | endmntent(mountTable); |
587 | |||
530 | if (ENABLE_FEATURE_CLEAN_UP) { | 588 | if (ENABLE_FEATURE_CLEAN_UP) { |
531 | free(mp->mnt_dir); | 589 | free(mp->mnt_dir); |
532 | free(fsname); | 590 | free(fsname); |