1 / 33

4.3. The Virtual File System

4.3. The Virtual File System. Jordi Garcia. 2013-2014. Concepts about the file system The user view The disk structure Files in disk – The ext2 FS The Virtual File System. Concepts about the file system The disk structure Files in disk – The ext2 FS The Virtual File System. The VFS.

kenley
Download Presentation

4.3. The Virtual File System

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. 4.3. The Virtual File System Jordi Garcia 2013-2014

  2. Concepts about the file system • The user view • The disk structure • Files in disk – The ext2 FS • The Virtual File System • Concepts about the file system • The disk structure • Files in disk – The ext2 FS • The Virtual File System The VFS (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Contents

  3. Disk: Device that stores information (files) • Many files x many users: OS management • Files organization • Directories • Links • Files protection: rwxrwxrwx • Data file: read / write / execute • Directory: • r allows reading directory contents • w allows writing directory contents (add or remove files) • x allows changing directory The File System (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Concepts (1)

  4. File system: Logical view of a disc • The information is organized: files, directories • Features • Inverted tree structure • Or graph (acyclic / cyclic), when links • Root directory: / • Current directory: . • Parent directory: .. • Exception: Parent of root directory • All processes have a working directory: cwd • Relative path (assuming cwd) • Absolute path (cwd not assumed) The File System (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Concepts (2)

  5. File: Any object with a name in the File System • File types • Regular file • Contains data • Directory • Contains files (regular, directory, …) • Link • Soft / symbolic (points to the name) • Hard (points to the content) • Device • Type, major, minor • Named pipe • Type p • … The File System (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Concepts (3)

  6. With . and .. files in each directory • If there are links, the tree becomes a graph / The File System etc dev usr home mnt bin lib jordi aaa josep bbb fff f1.c f1.o f1 Example (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu

  7. Usual I/O system calls, and • And other system calls to manage • Permissions • Relationship • Features • … The File System (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Additional system calls

  8. IN MEMORY • Organize files (namespace, directories) • Manage file contents in disk • Manage disk space (allocated/free) • … and guarantee correctness, robustness, protection and efficiency The File System IN DISK (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu OS responsibilities

  9. Concepts about the file system • The disk structure • Disk structure • Disk contents • Files in disk – The ext2 FS • The Virtual File System • Concepts about the file system • The disk structure • Files in disk – The ext2 FS • The Virtual File System The VFS (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Contents

  10. Consists of: Platter/head/track/sector • All sectors have the same size • It can also be seen as a list of sectors The disk structure SECTOR-1 SECTOR-2 SECTOR-3 SECTOR-4 … SECTOR-N (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu The disk

  11. Metadata • Boot sector (optional, only if bootable disk) • Super block (one, or several through the disk) • Disk structure (metadata / data), size, … • List of free sectors • Info about files (the data) storage • Data: organized in blocks • 1 block (OS view) = N sectors (disk view) • The actual format depends on specific FS • ext2, ext3, NTFS, … The disk structure Super block Info aboutfiles storage Datablock Datablock Datablock Datablock Datablock … Super block Info aboutfiles storage Datablock Datablock Datablock … BOOT sector Disk contents (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu

  12. Disk allocation strategies • Continuous • For write-once disks • Discontinuous (at block level) • Linked list: FAT • Index table: inode • The ext2 file system • Free space management • Depends on allocation strategy • Bitmap of free blocks The disk structure (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Space allocation/free

  13. Concepts about the file system • The disk structure • Files in disk – The ext2 FS • Regular file • Directory • Links • Other types • The Virtual File System • Concepts about the file system • The disk structure • Files in disk – The ext2 FS • The Virtual File System The VFS (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Contents

  14. Contains: data (any type) • Where: In data blocks, discontinuously • File attributes • Packed into one data structure: inode • Metadata with all information about the file • … including the index table • … except the file name (!) Files in disk – ext2 Super block List of inodes Data Data Data Data Data … Super block List of inodes Data Data Data … BOOT sector Info Inode Index table Regular file (1) (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu

  15. The inode data structure • 1 inode per file • File type: data(dir, link, device, pipe, …) • Size (determines #blocks and offset in last block) • Permissions • Proprietary • Dates (creation, modification, access) • Number of references (later) • … • Index table (13 pointers) • 10 direct pointers • 1 single indirect pointer • 1 double indirect pointer • 1 triple indirect pointer Files in disk – ext2 (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Regular file (2)

  16. Contains: List of files/inodes • Where: In data blocks • Usually 1 block but, if more, discontinuously • Data block contents • file name - #inode • Always, at least, . and .. directories Files in disk – ext2 #inode file name Info #inode file name Inode file name #inode Index table … … Super block List of inodes Data Data Data Data Data … Super block List of inodes Data Data Data … BOOT sector Directory file (1) (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu

  17. The inode data structure • File type: dir • All other fields are similar than regular file • Considerations in Linux • Root directory inode is always #0 • . directory points to the same directory • .. directory points to the parent • Except for root, that points to itself Files in disk – ext2 (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Directory file (2)

  18. In Linux, the root inode is always #0 • Build the following file system: • Inodes • Data blocks Files in disk – ext2 type: DIR type: DIR type: DATA type: DIR type: DIR type: DATA type: DIR type: DATA 2 8 11 15 7 18 3 6 #7 #1 #5 #6 #4 #2 #3 #0 patim patam patum . . . . . 2 6 7 0 4 .. .. .. .. .. 0 0 2 0 0 A A f1 1 6 4 f1 B f2 5 3 2 C 7 #3 #15 #18 #6 #8 #11 #2 #7 Example (1) (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu

  19. Soft Link (or symbolic link) • New file object that points to a pathname • The inode data structure contains • File type: link • All other fields are similar than regular files • The data block contains the path name • Hard link • New directory entry (name) that points to an existing inode • There is not any specific inode for it • Number of references ++ • There are not data blocks for it • Note that . and .. are hard links Files in disk – ext2 (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Links

  20. Device • File object that represents a device in the FS • The inode data structure contains • File type: char / block • Major, minor, … • No data blocks are used • Named pipe • File object that represents a pipe in the FS • The inode data structure contains • File type: pipe • No data blocks are used • And more: Sockets, … Files in disk – ext2 (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Other types

  21. In Linux, the root inode is always #0 • Build the following file system: • Inodes • Data blocks Files in disk – ext2 type: DIR #refs = 3 type: DATA #refs = 2 type: DIR #refs = 2 type: DIR #refs = 2 type: DATA #refs = 1 type: LINK #refs = 1 type: DIR #refs = 5 11 7 8 6 2 3 15 18 #0 #4 #2 #5 #1 #7 #3 /B/file3 patim . 4 /B/file3 patam . . . 7 0 2 .. 0 .. .. .. 0 0 0 file1 3 A file3 file4 5 1 4 file2 5 B D 2 7 C 7 #3 #11 #18 #15 #6 #8 #2 #7 Example (2) (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu

  22. Concepts about the file system • The disk structure • Files in disk – The ext2 FS • The Virtual File System • Overview • Internal VFS data structures • System calls and the VFS • Concepts about the file system • The disk structure • Files in disk – The ext2 FS • The Virtual File System The VFS (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Contents

  23. Abstraction layer on top of a specific FS void main() { read(…); write(…); } void main() { read(…); write(…); } User Virtual File System Syscalls interface System Virtual File System Procs & memory management IPC … ext2 ext3 FAT NTFS Blocks server (buffer cache) device driver device driver device driver Overview (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu

  24. FS: Information in disk, non-volatile, to store and organize files according to a predetermined format (ie: ext2, FAT, NTFS, …) • Different FS offer different options, attributes, security levels, … but it is independent of the user interface and VFS implementation • VFS: Information in memory, part of the OS, to access and manage the files at run-time (from a process) • Contains a copy of the information in disk (metadata) to speed up the access times Virtual File System (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu So …

  25. Different devices and/or partitions can be accessed in a system • Devices: hard disks, pen drives, network units • Partitions: Set of consecutive sectors in disk (metadata and data blocks), managed as independent logic entity • Each device and/or partition has its own directory structure and FS implementation • In order to access them, they have to be mounted in the main directory tree • mount –t ext2 /dev/hda1 /home / Virtual File System etc dev usr home mnt bin lib usr1 aaa usr2 bbb / f1.c f1.o f1 dir1 dir3 dir2 aaa bbb (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Mounting FS

  26. Channels Table done! • Defines the files that can be accessed by a process • Open Files Table done! • Represents the opened files in the system • Inodes Table done! • Contains the used files, a “copy” of the inode object • And other run-time information, such as #refs • Actually, inodes in memory (IT) are called vnodes, and are a superset to represent the inodes info + other FS related info • Buffer cache  new! • Contains a copy of data blocks (for any device) • Used to speed access times and facilitate sharing • Also, dentry cache with a copy of directory entries Virtual File System (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Internal VFS data structures

  27. The opensyscall receives a file name (path) as a parameter and, therefore, it has to access the VFS • Sequence of inodes and directory data blocks • Until the last inode is reached(and added to the IT, if first time) • No data blocks are accessed! • 1 OFT entry is added • 1 CT entry is added • In case of caches, most of these disk access may be avoided or, later, reused Virtual File System (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu open and the VFS (1)

  28. If the opened file is new (create), a new line in the directory data block will be added • Create new indode (and write to the disk) • Modify directory data block • Modify directory inode (data, size) • And modify super block (list of free inodes) Virtual File System (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu open and the VFS (2)

  29. #0 / • Compute number of disk accesses to execute: • open(“/A/file1”, O_RDONLY); • open(“/A/file2”, O_RDONLY); • Assuming: • 1 inode = 1 block • 1 directory = 1 block • No caches of any type are used #4 #2 A B #3 #5 #5 file3 file1 file2 link to /B/file3 Virtual File System Example (3) (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu

  30. The readsyscall reads data blocks from disk, as long as they are not in the buffer cache • 1 or more, depending on size and offset • Also, depends on whether blocks are pointed by direct or indirect indexes in the inode Virtual File System (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu read and the VFS

  31. The writesyscall writes data blocks to the buffer cache (if present) • Later (periodically), data blocks from the buffer cache are written back to the disk • Assuming N blocks have to be written (depending on size and offset), special attention has to be paid to the first and last • If initial offset is not block start, then this data block has to be read before writing • If final offset is not block end, then this data block has to be read before writing • All other data blocks are written directly • Also, depends on whether blocks are pointed by direct or indirect indexes in the inode Virtual File System (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu write and the VFS

  32. Regular file • Decrements #refs and if zero removes inode + data blocks • Removes directory entry for this file • Directory • Some VFS check if directory is empty; otherwise remove recursively all files included in it • Decrements #refs and if zero removes inode + data block • Removes directory entry for this file • Soft link • Decrements #refs and if zero removes inode + data blocks • Does not remove the file pointed by this link • Removes directory entry for this file • Other special files, just remove the inode Virtual File System (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu File deletion in the VFS

  33. The presence of links in a FS turns the directory tree into a directory graph • If the graph is cyclic, the OS has to control infinite loops during file access, backup, … • Different OS strategies to manage this • Cycles with soft-links are easy to manage. For instance, the backup process does not follow any soft-link • Cycles with hard-links are really difficult to manage, so • Deny hard links if they cause a cycle • Implement some type of mechanism to detect cycles Virtual File System (c) 2013, Prof. Jordi Garcia | mailto:jordig@ac.upc.edu Last considerations

More Related