An In-Memory File System is a simplified version of a real file system (like NTFS, ext4, or APFS), designed to run entirely in memory.
Loading simulation...
It mimics the hierarchical structure of directories and files, enabling operations like:
In this chapter, we will explore the low-level design of file system in detail.
Let's start by clarifying the requirements:
Before starting the design, it's important to ask thoughtful questions to uncover hidden assumptions, clarify ambiguities, and define the system's scope more precisely.
Here is an example of how a conversation between the candidate and the interviewer might unfold:
Candidate: Should the file system support both files and directories in a hierarchical structure?
Interviewer: : Yes. The system should model a typical UNIX-style file system with nested files and directories.
Candidate: How will a user interact with this file system? Should I design a GUI, or a command-line interface?
Interviewer: A command-line interface (CLI) is the way to go. The system should be able to parse and execute a set of basic shell commands.
Candidate: What are the primary commands it should support?
Interviewer: Let's implement the core navigation and manipulation commands: mkdir (make directory), cd (change directory), ls (list contents), pwd (print working directory), touch (create an empty file), and cat (view file content). It would also be great to support writing content to a file, perhaps through a simplified echo 'text' > file syntax.
Candidate: Regarding the ls command, should it just list names, or should it support options like ls -l for a more detailed view?
Interviewer: That's an excellent feature to include. The design should be flexible enough to support both a simple listing of names and a detailed format that shows metadata, like whether an entry is a file or a directory and its creation time.
Candidate: How should the system handle paths? Does it need to support both absolute paths (starting from the root '/') and relative paths (from the current directory)?
Interviewer: Yes, that's a key requirement. The system must maintain a concept of a "current working directory" and correctly resolve both absolute and relative paths, including . (current directory) and .. (parent directory).
Candidate: What about advanced file system features like user permissions, ownership, symbolic links, or file locking?
Interviewer: Let's keep those out of scope. The primary focus is on the hierarchical data structure and the command execution framework. We'll assume a single-user environment with no permission constraints.
After gathering the details, we can summarize the key system requirements.
mkdir, cd, touch, ls, pwd, cat, and echo?ls command should support a simple format and a detailed (-l) format.