Question: Design and implement a C program to simulate the Unix / Linux file system tree. The program should work as follows. ( a ) .

Design and implement a C program to simulate the Unix/Linux file system tree. The
program should work as follows.
(a). Start with a / node, which is also the Current Working Directory (CWD).
(b). Prompt the user for a command. Valid commands are:
mkdir, rmdir, cd, ls, pwd, creat, rm, save, reload, menu, quit
(c). Execute the command, with appropriate tracing messages.
(d). Repeat (2) until the "quit" command, which terminates the program.
The following outlines the suggested organization of the program.
(1) NODE type: Define a C structure for the NODE type containing
64 chars: name string of the node;
char: node type: D for directory or F for file
node pointers: *childPtr,*siblingPtr,*parentPtr;
#include
int main()
{
int a, b, c;
a =4; b =5;
c= Add(a,b);
//Add the remaining code
}
(2) Global Variables:
NODE *root,*cwd; //root and CWD pointers
char line[128]; //user input command line
char command[16], pathname[64]; //command and pathname strings
char dname[64], bname[64];
(others as needed)
(3) The main function
int main()
{
initialize(); //initialize root noode of the file system tree
while(1){
get user input line =[command pathname];
identify the command;
execute the command;
break if command =quit;
(4) Get user inputs: Assume that each user input line contains a command with an optional
pathname. The reader may use scanf() to read user inputs from stdin. A better technique is as
follows
fgets(line,128, stdin); //get at most 128 chars from stdin
line[strlen(line)-1=0; //kill
at the end of line
sscanf(line,%s %s, command, pathname);
(5) Identify command:
If(!strcmp(command,mkdir)
mkdir(pathname);
else if (!strcmp(command,rmdir)
rmdir(pathname);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!