#include <linux/proc_fs.h>
static struct proc_dir_entry *proc_xxx = NULL;
int xxx_read_proc(char *page, char **start, off_t off,int count, int *eof, void *data)
{
int len = 0;
if(off > 0)
{
*eof = 1;
return 0;
}
len = sprintf(page + len,"Debug Mode: echo 1 >/proc/driver/xxx \n");
len += sprintf(page + len,"Normal Mode: echo 0 >/proc/driver/xxx \n");
return len;
}
static int xxx_write_proc(struct file *file, const char __user *buffer, unsigned long count, void *data)
{
char CommandLine[20] = {0};
if (0 != copy_from_user(CommandLine, buffer, 20))
{
printk("copy_from_user failed\r\n");
return -1;
}
sscanf(CommandLine, "%x", &DebugFlag);
return count;
}
static int __init xxx_init(void)
{
proc_xxx = create_proc_entry(MODULE_NAME, 0644,proc_root_driver);
if(proc_xxx != NULL)
{
proc_xxx->owner = THIS_MODULE;
proc_xxx->read_proc = xxx_read_proc;
proc_xxx->write_proc = xxx_write_proc;
}
else
{
printk("create_proc_entry for xxx failed!\n");
goto unregister_chrdev;
}
return 0;
}
static void __exit xxx_exit(void)
{
remove_proc_entry(MODULE_NAME,proc_root_driver);
}
module_init(xxx_init);
module_exit(xxx_exit);
Proc文件系统
最新推荐文章于 2023-05-09 13:46:18 发布