免费注册 查看新帖 |

Chinaunix

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

求助~ [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-08-07 14:35 |只看该作者 |倒序浏览
#define __NO_VERSION__

#include <linux/module.h>
#include <linux/config.h>
#include <linux/version.h>

#include <asm/uaccess.h>

#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 ssize_t read_test(struct file *file,char *buf,size_t count,loff_t *f_pos)

{ int left;

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

for(left = count ; left > 0 ; left--)
{
__put_user(1,buf);
buf++;
}

return count;
}


static ssize_t write_test(struct file *file, const char *buf, size_t count, loff_t *f_pos)
{
return count;
}

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

{
MOD_INC_USE_COUNT;
return 0;
}

static int release_test(struct inode *inode,struct file *file )
{
MOD_DEC_USE_COUNT;
return 0;
}


struct file_operations test_fops = {
read:read_test,
write:write_test,
open: open_test,
release:release_test
};

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\n");
return result;

}

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

return 0;

}


void cleanup_module(void)

{

unregister_chrdev(test_major, "test");

}
test.c文件是这样写的,redhat90 2.4.20-8版
Makefile
CC=gcc
MODCFLAGS:=-Wall -DMODULE -D__KERNEL__ -DLINUX -I /usr/src/linux-2.4.20-8/include
test.o:test.c
                  $(CC) $(MODCFLAGS) -c test.c
网上说直接编译能生成.o文件,可我却出如下错误
test.c:46: storage size of `test_fops' isn't known
生成不了.o文件,请问是什么原因,谢谢

论坛徽章:
3
金牛座
日期:2014-06-14 22:04:062015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:45
2 [报告]
发表于 2008-08-07 14:48 |只看该作者
你这个makefile写的似乎不对,你看看这个hello-1的makefile
TARGET  := hello-1
WARN    := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE := -isystem /lib/modules/`uname -r`/build/include
CFLAGS  := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
CC      := gcc-3.0
       
${TARGET}.o: ${TARGET}.c

.PHONY: clean

clean:
    rm -rf {TARGET}.o

论坛徽章:
0
3 [报告]
发表于 2008-08-10 14:27 |只看该作者
struct file_operations test_fops = {
read:read_test,
write:write_test,
open: open_test,
release:release_test  //是不是少了个"," ?
};

论坛徽章:
3
金牛座
日期:2014-06-14 22:04:062015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:45
4 [报告]
发表于 2008-08-11 09:56 |只看该作者

回复 #3 tudouren 的帖子

不是,这个地方不能加“,”,这是对的。

论坛徽章:
0
5 [报告]
发表于 2008-08-11 15:17 |只看该作者
感谢~ 问题已经解决了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP