CSE Roadmap

Core tier · about 4 hours · 6 parts

Part 2 of 6 · 2 min read

Requirements

Paths in, files and folders out.

Think of a filing cabinet. The cabinet holds drawers. A drawer holds folders. A folder holds papers and other folders. To find a paper, a clerk follows a path: "second drawer, then the folder named Work, then the paper named Budget". A file system is that cabinet, and a path is the clerk's route.

Questions and the answers assumed here:

  1. What are the node kinds? Files with text, and directories that hold nodes.
  2. What is a path? A string such as /docs/work/a.txt, starting at the root /.
  3. Which special parts? . means this folder, and .. means the parent folder.
  4. Which operations? Make a folder, create a file, write and read a file, list a folder, get a size, move or rename, delete, and find by name ending.
  5. Names unique? Within one folder, yes.
  6. Out of scope: permissions, links, timestamps beyond a counter, and threads.

The numbered requirements:

  • R1. The tree has one root directory, which cannot be deleted or moved.
  • R2. A path must start with /. Paths with . and .. are cleaned up before use.
  • R3. Creating something that exists is refused.
  • R4. Reading or writing needs a file. Listing needs a directory, though listing a file shows just the file.
  • R5. The size of a file is its length. The size of a directory is the sum of everything inside it.
  • R6. A move keeps the content and may rename.
  • R7. A directory cannot be moved into itself or into one of its own children.
  • R8. Every failure gives a clear message and changes nothing.

Path

A path is a string that names a node by listing the folders to open from the root, in order, separated by slashes.

Example: /docs/work/a.txt means open docs, then work, then the item a.txt.

Check yourself: 1. What does .. mean in a path? 2. What is the size of a folder? 3. Why can a folder not be moved into itself?