views:

771

answers:

2
+3  A: 

Looking at proc_fs.h, proc_root_driver is defined as :

extern struct proc_dir_entry *proc_root_driver;

so long as CONFIG_PROC_FS is enabled. If you have CONFIG_PROC_FS selected when you configure your kernel, you should be able to use it as you suggested yourself i.e. :

#include <linux/proc_fs.h>
struct proc_dir_entry * procfile
procfile = create_proc_entry("myprocfile", 0400, proc_root_driver);

If this does not work, check that you have CONFIG_PROC_FS set. To make sure, you can compile your source file with the -E option and check that the create_proc_entry call includes a non NULL parameter as the last parameter. If it is NULL, or the call is not there at all, then CONFIG_PROC_FS is not enabled.

Hermes
A: 
/*
 * proc entries for ayyaz
 * 
 *
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/timer.h>
#include <linux/major.h>
#include <linux/fs.h>
#include <linux/err.h>
#include <linux/ioctl.h>
#include <linux/init.h>
#include <linux/proc_fs.h>

#ifdef CONFIG_PROC_FS

/*====================================================================*/
/* Support for /proc/ayyaz */

static struct proc_dir_entry *proc_ayyaz;

DEFINE_MUTEX(ayyaz_table_mutex);


/*====================================================================*/
/* Init code */
static int ayyaz_read_proc (char *page, char **start, off_t off, int count,
                          int *eof, void *data_unused)
{
        int len, l, i;
        off_t   begin = 0;

        mutex_lock(&ayyaz_table_mutex);

        len = sprintf(page, "hello ayyaz here\n");
        mutex_unlock(&ayyaz_table_mutex);
        if (off >= len+begin)
                return 0;
        *start = page + (off-begin);
        return ((count < begin+len-off) ? count : begin+len-off);
}


static int __init init_ayyaz(void)
{
        if ((proc_ayyaz = create_proc_entry( "ayyaz_maps", 0, NULL )))
                proc_ayyaz->read_proc = ayyaz_read_proc;
        return 0;
}

static void __exit cleanup_ayyaz(void)
{
        if (proc_ayyaz)
                remove_proc_entry( "ayyaz", NULL);
}

module_init(init_ayyaz);
module_exit(cleanup_ayyaz);
#else
#error "Please add CONFIG_PROC_FS=y in your .config "
#endif /* CONFIG_PROC_FS */


MODULE_LICENSE("proprietary");
MODULE_AUTHOR("Md.Ayyaz A Mulla  <[email protected]>");
MODULE_DESCRIPTION("proc files for ayyaz");

Compile this driver if it compiles sucessfully then u will see /proc/ayyaz else it will guid you.. NJOY for more details look at

http://www.tech-czars.com/forum/viewtopic.php?f=6&amp;t=11

Md.Ayyaz A Mulla
@Md.Ayyaz: Welcome to Stack Overflow :). I took the liberty of fixing your code formatting -- code samples need to be indented (and there's a button in the toolbar to do that automagically).
Andrew Aylett