Operating Systems 2015F: Tutorial 3

From Soma-notes
Revision as of 15:10, 1 October 2015 by Soma (talk | contribs) (Created page with "In this tutorial you will be running and making simple changes to [http://homeostasis.scs.carleton.ca/~soma/os-2015f/code/ones.zip the ones module] from [[Operating Systems 20...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

In this tutorial you will be running and making simple changes to the ones module from the last tutorial. If you haven't completed the kernel portion of Tutorial 2 then please go back and complete it before proceeding.

Modify the ones module to make it print information on the process that called it, as suggested below. You should report the output using an informational printk, e.g., use the "info()" call as used elsewhere in the source.

Note that the kernel version being used in the class VM is 3.13.0. Be sure to look at this version of the linux kernel source when looking at the Linux Cross Reference. You should be able to at least get through the first four in tutorial; you should work on the rest on your own in order to gain skill with kernel development.

  1. Log the current process ID as reported by the getpid system call.
  2. Log the current user ID as reported by the getuid system call.
  3. Log the effective user ID as reported by the geteuid system call. (What is the difference between this and the previous call?)
  4. Log the current working directory as reported by the getcwd system call. (strace /bin/pwd to see this system call being used).
  5. Change the code of the ones module so that /dev/ones is readable and writable by all users (without manually changing the permissions on the special file /dev/ones).
  6. Modify the module to create a new device "/dev/onelines" that inserts a line break ('\n') every 78 characters. Be sure to do the right thing when the output isn't divisible by 78, i.e., handle partial lines properly. (Note the sysfs entries for oneslines should also appear in /sys/class/comp3000.)
  7. Modify the module to create a new device "/dev/repeatchar" that produces a character device that can input exactly one character. (If more than one character is given to it, it only uses the first.) It then outputs that character an unbounded number of times. By default, it should output "1" so it behave exactly as "ones" did before.

Questions to consider

  1. What is the purpose of the ones_fops struct? How are its values used?
  2. Many places in the Linux kernel source code use goto statements (like ones_init()). Is this an acceptable practice in the context of kernel programming?
  3. Why does the kernel code use functions like printk() rather than printf or other functions from the standard C library?