Annotated by B. Hirsbrunner File Systems Chapter Files 5.2 Directories 5.3 File System Implementation 5.4 Security 5.5 Protection Mechanism 5.6 Overview 5.7 Implementation of the Minix 3 File System Andrew S. Tanenbaum and Albert S. Woodhull Operating Systems (The Minix Book), 3rd edition Prentice Hall © 2006 Lecture 11, 4 December 2012
Annotated by B. Hirsbrunner 2 5. Essential Requirements for Long-term Information Storage 1.Must store large amounts of data 2.Information stored must survive the termination of the process using it 3.Multiple processes must be able to access the information concurrently
Annotated by B. Hirsbrunner File Naming Fig. 5.1 Typical file extensions.
Annotated by B. Hirsbrunner File Structure Fig. 5.2 Three kinds of files a)byte sequence b)record sequence c)tree
Annotated by B. Hirsbrunner File Types Fig. 5.3 (a) An executable file (b) An archive Magic number: identifies the file as an executable
Annotated by B. Hirsbrunner File Access Sequential access –read all bytes/records from the beginning –cannot jump around, could rewind or back up –convenient when medium was magnetic tape Random access –bytes/records read in any order –essential for data base systems –read can be implemented by : move file marker (seek), then read sequentially (Unix, Windows) Give the position in the file to start reading at
Annotated by B. Hirsbrunner File Attributes Fig. 5.4 Some possible file attributes see OS X packages and meta data !
Annotated by B. Hirsbrunner File Operations Create Delete Open Close Read Write Append Seek Get attributes Set attributes Rename Lock The most common system calls relating to files:
Annotated by B. Hirsbrunner Simple Directories Fig. 5.5 a)A simple directory (e.g. Windows) o containing fixed size entries o with disk addresses and attributes in directory entry b)Directory in which each entry just refers to an i-node (e.g. Unix)
Annotated by B. Hirsbrunner Hierarchical Directory Systems Fig 5.6.a A single level directory system –contains 4 files –owned by 3 different people, A, B, and C
Annotated by B. Hirsbrunner Hierarchical Directory Systems Fig. 5.6.b A hierarchical directory system
Annotated by B. Hirsbrunner 12 Fig. 5.7 A UNIX directory tree Path Names
Annotated by B. Hirsbrunner Directories and Paths: Minix3 Fig (a) Root file system. (b) An unmounted file system. (c) The result of mounting the file system of (b) on /usr/ Special file: contains no data, but provides a mechanism to map physical devices to file names 13
Annotated by B. Hirsbrunner Directory Operations Create Delete Opendir Closedir Readdir Rename Link Unlink The most common system calls relating to directories: hard / symbolic link, see later (variants: alias in OS X, shortcut in Windows)
Annotated by B. Hirsbrunner File System Layout Fig. 5.8 A possible file system layout MBR = Master Boot Record Super block: contains all the key parameters about the file sytem
Annotated by B. Hirsbrunner File System Layout: MINIX 3 Fig Disk layout for a floppy disk or small hard disk partition, with 64 i-nodes and a 1-KB block size (i.e., two consecutive 512-byte sectors are treated as a single block). zone: 1, 2, 4, …, 2 n blocks 16
Annotated by B. Hirsbrunner Contiguous File Allocation Idea: allocate n consecutive blocks on the disk Advantage Very simple to implement Excellent read performance Major drawback in time, the disk becomes fragmented often, the final file size is not known at creation time Usage magnetic disk file systems optical write-once media: CD-ROMs, DVDs, …
Annotated by B. Hirsbrunner Linked List File Allocation Fig. 5.9 Storing a file as a linked list of disk blocks Fig 5.10 Linked list allocation using a file allocation table in RAM
Annotated by B. Hirsbrunner i-nodes Fig An i-node with three levels of indirect blocks
Annotated by B. Hirsbrunner Shared Files Fig File system containing a shared file Hard link vs symbolic (or soft) link Unix command: link
Annotated by B. Hirsbrunner Shared Files : hard link Fig a) Situation prior to linking b) After the hard link is created c) After the original owner removes the file Andrew S. Tanenbaum: "Modern Operating Systems", 3rd edition, Prentice Hall © 2009
Annotated by B. Hirsbrunner 22 Example: rsync to mimic Apple’s TimeMachine Source: Question: hard link or soft link ?
Annotated by B. Hirsbrunner Operations required to remove a file in UNIX Remove the file from its directory. Release the i-node to the pool of free i-nodes. Return all the disk blocks to the pool of free disk blocks Journaling File Systems Problem if the system crashes during these actions Solution Write a log entry listing the three actions to be completed and write it to disk + atomic transaction (i.e. 'begin transaction', 'end transaction') Andrew S. Tanenbaum: "Modern Operating Systems", 3rd edition, Prentice Hall ©
Annotated by B. Hirsbrunner Fig Position of the virtual file system Virtual File Systems Andrew S. Tanenbaum: "Modern Operating Systems", 3rd edition, Prentice Hall ©
Annotated by B. Hirsbrunner Directories in Windows 98 Fig An entry for (part of) a long file name in Windows 98. Fig 5.13 A Windows 98 base directory entry. 25
Annotated by B. Hirsbrunner Directories in Unix Fig A Version 7 UNIX directory entry
Annotated by B. Hirsbrunner Directories in Unix Fig The steps in looking up /usr/ast/mbox
Annotated by B. Hirsbrunner Reducing Disk Arm Motion Fig a)i-nodes placed at the start of the disk. b)Disk divided into cylinder groups, each with its own blocks and i-nodes. 28