include/linux/cdev.h

本文深入探讨了Linux内核中的cdev模块,解释了其结构、初始化、分配、释放、添加、删除等核心操作,并提供了实例代码帮助理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#ifndef _LINUX_CDEV_H
#define _LINUX_CDEV_H

#include <linux/kobject.h>
#include <linux/kdev_t.h>
#include <linux/list.h>

struct file_operations;
struct inode;
struct module;

struct cdev {
    struct kobject kobj;
    struct module *owner;
    const struct file_operations *ops;
    struct list_head list;
    dev_t dev;
    unsigned int count;
};

void cdev_init(struct cdev *, const struct file_operations *);

struct cdev *cdev_alloc(void);

void cdev_put(struct cdev *p);

int cdev_add(struct cdev *, dev_t, unsigned);

void cdev_del(struct cdev *);

int cdev_index(struct inode *inode);

void cd_forget(struct inode *);

extern struct backing_dev_info directly_mappable_cdev_bdi;

#endif

 
我现在安装了gcc-12,执行make后报错:$ make make -C /lib/modules/6.8.0-65-generic/build M=/home/tp/kernel_code modules make[1]: 进入目录“/usr/src/linux-headers-6.8.0-65-generic” warning: the compiler differs from the one used to build the kernel The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0 You are using: gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0 CC [M] /home/tp/kernel_code/char_dev.o In file included from ./arch/x86/include/asm/mem_encrypt.h:15, from ./include/linux/mem_encrypt.h:17, from ./arch/x86/include/asm/processor-flags.h:6, from ./arch/x86/include/asm/processor.h:5, from ./arch/x86/include/asm/timex.h:5, from ./include/linux/timex.h:67, from ./include/linux/time32.h:13, from ./include/linux/time.h:60, from ./include/linux/stat.h:19, from ./include/linux/module.h:13, from /home/tp/kernel_code/char_dev.c:1: /home/tp/kernel_code/char_dev.c: In function ‘char_dev_init’: ./include/linux/init.h:188:22: error: passing argument 1 of ‘class_create’ from incompatible pointer type [-Werror=incompatible-pointer-types] 188 | #define THIS_MODULE (&__this_module) | ~^~~~~~~~~~~~~~~ | | | struct module * /home/tp/kernel_code/char_dev.c:83:31: note: in expansion of macro ‘THIS_MODULE’ 83 | char_class = class_create(THIS_MODULE, CLASS_NAME); | ^~~~~~~~~~~ In file included from ./include/linux/device.h:31, from ./include/linux/cdev.h:8, from /home/tp/kernel_code/char_dev.c:3: ./include/linux/device/class.h:228:54: note: expected ‘const char *’ but argument is of type ‘struct module *’ 228 | class * __must_check class_create(const char *name); | ~~~~~~~~~~^~ /home/tp/kernel_code/char_dev.c:83:18: error: too many arguments to function ‘class_create’ 83 | char_class = class_create(THIS_MODULE, CLASS_NAME); | ^~~~~~~~~~~~ ./include/linux/device/class.h:228:29: note: declared here 228 | struct class * __must_check class_create(const char *name); | ^~~~~~~~~~~~ cc1: some warnings being treated as errors make[3]: *** [scripts/Makefile.build:243:/home/tp/kernel_code/char_dev.o] 错误 1 make[2]: *** [/usr/src/linux-headers-6.8.0-65-generic/Makefile:1925:/home/tp/kernel_code] 错误 2 make[1]: *** [Makefile:240:__sub-make] 错误 2 make[1]: 离开目录“/usr/src/linux-headers-6.8.0-65-generic” make: *** [Makefile:5:all] 错误 2
08-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值