QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

楼主: flyhappy007

我写的linux驱动程序,有问题,帮忙指导.谢谢

[复制链接]
发表于 2006-2-18 23:05:24 | 显示全部楼层
我结合楼上几位大哥的建议  重新编译了问题如下:
代码:
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include<linux/config.h>
#include<linux/module.h>
#include<linux/kernel.h
#include<linux/version.h>
#include<linux/types.h>
#include<linux/fs.h>
#include<linux/mm.h>
#include<linux/errno.h>
#include<asm/segment.h>
char kernel_version[]=UTS_RELEASE;

struct file_operations
{
int (*seek) (struct inode *,struct file * ,off_t,int);
int (*read) (struct inode *,struct file * ,char ,int);
int (*write) (struct inode *,struct file * ,off_t,int);
int (*readdir) (struct inode *,struct file *,struct dirent * ,int);
int (*select) (struct inode *,struct file *,int ,select_table *);
int (*ioctl) (struct inode *,struct file *,unsigned int ,unsigned long);
int (*mmap) (struct inode *,struct file * ,struct file *,struct vm_area_struct * );
int (*open) (struct inode *,struct file *);
int (*release) (struct inode * ,struct file *);
int (*fsync ) (struct inode * ,struct file *);
int (*fasync) (struct inode *,struct file *,int);
int (*check_media_change) (struct inode * ,struct file *);
int (*revalidate) (dev_t dev);
};
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_test(struct inode* inode,struct file * file,const char * buf ,int count)
{
return count;
};

static int open_test(struct inode * inode,struct file * file)
{
MOD_INC_USE_COUNT;
return 0;
};
static void release_test(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("<0> test :can't get major number.\n");
return result;
}
if(test_major==0) test_major=result; /*dynamic */
return 0;
}
/*卸载设备驱动程序 */
void cleanup_module(void)
{
unregister_chrdev(test_major,"test");
}

编译命令:
gcc -c -O2 -DMODULE -D__KERNEL__ -I/usr/src/linux-2.4.20-8/include test2.c
提示如下:
test2.c:19: redefinition of `struct file_operations'
test2.c:23: warning: `struct dirent' declared inside parameter list
test2.c:23: warning: its scope is only this definition or declaration, which is probably not what you want
test2.c:24: parse error before "select_table"
test2.c: In function `read_test':
test2.c:38: `VERIFY_WRITE' undeclared (first use in this function)
test2.c:38: (Each undeclared identifier is reported only once
test2.c:38: for each function it appears in.)
test2.c: At top level:
test2.c:65: warning: initialization from incompatible pointer type
test2.c:66: warning: initialization from incompatible pointer type
test2.c:72: warning: initialization from incompatible pointer type

我用的是RedHat 9.0 linux-2.4.20-8的内核
希望高手指点 全天等候!
回复

使用道具 举报

发表于 2006-6-18 21:40:11 | 显示全部楼层
删去
struct file_operations
{
int (*seek) (struct inode *,struct file * ,off_t,int);
int (*read) (struct inode *,struct file * ,char ,int);
int (*write) (struct inode *,struct file * ,off_t,int);
int (*readdir) (struct inode *,struct file *,struct dirent * ,int);
int (*select) (struct inode *,struct file *,int ,select_table *);
int (*ioctl) (struct inode *,struct file *,unsigned int ,unsigned long);
int (*mmap) (struct inode *,struct file * ,struct file *,struct vm_area_struct * );
int (*open) (struct inode *,struct file *);
int (*release) (struct inode * ,struct file *);
int (*fsync ) (struct inode * ,struct file *);
int (*fasync) (struct inode *,struct file *,int);
int (*check_media_change) (struct inode * ,struct file *);
int (*revalidate) (dev_t dev);
};
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-22 12:53 , Processed in 0.043499 second(s), 12 queries .

© 2021 Powered by Discuz! X3.5.

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