mirror of
https://git.code.sf.net/p/ntfs-3g/ntfs-3g.git
synced 2024-11-27 03:53:48 +08:00
Fixed trailing '/' circumstances and simplified path normalization
This commit is contained in:
parent
b8a6013531
commit
b929b94aaa
@ -34,7 +34,7 @@ struct CACHED_GENERIC {
|
||||
|
||||
struct CACHED_INODE {
|
||||
struct CACHED_INODE *next;
|
||||
char *pathname;
|
||||
const char *pathname;
|
||||
u64 inum;
|
||||
} ;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user