Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Version 0.1.10
  • Loading branch information
cnanakos committed Sep 11, 2014
0 parents commit 18125d8
Show file tree
Hide file tree
Showing 13 changed files with 1,658 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
MANIFEST
*.pyc
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kmodpy was written by:
Chrysostomos Nanakos <[email protected]>
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include AUTHORS
include COPYING
recursive-include kmodpy *.py
33 changes: 33 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
kmodpy
------

The libkmod2 is a library that provides an API for insertion, removal,
configuration and listing of kernel modules.

kmodpy is a Python ctypes wrapper module for libkmod, exposing common module
operations: listing of installed modules, modprobe, modinfo, show_depends and
rmmod.

Follows an example executed as root:

::

>>> import kmodpy
>>> km = kmodpy.Kmod()
>>> [m for m in km.list()]
[(u'nfs', 407706),
(u'nfs_acl', 12741)
...
(u'virtio_blk', 17549)]
>>> km.modprobe("loop", extra_options="max_loop=8")
>>> km.rmmod("loop")
>>> list(km.modinfo("loop"))
[('alias', 'char-major-10-237'), ('alias', 'block-major-7-*'),
('license', 'GPL'), ('parm', 'max_part:Maximum number of
partitions per loop device'), ('parmtype', 'max_part:int'),
('parm', 'max_loop:Maximum number of loop
devices'), ('parmtype', 'max_loop:int'), ('depends', ''),
('intree', 'Y'), ('vermagic', '3.12-1-amd64 SMP mod_unload
modversions '), ('alias', 'devname:loop-control')]
>>> list(km.show_depends("ext4"))
['mbcache', 'crc16', 'jbd2']
1 change: 1 addition & 0 deletions README.rst
25 changes: 25 additions & 0 deletions kmodpy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (C) 2014 Chrysostomos Nanakos <[email protected]>
#
# This file is part of kmodpy.
#
# kmodpy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with kmodpy. If not, see <http://www.gnu.org/licenses/>.


"Python interface to kmod API"

from .version import __version__
try:
from .kmod import Kmod
except ImportError:
pass
100 changes: 100 additions & 0 deletions kmodpy/_libkmod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright (C) 2014 Chrysostomos Nanakos <[email protected]>
#
# This file is part of kmodpy.
#
# kmodpy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with kmodpy. If not, see <http://www.gnu.org/licenses/>.


from ctypes import *
from ctypes.util import find_library
from _libkmod_h import *

libkmod = find_library("kmod")
if libkmod is None:
raise OSError("Could not load libkmod dynamic library")

kmod = cdll.LoadLibrary(libkmod)

kmod_new = kmod.kmod_new
kmod_new.argtypes = [c_char_p, c_char_p]
kmod_new.restype = POINTER(kmod_ctx)

kmod_load_resources = kmod.kmod_load_resources
kmod_load_resources.argtypes = [POINTER(kmod_ctx)]
kmod_load_resources.restype = c_int

kmod_module_new_from_loaded = kmod.kmod_module_new_from_loaded
kmod_module_new_from_loaded.argtypes = [POINTER(kmod_ctx), POINTER(POINTER(kmod_list))]
kmod_module_new_from_loaded.restype = c_int

kmod_module_get_module = kmod.kmod_module_get_module
kmod_module_get_module.argtypes = [POINTER(kmod_list)]
kmod_module_get_module.restype = POINTER(kmod_module)

kmod_module_get_name = kmod.kmod_module_get_name
kmod_module_get_name.argtypes = [POINTER(kmod_module)]
kmod_module_get_name.restype = c_char_p

kmod_module_unref = kmod.kmod_module_unref
kmod_module_unref.argtypes = [POINTER(kmod_module)]

kmod_module_get_refcnt = kmod.kmod_module_get_refcnt
kmod_module_get_refcnt.argtypes = [POINTER(kmod_module)]
kmod_module_get_refcnt.restype = c_int

kmod_module_get_size = kmod.kmod_module_get_size
kmod_module_get_size.argtypes = [POINTER(kmod_module)]
kmod_module_get_size.restype = c_long

kmod_module_new_from_lookup = kmod.kmod_module_new_from_lookup
kmod_module_new_from_lookup.argtypes = [POINTER(kmod_ctx), c_char_p,
POINTER(POINTER(kmod_list))]
kmod_module_new_from_lookup.restype = c_int

kmod_module_insert_module = kmod.kmod_module_insert_module
kmod_module_insert_module.argtypes = [POINTER(kmod_module), c_uint32, c_char_p]
kmod_module_insert_module.restype = c_int

kmod_module_remove_module = kmod.kmod_module_remove_module
kmod_module_remove_module.argtypes = [POINTER(kmod_module), c_uint32]
kmod_module_remove_module.restype = c_int

kmod_module_get_info = kmod.kmod_module_get_info
kmod_module_get_info.argtypes = [POINTER(kmod_module),
POINTER(POINTER(kmod_list))]
kmod_module_get_info.restype = c_int

kmod_module_info_get_key = kmod.kmod_module_info_get_key
kmod_module_info_get_key.argtypes = [POINTER(kmod_list)]
kmod_module_info_get_key.restype = c_char_p

kmod_module_info_get_value = kmod.kmod_module_info_get_value
kmod_module_info_get_value.argtypes = [POINTER(kmod_list)]
kmod_module_info_get_value.restype = c_char_p

kmod_module_info_free_list = kmod.kmod_module_info_free_list
kmod_module_info_free_list.argtypes = [POINTER(kmod_list)]

kmod_module_get_dependencies = kmod.kmod_module_get_dependencies
kmod_module_get_dependencies.argtypes = [POINTER(kmod_module)]
kmod_module_get_dependencies.restype = POINTER(kmod_list)

__all__ = ['kmod_new', 'kmod_load_resources', 'kmod_module_new_from_loaded',
'kmod_module_get_module', 'kmod_module_get_name',
'kmod_module_unref', 'kmod_module_get_refcnt',
'kmod_module_get_size', 'kmod_module_new_from_lookup',
'kmod_module_insert_module', 'kmod_module_remove_module',
'kmod_ctx', 'kmod_list', 'kmod_module_get_info',
'kmod_module_info_get_key', 'kmod_module_info_get_value',
'kmod_module_info_free_list', 'kmod_module_get_dependencies']
Loading

0 comments on commit 18125d8

Please sign in to comment.