QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 778|回复: 0

驱动程序问题

[复制链接]
发表于 2005-3-8 10:58:59 | 显示全部楼层 |阅读模式
#ifndef __KERNEL__
#  define __KERNEL__
#endif
#ifndef MODULE
#  define MODULE
#endif

#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/time.h>
#include <linux/devfs_fs_kernel.h>

#define DF_IOC_MAGIC  'k'

#define DF_IOCRESET         _IO(DF_IOC_MAGIC, 0)
#define DF_GETTIME         _IO(DF_IOC_MAGIC, 1)


int df_open(struct inode *inode, struct file *filp){
   return 0;
}
int df_release(struct inode *inode, struct file *filp){
   return 0;
}

int df_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg){
   struct timeval time;
   
   switch(cmd){
   case DF_IOCRESET:
      while (MOD_IN_USE)
         MOD_DEC_USE_COUNT;
      MOD_INC_USE_COUNT;
      break;
   case DF_GETTIME:
      do_gettimeofday(&time);
      return(time.tv_sec);
      break;
   default:
      return -ENOTTY;
   }
   
   return 0;
}

struct file_operations df_fops = {
   ioctl:      df_ioctl,
   open:      df_open,
   release:   df_release,
};

devfs_handle_t df_devfs_dir;
devfs_handle_t de;

int df_init(){
   
   EXPORT_NO_SYMBOLS;

   SET_MODULE_OWNER(&df_fops);
   
   df_devfs_dir = devfs_mk_dir(NULL, "linuxfans", NULL);
   if (!df_devfs_dir) return -EBUSY;

   de = devfs_register(df_devfs_dir, "dragonfly",
         DEVFS_FL_AUTO_DEVNUM,
         0, 0, S_IFCHR | S_IRUGO | S_IWUGO,
         &df_fops,
         NULL);

   return 0;
}
   
void df_cleanup(){
   devfs_unregister(de);
   devfs_unregister(df_devfs_dir);
}

module_init(df_init);
module_exit(df_cleanup);
MODULE_LICENSE("GPL");

编译没有问题,insmod时# insmod df.o
df.o: init_module: Device or resource busy
Hint: insmod errors can be caused by incorrect module parameters, including
invalid IO or IRQ parameters.
      You may find more information in syslog or the output from dmesg
请教!谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-9-20 07:37 , Processed in 0.044226 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

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