CS 3733 Operating Systems, Fall 2003 Assignment 1


Due Thursday, September 18, 2003

Assignment 1 has 9 parts, but most of them are short.


Part 0:
Read sections 5.1 and 5.2 of USP. Make a directory called cs3733 somewhere on your account. Make a subdirectory called assign1 for the following parts of the assignment. Remember that you need to keep all source code for assignments for this course until the course is over.

Part 1:
Download, compile and run the program shownames.c. The programs from USP are accessible through this link.

Part 2
Download the file printaccess.c and write a main program called printtime.c. The main program will take one command-line argument and pass it to printaccess. Create a makefile to compile and link printtime and printaccess. The same makefile should be able to compile showname from Part 1. You may use the makefile from the chapter 5 programs of USP as a guide. In the following parts, modify the same makefile so that it can compile and link the new programs as you write them.

Part 3:
Copy printaccess.c to printmodseconds.c and modify the new file to contain the function printmodseconds. This function prints the modification time is seconds since the Epoch. You will be printing the integer stored in the st_mtime field of the stat structure. This integer is of type time_t which may be an int, long or long long depending on the system. Cast it to a long long and print it using the %lld format specification. For this and future parts, use lstat instead of stat.

Modify printtime so that it calls printmodseconds instead of printaccess. Modify the makefile accordingly. Compile test this program.

Part 4:
Copy printtime.c to printsize.c and printmodseconds.c to printnumbytes.c. Modify printsize.c so that it calls printnumbytes instead of printmodseconds. Modify printnumbytes so that it prints the st_size field of the stat structure. Compile and test this program.

Part 5:
Write a function with the following prototype:
int getinfo(char *path, char *buf, int bufsize);
that gets information about the file specified by path and puts an information string in the array buf. If the function is successful it returns 0. Otherwise it returns -1. It can fail if either the lstat fails or if the information string being created does not fit in bufsize bytes. In this latter case, it is OK to have modified buf but you may not modify memory outside of the array. The getinfo function should not modify the string passed as the first parameter.

The info created contains exactly three tokens followed by a newline and a string terminator. The info line starts with the name of the file *path, followed by a single blank, followed by the modification time in seconds since the Epoch (like in printmodseconds) followed by a single blank and the size in bytes. This is is followed immediately by a newline and a string terminator. The line should contain exactly 2 blanks. If the name of the file contains blanks, each blank should be replaced by a '%' character. You might want to look at the man page for snprintf.

Write a main program called printoneinfo that takes one command-line argument and calls getinfo using this as its first parameter. Print the results of getinfo if successful or an appropriate error message if not. Use a statically defined buffer of fixed size in your call to getinfo. Thoroughly test getinfo.

Part 6:
Write a main program called showinfo that takes a single command-line argument, the name of a directory. It should start out like shownames, but for each file it should call getinfo and print the string produced if getinfo was successful. Otherwise it should print a one-line error message and continue. Test your program thoroughly. Make sure that it handles errors correctly. Use a single statically allocated buffer of size BUFSIZE for your calls to getinfo. Use a #define to define the value of BUFSIZE near the top of your showinfo program. You should make sure the program runs correctly on the Sun machines in the lab.

Notice that readdir only gives you the name of the file, not the full path to the file needed by getinfo. Solve this problem by calling chdir in showinfo after opening the directory.

Part 7:
After you think you have debugged your program, run lint on it and save the output generated. Use the following on the Sun system:
lint showinfo.c getinfo.c
Notice that no lint options are used above. If you get a large number of messages, use:
lint -Xarch=v9 showinfo.c getinfo.c
but do not use any other lint options.
Make sure you understand all of the lint warnings and make modifications in your programs to eliminate those that should not be there. Save the new output generated by lint. This will be turned in.

Part 8:
Set the value of BUFSIZE in your showinfo program to 30 and recompile. Run your showinfo program on the file ~srobbins/cs3733f2003/a1data. Use cut and paste to put the output in a file and save it. You will be printing out this file and handing it in. Please be sure that your have removed any debugging statements from your programs before producing your test output.


Handing in your program:
Use this cover sheet. Consecutively number all of the other pages you turn in. Each page that contains your work should have a number on it. Turn this in at the beginning of lecture on the due date.