分类:
2005-09-28 15:27:15
#include
#include
#include
#include
#include
#include
/* Deal with CONFIG_MODVERSIONS */
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include
#endif
/* In 2.2.3 /usr/include/linux/version.h includes a
* macro for this, but 2.0.35 doesn't - so I add it
* here if necessary. */
#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) ((a)*65536+(b)*256+(c))
#endif
#define MY_PROC_ENTRY_NAME "my_proc_entry"
struct proc_dir_entry *my_proc_entry=NULL;
static ssize_t ip_prof_output(
struct file *file,
char *buf,
size_t len,
loff_t *offset)
{
/* ... implement output from proc entry here ... */
return 0; /* returns number of output bytes */
}
static ssize_t ip_prof_input(
struct file *file,
const char *buf,
size_t len,
loff_t *offset)
{
/* ... implemetnt input into proc entry here ... */
return 0; /* returns number of input bytes */
}
int my_proc_entry_open(struct inode *inode, struct file *file) {
return 0;
}
int my_proc_entry_close(struct inode *inode, struct file *file){
return 0;
}
static int my_proc_entry_permission( struct inode *inode, int op) {
/* allow supeuser access only. doesn't really matter. */
if(op==4 || (op==2 && current->euid==0))
return 0;
return -EACCES;
}
static struct file_operations my_proc_entry_fops =
{
read: ip_prof_output,
write: ip_prof_input,
open: my_proc_entry_open,
release:my_proc_entry_close,
};
static struct inode_operations my_proc_entry_iops =
{
permission: my_proc_entry_permission
};
int start_my_proc_entry(void) {
my_proc_entry = create_proc_entry(MY_PROC_ENTRY_NAME, S_IFREG | S_IRUGO | S_IWUSR, &proc_root);
if ( !my_proc_entry ) return -ENOMEM;
my_proc_entry->proc_fops = &my_proc_entry_fops;
my_proc_entry->proc_iops = &my_proc_entry_iops;
return 0;
}
int stop_my_proc_entry(void) {
printk("my_proc_entry: terminating.
");
remove_proc_entry(MY_PROC_ENTRY_NAME, &proc_root);
return 0;
}
module_init(start_my_proc_entry);
module_exit(stop_my_proc_entry);