1

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.)

6 Comments

so how can I fix the bug?
@Frederick888, declare the variable, I thought that would be obvious. Check the definition of proc_create_entry for its return type and use that. By putting that type in front of p, you change that line from an assignment statement to a variable declaration with initialization.
i've declared p with static struct proc_dir_entry *p = NULL; and the struct comes from proc_fs.h
Why the static? And why the NULL. Just declare a local variable in the place that the compiler complains.
so i deleted the declaration and all the statics, and replaced the code above with struct proc_dir_entry *p = proc_create_entry(PROCFS_NAME, 0644, NULL);, but all the errors remained.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.