|
楼主 |
发表于 2003-5-25 22:28:35
|
显示全部楼层
dragonfly.c
dragonfly.c
[code:1]
#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>
#include "df.h"
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");
[/code:1] |
|