Created
May 28, 2013 09:23
-
-
Save starbops/5661574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> | |
#include <linux/proc_fs.h> | |
extern int flag_macaddr; | |
static struct proc_dir_entry *macaddr_file; | |
static int proc_read_macaddr(char *page, char **start, off_t off, | |
int count, int *eof, void *data) | |
{ | |
printk("flag_macaddr is %d\n", flag_macaddr); | |
return 0; | |
} | |
static int proc_write_macaddr(struct file *file, const char *buffer, | |
unsigned long count, void *data) | |
{ | |
switch (buffer[0]) { | |
case '0': | |
flag_macaddr = 0; | |
return count; | |
case '1': | |
flag_macaddr = 1; | |
return count; | |
default: | |
return -EFAULT; | |
} | |
10 | |
return count; | |
} | |
int init_module(void) | |
{ | |
int ret = 0; | |
macaddr_file = create_proc_entry("proc_macaddr", 0644, NULL); | |
if (macaddr_file == NULL) { | |
ret = -ENOMEM; | |
printk("Could not create proc entry\n"); | |
} else { | |
macaddr_file->read_proc = proc_read_macaddr; | |
macaddr_file->write_proc = proc_write_macaddr; | |
macaddr_file->owner = THIS_MODULE; | |
printk("/proc/%s initialized\n", "proc_macaddr"); | |
} | |
return ret; | |
} | |
void cleanup_module(void) | |
{ | |
flag_macaddr = 0; | |
remove_proc_entry("proc_macaddr", NULL); | |
printk("/proc/%s removed\n", "proc_macaddr"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment