Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'master' of github.com:dr-itz/zhaw-os

  • Loading branch information...
commit 58dafbe5bedc2bf1c1e2a19016bfdfb696145216 2 parents 9f0040a + bfaa719
Daniel Ritz authored
7 linux-module/.gitignore
... ... @@ -0,0 +1,7 @@
  1 +*.ko
  2 +*.o
  3 +*.mod.c
  4 +.*.cmd
  5 +.tmp_versions/
  6 +Module.symvers
  7 +modules.order
1  linux-module/Makefile
... ... @@ -0,0 +1 @@
  1 +obj-m := dummy.o
1  linux-module/build.sh
... ... @@ -0,0 +1 @@
  1 +make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
85 linux-module/dummy.c
... ... @@ -0,0 +1,85 @@
  1 +#include <linux/kernel.h>
  2 +#include <linux/module.h>
  3 +#include <linux/init.h>
  4 +#include <linux/slab.h>
  5 +#include <linux/fs.h>
  6 +#include <linux/errno.h>
  7 +#include <linux/types.h>
  8 +#include <linux/uaccess.h>
  9 +
  10 +static int memory_major = 60;
  11 +static char *memory_buffer;
  12 +
  13 +static int memory_open(struct inode *inode, struct file *filp)
  14 +{
  15 + return 0;
  16 +}
  17 +
  18 +static int memory_release(struct inode *inode, struct file *filp)
  19 +{
  20 + return 0;
  21 +}
  22 +
  23 +static ssize_t memory_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
  24 +{
  25 + copy_to_user(buf, memory_buffer, 1);
  26 + if (*f_pos == 0) {
  27 + (*f_pos)++;
  28 + return 1;
  29 + }
  30 + return 0;
  31 +}
  32 +
  33 +static ssize_t memory_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)
  34 +{
  35 + const char *tmp = buf + count - 1;
  36 + copy_from_user(memory_buffer, tmp, 1);
  37 + return 1;
  38 +}
  39 +
  40 +static struct file_operations memory_fops = {
  41 + .read = memory_read,
  42 + .write = memory_write,
  43 + .open = memory_open,
  44 + .release = memory_release
  45 +};
  46 +
  47 +static int __init dummy_init(void)
  48 +{
  49 + int ret;
  50 +
  51 + printk(KERN_INFO "Dummy is loading\n");
  52 +
  53 + memory_buffer = kmalloc(1, GFP_KERNEL);
  54 + if (!memory_buffer)
  55 + return -ENOMEM;
  56 +
  57 + memset(memory_buffer, 0, 1);
  58 +
  59 + ret = register_chrdev(memory_major, "dummy", &memory_fops);
  60 + if (ret < 0)
  61 + goto fail;
  62 +
  63 + printk(KERN_INFO "Dummy initialized\n");
  64 + return 0;
  65 +
  66 +fail:
  67 + printk(KERN_INFO "dummy: cannot obtain major number %d\n", memory_major);
  68 + kfree(memory_buffer);
  69 + return ret;
  70 +}
  71 +
  72 +static void __exit dummy_exit(void)
  73 +{
  74 + unregister_chrdev(memory_major, "dummy");
  75 + kfree(memory_buffer);
  76 +
  77 + printk(KERN_INFO "Dummy is unloading, time to buzz off\n");
  78 +}
  79 +
  80 +module_init(dummy_init);
  81 +module_exit(dummy_exit);
  82 +
  83 +MODULE_AUTHOR("DrItz");
  84 +MODULE_DESCRIPTION("Dumber than a dummy");
  85 +MODULE_LICENSE("GPL");

0 comments on commit 58dafbe

Please sign in to comment.
Something went wrong with that request. Please try again.