In this exercise you will inspect an update to the previous module where we also have a write
implementation for the miscdev
device.
- Connect to your VM using ssh.
Start tmux so that connection issues do not prevent you from being able to get back to your shell:
tmux -u attach -d || tmux -u
Build the module with make
:
make
Load the module using insmod
:
sudo insmod miscdev.ko
You can also see it in /dev
:
ls -l /dev/lkp_miscdev
As follows:
crw-rw-rw- 1 root root 10, 123 Nov 30 14:53 /dev/lkp_miscdev
Note that the permissions are different: now everyone is allowed to read from and write to the device.
Write to device using redirection:
echo testing > /dev/lkp_miscdev
Read from device using cat
:
cat /dev/lkp_miscdev
You should see:
testing
This is the text that was written in the previous task. You can repeat tasks 6 and 7 with different contents.
If we issue multiple writes to the device (e.g., using cat > /dev/lkp_miscdev
and writing multiple lines), read
will only return the last one. Why? How can we fix this?
In this exercise, you built on previous one and got familiar with how Rust ensures that memory remains available when in use, and how it forces the use of synchronization primitives when needed. You also saw how a write
implementation can be exercised from the shell.