Documente Academic
Documente Profesional
Documente Cultură
A time log following the format of the 1st 2 labs is required. (3 marks)
In all cases provide a program listing, the command lines used to run the program, a status statement
indication of any problems or how you verified the program worked and the output. All of these
programs are to be written in C – several people have started on the wrong foot by looking at stat in
section 1 of the manual not section 2. Refer to the posted examples on the course web site.
1. Apply the stat function to a list of files on the command line. Print out the file size in bytes, the
total amount of space it takes up on the disk (block size * the number of 512B blocks) and the
%utilization (file size/space taken up on disk) (2 marks)
2. Apply the fstat function to a list of 4 files on the command line where the files are in different
system directories such as /usr/bin, $ORACLE_HOME, one of your directories with 2 files
belonging to different groups. Avoid using a directory as data. Unlike stat, fstat requires that
you open the file first to obtain a file descriptor so choose files that you can read.
Use the getpwuid and getgrgid functions to list each file owner’s userid, real name and group
name. (3 marks)
3. Write a C program that takes 2 arguments on the command line. The first argument is a
directory and the 2nd is a file in that directory.
The main program checks that both exist and that the first argument is a directory. It then calls
a function that first lists up to 5 files in the directory with an inode that is less than the 2nd file,
then up to 5 files with inodes greater than the current file. The output should show the file
names and the inode numbers. (3 marks)
Write a C application that takes 2 command line argument – a source directory and a destination
directory. Your program should make a copy of the structure of the directory so that the file names,
modification and last access times, permissions and file types (directory and regular files only) are the
same. You do not have to copy the file content in all cases.
1. If the file name is . or .. don’t make a copy – skip the entry. Your new directory will have these
anyway. (1)
2. Your program should also detect and skip any symbolic links. (1)
3. If the file is of type directory make a new directory, however you do not have to duplicate the
contents of that directory. (1)
4. Set the modification and access times of the new file to be the same as the old file. (2)
5. Set the permissions of the new file to be the same as the old file. (2)
6. If the size of the old file is less than 40K in size, use fread and fwrite to copy it to the new
directory. This should be done before setting the times. (2)
7. The selection of test data is important. You may have to create a directory to test all features of
the program or perhaps you can find one. Discuss why your chosen test directory is a
reasonable choice. (1)
This exercise is best done in the lab in week 7 when you are otherwise busy studying for exams.
I don’t ask you to spend much time outside of the lab this week, which is why this is a 3 week
not a 2 week assignment. (4 marks)
Bonus: Describe how you used gdb to solve a debugging problem in one of the previous
exercises. (2 marks)
3. In Lab 2 you probably created a .h file for your data type declaration. (or use either my PERSON
or FLIGHT example). Move the .h file to a subdirectory. Recompile using the -I option. Record
the command line and report if the compile was successful.
There are 40 available marks listed on this assignment. It will be marked out of 35. You may
suggest and create extra features for up to 5 extra bonus marks if you contact me before the due
date and get approval. Duplicate requests will may be turned down so ask early. For example
you might decide to modify one of the exercises to use getopt or getopt_long flags or map out and
create a data structure diagram one of the data structures used by system function calls.