[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

[LI] Re : Modules



Hi
It depends what type of module you are writing. e.g this module should work
for all kernels as there is nothing except the printk() function, which is
present in every kernel, and we have not defind any variable so we don't
have to bother about the type of variable, to take care of exporting
those(in older kernels) variables...

#define MODULE 	/* you are writing a module */

#define <linux/module.h>
int init_module(void)
{
	printk("Hello World..!\n");
	return 0;
}

void cleanup_module(void)
{
	printk("Good Bye..!\n");
}

If you move forward you can write a module which can work with a range of
kernels,say from 1.8.x to 2.3.x, BUT it's not possible to write it without
meddling with the kernel because the very first thing is the version, which
you'll have to take care of. For same MAJOR and MINOR number kernels you
don't have to bother so much.There are some additions, aome enhancements in
every new kernel(I think this is the only reason to release a new LINUX
kernel) so it's but natural that there will be some changes in the new
kernel. Untill and unless you use those CHANGED or ADDED functionalities
your module will work smoothly. e.g suppose you're writing a module for
allocating free pages to your module. I'm giving this only for example.
There are four functions available

get_free_page()
__get_free_page()
__get_free_pages()
__get_dma_free()

Now if you are trying to write a module which should be portable on kernel
ranging from 1.6 to 2.2.x (I haven't gone through the code of 2.3.x yet) you
should not use the functions __get_free_pages() and __get_dma_free() because
the way we should call these functions has changed so make your module
portable you should use get_free_page() and/or __get_free_pages(). 

Decide the domain in which you want to write modules(networking(protocols),
device drivers(block,char,network),file system, memory
management,scheduler,etc. and then go through the relevant code of
kernel(beleive me it'll be a subset of the whole code) and I feel you'll
enjoy writing your modules and also you can realy write a portable module.

Ajit 
----------------------------------------------------------------------------
-------------------------
Best way to learn Linux is to put comments in the source code
___________________________________________________

> -----Original Message-----
> From:	Sitaram Chamarty [SMTP:sitaram@xxxxxxxxxxxxxxx]
> Sent:	Wednesday, January 12, 2000 8:45 AM
> To:	linux-india@xxxxxxxxxxxxxxxxxxxxx
> Subject:	Re: [LI] Modules ??
> 
> On Tue, Jan 11, 2000 at 04:22:24PM +0530, Syed Khader Vali wrote:
> 
> > This might look very silly as I am learning the
> > kernel internals just now. Is it possible that
> > I can create a module that works with any
> > version of the kernel ( for 2.2.xx kernels and beyond ) without meddling
> with the kernel.
> 
> Probably not 2.2.x AND 2.3.x, but within n.m.x where n and m are
> fixed - yes it is possible.  Even within that you may have to have
> a separate version for SMP and one for UP, though...
> 
> I have no idea _how_ to do it, but I do know that it can be done
> and is done.  Example: download the OSS drivers from
> opensound.com.  They are "shareware" - you try it, and if it works
> for you, you pay $20 to get a license.
> 
> Ditributed in binary, there are separate modules for 2.2 SMP and
> for UP.  Last time I checked, anyway...
> 
> I did use them for a while too, but didnt like them too much and
> now there is a free driver from Zach brown at RH.  This one comes
> as source - you just compile it into a ".o" and "insmod" it (after
> first "insmod"-ing "soundcore".
> 
> As simple as that, and it is supposed to work with any 2.2.x
> kernel...
> 
> So yes indeed it can be done.  Just dont ask me how - I've never
> written a kernel module in my life.
> 
> (If you want to see the Maestro 2E sources, I think it is at
> http://people.redhat.com/zab/maestro - check it out.)
> 
> To whet your curiosity, here's an excerpt from the above page:
> 
>     Included here is all you need to compile and insert the driver
>     on a 2.2 box. 2.3 should be close. If you're replacing the
>     driver as distributed in a kernel, dropping maestro.c from the
>     tarball into the kernel tree on top of the old maestro.c (make
>     a backup first!) should come close to working. 
> 
> And needless to say - you don't really have to recompile your
> kernel itself for any of this to work.
> --------------------------------------------------------------------
> The Linux India Mailing List Archives are now available.  Please search
> the archive at http://lists.linux-india.org/ before posting your question
> to avoid repetition and save bandwidth.


--------------------------------------------------------------------
The Linux India Mailing List Archives are now available.  Please search
the archive at http://lists.linux-india.org/ before posting your question
to avoid repetition and save bandwidth.