"base_fs.c",
"perms.c",
"basefs_allocator.c",
- "hashmap.c",
],
target: {
host: {
base_fs.c \
perms.c \
basefs_allocator.c \
- hashmap.c \
e2fsdroid_cflags := -W -Wall -Werror -Wno-error=macro-redefined
}
}
-struct hashmap *basefs_parse(const char *file, const char *mountpoint)
+struct ext2fs_hashmap *basefs_parse(const char *file, const char *mountpoint)
{
int err;
- struct hashmap *entries = NULL;
+ struct ext2fs_hashmap *entries = NULL;
struct basefs_entry *entry;
FILE *f = basefs_open(file);
if (!f)
return NULL;
- entries = hashmap_create(djb2_hash, free_base_fs_entry, 1024);
+ entries = ext2fs_hashmap_create(ext2fs_djb2_hash, free_base_fs_entry, 1024);
if (!entries)
goto end;
while ((entry = basefs_readline(f, mountpoint, &err)))
- hashmap_add(entries, entry, entry->path);
+ ext2fs_hashmap_add(entries, entry, entry->path,
+ strlen(entry->path));
if (err) {
fclose(f);
- hashmap_free(entries);
+ ext2fs_hashmap_free(entries);
return NULL;
}
end:
extern struct fsmap_format base_fs_format;
-struct hashmap *basefs_parse(const char *file, const char *mountpoint);
+struct ext2fs_hashmap *basefs_parse(const char *file, const char *mountpoint);
#endif /* !BASE_FS_H */
#include "base_fs.h"
struct base_fs_allocator {
- struct hashmap *entries;
+ struct ext2fs_hashmap *entries;
struct basefs_entry *cur_entry;
};
{
errcode_t retval;
struct basefs_entry *e;
- struct hashmap_entry *it = NULL;
+ struct ext2fs_hashmap_entry *it = NULL;
struct base_fs_allocator *allocator;
- struct hashmap *entries = basefs_parse(file, mountpoint);
+ struct ext2fs_hashmap *entries = basefs_parse(file, mountpoint);
if (!entries)
return -1;
retval = ext2fs_read_bitmaps(fs);
if (retval)
goto err_bitmap;
- while ((e = hashmap_iter_in_order(entries, &it)))
+ while ((e = ext2fs_hashmap_iter_in_order(entries, &it)))
fs_reserve_blocks_range(fs, e->head);
allocator->cur_entry = NULL;
err_bitmap:
free(allocator);
err_alloc:
- hashmap_free(entries);
+ ext2fs_hashmap_free(entries);
return EXIT_FAILURE;
}
void base_fs_alloc_cleanup(ext2_filsys fs)
{
struct basefs_entry *e;
- struct hashmap_entry *it = NULL;
+ struct ext2fs_hashmap_entry *it = NULL;
struct base_fs_allocator *allocator = fs->priv_data;
- while ((e = hashmap_iter_in_order(allocator->entries, &it))) {
+ while ((e = ext2fs_hashmap_iter_in_order(allocator->entries, &it))) {
fs_free_blocks_range(fs, e->head);
delete_block_ranges(e->head);
e->head = e->tail = NULL;
fs->priv_data = NULL;
fs->get_alloc_block2 = NULL;
- hashmap_free(allocator->entries);
+ ext2fs_hashmap_free(allocator->entries);
free(allocator);
}
return 0;
if (allocator)
- allocator->cur_entry = hashmap_lookup(allocator->entries,
- target_path);
+ allocator->cur_entry = ext2fs_hashmap_lookup(allocator->entries,
+ target_path,
+ strlen(target_path));
return 0;
}
+++ /dev/null
-#include "hashmap.h"
-#include <string.h>
-
-uint32_t djb2_hash(const void *str)
-{
- int c;
- const char *s = str;
- uint32_t hash = 5381;
-
- while ((c = *s++))
- hash = ((hash << 5) + hash) + c;
- return hash;
-}
-
-struct hashmap *hashmap_create(uint32_t(*hash_fct)(const void*),
- void(*free_fct)(void*), size_t size)
-{
- struct hashmap *h = calloc(sizeof(struct hashmap) +
- sizeof(struct hashmap_entry) * size, 1);
- h->size = size;
- h->free = free_fct;
- h->hash = hash_fct;
- h->first = h->last = NULL;
- return h;
-}
-
-void hashmap_add(struct hashmap *h, void *data, const void *key)
-{
- uint32_t hash = h->hash(key) % h->size;
- struct hashmap_entry *e = malloc(sizeof(*e));
-
- e->data = data;
- e->key = key;
- e->next = h->entries[hash];
- h->entries[hash] = e;
-
- e->list_prev = NULL;
- e->list_next = h->first;
- if (h->first)
- h->first->list_prev = e;
- h->first = e;
- if (!h->last)
- h->last = e;
-}
-
-void *hashmap_lookup(struct hashmap *h, const void *key)
-{
- struct hashmap_entry *iter;
- uint32_t hash = h->hash(key) % h->size;
-
- for (iter = h->entries[hash]; iter; iter = iter->next)
- if (!strcmp(iter->key, key))
- return iter->data;
- return NULL;
-}
-
-void *hashmap_iter_in_order(struct hashmap *h, struct hashmap_entry **it)
-{
- *it = *it ? (*it)->list_next : h->first;
- return *it ? (*it)->data : NULL;
-}
-
-void hashmap_free(struct hashmap *h)
-{
- for (size_t i = 0; i < h->size; ++i) {
- struct hashmap_entry *it = h->entries[i];
- while (it) {
- struct hashmap_entry *tmp = it->next;
- if (h->free)
- h->free(it->data);
- free(it);
- it = tmp;
- }
- }
- free(h);
-}
+++ /dev/null
-#ifndef HASHMAP_H
-# define HASHMAP_H
-
-# include <stdlib.h>
-# include <stdint.h>
-
-struct hashmap {
- uint32_t size;
- uint32_t(*hash)(const void *key);
- void(*free)(void*);
- struct hashmap_entry *first;
- struct hashmap_entry *last;
- struct hashmap_entry {
- void *data;
- const void *key;
- struct hashmap_entry *next;
- struct hashmap_entry *list_next;
- struct hashmap_entry *list_prev;
- } *entries[0];
-};
-
-struct hashmap *hashmap_create(uint32_t(*hash_fct)(const void*),
- void(*free_fct)(void*), size_t size);
-void hashmap_add(struct hashmap *h, void *data, const void *key);
-void *hashmap_lookup(struct hashmap *h, const void *key);
-void *hashmap_iter_in_order(struct hashmap *h, struct hashmap_entry **it);
-void hashmap_del(struct hashmap *h, struct hashmap_entry *e);
-void hashmap_free(struct hashmap *h);
-
-uint32_t djb2_hash(const void *str);
-
-#endif /* !HASHMAP_H */
#include "config.h"
#include <stdlib.h>
#include <string.h>
+#include <stdint.h>
#include "blkidP.h"
"get_pathname.c",
"getsize.c",
"getsectsize.c",
+ "hashmap.c",
"i_block.c",
"icount.c",
"imager.c",
get_pathname.o \
getsize.o \
getsectsize.o \
+ hashmap.o \
i_block.o \
icount.o \
ind_block.o \
$(srcdir)/get_pathname.c \
$(srcdir)/getsize.c \
$(srcdir)/getsectsize.c \
+ $(srcdir)/hashmap.c \
$(srcdir)/i_block.c \
$(srcdir)/icount.c \
$(srcdir)/ind_block.c \
--- /dev/null
+#include "hashmap.h"
+#include <string.h>
+
+uint32_t ext2fs_djb2_hash(const void *str, size_t size)
+{
+ int c;
+ const char *s = str;
+ uint32_t hash = 5381;
+
+ while (size-- > 0) {
+ c = *s++;
+ hash = ((hash << 5) + hash) + c;
+ }
+ return hash;
+}
+
+struct ext2fs_hashmap *ext2fs_hashmap_create(
+ uint32_t(*hash_fct)(const void*, size_t),
+ void(*free_fct)(void*), size_t size)
+{
+ struct ext2fs_hashmap *h = calloc(sizeof(struct ext2fs_hashmap) +
+ sizeof(struct ext2fs_hashmap_entry) * size, 1);
+ h->size = size;
+ h->free = free_fct;
+ h->hash = hash_fct;
+ h->first = h->last = NULL;
+ return h;
+}
+
+void ext2fs_hashmap_add(struct ext2fs_hashmap *h, void *data, const void *key,
+ size_t key_len)
+{
+ uint32_t hash = h->hash(key, key_len) % h->size;
+ struct ext2fs_hashmap_entry *e = malloc(sizeof(*e));
+
+ e->data = data;
+ e->key = key;
+ e->key_len = key_len;
+ e->next = h->entries[hash];
+ h->entries[hash] = e;
+
+ e->list_prev = NULL;
+ e->list_next = h->first;
+ if (h->first)
+ h->first->list_prev = e;
+ h->first = e;
+ if (!h->last)
+ h->last = e;
+}
+
+void *ext2fs_hashmap_lookup(struct ext2fs_hashmap *h, const void *key,
+ size_t key_len)
+{
+ struct ext2fs_hashmap_entry *iter;
+ uint32_t hash = h->hash(key, key_len) % h->size;
+
+ for (iter = h->entries[hash]; iter; iter = iter->next)
+ if (iter->key_len == key_len && !memcmp(iter->key, key, key_len))
+ return iter->data;
+ return NULL;
+}
+
+void *ext2fs_hashmap_iter_in_order(struct ext2fs_hashmap *h,
+ struct ext2fs_hashmap_entry **it)
+{
+ *it = *it ? (*it)->list_next : h->first;
+ return *it ? (*it)->data : NULL;
+}
+
+void ext2fs_hashmap_free(struct ext2fs_hashmap *h)
+{
+ for (size_t i = 0; i < h->size; ++i) {
+ struct ext2fs_hashmap_entry *it = h->entries[i];
+ while (it) {
+ struct ext2fs_hashmap_entry *tmp = it->next;
+ if (h->free)
+ h->free(it->data);
+ free(it);
+ it = tmp;
+ }
+ }
+ free(h);
+}
--- /dev/null
+#ifndef HASHMAP_H
+# define HASHMAP_H
+
+# include <stdlib.h>
+# include <stdint.h>
+
+struct ext2fs_hashmap {
+ uint32_t size;
+ uint32_t(*hash)(const void *key, size_t len);
+ void(*free)(void*);
+ struct ext2fs_hashmap_entry *first;
+ struct ext2fs_hashmap_entry *last;
+ struct ext2fs_hashmap_entry {
+ void *data;
+ const void *key;
+ size_t key_len;
+ struct ext2fs_hashmap_entry *next;
+ struct ext2fs_hashmap_entry *list_next;
+ struct ext2fs_hashmap_entry *list_prev;
+ } *entries[0];
+};
+
+struct ext2fs_hashmap *ext2fs_hashmap_create(
+ uint32_t(*hash_fct)(const void*, size_t),
+ void(*free_fct)(void*), size_t size);
+void ext2fs_hashmap_add(struct ext2fs_hashmap *h, void *data, const void *key,
+ size_t key_len);
+void *ext2fs_hashmap_lookup(struct ext2fs_hashmap *h, const void *key,
+ size_t key_len);
+void *ext2fs_hashmap_iter_in_order(struct ext2fs_hashmap *h,
+ struct ext2fs_hashmap_entry **it);
+void ext2fs_hashmap_del(struct ext2fs_hashmap *h,
+ struct ext2fs_hashmap_entry *e);
+void ext2fs_hashmap_free(struct ext2fs_hashmap *h);
+
+uint32_t ext2fs_djb2_hash(const void *str, size_t size);
+
+#endif /* !HASHMAP_H */