QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 865|回复: 0

另一个驱动程序例子问题,麻烦大伙了

[复制链接]
发表于 2005-3-9 14:03:08 | 显示全部楼层 |阅读模式
#define __NO_VERSION__

#include <linux/modules.h>

#include <linux/version.h>

char kernel_version [] = UTS_RELEASE;

#include <linux/types.h>

#include <linux/fs.h>

#include <linux/mm.h>

#include <linux/errno.h>

#include <asm/segment.h>

unsigned int test_major = 0;

static int read_test(struct inode *node,struct file *file,

char *buf,int count)

{

int left;


if (verify_area(VERIFY_WRITE,buf,count) == -EFAULT )

return -EFAULT;

for(left = count ; left > 0 ; left--)

{

__put_user(1,buf,1);

buf++;

}

return count;

}
static int write_tibet(struct inode *inode,struct file *file,

const char *buf,int count)

{

return count;

}

static int open_tibet(struct inode *inode,struct file *file )

{

MOD_INC_USE_COUNT;

return 0;

} static void release_tibet(struct inode *inode,struct file *file )

{

MOD_DEC_USE_COUNT;

}
struct file_operations test_fops = {

NULL,

read_test,

write_test,

NULL, /* test_readdir */

NULL,

NULL, /* test_ioctl */

NULL, /* test_mmap */

open_test,

release_test, NULL, /* test_fsync */

NULL, /* test_fasync */

/* nothing more, fill with NULLs */

};
int init_module(void)

{

int result;


result = register_chrdev(0, "test", &test_fops);

if (result < 0) {

printk(KERN_INFO "test: can't get major number ");

return result;

}

if (test_major == 0) test_major = result; /* dynamic */

return 0;

}
void cleanup_module(void)

{

unregister_chrdev(test_major, "test");

}
??????????????????????????????
# gcc -I/usr/src/linux-2.4/include -D__KERNEL__ -Wall -O
-c tt.c
tt.c: In function `read_test':
tt.c:17: warning: implicit declaration of function `verify_area'
tt.c:17: `VERIFY_WRITE' undeclared (first use in this function)
tt.c:17: (Each undeclared identifier is reported only once
tt.c:17: for each function it appears in.)
tt.c:20: warning: implicit declaration of function `__put_user'
tt.c: At top level:
tt.c:33: warning: initialization from incompatible pointer type
tt.c:33: warning: initialization from incompatible pointer type
tt.c:33: warning: initialization from incompatible pointer type
我搜了下头文件源程序,把verify-area换成verify-area-20
__put_user换成——PUT—USER还是不行
请教,谢谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-2 12:25 , Processed in 0.051201 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表