Operating Systems 2019W: Assignment 3

From Soma-notes
Revision as of 14:55, 23 March 2019 by Soma (talk | contribs) (→‎Test Code)
Jump to navigation Jump to search

Please submit the answers to the following questions via CULearn by 11:55 PM on Tuesday, March 26, 2019. There are 20 points in 9 questions.

Submit your answers as a single text file named "<username>-comp3000-assign3.txt" (where username is your MyCarletonOne username). The first four lines of this file should be "COMP 3000 Assignment 3", your name, student number, and the date of submission. You may wish to format your answers in Markdown to improve their appearance.

No other formats will be accepted. Submitting in another format will likely result in your assignment not being graded and you receiving no marks for this assignment. In particular do not submit an MS Word or OpenOffice file as your answers document!

Don't forget to include what outside resources you used to complete each of your answers, including other students, man pages, and web resources. You do not need to list help from the instructor, TA, or information found in the textbook.

Please make your best effort to do a proper implementation where required. There will be times where you may be tempted to copy large portions of code from other parts of the kernel. While you may have to copy a small number of lines, avoid duplicating significant functionality.

When an answer asks for modifications to the remember module, please give your code as a "diff -c" versus the original remember.c or versus the code for a previous answer. Points may be deducted for code in improper form. (Note that by using diff -c it is easily possible to automatically apply your changes to the original code in order to get a full working version.)

Questions

  1. [2] What are two reasons Linux kernel code doesn't make system calls?
  2. [2] What code could we use to get the information returned by getuid and geteuid system calls in the kernel? How do you know your code is correct?
  3. [2] When you unload a kernel module, can the kernel automatically deallocate the resources that were used by the module? Explain.
  4. [2] If you remove the remember module while a process is accessing it, what happens to the process? Please give your test program and appropriate output from ps. What happens if you try to reload the remember module?
  5. [2] What happens if you call class_create() in a module using a class name that already exists in the kernel? Describe the process by which you figured out your answer.
  6. [2] Fix the remember module so that it returns EFAULT to userspace when given an invalid pointer. Describe the process by which you figured out your answer.
  7. [2] In the remember module, modify remember_read() so it uses a non-zero offset properly rather than simply logging an error. Describe the process by which you figured out your answer.
  8. [2] Modify the remember module so llseek system calls work as they do on regular files, for whence values of SEEK_CUR and SEEK_SET. You should not allow the offset to be set to a value past the current end of file. Describe the process by which you figured out your answer.
  9. [4] Modify the remember module so the behavior of writes change as follows. Explain how you verified each.
    1. [1] Increase the allocation size to 16K of storage.
    2. [1] Allocate memory when data is first written to /dev/remember and free memory when zero bytes are written to /dev/remember or when the remember module is unloaded.
    3. [1] Preserve data across writes such that a shorter write preserves data from a previous longer write.
    4. [1] Allow writes to non-zero offsets (subject to the maximum size of /dev/remember).

Test Code

For the programming questions, you should create tests. Here's a fragment of a test program that test for null pointer access when writing.

  1. include <stdio.h>
  2. include <stdlib.h>
  3. include <sys/types.h>
  4. include <unistd.h>
  5. include <sys/stat.h>
  6. include <fcntl.h>

int open_remember(void) {

       int fd;
       fd = open("/dev/remember", O_RDWR);
       
       if (fd < 0) {
               fprintf(stderr, "Could not open the remember device.\n");
               exit(-1);
       }
       return fd;

}

void read_null_test(void) {

       ssize_t c;        
       int fd;
       fd = open_remember();
       
       c = read(fd, NULL, 1024);
       if (c >= 0) {
               printf("read with NULL buffer succeeded\n");
       } else {
               perror("Error reading remember in NULL buffer test");
       }
       close(fd);

}

int main(int argc, char *argv) {

       read_null_test();
       
       return 0;

}

</listing>