/* Implementation of Linklist in Kernel */ # include # include # include # include # include typedef struct key_map { struct list_head list; int key; unsigned long long global_id; } key_map; int i=0; key_map *ptr = NULL; /** here i have declared it as extern and then assigned them in ll_init */ extern unsigned long long (*ptr1)(int); extern void (*ptr2)(int, unsigned long long); /*--------------------------------------------------------------------- */ void start(void) { ptr=(key_map *)kmalloc(sizeof(key_map),GFP_KERNEL); ptr->key = 0; ptr->global_id = 0; INIT_LIST_HEAD(&ptr->list); } void addk(int key, unsigned long long global_id) { key_map *temp = NULL; temp = (key_map *)kmalloc(sizeof(key_map),GFP_KERNEL); temp->key = key; temp->global_id = global_id; list_add(&temp->list,&ptr->list); printk(KERN_ALERT "\n Inserted a value : %d -> %lli ",temp->key,temp->global_id); } unsigned long long findk(int key) { key_map *temp = NULL; int i=0; printk(KERN_ALERT "\nwhat is the value of key(findk)::%d",key); for (temp=(key_map *)ptr->list.next;temp!=ptr;temp=(key_map *)temp->list.next) { printk(KERN_ALERT "\n%d -> %lli(findk)",temp->key,temp->global_id); if(temp->key == key) { i++; return(temp->global_id); } } printk(KERN_ALERT "\nhow many times i went in da loop %d\n",i); return 0; } static int ll_init(void) { printk(KERN_ALERT "\nLL entered !!!"); start(); ptr1 = findk; ptr2 = addk; return 0; } static void ll_exit(void) { printk(KERN_ALERT "\nLL exited !!!"); } module_init(ll_init); module_exit(ll_exit);