1 / 60

第六章 檔案系統 File Systems

第六章 檔案系統 File Systems. 鄧姚文 http://www.ywdeng.idv.tw. 大綱. 6.1 Files 檔案 6.2 Directories 目錄 6.3 File system implementation 檔案系統的實作 6.4 Example file systems 檔案系統實例. Long-term Information Storage. 檔案系統和辦公室裡的公文系統非常相似 公文櫃 --- 硬碟裡的一個檔案系統 公文櫃有許多個抽屜 --- 目錄 / 檔案匣 公文 --- 檔案 長期儲存資料的機制

zada
Download Presentation

第六章 檔案系統 File Systems

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. 第六章 檔案系統File Systems 鄧姚文 http://www.ywdeng.idv.tw Tanenbaum作業系統2Ed

  2. 大綱 • 6.1 Files 檔案 • 6.2 Directories 目錄 • 6.3 File system implementation 檔案系統的實作 • 6.4 Example file systems 檔案系統實例 Tanenbaum作業系統2Ed

  3. Long-term Information Storage • 檔案系統和辦公室裡的公文系統非常相似 • 公文櫃 --- 硬碟裡的一個檔案系統 • 公文櫃有許多個抽屜 --- 目錄/檔案匣 • 公文 --- 檔案 • 長期儲存資料的機制 • Must be possible to store a vary large amount of information – 容量要大 • The information must survive the termination of the process using it – 獨立存在 • Multiple processes must be able to access the information concurrently – 可以共用 Tanenbaum作業系統2Ed

  4. File Naming • Typical file extensions. Tanenbaum作業系統2Ed

  5. File Structure • Three kinds of files • byte sequence • record sequence • tree Tanenbaum作業系統2Ed

  6. File Types • Regular files 一般檔案 • 使用者的資料檔,各自定義其格式 • 可執行檔(Executables)須符合系統定義的格式 • ELF: executable and linkable format • Directories 目錄 • Character special files 對應到字元裝置 • Block special files 對應到區塊裝置 Tanenbaum作業系統2Ed

  7. File Types (a) An executable file (b) An archive Tanenbaum作業系統2Ed

  8. File Access • Sequential access 循序 • read all bytes/records from the beginning • cannot jump around, could rewind or back up • convenient when medium was magetic tape • Random access 隨機 • bytes/records read in any order • essential for database systems • read can be … • move file marker (seek), then read or … • read and then move file marker Tanenbaum作業系統2Ed

  9. File Attributes • Possible file attributes Tanenbaum作業系統2Ed

  10. File Operations • Create 創建 • Delete 刪除 • Open 開啟 • Close 關閉 • Read 讀 • Write 寫 • Append 附加 • Seek 搜尋 • Get attributes 取得屬性 • Set Attributes 設定屬性 • Rename 改名 Tanenbaum作業系統2Ed

  11. An Example Program Using File System Calls (1/2) Tanenbaum作業系統2Ed

  12. An Example Program Using File System Calls (2/2) Tanenbaum作業系統2Ed

  13. Memory-Mapped Files記憶體映對檔案 • Segmented process before mapping files into its address space • Process after mapping • existing file abc into one segment • creating new segment for xyz 檔案長度? 超級大檔案? Tanenbaum作業系統2Ed

  14. Directories 目錄、檔案夾Single-Level Directory Systems • A single level directory system • contains 4 files • owned by 3 different people, A, B, and C 檔名不能重複! Tanenbaum作業系統2Ed

  15. Two-level Directory Systems • Letters indicate owners of the directories and files Tanenbaum作業系統2Ed

  16. Hierarchical Directory Systems • A hierarchical directory system Tanenbaum作業系統2Ed

  17. Path Names • A UNIX directory tree 絕對路徑 /usr/local/bin/wget 相對路徑 ../../bib/main.bib ./bin/mirror 目前目錄 . 上一層目錄 .. Tanenbaum作業系統2Ed

  18. Directory Operations • Create • Delete • Opendir • Closedir • Readdir • Rename • Link • Unlink Tanenbaum作業系統2Ed

  19. File System Implementation • A possible file system layout Tanenbaum作業系統2Ed

  20. Implementing Files (1) • Contiguous allocation of disk space for 7 files • State of the disk after files D and E have been removed Tanenbaum作業系統2Ed

  21. Implementing Files (2) • Storing a file as a linked list of disk blocks Tanenbaum作業系統2Ed

  22. Implementing Files (3) • Linked list allocation using a file allocation table in RAM Tanenbaum作業系統2Ed

  23. Implementing Files (4) • An example i-node Tanenbaum作業系統2Ed

  24. Implementing Directories (1) • A simple directory • fixed size entries • disk addresses and attributes in directory entry • Directory in which each entry just refers to an i-node Tanenbaum作業系統2Ed

  25. Implementing Directories (2) • Two ways of handling long file names in directory • In-line • In a heap Tanenbaum作業系統2Ed

  26. Shared Files (1) • File system containing a shared file Tanenbaum作業系統2Ed

  27. Shared Files (2) • (a) Situation prior to linking • (b) After the link is created • (c)After the original owner removes the file Tanenbaum作業系統2Ed

  28. Hard Link and Soft Link • UNIX • Hard Link • ln target link_name • Soft Link (Symbolic Link) • ln -s target link_name • Windows (XP and Later) • Hard Link • fsutil hardlink create NewFilename ExistingFilename • Soft Link Tanenbaum作業系統2Ed

  29. Disk Space Management (1) • Dark line (left hand scale) gives data rate of a disk • Dotted line (right hand scale) gives disk space efficiency • All files 2KB Compromise: 4KB Block size Block size(bytes) Tanenbaum作業系統2Ed

  30. Disk Space Management (2)Keep Track of Free Blocks • Storing the free list on a linked list • A bit map Tanenbaum作業系統2Ed

  31. Disk Space Management (3) • Almost-full block of pointers to free disk blocks in RAM • three blocks of pointers on disk • Result of freeing a 3-block file • Alternative strategy for handling 3 free blocks • shaded entries are pointers to free disk blocks Tanenbaum作業系統2Ed

  32. Disk Space Management (4)Disk Quota 配額 • Quotas for keeping track of each user’s disk use Tanenbaum作業系統2Ed

  33. Backups 備份 • Recover from disaster • Recover from stupidity • Don’t dump device special files • Incremental dump • Compress or not to compress… • Difficult to backup an active file system • Security problem • Physical dump / Logical dump Tanenbaum作業系統2Ed

  34. File System Reliability (1) • A file system to be dumped • squares are directories, circles are files • shaded items, modified since last dump • each directory & file labeled by i-node number File that has not changed Tanenbaum作業系統2Ed

  35. File System Reliability (2) • The logical dumping algorithm • Mark all directories and modifies files • Unmark any directories that have no modified files or directories in them or under them • Dump all the marked directories • Dump all the marked files Tanenbaum作業系統2Ed

  36. File System Reliability (2) Bit maps used by the logical dumping algorithm Tanenbaum作業系統2Ed

  37. File System Reliability (2) • Restore from backups • Create an empty file system • Restore the most recent full dump • Repeat with the first incremental dump after the full dump, then the next one, and so on. • Reconstruct the free block list Tanenbaum作業系統2Ed

  38. File System Reliability (3) • File system states (a) consistent (b) missing block (c) duplicate block in free list (d) duplicate data block 1 1 1 Tanenbaum作業系統2Ed

  39. File System Performance (1)block cache/buffer cache The block cache data structures h(device, disk address) Tanenbaum作業系統2Ed

  40. File System Performance (1)block cache/buffer cache • Modified LRU • Is the block likely to be needed again soon? • Is the block essential to the consistency of the file system? • Unix: sync every 30 seconds • Write-through cache • All modified blocks are written back to the disk immediately • Block Read Ahead • Get blocks into the cache before they are needed to increase the hit rate • Only works for files that are being read sequentially Tanenbaum作業系統2Ed

  41. File System Performance (2)reduce disk arm motion • I-nodes placed at the start of the disk • Disk divided into cylinder groups • each with its own blocks and i-nodes Tanenbaum作業系統2Ed

  42. Log-Structured File Systems • With CPUs faster, memory larger • disk caches can also be larger • increasing number of read requests can come from cache • thus, most disk accesses will be writes • LFS Strategy structures entire disk as a log • have all writes initially buffered in memory • periodically write these to the end of the disk log • when file opened, locate i-node, then find blocks Tanenbaum作業系統2Ed

  43. Example File SystemsCD-ROM File Systems • ISO 9660 • Level 1: 8+3 字檔名, 8 字目錄名, contiguous allocation • Level 2: 31 字檔名 • Level 3: relax the contiguous limitation • Rock Ridge Extensions • UNIX • Joliet Extension • Windows Tanenbaum作業系統2Ed

  44. Example File SystemsCD-ROM File Systems: ISO 9660 • Logical block (logical sector): 2352 bytes • Preamble, error correction, overhead: 304 bytes • Payload: 2048 bytes • 1 CD Set: up to 216-1 CDs • The first 16 blocks • Not defined by ISO 9660 • Provide bootstrap program • Primary volume descriptor: general information Tanenbaum作業系統2Ed

  45. Example File SystemsCD-ROM File Systems: ISO 9660 Binary fields encoded twice: little-endian (Pentium) and big-endian (SPARC) 16-bit numbers use 4 bytes, 32-bit numbers use 8 bytes Years begin to count at 1900, suffering from a Y2156 problem. Tanenbaum作業系統2Ed

  46. Example File SystemsCD-ROM File Systems: Rock Ridge • Rock Ridge Extension • By the UNIX community • Use the SYSTEM USE field • PX: POSIX attributes, rwxrwxrwx, SETUID, SETGID • PN: Major and minor device numbers • SL: Symbolic link, link to another file system • NM: Alternative name, not subject to charset and length limit • CL: Child location • PL: Parent location • RE: Relocation • TF: Time stamps (file created, modified, accessed) Tanenbaum作業系統2Ed

  47. Example File SystemsCD-ROM File Systems: Joliet • Joliet Extension • From Microsoft • Major extension • Long file name (64 characters) • Unicode character set (1 character = 2 bytes) • Directory nesting deeper than eight levels • Directory names with extensions Tanenbaum作業系統2Ed

  48. The CP/M File System • CP/M: Control Program for Microcomputers (1977) • Gary Kildall, Digital Research, Inc • Intel 8080 CPU, 4 KB RAM, 8-inch floppy of 180 KB • Zilog Z80 CPU, 64 KB RAM, 720 KB Floppy • Historically important, direct ancestor of MS-DOS • Simplicity • A reference OS for embedded systems • Splitting BIOS from CP/M • Portability • CP/M interact with the hardware only by making BIOS calls • Only one directory: fixed-size entries (32-byte each) Tanenbaum作業系統2Ed

  49. The CP/M File System (1) Memory layout of CP/M 17 I/O calls 3584 bytes 2KB 256 bytes Tanenbaum作業系統2Ed

  50. The CP/M File System (2) • The CP/M directory entry format Block count: in units of 128 bytes (128-byte physical sectors) Disk block size: 1 KB Max. file size 16 KB Files larger than 16 KB use EXTENT field Tanenbaum作業系統2Ed

More Related