From b929b94aaaac6133ba6147397ec416483a17df10 Mon Sep 17 00:00:00 2001 From: jpandre Date: Thu, 17 Apr 2008 10:26:15 +0000 Subject: [PATCH] Fixed trailing '/' circumstances and simplified path normalization --- include/ntfs-3g/misc.h | 2 +- libntfs-3g/dir.c | 53 +++++++++++------------------------------- libntfs-3g/security.c | 2 +- src/ntfs-3g.c | 6 ++--- 4 files changed, 19 insertions(+), 44 deletions(-) diff --git a/include/ntfs-3g/misc.h b/include/ntfs-3g/misc.h index fded6555..a1d685f6 100644 --- a/include/ntfs-3g/misc.h +++ b/include/ntfs-3g/misc.h @@ -34,7 +34,7 @@ struct CACHED_GENERIC { struct CACHED_INODE { struct CACHED_INODE *next; - char *pathname; + const char *pathname; u64 inum; } ; diff --git a/libntfs-3g/dir.c b/libntfs-3g/dir.c index 7b75de00..457e1cbe 100644 --- a/libntfs-3g/dir.c +++ b/libntfs-3g/dir.c @@ -108,30 +108,6 @@ static int inode_cache_inv_compare(const struct CACHED_GENERIC *cached, && (cached->pathname[len] != '/'))); } -/* - * Normalize file paths for cacheing - * Just remove leading and trailing '/', there should not be any - * non-standard components (such as "/../" or "/./") because - * paths have been rewritten by fuse. - * - * Returns the first non-'/' char in the original path - */ - -static char *path_normalize(char *path) -{ - int len; - char *p; - - /* remove leading and trailing '/' even for root */ - len = strlen(path); - while ((len > 1) && (path[len - 1] == PATH_SEP)) - path[--len] = '\0'; - p = path; - while (*p == PATH_SEP) - p++; - return (p); - } - #endif /** @@ -503,14 +479,14 @@ ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, goto out; } -#if CACHE_INODE_SIZE - fullname = path_normalize(ascii); - p = fullname; -#else p = ascii; /* Remove leading /'s. */ while (p && *p && *p == PATH_SEP) p++; +#if CACHE_INODE_SIZE + fullname = p; + if (p[0] && (p[strlen(p)-1] == PATH_SEP)) + ntfs_log_error("Unnormalized path %s\n",ascii); #endif if (parent) { ni = parent; @@ -1503,8 +1479,8 @@ int ntfs_delete(ntfs_volume *vol, const char *pathname, BOOL case_sensitive_match = TRUE; int err = 0; #if CACHE_INODE_SIZE - char *ascii; struct CACHED_INODE item; + const char *p; int count; #endif @@ -1674,17 +1650,16 @@ out: err = errno; #if CACHE_INODE_SIZE /* invalide cache entry, even if there was an error */ - ascii = strdup(pathname); - if (ascii) { - char *p; - - item.pathname = path_normalize(ascii); - count = ntfs_invalidate_cache(vol->inode_cache, GENERIC(&item), + /* Remove leading /'s. */ + p = pathname; + while (*p == PATH_SEP) + p++; + if (p[0] && (p[strlen(p)-1] == PATH_SEP)) + ntfs_log_error("Unnormalized path %s\n",pathname); + item.pathname = p; + count = ntfs_invalidate_cache(vol->inode_cache, GENERIC(&item), inode_cache_inv_compare); - p = ascii; /* do not clear ascii */ - free(p); - } - if (!ascii || !count) + if (!count) ntfs_log_error("Could not delete inode cache entry for %s\n", pathname); #endif diff --git a/libntfs-3g/security.c b/libntfs-3g/security.c index 1ad0e40c..8cfc1c0a 100644 --- a/libntfs-3g/security.c +++ b/libntfs-3g/security.c @@ -3758,7 +3758,7 @@ BOOL ntfs_allowed_dir_access(struct SECURITY_CONTEXT *scx, /* the root of file system is seen as a parent of itself */ /* is that correct ? */ name = strrchr(dirpath, '/'); - *++name = 0; + *name = 0; dir_ni = ntfs_pathname_to_inode(scx->vol, NULL, dirpath); if (dir_ni) { allow = ntfs_allowed_access(scx,dirpath, diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index f109cd93..b5f530b7 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -1043,7 +1043,7 @@ static int ntfs_fuse_create(const char *org_path, dev_t typemode, dev_t dev, goto exit; } /* Open parent directory. */ - *name = 0; + *--name = 0; dir_ni = ntfs_pathname_to_inode(ctx->vol, NULL, dir_path); if (!dir_ni) { free(path); @@ -1251,7 +1251,7 @@ static int ntfs_fuse_link(const char *old_path, const char *new_path) goto exit; } /* Open parent directory. */ - *name = 0; + *--name = 0; dir_ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!dir_ni) { res = -errno; @@ -1313,7 +1313,7 @@ static int ntfs_fuse_rm(const char *org_path) goto exit; } /* Open parent directory. */ - *name = 0; + *--name = 0; dir_ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!dir_ni) { res = -errno;