当前位置: 技术问答>linux和unix
内核模块成功加载后的调用问题
来源: 互联网 发布时间:2015-08-04
本文导语: 我写了一个内核模块程序test.c,代码如下: #define __NO_VERSION__ #include #include #include #include #include #include #include #include unsigned int test_major=0; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) static ssize_t read_test(struct...
我写了一个内核模块程序test.c,代码如下:
#define __NO_VERSION__
#include
#include
#include
#include
#include
#include
#include
#include
unsigned int test_major=0;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
static ssize_t read_test(struct file*file,char *buf,size_t length,loff_t *offset)
#else
static int read_test(struct inode*node,struct file*file,char *buf,int count)
#endif
{
printk("read_testn");
return 0;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
static ssize_t write_test(struct file*file,const char *buf,size_t length,loff_t *offset)
#else
static int write_test(struct inode*node,struct file *file, const char *buf,int count)
#endif
{
printk("write_testn");
return 0;
}
static int open_test(struct inode *node,struct file *file)
{
printk("open_testn");
return 0;
}
static int release_test(struct inode *node,struct file *file)
{
printk("release_testn");
return 1;
}
struct file_operations test_fops=
{
#if LINUX_VERSION_CODE >= 0X020400
owner: THIS_MODULE,
#endif
read: read_test,
write: write_test,
open: open_test,
release : release_test,
};
int init_module(void)
{
int result;
result=register_chrdev(254,"test",&test_fops);
if (result
#define __NO_VERSION__
#include
#include
#include
#include
#include
#include
#include
#include
unsigned int test_major=0;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
static ssize_t read_test(struct file*file,char *buf,size_t length,loff_t *offset)
#else
static int read_test(struct inode*node,struct file*file,char *buf,int count)
#endif
{
printk("read_testn");
return 0;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
static ssize_t write_test(struct file*file,const char *buf,size_t length,loff_t *offset)
#else
static int write_test(struct inode*node,struct file *file, const char *buf,int count)
#endif
{
printk("write_testn");
return 0;
}
static int open_test(struct inode *node,struct file *file)
{
printk("open_testn");
return 0;
}
static int release_test(struct inode *node,struct file *file)
{
printk("release_testn");
return 1;
}
struct file_operations test_fops=
{
#if LINUX_VERSION_CODE >= 0X020400
owner: THIS_MODULE,
#endif
read: read_test,
write: write_test,
open: open_test,
release : release_test,
};
int init_module(void)
{
int result;
result=register_chrdev(254,"test",&test_fops);
if (result