原本的字元裝置只能有255個驅動程式,原因是乙個主裝置號占用了0~255的次裝置號
把register_chrdev展開可得到一下幾個部分:register_chrdev_region/alloc_chrdev_region,cdev_init,cdev_add
參照register_chrdev的寫法完成hello.c的**
1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14hello.c15static
intmajor;
1617
static
int hello_open(struct inode *inode, struct file *file)
1822
23static
int hello2_open(struct inode *inode, struct file *file)
2428
2930
31static
struct file_operations hello_fops =;
3536
static
struct file_operations hello2_fops =;
4041
#define hello_cnt 2
4243
static
struct
cdev hello_cdev;
44static
struct
cdev hello2_cdev;
45static
struct
class *cls;
4647
48static
int hello_init(void)49
else
59 cdev_init(&hello_cdev, &hello_fops);
60 cdev_add(&hello_cdev, devid, hello_cnt);
6162 devid = mkdev(major, 2
);63 register_chrdev_region(devid, 1, "
hello2");
64 cdev_init(&hello2_cdev, &hello2_fops);
65 cdev_add(&hello2_cdev, devid, 1
);66
67 cls = class_create(this_module, "
hello");
68 class_device_create(cls, null, mkdev(major, 0), null, "
hello0
"); /*
/dev/hello0
*/69 class_device_create(cls, null, mkdev(major, 1), null, "
hello1
"); /*
/dev/hello1
*/70 class_device_create(cls, null, mkdev(major, 2), null, "
hello2
"); /*
/dev/hello2
*/71 class_device_create(cls, null, mkdev(major, 3), null, "
hello3
"); /*
/dev/hello3
*/72
7374
return0;
7576}77
78static
void hello_exit(void)79
9293
module_init(hello_init);
94module_exit(hello_exit);
9596
97 module_license("
gpl");
(major,0~1)對應於hello,即/dev/hello0,/dev/hello1
(major,2)對應於hello2,即/dev/hello2
/dev/hello3打不開
另一種字元裝置驅動程式
前一種字元裝置驅動程式 之前通過register chrdev 0,hello hello fops 註冊字元驅動程式,乙個主裝置號下的所有裝置 major,0 major,255 都對應hello fops。另一種字元裝置驅動程式 實現函式 自動分配主裝置號,只有 major,0 和 major,...
tab標籤的另一種寫法
丁噹乙個人不可能 陳楚生經過 ella 壞女孩 楊冪 有點捨不得 羅志祥不具名的悲傷 許嵩胡蘿蔔須 鳳凰傳奇 最炫民族風 by2你並不懂我 justin boyfriend 張杰逆戰 槍戰網遊 main left good container main left good ul container ...
最近學到update的另一種寫法
最近學到update的另一種寫法,是以前自己從來沒有使用過的,看了一下文件,也沒有找到很詳細的說明。這種update方式其基礎是建立在query中的,所以可以確保使用cbo而非rbo,可以在大表的更新時明顯得提高效率。在這裡記錄一下基本的方法 sql create table a id int,a1...