linux 文件 device,请教一个linux字符设备文件的问题

我刚开始学习内核编程,看的是The Linux Kernel Module Programming Guide,2.6版的,并且重新编译了内核2.6.36。我编译Example4-1.chardev.c那个程序的时候出现了以下的问题:

chardev.c:In function init_module:

chardev.c:30:error:implicit declaration of function register_chrdev

chardev.c:In function cleanup_module:

chardev.c:47:error:implicit declaration of function unregister_chrdev

chardev.c:At top level:

chardev.c:54:warning:struct inode declared inside parameter list

chardev.c:54:error:conflicting types for device_open

chardev.c:8:error:prevoius declaration of device_open was here

chardev.c:66:warning:struct inode declared inside parameter list

chardev.c:66:error:conflicting types for device_release

chardev.c:9:error:prevoius declaration of device_release was here

chardev.c:89:error:conflicting types for device_write

chardev.c:11:error:prevoius declaration of device_write was here

请问各位高手是什么原因?非常感谢!

源代码如下:

/*

*  chardev.c: Creates a read-only char device that says how many times

*  you've read from the dev file

*/

#include

#include

#include

#include         /* for put_user */

/*

*  Prototypes - this would normally go in a .h file

*/

int init_module(void);

void cleanup_module(void);

static int device_open(struct inode *, struct file *);

static int device_release(struct inode *, struct file *);

static ssize_t device_read(struct file *, char *, size_t, loff_t *);

static ssize_t device_write(struct file *, const char *, size_t, loff_t *);

#define SUCCESS 0

#define DEVICE_NAME "chardev"   /* Dev name as it appears in /proc/devices   */

#define BUF_LEN 80              /* Max length of the message from the device */

/*

* Global variables are declared as static, so are global within the file.

*/

static int Major;               /* Major number assigned to our device driver */

static int Device_Open = 0;     /* Is device open?

* Used to prevent multiple access to device */

static char msg[BUF_LEN];       /* The msg the device will give when asked */

static char *msg_Ptr;

static struct file_operations fops = {

.read = device_read,

.write = device_write,

.open = device_open,

.release = device_release

};

/*

* This function is called when the module is loaded

*/

int init_module(void)

{

Major = register_chrdev(0, DEVICE_NAME, &fops);

if (Major  /dev/hello

*/

static ssize_t

device_write(struct file *filp, const char *buff, size_t len, loff_t * off)

{

printk(KERN_ALERT "Sorry, this operation isn't supported.n");

return -EINVAL;

}

|

linux-2.6.23版本上把这个返回值从int改为void了。

commit e53252d97e670a38b1d2e9723b48077bba11ddda

Author: Akinobu Mita

Date:   Thu Jul 19 01:47:51 2007 -0700

unregister_chrdev() return void

unregister_chrdev() does not return meaningful value.  This patch makes it

return void like most unregister_* functions.

Signed-off-by: Akinobu Mita

Signed-off-by: Andrew Morton

Signed-off-by: Linus Torvalds

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值