Module: xenomai-forge
Branch: next
Commit: 1c9ed6150dbbed2ce78d3fb75aa89cde432492f8
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=1c9ed6150dbbed2ce78d3fb75aa89cde432492f8

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Jun  6 11:38:45 2013 +0200

copperplate/hash: introduce generic key type

We don't want hash keys to be restricted to character strings
anymore.

Client code may now use whatever key type fits, mentioning the actual
key length in all relevant calls. In addition, the node comparison
routine has to be specified in the [pv]hash_init() call.

---

 include/copperplate/hash.h        |   83 +++++++++++++++++++++----------
 lib/copperplate/cluster.c         |   21 ++++----
 lib/copperplate/hash.c            |   97 ++++++++++++++++++++++++-------------
 lib/copperplate/heapobj-pshared.c |    2 +-
 lib/copperplate/registry.c        |   25 +++++-----
 5 files changed, 145 insertions(+), 83 deletions(-)

diff --git a/include/copperplate/hash.h b/include/copperplate/hash.h
index d43cfb4..b29381b 100644
--- a/include/copperplate/hash.h
+++ b/include/copperplate/hash.h
@@ -25,7 +25,8 @@
 #define HASHSLOTS  (1<<8)
 
 struct hashobj {
-       const char *key;
+       const void *key;
+       size_t len;
        struct holder link;
 };
 
@@ -35,13 +36,16 @@ struct hash_bucket {
 
 struct hash_table {
        struct hash_bucket table[HASHSLOTS];
+       int (*compare)(const struct hashobj *l,
+                      const struct hashobj *r);
        pthread_mutex_t lock;
 };
 
 #ifdef CONFIG_XENO_PSHARED
 /* Private version - not shareable between processes. */
 struct pvhashobj {
-       const char *key;
+       const void *key;
+       size_t len;
        struct pvholder link;
 };
 
@@ -51,6 +55,8 @@ struct pvhash_bucket {
 
 struct pvhash_table {
        struct pvhash_bucket table[HASHSLOTS];
+       int (*compare)(const struct pvhashobj *l,
+                      const struct pvhashobj *r);
        pthread_mutex_t lock;
 };
 #else /* !CONFIG_XENO_PSHARED */
@@ -64,93 +70,115 @@ extern "C" {
 #endif
 
 unsigned int __hash_key(const void *key,
-                       int length, unsigned int c);
+                       size_t length, unsigned int c);
 
-void __hash_init(void *heap, struct hash_table *t);
+void __hash_init(void *heap, struct hash_table *t,
+                int (*compare)(const struct hashobj *l,
+                               const struct hashobj *r));
 
 int __hash_enter(struct hash_table *t,
-                const char *key, struct hashobj *newobj,
-                int nodup);
+                const void *key, size_t len,
+                struct hashobj *newobj, int nodup);
 
-static inline void hash_init(struct hash_table *t)
+static inline void hash_init(struct hash_table *t,
+                            int (*compare)(const struct hashobj *l,
+                                           const struct hashobj *r))
 {
-       __hash_init(__main_heap, t);
+       __hash_init(__main_heap, t, compare);
 }
 
 void hash_destroy(struct hash_table *t);
 
 static inline int hash_enter(struct hash_table *t,
-                            const char *key, struct hashobj *newobj)
+                            const void *key, size_t len,
+                            struct hashobj *newobj)
 {
-       return __hash_enter(t, key, newobj, 1);
+       return __hash_enter(t, key, len, newobj, 1);
 }
 
 static inline int hash_enter_dup(struct hash_table *t,
-                                const char *key, struct hashobj *newobj)
+                                const void *key, size_t len,
+                                struct hashobj *newobj)
 {
-       return __hash_enter(t, key, newobj, 0);
+       return __hash_enter(t, key, len, newobj, 0);
 }
 
 int hash_remove(struct hash_table *t, struct hashobj *delobj);
 
-struct hashobj *hash_search(struct hash_table *t, const char *key);
+struct hashobj *hash_search(struct hash_table *t,
+                           const void *key, size_t len);
 
 int hash_walk(struct hash_table *t,
                int (*walk)(struct hash_table *t, struct hashobj *obj));
 
+int hash_compare_strings(const struct hashobj *l,
+                        const struct hashobj *r);
+
 #ifdef CONFIG_XENO_PSHARED
 
 int __hash_enter_probe(struct hash_table *t,
-                      const char *key, struct hashobj *newobj,
+                      const void *key, size_t len,
+                      struct hashobj *newobj,
                       int (*probefn)(struct hashobj *oldobj),
                       int nodup);
 
 int __pvhash_enter(struct pvhash_table *t,
-                  const char *key, struct pvhashobj *newobj,
-                  int nodup);
+                  const void *key, size_t len,
+                  struct pvhashobj *newobj, int nodup);
 
 static inline
 int hash_enter_probe(struct hash_table *t,
-                    const char *key, struct hashobj *newobj,
+                    const void *key, size_t len,
+                    struct hashobj *newobj,
                     int (*probefn)(struct hashobj *oldobj))
 {
-       return __hash_enter_probe(t, key, newobj, probefn, 1);
+       return __hash_enter_probe(t, key, len, newobj, probefn, 1);
 }
 
 static inline
 int hash_enter_probe_dup(struct hash_table *t,
-                        const char *key, struct hashobj *newobj,
+                        const void *key, size_t len,
+                        struct hashobj *newobj,
                         int (*probefn)(struct hashobj *oldobj))
 {
-       return __hash_enter_probe(t, key, newobj, probefn, 0);
+       return __hash_enter_probe(t, key, len, newobj, probefn, 0);
 }
 
-struct hashobj *hash_search_probe(struct hash_table *t, const char *key,
+struct hashobj *hash_search_probe(struct hash_table *t,
+                                 const void *key, size_t len,
                                  int (*probefn)(struct hashobj *obj));
 
-void pvhash_init(struct pvhash_table *t);
+void pvhash_init(struct pvhash_table *t,
+                int (*compare)(const struct pvhashobj *l,
+                               const struct pvhashobj *r));
 
 static inline
 int pvhash_enter(struct pvhash_table *t,
-                const char *key, struct pvhashobj *newobj)
+                const void *key, size_t len,
+                struct pvhashobj *newobj)
 {
-       return __pvhash_enter(t, key, newobj, 1);
+       return __pvhash_enter(t, key, len, newobj, 1);
 }
 
 static inline
 int pvhash_enter_dup(struct pvhash_table *t,
-                    const char *key, struct pvhashobj *newobj)
+                    const void *key, size_t len,
+                    struct pvhashobj *newobj)
 {
-       return __pvhash_enter(t, key, newobj, 0);
+       return __pvhash_enter(t, key, len, newobj, 0);
 }
 
 int pvhash_remove(struct pvhash_table *t, struct pvhashobj *delobj);
 
-struct pvhashobj *pvhash_search(struct pvhash_table *t, const char *key);
+struct pvhashobj *pvhash_search(struct pvhash_table *t,
+                               const void *key, size_t len);
 
 int pvhash_walk(struct pvhash_table *t,
                int (*walk)(struct pvhash_table *t, struct pvhashobj *obj));
 
+int pvhash_compare_strings(const struct pvhashobj *l,
+                          const struct pvhashobj *r);
+
 #else /* !CONFIG_XENO_PSHARED */
 #define pvhash_init            hash_init
 #define pvhash_enter           hash_enter
@@ -158,6 +186,7 @@ int pvhash_walk(struct pvhash_table *t,
 #define pvhash_remove          hash_remove
 #define pvhash_search          hash_search
 #define pvhash_walk            hash_walk
+#define pvhash_compare_strings hash_compare_strings
 #endif /* !CONFIG_XENO_PSHARED */
 
 #ifdef __cplusplus
diff --git a/lib/copperplate/cluster.c b/lib/copperplate/cluster.c
index 47d2b54..3d8173c 100644
--- a/lib/copperplate/cluster.c
+++ b/lib/copperplate/cluster.c
@@ -115,7 +115,7 @@ int cluster_init(struct cluster *c, const char *name)
         * clusters.
         */
 redo:
-       hobj = hash_search(&main_catalog, name);
+       hobj = hash_search(&main_catalog, name, strlen(name));
        if (hobj) {
                d = container_of(hobj, struct dictionary, hobj);
                goto out;
@@ -127,8 +127,8 @@ redo:
                goto out;
        }
 
-       hash_init(&d->table);
-       ret = hash_enter(&main_catalog, name, &d->hobj);
+       hash_init(&d->table, hash_compare_strings);
+       ret = hash_enter(&main_catalog, name, strlen(name), &d->hobj);
        if (ret == -EEXIST) {
                /*
                 * Someone seems to have slipped in, creating the
@@ -164,7 +164,7 @@ int cluster_addobj(struct cluster *c, const char *name,
         * owner node existence, overwriting dead instances on the
         * fly.
         */
-       return hash_enter_probe(&c->d->table, name,
+       return hash_enter_probe(&c->d->table, name, strlen(name),
                                &cobj->hobj, cluster_probe);
 }
 
@@ -176,7 +176,7 @@ int cluster_addobj_dup(struct cluster *c, const char *name,
         * Same as cluster_addobj(), but allows for duplicate keys in
         * live objects.
         */
-       return hash_enter_probe_dup(&c->d->table, name,
+       return hash_enter_probe_dup(&c->d->table, name, strlen(name),
                                    &cobj->hobj, cluster_probe);
 }
 
@@ -193,7 +193,8 @@ struct clusterobj *cluster_findobj(struct cluster *c, const 
char *name)
         * Search for object entry and probe for owner node existence,
         * discarding dead instances on the fly.
         */
-       hobj = hash_search_probe(&c->d->table, name, cluster_probe);
+       hobj = hash_search_probe(&c->d->table, name, strlen(name),
+                                cluster_probe);
        if (hobj == NULL)
                return NULL;
 
@@ -317,7 +318,7 @@ out:
 
 int pvcluster_init(struct pvcluster *c, const char *name)
 {
-       pvhash_init(&c->table);
+       pvhash_init(&c->table, pvhash_compare_strings);
        return 0;
 }
 
@@ -329,13 +330,13 @@ void pvcluster_destroy(struct pvcluster *c)
 int pvcluster_addobj(struct pvcluster *c, const char *name,
                     struct pvclusterobj *cobj)
 {
-       return pvhash_enter(&c->table, name, &cobj->hobj);
+       return pvhash_enter(&c->table, name, strlen(name), &cobj->hobj);
 }
 
 int pvcluster_addobj_dup(struct pvcluster *c, const char *name,
                         struct pvclusterobj *cobj)
 {
-       return pvhash_enter_dup(&c->table, name, &cobj->hobj);
+       return pvhash_enter_dup(&c->table, name, strlen(name), &cobj->hobj);
 }
 
 int pvcluster_delobj(struct pvcluster *c, struct pvclusterobj *cobj)
@@ -347,7 +348,7 @@ struct pvclusterobj *pvcluster_findobj(struct pvcluster *c, 
const char *name)
 {
        struct pvhashobj *hobj;
 
-       hobj = pvhash_search(&c->table, name);
+       hobj = pvhash_search(&c->table, name, strlen(name));
        if (hobj == NULL)
                return NULL;
 
diff --git a/lib/copperplate/hash.c b/lib/copperplate/hash.c
index ba0d51a..5e9285b 100644
--- a/lib/copperplate/hash.c
+++ b/lib/copperplate/hash.c
@@ -51,12 +51,12 @@
 
 #define GOLDEN_HASH_RATIO  0x9e3779b9  /* Arbitrary value. */
 
-unsigned int __hash_key(const void *key, int length, unsigned int c)
+unsigned int __hash_key(const void *key, size_t length, unsigned int c)
 {
        const unsigned char *k = key;
        unsigned int a, b, len;
 
-       len = length;
+       len = (unsigned int)length;
        a = b = GOLDEN_HASH_RATIO;
 
        while (len >= 12) {
@@ -68,7 +68,7 @@ unsigned int __hash_key(const void *key, int length, unsigned 
int c)
                len -= 12;
        }
 
-       c += length;
+       c += (unsigned int)length;
 
        switch (len) {
        case 11: c += ((unsigned int)k[10]<<24);
@@ -89,7 +89,9 @@ unsigned int __hash_key(const void *key, int length, unsigned 
int c)
        return c;
 }
 
-void __hash_init(void *heap, struct hash_table *t)
+void __hash_init(void *heap, struct hash_table *t,
+                int (*compare)(const struct hashobj *l,
+                               const struct hashobj *r))
 {
        pthread_mutexattr_t mattr;
        int n;
@@ -97,6 +99,7 @@ void __hash_init(void *heap, struct hash_table *t)
        for (n = 0; n < HASHSLOTS; n++)
                __list_init(heap, &t->table[n].obj_list);
 
+       t->compare = compare;
        __RT(pthread_mutexattr_init(&mattr));
        __RT(pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT));
        __RT(pthread_mutexattr_setpshared(&mattr, mutex_scope_attribute));
@@ -109,14 +112,16 @@ void hash_destroy(struct hash_table *t)
        __RT(pthread_mutex_destroy(&t->lock));
 }
 
-static struct hash_bucket *do_hash(struct hash_table *t, const char *key)
+static struct hash_bucket *do_hash(struct hash_table *t,
+                                  const void *key, size_t len)
 {
-       unsigned int hash = __hash_key(key, strlen(key), 0);
+       unsigned int hash = __hash_key(key, len, 0);
        return &t->table[hash & (HASHSLOTS-1)];
 }
 
 int __hash_enter(struct hash_table *t,
-                const char *key, struct hashobj *newobj,
+                const void *key, size_t len,
+                struct hashobj *newobj,
                 int nodup)
 {
        struct hash_bucket *bucket;
@@ -125,13 +130,13 @@ int __hash_enter(struct hash_table *t,
 
        holder_init(&newobj->link);
        newobj->key = key;
-       bucket = do_hash(t, key);
+       bucket = do_hash(t, key, len);
 
        write_lock_nocancel(&t->lock);
 
        if (nodup && !list_empty(&bucket->obj_list)) {
                list_for_each_entry(obj, &bucket->obj_list, link) {
-                       if (strcmp(obj->key, key) == 0) {
+                       if (t->compare(obj, newobj) == 0) {
                                ret = -EEXIST;
                                goto out;
                        }
@@ -151,7 +156,7 @@ int hash_remove(struct hash_table *t, struct hashobj 
*delobj)
        struct hashobj *obj;
        int ret = -ESRCH;
 
-       bucket = do_hash(t, delobj->key);
+       bucket = do_hash(t, delobj->key, delobj->len);
 
        write_lock_nocancel(&t->lock);
 
@@ -170,18 +175,21 @@ out:
        return __bt(ret);
 }
 
-struct hashobj *hash_search(struct hash_table *t, const char *key)
+struct hashobj *hash_search(struct hash_table *t, const void *key,
+                           size_t len)
 {
        struct hash_bucket *bucket;
-       struct hashobj *obj;
+       struct hashobj *obj, _obj;
 
-       bucket = do_hash(t, key);
+       bucket = do_hash(t, key, len);
 
        read_lock_nocancel(&t->lock);
 
        if (!list_empty(&bucket->obj_list)) {
+               _obj.key = key;
+               _obj.len = len;
                list_for_each_entry(obj, &bucket->obj_list, link) {
-                       if (strcmp(obj->key, key) == 0)
+                       if (t->compare(obj, &_obj) == 0)
                                goto out;
                }
        }
@@ -219,10 +227,17 @@ int hash_walk(struct hash_table *t,
        return 0;
 }
 
+int hash_compare_strings(const struct hashobj *l,
+                        const struct hashobj *r)
+{
+       return strcmp(l->key, r->key);
+}
+
 #ifdef CONFIG_XENO_PSHARED
 
 int __hash_enter_probe(struct hash_table *t,
-                      const char *key, struct hashobj *newobj,
+                      const void *key, size_t len,
+                      struct hashobj *newobj,
                       int (*probefn)(struct hashobj *oldobj),
                       int nodup)
 {
@@ -232,14 +247,14 @@ int __hash_enter_probe(struct hash_table *t,
 
        holder_init(&newobj->link);
        newobj->key = key;
-       bucket = do_hash(t, key);
+       bucket = do_hash(t, key, len);
 
        push_cleanup_lock(&t->lock);
        write_lock(&t->lock);
 
        if (!list_empty(&bucket->obj_list)) {
                list_for_each_entry_safe(obj, tmp, &bucket->obj_list, link) {
-                       if (strcmp(obj->key, key) == 0) {
+                       if (t->compare(obj, newobj) == 0) {
                                if (probefn(obj)) {
                                        if (nodup) {
                                                ret = -EEXIST;
@@ -260,20 +275,23 @@ out:
        return ret;
 }
 
-struct hashobj *hash_search_probe(struct hash_table *t, const char *key,
+struct hashobj *hash_search_probe(struct hash_table *t,
+                                 const void *key, size_t len,
                                  int (*probefn)(struct hashobj *obj))
 {
+       struct hashobj *obj, *tmp, _obj;
        struct hash_bucket *bucket;
-       struct hashobj *obj, *tmp;
 
-       bucket = do_hash(t, key);
+       bucket = do_hash(t, key, len);
 
        push_cleanup_lock(&t->lock);
        write_lock(&t->lock);
 
        if (!list_empty(&bucket->obj_list)) {
+               _obj.key = key;
+               _obj.len = len;
                list_for_each_entry_safe(obj, tmp, &bucket->obj_list, link) {
-                       if (strcmp(obj->key, key) == 0) {
+                       if (t->compare(obj, &_obj) == 0) {
                                if (!probefn(obj)) {
                                        list_remove_init(&obj->link);
                                        continue;
@@ -290,7 +308,9 @@ out:
        return obj;
 }
 
-void pvhash_init(struct pvhash_table *t)
+void pvhash_init(struct pvhash_table *t,
+                int (*compare)(const struct pvhashobj *l,
+                               const struct pvhashobj *r))
 {
        pthread_mutexattr_t mattr;
        int n;
@@ -298,6 +318,7 @@ void pvhash_init(struct pvhash_table *t)
        for (n = 0; n < HASHSLOTS; n++)
                pvlist_init(&t->table[n].obj_list);
 
+       t->compare = compare;
        __RT(pthread_mutexattr_init(&mattr));
        __RT(pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT));
        __RT(pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_PRIVATE));
@@ -305,15 +326,16 @@ void pvhash_init(struct pvhash_table *t)
        __RT(pthread_mutexattr_destroy(&mattr));
 }
 
-static struct pvhash_bucket *do_pvhash(struct pvhash_table *t, const char *key)
+static struct pvhash_bucket *do_pvhash(struct pvhash_table *t,
+                                      const void *key, size_t len)
 {
-       unsigned int hash = __hash_key(key, strlen(key), 0);
+       unsigned int hash = __hash_key(key, len, 0);
        return &t->table[hash & (HASHSLOTS-1)];
 }
 
 int __pvhash_enter(struct pvhash_table *t,
-                  const char *key, struct pvhashobj *newobj,
-                  int nodup)
+                  const void *key, size_t len,
+                  struct pvhashobj *newobj, int nodup)
 {
        struct pvhash_bucket *bucket;
        struct pvhashobj *obj;
@@ -321,13 +343,13 @@ int __pvhash_enter(struct pvhash_table *t,
 
        pvholder_init(&newobj->link);
        newobj->key = key;
-       bucket = do_pvhash(t, key);
+       bucket = do_pvhash(t, key, len);
 
        write_lock_nocancel(&t->lock);
 
        if (nodup && !pvlist_empty(&bucket->obj_list)) {
                pvlist_for_each_entry(obj, &bucket->obj_list, link) {
-                       if (strcmp(obj->key, key) == 0) {
+                       if (t->compare(obj, newobj) == 0) {
                                ret = -EEXIST;
                                goto out;
                        }
@@ -347,7 +369,7 @@ int pvhash_remove(struct pvhash_table *t, struct pvhashobj 
*delobj)
        struct pvhashobj *obj;
        int ret = -ESRCH;
 
-       bucket = do_pvhash(t, delobj->key);
+       bucket = do_pvhash(t, delobj->key, delobj->len);
 
        write_lock_nocancel(&t->lock);
 
@@ -366,18 +388,21 @@ out:
        return __bt(ret);
 }
 
-struct pvhashobj *pvhash_search(struct pvhash_table *t, const char *key)
+struct pvhashobj *pvhash_search(struct pvhash_table *t,
+                               const void *key, size_t len)
 {
        struct pvhash_bucket *bucket;
-       struct pvhashobj *obj;
+       struct pvhashobj *obj, _obj;
 
-       bucket = do_pvhash(t, key);
+       bucket = do_pvhash(t, key, len);
 
        read_lock_nocancel(&t->lock);
 
        if (!pvlist_empty(&bucket->obj_list)) {
+               _obj.key = key;
+               _obj.len = len;
                pvlist_for_each_entry(obj, &bucket->obj_list, link) {
-                       if (strcmp(obj->key, key) == 0)
+                       if (t->compare(obj, &_obj) == 0)
                                goto out;
                }
        }
@@ -415,4 +440,10 @@ int pvhash_walk(struct pvhash_table *t,
        return 0;
 }
 
+int pvhash_compare_strings(const struct pvhashobj *l,
+                          const struct pvhashobj *r)
+{
+       return strcmp(l->key, r->key);
+}
+
 #endif /* CONFIG_XENO_PSHARED */
diff --git a/lib/copperplate/heapobj-pshared.c 
b/lib/copperplate/heapobj-pshared.c
index 9b28b97..b8308e0 100644
--- a/lib/copperplate/heapobj-pshared.c
+++ b/lib/copperplate/heapobj-pshared.c
@@ -198,7 +198,7 @@ static void init_main_heap(struct session_heap *m_heap, 
void *mem, size_t size)
        __RT(pthread_mutex_init(&m_heap->sysgroup.lock, &mattr));
        __RT(pthread_mutexattr_destroy(&mattr));
 
-       __hash_init(m_heap, &m_heap->catalog);
+       __hash_init(m_heap, &m_heap->catalog, hash_compare_strings);
        m_heap->sysgroup.thread_count = 0;
        __list_init(m_heap, &m_heap->sysgroup.thread_list);
        m_heap->sysgroup.heap_count = 0;
diff --git a/lib/copperplate/registry.c b/lib/copperplate/registry.c
index fd3661d..093113e 100644
--- a/lib/copperplate/registry.c
+++ b/lib/copperplate/registry.c
@@ -118,7 +118,7 @@ int registry_add_dir(const char *fmt, ...)
                if (path == basename)
                        basename++;
                *basename = '\0';
-               hobj = pvhash_search(&p->dirs, path);
+               hobj = pvhash_search(&p->dirs, path, strlen(path));
                if (hobj == NULL) {
                        ret = -ENOENT;
                        goto fail;
@@ -133,7 +133,7 @@ int registry_add_dir(const char *fmt, ...)
        pvlist_init(&d->dir_list);
        d->ndirs = d->nfiles = 0;
        d->ctime = now;
-       ret = pvhash_enter(&p->dirs, d->path, &d->hobj);
+       ret = pvhash_enter(&p->dirs, d->path, strlen(d->path), &d->hobj);
        if (ret) {
        fail:
                pvfree(d->path);
@@ -192,13 +192,14 @@ int registry_add_file(struct fsobj *fsobj, int mode, 
const char *fmt, ...)
 
        write_lock_safe(&p->lock, state);
 
-       ret = pvhash_enter(&p->files, fsobj->path, &fsobj->hobj);
+       ret = pvhash_enter(&p->files, fsobj->path, strlen(fsobj->path),
+                          &fsobj->hobj);
        if (ret)
                goto fail;
 
        *basename = '\0';
        dir = basename == path ? "/" : path;
-       hobj = pvhash_search(&p->dirs, dir);
+       hobj = pvhash_search(&p->dirs, dir, strlen(dir));
        if (hobj == NULL) {
        fail:
                pvhash_remove(&p->files, &fsobj->hobj);
@@ -269,7 +270,7 @@ static int regfs_getattr(const char *path, struct stat 
*sbuf)
 
        read_lock_nocancel(&p->lock);
 
-       hobj = pvhash_search(&p->dirs, path);
+       hobj = pvhash_search(&p->dirs, path, strlen(path));
        if (hobj) {
                d = container_of(hobj, struct regfs_dir, hobj);
                sbuf->st_mode = S_IFDIR | 0755;
@@ -280,7 +281,7 @@ static int regfs_getattr(const char *path, struct stat 
*sbuf)
                goto done;
        }
 
-       hobj = pvhash_search(&p->files, path);
+       hobj = pvhash_search(&p->files, path, strlen(path));
        if (hobj) {
                fsobj = container_of(hobj, struct fsobj, hobj);
                sbuf->st_mode = S_IFREG;
@@ -318,7 +319,7 @@ static int regfs_readdir(const char *path, void *buf, 
fuse_fill_dir_t filler,
 
        read_lock_nocancel(&p->lock);
 
-       hobj = pvhash_search(&p->dirs, path);
+       hobj = pvhash_search(&p->dirs, path, strlen(path));
        if (hobj == NULL) {
                read_unlock(&p->lock);
                return __bt(-ENOENT);
@@ -359,7 +360,7 @@ static int regfs_open(const char *path, struct 
fuse_file_info *fi)
 
        read_lock_nocancel(&p->lock);
 
-       hobj = pvhash_search(&p->files, path);
+       hobj = pvhash_search(&p->files, path, strlen(path));
        if (hobj == NULL) {
                ret = -ENOENT;
                goto done;
@@ -384,7 +385,7 @@ static int regfs_read(const char *path, char *buf, size_t 
size, off_t offset,
 
        read_lock_nocancel(&p->lock);
 
-       hobj = pvhash_search(&p->files, path);
+       hobj = pvhash_search(&p->files, path, strlen(path));
        if (hobj == NULL) {
                read_unlock(&p->lock);
                return __bt(-EIO);
@@ -416,7 +417,7 @@ static int regfs_write(const char *path, const char *buf, 
size_t size, off_t off
 
        read_lock_nocancel(&p->lock);
 
-       hobj = pvhash_search(&p->files, path);
+       hobj = pvhash_search(&p->files, path, strlen(path));
        if (hobj == NULL) {
                read_unlock(&p->lock);
                return __bt(-EIO);
@@ -616,8 +617,8 @@ int __registry_pkg_init(const char *arg0, char *mountpt)
        __RT(pthread_mutex_init(&p->lock, &mattr));
        __RT(pthread_mutexattr_destroy(&mattr));
 
-       pvhash_init(&p->files);
-       pvhash_init(&p->dirs);
+       pvhash_init(&p->files, pvhash_compare_strings);
+       pvhash_init(&p->dirs, pvhash_compare_strings);
 
        registry_add_dir("/");  /* Create the fs root. */
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to