khtmlparser.c

#include <linux/init.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/syscalls.h>
#include <linux/fcntl.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/unistd.h>
#include <asm/uaccess.h>
MODULE_LICENSE("Dual BSD/GPL");

#include "common.h"

static int khtmlparser_init(void)
{
mm_segment_t fs;
unsigned long ini, end, now, best, tsc;
int i;
struct file *fd;
char *html;
char *text;
html = kzalloc(BUFF_LEN, GFP_KERNEL);
text = kzalloc(BUFF_LEN, GFP_KERNEL);
best = ~0;
measure_time(0);
tsc = best;
printk(KERN_INFO "Time taken for no code: %ld\n", tsc);

/*Measure time of reading a file*/
/*Prepare to invoke system call*/
fs = get_fs(); /*Save previous value*/
set_fs(get_ds()); /*use kernel limit*/
/*Call system call*/
fd = filp_open(FILE_NAME, O_RDONLY, 0600);
if(IS_ERR(fd)){
printk(KERN_INFO "flip_open returned an error\n");
return(-EINVAL);
}
if(fd->f_op && fd->f_op->read){
best = ~0;
measure_time(fd->f_op->read(fd, html, 1000, &fd->f_pos));
printk(KERN_INFO "Time taken by read: %ld\n", best-tsc);
parse_html(html, text); /*Parse html to text*/
printk(KERN_INFO "Parsed text: %s", text);
}
if(fd) filp_close(fd, NULL);
set_fs(fs); /*restore before returning to userspace*/
return -EINVAL;
}

/*Never used*/
static void khtmlparser_exit(void)
{
}

module_init(khtmlparser_init);
module_exit(khtmlparser_exit);