2007年12月12日 星期三

Linux Kernel Project 2

Project 2

The purpose of project 2 is to let you understand and be familiar with the Linux System Call mechanism.

* Project Description:
o In this project, you need to write an application program which reads a single character string that you type in the keyboard and which then saves the typed character string in a file name original.txt.
o The characters you can typed are the lowcase English characters and the Space key only.
o After receiving a single character string, such as ``I like linux kernel'', your program does not need to read any other character. It then saves the typed character string into the file original.tex and terminates.
o You need to modify the Linux kernel so that after your application program issues a read() system call and after your process changes into kernel mode to read the typed string into a user mode varialbe, say char input_string[1000], your kernel will automatically fork a child process ; hence, both the parent process and child process have its own character array input_array[1000] and these two character arrays have the same content.
o After forking a child process, the parent process just returns to its user mode. When coming back to the user mode, because the parent process thinks it only just finished a read system call and doesn't know the execution of the fork, it just saves the content of the input_string[1000] into the file original.tex and exits.
o By using the Character Translation Rules listed below your child process encodes the content of its input_string[1000] character array into the corresponding cypher text and saves the result back to the input_string[1000] character arrary.
o Then when returning to its user mode, the child process save the content of its input_string[1000] array into file cypher.tex.
o In your application program, you can NOT use the fork(), clone(), and vfork() system call. But you can use get_pid-related system calls.
o Character translation Rules
+ a --> z
+ b --> y
+ c --> x
+ d --> w
+ e --> v
+ f --> u
+ g --> t
+ h --> s
+ i --> r
+ j --> q
+ k --> p
+ l --> o
+ m --> n
+ n --> m
+ o --> l
+ p --> k
+ q --> j
+ r --> i
+ s --> h
+ t --> g
+ u --> f
+ v --> e
+ w --> d
+ x --> c
+ y --> b
+ z --> a
+ Space --> Space
o Encoding Example:
+ e.g. Input character string --> ``this is a book''
+ cypher character string --> ``gsrh rh z yllp''
o P.S.: Even though when your application program executes a read system call, your kernel will fork a child process right after the read system call handler is going to finish, from the point of view of the application program, it only executes a read system call; hence, the return value of the read, i.e. the number of characters read or error code, should be the same as the one before the fork is executed. It should NOT return the PID of any process. The same rule applies to the child process.
* Project Submission:
o The due day is 14th January, 2008.
o On site demo for this project is required.
o Contact the TAs to arrange/schedule your demo time.
o You need to submit reports to the TAs also and the reports must include your source code.
o You need to submit two versions of reports. One is a hard-copy version and the other is a MS Word file one.
o Late sumbission is NOT accepted.
* Tips
o You may need to add one new system call into your kernel so that you can use it to notify the kernel which procees needs to fork a process after finishing a read system call.
o If you need to add any field into the process descriptor of a process, add the field in the rear part of the task_struct structure.
o Make sure only the parent process that executes your application program will automatically fork a child process before its read system call prepares to return to user mode. Its child process can not do this extra fork system call.
o Before changing your kernel code, make sure whether your system calls, especially the read system call, are handled through int 80h or sysenter.

沒有留言: