mcctrl inital version (to be destroyed)

This commit is contained in:
Taku Shimosawa
2011-11-12 02:25:54 +09:00
parent 2773606466
commit d952688263
4 changed files with 158 additions and 0 deletions

73
linux/mod_mcctrl/driver.c Normal file
View File

@ -0,0 +1,73 @@
/*
*
*/
#include <linux/sched.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/slab.h>
#include "mcctrl.h"
extern long __mcctrl_control(struct mcctrl_priv *, unsigned int, unsigned long);
static int mcctrl_open(struct inode *inode, struct file *file)
{
struct mcctrl_priv *mcc_data;
mcc_data = kzalloc(sizeof(struct mcctrl_priv), GFP_KERNEL);
if (!mcc_data) {
return -ENOMEM;
}
file->private_data = mcc_data;
return 0;
}
static int mcctrl_release(struct inode *inode, struct file *file)
{
struct mcctrl_priv *mcc_data = file->private_data;
if (mcc_data) {
if (mcc_data->desc) {
kfree(mcc_data->desc);
}
kfree(mcc_data);
}
return 0;
}
static long mcctrl_ioctl(struct file *file, unsigned int request,
unsigned long arg)
{
struct mcctrl_priv *mcc_data = file->private_data;
return __mcctrl_control(mcc_data, request, arg);
}
static struct file_operations mcctrl_ops = {
.open = mcctrl_open,
.unlocked_ioctl = mcctrl_ioctl,
.release = mcctrl_release,
};
static struct miscdevice mcctrl_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "mcctrl",
.fops = &mcctrl_ops,
};
static int __init mcctrl_init(void)
{
return misc_register(&mcctrl_dev);
}
static void __exit mcctrl_exit(void)
{
misc_deregister(&mcctrl_dev);
}
MODULE_LICENSE("GPL v2");
module_init(mcctrl_init);
module_exit(mcctrl_exit);