Download presentation
Presentation is loading. Please wait.
Published byBaldric Blake Modified over 8 years ago
1
File System Department of Computer Science Southern Illinois University Edwardsville Spring, 2016 Dr. Hiroshi Fujinoki E-mail: hfujino@siue.edu CS 314 Operating Systems File_System/001
2
CS 314 Operating Systems What is “file system”? Hard-Disk Drive Unit (Hardware) Device Drivers File System Semantics & Logical Structure Users Software implementation of files and directories CD-ROM Drive Unit Device Drivers Semantics Logical Structure Software implementation of files and directories Hide implementations details (absorb various types in hardware device) e.g., “Read 100 bytes from “my.txt” Provide users with high-level manipulations for files File_System/002 File system is an OS component that manages files for users (or applications) Hide implementation
3
CS 314 Operating Systems Question: Why not just memory (why do we need “files”)? Information must survive after a system is shut down Capacity of physical memory is usually limited Why do we need file system (or files)? (We can’t perform big application) Paging IPC through memory (shared memory) is not easy IPC through a file (pipe) is easier Identifying data you want to access is easy You can give a file name to a set of data You don’t have to use a pointer to access data (OS (i.e., file system) does this for you) Manipulating set of data is easy in file - save- copy - concatenate- delete - move File_System/003
4
CS 314 Operating Systems The five essential functions in a file system Storing files a unit of data to be manipulated Regular files: Directories: A special file that gives a tree-like hierarchical structure to ordinary files Free-disk space management Disk space allocation for each file (FAT, i-node, etc) (bit-map, array, linked-list) Similar to “free-memory management” File_System/004 User interface (let human users manipulate files) create, read, write, append, copy, move, etc. Access control (Who can read, write, execute, delete a file?)
5
File_System/005 Categories of files Files Directories Character Files Block Files Ordinary Files Special Files Ordinary Files Special Files Files for which unit of I/O is “character” Files for which unit of I/O is “record” Regular Files Files for which I/O can be performed I/O Files Executable Files For saving your data For saving your data As the interface to an I/O device As the interface to an I/O device Tree Files CS 314 Operating Systems
6
File_System/006 Hierarchical Directory Systems = Directory = File (ordinary file) Root Directory Files are a leaf-node Directories can have files and/or directories Directories can be a leaf-node Ownership of a directory is usually inherited to child directories Each drive (file system) starts with the root directory (user data will be stored there) Most of modern OSes use HDS CD (Change Directory) CWD (Current Working Directory)
7
Executable File File_System/007 Executable Files File Header Program Codes Data & Constants Relocation bits Symbol Table Magic Number Program code size Data size BSS size Symbol table size Entry point Flags CPU Program codes (machine codes) CS 314 Operating Systems
8
file CS 314 Operating Systems File_System/008 Internal File Organizations How does the contents in a file looks from user’s view? - You request data from file. The file system returns the requested data as a sequence of bytes. - No structure in returned data (OS does not care the contents. It’s all up to you.) Character Sequence (A.K.A “Byte Sequence”) Block Sequence (A.K.A. “Record Sequence”) - Contents in a file are organized as “records” - File read/write is in the unit of “record” Example: fprintf (name, address, phone_num, age); “record” file record Example: read (file_ID, buffer, number_bytes);
9
CS 314 Operating Systems File_System/010 Two access methods to files 1. Sequential Access Data in a file can be accessed from the beginning of a file to the end Data is accessed always in the same order Example: file saved on a tape Access Head
10
CS 314 Operating Systems File_System/011 2. Random Access Data in a file can be accessed from any where within a file You can specify data in a file (usually as “record”) Example: files saved on hard disk and floppy disk Disk File Data Access Head Two access methods to files
11
Disk-Drive Unit CS 314 Operating Systems (from CS312 Computer Architecture) File_System/017 Disk (physical) Track (logical) sector (logical) Hardware Organization (Disk) Motor spindle (physical)
12
CS 314 Operating Systems File_System/018 File System Implementation Sector allocations to files & managing sector allocations to files Contiguous allocation Non-Contiguous allocation (a) File space allocations (b) Managing space allocations Linked-list (“chained”) Indexed
13
CS 314 Operating Systems (from CS312 Computer Architecture) File_System/012 File System Implementation Structure of a file system Disk (Disk Platter) Physical Drive Capacity
14
CS 314 Operating Systems File_System/013 Logical internal format of a disk drive Structure of a file system Physical Drive Capacity MBR Partition Table Partition #1Partition #N Logical Drive Size of a partition The first sector for a partition The last sector for a partition Type of file system used for this partition
15
File_System/014 File System Implementation Structure of a file system Physical Drive Capacity MBR Partition Table Partition #1Partition #N Logical Drive Boot Block Super Block Free Space Management File Allocation Information The Root Directory Other files & directories Logical Drive CS 314 Operating Systems
16
File_System/015 System Boot Sequence You turn on power CPU jumps to the beginning of BIOS ROM CPU executes POST and initializes hardware - Memory access latency, initialize video card, etc. CPU executes BIOS routine to load MBR CPU jumps to the routine in MBR MBR contains a routine to check the partition table - Find out which logical drive is the system boot drive - Load the boot block of the boot drive and CPU jumps to it - The boot block contains a routine to start OS CS 314 Operating Systems
17
Logical Drive #0 (the first logical drive) CS 314 Operating Systems File_System/016 File System Implementation Structure of a file system Physical Drive MBR Partition Table Partition #1Partition #N Logical Drive Boot Block Super Block Free Space Management File Allocation Information The Root Directory Other files & directories Power-On Hardware Software This is the file system
18
CS 314 Operating Systems File_System/019 File System Implementation (1) Contiguous sector allocations * Microsoft calls “block” as “cluster” File A (5 blocks) File B (4 blocks) File C (12 blocks) File D (8 blocks) File E (7 blocks) Advantages Easy implementation File Name1st blockFile size File A05 blocks File B54 blocks File C912 blocks File D218 blocks File E297 blocks Fast access Blocks (sectors) are always contiguous Minimum head seek time Block* (a collection of sectors)
19
CS 314 Operating Systems File_System/020 File System Implementation (1) Contiguous sector allocations File A (5 blocks) File B (4 blocks) File C (12 blocks) File D (8 blocks) File E (7 blocks) Disadvantages Halls of “free blocks” (external fragmentation) Disk space will be wasted by halls Compaction (de-fragmentation) Expensive operation (for large disks)
20
CS 314 Operating Systems File_System/021 File System Implementation
21
CS 314 Operating Systems File_System/022 File System Implementation (2) Non-Contiguous sector allocations A file Need to manage sector allocations File Allocation Table (FAT) Linked-list of disk blocks i-node Advantages No external fragmentation (Windows’ approach) (UNIX’s approach)
22
CS 314 Operating Systems File_System/023 File System Implementation File Name1st blockFile size File A115 blocks A file NULL Linked-list of blocks
23
File Allocation Table (FAT) CS 314 Operating Systems File_System/024 File System Implementation File Name1st blockFile size File A115 blocks A file File Allocation Table 13 2 31 111323136 31
24
CS 314 Operating Systems File_System/025 File System Implementation File NamePointerFile size File A5 blocks A file i-node 11 13 2 36 31 What if a file is very large? If # of blocks needed is more than i-node?
25
CS 314 Operating Systems File_System/026 File System Implementation File NamePointerFile size File A5 blocks A file i-node Pointer
26
Disk Drive (HDD) File_System/027 Memory-Mapped Files Concept Try to access files as memory Virtual Address Space File Disk Sector (or a block of sectors) CS 314 Operating Systems
27
File_System/028 Memory-Mapped Files Concept Try to access files as memory Virtual Address Space File Disk Drive (HDD) Disk Sector (or a block of sectors) Memory Access (it’s an extension of “paging”) CS 314 Operating Systems
28
File_System/029 Memory-Mapped Files What are the motivations in doing this? We can access any data using a pointer - No need for calling “read” or “write” - No need for preparing “buffer” and buffer copies status = read (fd, buffer, bytes_read); if (status > 0) destination [0] = buffer[0]; destination [0] = my_pointer; - No need for “file descriptor” CS 314 Operating Systems
29
File_System/030 Memory-Mapped Files How can we use memory-mapped files? Map a file (to the virtual address space) - OS calls file system and performs “open” - It’s hidden from a user (or application program) - OS performs address boundary check - It’s hidden from a user (or application program) - OS saves updated data in the file - OS calls file system and performs “close” A user (or application program) can access a file as if it were memory access Un-map the file CS 314 Operating Systems
30
File_System/031 Memory-Mapped Files Virtual Address Space (Segment #1) File Disk Drive (HDD) Disk Sector (or a block of sectors) “Segmentation” can be applied to Memory-mapped files Virtual Address Space (Segment #2) 0000 Virtual Address Space (Segment #N) Segment All segments start at address = 0 CS 314 Operating Systems
31
File_System/000 CS 314 Operating Systems
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.