file system

Work in Progress

Summary

Directory structures

StructureCore IdeaSharingAdvantagesDisadvantages
single-levelone directory for all files- easy to implement
- no path traversal needed
- name conflicts
- no organization
- not scalable
tree-structurehierarchical directories with a single root- good organization
- scalable
- intuitive
- no direct sharing (files duplicated if needed)
DAGfiles/directories can have multiple parents (shared nodes)- efficient sharing, no duplication- must prevent cycles
general graphallows cycles in directory structure- maximum flexibility in sharing- complex traversal, risk of infinite loops, requires cycle detection

Hard and symbolic links

StructureCore IdeaAdvantagesDisadvantages
hard linkseparate pointers to the same file- low overhead- deletion problem, original directory is owner
symbolic linkstore a pathname in a special file- simple deletion, only delete the link file- larger overhead, link file occupies space

Concept

  • memory is volatile, secondary storage is persistent
  • file system is an abstraction over the physical storage
  • high level resource management
  • protect and share between processes and users
  • criteria:
    • self-contained - info stored on the disk is enough to describe the organization
    • persistent - last beyond the lifetime of the OS and processes
    • efficient - minimum overhead for bookkeeping

File

  • locgial unit of information created by process
  • abstact data type, with a set of operations with several implementations
  • contains:
    • data - structured in some way, program must know how to read it
    • metadata/attributes - information associated with the file
  • types:
    • regular files - ASCII files or binary files
    • directories
    • special files

File metadata

  • name - human readable reference
  • identifier - unique id used by the file system
  • type - indicates the use of the file,
  • size - size in bytes
  • protection - access permissions
  • time - creation/modification time
  • owner - owner user id
  • table of content - information for the file system to determin how to access the file

File protection

  • controlled access to the information stored in a file
  • restrict access based on user identity
Type of accessDescription
readsee the contents of the file
writewrite to/rewrite the file
executeload into memory and execute
appendadd new information to the end of the file
deleteremove file from file system
listread metadata

Access control list(ACL)

  • list of user identity -> allowed access types
  • pros - very customizable
  • cons - too much info for one file

Minimal ACL

File access

Sequential access

  • read data in order
  • cannot skip but can be rewound

Random access

  • read in any order
  • read an offset

Direct access

  • file containing fixed-length records
  • random access to any record

File operations

  • OS provides syscalls for file management
  • OS maintains:
    • file pointer - current location in the file
    • disk location - file location on disk
    • open count - number of processes that have the file open
Type of accessDescription
createnew file is created with no data
openperformed before further operations
to prepare the necessary information for file operations later
readread data from file, usually starting from current position
writewrite data to file, usually starting from current position
repositionalso known as seek
move the current position to a new location
no actual read/write is performed
truncateremoves data between specified position to end of file

System-wide open-file table

  • one entry per unique file

Per-process open-file table

  • one entry per file used in the process
  • each entry points to the system-wide table

Directory

  • provides logical grouping of files
  • keep track of files

Single-level

  • all files in one single root directory

Tree-structure

  • sub-directories
  • absolute pathname
    • path all the way from root
  • relative pathname
    • following the current working directory(CWD)

Directed acyclic graph(DAG)

  • files/sub-directories can be shared
  • hard link
    • ln
    • to a file in another directory
    • two pointers to the actual file on disk
  • symbolic link
    • ln -s
    • to a file or directory
    • special link file with the pathname

General graph

  • hard to traverse - prevent infinite looping
  • hard to manage when moving files/directories