LinuxÒÁµéÔ°ÂÛ̳'s Archiver

robin_lu ·¢±íÓÚ 2007-8-12 14:08

дÁ˸ö¼òµ¥µÄÉ豸Çý¶¯£¬µ÷ÊÔ³öÁËÎÊÌ⣬Çë¸ßÊÖÖ¸Õý£¡£¡£¡

µ÷ÊÔ³öÏÖÈçÏÂÎÊÌ⣺

test1.C:47: sorry, not implemented: non-trivial labeled initializers
test1.C:47: invalid conversion from `ssize_t (*)(file*, char*, unsigned int,
   loff_t*)' to `loff_t (*)(file*, long long int, int)'
test1.C:47: sorry, not implemented: non-trivial labeled initializers
test1.C:47: invalid conversion from `ssize_t (*)(file*, const char*, unsigned
   int, loff_t*)' to `ssize_t (*)(file*, char*, unsigned int, loff_t*)'
test1.C:47: sorry, not implemented: non-trivial labeled initializers
test1.C:47: invalid conversion from `int (*)(inode*, file*)' to `ssize_t
   (*)(file*, const char*, unsigned int, loff_t*)'
test1.C:47: sorry, not implemented: non-trivial labeled initializers
test1.C:47: invalid conversion from `int (*)(inode*, file*)' to `int (*)(file*,
   void*, int (*)(void*, const char*, int, long long int, long unsigned int,
   unsigned int))'


Çë¸÷λ¸øµã½â¾öÒâ¼û£¬Ð»Ð»£¡:'(

$ gcc -D_KERNEL_ -DMODULE -DLINUX -I/usr/src/linux-2.4.20-8/include  -c  test1.C

Ô´´úÂëÈçÏ£º

#ifndef __KERNEL__
  #define __KERNEL__
#endif

#ifndef MODULE
  #define MODULE
#endif

#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>     // printk()
#include <linux/types.h>   // size_t
#include <asm/delay.h>
#include <asm/uaccess.h>

MODULE_LICENSE("GPL");

#define MAJOR_NUM 0 //Ö÷É豸ºÅ

static int test_var = 66;

static ssize_t test_read(struct file *filp, char *buf, size_t len, loff_t *f_pos);
static ssize_t test_write(struct file *filp, const char *buf, size_t len, loff_t *f_pos);
static int test_open(struct inode *inode, struct file *file);
static int test_release(struct inode *inode, struct file *file);
static int test_init(void);
static void  test_exit(void);

static struct file_operations test_fops ={

  owner:    THIS_MODULE,       

  read:     test_read,

  write:    test_write,

  open:     test_open,

  release:  test_release,
};


static int test_init(void)
{
  int ret=register_chrdev(MAJOR_NUM, "test", &test_fops);

if(ret)
  {
   printk("test register failure");

  }
else
  {
   printk("test register success!");
  }
return ret;
}


static void  test_exit(void)
{
  int ret=unregister_chrdev(MAJOR_NUM, "test");

if(ret)
  {
   printk("test unregister failure");
  }

else
  {
   printk("test unregister success");
  }

}


static ssize_t  test_read(struct file *filp, char *buf, size_t len, loff_t *f_pos)
{

if(copy_to_user(buf, &test_var, sizeof(int)))
  {
   return - EFAULT;
  }

return sizeof(int);

}


static ssize_t test_write(struct file *filp, const char *buf, size_t len, loff_t *f_pos)
{

if(copy_from_user(&test_var, buf, sizeof(int)))
  {
    return - EFAULT;
  }

return sizeof(int);

}


static int test_open(struct inode *inode,struct file *file)
{
          MOD_INC_USE_COUNT;
          return 0;
}


static int test_release(struct inode *inode,struct file *file)
{
          MOD_DEC_USE_COUNT;
          return (0);
}
module_init(test_init);
module_exit(test_exit);

AIKO_sex ·¢±íÓÚ 2007-8-13 09:25

Çý¶¯ÕýÈ·

±àÒëÃüÁî»òÐí·¾¶ÓÐÎÊÌâ

robin_lu ·¢±íÓÚ 2007-8-13 16:38

¼ÈÈ»ÒѾ­°ïæ»Ø´ðÁË   ÄÇôÄܸø³ö¾ßÌåÏêϸµÄ²Ù×÷Âð£¿Ð»Ð»£¡

AIKO_sex ·¢±íÓÚ 2007-8-13 17:04

±ÈÈç˵2¡£4¡£20£­8

¿´ÆðÀ´ÊÇredhat8

ÄãµÄÈç¹û²»ÊÇ·¾¶¾ÍÓÐÎÊÌâ±àÒëÆ÷Èç¹ûÒ²²»ÊÇÒ²¿ÉÄÜÓÐÎÊÌâ

robin_lu ·¢±íÓÚ 2007-8-13 21:14

ÎҵľÍÊÇredhat9µÄ   

ÎÒÖªµÀÎÊÌâÁË  

°Ñ test1.C  ¸ÄΪ test1.c  ¾ÍOKÁË     

ÆäËû ûÓÐÎÊÌâ  Õý³£±àÒëͨ¹ý£¡£¡:lol :lol :lol

yuzheng110 ·¢±íÓÚ 2007-8-22 10:06

ÎÒ°ÑÄãµÄÀý×ÓÔÚÎҵĶöREDHAT9¡£0ÉϱãÒ˳öºÜ¶à´íÎó£¬ Ëµdelay.h ¡£¡£¶¼ÕÒ²»µ½£¬ ÊDz»ÊÇÎÒÄÄÀïûŪºÃ°¡£¬ Çë°ïæ¿©£¬ »¹Ã»ÔÚLINUXÉϳɹ¦±ãÒ˹ýÒ»¸öÉ豸Çý¶¯£¬ ÓôÃÆÖС£¡£:Q

tengqian ·¢±íÓÚ 2007-8-22 21:05

ÔÚregist_chardevÖУ¬Ö÷É豸ºÃΪÁãʱ±íʾ×Ô¶¯»ñÈ¡É豸ºÅ£¬·µ»ØÖµRET²ÅÊÇÄãËùÉêÇëµ½µÄÖ÷É豸ºÅ£¬ÄãÓ¦¸Ã¼°Ê±¸ü¸ÄMAJORµÄÖµ£¬²¢ÇÒÄãûÓÐʹÓÃÉ豸ÎļþϵͳÀ´½¨Á¢Îļþ½Úµã£¬É豸Îļþ½ÚµãµÄ½¨Á¢º¯ÊýΪdevfs_register,²ÎÊýÓкܶ࣬ÆäÖÐÓÐÒ»¸öÊÇ´ÎÉ豸ºÅ¡£

luotuo2761 ·¢±íÓÚ 2007-9-17 21:06

GPIOÇý¶¯

×î½üÔÚѧÇý¶¯£¬µ«ÊÇ¿àÓÚÎÞ´¦ÏÂÊÖ£¬Ï£Íû¸ßÊÖÄÜÌṩ¸öGPIOµÄÇý¶¯¹²Ñ§Ï°£¬Ð»Ð»£¬ÎÒµÄÓÊÏäÊÇ[email]luotuo2761@sohu.com[/email]

Ò³: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.