1 / 43

Module 11: File-System Interface

Module 11: File-System Interface. File Concept Contiguous logical address space Types: Data numeric character binary Program. File Structure. 내부구조에 대한 제한이 없음 – Just a sequence of words, bytes Simple record structure Lines Fixed length Variable length Complex Structures

noel-sweet
Download Presentation

Module 11: File-System Interface

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Module 11: File-System Interface • File Concept • Contiguous logical address space • Types: • Data • numeric • character • binary • Program Applied Operating System Concepts

  2. File Structure • 내부구조에 대한 제한이 없음 – Just a sequence of words, bytes • Simple record structure • Lines • Fixed length • Variable length • Complex Structures • Formatted document • Relocatable load file – text, data, symbol table, other headers, … • Who decides: • Operating system • Program Applied Operating System Concepts

  3. File Attributes (file metadata) • Name – only information kept in human-readable form. • Type – needed for systems that support different types. (다음 쪽) • Location – pointer to file location on device. • Size – current file size. • Protection – controls who can do reading, writing, executing. • Time, date, and user identification – data for protection, security, and usage monitoring. • Information about files are kept in the directory (폴더) structure, which is maintained on the disk. Applied Operating System Concepts

  4. File Types – name, extension {object modules} Applied Operating System Concepts

  5. File Operations • create • write • read • reposition within file – file seek • delete • truncate • open(Fi) – File 의 meta-정보를 디스크로부터 메모리로 가져옴 Search the directory structure to do this • close (Fi) Applied Operating System Concepts

  6. Access Methods • Sequential Access [카셋 테잎과 유사] read next write next reset to BOF no read after last write (rewrite) • Direct Access [LP 레코드 판과 유사] read n write n position to n read next write next rewrite n ** n = relative block number Applied Operating System Concepts

  7. Directory Structure • A collection of nodes containing information about files. Directory Files F 1 F 2 F 3 F 4 F n • Both the directory structure and the files reside on disk. • Backups of these two structures are kept on tapes. Applied Operating System Concepts

  8. Directory Structure (UNIX 방식) Directory 이름과 pointer Metadata Pointers to data (여러 disk 섹터들) F 3 File의 Meta data F 1 F 2 F 4 F n File의 실제 Data F 1 F 3 F 2 F 4 F n Applied Operating System Concepts

  9. Operations Performed on Directory • Search for a file • Create a file • Delete a file • List a directory • Rename a file • Traverse the file system Applied Operating System Concepts

  10. Single-Level Directory • A single directory for all users. • Naming problem • 충돌 • DOS 11 char, UNIX 255 char • Grouping problem Applied Operating System Concepts

  11. Two-Level Directory • Separate directory for each user. • “Pathname” • 사용자간 이름출동 없음 • No grouping capability Applied Operating System Concepts

  12. Tree-Structured Directories • Subdirectory 허용 (per each user) • Grouping 가능 • Home directory (per each user) • Current (working) directory • Absolute, relative pathname • eg cd / koh / ch1 • Search path (명령어 해석기) – 현재 환경 • 삭제시 문제: empty directory? (편의/위험) Applied Operating System Concepts

  13. Acyclic-Graph Directories • The same (subdirectory, file) may be in two different directories X Cycle not allowed • No cyclesallowed (acyclic) • Directory 공유 • “Both Koh & Lee need directory Y below” Applied Operating System Concepts

  14. Acyclic-Graph Directories • The same (subdirectory, file) may be in two different directories •  1. traverse 시 문제 (visit same node twice) 2. Delete 시 문제 • 시나리오: • Koh has subdirectory X (ie Koh has an entry for X) • Lee need to have X below his directory • UNIX – creates a “link” ( a new directory entry) in Lee’s directory • (방법 – “Hard link”) • 원래 Koh directory의 entry를 (file의 metadata) 물리적으로 (lee 에도) 복사 X 를 update 할 경우 consistency 문제 발생 (eg protection mode 변경) • X 를 delete 하면? Rerefence count 를 운영하여 0 이 되면 file delete. • (방법- “Symbolic link”) • Link is pathname -- 원장은 물리적으로 한부만 (X- 원장 소재의 pathname) • 문제: koh 가 X -원장을 삭제하면 lee의 link 는 dangling reference가 된다? • Lee 가 access 시도할 때 Just say “…. illegal file ….” Koh Lee X Applied Operating System Concepts

  15. General Graph Directory Cycle Applied Operating System Concepts

  16. General Graph Directory (Cont.) • Cycle 허용 • 대신 traverse, delete 등의 알고리즘이 까다로와 짐 • Traverse • Cycle 내에서 infinite loop  traverse 가 파행이 됨 • Delete • 즉 X의 reference count 는 결코 0이 안됨 (0 면 delete) • (self-referencing) • Koh 에서 X link 를 지워도 X 는 deallocate 가 안됨 • (즉 외부로부터 X를 access 하는 길이 없어져도 ..) • 이 경우 Garbage collection에서 처리 가능. 1stphase --access 불가능한 node 들을 marking 2 nd phase – delete marked nodes 그러나 Disk 경우 garbage collection이 매우 느림 – 자주 못함 • How do we guarantee no cycles? • Allow links only to files (not to subdirectories). • Every time a new link is added, use a cycle detection algorithm to determine whether it is OK. Koh X Applied Operating System Concepts

  17. Protection • File owner/creator should be able to control: • what operation can be performed on the file • by whom • Types of access • Read • Write • Execute • Append • Delete • List (name, attribute) • Access Control 방법 • Access control matrix me group all Too big • Unix – 전체 user를 세 구분으로 (여러 group?) rwxrwxrwx • Password per file -- all-or-nothing, 관리, 암기, …문제 Applied Operating System Concepts

  18. Groups • Mode of access: read, write, execute • Three classes of users Octal RWX a) owner access ‘7’  1 1 1 RWX b) group access ‘6’  1 1 0 RWX c) public (아무나) access ‘1’  0 0 1 • Ask super-user to create a group (unique name), say G, and add users to the group. • Attach a group to a file chgrpG game • For a particular file (say game) or subdirectory, define an appropriate access. owner group public chmod 761 Game 761 = 111 110 001 Applied Operating System Concepts

  19. File-System Structure • File system resides on secondary storage (disks) == (data structure + code) • File system organized into layers. (logical file system  I/O control  device) • Open() system call • 디스크로부터 지정된 파일의 메타정보를 메모리로 가지고 옴 • 이를 위하여 directory structure 를 search • Open-file table • 메모리에 있는 (현재 open 된) 파일들의 메타정보 보관소 • File descriptor (file handle, file control block) • Index into this table • Why? • Directory search is expensive 예: /a/b/c/d/e.hwp • So many files in disk • Mounting (see next two pages) disk I/O’s Applied Operating System Concepts

  20. File-System Structure Open()retrieves metadata from disk to main memory File metadata File metadata File Content Applied Operating System Concepts

  21. This metadata has pointers to data sectors File metadata File metadata File content File content File content File content Applied Operating System Concepts

  22. This metadata has pointers to data sectors Index (File handle) (File descriptor) File A metadata File content File content File B metadata File content File content File content File content Applied Operating System Concepts

  23. Mounting File-System (UNIX) / HD: Hard Disk CD: Compact Disk FD: Floppy Disk bin etc usr HD date sh getty passwd “root file system” (Boot 시 선택된 file system) CD Now all files under root file system can be accessed Question: how do we access files in other FD? FD Applied Operating System Concepts

  24. Answer: (1) Windows 경우 -- 각자 root (C: D: E: ) (2) UNIX 경우 ---- mount them (구분 불가) / bin etc usr HD date sh getty passwd Mount it! CD 새 pathname  /usr/src/uts / bin include src FD banner yacc studio.h uts Applied Operating System Concepts

  25. Allocation of File Data in Disk1. Contiguous – 한 덩어리로 2. Linked – sector 들을 link로 연결3. Indexed – sector pointer 들 Applied Operating System Concepts

  26. Contiguous Allocation (1/3) • Each file occupies a set of contiguous blocks on the disk. • Simple – only starting location (block #) and length (# of blocks) are required. • Wasteful of space • dynamic storage-allocation  external fragmentation •  numerous small holes • File grow 가 어려움. • file 생성시 얼마나 큰 hole을 배당할 것인가? • grow 가능 vs 낭비 (internal fragmentation) • Fast I/O • 한번의 seek/rotation으로 많은 바이트 transfer • Realtime file 용으로, 또는 • 이미 run 중이던 process의 swapping용 (total R/W 보장, no grow) 어려움: 공간관리 이득: 속도 Applied Operating System Concepts

  27. Linked Allocation (2/3) • Each file is a linked list of disk blocks: • blocks may be scattered anywhere on the disk. pointer Each block = File Content Applied Operating System Concepts

  28. Allocate as needed, link together; e.g., file starts at block 9 Head pointer 한개만 관리 Applied Operating System Concepts

  29. Linked Allocation (Cont.) • Simple – need only starting address • Free-space management system – no waste of space • 단점 • No random access • Disk I/O efficiency (매 sector I/O 마다 seek/rotation) • Reliability 문제 • (한 sector 가 고장나 pointer 가 유실되면 …. 많은 부분을 잃음) • Space for pointers (0.78% for pointers – 512 B/sector, 4 B/pointer) • 변형: File-allocation table (FAT) • disk-space allocation used by MS-DOS and OS/2. Applied Operating System Concepts

  30. 1st Data Sector 217 F A T (이 table 에 link point 들만 모아 놓음) Directory entry file_name start-block Koh 217 (One entry for each disk block) 2nd Data Sector 339 • 217 339 • 339 618 • EOF • 0 • F A T 1st block of file 3rd Data Sector 618 (Unused block) ** 장점: random access time is improved Applied Operating System Concepts

  31. Indexed Allocation (3/3) • Each file has its own index block (part of file metadata) • Index block is an array of pointers to disk blocks • Speed up direct access. • Logical view. disk blocks index table Applied Operating System Concepts

  32. Example of Indexed Allocation pointer 여러 개 필요 Applied Operating System Concepts

  33. Indexed Allocation – Mapping (Cont.) • What if file is too large? one disk block is too small for index table • Linked scheme – Link blocks of index table (no limit on size). • Two-level index • Combined (UNIX 예) d d d i i i each index node fan out N Applied Operating System Concepts

  34. Combined Scheme: UNIX (4K bytes per block) Applied Operating System Concepts

  35. Management of Free Space Applied Operating System Concepts

  36. Free-Space Management 0 1 2 n-1 • Bit map or bit vector 1 … 0 1 1 0  block[i] free 1  block[i] occupied bit[i] = • Block number calculation • Bit map requires extra space. • Easy to get contiguous files • (number of bits per word) * • (number of 0-value words) + • offset of first 1 bit Applied Operating System Concepts

  37. Free-Space Management (Cont.) …. These are data structure problems ……. • Linked list • Link all the free blocks (free list) • Traversing this list is slow (disk I/O), but is not frequent • Cannot get contiguous space easily • No waste of space • Grouping • Modification of linked list approach • First free block has n pointers • n-1 pointers point to free block • Last block  same kind (another n pointers) • Counting • Keep track of (first free block, # of contiguous free blocks) • Generally, several contiguous blocks are allocated & freed together Applied Operating System Concepts

  38. So … • “File System” means data structure on disk • “logical formatting” – initializing this data structure • Accessing a disk file is OS dependent operation Applied Operating System Concepts

  39. Directory Implementation Pointers File 이름 • Linear list of file names with pointers to the data blocks. • simple to program • Linear search to find a particular entry • which is time-consuming • Hash Table • linear list (but has extra hash table) • Hash table converts (file name) to pointer to (this file’s linear list). • decreases directory search time • collisions – situations where two file names hash to the same location 숙제.hwp 그림.jpeg 강의.ppt game.exe 1223 984 34 Applied Operating System Concepts

  40. Efficiency and Performance • Efficient use of disk space is dependent on: • disk allocation and directory algorithms • types of data kept in file’s directory entry • Performance • disk cache • separate section of main memory for frequently used blocks • free-behind and read-ahead • techniques to optimize sequential access • Sequential access 이면 next block request 할때 현 block을 free • virtual disk, or RAM disk. • improve PC performance by dedicating section of memory Applied Operating System Concepts

  41. Various Disk-Caching Locations Applied Operating System Concepts

  42. Recovery • Consistency checker • Some part of file system is kept in memory • What if system crashes? Not all the info can be saved to disk • If directory or file control block (metadata) are lost? • At boot time -- compare data in directory structure with data blocks on disk, and tries to fix inconsistencies. • Use system programs to back up data from disk to another storage device (floppy disk, magnetic tape). • Recover lost file or disk by restoring data from backup. Applied Operating System Concepts

  43. We skip Chapter 12, 14-17. Applied Operating System Concepts

More Related