Unix Systems Programming: Lab 2 - Stat, Make & file I/O
Due: Sunday, January 22, 2017 @ 5:00 pm
Purpose and Rationale
The purpose of this lab is to allow students to become comfortable with
Unix file I/O operations,
make
and makefiles.
Resources
FAQ
(submission instructions and other useful stuff)
If you are not on piazza, go to the course syllabus and register.
Lecture 2 is the primary source for this lab.
All work should be done on a machine in the department's
Linux
cluster. You can refer to ssh
for
more
information on
how to log into a remote machine.
Marks Distribution
Exercise 1 |
6 points |
Exercise 2 |
6 points |
TOTAL |
12 points |
NOTE: If your code does not compile, it cannot be graded, and you will receive a 0 for that portion of the lab.
LAB 2
- EXERCISE 1: Implement the stat command in
C. Write a C program
called my_stat that implements the default behavior
of the UNIX stat command. Your output
should exactly match the default output of the stat
command on the cluster. For instance:
File: "/usr/bin/stat"
Size: 7212
Blocks:
16
IO Block: 4096 Regular File
Device: 303h/771d Inode:
311082 Links:
1
Access: (0755/-rwxr-xr-x) Uid:
( 0/
root) Gid: (
0/ root)
Access: Wed Jul 10 23:00:30 2002
Modify: Wed Aug 8 10:49:41 2001
Change: Thu Apr 4 12:34:28 2002
Hint: "man stat" and "man 2 stat".
Again, the output of your stat program with the option should
match the output of the original stat program. For those of
you using
Molay's text, you will find his discussion on the stat call on pages
82ff
quite helpful in using the stat call and formatting the output
correctly.
For extra credit (5 points): Implement
handling of any one of the following two
flags:
-L (follow Links)
-c --format (implement a subset of 5 of the formatting options (your
choice which 5))
DELIVERABLES: your source file(s)
(e.g., mystat.c), a makefile, and a README as
described below in Deliverables
- EXERCISE 2: Implement a simplified version of the UNIX
program "cp"
, which copies one file to another. Call the file filecopy.c.
This
version copies only files, it does not permit the second argument to be
a
directory. We also ignore all options in command "filecopy".
Please follow these steps:
- Read the chapters in the Kerrisk text as per the syllabus.
- Read and understand these examples:
read.c and
write.c; (man 2 read; man 2 write if necessary)
- Use Low-level File Access functions such as creat,
open, read,
write, close, etc.) to implement this command
- You must handle the situation when the second argument
is the same
as the first, i.e., you should not allow a file to be copied over
itself.
Handle this situation intelligently.
- Acctually, you only need to integrate above examples
and add only serveral lines.
DELIVERABLES: your source file(s)
(e.g., filecopy.c), a makefile, and a README as
described below in Deliverables
Carefully follow the steps below.
- Please create subdirectories ex1 and ex2, and place each exercise's materials
in its respective directory as described below: