当前位置: 技术问答>linux和unix
linux下驱动失败,请看程序 /dev/simple_char
来源: 互联网 发布时间:2016-07-21
本文导语: /////////////////////////////////////////简单的驱动程序: #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define SIMPLE_CHAR_MAJOR 233 // ------------------- READ --...
/////////////////////////////////////////简单的驱动程序:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define SIMPLE_CHAR_MAJOR 233
// ------------------- READ ------------------------
static ssize_t simplechar_read (struct file * file ,char *buf, size_t count, loff_t
*offset)
{
printk ("simplechar_read has been called n");
return 0;
}
// ------------------- WRITE -----------------------
static ssize_t simplechar_write (struct file * file ,const char *buf, size_t count,
loff_t *offset)
{
printk ("simplechar_write has been called n");
return 0;
}
// ------------------- IOCTL -----------------------
int simplechar_ioctl (struct inode * inode ,struct file * file, unsigned int cmd,
unsigned long arg)
{
printk ("simplechar_ioctl has been called n");
return 0;
}
// ------------------- OPEN ------------------------
static int simplechar_open (struct inode * inode ,struct file * file)
{
printk ("simplechar_open has been calledn");
return 0;
}
// ------------------- RELEASE/CLOSE ---------------
static int simplechar_release (struct inode * inode ,struct file * file)
{
printk ("simplechar_release has been called n");
return 0;
}
static struct file_operations simple_char_ops = {
.owner = THIS_MODULE,
.read = simplechar_read,
.write = simplechar_write,
.ioctl = simplechar_ioctl,
.open = simplechar_open,
.release = simplechar_release,
};
static int __init simplechar_init(void)
{
int ret = -ENODEV;
printk ("simplechar_init… …n");
ret = register_chrdev(SIMPLE_CHAR_MAJOR, "simple_char", &simple_char_ops);
if( ret
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define SIMPLE_CHAR_MAJOR 233
// ------------------- READ ------------------------
static ssize_t simplechar_read (struct file * file ,char *buf, size_t count, loff_t
*offset)
{
printk ("simplechar_read has been called n");
return 0;
}
// ------------------- WRITE -----------------------
static ssize_t simplechar_write (struct file * file ,const char *buf, size_t count,
loff_t *offset)
{
printk ("simplechar_write has been called n");
return 0;
}
// ------------------- IOCTL -----------------------
int simplechar_ioctl (struct inode * inode ,struct file * file, unsigned int cmd,
unsigned long arg)
{
printk ("simplechar_ioctl has been called n");
return 0;
}
// ------------------- OPEN ------------------------
static int simplechar_open (struct inode * inode ,struct file * file)
{
printk ("simplechar_open has been calledn");
return 0;
}
// ------------------- RELEASE/CLOSE ---------------
static int simplechar_release (struct inode * inode ,struct file * file)
{
printk ("simplechar_release has been called n");
return 0;
}
static struct file_operations simple_char_ops = {
.owner = THIS_MODULE,
.read = simplechar_read,
.write = simplechar_write,
.ioctl = simplechar_ioctl,
.open = simplechar_open,
.release = simplechar_release,
};
static int __init simplechar_init(void)
{
int ret = -ENODEV;
printk ("simplechar_init… …n");
ret = register_chrdev(SIMPLE_CHAR_MAJOR, "simple_char", &simple_char_ops);
if( ret