aboutsummaryrefslogtreecommitdiff
path: root/util-linux/mount.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/mount.c')
-rw-r--r--util-linux/mount.c80
1 files changed, 70 insertions, 10 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c
index 0baa74c7c..722d0be92 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -181,6 +181,7 @@ static const int32_t mount_options[] = {
181 /* "relatime" */ MS_RELATIME, 181 /* "relatime" */ MS_RELATIME,
182 /* "norelatime" */ ~MS_RELATIME, 182 /* "norelatime" */ ~MS_RELATIME,
183 /* "loud" */ ~MS_SILENT, 183 /* "loud" */ ~MS_SILENT,
184 /* "rbind" */ MS_BIND|MS_RECURSIVE,
184 185
185 // action flags 186 // action flags
186 /* "union" */ MS_UNION, 187 /* "union" */ MS_UNION,
@@ -192,7 +193,7 @@ static const int32_t mount_options[] = {
192 /* "unbindable" */ MS_UNBINDABLE, 193 /* "unbindable" */ MS_UNBINDABLE,
193 /* "rshared" */ MS_SHARED|MS_RECURSIVE, 194 /* "rshared" */ MS_SHARED|MS_RECURSIVE,
194 /* "rslave" */ MS_SLAVE|MS_RECURSIVE, 195 /* "rslave" */ MS_SLAVE|MS_RECURSIVE,
195 /* "rprivate" */ MS_SLAVE|MS_RECURSIVE, 196 /* "rprivate" */ MS_PRIVATE|MS_RECURSIVE,
196 /* "runbindable" */ MS_UNBINDABLE|MS_RECURSIVE, 197 /* "runbindable" */ MS_UNBINDABLE|MS_RECURSIVE,
197 ) 198 )
198 199
@@ -236,6 +237,7 @@ static const char mount_option_str[] =
236 "relatime\0" 237 "relatime\0"
237 "norelatime\0" 238 "norelatime\0"
238 "loud\0" 239 "loud\0"
240 "rbind\0"
239 241
240 // action flags 242 // action flags
241 "union\0" 243 "union\0"
@@ -279,6 +281,61 @@ enum { GETMNTENT_BUFSIZE = COMMON_BUFSIZE - offsetof(struct globals, getmntent_b
279#define fslist (G.fslist ) 281#define fslist (G.fslist )
280#define getmntent_buf (G.getmntent_buf ) 282#define getmntent_buf (G.getmntent_buf )
281 283
284#if ENABLE_FEATURE_MTAB_SUPPORT
285/*
286 * update_mtab_entry_on_move() is used to update entry in case of mount --move.
287 * we are looking for existing entries mnt_dir which is equal to mnt_fsname of
288 * input mntent and replace it by new one.
289 */
290static void FAST_FUNC update_mtab_entry_on_move(const struct mntent *mp)
291{
292 struct mntent *entries, *m;
293 int i, count;
294 FILE *mountTable;
295
296 mountTable = setmntent(bb_path_mtab_file, "r");
297 if (!mountTable) {
298 bb_perror_msg(bb_path_mtab_file);
299 return;
300 }
301
302 entries = NULL;
303 count = 0;
304 while ((m = getmntent(mountTable)) != NULL) {
305 entries = xrealloc_vector(entries, 3, count);
306 entries[count].mnt_fsname = xstrdup(m->mnt_fsname);
307 entries[count].mnt_dir = xstrdup(m->mnt_dir);
308 entries[count].mnt_type = xstrdup(m->mnt_type);
309 entries[count].mnt_opts = xstrdup(m->mnt_opts);
310 entries[count].mnt_freq = m->mnt_freq;
311 entries[count].mnt_passno = m->mnt_passno;
312 count++;
313 }
314 endmntent(mountTable);
315
316 mountTable = setmntent(bb_path_mtab_file, "w");
317 if (mountTable) {
318 for (i = 0; i < count; i++) {
319 if (strcmp(entries[i].mnt_dir, mp->mnt_fsname) != 0)
320 addmntent(mountTable, &entries[i]);
321 else
322 addmntent(mountTable, mp);
323 }
324 endmntent(mountTable);
325 } else if (errno != EROFS)
326 bb_perror_msg(bb_path_mtab_file);
327
328 if (ENABLE_FEATURE_CLEAN_UP) {
329 for (i = 0; i < count; i++) {
330 free(entries[i].mnt_fsname);
331 free(entries[i].mnt_dir);
332 free(entries[i].mnt_type);
333 free(entries[i].mnt_opts);
334 }
335 free(entries);
336 }
337}
338#endif
282 339
283#if ENABLE_FEATURE_MOUNT_VERBOSE 340#if ENABLE_FEATURE_MOUNT_VERBOSE
284static int verbose_mount(const char *source, const char *target, 341static int verbose_mount(const char *source, const char *target,
@@ -496,12 +553,11 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts)
496 int i; 553 int i;
497 554
498 if (!mountTable) { 555 if (!mountTable) {
499 bb_error_msg("no %s", bb_path_mtab_file); 556 bb_perror_msg(bb_path_mtab_file);
500 goto ret; 557 goto ret;
501 } 558 }
502 559
503 // Add vfs string flags 560 // Add vfs string flags
504
505 for (i = 0; mount_options[i] != MS_REMOUNT; i++) { 561 for (i = 0; mount_options[i] != MS_REMOUNT; i++) {
506 if (mount_options[i] > 0 && (mount_options[i] & vfsflags)) 562 if (mount_options[i] > 0 && (mount_options[i] & vfsflags))
507 append_mount_options(&(mp->mnt_opts), option_str); 563 append_mount_options(&(mp->mnt_opts), option_str);
@@ -509,24 +565,28 @@ static int mount_it_now(struct mntent *mp, long vfsflags, char *filteropts)
509 } 565 }
510 566
511 // Remove trailing / (if any) from directory we mounted on 567 // Remove trailing / (if any) from directory we mounted on
512
513 i = strlen(mp->mnt_dir) - 1; 568 i = strlen(mp->mnt_dir) - 1;
514 if (i > 0 && mp->mnt_dir[i] == '/') mp->mnt_dir[i] = '\0'; 569 while (i > 0 && mp->mnt_dir[i] == '/')
570 mp->mnt_dir[i--] = '\0';
515 571
516 // Convert to canonical pathnames as needed 572 // Convert to canonical pathnames as needed
517
518 mp->mnt_dir = bb_simplify_path(mp->mnt_dir); 573 mp->mnt_dir = bb_simplify_path(mp->mnt_dir);
519 fsname = 0; 574 fsname = NULL;
520 if (!mp->mnt_type || !*mp->mnt_type) { // bind mount 575 if (!mp->mnt_type || !*mp->mnt_type) { // bind mount
521 mp->mnt_fsname = fsname = bb_simplify_path(mp->mnt_fsname); 576 mp->mnt_fsname = fsname = bb_simplify_path(mp->mnt_fsname);
522 mp->mnt_type = (char*)"bind"; 577 mp->mnt_type = (char*)"bind";
523 } 578 }
524 mp->mnt_freq = mp->mnt_passno = 0; 579 mp->mnt_freq = mp->mnt_passno = 0;
525 580
526 // Write and close. 581 // Write and close
527 582#if ENABLE_FEATURE_MTAB_SUPPORT
528 addmntent(mountTable, mp); 583 if (vfsflags & MS_MOVE)
584 update_mtab_entry_on_move(mp);
585 else
586#endif
587 addmntent(mountTable, mp);
529 endmntent(mountTable); 588 endmntent(mountTable);
589
530 if (ENABLE_FEATURE_CLEAN_UP) { 590 if (ENABLE_FEATURE_CLEAN_UP) {
531 free(mp->mnt_dir); 591 free(mp->mnt_dir);
532 free(fsname); 592 free(fsname);