Book Note: Linux Device Driver Dos and Don'ts
Book Note: Linux Device Driver Dos and Don'ts
http://janitor.kernelnewbies.org/docs/driver-howto.html
what a hardened (robust) device
driver should mean and how it should be implemented and measured.
1.3 Robust device drivers
-Follows the Linux CodingStyle.
-Efficient in managing faults and handling, reporting and recovering from errors.
(Also not panic() happy.)
-Complies with latest Linux kernel APIs and interfaces.
(Uses the new device driver model, kobjects and sysfs.)
-Properly manages resources (memory, semaphores, interrupts, etc.).
-Uses kernel-provided "C" I/O functions instead of assembly code.
2.0 Where do I start?
3.0 OK, I'm ready...
3.1 Efficient error handling, reporting and recovery:
1)<printk()>
you should always check printk() calls to include appropriate KERN_* constant.
2)<goto>
3) <Enumerated return codes> <return EWHATEVER should be return -EWHATEVER>
4) <No need to panic()>
Rather, the device driver should try to recover, re-initialize, or finally simply
return an appropriate error code, release allocated resources, log a message and
exit gracefully.
3.2.1 Module interface changes
<Initialization and cleanup>
<Module Reference Count macros>
You no longer need to adjust your own module reference count
-Reference counting from other modules:
;A Golden Rule: if you are calling through a function pointer into a (different) module,
you must hold a reference to that module.
Otherwise you risk sleeping in the module while it is unloaded.
You can get a reference to a module by using:
try_module_get(owner);
and you don't have to check if OWNER != NULL, this is done by try_module_g
相关文档:
1、Linux系统下.ko文件是什么文件?.so文件是什么文件?
.ko -- kernel object,内核模块,可以在Linux内核起来之后动态的加载和卸载。
.so -- shared object,用户层的动态库 (于.a 对应),使用同一个.so的程序在运行时
只需要该.so的同一份拷贝 ......
所有的内核代码,基本都包含了linux\compile.h这个文件,所以它是基础,打算先分析这个文件里的代码看看,有空再分析分析其它的代码。
首先印入眼帘的是对__ASSEMBLY__这个宏的判断,这个变量实际是在编译汇编代码的时候,由编译器使用-D这样的参数加进去 的,AFLAGS这个变量也定义了这个变量,gcc会把这个宏定义为1。用在 ......
安装rpm包
配置:
重起vsftpd服务:service vsftpd restart
启动vsftpd服务:service vsftpd start
1. 匿名服务器的连接(独立的服务器)
修改/etc/vsftpd/vsftpd.conf配置文件一下项,没有则添加:
Anonymous_enable=yes (允许匿名登陆)
Dirmessage_enable=yes
(切换目录时,显示目录下.message的内容)
Loca ......
用户可以用任何编辑程序来编写Shell程序。因为Shell程序是解释执行的,所以不需要编译成目的程序。按照Shell编程的惯例,以 bash为例,程序的第一行一般为“#!/bin/bash”,其中 # 表示该行是注释,叹号 ! 告诉Shell运行叹号之后的命令并用文档的其余部分作为输入,也就是运行/bin/bash并让/bin/bash去执行Shel ......
一.前言
Linux拥有丰富各种源代码资源,但是大部分代码在Windows平台情况是无法正常编译的。Windows平台根本无法直接利用这些源代码资源。如果想要使用完整的代码,就要做移植工作。因为C/C++ Library的不同和其他的一些原因,移植C/C++代码是一项困难的工作。本文将以一个实际的例子(Tar)来说明如何把Linux代码移植 ......