Find the answer to your Linux question:
Results 1 to 10 of 10
hello friends i write a module related to proc file system, but when i compile it i got error message that is given below. how can i overcome this error?? ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2007
    Posts
    16

    makefile error for procfile system


    hello friends
    i write a module related to proc file system, but when i compile it i got error message that is given below. how can i overcome this error?? my kernel version is 2.6.9.pls help me anyone.......
    regards shabeer


    make -C /lib/modules/2.6.9-5.EL/build M=/home/shabeer/dd modules
    make[1]: Entering directory `/usr/src/kernels/2.6.9-5.EL-i686'
    CC [M] /home/shabeer/dd/procfs1.o
    /home/shabeer/dd/procfs1.c: In function `init_module':
    /home/shabeer/dd/procfs1.c:83: error: stray '\226' in program
    /home/shabeer/dd/procfs1.c:83: error: stray '\136' in program
    /home/shabeer/dd/procfs1.c:83: error: stray '\146' in program
    /home/shabeer/dd/procfs1.c:85: error: stray '\226' in program
    /home/shabeer/dd/procfs1.c:85: error: stray '\136' in program
    /home/shabeer/dd/procfs1.c:85: error: stray '\146' in program
    /home/shabeer/dd/procfs1.c:85: error: `read_proc' undeclared (first use in this function)
    /home/shabeer/dd/procfs1.c:85: error: (Each undeclared identifier is reported only once
    /home/shabeer/dd/procfs1.c:85: error: for each function it appears in.)
    /home/shabeer/dd/procfs1.c:86: error: stray '\226' in program
    /home/shabeer/dd/procfs1.c:86: error: stray '\136' in program
    /home/shabeer/dd/procfs1.c:86: error: stray '\146' in program
    /home/shabeer/dd/procfs1.c:86: error: `owner' undeclared (first use in this function)
    /home/shabeer/dd/procfs1.c:87: error: stray '\226' in program
    /home/shabeer/dd/procfs1.c:87: error: stray '\136' in program
    /home/shabeer/dd/procfs1.c:87: error: stray '\146' in program
    /home/shabeer/dd/procfs1.c:87: error: `mode' undeclared (first use in this function)
    /home/shabeer/dd/procfs1.c:88: error: stray '\226' in program
    /home/shabeer/dd/procfs1.c:88: error: stray '\136' in program
    /home/shabeer/dd/procfs1.c:88: error: stray '\146' in program
    /home/shabeer/dd/procfs1.c:88: error: `uid' undeclared (first use in this function)
    /home/shabeer/dd/procfs1.c:89: error: stray '\226' in program
    /home/shabeer/dd/procfs1.c:89: error: stray '\136' in program
    /home/shabeer/dd/procfs1.c:89: error: stray '\146' in program
    /home/shabeer/dd/procfs1.c:89: error: `gid' undeclared (first use in this function)
    /home/shabeer/dd/procfs1.c:90: error: stray '\226' in program
    /home/shabeer/dd/procfs1.c:90: error: stray '\136' in program
    /home/shabeer/dd/procfs1.c:90: error: stray '\146' in program
    /home/shabeer/dd/procfs1.c:90: error: `size' undeclared (first use in this function)
    make[2]: *** [/home/shabeer/dd/procfs1.o] Error 1
    make[1]: *** [_module_/home/shabeer/dd] Error 2
    make[1]: Leaving directory `/usr/src/kernels/2.6.9-5.EL-i686'
    make: *** [default] Error 2

  2. #2
    Just Joined! vijay_kernel's Avatar
    Join Date
    Apr 2007
    Posts
    77
    Hi Shabeer,

    There must be an error in your source file please check your source file and let me know.

  3. #3
    Just Joined!
    Join Date
    Aug 2006
    Location
    india
    Posts
    57
    hi
    if ur code is under GPL please put it in forum i will try my best to fix up the bug

    regards,
    kingraja.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Apr 2007
    Posts
    16

    code

    hello
    actually the code is nothing but i copied from the Peter Jay Salzman,s "The linux kernel Moduule programming guide and that code is given below


    #include <linux/moduleparam.h>
    #include <linux/init.h>
    #include <linux/stat.h>
    #include <linux/module.h> /* Specifically, a module */
    #include <linux/kernel.h> /* We're doing kernel work */
    #include <linux/proc_fs.h> /* Necessary because we use the proc fs */
    #define procfs_name "helloworld"

    struct proc_dir_entry *Our_Proc_File;

    procfile_read(char *buffer,char **buffer_location,off_t offset, int buffer_length, int *eof, void *data)
    {
    int ret;
    printk(KERN_INFO "procfile_read (/proc/%s) called\n", procfs_name);
    if (offset > 0) {
    ret = 0;
    }
    else
    {
    ret = sprintf(buffer, "HelloWorld!\n");
    }
    return ret;
    }
    static int __init proc_init(void)
    {
    Our_Proc_File = create_proc_entry(procfs_name, 0644, NULL);
    if (Our_Proc_File == NULL) {
    remove_proc_entry(procfs_name, &proc_root);
    printk(KERN_ALERT "Error: Could not initialize /proc/%s\n",procfs_name);
    return −ENOMEM;
    }
    Our_Proc_File−>read_proc = procfile_read;
    Our_Proc_File−>owner = THIS_MODULE;
    Our_Proc_File−>mode = S_IFREG | S_IRUGO;
    Our_Proc_File−>uid = 0;
    Our_Proc_File−>gid = 0;
    Our_Proc_File−>size = 37;
    printk(KERN_INFO "/proc/%s created\n", procfs_name);
    return 0; /* everything is ok */
    }

    static void __exit proc_exit(void)
    {
    remove_proc_entry(procfs_name, &proc_root);
    printk(KERN_INFO "/proc/%s removed\n", procfs_name);
    }

    module_init(proc_init);
    module_exit(proc_exit);

  6. #5
    Just Joined!
    Join Date
    Aug 2006
    Location
    india
    Posts
    57
    hi,
    The way u make this proc file is different ,the errors what u got is because ur doing just "cc to the module" which inturn is looking for main & init,exit cant be understood even the headers

    so please come back with ur make.

  7. #6
    Just Joined! vijay_kernel's Avatar
    Join Date
    Apr 2007
    Posts
    77
    Hi Shabeer ,

    I gone thru your source code and found that you have not copied the correctly,

    Here is the code ....
    procfs1.c


    #include <linux/module.h> /* Specifically, a module */
    #include <linux/kernel.h> /* We're doing kernel work */
    #include <linux/proc_fs.h> /* Necessary because we use the proc fs */
    #include <asm/uaccess.h> /* for copy_from_user */

    #define PROCFS_MAX_SIZE 1024
    #define PROCFS_NAME "buffer1k"

    static struct proc_dir_entry *Our_Proc_File;

    static char procfs_buffer[PROCFS_MAX_SIZE];

    static unsigned long procfs_buffer_size = 0;

    int
    procfile_read(char *buffer, char **buffer_location, off_t offset,
    int buffer_length, int *eof, void *data)

    {
    int ret;

    printk(KERN_INFO "procfile_read (/proc/%s) called\n", PROCFS_NAME);
    if (offset > 0) {
    /* we have finished to read, return 0 */
    ret = 0;
    } else {
    /* fill the buffer, return the buffer size */
    memcpy(buffer, procfs_buffer, procfs_buffer_size);
    ret = procfs_buffer_size;
    }
    return ret;
    }


    int procfile_write(struct file *file, const char *buffer, unsigned long count, void *data)
    {
    /* get buffer size */
    procfs_buffer_size = count;
    if (procfs_buffer_size > PROCFS_MAX_SIZE ) {

    procfs_buffer_size = PROCFS_MAX_SIZE;
    }

    /* write data to the buffer */
    if ( copy_from_user(procfs_buffer, buffer, procfs_buffer_size) ) {

    return -EFAULT;
    }

    return procfs_buffer_size;
    }



    int init_module()
    {
    /* create the /proc file */
    Our_Proc_File = create_proc_entry(PROCFS_NAME, 0644, NULL);

    if (Our_Proc_File == NULL) {

    remove_proc_entry(PROCFS_NAME, &proc_root);
    printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", PROCFS_NAME);
    return -ENOMEM;
    }
    Our_Proc_File->read_proc = procfile_read;
    Our_Proc_File->write_proc = procfile_write;
    Our_Proc_File->owner = THIS_MODULE;
    Our_Proc_File->mode = S_IFREG | S_IRUGO;
    Our_Proc_File->uid = 0;
    Our_Proc_File->gid = 0;
    Our_Proc_File->size = 37;
    printk(KERN_INFO "/proc/%s created\n", PROCFS_NAME);
    return 0; /* everything is ok */
    }



    void cleanup_module()
    {
    remove_proc_entry(PROCFS_NAME, &proc_root);
    printk(KERN_INFO "/proc/%s removed\n", PROCFS_NAME);
    }



    Now execute this code , i am sure it should work this time.

    Your makefile would be like this....




    obj-m += procfs1.o

    all:
    make -C /lib/modules/2.6.15-28-amd64-xeon/build M=$(PWD) modules
    clean:
    make -C /lib/modules/2.6.15-28-amd64-xeon/build M=$(PWD) clean

  8. #7
    Just Joined! vijay_kernel's Avatar
    Join Date
    Apr 2007
    Posts
    77
    Hi Shabeer ,

    I gone thru your source code and found that you have not copied the correctly,

    Here is the code ....
    procfs1.c


    #include <linux/module.h> /* Specifically, a module */
    #include <linux/kernel.h> /* We're doing kernel work */
    #include <linux/proc_fs.h> /* Necessary because we use the proc fs */
    #include <asm/uaccess.h> /* for copy_from_user */

    #define PROCFS_MAX_SIZE 1024
    #define PROCFS_NAME "buffer1k"

    static struct proc_dir_entry *Our_Proc_File;

    static char procfs_buffer[PROCFS_MAX_SIZE];

    static unsigned long procfs_buffer_size = 0;

    int
    procfile_read(char *buffer, char **buffer_location, off_t offset,
    int buffer_length, int *eof, void *data)

    {
    int ret;

    printk(KERN_INFO "procfile_read (/proc/%s) called\n", PROCFS_NAME);
    if (offset > 0) {
    /* we have finished to read, return 0 */
    ret = 0;
    } else {
    /* fill the buffer, return the buffer size */
    memcpy(buffer, procfs_buffer, procfs_buffer_size);
    ret = procfs_buffer_size;
    }
    return ret;
    }


    int procfile_write(struct file *file, const char *buffer, unsigned long count, void *data)
    {
    /* get buffer size */
    procfs_buffer_size = count;
    if (procfs_buffer_size > PROCFS_MAX_SIZE ) {

    procfs_buffer_size = PROCFS_MAX_SIZE;
    }

    /* write data to the buffer */
    if ( copy_from_user(procfs_buffer, buffer, procfs_buffer_size) ) {

    return -EFAULT;
    }

    return procfs_buffer_size;
    }



    int init_module()
    {
    /* create the /proc file */
    Our_Proc_File = create_proc_entry(PROCFS_NAME, 0644, NULL);

    if (Our_Proc_File == NULL) {

    remove_proc_entry(PROCFS_NAME, &proc_root);
    printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", PROCFS_NAME);
    return -ENOMEM;
    }
    Our_Proc_File->read_proc = procfile_read;
    Our_Proc_File->write_proc = procfile_write;
    Our_Proc_File->owner = THIS_MODULE;
    Our_Proc_File->mode = S_IFREG | S_IRUGO;
    Our_Proc_File->uid = 0;
    Our_Proc_File->gid = 0;
    Our_Proc_File->size = 37;
    printk(KERN_INFO "/proc/%s created\n", PROCFS_NAME);
    return 0; /* everything is ok */
    }



    void cleanup_module()
    {
    remove_proc_entry(PROCFS_NAME, &proc_root);
    printk(KERN_INFO "/proc/%s removed\n", PROCFS_NAME);
    }



    Now execute this code , i am sure it should work this time.

    Your makefile would be like this....




    obj-m += procfs1.o

    all:
    make -C /lib/modules/2.6.15-28-amd64-xeon/build M=$(PWD) modules
    clean:
    make -C /lib/modules/2.6.15-28-amd64-xeon/build M=$(PWD) clean



    Cheers,
    Vijay.

  9. #8
    Just Joined!
    Join Date
    Apr 2007
    Posts
    16
    hi vijay,
    till now i dont clear this error.I Copy ur program and compile it the same error occure.Also i use pentium processor and my Makefile is shown below


    ************************************************** *******************************8
    ifneq ($(KERNELRELEASE),)
    obj-m := procfs11.o
    else
    KERNELDIR ?= /lib/modules/$(shell uname -r)/build
    PWD := $(shell pwd)

    default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

    endif
    ************************************************** ***************************
    is der any problem with this makefile?
    Thans for ur valuable replay

  10. #9
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Your makefile isn't proper, the name of your c file is procfs1.c and in your makefile you're trying to make procfs11.o instead of procfs1.o.

    Try this makefile and use real tabs (!) before the make commandos:

    Code:
    obj-m += procfs1.o
    
    all:
    	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    
    clean:
    	make −C /lib/modules/$(shell uname −r)/build M=$(PWD) clean
    And please place your code between code tags next time, thats easier for others to read.

    Regards

  11. #10
    Just Joined!
    Join Date
    Apr 2007
    Posts
    16
    Thankyou friends i got the output

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •