================================================================================ DATA STRUCTURES AND ALGORITHMS ASSIGNMENT 7: File System Simulator Using Trees State University of Zanzibar (SUZA) ================================================================================ ANTI-PLAGIARISM NOTICE: This assignment requires LIVE DEMONSTRATION (viva). You must: 1. Explain every function in your code 2. Modify your code on the spot when asked 3. Answer questions about your design choices 4. Submit a HANDWRITTEN design document AI-generated or copied code will result in ZERO marks. ================================================================================ PROJECT DESCRIPTION ================================================================================ Build a simplified file system simulator using a tree data structure. The file system should support directories (folders) and files, organized in a hierarchical tree structure. ================================================================================ REQUIREMENTS ================================================================================ DATA STRUCTURES: struct FileNode { char name[50]; int isDirectory; // 1 for directory, 0 for file int size; // file size in bytes (0 for directories) struct FileNode *child; // first child (for directories) struct FileNode *sibling; // next sibling in same directory struct FileNode *parent; // parent directory }; OPERATIONS TO IMPLEMENT: 1. mkdir - Create a new directory inside the current directory - Print error if name already exists 2. touch - Create a new file with given size inside current directory - Print error if name already exists 3. ls - List all files and directories in current directory - Display type (DIR/FILE), name, and size - Format: DIR documents DIR pictures FILE readme.txt 1024 FILE notes.txt 512 4. cd - Change to specified directory - Support "cd .." to go to parent - Print error if directory not found 5. pwd - Print current working directory path - Example: /home/student/documents 6. find - Search for file/directory by name in entire tree - Print full path of all matches 7. rm - Remove a file or empty directory from current directory - If directory is not empty, ask for confirmation - Recursively delete contents if confirmed 8. tree - Display entire file system as a visual tree: / |-- documents/ | |-- report.txt (2048) | |-- notes.txt (512) |-- pictures/ | |-- photo1.jpg (4096) |-- readme.txt (1024) 9. size - Calculate total size of all files in a directory (recursively) 10. save - Save entire file system structure to a text file - Format: PATH TYPE SIZE (one entry per line) 11. load - Load file system from saved file - Reconstruct the tree ================================================================================ MENU INTERFACE ================================================================================ The program should have a command-line style interface: File System Simulator Type 'help' for available commands /> mkdir home Directory 'home' created. /> cd home /home> mkdir documents /home> touch readme.txt 1024 /home> ls DIR documents FILE readme.txt 1024 /home> pwd /home /home> tree ... /home> quit ================================================================================ TEST SCENARIOS ================================================================================ Build this structure and verify all operations: / |-- home/ | |-- student/ | | |-- assignment.c (2048) | | |-- notes.txt (512) | |-- shared/ | |-- data.csv (4096) |-- tmp/ | |-- temp.txt (100) Test: pwd from student -> /home/student Test: find assignment.c -> /home/student/assignment.c Test: size home -> 6656 (2048+512+4096) Test: rm temp.txt from tmp, then ls tmp -> (empty) Test: save and load, verify tree is identical ================================================================================ HANDWRITTEN DESIGN DOCUMENT (Required) ================================================================================ Submit on paper: 1. Draw the tree structure for the test scenario above 2. Explain your choice of child-sibling representation 3. Trace the pwd function call from /home/student 4. Trace the find function searching for "data.csv" 5. Explain how rm handles recursive deletion ================================================================================ GRADING RUBRIC ================================================================================ | Component | Marks | |------------------------------|-------| | Data structure design | 10 | | mkdir, touch, ls | 15 | | cd, pwd | 15 | | find, rm | 15 | | tree display | 10 | | size calculation | 5 | | save/load | 10 | | Menu interface & error handling| 5 | | Handwritten design document | 15 | | Total | 100 | Viva Demonstration: Required (multiplier: 0 or 1) - You must run the program and explain your code - Be prepared to add a new feature on the spot ================================================================================ VIVA QUESTIONS: ================================================================================ 1. Why did you use child-sibling representation? 2. What is the time complexity of your find operation? 3. How does your cd handle invalid paths? 4. Add a "mv" (move) command that moves a file to another directory (live). 5. How would you implement file permissions? 6. What would change if you used a BST instead of a general tree? ================================================================================