Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C Program to Simulate a UNIX-based filesystem) My goal is to implement a simulation of a UNIX filesystem by writing a program in C and

(C Program to Simulate a UNIX-based filesystem) My goal is to implement a simulation of a UNIX filesystem by writing a program in C and using a slightly modified Binary Search Tree. Initially, the filesystem will be setup with an Owner(User name) and a root node: "yourname/root/." For simplicities sake, a file or a folder node will be the same struct (a flag in the struct for the nodes will indicate whether the node is a file or directory, or the first character of the file/dir name will be either an F for file or D for directory). The modified binary tree will look like this (its just a slight modification of a tree, the sibling pointer of a parent folder points to the first alphabetical file or folder in the and are arranged in a linked-list type fashion):

image text in transcribed I would like to maintain alphabetized order (if you notice a directory does not always point to a child directory, just the first alphabetical node of the given directory) and anything above the root is inaccessible. So essentially after the simulation is set up (the user name node and root are created and linked, or even you may have just one node as the root just named "yourname/root/"). The goal is to be able to give UNIX-based terminal commands to create 'files' and 'directories', and have them all insert, remove, copy, etc correctly, based on the given command. Note that it is a simulation, and no files or directories are being created or deleted. All commands, described below, will simply be read from the command line (although, eventually, once I get it working, I will have commands read from a text file all at once and then executed in order).

The commands required to be implemented are 'ls' whcih list all the files and directories in a given directory alphabetically, which they should be anyway if you start at the beginning of the parent folders sibling pointer, 'mkdir ' will creates a new directory given it does not exist in the current, 'cd ' will change to directory if exists, 'cd ..' moves to the parent of current directory, 'pwd' displays the full path of the current directory, 'addf ' adds a file to the current directory given it does not already exist, 'mv ' changes the name of the file or directory to the new name, 'cp ' hard-copies file or folder to the new name, 'rm ' locates and removes the file or directory, 'bye' - ends the session, and 'whereis ' displays path to first occurrence of file or directory if it exists.

Thanks to anyone who can give me some help, it would be much appreciated. I really would like to see how a good programmer (or good programmers) would set up their struct for the files/directories (and root, since they are all the same struct) for easy access, searching, insertion, and deletion, as well as even just pseudo code on going about the aforementioned searching and manipulation of the nodes. Thanks to anyone who can help! (Note: again, this is a simulation so all I need is a single struct for the nodes representing the root, directories, and files.) Just a good start would be greatly appreciated; I'm trying to figure out what I need in my structure and what I don't, and then move on to the essentially tree traversal functions to execute the required commands and of course create and delete nodes.

User Node F File D = Directory Root D @

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions