From: Lucas De Marchi Date: Thu, 8 Dec 2011 17:10:55 +0000 (-0200) Subject: index: mm: Add flag to open call to populate buffer X-Git-Tag: v1~55^2~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5109f2b422144c33e9f60d86d7189baef3cab57a;p=thirdparty%2Fkmod.git index: mm: Add flag to open call to populate buffer --- diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index bfabd10d..ce4ad6aa 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 ae44b25e..a6aba5e8 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);