#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h> /* printk() */
#include <linux/slab.h> /* kmalloc() */
#include <linux/fs.h> /* everything... */
#include <linux/errno.h> /* error codes */
#include <linux/types.h> /* size_t */
#include <linux/proc_fs.h>
#include <linux/fcntl.h> /* O_ACCMODE */
#include <asm/uaccess.h> /* copy_from/to_user */

MODULE_LICENSE("Dual BSD/GPL");

/* Declaration of memory.c functions */
int memory_open(struct inode *inode, struct file *filp);
int memory_release(struct inode *inode, struct file *filp);
ssize_t memory_read(struct file *filp, char *buf, size_t count, loff_t *f_pos);
ssize_t memory_write(struct file *filp,
                     const char *buf, size_t count, loff_t *f_pos);
void memory_exit(void);
int memory_init(void);

/* Structure that declares the usual file access functions */
struct file_operations memory_fops = {
    read:    memory_read,
    write:   memory_write,
    open:    memory_open,
    release: memory_release
};

/* Declaration of the init and exit functions */
module_init(memory_init);
module_exit(memory_exit);

/* Global variables of the driver */
int memory_major = ;                        /* Major Device Number */
char *memory_buffer;                        /* Buffer to store data */

int memory_init(void) {
     int result;

     /* Register device using register_chrdev() function */

     if (result < 0) {
          printk("Memory: cannot obtain major number %d\n", memory_major);
          return result;
     }
     /* Allocating memory for the buffer; use kmalloc() not malloc() */
     memory_buffer = 
     if (!memory_buffer) {
          result = -ENOMEM;
          memory_exit();
          return result;
     }

     printk("Inserting memory module\n");

     return 0;
}

void memory_exit(void) {
     /* Freeing the major number using unregister_chrdev() function */

     /* Freeing buffer memory */
     if (memory_buffer) {
          kfree(memory_buffer);
     }
     printk("Removing memory module\n");
}

int memory_open(struct inode *inode, struct file *filp) {

     return 0;
}

int memory_release(struct inode *inode, struct file *filp) {

     return 0;
}

ssize_t memory_read(struct file *filp, char *buf,
                    size_t count, loff_t *f_pos) {
     /* Transfering data to user space using copy_to_user() function */

     if (*f_pos == 0) {
          *f_pos+=1;            /* Change this code correctly! */
          return 1;
     } else {
          return 0;
     }
}

ssize_t memory_write( struct file *filp, const char *buf,
                      size_t count, loff_t *f_pos) {
     char *tmp;

     tmp=buf+count-1;           /* Change this line of code */
     /** Copy to kernel space using copy_from_user() function */

     return 1;
}

