diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-14 13:19:19 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-14 13:19:19 +0000 |
commit | 727ef9444770bdd4f8253e96218ec1d5bc9888d3 (patch) | |
tree | 26fd5d048cebf8bfa0816e23341ec19abe40b47a | |
parent | 85c6de71bf23e991c8ae570e637839a59222496a (diff) | |
download | busybox-727ef9444770bdd4f8253e96218ec1d5bc9888d3.tar.gz |
mount: fix mtab support (but it is still rather buggy)
-rw-r--r-- | util-linux/mount.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index bd2a62d64..4ed000e88 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -223,6 +223,8 @@ int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts) * mtab file by hand, add the new entry to it now. */ if(ENABLE_FEATURE_MTAB_SUPPORT && useMtab && !rc) { + char dirbuf[PATH_MAX]; + char srcbuf[PATH_MAX]; FILE *mountTable = setmntent(bb_path_mtab_file, "a+"); int i; @@ -232,27 +234,39 @@ int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts) // Add vfs string flags for(i=0; mount_options[i].flags != MS_REMOUNT; i++) - if (mount_options[i].flags > 0) + if (mount_options[i].flags > 0 && (mount_options[i].flags&vfsflags)) append_mount_options(&(mp->mnt_opts), mount_options[i].name); // Remove trailing / (if any) from directory we mounted on - i = strlen(mp->mnt_dir); - if(i>1 && mp->mnt_dir[i-1] == '/') mp->mnt_dir[i-1] = 0; + i = strlen(mp->mnt_dir) - 1; + if(i > 0 && mp->mnt_dir[i] == '/') mp->mnt_dir[i] = 0; + + // Add full pathnames as needed + + if (mp->mnt_dir[0] != '/') { + getcwd(dirbuf, sizeof(dirbuf)); + i = strlen(dirbuf); + /* strcat() would be unsafe here */ + snprintf(dirbuf+i, sizeof(dirbuf)-i, "/%s", mp->mnt_dir); + mp->mnt_dir = dirbuf; + } + if (!mp->mnt_type || !*mp->mnt_type) { /* bind mount */ + if (mp->mnt_fsname[0] != '/') { + getcwd(srcbuf, sizeof(srcbuf)); + i = strlen(srcbuf); + snprintf(srcbuf+i, sizeof(srcbuf)-i, "/%s", + mp->mnt_fsname); + mp->mnt_fsname = srcbuf; + } + mp->mnt_type = "none"; + mp->mnt_freq = mp->mnt_passno = 0; + } // Write and close. - if(!mp->mnt_type || !*mp->mnt_type) mp->mnt_type="--bind"; -// addmntent(mountTable, mp); -if(0) bb_error_msg("buggy: addmntent(fsname='%s' dir='%s' type='%s' opts='%s')", -mp->mnt_fsname, -mp->mnt_dir, -mp->mnt_type, -mp->mnt_opts -); + addmntent(mountTable, mp); endmntent(mountTable); - if (ENABLE_FEATURE_CLEAN_UP) - if(strcmp(mp->mnt_type,"--bind")) mp->mnt_type = 0; } return rc; |