diff --git a/fs/vfs/dcache.c b/fs/vfs/dcache.c index cb091ca..ad171e7 100644 --- a/fs/vfs/dcache.c +++ b/fs/vfs/dcache.c @@ -9,17 +9,17 @@ struct dc_entry dcache[DCACHE_SIZE]; static spinlock_t dcache_locks[DCACHE_NLOCKS]; -static unsigned long dcache_hash(struct dc_entry *parent, const char *name) +static u64 dcache_hash(struct dc_entry *parent, const char *name) { - unsigned long h = (unsigned long)parent; + u64 h = (u64)parent; while (*name) - h = ((h << 5) - h) + (unsigned char)*name++; + h = ((h << 5) - h) + (u8)*name++; return h; } static spinlock_t *dcache_lock_for(struct dc_entry *parent, const char *name) { - unsigned long h = dcache_hash(parent, name); + u64 h = dcache_hash(parent, name); return &dcache_locks[h & (DCACHE_NLOCKS - 1)]; } @@ -34,11 +34,11 @@ void dcache_init(void) void dcache_insert(struct dc_entry *parent, dirent_t *dirent, const char *name) { spinlock_t *lock = dcache_lock_for(parent, name); - unsigned long h = dcache_hash(parent, name); + u64 h = dcache_hash(parent, name); spinlock_acquire(lock); for (int i = 0; i < DCACHE_SIZE; i++) { - unsigned int b = (h + i) & (DCACHE_SIZE - 1); + u32 b = (h + i) & (DCACHE_SIZE - 1); struct dc_entry *s = &dcache[b]; if (!s->parent || s->parent == DC_TOMBSTONE || s->dirent->refcount == 0) { @@ -67,24 +67,20 @@ void dcache_remove(struct dc_entry *d) struct dc_entry *dcache_lookup(struct dc_entry *parent, const char *name) { - spinlock_t *lock = dcache_lock_for(parent, name); - unsigned long h = dcache_hash(parent, name); + CLEANUP_SLOCK spinlock_t *lock = dcache_lock_for(parent, name); + u64 h = dcache_hash(parent, name); struct dc_entry *result = NULL; - spinlock_acquire(lock); for (int i = 0; i < DCACHE_SIZE; i++) { - unsigned int b = (h + i) & (DCACHE_SIZE - 1); + u32 b = (h + i) & (DCACHE_SIZE - 1); struct dc_entry *s = &dcache[b]; if (!s->parent) - goto out; + return NULL; - if (s->parent != DC_TOMBSTONE && s->parent == parent && !strcmp(s->d_name, name)) { - result = s; - goto out; - } + if (s->parent != DC_TOMBSTONE && s->parent == parent && !strcmp(s->d_name, name)) + return s; } -out: - spinlock_release(lock); - return result; + + return NULL; }