Chapter 10 File System June 2015 Seungjae Baek
Chapter 10. File System June, 2015 Seungjae Baek Dept. of software Dankook University http: //embedded. dankook. ac. kr/~baeksj Seungjae Baek
Contents 10. 1 File Concept 10. 2 Access Methods 10. 3 Directory and Disk Structure 10. 4 File-System Mounting 10. 5 File Sharing 10. 6 Protection 10. 7 Summary 2 Seungjae Baek
Chapter Objectives To explain the function of file systems To describe the interfaces to file systems To discuss file-system design tradeoffs, including access methods, file sharing, file locking, and directory structures To explore file-system protection 3 Seungjae Baek
10. 1 File Concept Secondary storage ü ü To backup main memory and to support persistent (nonvolatile) Managed by file systems (FAT, Ext 4, NTFS, UFS, NFS, …) File system ü Supports a uniform logical view of storage media § Abstract from the physical properties of its storage devices ü Consists of two distinct parts § Files: a collection of related information defined by its creator • A sequence of bytes or records or formatted rigidly § Directory structure: organizes files in the file system • Directory itself is treated as file 4 Seungjae Baek
10. 1 File Concept File attributes ü ü ü Name: kept in human-readable form User identification: creator Identifier: unique number (or tag) to identify a file within file system § fd (file descriptor), file handle ü Type: file systems generally support different types of files § binary, word, multimedia, compressed, … § regular, directory, device file, pipe, … ü ü Size and position: file size and current read/write offset Location: pointer to a device and sectors on device § linked list, inode, FAT, … ü ü ü Protection: controls who can do reading, writing, executing Time and date: creation, last modification, last use time. useful for security and usage monitoring Some information about files are kept in the directory structure while others are in a special data structure § directory entry (file name, id) and FCB (File Control Block, eg. inode) 5 Seungjae Baek
10. 1 File Concept File operations ü Create a file § Allocate space in storage. Then, make a new entry in directory ü Open/Close a file § Find the file and make it accessible/inaccessible § Manage the open-file table, Use index (e. g. fd) instead of file name in OS for performance purpose ü Write a file § Find file’s location in storage and write data § Manage a current-file-position pointer (offset in file) ü Read a file § Find file’s location in storage and read data (also, managing the pointer) ü Reposition within a file § Change the current-file-position pointer ü Delete a file § Release all file attributes and contents ü Truncate a file § Release the contents of a file but keep its attributes ü Others: rename, append, get/set attributes, … 6 Seungjae Baek
10. 1 File Concept Information associated with an open file ü ü File descriptor: index Open File Table § Pointer (offset), count ü In-memory inode (or FCB) § A kind of caching of in-storage inode § File access permission, disk location Locking an open file ü Orchestrate the concurrent accesses to a file (shared by multiple processes) § Shared lock, exclusive lock (like the reader-writer lock) ü Mandatory or advisory: § Mandatory – access is denied depending on locks held and requested § Advisory – processes can find status of locks and decide what to do (its up to software developer) § Windows adopt mandatory, while UNIX systems employ advisory locks 7 Seungjae Baek
10. 1 File Concept File type ü Name and extension § Just hint, not enforced in Oss ü Some file has a magic number stored at the beginning of files § ELF (Executable linking format), shell script, Post. Script file, … § It informs the internal structure of a file to OSs (note that each application also has its own numbers to identify the structure) 8 Seungjae Baek
10. 2 Access Methods Sequential access ü Data in a file is accessed in order, one after the other § Read/write from CP(Current Position), CP is advanced automatically § Common pattern: compiler, multimedia player, … § Support rewind (reset), skip forward/backward, … Direct access (relative access) ü Can place the current position randomly at any location § Set CP to n, and then read/write § Common pattern: DB, structured access, . . ü Index based access § Index: contains pointers to the location of data 9 Seungjae Baek
10. 3 Directory and Disk Structure Partition and file system ü Partition (or slice) § A storage device is usually divided into several partitions § Sometimes, multiple storage devices are collected into a partition § Each partition has its own file system (volume) ü File system § Consists of directory and files (directory can be scattered) § File system information: superblock or volume table of contents 10 Seungjae Baek
10. 3 Directory and Disk Structure Directory ü ü A collection of nodes containing information about files (and directories) Each directory consists of a set of entry where each entry has file name and pointers to a block managing file attributes (eg. inode #) Operations performed on directory ü ü ü Search for a file Create a file Delete a file List a directory Rename a file Traverse a file system 11 Seungjae Baek
10. 3 Directory and Disk Structure Directory structure ü Single-level directory § All files are contained in the same directory § Hard to grouping: classification § Hard to flexible naming: same name to different file and vice versa ü Two-level directory § Create a separate directory for each user (or each class, country, …) § Can improve the grouping and naming problem 12 Seungjae Baek
10. 3 Directory and Disk Structure Directory structure ü Tree-structured directory § Extend the two-level to a tree of arbitrary height • • § § A directory contains a set of files or directories Treat a directory exactly the same as file (UNIX) or treat directory as entity separate from file with different system calls (Windows) More flexible grouping capability Make use of the locality of related files during file search (efficiency) Path (absolute, relative), Current directory (working directory) Directory manipulation facility: cd, mkdir, rmdir, … 13 Seungjae Baek
10. 3 Directory and Disk Structure Directory structure ü Acyclic-graph directory (most common) § Support shared subdirectories or files • • Changing one affects another directly Need sharing semantics § Link • • ü A pointer to another file (or directory) hard or symbolic General graph directory § Allow upward pointers § Complete flexibility § Issues • • Need to prevent infinite loop while traversing Self referencing (especially for deletion) 14 Seungjae Baek
10. 3 Directory and Disk Structure Conventions about directory name 15 Seungjae Baek
10. 3 Directory and Disk Structure Relation between partition, file system and directory ü A variety of file systems § General FS: UFS, FFS, EXT 2/3/4, FAT, NTFS, LFS, Flash FS, GFS, … § Special: NFS, procfs, devfs, tmpfs, … ü Each file system on a partition is connected through directory § Mount/Unmount mechanism 16 Seungjae Baek
10. 4 File-System Mounting Mount ü A file system must be mounted before it can be accessed (like a file must be opened before it is accessed) § eg. ) $mount /dev/hda 2 /home ü /* mount partition-name mount-point */ Make files (of the mounted file system) available within the file-system name space § eg. ) $ cp /home/srtsai/public_html/a. htm /var/spool 17 Seungjae Baek
10. 5 File Sharing File owner (user) and group ü ü User ID, Group ID To support sharing and protection among multiple users Remote File Sharing ü ü ü To support file sharing across network ftp DFS (distributed file system) WWW (World Wide Web) Examples § DFS • • NFS (Network File System): Client-server model, RPC (Remote Procedure Call), Stateless failure mode (vs. stateful failure mode) CIFS (Common Internet File System): standard windows protocol § Distributed Naming Service • • Provide information needed for remote computing eg. DNS (Domain Name Service), LDAP (Lightweight Directory Access Protocol), Active directory § Consistency semantics • UNIX semantics vs. Session semantics (AFS) vs. Disconnect semantics (Coda) 18 Seungjae Baek
10. 5 Protection Based on access control list (ACL) ü ü ü User classification: User, Group, Others Access types: read, write, execute, append, delete, list Implementation § UNIX: bit manipulation § Windows: GUI supports Based on other techniques ü ü Associate a password with each file Divide the root privilege into multiple sub-privileges (isolation) 19 Seungjae Baek
10. 7 Summary File: abstract data type ü ü ü A sequence of bytes (or logical records) Interfaces: open, read, write, … Functionalities of OS for file § Map the logical file concept onto physical storage devices Directory ü ü Allow files to be organized Tree-structure, acyclic-graph structure, general graph structure Mount mechanism ü ü File system, partition, volume Make file systems available within the file system name space Sharing and protection ü ü Based on ACL (Access Control List) or password or others Need consistency semantics 20 Seungjae Baek
- Slides: 20