Frederick Zhang
Frederick Zhang

Reputation: 3683

Error "implicit declaration" with proc_create_entry from proc_fs.h

I'm using Fedora 19 with the kernel of 3.11.6-200.fc19.x86_64

I had some errors when learning proc_fs.h It seems that these codes can be normally compiled on Ubuntu 12.04, I just cannot figure out what's wrong with it on Fedora.

[root@frederick-pc Test]# make
make -C /lib/modules/3.11.6-200.fc19.x86_64/build M=/home/frederick/Documents/HW_2nd/Test modules
make[1]: Entering directory `/usr/src/kernels/3.11.6-200.fc19.x86_64'
  CC [M]  /home/frederick/Documents/HW_2nd/Test/rw_proc.o
/home/frederick/Documents/HW_2nd/Test/rw_proc.c: In function ‘rw_proc_init’:
/home/frederick/Documents/HW_2nd/Test/rw_proc.c:43:2: error: implicit declaration of function ‘proc_create_entry’ [-Werror=implicit-function-declaration]
  p = proc_create_entry(PROCFS_NAME, 0644, NULL);
  ^
/home/frederick/Documents/HW_2nd/Test/rw_proc.c:43:4: warning: assignment makes pointer from integer without a cast [enabled by default]
  p = proc_create_entry(PROCFS_NAME, 0644, NULL);
    ^
/home/frederick/Documents/HW_2nd/Test/rw_proc.c:51:3: error: dereferencing pointer to incomplete type
  p->read_proc = procfile_read;
   ^
/home/frederick/Documents/HW_2nd/Test/rw_proc.c:52:3: error: dereferencing pointer to incomplete type
  p->write_proc = procfile_write;
   ^
/home/frederick/Documents/HW_2nd/Test/rw_proc.c:54:3: error: dereferencing pointer to incomplete type
  p->mode = S_IFREG | S_IRUGO;
   ^
/home/frederick/Documents/HW_2nd/Test/rw_proc.c:55:3: error: dereferencing pointer to incomplete type
  p->uid = 0;
   ^
/home/frederick/Documents/HW_2nd/Test/rw_proc.c:56:3: error: dereferencing pointer to incomplete type
  p->gid = 0;
   ^
/home/frederick/Documents/HW_2nd/Test/rw_proc.c:57:3: error: dereferencing pointer to incomplete type
  p->size = 37;
   ^
cc1: some warnings being treated as errors
make[2]: *** [/home/frederick/Documents/HW_2nd/Test/rw_proc.o] Error 1
make[1]: *** [_module_/home/frederick/Documents/HW_2nd/Test] Error 2
make[1]: Leaving directory `/usr/src/kernels/3.11.6-200.fc19.x86_64'
make: *** [default] Error 2

here're my codes

rw_proc.c

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

#define PROCFS_MAX_SIZE 1024
#define PROCFS_NAME "my_procfile_1k"

MODULE_LICENSE("GPL");

static struct proc_dir_entry *p = NULL;
static char procfs_buffer[PROCFS_MAX_SIZE];
static unsigned long procfs_buffer_size = 0;
static 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) 
    {
        ret = 0;
    } 
    else 
    {
        memcpy(buffer, procfs_buffer, procfs_buffer_size);
        ret = procfs_buffer_size;
    }
    return ret;
}
static int procfile_write(struct file *file, const char *buffer, unsigned long count,void *data)
{
    procfs_buffer_size = count;
    if (procfs_buffer_size > PROCFS_MAX_SIZE ) {
    procfs_buffer_size = PROCFS_MAX_SIZE;
    }
        if ( copy_from_user(procfs_buffer, buffer, procfs_buffer_size) ) {
        return EFAULT;
    }
    return procfs_buffer_size;
}

static int rw_proc_init(void)
{
    p = proc_create_entry(PROCFS_NAME, 0644, NULL);
    if (p == NULL) 
    {
        remove_proc_entry(PROCFS_NAME, NULL);
        printk(KERN_ALERT "Error: Could not initialize /proc/%s\n",
        PROCFS_NAME);
        return ENOMEM;
    }
    p->read_proc = procfile_read;
    p->write_proc = procfile_write;
    //p->owner = THIS_MODULE;
    p->mode = S_IFREG | S_IRUGO;
    p->uid = 0;
    p->gid = 0;
    p->size = 37;
    printk(KERN_INFO "/proc/%s created\n", PROCFS_NAME);
    return 0;
}

static void rw_proc_exit(void)
{
    remove_proc_entry(PROCFS_NAME, NULL);
    printk(KERN_INFO "/proc/%s removed\n", PROCFS_NAME);
}

module_init(rw_proc_init);
module_exit(rw_proc_exit);

Who can help me? THX

Upvotes: 1

Views: 1981

Answers (2)

Frederick Zhang
Frederick Zhang

Reputation: 3683

Well finally i resolved the problem myself

it seems that since the version of 3.10.0, the function of proc_create_entry() has been deleted and replaced by proc_create()

so just replace them in the codes if you're compiling with a kernel newer than 3.10.0

Upvotes: 1

Jens Gustedt
Jens Gustedt

Reputation: 78903

Your variable p is not declared, this is what the compiler is trying to tell you. You'd just have to declare the variable locally at the beginning of the function like that:

struct proc_dir_entry *p = proc_create_entry(PROCFS_NAME, 0644, NULL);

(if struct proc_dir_entry* is really the type that the function returns, I didn't check.)

Upvotes: 0

Related Questions