UNIX File Systems (based on Chap 4. in the book “the design of the UNIX OS”) Acknowledgement : Soongsil Univ. Presentation Materials 단국대 최종무 교수님 강의노트.

Slides:



Advertisements
Similar presentations
Operating Systems File Management.
Advertisements

Chapter 4 : File Systems What is a file system?
Free Space and Allocation Issues
File Systems.
Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection.
Allocation Methods - Contiguous
File Systems Examples.
Chapter 10: File-System Interface
Ext2/Ext3 Linux File System Reporter: Po-Liang, Wu.
UNIX File Systems (Chap 4. in the book “the design of the UNIX OS”) Acknowledgement : Soongsil Univ. Presentation Materials.
Lecture 3 & 4: FILE SYSTEM.
File System Implementation CSCI 444/544 Operating Systems Fall 2008.
Files. System Calls for File System Accessing files –Open, read, write, lseek, close Creating files –Create, mknod.
Operating Systems File systems
Ceng Operating Systems
6/24/2015B.RamamurthyPage 1 File System B. Ramamurthy.
1 File Management in Representative Operating Systems.
Wince File systems. File system on embedded File system choice on embedded is important –File system size can be an issue –Different media are used –
1 Course Outline Processes & Threads CPU Scheduling Synchronization & Deadlock Memory Management File Systems & I/O Networks, Protection and Security.
7/15/2015B.RamamurthyPage 1 File System B. Ramamurthy.
Secondary Storage Management Hank Levy. 8/7/20152 Secondary Storage • Secondary Storage is usually: –anything outside of “primary memory” –storage that.
1 Project: File System Textbook: pages Lubomir Bic.
File System. NET+OS 6 File System Architecture Design Goals File System Layer Design Storage Services Layer Design RAM Services Layer Design Flash Services.
1 File System Implementation Operating Systems Hebrew University Spring 2010.
Chapter 8 File Management
File Systems (1). Readings r Silbershatz et al: 10.1,10.2,
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Disk Access. DISK STRUCTURE Sector: Smallest unit of data transfer from/to disk; 512B 2/4/8 adjacent sectors transferred together: Blocks Read/write heads.
1Fall 2008, Chapter 11 Disk Hardware Arm can move in and out Read / write head can access a ring of data as the disk rotates Disk consists of one or more.
Chapter 4. INTERNAL REPRESENTATION OF FILES
File System Review bottomupcs.com J. Kubiatowicz, UC Berkeley.
File Systems CSCI What is a file? A file is information that is stored on disks or other external media.
10/23/ File System Architecture. 10/23/ / bin unixdev etc user jim mike x y z tty00 tty01 File System architecture.
Chapter 5 File Management File System Implementation.
File Management Chapter 12. File Management File management system is considered part of the operating system Input to applications is by means of a file.
File System Implementation
Chapter 4. INTERNAL REPRESENTATION OF FILES
Files & File system. A Possible File System Layout Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved
Project 6 Unix File System. Administrative No Design Review – A design document instead 2-3 pages max No collaboration with peers – Piazza is for clarifications.
Disk & File System Management Disk Allocation Free Space Management Directory Structure Naming Disk Scheduling Protection CSE 331 Operating Systems Design.
Chapter 16 File Management The Architecture of Computer Hardware and Systems Software: An Information Technology Approach 3rd Edition, Irv Englander John.
CE Operating Systems Lecture 17 File systems – interface and implementation.
1 Chapter 4. INTERNAL REPRESENTATION OF FILES THE DESIGN OF THE UNIX OPERATING SYSTEM Maurice J. bach Prentice Hall.
UNIX File System (UFS) Chapter Five.
File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted).
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Files and file allocation.
Lecture 10 Page 1 CS 111 Summer 2013 File Systems Control Structures A file is a named collection of information Primary roles of file system: – To store.
Linux File system Implementations
Foundation of Unix Operating Systems
Lecture 19 Linux/Unix – File System
11.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 11.5 Free-Space Management Bit vector (n blocks) … 012n-1 bit[i] =  1  block[i]
MINIX Presented by: Clinton Morse, Joseph Paetz, Theresa Sullivan, and Angela Volk.
File System Design David E. Culler CS162 – Operating Systems and Systems Programming Lecture 23 October 22, 2014 Reading: A&D a HW 4 out Proj 2 out.
File Systems and Disk Management
Day 28 File System.
EXT in Detail High-Performance Database Research Center
Today topics: File System Implementation
Chapter 11: File System Implementation
Day 27 File System.
File System Structure How do I organize a disk into a file system?
Buffer Cache.
Filesystems.
Chapter 4: System calls for the file system
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
Chapter 16 File Management
UNIX File Systems (Chap 4. in the book “the design of the UNIX OS”)
Internal Representation of Files
Structure of Processes
Mr. M. D. Jamadar Assistant Professor
Introduction to Operating Systems
Presentation transcript:

UNIX File Systems (based on Chap 4. in the book “the design of the UNIX OS”) Acknowledgement : Soongsil Univ. Presentation Materials 단국대 최종무 교수님 강의노트

Hard Disk Drive Structure Characteristics Seek time, rotational latency, transmission time Disk Scheduling?, cylinder group?, Buffering?

Flash Memory limitation Seek optimization 이 불필요 Block erasure : block 단위로 지워짐. Memory wear : # of erase limiation Read disturb Seek optimization 이 불필요 Require strong reliability (e.g. power failure recovery)

File System  the system in which files are named and where they are placed logically for storage and retrieval 컴퓨터에서 파일이나 자료를 쉽게 발견 및 접근(read/write)할 수 있도록 보관/조직하는 체제 Properties Hierarchical structure Ability to create, read/write, and delete files Dynamic growth of files Protection of file data

File System 하는일 Support file interfaces to user File management File interface: open, close, read, write, … Directory manipulation: mkdir, cd, rmdir,… File system interfaces: mount, mkfs, fsck, … File management i-node, FAT Access control, attribute control, .. Storage management Disk management (Block allocation, I/O handling, …)

OS별 File Systems UNIX File System LINUX : EXT2, EXT3, EXT4 Windows : NTFS OS X (Apple Mac OS) : HFS+ Traditional OS (MS-Windows 9x) : FAT32

FAT Size limitation of FAT32 단순/빠르고 호환성이 좋음 (대부분의 OS에서 사용가능) 32GB보다 큰 파티션을 만들수 없다 4GB 초과하는 파일을 만들수 없다 단순/빠르고 호환성이 좋음 (대부분의 OS에서 사용가능)

FAT File Allocation Table

FAT

NTFS MS-Windows 계열 OS 기본 file system 보안 (사용 권한 및 암호화) 신뢰성 (파일시스템 오류 자동 복구) Storage growth Support for Large volume and file sizes (대용량 파일(16EB)/볼륨 지원) 호환성 떨어짐 (Mac OS에서는 read만 지원, LINUX에서는 배포판/버전에 따라 불분명)

UNIX File System Overview Boot block : 부팅에 필요한 정보 저장 Super block : file system 전체 정보 저장 i-list : 각 file당 하나의 i-node 할당, file 정보 저장 Data blocks : 실제 파일 내용을 블록 단위 저장 Block : 데이터를 한번에 읽고 쓰는 단위 (주로 1KB~4KB)

File System Layout Root directory의 i-node 는 미리 정해져 있음.

Sample File System

File Sharing Each user has a “file descriptor table” (or “per-user open file table”) Each entry in the channel table is a pointer to an entry in the system-wide “open file table” Each entry in the open file table contains a file offset (file pointer) and a pointer to an entry in the “memory-resident i-node table” If a process opens an already-open file, a new open file table entry is created (with a new file offset), pointing to the same entry in the memory-resident i-node table If a process forks, the child gets a copy of the channel table (and thus the same file offset)

UNIX File System Overview

EXT2 file system LINUX 기본 file system Ext2 특징 Ext3 특징 Ext4 특징 block group 도입 : 같은 파일은 같은 block group (하드 디스크상 같은 cylinder)을 가능한 사용하여 성능 향상(disk seek time, fragmentation ) Ext3 특징 Journaling 기능 도입: Logging and Fast Recovery Ext4 특징 Large size 파일 지원

UNIX File System

Table of Contents Inodes Structure of a regular file Directories Conversion of a path name to an Inode Super block Inode assignment to a new file Allocation of disk blocks Other file types Summary

Summary Inode is the data structure that describes the attributes of a file, including the layout of its data on disk. Two versions of the inode Disk copy : store the inode information when file is not in use In-core copy : record the information about active files. Inode disk blocks Directories : files that correlate file name components to inode numbers namei : convert file names to inodes Inode assignment Disk block assignment

Table of Contents Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Summary

Definition of Inodes Every file has a unique inode Contain the information necessary for a process to access a file Exist in a static form on disk Kernel reads them into an in-core inode to manipulate them.

Contents of Disk inodes File owner identifier (individual/group owner) File type (regular, directory,..) File access permission (owner,group,other) File access time Number of links to the file Table of contents for the disk address of data in a file (byte stream vs discontiguous disk blocks) File size * inode does not specify the path name that access the file

Sample Disk Inode File owner identifier File type File access permission File access time Number of links to the file Table of contents for the disk address of data in a file File size Owner mjb Group os Type regular file Perms rwxr-xr-x Accessed Oct 23 1984 1:45 P.M Modified Oct 22 1984 10:3 A.M Inode Oct 23 1984 1:30 P.M Size 6030 bytes Disk addresses

Distinction Between Writing inode and File File change only when writing it. Inode change when changing the file, or when changing its owner, permisson,or link settings. Changing a file implies a change to the inode, But, changing the inode does not imply that the file change.

Contents of The In-core copy of The Inode Fields of the disk inode Status of the in-core inode, indicating whether Inode is locked Process is waiting for the inode to become unlocked In-core inode differs from the disk copy as a result of a change to the data in the inode In-core inode differs from the disk copy as a result of a change to the file data Inode number (linear array on disk, disk inode does not need this field) Reference count

Inode Lock and Reference Count Kernel manipulates them independently Inode lock Set during execution of a system call to prevent other processes from accessing the inode while it is in use. Kernel releases the lock at the conclusion of the system call Reference count Kernel increase/decrease when reference is active/inactive Prevent the kernel from reallocating an active in-core inode

Table of Contents Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Summary

Direct and Indirect Blocks in Inode single indirect double indirect triple indirect Inode Data Blocks

Byte Capacity of a File System V UNIX. Assume that Run with 13 entries 1 logical block : 1K bytes Block number address : a 32 bit (4byte) integer 1 block can hold up to 256 block number (1024byte / 4byte) 10 direct blocks with 1K bytes each=10K bytes 1 indirect block with 256 direct blocks= 1K*256=256K bytes 1 double indirect block with 256 indirect blocks=256K*256=64M bytes 1 triple indirect block with 256 double indirect blocks=64M*256=16G Size of a file : 4G (232), if file size field in inode is 32bits * Refer to the link on our class webpage for the case of current UNIX file system.

Byte Offset and Block Number Process access data in a file by byte offset. The file starts at logical block 0 and continues to a logical block number corresponding to the file size Kernel accesses the inode and converts the logical file block into the appropriate disk block

Conversion of Byte Offset to Block Number Algorithm bmap /* block map of logical file byte offset to file system block */ Input : inode, byte offset Output: (1)block number in file system, (2)byte offset into block, (3)bytes of I/O in block, (4)read ahead block number calculate logical block number in file from byte offset; calculate start byte in block for I/O; /* output 2 */ calculate number of bytes to copy to user; /* output 3 */ check if read-ahead applicable, mark inode; /* output 4*/ determine level of indirection; while(not at necessary level of indirection) calculate index into inode or indirect block from logical block number in file; get disk block number from inode or indirect block; release buffer from previous disk read, if any (algorithm brelse); if(no more levels of indirection) return (block number); read indirect disk block (algorithm bread); adjust logical block number in file according to level of indirection;

Block Layout of a Sample File and Its inode 4096 228 45423 11111 101 367 428 9156 824 331 3333 Single indirect Double indirect Data block 75 Byte 9000 in a file -> 8block 808th byte 8 8 816th byte (10K+256K) Byte 350,000 in a file 11

Block Entry in the Inode is 0 Logical block entry contain no data. Process never wrote data into the file at that byte offset No disk space is wasted Cause by using the lseek and write system call

Table of Contents Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Summary

Directories A directory is a file Its data is a sequence of entries, each consisting of an inode number and the name of a file contained in the directory Path name is a null terminated character string divided by “/” Each component except the last must be the name of a directory, last component may be a non-directory file

Directory Layout for /etc Each entry : inode number and filename Inode Number (2 bytes) File Names 83 2 1798 1276 ... 95 188 . .. init fsck … crash mkfs inittab

Directories : How How do you find files? How do you list files (ls) Read the directory, search for the name you want (checking for wildcards) How do you list files (ls) Read directory contents, print name field How do you list file attributes (ls -l) Read directory contents, open inodes, print name + attributes

Table of Contents Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Summary

Algorithm for Conversion of a Path Name to an Inode Algorithm namei /* convert path name to inode */ Input : path name Output : locked inode { if(path name starts from root) working inode = root inode (algorithm iget); else working inode = current directory inode (algorithm iget); while(there is more path name){ read next path name component from input; verify that working inode is of directory,access permission OK; if(working inode is of root and component is “..”) continue; /* loop back to while */ read directory (working inode) by repeated use of algorithms bmap,bread and brelse; …

Algorithm for Conversion of a Path Name to an Inode if(component matches an entry in directory (working inode)){ get inode number for matched component; release working inode (algorithm iput); working inode=inode of matched component(algorithm iget); } else /* component not in directory return (no inode); } return (working inode);

Table of Contents Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Other File Types Summary

Super block File System Super block consists of the size of the file system the number of free blocks in the file system a list of free blocks available on the file system the index of the next free block in the free block list the size of the inode list the number of free inodes in the file system a list of free inodes in the file system the index of the next free inode in the free inode list lock fields for the free block and free inode lists a flag indicating that the super block has been modified boot block super block inode list data blocks

Table of Contents Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Summary

Inode Assignment to a New File Super block contains an array to store the index numbers of free inodes in the file system remembered inode 이 inode보다 작은 번호의 inode는 superblock free list에 없음을 보장한다. reduce free inode search time

Algorithm for Assigning New Inodes Algorithm ialloc /* allocate inode */ Input : file system Output : locked inode { while(not done){ if(super block locked) { sleep(event super block becomes free); continue; } if(inode list in super block is empty){ lock super block; get remembered inode for free inode search; search disk for free inodes until super block full, or no more free inodes (bread and brelese); unlock super block; wake up (event super block becomes free); if(no free inodes found on disk) return (no inode); set remembered inode for next free inode search;

Algorithm for Assigning New Inodes /* there are inodes in super block inode list */ get inode number from super block inode list; get inode (algorithm iget); if(inode not free after all) { write inode to disk; release inode (algorithm iput); continue; /* while loop */ } /* inode is free */ initialize inode; decrement file system free inode count; return (inode); } // end of while

Assigning Free Inode from Middle of List free inodes 83 48 empty 18 19 20 array1 Super Block Free Inode List index free inodes 83 empty 18 19 20 array2

Assigning Free Inode – Super Block List Empty index 470 empty array1 Super Block Free Inode List 535 free inodes 476 475 471 array2 48 49 50 remembered inode

Algorithm for Freeing Inode Algorithm ifree /* inode free */ Input : file system inode number Output : none { increment file system free inode count; if(super block locked) return; if(inode list full){ if(inode number less than remembered inode for search) set remembered inode for search = input inode number; } else store inode number in inode list; return; }

Placing Free Inode Numbers Into the Super Block 535 476 475 471 free inodes remembered inode Original Super Block List of Free Inodes index Free Inode 499 499 476 475 471 free inodes remembered inode index Free Inode 601 499 476 475 471 free inodes remembered inode index

Table of Contents Inodes Structure of a Regular File Directories Conversion of a Path Name to an Inode Super Block Inode Assignment to a New File Allocation of Disk Blocks Summary

Linked List of Free Disk Block Numbers 109 106 103 100 ………………………….. 211 208 205 202 …………………… 112 109 310 307 304 301 …………………… 214 211 409 406 403 400 …………………… 313 310 Super block list

Algorithm for Allocating Disk Block Algorithm alloc /* file system block allocation */ Input : file system number Output : buffer for new block { while(super block locked) sleep (event super block not locked); remove block from super block free list; if(removed last block from free list){ lock super block; read block just taken from free list (algorithm bread); copy block numbers in block into super block; release block buffer (algorithm brelse); unlock super block; wake up processes (event super block not locked); } …

Algorithm for Allocating Disk Block … get buffer form block removed from super block list (algorithm getblk); zero buffer contents; decrement total count of free blocks; mark super block modified; return buffer; }

Requesting and Freeing Disk Blocks super block list 109 ………………………………………………………… 109 211 208 205 202 …………………………….. 112 original configuration 109 949 ………………………………………………….. 109 211 208 205 202 ………………………………. 112 After freeing block number 949

Requesting and Freeing Disk Blocks 109 ……………………………………………………….. 109 211 208 205 202 ………………………………. 112 After assigning block number(949) 211 208 205 202 ……………………………… 112 211 344 341 338 335 ………………………………. 243 After assigning block number(109) replenish super block free list