linukso吧 关注:1,482贴子:173,707
  • 5回复贴,共1

求助,程序编译不过。。。= =。搞不懂了求教

只看楼主收藏回复

#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <asm/uaccess.h>
MODULE_LICENSE("GPL");
#define MAJOR_NUM 254 //主设备号
static char str[20]="Hello,Wrold!"; //"string"设备的数组
static ssize_t string_read(struct file *filp, char *buf,size_t len,loff_t *loff) //读函数
{
//将str[]中的内容从内核空间复制到用户空间
if (copy_to_user(buf, &str, sizeof(str)))
{
return -1;
}
return sizeof(str);
}
static ssize_t string_write(struct file *filp,const char *buf,size_t len,loff_t *off) //写函数
{
//将用户空间的数据复制到内核空间的str[]数组中
if(copy_from_user(&str,buf,sizeof(str)))
{
return -1;
}
return sizeof(str);
}
//初始化字符设备驱动的file_operations结构体
struct file_operations string_fops=
{
read: string_read, //将标准的读取函数指向对应于设备的具体函数
write: string_write, //将标准的写函数指向对应于设备的具体函数
};
static int __init string_init(void)
{
int ret;
//注册设备驱动
ret = register_chrdev(MAJOR_NUM, "string", &string_fops);
if (ret)
{
printk("string register failure"); //注册失败
}
else
{
printk("string register success"); //注册成功
}
return ret;
}
static void __exit string_exit(void)
{
int ret;
//销毁设备驱动
ret = unregister_chrdev(MAJOR_NUM, "string");
if (ret)
{
printk("string unregister failure");
}
else
{
printk("string unregister success");
}
}
module_init(string_init);
module_exit(string_exit);
TUT。。。实在不会解决了
系统为centOS 6.3


IP属地:广东1楼2013-06-24 22:34回复
    吓尿,还以为在linux吧,怎么问问题的跑这了


    IP属地:山东来自手机贴吧2楼2013-06-24 22:37
    收起回复
      2025-06-13 09:19:56
      广告
      @金狼古十四


      来自Android客户端3楼2013-06-24 23:22
      收起回复