#include <linux/config.h>
#include <linux/module.h>
#include <linux/version.h>
#include <asm/uaccess.h>  

#include <linux/types.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/errno.h>
#include <asm/segment.h>


int major=66;
#define	BUF_LEN 100
static	int msg_len=0;
static char kbuf[BUF_LEN];

static ssize_t read_bufdev(struct file *zfile, char *buf, size_t length, 
		loff_t *offset){
	int n=0;

	printk(KERN_INFO "I am in the read routine\n");
			put_user(kbuf[n],buf++); /* transfer one byte to the user buffer */
	
	return 1;
}

static ssize_t write_bufdev(struct file *zfile, const char *buf, size_t length,
		loff_t *offset) {
	int n=0;

	printk(KERN_INFO "I am in the write routine\n");
			get_user(kbuf[n], buf+n); /* transfer one byte from the user buffer */
	
	return 1;
}


static int open_bufdev(struct inode *zinode, struct file *zfile) {

	return 0;
}

static int release_bufdev(struct inode *zinode, struct file *zfile) {
	return 0;
}

static struct file_operations bufdev_fops = {
  .owner= THIS_MODULE,
  .read= read_bufdev,
  .write= write_bufdev,
  .open= open_bufdev,
  .release= release_bufdev,
};

int init_bufdev(void)
{
int status;
if((status = register_chrdev(major, "bufdev", &bufdev_fops)) <0) {
    printk("unable to get major for bufdev device\n");
    return -1;
  }
    return 0;
}

void cleanup_bufdev(void)
{
  unregister_chrdev(major, "bufdev");
}

module_init(init_bufdev);
module_exit(cleanup_bufdev);
