CS计算机代考程序代写 Elixir Last updated: March 22, 2021

Last updated: March 22, 2021
Carleton University School of Computer Science
COMP 3000 (WINTER 2021) OPERATING SYSTEMS TUTORIAL 7
SPECIAL FILES
In this part your goal is to learn how special files are similar to and different from regular files.
Tasks part A: Understanding special files
1. Try the following commands as a non-privileged user. What does each do? How do the files f1-f3 compare? How do they compare to /dev/urandom? Remember you can get output from
using cat or dd. If you use cat, make sure to pipe it to less!
/dev/urandom
a.cp /dev/urandom f1 (hit Ctrl+C right away to avoid a huge file) b.sudo cp -a /dev/urandom f2
c.sudo mknod f3 c 1 9
Note: If you see any command running for more than a few seconds, hit Ctrl+C right away, check the produced file (often it¡¯s very large) and delete it if not needed.
¡°-a¡± preserves all properties of the device node, so you are creating an identical copy (equivalent to calling mknod, hence the need for root). By contrast, without ¡°-a¡± cp just tries to read from the device node (invoking the driver¡¯s read() function) and write to another created regular file. As /dev/urandom never sends an end-of-file (EOF) you will get infinite data, hence filling up your disk (that¡¯s why you must stop it right away).
2. Makenamedpipesusingmknodand .Usethemtosimulate usingjustthe>and< operators. wc < mypipe & ls > mypipe
Here assume you have a named pipe in your current directory called mypipe. The ¡°&¡± operator runs the first one in the background and starts the second so that both can execute at the same time (not blocked). You can also use two terminals as was done in one lecture.
3. Usemknodtomakeacopyofyourcurrentterminal’stty-/dev/tty(Hint:considerhowyoudid something similar with above). You can name it mytty. Examine its characteristics using . Do the same for the original tty.
The main purpose here is to show you that when both the major number and the minor
/dev/urandom
stty –file=mytty
mkfifo
ls | wc
number are the same, you are technically operating the same device instance. Reflected from your tty, you should be able to see (from task 4 below) that disabling echo for mytty is equivalent to disabling echo for your original tty.
Note: the exact behavior of multiple device nodes with identical major/minor varies with device drivers. In previous tutorials, you might have seen that your current tty is also /dev/pts/1 (which /dev/tty points to). But if you do the same to it, the PTMX/PTS driver won¡¯t allow it (Input/output error).
ls -l /dev/tty
crw-rw-rw- 1 root tty 5, 0 Mar 22 23:50 /dev/tty
sudo cp -a /dev/tty mytty
tty.
or , to make a copy of your current
sudo mknod mytty c 5 0

Now, you can (this is equivalent to ) To get echo back, you need to blindly type stty echo, and hit Enter.
4. Runstty–helptoseewhatyoucandowithstty.Trydisablinglocalecho.Howdoestheshell behave with echo disabled? How can you restore echo without logging out and back in?
See above.
stty -F mytty -echo
stty -echo
LINUX KERNEL MODULES
Tasks part B: A simple kernel module
Download the source for this simple module, unpack, and build it by typing “make”.
1. Installthemoduleusing”sudoinsmodsimple.ko”.Thehellomessageisrecordedinthekernel logs. How do you view the kernel logs? How many ways are there to view them?
There are multiple ways. You can use dmesg to check kernel messages since the most recent boot, or view /var/log/syslog or /var/log/kern.log.
2. Checktoseethatthemodulehasbeenloaded.Howdoyoudothis?
lsmod
3. Removethemodulefromthekernel.Whatdidyoudo?
sudo rmmod simple
Tasks part C: A character device kernel module (driver)
Download the source for ones, a kernel module implementing a character device that outputs an unbounded string of “1”‘s. Build, compile, and run it as before.
1. Whatkernelmessagesdoesthemodulegenerate?Doesitcreateanynewfiles(otherthan )? If so, where? (Hint: search in /sys)
2. What happens when you “cat” the device /dev/ones? How can you limit the output in more than one way?
cat /dev/ones | less
3. Addmoreprintk()¡¯s(whereyouseeneeded)tofindoutatwhichpointwhichfunctionsinones.c are called and for which purpose.
/dev/ones
sudo find /sys -name ones
Tasks part D: Getting process information from a module
Download the source newgetpid.c. Build and run it as before. Hints for the questions below: https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h, https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/current.h, https://elixir.bootlin.com/linux/latest/source/include/linux/cred.h
2

1. Whattypeis” “?Howcanyoufigurethisout?
2. Modifynewgetpid.csothatitcreatesadevicefile/dev/describeratherthan/dev/newgetpid.
#define DEVICE_NAME “describe”
3. Make/dev/describeoutputthecallingprocess’sparentID(ppid),userID(uid),groupID(gid), effective user ID (euid), and effective group ID (egid).
struct task_struct *
current
Not considering namespaces:
snprintf(message, 150, “Your PID is %d; your PPID is %d; your UID is %d; your GID
is %d; EUID is %d; your EGID is %d!\n”, thepid, task_ppid_nr(current), current- >cred->uid.val, current->cred->gid.val, current->cred->euid.val, current->cred-
>egid.val);
Considering namespaces:
snprintf(message, 150, “Your PID is %d; your PPID is %d; your UID is %d; your GID
is %d; EUID is %d; your EGID is %d!\n”, thepid, task_ppid_nr(current),
from_kuid_munged(current_user_ns(), current->cred->uid), from_kgid_munged(current_user_ns(), current->cred->gid),
from_kuid_munged(current_user_ns(), current->cred->euid),
from_kgid_munged(current_user_ns(), current->cred->egid));
3