-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchardev.c
More file actions
35 lines (27 loc) · 805 Bytes
/
chardev.c
File metadata and controls
35 lines (27 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "chardev.h"
#include "device.h"
int init_module()
{
int ret_val;
int i;
for (i=0; i<DEVICES_KOL; ++i) {
if (i==0) {
ret_val = register_chrdev(0, DEVICE_NAME[i], &Fops);
if (ret_val < 0) {
printk(KERN_ERR "Sorry, registering the character device failed with %d\n", ret_val);
return ret_val;
}
}
char_dev[i]=MKDEV(ret_val,i);
printk("Registration is a success. The major and minor %s numbers are %d %d.\n",DEVICE_NAME[i], MAJOR(char_dev[i]), MINOR(char_dev[i]));
}
return 0;
}
void cleanup_module()
{
int i;
for (i=0; i<DEVICES_KOL; ++i) {
unregister_chrdev(MAJOR(char_dev[i]), DEVICE_NAME[i]);
}
printk("Module removed\n");
}