/*****************************************************************************
 * $Id: proc_hello.c 1.4 2002/08/04 03:26:43 jimb Exp jimb $
 * Author   : Jim Brooks <jim@jimbrooks.org>
 * Purpose  : This is a kernel module that creates a read-only /proc/hello file
 *            which outputs "Hello" when read (of course).
 * Legal    : Released without restrictions into the public domain.
 *            This software is provided "AS-IS" without any express or implied
 *            warranty nor guarantee.  In no event will the author be held
 *            liable for any damages arising from the use of this software
 *            nor derivative works.
 *****************************************************************************/

#define MODULE
#define __KERNEL__

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>

static struct proc_dir_entry* procDirEntry;

/*****************************************************************************
 * This is called when the proc file is read.
 *****************************************************************************/
static int
proc_hello_read( char*  buf,
                 char** start,
                 off_t  offset,
                 int    count,
                 int*   eof,
                 void*  data )
{
    int     len     = 0;

    len += sprintf( buf+len, "Hello, world! \n" );

    *eof = 1;

    return len;
}

/*****************************************************************************
 * Initialize module.
 *****************************************************************************/
int
init_module( void )
{
    /*
     * Create /proc/hello file.
     */
    procDirEntry = \
    create_proc_read_entry( "hello",
                            0,      /* default mode */
                            NULL,   /* parent dir */
                            proc_hello_read,
                            NULL ); /* client data */
    if ( procDirEntry == NULL )
    {
        printk( KERN_DEBUG "create_proc_read_entry() failed \n" );
        return -ENODEV;
    }

    return 0;
}

/*****************************************************************************
 * Release module.
 *****************************************************************************/
void
cleanup_module( void )
{
    /*
     * Remove /proc file.
     */
    remove_proc_entry( "hello", NULL/*parent dir*/ );
}
