1# Copyright (C) 2012 W. Trevor King <wking@tremily.us>
2#
3# This file is part of python-kmod.
4#
5# python-kmod is free software: you can redistribute it and/or modify it under
6# the terms of the GNU Lesser General Public License version 2.1 as published
7# by the Free Software Foundation.
8#
9# python-kmod is distributed in the hope that it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
12# details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with python-kmod.  If not, see <http://www.gnu.org/licenses/>.
16
17cimport libc.stdint as _stdint
18
19
20cdef extern from *:
21    ctypedef char* const_char_ptr 'const char *'
22    ctypedef char* const_char_const_ptr 'const char const *'
23    ctypedef void* const_void_ptr 'const void *'
24
25
26cdef extern from 'stdbool.h':
27    ctypedef struct bool:
28        pass
29
30
31cdef extern from 'libkmod/libkmod.h':
32    # library user context - reads the config and system
33    # environment, user variables, allows custom logging
34    cdef struct kmod_ctx:
35        pass
36
37    kmod_ctx *kmod_new(
38        const_char_ptr dirname, const_char_const_ptr config_paths)
39    kmod_ctx *kmod_ref(kmod_ctx *ctx)
40    kmod_ctx *kmod_unref(kmod_ctx *ctx)
41
42    # Management of libkmod's resources
43    int kmod_load_resources(kmod_ctx *ctx)
44    void kmod_unload_resources(kmod_ctx *ctx)
45
46    # access to kmod generated lists
47    cdef struct kmod_list:
48        pass
49    ctypedef kmod_list* const_kmod_list_ptr 'const struct kmod_list *'
50    kmod_list *kmod_list_next(
51        const_kmod_list_ptr list, const_kmod_list_ptr curr)
52    kmod_list *kmod_list_prev(
53        const_kmod_list_ptr list, const_kmod_list_ptr curr)
54    kmod_list *kmod_list_last(const_kmod_list_ptr list)
55
56    # Operate on kernel modules
57    cdef struct kmod_module:
58        pass
59    ctypedef kmod_module* const_kmod_module_ptr 'const struct kmod_module *'
60    int kmod_module_new_from_name(
61        kmod_ctx *ctx, const_char_ptr name, kmod_module **mod)
62    int kmod_module_new_from_lookup(
63        kmod_ctx *ctx, const_char_ptr given_alias, kmod_list **list)
64    int kmod_module_new_from_loaded(kmod_ctx *ctx, kmod_list **list)
65
66    kmod_module *kmod_module_ref(kmod_module *mod)
67    kmod_module *kmod_module_unref(kmod_module *mod)
68    int kmod_module_unref_list(kmod_list *list)
69    kmod_module *kmod_module_get_module(kmod_list *entry)
70
71    # Flags to kmod_module_probe_insert_module
72    # codes below can be used in return value, too
73    enum: KMOD_PROBE_APPLY_BLACKLIST
74
75    #ctypedef int (*install_callback_t)(
76    #    kmod_module *m, const_char_ptr cmdline, const_void_ptr data)
77    #ctypedef void (*print_action_callback_t)(
78    #    kmod_module *m, bool install, const_char_ptr options)
79
80    int kmod_module_remove_module(
81        kmod_module *mod, unsigned int flags)
82    int kmod_module_insert_module(
83        kmod_module *mod, unsigned int flags, const_char_ptr options)
84    int kmod_module_probe_insert_module(
85        kmod_module *mod, unsigned int flags, const_char_ptr extra_options,
86        int (*run_install)(
87            kmod_module *m, const_char_ptr cmdline, void *data),
88        const_void_ptr data,
89        void (*print_action)(
90            kmod_module *m, bool install, const_char_ptr options),
91        )
92
93    const_char_ptr kmod_module_get_name(const_kmod_module_ptr mod)
94    const_char_ptr kmod_module_get_path(const_kmod_module_ptr mod)
95    const_char_ptr kmod_module_get_options(const_kmod_module_ptr mod)
96    const_char_ptr kmod_module_get_install_commands(const_kmod_module_ptr mod)
97    const_char_ptr kmod_module_get_remove_commands(const_kmod_module_ptr mod)
98
99    # Information regarding "live information" from module's state, as
100    # returned by kernel
101    int kmod_module_get_refcnt(const_kmod_module_ptr mod)
102    long kmod_module_get_size(const_kmod_module_ptr mod)
103
104    # Information retrieved from ELF headers and section
105    int kmod_module_get_info(const_kmod_module_ptr mod, kmod_list **list)
106    const_char_ptr kmod_module_info_get_key(const_kmod_list_ptr entry)
107    const_char_ptr kmod_module_info_get_value(const_kmod_list_ptr entry)
108    void kmod_module_info_free_list(kmod_list *list)
109
110    int kmod_module_get_versions(const_kmod_module_ptr mod, kmod_list **list)
111    const_char_ptr kmod_module_version_get_symbol(const_kmod_list_ptr entry)
112    _stdint.uint64_t kmod_module_version_get_crc(const_kmod_list_ptr entry)
113    void kmod_module_versions_free_list(kmod_list *list)
114