Ive already completed part 1 and now working on part II Thes
I\'ve already completed part 1 and now working on part II.
These codes are what i have so far:
simple-solution.c:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/slab.h>
struct birthday
{
int month;
int day;
int year;
char *name;
struct list_head list;
};
static LIST_HEAD(birthday_list);
int simple_init(void)
{
________________________________
Makefile:
obj-m += simple-solution.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Programming Projects Linux Kernel Modules In this project, you will learn how to create a kernel module and load it into the Linux kernel. The project can be completed using the Linux virtual machine that is available with this text. Although you may use an editor to write these C programs, you will have to use the terminal application to compile the programs, and you will have to enter commands on the command line to manage the modules in the kernel. As you\'ll discover, the advantage of developing kernel modules is that it is a relatively easy method of interacting with the kernel, thus allowing you to write programs that directly invoke kernel functions. It is important for you to keep in mind that you are indeed writing kernel code that directly interacts with the kernel. That normally means that any errors in the code could crash the system! However, since you will be using a virtual machine, any failures will at worst only require rebooting the system. Part I-Creating Kernel Modules The first part of this project involves following a series of steps for creating and inserting a module into the Linux kernel. Programming Projects 97 You can list all kernel modules that are currently loaded by entering the lsmod. This command will list the current kernel modules in three columns: name, size, and where the module is being used The following program (nam simple.c and available with the source code for this text) illustrates a very basic kernel module that prints appropriate messages when the kernel module is loaded and unloadedSolution
Kindly checkout this program and comment if you face any issues with it .
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/slab.h>
struct birthday
{
int month;
int day;
int year;
char *name;
struct list_head list;
};
static LIST_HEAD(birthday_list);
int simple_init(void)
{
int i=0;
int day = 2, month = 8 ,year = 1995;
char* name[] = {\"linux\",\"unix\",\"Mac\",\"Windows\",\"Solaris\"};
struct birthday *temp = NULL;
while(i<5){
temp = kmalloc(sizeof(*temp),GFP_KERNEL);
temp->day = day++;
temp->month = month++;
temp->year = year++;
temp->name = name[i];
INIT_HEAD_LIST(&(temp->list));
list_add_tail(&(temp->list) , &(birthday_list));
i++;
}
temp = NULL;
list_for_each_entry(temp, &birthday_list, list){
printk(KERN_INFO \"Name : <%s>\ \",temp->name);
printk(KERN_INFO \"Birthday day : <%d/%d/%d>\ \",temp->month,temp->day,temp->year);
}
return 0;
}
int simple_exit(void)
{
struct birthday* ptr=NULL , *next = NULL;
int i =1;
list_for_each_entry_safe(ptr,next,&birthday_list,list){
printk(KERN_INFO \"Removind Element <%d> from list \ \",i++);
list_del(&(ptr->list));
kfree(ptr);
}
return 0;
}
module_init(simple_init);
module_exit(simple_exit);
MODULE_LICENSE(\"GPL\");
MODULE_DESCRIPTION(\"Simple Module\");
MODULE_AUTHOR(\"BLA_BLA\");


