From fc2382b7424189358459f2d87413edef698a2ea3 Mon Sep 17 00:00:00 2001 From: cha0smaster Date: Mon, 18 Jul 2005 02:09:43 +0000 Subject: [PATCH] libntfs/volume.c: fix ntfs_check_if_mounted to cope with dirrerent names of same file. ntfsprogs/ntfsmount.c: don't put relative path to /etc/mtab. --- ChangeLog | 1 + libntfs/volume.c | 36 ++++++++++++++++++++++++++++++++---- ntfsprogs/ntfsmount.c | 26 +++++++++++++++++++------- 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 712100a7..710651b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ xx/07/2005 - 1.11.0-WIP - Fixes and a new utility ntfsmount, a FUSE ntfsmodule. when sector size was less than 512 bytes and then we wrote 512 bytes, i.e. beyond the end of the device.) (Anton) - Add new utility (make extra) - ntfsdecrypt. (Yuval) + - Improve "already mounted" ckeck. (Yura) 20/06/2005 - 1.10.0 - Lots of new features, enhancements, and bug fixes. diff --git a/libntfs/volume.c b/libntfs/volume.c index 4412f749..7f8e0a39 100644 --- a/libntfs/volume.c +++ b/libntfs/volume.c @@ -1246,16 +1246,35 @@ int ntfs_umount(ntfs_volume *vol, static int ntfs_mntent_check(const char *file, unsigned long *mnt_flags) { struct mntent *mnt; + char *real_file = NULL, *real_fsname = NULL; FILE *f; + int err = 0; - if (!(f = setmntent(MOUNTED, "r"))) + real_file = malloc(PATH_MAX + 1); + if (!real_file) return -1; - while ((mnt = getmntent(f))) - if (!strcmp(file, mnt->mnt_fsname)) + real_fsname = malloc(PATH_MAX + 1); + if (!real_fsname) { + err = errno; + goto exit; + } + if (!realpath(file, real_file)) { + err = errno; + goto exit; + } + if (!(f = setmntent(MOUNTED, "r"))) { + err = errno; + goto exit; + } + while ((mnt = getmntent(f))) { + if (!realpath(mnt->mnt_fsname, real_fsname)) + continue; + if (!strcmp(real_file, real_fsname)) break; + } endmntent(f); if (!mnt) - return 0; + goto exit; *mnt_flags = NTFS_MF_MOUNTED; if (!strcmp(mnt->mnt_dir, "/")) *mnt_flags |= NTFS_MF_ISROOT; @@ -1263,6 +1282,15 @@ static int ntfs_mntent_check(const char *file, unsigned long *mnt_flags) if (hasmntopt(mnt, "ro") && !hasmntopt(mnt, "rw")) *mnt_flags |= NTFS_MF_READONLY; #endif +exit: + if (real_file) + free(real_file); + if (real_fsname) + free(real_fsname); + if (err) { + errno = err; + return -1; + } return 0; } #endif /* HAVE_MNTENT_H */ diff --git a/ntfsprogs/ntfsmount.c b/ntfsprogs/ntfsmount.c index 363d7d82..659f6424 100644 --- a/ntfsprogs/ntfsmount.c +++ b/ntfsprogs/ntfsmount.c @@ -32,6 +32,7 @@ #include #include #include +#include #ifdef HAVE_SETXATTR #include @@ -905,12 +906,12 @@ static char *parse_options(char *options, char **device) *device = NULL; /* - * +3 for different in length of "fsname=..." and "dev=...". - * +1 for comma - * +1 for null-terminator. - * Total: +5 + * +3 for different in length of "fsname=..." and "dev=...". + * +1 for comma. + * +1 for null-terminator. + * +PATH_MAX for resolved by realpath() device name */ - ret = malloc(strlen(def_opts) + strlen(options) + 5); + ret = malloc(strlen(def_opts) + strlen(options) + 5 + PATH_MAX); if (!ret) { perror("malloc failed"); return NULL; @@ -929,8 +930,19 @@ static char *parse_options(char *options, char **device) Eprintf("dev option should have value.\n"); goto err_exit; } - *device = malloc(strlen(val) + 1); - strcpy(*device, val); + *device = malloc(PATH_MAX + 1); + if (!*device) + goto err_exit; + /* We don't want relative path in /etc/mtab. */ + if (val[0] != '/') { + if (!realpath(val, *device)) { + perror(""); + free(*device); + *device = NULL; + goto err_exit; + } + } else + strcpy(*device, val); } else if (!strcmp(opt, "ro")) { /* Read-only mount. */ if (val) { Eprintf("ro option should not have value.\n");