From: Lucas De Marchi Date: Wed, 4 Jan 2012 10:19:34 +0000 (-0200) Subject: file: take a weakref to ctx X-Git-Tag: v3~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c68e92f73133d4220bc6dfe1ca960cf58da7a4b3;p=thirdparty%2Fkmod.git file: take a weakref to ctx --- diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c index 809c7cdd..4ea2a8dd 100644 --- a/libkmod/libkmod-file.c +++ b/libkmod/libkmod-file.c @@ -55,6 +55,7 @@ struct kmod_file { off_t size; void *memory; const struct file_ops *ops; + const struct kmod_ctx *ctx; }; #ifdef ENABLE_XZ @@ -261,7 +262,8 @@ static const struct file_ops reg_ops = { load_reg, unload_reg }; -struct kmod_file *kmod_file_open(const char *filename) +struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, + const char *filename) { struct kmod_file *file = calloc(1, sizeof(struct kmod_file)); const struct comp_type *itr; @@ -312,6 +314,7 @@ struct kmod_file *kmod_file_open(const char *filename) file->ops = ®_ops; err = file->ops->load(file); + file->ctx = ctx; error: if (err < 0) { if (file->fd >= 0) diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index b0cee364..12797593 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -762,7 +762,7 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, return -ENOSYS; } - file = kmod_file_open(path); + file = kmod_file_open(mod->ctx, path); if (file == NULL) { err = -errno; return err; @@ -1938,7 +1938,7 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_ if (path == NULL) return -ENOENT; - file = kmod_file_open(path); + file = kmod_file_open(mod->ctx, path); if (file == NULL) return -errno; @@ -2116,7 +2116,7 @@ KMOD_EXPORT int kmod_module_get_versions(const struct kmod_module *mod, struct k if (path == NULL) return -ENOENT; - file = kmod_file_open(path); + file = kmod_file_open(mod->ctx, path); if (file == NULL) return -errno; @@ -2281,7 +2281,7 @@ KMOD_EXPORT int kmod_module_get_symbols(const struct kmod_module *mod, struct km if (path == NULL) return -ENOENT; - file = kmod_file_open(path); + file = kmod_file_open(mod->ctx, path); if (file == NULL) return -errno; @@ -2449,7 +2449,7 @@ KMOD_EXPORT int kmod_module_get_dependency_symbols(const struct kmod_module *mod if (path == NULL) return -ENOENT; - file = kmod_file_open(path); + file = kmod_file_open(mod->ctx, path); if (file == NULL) return -errno; diff --git a/libkmod/libkmod-private.h b/libkmod/libkmod-private.h index 71f8c206..cdeaee57 100644 --- a/libkmod/libkmod-private.h +++ b/libkmod/libkmod-private.h @@ -140,7 +140,7 @@ void kmod_module_set_remove_commands(struct kmod_module *mod, const char *cmd) _ #include "libkmod-hash.h" /* libkmod-file.c */ -struct kmod_file *kmod_file_open(const char *filename) __must_check __attribute__((nonnull(1))); +struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) __must_check __attribute__((nonnull(1,2))); void *kmod_file_get_contents(const struct kmod_file *file) __must_check __attribute__((nonnull(1))); off_t kmod_file_get_size(const struct kmod_file *file) __must_check __attribute__((nonnull(1))); void kmod_file_unref(struct kmod_file *file) __attribute__((nonnull(1)));