Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

It needs to show this #include #include #include #include #include struct birthday { int month; int day; int year; char *name; struct list_head list; };

It needs to show this

#include

#include

#include

#include

#include

struct birthday

{

int month;

int day;

int year;

char *name;

struct list_head list;

};

/**

* The following defines and initializes a list_head object named birthday_list

*/

static LIST_HEAD(birthday_list);

int simple_init(void)

{

struct birthday *person;

/* Creating Person 1 */

person = kmalloc(sizeof(*person), GFP_KERNEL);

person->month = 8;

person->day = 12;

person->year = 1993;

person->name = "Aaron";

INIT_LIST_HEAD(&person->list);

list_add_tail(&person->list, &birthday_list);

/* Creating Person 2 */

person = kmalloc(sizeof(*person), GFP_KERNEL);

person->month = 4;

person->day = 15;

person->year = 1993;

person->name = "Fish";

INIT_LIST_HEAD(&person->list);

list_add_tail(&person->list, &birthday_list);

/* Creating Person 3 */

person = kmalloc(sizeof(*person), GFP_KERNEL);

person->month = 3;

person->day = 29;

person->year = 1983;

person->name = "js";

INIT_LIST_HEAD(&person->list);

list_add_tail(&person->list, &birthday_list);

/* Creating Person 4 */

person = kmalloc(sizeof(*person), GFP_KERNEL);

person->month = 7;

person->day = 25;

person->year = 1999;

person->name = "Mark";

INIT_LIST_HEAD(&person->list);

list_add_tail(&person->list, &birthday_list);

/* Creating Person 5 */

person = kmalloc(sizeof(*person), GFP_KERNEL);

person->month = 7;

person->day = 19;

person->year = 1992;

person->name = "Leah";

INIT_LIST_HEAD(&person->list);

list_add_tail(&person->list, &birthday_list);

/* Creating Person 6 */

person = kmalloc(sizeof(*person), GFP_KERNEL);

person->month = 1;

person->day = 11;

person->year = 1991;

person->name = "Han";

INIT_LIST_HEAD(&person->list);

list_add_tail(&person->list, &birthday_list);

printk(KERN_INFO "Loading Module ");

struct birthday *ptr;

list_for_each_entry(ptr, &birthday_list, list) {

/* On each iteration ptr points */

/* to the next birthday struct */

if(ptr ==NULL){

print("List is empty");

}else{

ptr=&birthday_list

while(ptr!=NULL){

ptr=ptr->list;

}

}

return 0;

}

void simple_exit(void) {

printk(KERN_INFO "Removing Module ");

struct birthday *ptr, *next

list_for_each_entry_safe(ptr, next, *birthday_list, list) {

while(ptr!=NULL){

ptr->next=*birthday_list->next;

*birthday_list->=NULL;

}

list_del(&ptr->list);

kfree(ptr);

}

}

module_init(simple_init);

module_exit(simple_exit);

MODULE_LICENSE("GPL");

MODULE_DESCRIPTION("Kernel Data Structures");

MODULE_AUTHOR("SGG");

Edit the incomplete C source code to create a linked list to store the birthday

information of 6 random students. For each person, the birthday information should include month, day, year, and name. When the module is loaded, traverse through the linked list and output its content to the kernel log buffer. In addition, write code to identify the youngest student by year (you can define 6 students born in 6 different years.) and remove that student from the list. After removing the youngest student, output the updated linked list content to the kernel log buffer. In the module exit point, delete the elements from the updated linked list and return the free memory back to the kernel. Make sure to output a message to the kernel log buffer every time an element is deleted.

The code i have is incomeplete, i need help try print the student that is the youngest

#include #include #include #include

struct birthday { };

/** * The following defines and initializes a list_head object named birthday_list */ static LIST_HEAD(birthday_list);

int simple_init(void) {

printk(KERN_INFO "Loading Module ");

return 0; }

void simple_exit(void) { printk(KERN_INFO "Removing Module ");

}

module_init( simple_init ); module_exit( simple_exit );

MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Kernel Data Structures"); MODULE_AUTHOR("SGG");

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn Mysql The Easy Way A Beginner Friendly Guide

Authors: Kiet Huynh

1st Edition

B0CNY7143T, 979-8869761545

More Books

Students also viewed these Databases questions