I have a kernel module which has a structure like this:
struct test {
int a;
int b;
.....
}
I have created an array of instances of this struct as:
struct test foo[8];
I want to export this structure or the array "foo" using EXPORT_SYMBOL
and access foo[0].a
in other kernel module.
I tried EXPORT_SYMBOL(foo);
from the provider module and extern struct test * foo;
in the receiver module but I am unable to access the variable. Please point where am I making mistake.
Here is some more of the code:
Kernel Module 1:
#include <....>
#include "test_config.h"
....
MODULE_LICENSE("GPL");
struct test {
int a;
int b;
.....
}
test_t foo[8];
//EXPORT_SYMBOL(foo);
/*Code to create sysctl variables out of these members of the struct test*/
int init_module(void)
{
printk(KERN_INFO "Hello World\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye Cruel World\n");
}
Kerne Module 2:
#include <linux/module.h>
#include <linux/kernel.h>
#include "test_config.h"
int init_module(void)
{
test_t foo[8];
printk ("Value of foo is :: %d\n", foo[0].a);
foo[0].a++;
printk(KERN_INFO "Hello Again World\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye Again Cruel World\n");
}
Here is the header file with the structure definition:
#ifndef __TEST_CONFIG
#define __TEST_CONFIG
typedef struct test
{
int a;
int b
int c;
int d;
float e;
}test_t;
#endif