Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6502

How to share data-structure definition between kernel modules and user-application?

$
0
0

I would like to develop a device-driver on linux(written in C) and a user-space library wrapping all functions provided by my device-driver (also written in C). Just to make it more clear, my library wil provide the following methods:

  • int myOpen();
  • void myClose();
  • mySetConf(MyconfStruct conf)
  • etc.

The function will use the file associated to my device-driver, in particular:

  • myOpen will call the open() of my device-driver
  • myClose will call the close() of my device-driver
  • mySetConf will call the ioctl() of my device driver and pass the myConfStruct as a parameter to configure the device-driver using ioctl().

assume myConfStruct is a simple structure containing something like this:

typedef struct {    uint16_t var1;    uint8_t var2;} myConfStruct;

I would like the myConfStruct to be a structure shared between both my user-application (library) and my kernel-driver using a single header.Are there any best-practice while doing this?I would like to have the structure defined into only one file, having it defined in multiple files seems to be quite error-prone if i plan on changing it in the future, but I understood that I should not include <linux/types.h> inside my user files and I shouldn't use <stdint.h> inside my device-driver.So another question is also, how can I define the interface between a module and the user-application so that who is implementing the application is not forced to include any linux header?


Viewing all articles
Browse latest Browse all 6502

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>