My question is what I have to do to get this output? $ uname –a; dmesg Linux tsa
ID: 3813402 • Letter: M
Question
My question is what I have to do to get this output?
$ uname –a; dmesg
Linux tsaoalbert-VirtualBox 4.8.0-36-generic #36~16.04.1-Ubuntu SMP Sun Feb 5 09:39:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[18657.187804] Loading Module
[18657.187806] Birthday: Month 10 Day 6 Year 1962
[18657.187807] Birthday: Month 8 Day 13 Year 1995
[18657.187807] Birthday: Month 9 Day 2 Year 1998
[18657.187808] Birthday: Month 8 Day 12 Year 1963
[18657.187808] Birthday: Month 10 Day 22 Year 1963
[18657.187809] Birthday: Month 8 Day 12 Year 1963
This is what I have so far.
#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;
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 *ptr;
int bdays[][3] = { {10,6,1962}, {8,13,1995}, {9,2, 1998}, {8,12, 1963}, {10,22, 1963}, {8,12, 1963} };
// int n = 5;
int n = (int)( sizeof(bdays) / sizeof(bdays[0]) ) ;
int i ; //
/* the pointer for list traversal */
printk(KERN_INFO "Loading Module ");
for ( i=0 ; i < n; ++i ) {
struct birthday *person_one;
person_one = kmalloc(sizeof(*person_one), GFP_KERNEL);
// TODO: fill in your codes here
person_one->month = 10;
person_one->day = 6;
person_one->year = 1962;
//The macro INIT LIST HEAD() initializes the list member in struct birthday.
// TODO: fill in your codes here
INIT_LIST_HEAD(&person_one->list);
list_add_tail(&person_one->list, &birthday_list);
// TODO: fill in your codes here
}
list_for_each_entry(ptr, &birthday_list, list) { /* now traverse the list */
printk(KERN_INFO "Birthday: Month %d Day %d Year %d ",ptr->month,ptr->day,ptr->year);
}
return 0;
}
void simple_exit(void) {
struct birthday *ptr, *next;
printk(KERN_INFO "Removing Module ");
list_for_each_entry_safe(ptr, next, &birthday_list, list) {
printk(KERN_INFO "Deleting %d/%d/%d ", ptr->day, ptr->month, ptr->year);
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");
___________________________________________________________________________________________
Explanation / Answer
//main.c
============================================================
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.