What is File System?
-
In computing, a file system or filesystem (often abbreviated to fs) controls how data is stored and retrieved. Without a file system, data placed in a storage medium would be one large body of data with no way to tell where one piece of data stops and the next begins. By separating the data into pieces and giving each piece a name, the data is easily isolated and identified. Taking its name from the way paper-based data management system is named, each group of data is called a “file.” The structure and logic rules used to manage the groups of data and their names is called a “file system.”
File System Architecture
-
A file system consists of two or three layers. Sometimes the layers are explicitly separated, and sometimes the functions are combined.[7]
The logical file system is responsible for interaction with the user application. It provides the application program interface (API) for file operations —
OPEN
,CLOSE
,READ
, etc., and passes the requested operation to the layer below it for processing. The logical file system “manage[s] open file table entries and per-process file descriptors”.[8] This layer provides “file access, directory operations, [and] security and protection”.[7]The second optional layer is the virtual file system. “This interface allows support for multiple concurrent instances of physical file systems, each of which is called a file system implementation”.[8]
The third layer is the physical file system. This layer is concerned with the physical operation of the storage device (e.g. disk). It processes physical blocks being read or written. It handles buffering and memory management and is responsible for the physical placement of blocks in specific locations on the storage medium. The physical file system interacts with the device drivers or with the channel to drive the storage device.[7]
How To Design
-
Assumption
- In-memory
- Only for file and directory
- metadata (name, creation time, access time, modification time, etc.)
-
Use Cases
- create
- read
- update
- delete
-
classes
-
FileSystem
- Entry
- metadate 的生成
- 生成文件路径: 1.需要文件名称; 2.parent的文件
- File extends Entry
- 实际的内容, 一般为byte
- 文件大小
- Directory extends Entry
- List< Entry > 当前directory数据
- Directory文件的大小
- File文件的数量
-