I see, the linker was trying to link your function (which is in a module and invisible to make) try function pointer: in fs/readdir.c define a global func pointer: void (*mytestPath)(); Then struct module *find_module(const char *YourDriverModuleName) if(module != NULL && mytestPath != NULL) { mytestPath(); } And then in your module: extern void (*mytestPath)(); module_init() { mytestPath=testPath; } 2009/11/11 Sam Carter <sam.w.carter@xxxxxxxxx>: > Sorry to ask again folks, but this is proving to be a nightmare. > > I need to call a function in a module I've made. I need to do this from the > file readdir.c in the kernel. At the moment, the module is a single file > which I've used insmod and rmmod to test. In it is the implementation of my > function 'testPath'. I also have a header file which has an empty > declaration of my function. The header file I have put in the fs/ directory > so it is in the same folder as the readdir.c file. > > So I'm lead to understand, in readdir.c, in the kernel, before compiling the > kernel, I need to add - > within fs/readdir.c > # include<YourCharDriver.H> > > at the top, under the existing include statements. In the same file, within > the syscall I'm modifying, I need to put - > struct module *find_module(const char *YourDriverModuleName) > if(module != NULL) > { > testPath(); > } > > This should test if my module is currently loaded, and if it is it will call > my testPath() function. > > Obviously I've used file names which actually reflect what my files are > called. The error happens when I try to compile the kernel with my changes > with a simple 'make'. Is that header file in the right place, and if it is, > then what would be causing the 'undefined reference to testPath, why am I > getting this when it all makes sense? > > Additionally, I've tried declaring the function as extern under the includes > in readdir.c, however this yields the same error. Although it seemingly > happens a little sooner into the kernel compilation procedure. > > Thanks again guys, all this help is appreciated! > > 2009/11/10 Pulkit Goel <vipulkit.goel@xxxxxxxxx> >> >> Hi, >> Mention at the top but after header file in readdir.c::: >> >> ..Heder file <> >> extern returntype YourDriverFunctionName(arg list); >> all other code.. >> >> >> >> Regards: >> Pulkit Goel >> mail:vipulkit.goel@xxxxxxxxx >> >> >> >> On Tue, Nov 10, 2009 at 4:41 PM, Sam Carter <sam.w.carter@xxxxxxxxx> >> wrote: >>> >>> Hi again Pulkit, may I ask you where exactly the kernel code section of >>> your reply belongs? I've put the extern part into readdir.c, but I still get >>> an error that it can't find the line inside the if statement you mentioned. >>> Help is appreciated, thanks :) >>> >>> 2009/11/9 Pulkit Goel <vipulkit.goel@xxxxxxxxx> >>>> >>>> Hi, >>>> >>>> Add In Kernel Code:: >>>> >>>> # include<YourCharDriver.H> >>>> OR >>>> extern YourDriverFunctionName(); >>>> >>>> :::::from this Driver Function declaration Comes in Kernel Code >>>> >>>> >>>> Add In Driver Code:: >>>> >>>> EXPORT_SYMBOL_GPL(YourDriverFunctionName); >>>> >>>> Calling Method in ""fs/readdir.c"" :: >>>> >>>> struct module *find_module(const char *YourDriverModuleName) >>>> if(module != NULL) >>>> { >>>> YourDriverFunctionName(); >>>> } >>>> >>>> >>>> >>>> >>>> Regards: >>>> Pulkit Goel >>>> mail:vipulkit.goel@xxxxxxxxx >>>> >>>> On Mon, Nov 9, 2009 at 3:35 PM, Sam Carter <sam.w.carter@xxxxxxxxx> >>>> wrote: >>>>> >>>>> When I try to compile the kernel with my changes to readdir.c, my >>>>> function in the driver is undefined and it therefore won't compile. This >>>>> also happens after I've compiled my driver against the kernel tree with the >>>>> EXPORT_SYMBOL in place. >>>>> >>>>> Any more thoughts on this? >>>>> >>>>> 2009/11/9 Zhu Yanhai <zhu.yanhai@xxxxxxxxx> >>>>>> >>>>>> EXPORT_SYMBOL_GPL(your func); >>>>>> Then this function can be called outside. >>>>>> >>>>>> For the second question, does this one work? >>>>>> >>>>>> /* Search for module by name: must hold module_mutex. */ >>>>>> struct module *find_module(const char *name) >>>>>> >>>>>> It's in kernel/module.c and has been exported. >>>>>> >>>>>> Regards, >>>>>> Zhu Yanhai >>>>>> >>>>>> >>>>>> >>>>>> 2009/11/8 Sam Carter <sam.w.carter@xxxxxxxxx>: >>>>>> > Hi all, >>>>>> > >>>>>> > I have a char driver/module which compiles and loads into the linux >>>>>> > kernel >>>>>> > just fine. In this driver are some functions which I would like to >>>>>> > access >>>>>> > from the kernel file 'fs/readdir.c'. Additionally, how can I test if >>>>>> > a >>>>>> > driver is loaded? >>>>>> > >>>>>> > I need something like the following. >>>>>> > >>>>>> > if(myDriver is loaded){ >>>>>> > >>>>>> > myDriver.functionCall(); >>>>>> > } >>>>>> > >>>>>> > All examples I've found on internet searches are doing it from >>>>>> > userspace >>>>>> > applications. >>>>>> > >>>>>> > Thanks for any help >>>>>> > >>>>>> > >>>>> >>>> >>> >> > > -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ