c语言 - 为什么我会收到错误消息"assignment of member ‘readdir’ in read-only object"



当我编译这个文件时,它抛出了以下错误。

kit.c: In function ‘hide_pid’://rootkit.c:109:9: error: assignment of member ‘readdir’ in read-only kit.c:
In function ‘restore’ 127
error: assignment of member ‘readdir’ in read-only object

有人知道为什么吗?

int hide_pid(readdir_t *orig_readdir, readdir_t new_readdir)
{
        struct file *filep;
        /*open /proc */
        if((filep = filp_open("/proc",O_RDONLY,0))==NULL)
        {
                return -1;
        }
        /*store proc's readdir*/
        if(orig_readdir)
                *orig_readdir = filep->f_op->readdir;
        /*set proc's readdir to new_readdir*/ //ERROR IN THE LINE BELOW
        filep->f_op->readdir=new_readdir;
        filp_close(filep,0);
        return 0;
}

int restore (readdir_t orig_readdir)
{
        struct file *filep;
        /*open /proc */
if ((filep = filp_open("/proc", O_RDONLY, 0)) == NULL) {
                return -1;
        }
        /*restore /proc's readdir*/ //ERROR BELOW
        filep->f_op->readdir = orig_readdir;
        filp_close(filep, 0);
        return 0;
}

定义ops向量(f_op)的结构体可能在其readdir字段的定义中使用了const,也可能在所有其他字段中使用了const。设置自己的操作向量比替换现有操作向量中的一两个方法要正常得多。

相关内容