菜鸟问题:隐式声明函数 copy_to_user。大家帮忙啊
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h> /* everything... */
#define DEVICE_NAME "demo"
#define demo_MAJOR 249
#define demo_MINOR 0
#define MAX_BUF_LEN 20
static char drv_buf[20];
static int demo_open(struct inode *inode, struct file *file) {
//MOD_INC_USE_COUNT;
sprintf(drv_buf,"device open sucess!\n");
printk("device open sucess!\n");
return 0;
}
static int demo_release(struct inode *inode, struct file *filp) {
//MOD_DEC_USE_COUNT;
printk("device release\n");
return 0;
}
static ssize_t demo_read(struct file *filp, char *buffer, size_t count, loff_t *ppos) {
if(count > MAX_BUF_LEN)
count=MAX_BUF_LEN;
copy_to_user(buffer, drv_buf,count);
printk("user read data from driver\n");
return count;
}
static ssize_t demo_write(struct file *filp,const char *buffer, size_t count) {
copy_from_user(drv_buf , buffer, count);
printk("user write data to driver\n");
//your code here
return count;
}
static struct file_operations demo_fops = {
write: demo_write,
read: demo_read,
open: demo_open,
release: demo_release,
};
static int __init demo_init(void) {
int result;
SET_MODULE_OWNER(&demo_fops);
result = register_chrdev(demo_MAJOR, "demo", &demo_fops);
if (result < 0) return result;
printk(DEVICE_NAME " initialized\n");
return 0;
}
static void __exit demo_exit(void) {
unregister_chrdev(demo_MAJOR, "demo");
printk(DEVICE_NAME " unloaded\n");
}
module_init(demo_init);
module_exit(demo_exit);
makefile
obj-m := demo.o
#KERNEL_DIR :=/lib/modules/$(shell uname -r)/build
KERNEL_DIR :=/lib/modules/2.6.18-1.2798.fc6/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules
#include <linux/init.h>
#include <linux/fs.h> /* everything... */
#define DEVICE_NAME "demo"
#define demo_MAJOR 249
#define demo_MINOR 0
#define MAX_BUF_LEN 20
static char drv_buf[20];
static int demo_open(struct inode *inode, struct file *file) {
//MOD_INC_USE_COUNT;
sprintf(drv_buf,"device open sucess!\n");
printk("device open sucess!\n");
return 0;
}
static int demo_release(struct inode *inode, struct file *filp) {
//MOD_DEC_USE_COUNT;
printk("device release\n");
return 0;
}
static ssize_t demo_read(struct file *filp, char *buffer, size_t count, loff_t *ppos) {
if(count > MAX_BUF_LEN)
count=MAX_BUF_LEN;
copy_to_user(buffer, drv_buf,count);
printk("user read data from driver\n");
return count;
}
static ssize_t demo_write(struct file *filp,const char *buffer, size_t count) {
copy_from_user(drv_buf , buffer, count);
printk("user write data to driver\n");
//your code here
return count;
}
static struct file_operations demo_fops = {
write: demo_write,
read: demo_read,
open: demo_open,
release: demo_release,
};
static int __init demo_init(void) {
int result;
SET_MODULE_OWNER(&demo_fops);
result = register_chrdev(demo_MAJOR, "demo", &demo_fops);
if (result < 0) return result;
printk(DEVICE_NAME " initialized\n");
return 0;
}
static void __exit demo_exit(void) {
unregister_chrdev(demo_MAJOR, "demo");
printk(DEVICE_NAME " unloaded\n");
}
module_init(demo_init);
module_exit(demo_exit);
makefile
obj-m := demo.o
#KERNEL_DIR :=/lib/modules/$(shell uname -r)/build
KERNEL_DIR :=/lib/modules/2.6.18-1.2798.fc6/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules
...全文
相关推荐
Bootstrap菜鸟教程
Bootstrap前端框架的使用
菜鸟学hibernate
NULL 博文链接:https://ouyida3.iteye.com/blog/1911685
w3cschool菜鸟教程--bootstrap教程
是基于w3cshool菜鸟教程网站上的bootstrap制作而成,非常详细,是很好的学习bootstrap的资料
实用代码脚本易语言源码菜鸟级的锁屏
实用代码脚本易语言源码菜鸟级的锁屏
关于oracle存储过程的基本语法
在oracle中,数据表别名不能加as;在存储过程中,select某一字段时,后面必须紧跟into,如果select整个记录,利用游标的话就另当别论了;在利用select...into...语法时,必须先确保数据库中有该条记录,否则会报出"no data found"异常;在存储过程中,别名不能和字段名称相同,否则虽然编译可以通过,但在运行阶段会报错


驱动开发/核心开发
