//-------------------------------------------------------------------
//	getinfo.c
//
//	This module creates a pseudo-file named '/proc/getinfo' and
//	illustrates use of the 'get_info()' kernel interface, which
//	is considerably changed (and simplified) in kernel 2.4 from 
//	the interface described in the Linux Kernel Projects manual
//	for kernel version 2.2.  We note these interface-changes:
//	
//	1) We can omit the '#include <linux/kernel.h>' directive.	
//	2) We can request default-values for directory and mode.
//	3) The 'get_info()' function-prototype is streamlined.
//	4) Can ignore 'my_buffer' argument (unless filesize > 3K). 
//	5) Linux will allocates and initializes 'proc_dir_entry'.
//	6) 'proc_register()' and 'proc_unregister()' are obsolete. 
//
//	Note that the command-syntax needed to compile and install
//	a module is more complicated when using kernel 2.4.26 than
//	the syntax as described in the 'Projets' manual, namely:
//
//	    compile using:  $ gcc -c -O -D__KERNEL__ -DMODULE 
//	             -I/lib/2.4.26/build/include getinfo.c
//  	    install using:  $ /sbin/insmod getinfo.o  
//
//	programmer: ALLAN CRUSE
//	written on: 24 SEP 2004
//-------------------------------------------------------------------

#include <linux/module.h>	// for init_module(), printk() 
#include <linux/proc_fs.h>	// for create_proc_info_entry() 

#define PROC_DIR  NULL		// use the default directory
#define FILE_MODE  0		// use the default file mode

static char modname[] = "getinfo";	// name for the file 

static int my_get_info( char *system_buffer, char **my_buffer, 
			off_t file_position, int system_buffer_length )
{
	int	len = 0;
	len += sprintf( system_buffer+len, "\n%s\n\n", modname );
	return	len;
}

int init_module( void )
{
	printk( "<1>\nInstalling \'%s\' module\n", modname );
	create_proc_info_entry( modname, 0, NULL, my_get_info );
	return	0;  //SUCCESS
}

void cleanup_module( void )
{
	remove_proc_entry( modname, NULL );
	printk( "<1>Removing \'%s\' module\n", modname );
}

MODULE_LICENSE("GPL");