-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_driver.c
More file actions
68 lines (55 loc) · 1.22 KB
/
Copy pathsample_driver.c
File metadata and controls
68 lines (55 loc) · 1.22 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/fs.h>
ssize_t sd_read (struct file *fileOp,char *buffPtr, size_t len,loff_t *offset);
static int device_major_num = 0;
static const char device_name[] = "Sample_Driver";
static struct file_operations sd_file_ops =
{
.owner = THIS_MODULE,
.read = sd_read,
};
ssize_t sd_read (struct file *fileOp,char *buffPtr, size_t len,loff_t *offset)
{
return 0;
}
ssize_t sd_write (struct file *fileOp, char *buffPtr, size_t len, loff_t *offset)
{
return 0;
}
static int sd_init(void)
{
printk(KERN_ALERT "sample driver init module\n");
return 0;
}
static void sd_exit(void)
{
printk(KERN_ALERT "sample driver exit module\n");
}
int register_sd(void)
{
int ret = 0;
ret = register_chrdev(0,device_name,&sd_file_ops);
if (ret < 0)
{
printk(KERN_ALERT "Failed to register char device\n");
device_major_num = ret;
}
else {
printk(KERN_ALERT "Char device created\n");
}
return ret;
}
void unregister_sd(void)
{
if (device_major_num != 0)
{
unregister_chrdev(device_major_num,device_name);
}
}
module_init(sd_init);
module_exit(sd_exit);
MODULE_AUTHOR("Prithwiraj Shome");
MODULE_LICENSE("GPL-2.0");
MODULE_DESCRIPTION("Sample driver");