diff --git a/src/statcache.c b/src/statcache.c
index d9e801f32b8b299ab78021e10bdb5ada292bf3ed..28f3e275199d561d2274bcb5e79e0a6b6693f826 100644 (file)
--- a/src/statcache.c
+++ b/src/statcache.c
-/* $Id$ */
-
/***
- This file is part of fusedav.
-
- fusedav is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- fusedav is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
- License for more details.
-
- You should have received a copy of the GNU General Public License
- along with fusedav; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Copyright (c) 2004-2006 Lennart Poettering
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation files
+ (the "Software"), to deal in the Software without restriction,
+ including without limitation the rights to use, copy, modify, merge,
+ publish, distribute, sublicense, and/or sell copies of the Software,
+ and to permit persons to whom the Software is furnished to do so,
+ subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
***/
#ifdef HAVE_CONFIG_H
if (debug)
fprintf(stderr, "CGET: %s\n", fn);
-
+
assert(cache);
-
+
h = calc_hash(fn);
ce = cache + (h % CACHE_SIZE);
pthread_mutex_lock(&stat_cache_mutex);
-
+
if (ce->stat_info.valid &&
ce->stat_info.filename &&
ce->stat_info.hash == h &&
!strcmp(ce->stat_info.filename, fn) &&
time(NULL) <= ce->stat_info.dead) {
-
+
*st = ce->stat_info.st;
if ((f = file_cache_get(fn))) {
}
pthread_mutex_unlock(&stat_cache_mutex);
-
+
return r;
}
if (debug)
fprintf(stderr, "CSET: %s\n", fn);
assert(cache);
-
+
h = calc_hash(fn);
ce = cache + (h % CACHE_SIZE);
ce->stat_info.filename = strdup(fn);
ce->stat_info.hash = h;
}
-
+
ce->stat_info.st = *st;
ce->stat_info.dead = time(NULL)+CACHE_TIMEOUT;
ce->stat_info.valid = 1;
struct cache_entry *ce;
assert(cache);
-
+
h = calc_hash(fn);
ce = cache + (h % CACHE_SIZE);
ce->stat_info.valid = 0;
free(ce->stat_info.filename);
ce->stat_info.filename = NULL;
-
+
pthread_mutex_unlock(&stat_cache_mutex);
}
struct cache_entry *ce;
struct dir_entry *de = NULL, *de2 = NULL;
assert(cache);
-
+
h = calc_hash(fn);
ce = cache + (h % CACHE_SIZE);
-
+
pthread_mutex_lock(&dir_cache_mutex);
if (!ce->dir_info.filling) {
-
+
if (!ce->dir_info.filename || ce->dir_info.hash != h || strcmp(ce->dir_info.filename, fn)) {
free(ce->dir_info.filename);
ce->dir_info.filename = strdup(fn);
ce->dir_info.valid2 = 0;
ce->dir_info.filling = 1;
}
-
+
pthread_mutex_unlock(&dir_cache_mutex);
free_dir_entries(de);
free_dir_entries(de2);
struct cache_entry *ce;
struct dir_entry *de = NULL;
assert(cache);
-
+
h = calc_hash(fn);
ce = cache + (h % CACHE_SIZE);
-
+
pthread_mutex_lock(&dir_cache_mutex);
-
+
if (ce->dir_info.filling &&
ce->dir_info.filename &&
ce->dir_info.hash == h &&
assert(!ce->dir_info.valid2);
if (success) {
-
+
ce->dir_info.valid2 = 1;
ce->dir_info.filling = 0;
ce->dir_info.dead2 = time(NULL)+CACHE_TIMEOUT;
-
+
if (!ce->dir_info.in_use) {
de = ce->dir_info.entries;
ce->dir_info.entries = ce->dir_info.entries2;
ce->dir_info.valid2 = 0;
ce->dir_info.valid = 1;
}
-
+
} else {
ce->dir_info.filling = 0;
de = ce->dir_info.entries2;
uint32_t h;
struct cache_entry *ce;
assert(cache);
-
+
h = calc_hash(fn);
ce = cache + (h % CACHE_SIZE);
-
+
pthread_mutex_lock(&dir_cache_mutex);
-
+
if (ce->dir_info.filling &&
ce->dir_info.filename &&
ce->dir_info.hash == h &&
assert(n);
strcpy(n->filename, subdir);
-
+
n->next = ce->dir_info.entries2;
ce->dir_info.entries2 = n;
}
@@ -284,12 +288,12 @@ int dir_cache_enumerate(const char *fn, void (*f) (const char*fn, const char *su
int r = -1;
assert(cache && f);
-
+
h = calc_hash(fn);
ce = cache + (h % CACHE_SIZE);
-
+
pthread_mutex_lock(&dir_cache_mutex);
-
+
if (ce->dir_info.valid &&
ce->dir_info.filename &&
ce->dir_info.hash == h &&
@@ -316,23 +320,23 @@ int dir_cache_enumerate(const char *fn, void (*f) (const char*fn, const char *su
r = 0;
}
-
+
pthread_mutex_unlock(&dir_cache_mutex);
free_dir_entries(de);
return r;
-}
+}
void dir_cache_invalidate(const char*fn) {
uint32_t h;
struct cache_entry *ce;
struct dir_entry *de = NULL;
assert(cache && fn);
-
+
h = calc_hash(fn);
ce = cache + (h % CACHE_SIZE);
pthread_mutex_lock(&dir_cache_mutex);
-
+
if (ce->dir_info.valid &&
ce->dir_info.filename &&
ce->dir_info.hash == h &&
de = ce->dir_info.entries;
ce->dir_info.entries = NULL;
}
-
+
pthread_mutex_unlock(&dir_cache_mutex);
free_dir_entries(de);
}
if (p[l-1] == '/')
p[l-1] = 0;
}
-
+
dir_cache_invalidate(p);
free(p);
} else
}
void cache_alloc(void) {
-
+
if (cache)
return;
assert(cache);
memset(cache, 0, sizeof(struct cache_entry)*CACHE_SIZE);
}
-