54 lines
1.1 KiB
C
54 lines
1.1 KiB
C
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/ioctl.h>
|
|
|
|
#include "io.h"
|
|
#include "counter_io_calls.h"
|
|
|
|
|
|
static dev_t io_device_no;
|
|
static struct class *io_device_class;
|
|
static struct cdev io_device;
|
|
|
|
#define DRIVER_NAME "cntiodev"
|
|
#define DRIVER_CLASS "CounterClass"
|
|
|
|
|
|
|
|
static int io_open(struct inode *device_file, struct file *instance) {
|
|
printk("counter - Info! io open was called\n");
|
|
return 0;
|
|
}
|
|
|
|
static int io_close(struct inode *device_file, struct file *instance) {
|
|
printk("counter - Info! io close was called\n");
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
static struct file_operations fops = {
|
|
.owner = THIS_MODULE,
|
|
.open = io_open,
|
|
.release = io_close,
|
|
};
|
|
|
|
int io_init(void) {
|
|
printk("counter - Info! io init\n");
|
|
|
|
if (alloc_chrdev_region(&io_device_no, 0, 1, DRIVER_NAME) < 0) {
|
|
printk("counter - ERROR! Device No. could not be allocated\n");
|
|
return -1;
|
|
}
|
|
printk("counter - Info! Device No. Major: %d, Minor: %d was registered!\n", my_device_nr >> 20, my_device_nr & 0xfffff);
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
void io_exit(void) {
|
|
}
|
|
|