Procfs hello world
Fuck you world... I will learn kernel, getting payed or not!!Here is a simple procfs hello world
The source (proc2.c)
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
static struct proc_dir_entry *proc_file;
int procfile_read(char *buf, char **buf_location, off_t offset,
int buf_len, int *eof, void *data)
{
return sprintf(buf, "Hello Word\n");
}
#define PROC_FILE_NAME "hello"
int init_module()
{
proc_file = create_proc_entry(PROC_FILE_NAME, 0644, NULL);
if (!proc_file) {
remove_proc_entry(PROC_FILE_NAME, NULL);
return -ENOMEM;
}
proc_file->read_proc = procfile_read;
proc_file->mode = 0644;
proc_file->uid = 0;
proc_file->gid = 0;
proc_file->size = 37;
return 0;
}
void cleanup_module()
{
remove_proc_entry(PROC_FILE_NAME, NULL);
}
The Makefile
obj-m += proc2.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
Compiling and running
Cheers :-P