clinuxversionlinux-device-driver

Obtain kernel module version from userspace


I'm writing a set of programs to run performance tests on a hardware device. I would like to be able to save version information for each of those subprograms inside of my main 'controller' program, so that it can be saved inside the test report. One of these subprograms is a simple kernel driver.

I know Linux kernel modules can expose version information using the MODULE_VERSION macro. This property can subsequently be read using modinfo on the command line.

Would it possible to access this information inside a C userspace program, and if so, how ?

I thought about exposing the version inside a character device from which I could read, but given the module file contains that information, it would be much more convenient to read that directly.


Solution

  • The version string of the loaded module should be in /sys/module/<modulename>/version if it exists (where <modulename> is the name of the module, with hyphens replaced with underscores). You can read the contents of that file using C standard I/O functions or POSIX file I/O functions. There may also be a srcversion file that contains a 23 hex digit string constructed from 92 bits of the 128 bit MD4 sum of the source code.