Question
Please use Ubuntu, Linux, and Virtual Box to solve the problem below(this is an operating systems question): ASSIGNMENT 1 The following code is a complete
Please use Ubuntu, Linux, and Virtual Box to solve the problem below(this is an operating systems question):
ASSIGNMENT 1
The following code is a complete helloworld module. Name it as new_module.c
#include
int init_new_module(void) { printk(KERN_INFO "Hello, world! "); return 0;
}
void exit_new_module(void) { printk(KERN_INFO "Goodbye, world! "); }
module_init(init_new_module); module_exit(exit_new_module);
The module defines two functions. init_module is invoked when the module is loaded into the kernel and exit_module is called when the module is removed from the kernel. module_init and module_exit are special kernel macros to indicate the role of these two functions.
Use the following makefile to compile the module. Name it as Makefile Note that here new_module.o is the output after compiling.
obj-m += new_module.o all: sudo make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: sudo make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Compile the new_module.c file using make command. # make
To insert the module into the Linux kernel: # sudo insmod new_module.ko
Use the following command to verify the module has been loaded: # lsmod
To remove the module from the kernel: # sudo rmmod new_module
When you insert or remove the module, corresponding information will be printed out under the dmesg.
ASSIGNMENT 2
Write a new kernel module following steps in assignment
1. This module creates an entry in the /proc file system. Use the following code skeleton to write the module:
#include
#define MAX_LEN 4096 static struct proc_dir_entry *proc_entry;
ssize_t read_proc(struct file *f, char *user_buf, size_t count, loff_t *off ) { //output the content of info to user's buffer pointed by page printk(KERN_INFO "procfs_read: read %lu bytes ", count); return count; }
ssize_t write_proc(struct file *f, const char *user_buf, size_t count, loff_t *off) { //copy the written data from user space and save it in info printk(KERN_INFO "procfs_write: write %lu bytes ", count); return count; }
struct file_operations proc_fops = { read: read_proc, write: write_proc };
int init_module( void ) { int ret = 0; //create the entry and allocated memory space for the proc entry
printk(KERN_INFO "test_proc created. ");
return ret; }
void cleanup_module( void ) { //remove the proc entry and free info space printk(KERN_INFO "test_proc deleted. "); }
Step 1: create an entry in proc file system named myproc when the kernel module is loaded; this entry myproc will be deleted when the kernel mode is deleted. You can use $ ls /proc/ to check whether it is existed. (Hint: proc_create() and remove_proc_entry() are needed.)
Step 2: implement read_proc and write_proc function to read/write the proc file entry in Step 1. You need to add codes for allocating memory in init_module and releasing the memory in cleanup_module for the proc file entry. (Hint: copy_to_user() is needed for the read and copy_from_user() is needed for write.)
To test your results, load the kernel module and there should be a new entry created under /proc. Use cat and echo to verify and change the content of the new entry.
You can use the following to test the read or write on the entry of proc file system. Here the root user is needed.
Please show source code, output screenshot of your parallel code and a report describe your code logic. Please show your modification (file diff1.txt, diff2.txt, ) and the screenshot of output
Please use diff command to highlight your modification: $ diff -u original_file.c modified_file.c. > diff.txt
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started