Based on the floppy disk program you have developed in project, you are asked to change the program to a floppy shell that supports Linux shell commands in addition to your existing floppy disk related commands. You are expected to use C programming language. Your implementation must work on Linux machine in BU004b lab.
- (10 points) Your shell should repeatedly display a prompt and allow the user to enter a command to run. Your shell is supposed to read the input from system standard input, parse the line with command and arguments, and execute. You may want to use fork() and exec*() system calls.
(30 points) Internal commands (running in the main process rather than the child process):
- Your shell should find the build-in command (see part2) in your current working directory first. If not found, it should search the directories in the shell's pathname environment (see part2).
- You are not allowed to use system(), as it invokes the system's /bin/sh shell. You should not use execlp() or execvp(), because your shell has its own path variable (explained in part2).
- By convention, the command arguments are seperated by white spaces. Please describe your customized argument seperation rules in your README document if you have special arrangement (not recommended though). Your shell does not need to handle special characters, like ",", "?", "\", except the redirection operators (<, >) in part3 and the pipeline operator (|) required in part4.
- Given a properly configured searching pathnames (see part2), your shell should be able to run all Linux shell commands, such as ls, pwd, cat, ..., etc.
- If the command cannot be found, a propriate error message must be printed and the shell should be waiting for the next command.
(20 points) The floppy shell build-in commands (running in the child process):
- exit: to exit the floppy shell.
- cd: is a command, obviously, to change directories. You may want to use the chdir system call.
- path: is not only a command to show the current command searching pathnames (if no argument is provided), but also a utility to modify (either add or remove) the command searching pathnames. Hint: you must locally maintain a character string to hold the current pathnames, and your main program should be able to modify the string given the commands like "path + ..." or "path - ...". Given any user entered command, as long as it is not an internal command, your program must first determine whether it is a build-in command (the executable can be found in the current directory). If it is not, your program then tries the possible existing shell commands (by using the maintained searching pathnames). If a command is neither a build-in command, nor a shell command, your shell should output an error message.
- path (without arguments) displays the pathnames currently set. e.g., "/bin:/sbin"
- path + /abc/def appends the pathname "/abc/def" to the "path" variable. e.g., "/bin:/sbin:/abc/def".
- path - /abc/def removes the pathname "/abc/def" from the "path" variable.
(15 points) I/O output redirection (>): your floppy shell should support output redirection. In particular, if the following command is entered:
- help: show the commands supported in the floppy shell, including the build-in commands and the local external commands.
- traverse [-l]: list the content in the root directory. The "-" option is used to list all detailed information, including the file attribution, the last modified time, the size, the full pathname and the starting cluster ID.
- showsector [sector number]: show the contents (in hex dump) of the specified sector number.
- showfat: show the content of FAT table (in the hex dump).
- For all above commands, you may assume the file name "imagefile.img" is equivalent to a floppy disk. That is, you may want to hard code it in your program.
5. $ flop: showsector 10 > myfile
The screen output will be redirected to a local file named "myfile". This redirection capability should work for all commands that produce screen output in your floppy shell.
(20 points) Extend you shell with pipeline (|). Given the following command,
- You may want to use open(), close(), dup2() system calls.
- Please refer to Unix file descriptors for the mapping of stdin, stdout and stderr to 0, 1, 2.
- Your shell does not need to handle rediction for build-in commands: exit, cd, path.
$ cmd1 | cmd2
the standard output of cmd1 is connected to the standard input of cmd2.
(10 points) This is optional (as a bonus) for undergrads, but is required for grads. Further extend your shell to support a mixture of pipelines and redirections like the following examples:
- You may want to use pipe() system call.
8. $ cmd1 | cmd2 > file1
- Provide a Makefile so make command would produce the executable.
- (5 points) Readme: you are required to write a README document (TXT only) that describes your project design detail and the execution sequence (with the commands). In particular, please explicitly state which part, if there is any, does not work and the possible reasons why that module does not work. For those working modules, please give a brief (in short) sample output.