免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 778 | 回复: 3
打印 上一主题 下一主题

关于驱动的问题 请各位大虾帮忙看看!!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-11-02 15:11 |只看该作者 |倒序浏览
我最近刚刚接触linux 看了一些书,感觉还不错,于是编写了一个很简单的驱动,可是怎么编译都通不过 请高手们帮忙看看啊 谢谢了!!
帮帮我啊我要郁闷死了~
编译后提示:
[root@zl wuliaotest]# gcc -D__KERNEL__-DMODULE-LINUX -c drvback.c
<command line>;: warning: ISO C requires whitespace after the macro name
drvback.c:127:1: warning: no newline at end of file
drvback.c:19: warning: `struct file' declared inside parameter list
drvback.c:19: warning: its scope is only this definition or declaration, which is probably not what you want.
drvback.c:19: warning: `struct inode' declared inside parameter list
drvback.c:46: warning: `struct file' declared inside parameter list
drvback.c:46: warning: `struct inode' declared inside parameter list
drvback.c:54: warning: `struct file' declared inside parameter list
drvback.c:54: warning: `struct inode' declared inside parameter list
drvback.c:62: warning: `struct file' declared inside parameter list
drvback.c:62: warning: `struct inode' declared inside parameter list
drvback.c:70: variable `test_fops' has initializer but incomplete type
drvback.c:72: warning: excess elements in struct initializer
drvback.c:72: warning: (near initialization for `test_fops')
drvback.c:74: warning: excess elements in struct initializer
drvback.c:74: warning: (near initialization for `test_fops')
drvback.c:76: warning: excess elements in struct initializer
drvback.c:76: warning: (near initialization for `test_fops')
drvback.c:78: warning: excess elements in struct initializer
drvback.c:78: warning: (near initialization for `test_fops')
drvback.c:80: warning: excess elements in struct initializer
drvback.c:80: warning: (near initialization for `test_fops')
drvback.c:82: warning: excess elements in struct initializer
drvback.c:82: warning: (near initialization for `test_fops')
drvback.c:84: warning: excess elements in struct initializer
drvback.c:84: warning: (near initialization for `test_fops')
drvback.c:86: warning: excess elements in struct initializer
drvback.c:86: warning: (near initialization for `test_fops')
drvback.c:88: warning: excess elements in struct initializer
drvback.c:88: warning: (near initialization for `test_fops')
drvback.c:88: warning: excess elements in struct initializer
drvback.c:88: warning: (near initialization for `test_fops')
drvback.c:90: warning: excess elements in struct initializer
drvback.c:90: warning:
源代码是:
#define __NO_VERSION__

#include <linux/module.h>;
#include <linux/version.h>;
#include <linux/kernel.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;
unsigned int test_major = 0;

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

char *buf,int count)

{

int left;


if (verify_area(1,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("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";

}

论坛徽章:
0
2 [报告]
发表于 2004-11-03 09:59 |只看该作者

关于驱动的问题 请各位大虾帮忙看看!!!

帮帮忙啊 给我解释啊,郁闷好几天了

论坛徽章:
0
3 [报告]
发表于 2004-11-03 18:44 |只看该作者

关于驱动的问题 请各位大虾帮忙看看!!!

还在郁闷 ,高手门 帮帮我啊 谢谢了
3Q~~~~~~~~~~

论坛徽章:
0
4 [报告]
发表于 2004-11-03 23:03 |只看该作者

关于驱动的问题 请各位大虾帮忙看看!!!

[quote]原帖由 "zljackdodo"]gcc -D__KERNEL__-DMODULE-LINUX -c drvback.c ..........[/quote 发表:


这个有问题,应该是 :


  1. gcc -D_KERNEL_    -DMODULE    -DLINUX -c drvback.c
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP