-
Notifications
You must be signed in to change notification settings - Fork 0
/
sesam-mod.c
72 lines (57 loc) · 1.22 KB
/
sesam-mod.c
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
69
70
71
72
#define __KERNEL__
#include <linux/modversions.h>
#include <linux/module.h>
#include <linux/tty.h>
#include <asm/uaccess.h>
#define LPT_PORT 0x3BC
static DECLARE_WAIT_QUEUE_HEAD(door_wait);
static spinlock_t door_dev_lock;
static int door_dev_open;
static void device_open(struct inode* inode, struct file* file)
{
spin_lock(&door_dev_lock);
if (door_dev_used) {
spin_unlock(&door_dev_lock);
return -EBUSY;
} else {
door_dev_used = 1;
spin_unlock(&door_dev_lock);
return 0;
}
}
statuc void device_release(struct inode* inode, struct file* file)
{
/* nothing to do */
return 0;
}
static void device_write(struct file* file, char* buffer,
size_t count, loff_t* ppos)
{
current->state = TASK_INTERRUPTIBLE;
return 0;
}
static struct file_operations* operations = {
owner: THIS_MODULE,
llseek: no_llseek,
read: NULL,
write: device_write,
poll: NULL,
ioctl: NULL,
open: device_open,
release: device_release,
fasync: NULL,
};
static struct miscdevice door_dev = {
0, "ovi", &operations
};
int init_module(void)
{
printk(KERN_INFO, "sesam-mod initializing");
spin_lock_init(&door_dev_lock);
door_dev_open = 0;
misc_register(&door_dev);
}
void cleanup_module(void)
{
misc_deregister(&door_dev);
}