曲径通幽论坛

标题: 不同内核版本对 struct file_operations 变量的定义 [打印本页]

作者: beyes    时间: 2009-8-26 01:18
标题: 不同内核版本对 struct file_operations 变量的定义
2.4 内核和 2.6 内核中对字符设备驱动程序的 file_operaions结构体定义了不同的实际域值。2.6内核中可以使用 2.4 内核的形式,但是最好使用相应版本的定义方式。没有定义不使用的域值时,初始化为 NULL 。

2.4 内核中的定义实例
struct file_operations xxx_fops = {
         
           llseek    :    xxx_llseek,
           read      :    xxx_read,
           write      :    xxx_write,
           ioctl       :    xxx_ioctl,
           open     :    xxx_open,
           release :    xxx_release,
}

2.6 内核中的定义实例
struct file_operations xxx_fops = {
         
           .llseek    =    xxx_llseek,
           .read      =    xxx_read,
           .write      =    xxx_write,
           .ioctl       =    xxx_ioctl,
           .open     =    xxx_open,
           .release =   xxx_release,
}

这种声明使用了标准 C 标签结构体初始化语法。这种语法使得驱动在结构体之间的定义改变变得更具有可移植性,并且可以证明,也使得代码更加的紧凑以及更有可读性。




欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2