Operating Systems ECE 344 File Systems Introduction Ashvin

  • Slides: 13
Download presentation
Operating Systems ECE 344 File Systems: Introduction Ashvin Goel ECE University of Toronto

Operating Systems ECE 344 File Systems: Introduction Ashvin Goel ECE University of Toronto

What is a File System? q A file system provides an abstraction for storing,

What is a File System? q A file system provides an abstraction for storing, organizing and accessing persistent data I. e. , data survives after process that created the data has terminated, and after machines crashes, reboot o This data is stored on disks, tapes, solid-state drives (SSD) … o q File-system data is organized as objects called files o q Files are accessed via system calls o q Need a way to find files, so files have names that are organized as directories Files can be accessed concurrently by different processes Portions of a file being accessed are cached in a buffer cache 2

Key File System Resources q Storage Media --- e. g. , disk q Files

Key File System Resources q Storage Media --- e. g. , disk q Files q Directories q Buffer Cache q The operating system also needs to keep track of open files. 3

Disk Blocks q Disks are accessed at the granularity of sectors o q Typically,

Disk Blocks q Disks are accessed at the granularity of sectors o q Typically, 512 bytes A file system allocates data in chunks called blocks The file system treats the disk as an array of blocks n o A block contains 2 contiguous sectors o Reduces overhead of managing individual bytes o Large blocks improve throughput but increase internal fragmentation o q Free block management o Keep track of free blocks § Uses bitmaps, linked list, B-trees o Allocate blocks to a file, manages free blocks § Issues similar to memory, swap management 4

Free Block Management - Bitmaps q Keep a bitmap in a separate area on

Free Block Management - Bitmaps q Keep a bitmap in a separate area on disk o q 1 bit per disk block Suppose block size = 4 KB, disk size = 1 TB Nr. of blocks = 244 M o Need 244 M bits > 30 MB disk space o need ~ 7, 500 disk blocks for the bitmap o q Advantages Allows allocating contiguous blocks to a file easily o Need only one bitmap block in memory at a time o q Disadvantages o Not optimized for allocating large contiguous set of blocks 5

Files q q The OS typically treats files as an unstructured sequence of bytes

Files q q The OS typically treats files as an unstructured sequence of bytes Programs can impose any format on files o q E. g. , application programs may look for specific file extension to indicate the file’s type However, OS needs to understand the format of executable files to execute programs o Standard used today ELF format (Executable and Linkable Format) To see what is in here on Unix: nm <executable_file> Executable file 6

File Metadata q Files have various attributes associated with them Name, owner, creation time,

File Metadata q Files have various attributes associated with them Name, owner, creation time, access permissions, size, etc. o These attributes are called file metadata o File system maintains file metadata in per-file data structures on disk o 7

Basic File-Related Calls q Open o q Start using file, set position to beginning

Basic File-Related Calls q Open o q Start using file, set position to beginning of file Read, Write Read/Write n bytes from/to current position o Update position o q Seek Move to a new position o Allows random access (mainly for disks, not tape) o q Close o q Stop using file Create, Rename, Delete, Get/Set attributes 8

Directories q Provide a method for naming, organizing and locating files q Store a

Directories q Provide a method for naming, organizing and locating files q Store a list of directory entries that point to files q Modern systems use hierarchical directories A directory contains files or sub-directories o E. g. , B contains entries for D, j and E o q Files are identified with pathnames o Absolute pathname § E. g. , cat /B/D/n o Relative pathname § Uses current directory A i m B D j n § E. g. , cd /B; cat D/n q Directory metadata is similar to files Interior node / Leaf node C E F k G o l H p q 9

Unix Directories: Links q Hard links More than one name for a file o

Unix Directories: Links q Hard links More than one name for a file o /C/F/r points to the same file as /B/D/n o Dag, instead of tree structure o q Symbolic links (short cuts) A file contains data naming another file (a redirect) o The file contents of /C/F/G/s are /B/D/m / A Interior node B C o i D m j E n r Leaf node F k G s o l H p q 10

Basic Directory-Related Calls q Open q Readdir Read entries in a directory o Each

Basic Directory-Related Calls q Open q Readdir Read entries in a directory o Each entry points to a file or sub-directory o q Seekdir o Simulated at user level q Close q Create, Rename, Delete, Get/Set attributes o q No Writedir! Link, Unlink o Add/remove a name for an existing file, or add/remove sym. link 11

Summary q High-level overview of file system: disk data blocks + file block management

Summary q High-level overview of file system: disk data blocks + file block management o files + application-level operations on them o directories + application-level operations on them o 12

Think Time q What is the purpose of directories in a file system? q

Think Time q What is the purpose of directories in a file system? q What operations update directories? q q In Unix, the directory hierarchy forms an acyclic graph. Explain how. How are cycles not allowed in the graph? 13