Anda di halaman 1dari 3

COSC 2P91 Assignment 4

Winter 2012/13
revised 3/27/2013
Due: Apr. 8 @ 12:00 pm (noon) (Late Date: Apr. 11).
File System Interface
This assignment is intended to provide experience using UNIX system calls. For a manual on the
GNU C Library (including the File System Interface-Ch 14) see:
ht t p: / / www. gnu. or g/ sof t war e/ l i bc/ manual / ht ml _node/ i ndex. ht ml .
The Shell
In UNIX, the shell
1
Write a C program to provide a simple shell for interacting with the UNIX file system. Once the
shell is running, the shell presents a prompt and the user enters a command at the console (one
command per line). When the command is complete the shell presents the prompt again. The
directory from which the shell is launched is the initial current working directory within the
shell.
is the command line interpreter that runs when you log on to UNIX and
reads and processes the commands (such as cd or r m) that you type at the console. The shell
itself is a program running on UNIX that interfaces with the operating system and, in particular
the file system. The most influential shells have been the C shell and the Bourne shell. When you
log on to sandcastle, you are using a successor to the Bourne shell called the Bourne-Again Shell
(or bash).
The commands are single letters and may be followed (separated by a space) by one or two
parameters, being simple file names (i.e. not path names). The commands are:
c filename
1
filename
2

copy the contents of filename
1
to the file filename
2
. filename
1
should be
a regular file in the current working directory. If filename
2
exists, it will be
replaced by the copy of filename
1
(i.e. old contents lost) otherwise it will be
created with the copy.
d filename
move down to filename in the directory structure. filename must be a
directory within the current working directory. filename becomes the current
working directory.
l
list (to the console) the contents (i.e. file names) of the current working directory.
The listing should include file name, file type (d for directory and r for regular)
and, for a regular file, the file size.
mfilename
make (create) a new directory file with name filename in the current working
directory.
n filename
create a new regular file with name filename in the current working directory.

1
see: http://en.wikipedia.org/wiki/Unix_shell
If filename already exists it will be replaced (i.e. contents lost). Lines of text
typed by the user after entering the n command are copied into the newly created
file until ^D (Ctrl-D) (EOF) is typed.
q
quit (terminate) the shell program (returning to bash).
r filename
1
filename
2

rename filename
1
to be filename
2
. filename
1
must be a file in the
current working directory. If filename
2
exists, it will be replaced (i.e. contents
lost), unless it is a non-empty directory. filename
2
will be in the current
working directory.
u
move up in the directory structure. Unless the current working directory is the
root, the parent directory of the current working directory becomes the current
working directory.
w
print the absolute file name of the current working directory to the console.
x filename
excise (remove) filename from the current working directory. filename
must be a regular file or an empty directory in the current working directory.
The user interface can be as simple as possible as long as it handles valid input (i.e. one character
command followed by one space and a filename followed by one space and a second filename
followed by end of line). Invalid operations do not have to produce error messages, however they
should not corrupt the file system. The copy command (c) should be implemented using low-
level I/O since the file being copied is not necessarily a text file.
Programming Style
The program should use good programming style and good C-style, in particular. A larger
number of simple functions is preferred over a small number of complex functions. The program
should be well documented, layout should be good and consistent and C programming
conventions should be followed.
Submission
The zip file: ht t p: / / www. cosc. br ocku. ca/ Of f er i ngs/ 2P91/ A4Fi l es. zi p contains two files
for testing & submission: t est f i l e. t xt a text (regular) file for testing your shell and
Scr i pt . t xt a script for running your shell for submission. Create a new directory for testing
your shell for submission. Copy the executable file for your shell into the new (empty) directory.
Unzip the file t est f i l e. t xt into the new directory (it should now contain two files, your
shell program and t est f i l e. t xt ).
The program should run on sandcastle. Start a script (scr i pt command). Run your program
from the directory created above and follow the sequence of commands in Scr i pt . t xt . After
you quit your shell, enter cnt l - d to stop scr i pt . The script will be created as the file
t ypescr i pt .
Your submission will be in two parts: electronic and paper. The paper submission should include
the listings of all C files you have written and the output of the scr i pt command
(t ypescr i pt ).
In addition to your paper submission, you must make an electronic submission of the assignment
including the . c and executable files of your program, runnable on sandcastle. You should have
a directory for the assignment on your Z: drive which contains the directory created for testing
above (as modified by following the Script using your shell). Log on to sandcastle and navigate
to the assignment directory, at the sandcastle prompt, type:
submi t 2p91
and, when prompted, enter the appropriate information using 4 as the assignment number. The
submission program will copy the entire working directory, and all subdirectories, to the marking
directory, so you should ensure that the content of the directory is what you desire to submit.
As usual, the complete paper submission should be placed in an envelope to which a completed
coversheet (ht t p: / / www. cosc. br ocku. ca/ cover page) is attached. The submission should be made to
the COSC 2P91 submission box outside J 328 in accordance with the assignment guidelines
(ht t p: / / www. cosc. br ocku. ca/ Of f er i ngs/ 2P91/ Assi gnGui de. pdf ) and not in violation of the regulations
on plagiarism (ht t p: / / www. br ocku. ca/ webcal / 2012/ under gr ad/ ar eg. ht ml #sec68,
ht t p: / / www. cosc. br ocku. ca/ about / pol i ci es/ pl agi ar i sm). Note: Assignments not including a
coversheet will not be marked.

Anda mungkin juga menyukai