CECS Home | ANU Home | Search ANU
The Australian National University
ANU College of Engineering and Computer Science
Research School of Computer Science
Printer Friendly Version of this Document

UniSAFE

Operating Systems Implementation

Laboratory 4

This laboratory should take you less than 2 hours to complete. Make sure you ask your tutor for help if you get stuck. You are expected to print out and read through these instruction before the lab time. Also your are expected to do about 1 hour of preparation.

Also as the laboratory proceeds you are expected to take notes of your findings/results. This will be shown to the tutor at the end of the laboratory session.

Learning Objectives

The main learning objectives for this lab is to understand how system calls work in linux.

In the lab 1 you modified the kernel to not allow the deletion of a file called "dont_delete". In general it is very unusual to have specific file names in the kernel as the kernel is supposed to provide mechanisms not policy. In this exercise you will add a system call so that a privileged user program can specify what filename should not be able to be deleted.

Preparation

Step 1 - System call structure.

To add a system call I suggest you use the system call getpid() as a template. Search for the string "getpid" in the complete kernel source tree then try to determine which file to modify to add in the system call.

Also have a look at the delete_module system call as an example. This is useful as it has a single parameter which is a string.

This will take some time to gain a good understanding of the system call structure. So make certain that you understand what is happening form the system call all the way down to the execution of code. This will span a number of points in the operating system's code.

Make a short note of how system calls work in linux. (You will need to show and explain this to your tutor at the end of the lab.)

During the Lab

Step 2 - Adding a system call

Place a copy of the kernel source code into your directory withing /scratch. Details of this are available in lab1. Note also to save on time with compiling the kernel there is a compiled version of the kernel with the required ".config" file. It is in:
 /dept/dcs/comp3300/public/linux-source-2.6.32.comp3300.tar.bz

The new system call should be called "sys_dont_delete" and should take a single filename argument. This routine can be added to "fs/namei.c". You will also need to add a static variable that holds the name of the file not to be deleted. Note that, you will need to work out the parameters for this system call. (Use sys_delete_module as an example.)

Step 3 - Adding the system call to the system call table

You should have found the system call table in step 1. Add the "sys_dont_delete" system call to this table at position 283. (over the top of the one left for kexec)

Step 4 - Compile the Kernel

Once the above two files are modified you can compile and install your new kernel. The rest of the lab is done in user space. (Assuming you have no bugs.) Remember the development cycle from the first lab.

Step 5 - Creating a user space program that calls the dont_delete system call

You then need to write a small C program in user space that implements the dont_delete() function call that calls the system call. This can be done via the "syscall" funcation (see "man 2 syscall"). See hints .

Step 6 - Test your solution

Test your solution by changing the name of the file you can not delete. Also use ltrace and strace to observe what is happening.

optional - extra

Write a simple version of "ls" in C. You will find the library calls "opendir", "readdir", "closedir", and "stat" useful. (Use man to look them up. Note that this does not involve modifing the kernel)

Use "ltrace" and "strace" on them. Anything unexpected?