diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | evspy-core.h | 6 | ||||
-rw-r--r-- | kmap/Makefile (renamed from khm/Makefile) | 2 | ||||
-rw-r--r-- | kmap/kmap.c (renamed from khm/khm.c) | 66 | ||||
-rw-r--r-- | kmap/kmap.h (renamed from khm/khm.h) | 26 | ||||
-rw-r--r-- | kmap/test_kmap.c (renamed from khm/test_khm.c) | 34 | ||||
-rw-r--r-- | maps/map_en.h | 8 | ||||
-rw-r--r-- | maps/map_es.h | 16 | ||||
-rw-r--r-- | maps/maps.h | 6 |
10 files changed, 84 insertions, 84 deletions
@@ -1,5 +1,5 @@ obj-m += evspy.o -evspy-objs := khm/khm.o evspy-core.o +evspy-objs := kmap/kmap.o evspy-core.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules @@ -41,7 +41,7 @@ Once it has been installed, you can load it when you want with A patch is supplied (evspy.patch) to be able to compile a kernel with evspy included. If KERN is the directory where your kernel is located, just copy the -patch there (KERN/) and copy all the evspy files (*.c, *.h, maps, khm) to +patch there (KERN/) and copy all the evspy files (*.c, *.h, maps, kmap) to KERN/drivers/input/. Then, cd to KERN and apply the patch: $ patch -p1 < evspy.patch diff --git a/evspy-core.h b/evspy-core.h index eec489c..dfc0b2e 100644 --- a/evspy-core.h +++ b/evspy-core.h @@ -30,7 +30,7 @@ #include <linux/stat.h> #include <linux/string.h> #include <asm/page.h> -#include "khm/khm.h" +#include "kmap/kmap.h" // Keyboard layouts #define EVS_KLAY_EN 0 @@ -130,7 +130,7 @@ } else if (is_ascii(c) || !shift_on) { \ __c = map[c]; \ } else { \ - if ((__vp = khm_get(shm, (c)))) \ + if ((__vp = kmap_get(skm, (c)))) \ __c = *(char *)__vp; \ else \ __c = map[c]; \ @@ -146,7 +146,7 @@ ({ \ void *__vp; \ char __c; \ - __vp = khm_get(ahm, (c)); \ + __vp = kmap_get(akm, (c)); \ if (__vp) __c = *(char *)__vp; \ else __c = map[c]; \ __c; \ diff --git a/khm/Makefile b/kmap/Makefile index 74ffd5f..62aa5c8 100644 --- a/khm/Makefile +++ b/kmap/Makefile @@ -1,5 +1,5 @@ obj-m += test.o -test-objs := khm.o test_khm.o +test-objs := kmap.o test_kmap.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules @@ -1,39 +1,39 @@ /* - * khm - (Linux) kernel hash map implementation + * kmap - (Linux) kernel map implementation * * Copyright (c) 2011 Guillermo Ramos <0xwille@gmail.com> * - * This file is part of khm + * This file is part of kmap * - * khm is free software: you can redistribute it and/or modify + * kmap is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * khm is distributed in the hope that it will be useful, + * kmap is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with khm. If not, see <http://www.gnu.org/licenses/>. + * along with kmap. If not, see <http://www.gnu.org/licenses/>. */ #include <linux/errno.h> #include <linux/list.h> #include <linux/slab.h> -#include "khm.h" +#include "kmap.h" /* * Returns the node with the value passed, or NULL in case it does not exist */ -static inline struct khashmap *khm_search(struct khashmap *head, int value) +static inline struct kmap *kmap_search(struct kmap *head, int value) { struct list_head *list; - struct khashmap *node; + struct kmap *node; list_for_each(list, &head->l) { - node = list_entry(list, struct khashmap, l); + node = list_entry(list, struct kmap, l); if (node->value == value) return node; } @@ -42,16 +42,16 @@ static inline struct khashmap *khm_search(struct khashmap *head, int value) } /* - * Prints in klog a representation of all the nodes in the hashmap + * Prints in klog a representation of all the nodes in the map */ -void khm_display(struct khashmap *head) +void kmap_display(struct kmap *head) { - struct khashmap *node; + struct kmap *node; struct list_head *list; printk(KERN_ALERT "Displaying..."); list_for_each(list, &head->l) { - node = list_entry(list, struct khashmap, l); + node = list_entry(list, struct kmap, l); printk(KERN_ALERT " %p: v=%d d=%s\n", node, node->value, (char*)node->data); } @@ -60,11 +60,11 @@ void khm_display(struct khashmap *head) /* * Creates and returns a new head node */ -inline struct khashmap *khm_create(void) +inline struct kmap *kmap_create(void) { - struct khashmap *head; + struct kmap *head; - head = kmalloc(sizeof(struct khashmap), GFP_KERNEL); + head = kmalloc(sizeof(struct kmap), GFP_KERNEL); if (unlikely(!head)) return NULL; @@ -74,15 +74,15 @@ inline struct khashmap *khm_create(void) } /* - * Deletes the hashmap and frees the memory used by its nodes + * Deletes the map and frees the memory used by its nodes */ -void khm_destroy(struct khashmap *head) +void kmap_destroy(struct kmap *head) { - struct khashmap *node; + struct kmap *node; struct list_head *list = head->l.next; while (list != &head->l) { - node = list_entry(list, struct khashmap, l); + node = list_entry(list, struct kmap, l); list = list->next; kfree(node); } @@ -91,17 +91,17 @@ void khm_destroy(struct khashmap *head) } /* - * Creates a new node with the given value and data, and adds it to the hm head + * Creates a new node with the given value and data, and adds it to the map head */ -int khm_insert(struct khashmap *head, int value, void *data) +int kmap_insert(struct kmap *head, int value, void *data) { - struct khashmap *new; + struct kmap *new; // Key already exists - if (khm_search(head, value)) + if (kmap_search(head, value)) return -EINVAL; - new = khm_create(); + new = kmap_create(); if (unlikely(!new)) return -ENOMEM; @@ -113,11 +113,11 @@ int khm_insert(struct khashmap *head, int value, void *data) } /* - * Removes from the hashmap the node with the given value. + * Removes from the map the node with the given value. */ -int khm_delete(struct khashmap *head, int value) +int kmap_delete(struct kmap *head, int value) { - struct khashmap *node = khm_search(head, value); + struct kmap *node = kmap_search(head, value); if (node) { list_del(&node->l); @@ -132,9 +132,9 @@ int khm_delete(struct khashmap *head, int value) * Returns the data mapped to the given value, or NULL if that value has no data * associated to it */ -void *khm_get(struct khashmap *head, int value) +void *kmap_get(struct kmap *head, int value) { - struct khashmap *node = khm_search(head, value); + struct kmap *node = kmap_search(head, value); if (node) return node->data; @@ -143,11 +143,11 @@ void *khm_get(struct khashmap *head, int value) } /* - * Associates the given value with new data, if the value was already in the hm + * Associates the given value with new data, if the value was already in the map */ -void khm_set(struct khashmap *head, int value, void *data) +void kmap_set(struct kmap *head, int value, void *data) { - struct khashmap *node = khm_search(head, value); + struct kmap *node = kmap_search(head, value); if (node) node->data = data; @@ -1,22 +1,22 @@ /* - * khm - (Linux) kernel hash map implementation + * kmap - (Linux) kernel map implementation * * Copyright (c) 2011 Guillermo Ramos <0xwille@gmail.com> * - * This file is part of khm + * This file is part of kmap * - * khm is free software: you can redistribute it and/or modify + * kmap is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * khm is distributed in the hope that it will be useful, + * kmap is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with khm. If not, see <http://www.gnu.org/licenses/>. + * along with kmap. If not, see <http://www.gnu.org/licenses/>. */ #include <linux/list.h> @@ -24,18 +24,18 @@ #ifndef KHM #define KHM -struct khashmap { +struct kmap { struct list_head l; int value; void *data; }; -struct khashmap *khm_create(void); -void khm_destroy(struct khashmap *head); -int khm_insert(struct khashmap *head, int value, void *data); -int khm_delete(struct khashmap *head, int value); -void *khm_get(struct khashmap *head, int value); -void khm_set(struct khashmap *head, int value, void *data); -void khm_display(struct khashmap *head); +struct kmap *kmap_create(void); +void kmap_destroy(struct kmap *head); +int kmap_insert(struct kmap *head, int value, void *data); +int kmap_delete(struct kmap *head, int value); +void *kmap_get(struct kmap *head, int value); +void kmap_set(struct kmap *head, int value, void *data); +void kmap_display(struct kmap *head); #endif // KHM diff --git a/khm/test_khm.c b/kmap/test_kmap.c index d8b0180..577eeb5 100644 --- a/khm/test_khm.c +++ b/kmap/test_kmap.c @@ -1,51 +1,51 @@ #include <linux/module.h> #include <linux/init.h> -#include "khm.h" +#include "kmap.h" #define Z_ASD 1 #define Z_QWE 2 #define Z_BLR 3 -static struct khashmap *hm; +static struct kmap *km; static int __init test_init(void) { char *values; - hm = khm_create(); + km = kmap_create(); - if ((values = (char*)khm_get(hm, Z_BLR))) + if ((values = (char*)kmap_get(km, Z_BLR))) printk(KERN_ALERT "ERROR: Z_BLR exists: %s\n", values); else printk(KERN_ALERT "Z_BLR does not exist (good)\n"); - if (khm_insert(hm, Z_ASD, "ASDF")) + if (kmap_insert(km, Z_ASD, "ASDF")) goto insert_err; - if (khm_insert(hm, Z_QWE, "QWERTY")) + if (kmap_insert(km, Z_QWE, "QWERTY")) goto insert_err; - if (khm_insert(hm, Z_BLR, "BLRBLRBLR")) + if (kmap_insert(km, Z_BLR, "BLRBLRBLR")) goto insert_err; - khm_display(hm); - khm_delete(hm, Z_QWE); - khm_display(hm); - khm_set(hm, Z_ASD, "ASDF NEW!!"); - khm_display(hm); + kmap_display(km); + kmap_delete(km, Z_QWE); + kmap_display(km); + kmap_set(km, Z_ASD, "ASDF NEW!!"); + kmap_display(km); - if ((values = (char*)khm_get(hm, Z_ASD))) + if ((values = (char*)kmap_get(km, Z_ASD))) printk(KERN_ALERT "Z_ASD: %s\n", values); else printk(KERN_ALERT "Z_ASD does not exist\n"); - if ((values = (char*)khm_get(hm, Z_QWE))) + if ((values = (char*)kmap_get(km, Z_QWE))) printk(KERN_ALERT "Z_QWE: %s\n", values); else printk(KERN_ALERT "Z_QWE does not exist\n"); - if ((values = (char*)khm_get(hm, Z_BLR))) + if ((values = (char*)kmap_get(km, Z_BLR))) printk(KERN_ALERT "Z_BLR: %s\n", values); else printk(KERN_ALERT "Z_BLR does not exist\n"); - if (khm_insert(hm, Z_ASD, "REPEATED!!")) + if (kmap_insert(km, Z_ASD, "REPEATED!!")) goto insert_err; return 0; @@ -57,7 +57,7 @@ insert_err: static void __exit test_exit(void) { - khm_destroy(hm); + kmap_destroy(km); } module_init(test_init); diff --git a/maps/map_en.h b/maps/map_en.h index 93b9db7..56fd895 100644 --- a/maps/map_en.h +++ b/maps/map_en.h @@ -8,13 +8,13 @@ // Shift map -#define EVS_SHIFT_BIND(KEY, VALUE) khm_insert(shm, (KEY), (VALUE)) +#define EVS_SHIFT_BIND(KEY, VALUE) kmap_insert(skm, (KEY), (VALUE)) -static struct khashmap *shm; +static struct kmap *skm; static void init_shiftmap(void) { - shm = khm_create(); + skm = kmap_create(); EVS_SHIFT_BIND(KEY_1, "!"); EVS_SHIFT_BIND(KEY_2, "@"); EVS_SHIFT_BIND(KEY_3, "#"); @@ -41,7 +41,7 @@ static void init_shiftmap(void) static inline void exit_shiftmap(void) { - khm_destroy(shm); + kmap_destroy(skm); } static char map[] = { diff --git a/maps/map_es.h b/maps/map_es.h index 1b0946f..b20f120 100644 --- a/maps/map_es.h +++ b/maps/map_es.h @@ -9,13 +9,13 @@ // Right Alt (ALTGR) map #define EVS_ALTGR_ENABLED -#define EVS_ALTGR_BIND(KEY, VALUE) khm_insert(ahm, (KEY), (VALUE)) +#define EVS_ALTGR_BIND(KEY, VALUE) kmap_insert(akm, (KEY), (VALUE)) -static struct khashmap *ahm; +static struct kmap *akm; static void init_altgrmap(void) { - ahm = khm_create(); + akm = kmap_create(); EVS_ALTGR_BIND(KEY_1, "|"); EVS_ALTGR_BIND(KEY_2, "@"); EVS_ALTGR_BIND(KEY_3, "#"); @@ -41,17 +41,17 @@ static void init_altgrmap(void) static inline void exit_altgrmap(void) { - khm_destroy(ahm); + kmap_destroy(akm); } // Shift map -#define EVS_SHIFT_BIND(KEY, VALUE) khm_insert(shm, (KEY), (VALUE)) +#define EVS_SHIFT_BIND(KEY, VALUE) kmap_insert(skm, (KEY), (VALUE)) -static struct khashmap *shm; +static struct kmap *skm; static void init_shiftmap(void) { - shm = khm_create(); + skm = kmap_create(); EVS_SHIFT_BIND(KEY_1, "!"); EVS_SHIFT_BIND(KEY_2, "\""); EVS_SHIFT_BIND(KEY_4, "$"); @@ -75,7 +75,7 @@ static void init_shiftmap(void) static inline void exit_shiftmap(void) { - khm_destroy(shm); + kmap_destroy(skm); } static char map[] = { diff --git a/maps/maps.h b/maps/maps.h index c6e3095..969dc6f 100644 --- a/maps/maps.h +++ b/maps/maps.h @@ -11,13 +11,13 @@ * position is the key value associated with the event code (index). It also * defines a function called init_shiftmap that can register any number of shift * keys to be parsed when shift or capslock has been pressed, and exit_shiftmap, - * that cleans up the map (by default, it just destroys the hashmap used by the + * that cleans up the map (by default, it just destroys the map used by the * previous function). * * For example, * EVS_SHIFT(KEY_7, "/"); * associates the key of number 7 to the slash character when shift is pressed. - * Yeah, the character associated is a string: this is because of the hashmap + * Yeah, the character associated is a string: this is because of the map (kmap) * implementation, [int -> (void *)]. * * From version 0.3 up, you can also define how evspy should register AltGr-key @@ -34,7 +34,7 @@ #define __EVS_MAPS #include <linux/input.h> -#include "../khm/khm.h" +#include "../kmap/kmap.h" // Load the map associated with the given keyboard layout |