diff options
author | Lucas De Marchi <lucas.demarchi@profusion.mobi> | 2011-12-08 15:10:55 -0200 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@profusion.mobi> | 2011-12-08 19:51:06 -0200 |
commit | 5109f2b422144c33e9f60d86d7189baef3cab57a (patch) | |
tree | 4f2fc9e4264e14881562a65386419139fd9abb4b /libkmod | |
parent | a4a750297d9ae0e1926c0f106b955b841b38a4b3 (diff) | |
download | kmod-5109f2b422144c33e9f60d86d7189baef3cab57a.tar.gz |
index: mm: Add flag to open call to populate buffer
Diffstat (limited to 'libkmod')
-rw-r--r-- | libkmod/libkmod-index.c | 13 | ||||
-rw-r--r-- | libkmod/libkmod-index.h | 3 |
2 files changed, 11 insertions, 5 deletions
diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index bfabd10..ce4ad6a 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -654,9 +654,11 @@ static void index_mm_free_node(struct index_mm_node *node) free(node); } -struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename) +struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, + bool populate) { int fd; + int flags; struct stat st; struct index_mm *idx; struct { @@ -681,9 +683,12 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename) goto fail; } - if ((idx->mm = mmap(0, st.st_size, PROT_READ, - MAP_PRIVATE | MAP_POPULATE, - fd, 0)) == MAP_FAILED) { + flags = MAP_PRIVATE; + if (populate) + flags |= MAP_POPULATE; + + if ((idx->mm = mmap(0, st.st_size, PROT_READ, flags, fd, 0)) + == MAP_FAILED) { ERR(ctx, "%m\n"); goto fail; } diff --git a/libkmod/libkmod-index.h b/libkmod/libkmod-index.h index ae44b25..a6aba5e 100644 --- a/libkmod/libkmod-index.h +++ b/libkmod/libkmod-index.h @@ -167,7 +167,8 @@ void index_values_free(struct index_value *values); /* Implementation using mmap */ struct index_mm; -struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename); +struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, + bool populate); void index_mm_close(struct index_mm *index); char *index_mm_search(struct index_mm *idx, const char *key); struct index_value *index_mm_searchwild(struct index_mm *idx, const char *key); |