CS 3733 Operating Systems, Fall 2006 Assignment 3 Comments
This assignment was graded on a basis of 30 points.
- strncpy does not always produce a string.
- r_read may do a partial read.
- for get_regular_files the result must be able to be freed with
freemakeargv.
This means that all of the strings containing the
filename must be made with a single malloc.
A simple way to do this is make a first pass and count the total length
of all regular file names, malloc space a buffer, then make a second
pass, filling the names in the buffer. Use makeargv to create
the argument list.
- In get_regular_files you must create a string containing the
path of each file you are testing, or you must chdir to the
directory containing the files.
- get_file: you should choose appropriate flags when you open the
file. You should use O_CREAT and probabaly O_TRUNC.
- get_file must close the file.
- send_file must first send the size of the file. Determine the
size of the file using stat.
- In send_file do not try to make a buffer to hold the entire file.
What would you do if the file were 1 Gig?
- Remember that read(fd,buf,n) (or r_read)
will not necessarily read
n bytes, even if you are reading from a file and the file
has n bytes left to read.
- Remember that write(fd,buf,n> will not necessarily write
n bytes. Use r_write.
- C declarations must be at the start of a block.
- No printing from anything in list_utility.c. This means
do not use perror.
- Use char buf[65] instead of malloc.
- Watch out for memory leaks.
- What does the following do:
sprintf(buf, "%d\0");
- It is useful to understand the general goal of the assignment. This
will help you understand why you are writing the functions.
Testing
- It should be clear from your test output what you tested and whether it
gave the correct answers.
- Example: To test get_regular_files, show the result of
ls -la on the directory and then show the regular files found.
Make sure you do this int a directory with subdirectories and FIFOs.
Don't just test this on the current directory.
This is a special case.
- Example: To test send_integer write a main program that
sends a integer to a FIFO. In another window, redirect the output of the
FIFO to a file. State what the integer the main program sent, and show the
contents of the file.
- You can test get_file in a similar way with a main program that
gets the file from a FIFO. In another window, send a file to the FIFO.
compare the resulting files.
- You can test send_file in a similar way. Or you can have one
program doing a get_file and the other a send_file
and connect these together with a FIFO. Compare the resulting files.
What is wrong with the following:
char * makepath(char *dir, char *name) {
int length = strlen(dir) + strlen(name) + 2;
char temp[length];
strcpy(temp,dir);
strcat(temp,"/");
strcat(temp,name);
return temp;
}