虚拟驱动程序编译问题

发布于 2022-10-15 09:12:01 字数 4866 浏览 19 评论 0

程序编译时老是出错,求解
程序:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/types.h>       
#include <linux/fs.h>       
#include <linux/cdev.h>
#define DEV_MAJOR 200
#define DEV_MINOR 0
MODULE_LICENSE("Casm SSDUT/GPL");
char *buf = "hello world!\n";
static int driver_open( struct inode *driver_inode, struct file *driver_file );
static int driver_release( struct inode *driver_inode, struct file *driver_file );
static ssize_t driver_read( struct file *p_file, char *u_buffer, size_t count, loff_t *ppos );
static ssize_t driver_write( struct file *p_file, char *u_buffer, size_t count, loff_t *ppos );
dev_t driver_dev;
struct cdev *driver_cdev;
struct file_operations driver_fops =
{
        owner        : THIS_MODULE,
        read        : driver_read,
        open        : driver_open,
        release        : driver_release,
        write        : driver_write,
};
static int driver_open( struct inode *p_inode, struct file *p_file )
{
        return( 0 );
}
static int driver_release( struct inode *p_inode, struct file *p_file )
{
        return( 0 );
}
static ssize_t driver_read( struct file *p_file, char *u_buffer, size_t count, loff_t *ppos )
{
        int rc;
        rc = copy_to_user( u_buffer, buf, count );
        return( rc );
}
static ssize_t driver_write( struct file *p_file, char *u_buffer, size_t count, loff_t *ppos )
{
        int rc;
        rc = copy_from_user( buf, u_buffer, count );
        return( rc );
}
static int driver_init( void )
{
        int rc;
        driver_dev = MKDEV( DEV_MAJOR, DEV_MINOR );
        rc = register_chrdev_region( driver_dev, 1, "driver" );
        if(rc < 0)
        {
                printk ("Panic! Could not register driver\n");
                return rc;
        }
        driver_cdev = cdev_alloc();
        driver_cdev->owner = THIS_MODULE;
        driver_cdev->ops = &driver_fops;
        cdev_init( driver_cdev, &driver_fops );
        cdev_add( driver_cdev, driver_dev, 1 );
        printk(KERN_ALERT "initial Device Successfully!\n");
        return( 0 );
}
static void driver_exit( void )
{
        cdev_del( driver_cdev );
        unregister_chrdev_region( driver_dev, 1 );
        printk(KERN_ALERT "Exit Device Successfully!\n");
}
module_init(driver_init);
module_exit(driver_exit);

Makefile:
PWD = $(shell pwd)
KERNEL_SRC = /usr/src/$(shell uname -r)
obj-m := driver.o
all:
        $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules
clean:
        rm *.ko
        rm *.o       

编译:
make -C /usr/src/kernels/2.6.33.3-85.fc13.i686.PAE M=/home/secretband/driver modules
make[1]: Entering directory `/usr/src/kernels/2.6.33.3-85.fc13.i686.PAE'
CC [M]  /home/secretband/driver/driver.o
/home/secretband/driver/driver.c:23: warning: initialization from incompatible pointer type
/home/secretband/driver/driver.c: In function ‘driver_read’:
/home/secretband/driver/driver.c:36: error: implicit declaration of function ‘copy_to_user’
/home/secretband/driver/driver.c: In function ‘driver_write’:
/home/secretband/driver/driver.c:42: error: implicit declaration of function ‘copy_from_user’
make[2]: *** [/home/secretband/driver/driver.o] Error 1
make[1]: *** [_module_/home/secretband/driver] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.33.3-85.fc13.i686.PAE'
make: *** [all] Error 2

求各位解答,纠结了一个上午了。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揪着可爱 2022-10-22 09:12:01

少了头文件!copy_to_user,copy_from_user找不到定义。包含<linux/uaccess.h>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文