免费注册 查看新帖 |

Chinaunix

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

学写模块,编译出了点问题,求教 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-03 09:45 |只看该作者 |倒序浏览

  1.       1 #ifndef _KERNEL_
  2.       2 #define _KERNEL_
  3.       3 #endif
  4.       4
  5.       5 #ifndef MODULE
  6.       6 #define MODULE
  7.       7 #endif
  8.       8
  9.       9 #include <linux/module.h>
  10.      10 #include <linux/fs.h>
  11.      11
  12.      12 static ssize_t myfile_read(struct file *file, char *buf, size_t count, loff_t *offset) ;
  13.      13 static ssize_t myfile_write(struct file *file, const char *buf, size_t count, loff_t *offse        t) ;
  14.      14 static int myfile_open(struct inode *inod, struct file *file) ;
  15.      15 static int myfile_flush(struct file *file) ;
  16.      16 static int myfile_release(struct inode *inod, struct file *file) ;
  17.      17
  18.      18 const static unsigned int major = 126 ;
  19.      19
  20.      20 static struct file_operations myfile_fops = {
  21.      21         read:           myfile_read,
  22.      22         write:          myfile_write,
  23.      23         open:           myfile_open,
  24.      24         flush:          myfile_flush,
  25.      25         release:        myfile_release,
  26.      26 } ;
  27.      27
  28.      28
  29.      29 static int myfile_open(struct inode *inod, struct file *file)
  30.      30 {
  31.      31         MOD_INC_USE_COUNT;
  32.      32         return 0;
  33.      33 }
  34.      34
  35.      35 static int myfile_release(struct inode *inod, struct file *file)
  36.      36 {
  37.      37         MOD_DEC_USE_COUNT;
  38.      38         return 0;
  39.      39 }
  40.      40
  41.      41 static ssize_t myfile_read(struct file *file, char *buf, size_t count, loff_t *offset)
  42.      42 {
  43.      43         printk("<4>read %d char success.\n", count) ;
  44.      44         return count ;
  45.      45 }
  46.      46
  47.      47 static ssize_t myfile_write(struct file *file, const char *buf, size_t count, loff_t *offse        t)
  48.      48 {
  49.      49         printk("<4>write %d char success.\n", count) ;
  50.      50         return count ;
  51.      51 }
  52.      52
  53.      53 static int myfile_flush(struct file *file)
  54.      54 {
  55.      55         printk("<4>flush file success.\n") ;
  56.      56         return 0;
  57.      57 }
  58.      58
  59.      59 static int module_init(void)
  60.      60 {
  61.      61         int regStatus ;
  62.      62
  63.      63         regStatus = register_chrdev(major, "myfile", &myfile_fops) ;
  64.      64         if (regStatus)
  65.      65         {
  66.      66                 printk("<4>cann't register device with kernel.\n") ;
  67.      67                 return regStatus ;
  68.      68         }
  69.      69         else
  70.      70         {
  71.      71                 printk("<4>device registered with major %d.\n", major) ;
  72.      72         }
  73.      73
  74.      74         printk("<4>Hello world!\n") ;
  75.      75         return 0;
  76.      76 }
  77.      77
  78.      78 static void module_exit(void)
  79.      79 {
  80.      80         unregister_chrdev(major, "myfile") ;
  81.      81         printk("<4>Bye!\n") ;
  82.      82 }
  83.      83
  84.      84 MODULE_LICENSE("GPL");

复制代码


编译的时候这样的错误:
hello.c:59: error: two or more data types in declaration of `init_module'
hello.c: In function `__init_module_inline':
hello.c:59: error: syntax error before "void"
hello.c: At top level:
hello.c:63: error: initializer element is not constant
hello.c:63: warning: data definition has no type or storage class
hello.c:64: error: syntax error before "if"
hello.c:74: error: syntax error before string constant
hello.c:74: warning: data definition has no type or storage class
hello.c:78: error: two or more data types in declaration of `cleanup_module'
hello.c: In function `__cleanup_module_inline':
hello.c:78: error: syntax error before "void"
hello.c: At top level:
hello.c:81: error: syntax error before string constant
hello.c:81: warning: data definition has no type or storage class
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP