Вот код по примерам книги linux устройства драйвера
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/cdev.h>
MODULE_LICENSE("Dual BSD/GPL");
dev_t dev;
unsigned baseminor = 0;
unsigned count = 1;
unsigned scull_major = 0;
char *name = "scull";
struct cdev *cdev;
struct scull_dev {
int quantum;
int qset;
unsigned long size;
unsigned int access_key;
struct semaphore sem;
struct cdev cdev;
};
struct scull_dev sdev;
loff_t scull_llseek ( struct file *file, loff_t pos, int n )
{
}
ssize_t scull_read ( struct file *file, char __user *usr, size_t count, loff_t *pos)
{
}
ssize_t scull_write ( struct file *file, const char __user *usr, size_t n, loff_t *lt )
{
}
int scull_open ( struct inode *inode, struct file *filp )
{
struct scull_dev *scdev;
scdev = container_of ( inode->i_cdev, struct scull_dev, cdev );
filp->private_data = scdev;
return 0;
}
struct file_operations scull = {
.owner = THIS_MODULE,
.llseek = scull_llseek,
.read = scull_read,
.write = scull_write,
.open = scull_open
};
static int hello_init ( void )
{
int err;
int result = alloc_chrdev_region ( &dev, baseminor, count, name );
scull_major = MAJOR(dev);
cdev_init ( &sdev.cdev, &scull );
sdev.cdev.owner = THIS_MODULE;
sdev.cdev.ops = &scull;
err = cdev_add ( &sdev.cdev, dev, 1 );
if ( err )
printk (KERN_NOTICE "Error %d adding scull%d", err, 0 );
}
static void hello_exit ( void )
{
cdev_del ( &sdev.cdev );
unregister_chrdev_region ( dev, count );
}
module_init ( hello_init );
module_exit ( hello_exit );