Master the fundamental concepts of file systems through this focused micro-challenge.
Directories map component names to inode numbers. mkdir creates a new directory inode and links . and ..; readdir iterates entries; rmdir removes empty dirs only.
API surface:
dirent records with inode typeFor example, removing /tmp/foo succeeds only when foo contains just . and ..; a stray file inode blocks removal with ENOTEMPTY.
mkdir(), rmdir(), and readdir() are POSIX primitives that every shell's ls, mkdir -p, and file manager ultimately call, and the . and .. entries you handle here are why cd .. works on every Unix system. Forgetting to skip . and .. when counting files is a classic bug that silently inflates file counts in backup and sync tools.
Before you call the implementation done, walk failure modes on purpose. Test empty structures, single-element edge cases, maximum concurrency, and errno paths that must not crash the program. OS code usually fails in production when happy-path tests pass but invariants break under contention or memory pressure.
Keep structures small and name fields after kernel counterparts when possible. That lets you read man pages and kernel source side by side while you work. Print observable events during development; remove noisy logs once tests pass reliably.
You will implement directory create, list, and remove atop your inode tree or real syscalls. This exercise requires dot and dot-dot handling in listings.
Implement directory operations.
Requirements:
Test:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github