Extended cacheing to any variable type

N2009_11_14_FIXES
jpandre 2008-04-17 13:26:52 +00:00
parent b929b94aaa
commit 5e30e6f204
5 changed files with 69 additions and 45 deletions

View File

@ -28,13 +28,16 @@
struct CACHED_GENERIC {
struct CACHED_GENERIC *next;
char *pathname;
void *variable;
size_t varsize;
void *fixed[0];
} ;
struct CACHED_INODE {
struct CACHED_INODE *next;
const char *pathname;
size_t varsize;
/* above fields must match "struct CACHED_GENERIC" */
u64 inum;
} ;

View File

@ -43,7 +43,8 @@ struct MAPPING {
};
/*
* Entry in the permissions cache
* Entry in the permissions cache
* Note : this cache is not organized as a generic cache
*/
struct CACHED_PERMISSIONS {
@ -61,7 +62,9 @@ struct CACHED_PERMISSIONS {
struct CACHED_PERMISSIONS_LEGACY {
struct CACHED_PERMISSIONS_LEGACY *next;
char *unused;
void *variable;
size_t varsize;
/* above fields must match "struct CACHED_GENERIC" */
u64 mft_no;
struct CACHED_PERMISSIONS perm;
} ;
@ -72,7 +75,9 @@ struct CACHED_PERMISSIONS_LEGACY {
struct CACHED_SECURID {
struct CACHED_SECURID *next;
void *unused;
void *variable;
size_t varsize;
/* above fields must match "struct CACHED_GENERIC" */
uid_t uid;
gid_t gid;
unsigned int dmode;
@ -81,6 +86,7 @@ struct CACHED_SECURID {
/*
* Header of the security cache
* (has no cache structure by itself)
*/
struct CACHED_PERMISSIONS_HEADER {
@ -168,8 +174,7 @@ le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx,
int ntfs_set_owner(struct SECURITY_CONTEXT *scx,
const char *path, ntfs_inode *ni, uid_t uid, gid_t gid);
int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx,
ntfs_inode *ni,
uid_t uid, gid_t gid, mode_t mode);
ntfs_inode *ni, uid_t uid, gid_t gid, mode_t mode);
le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx,
const char *dir_path, ntfs_inode *dir_ni, BOOL fordir);
int ntfs_open_secure(ntfs_volume *vol);

View File

@ -87,7 +87,8 @@ ntfschar NTFS_INDEX_R[3] = { const_cpu_to_le16('$'), const_cpu_to_le16('R'),
static int inode_cache_compare(const struct CACHED_GENERIC *cached,
const struct CACHED_GENERIC *wanted)
{
return (strcmp(cached->pathname, wanted->pathname));
return (!cached->variable
|| strcmp(cached->variable, wanted->variable));
}
/*
@ -102,10 +103,12 @@ static int inode_cache_inv_compare(const struct CACHED_GENERIC *cached,
{
int len;
len = strlen(wanted->pathname);
return (strncmp(cached->pathname, wanted->pathname,len)
|| ((cached->pathname[len] != '\0')
&& (cached->pathname[len] != '/')));
len = strlen(wanted->variable);
return (!cached->variable
|| strncmp((const char*)cached->variable,
(const char*)wanted->variable,len)
|| ((((const char*)cached->variable)[len] != '\0')
&& (((const char*)cached->variable)[len] != '/')));
}
#endif
@ -497,6 +500,7 @@ ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent,
*/
if (*fullname) {
item.pathname = fullname;
item.varsize = strlen(fullname) + 1;
cached = (struct CACHED_INODE*)ntfs_fetch_cache(
vol->inode_cache, GENERIC(&item),
inode_cache_compare);
@ -553,6 +557,7 @@ ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent,
inum = ntfs_inode_lookup_by_name(ni, unicode, len);
else {
item.pathname = fullname;
item.varsize = strlen(fullname) + 1;
cached = (struct CACHED_INODE*)ntfs_fetch_cache(
vol->inode_cache, GENERIC(&item),
inode_cache_compare);

View File

@ -136,15 +136,14 @@ struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache,
/*
* Search sequentially in LRU list to locate the end,
* and find out whether the entry is already in list
* As we normally go to the end, no statitics is
* As we normally go to the end, no statistics is
* kept.
*/
current = cache->most_recent_entry;
previous = (struct CACHED_GENERIC*)NULL;
before = (struct CACHED_GENERIC*)NULL;
while (current
&& (!current->pathname
|| compare(current, item))) {
&& compare(current, item)) {
before = previous;
previous = current;
current = current->next;
@ -162,35 +161,37 @@ struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache,
if (cache->free_entry) {
current = cache->free_entry;
cache->free_entry = cache->free_entry->next;
if (item->pathname) {
current->pathname = ntfs_malloc(
strlen(item->pathname) + 1);
if (item->varsize) {
current->variable = ntfs_malloc(
item->varsize);
} else
current->pathname = (char*)NULL;
current->variable = (void*)NULL;
current->varsize = item->varsize;
} else {
before->next = (struct CACHED_GENERIC*)NULL;
current = previous;
if (item->pathname) {
if (current->pathname)
current->pathname = realloc(
current->pathname,
strlen(item->pathname) + 1);
if (item->varsize) {
if (current->varsize)
current->variable = realloc(
current->variable,
item->varsize);
else
current->pathname = ntfs_malloc(
strlen(item->pathname) + 1);
current->variable = ntfs_malloc(
item->varsize);
} else {
if (current->pathname)
free(current->pathname);
current->pathname = (char*)NULL;
if (current->varsize)
free(current->variable);
current->variable = (void*)NULL;
}
current->varsize = item->varsize;
}
current->next = cache->most_recent_entry;
cache->most_recent_entry = current;
memcpy(current->fixed, item->fixed, cache->fixed_size);
if (item->pathname) {
if (current->pathname) {
strcpy(current->pathname,
item->pathname);
if (item->varsize) {
if (current->variable) {
memcpy(current->variable,
item->variable, item->varsize);
} else {
/*
* no more memory for variable part
@ -202,8 +203,10 @@ struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache,
cache->free_entry = current;
current = (struct CACHED_GENERIC*)NULL;
}
} else
current->pathname = (char*)NULL;
} else {
current->variable = (void*)NULL;
current->varsize = 0;
}
}
cache->writes++;
}
@ -248,8 +251,9 @@ int ntfs_invalidate_cache(struct CACHE_HEADER *cache,
cache->most_recent_entry = current->next;
current->next = cache->free_entry;
cache->free_entry = current;
if (current->pathname)
free(current->pathname);
if (current->variable)
free(current->variable);
current->varsize = 0;
if (previous)
current = previous->next;
else
@ -274,8 +278,8 @@ static void ntfs_free_cache(struct CACHE_HEADER *cache)
if (cache) {
for (entry=cache->most_recent_entry; entry; entry=entry->next)
if (entry->pathname)
free(entry->pathname);
if (entry->variable)
free(entry->variable);
free(cache);
}
}
@ -310,12 +314,14 @@ static struct CACHE_HEADER *ntfs_create_cache(const char *name,
for (i=0; i<(item_count - 1); i++) {
q = (struct CACHED_GENERIC*)((char*)p + full_item_size);
p->next = q;
p->pathname = (char*)NULL;
p->variable = (void*)NULL;
p->varsize = 0;
p = q;
}
/* special for the last entry */
p->next = (struct CACHED_GENERIC*)NULL;
p->pathname = (char*)NULL;
p->variable = (void*)NULL;
p->varsize = 0;
}
return (cache);
}

View File

@ -2119,7 +2119,8 @@ static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx,
wanted.perm.inh_fileid = cpu_to_le32(0);
wanted.perm.inh_dirid = cpu_to_le32(0);
wanted.mft_no = ni->mft_no;
wanted.unused = (char*)NULL;
wanted.variable = (void*)NULL;
wanted.varsize = 0;
legacy = (struct CACHED_PERMISSIONS_LEGACY*)ntfs_enter_cache(
scx->vol->legacy_cache, GENERIC(&wanted),
(cache_compare)leg_compare);
@ -2177,7 +2178,8 @@ static struct CACHED_PERMISSIONS *fetch_cache(struct SECURITY_CONTEXT *scx,
struct CACHED_PERMISSIONS_LEGACY *legacy;
wanted.mft_no = ni->mft_no;
wanted.unused = (char*)NULL;
wanted.variable = (void*)NULL;
wanted.varsize = 0;
legacy = (struct CACHED_PERMISSIONS_LEGACY*)ntfs_fetch_cache(
scx->vol->legacy_cache, GENERIC(&wanted),
(cache_compare)leg_compare);
@ -3385,7 +3387,8 @@ le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx,
wanted.gid = gid;
wanted.dmode = mode & 07777;
if (isdir) wanted.dmode |= 0x10000;
wanted.unused = (char*)NULL;
wanted.variable = (void*)NULL;
wanted.varsize = 0;
cached = (const struct CACHED_SECURID*)ntfs_fetch_cache(
scx->vol->securid_cache, GENERIC(&wanted),
(cache_compare)compare);
@ -3459,7 +3462,8 @@ int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
wanted.gid = gid;
wanted.dmode = mode & 07777;
if (isdir) wanted.dmode |= 0x10000;
wanted.unused = (char*)NULL;
wanted.variable = (void*)NULL;
wanted.varsize = 0;
cached = (const struct CACHED_SECURID*)ntfs_fetch_cache(
scx->vol->securid_cache, GENERIC(&wanted),
(cache_compare)compare);
@ -3501,7 +3505,8 @@ int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
struct CACHED_PERMISSIONS_LEGACY legacy;
legacy.mft_no = ni->mft_no;
legacy.unused = (char*)NULL;
legacy.variable = (void*)NULL;
legacy.varsize = 0;
ntfs_invalidate_cache(scx->vol->legacy_cache,
GENERIC(&legacy),
(cache_compare)leg_compare);