As the web references tell you, its a really bad idea.
There is no protection, and its almost a raw i/o operation you're
doing.
If you still want to do it.
This is a simple file open, and read 1 byte of data.
<code>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <asm/uaccess.h>
int init_module(void)
{
char c[1];
struct file *op;
op = filp_open("/root/abc", O_RDONLY, 0);
if(op == NULL) {
printk("error, opening\n");
return -1;
} else {
mm_segment_t fs;
fs = get_fs();
set_fs(get_ds());
printk("ok, continue\n");
int ret;
ret = op->f_op->read(op, c, 1, &op->f_pos);
set_fs(fs);
printk("%d\n", ret);
printk("%s\n", c);
return 0;
}
}
void cleanup_module(void)
{
//Nothing to do here
}
MODULE_LICENSE("GPL");
<end_of_code>
I tested it on a slightly modified 2.6.25 (fedora 9)
Assumptions :
1) You know how to get this module compiled.
2) There is a file called "abc" under your /root directory and it has
atleast 1 byte of data.
If you noticed the main function is "filp_open"
get_fs and set_fs are for the fs specific info.
This program can read from any filesystem, even cdroms!
If you're looking for something really specific to EXT then I suggest
you go a layer below this(as in below the VFS).