Translation of C struct to D
Michael Kremser
mkspamx-usenet at yahoo.de
Mon Nov 14 12:54:28 PST 2011
Hi!
I currently try to create a simple linux driver (for test purposes) just
like in [1] in D based on [2]. The main difficulty is to call
register_chrdev. It expects an argument "fops" of type file_operations
which can look like that in C:
static struct file_operations fops = {
.read = device_read,
.write = device_write,
.open = device_open,
.release = device_release
};
device_read and so on are functions. Originally, file_operations has
much more fields and it's possible to omit unused fields.
What I tried so far: I declared "register_chrdev" as follows:
extern (C):
int register_chrdev (uint major, char *name, file_operations *fops);
My try for the translation of file_operations looks like that:
struct file_operations {
int function() open;
int function() release;
};
In init_module() I have the following code:
char[] DEVICE_NAME = "dtestdev";
file_operations fops;
fops.open = &device_open;
fops.release = &device_close;
Major = register_chrdev(0, std.string.toStringz(DEVICE_NAME), &fops);
The code compiles with some warnings, and if I try to insert it into the
kernel, I get some messages in the kernel log.
WARNING: "_D3std6string9toStringzFAaZPa" [...../hello.ko] undefined!
WARNING: "_Dmodule_ref" [...../hello.ko] undefined!
WARNING: "_D15TypeInfo_Struct6__vtblZ" [...../hello.ko] undefined!
WARNING: "register_chrdev" [...../hello.ko] undefined!
WARNING: "_D3std6string12__ModuleInfoZ" [...../hello.ko] undefined!
Nov 14 21:12:39 eeepc1104 kernel: [17127.068990] hello: Unknown symbol
_D3std6string12__ModuleInfoZ (err 0)
Nov 14 21:12:39 eeepc1104 kernel: [17127.069613] hello: Unknown symbol
register_chrdev (err 0)
Nov 14 21:12:39 eeepc1104 kernel: [17127.070462] hello: Unknown symbol
_D15TypeInfo_Struct6__vtblZ (err 0)
Nov 14 21:12:39 eeepc1104 kernel: [17127.071359] hello: Unknown symbol
_Dmodule_ref (err 0)
Nov 14 21:12:39 eeepc1104 kernel: [17127.072352] hello: Unknown symbol
_D3std6string9toStringzFAaZPa (err 0)
Any help greatly appreciated.
Greetings
Michael
[1] http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html#AEN680
[2]
http://iainbuclaw.wordpress.com/2010/05/22/writing-a-linux-kernel-module-in-d/
More information about the Digitalmars-d
mailing list