1 / 58

Lecture 9 File Systems and Linux Virtual File System (Homework#4 Task 1 included at slide no.16)

Learn about files and file systems in the context of Linux, including structuring, access, protection, and implementation. Explore disk organization and in-memory file system structures. Discover various file access methods and operations supported in Linux.

cgloria
Download Presentation

Lecture 9 File Systems and Linux Virtual File System (Homework#4 Task 1 included at slide no.16)

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. Nov. 13, 2015 Kyu Ho Park Lecture 9 File Systems andLinux Virtual File System(Homework#4 Task 1 included at slide no.16)

  2. Files • File: a logical unit of information created by process. Files are managed by the OS. • How they are structured, named, accessed, used,protected, implemented, etc. • File System: The part of the OS dealing with files is known as the file system.

  3. Disk • Disk : It is considered as a linear sequence of fixed-size blocks and supporting two operations: • Issues to be solved: • How do you find information? • How do you keep one user from reading another user’s data? • How do you know which blocks are free?

  4. File Systems • How the file system can be looked to the user; • Define a file and its attributes, the operations allowed on a file, and the directory structure for organizing a file. • Algorithms and data structures to map the logical file system to the physical disk.

  5. File System Overview[ On Disk] • Boot block: It contains information needed by the system to boot an operating system. • Volume control block: It contains volume( or partition) details, such as the number of blocks in the partition, size of blocks, free-block count and free-block pointers, free FCB count and FCB pointers. In UNIX, it is called a superblock. 5

  6. File System Overview • A directory structure per file system: In UNIX, it includes file names and associated inode numbers. • A per-file FCB: In UNIX, it is called i-node 6

  7. In-memory • An in-memory mount table: It contains information about each mounted volume. • An in-memory directory-structure cache: It holds the directory information of recently accessed directories. • System-wide open-file table: It contains a copy of the FCB of each open file. • Per-process open-file table: It contains a pointer to the appropriate entry in the system-wide open-file table. 7

  8. In-Memory File System Structures index read (index) data blocks per-process open-file table system-wide open-file table file-control block user space kernel memory secondary storage

  9. Page Cache • A page cache caches pages rather than disk blocks using virtual memory techniques • Memory-mapped I/O uses a page cache • Routine I/O through the file system uses the buffer (disk) cache • This leads to the following figure

  10. I/O Without a Unified Buffer Cache memory-mapped I/O I/O using read( ) and write( ) page cache buffer cache file system

  11. Unified Buffer Cache • A unified buffer cache uses the same page cache to cache both memory-mapped pages and ordinary file system I/O

  12. I/O Using a Unified Buffer Cache memory-mapped I/O I/O using read( ) and write( ) buffer cache file system

  13. File Structure 1 Record 1 Byte • Three kinds of files • byte sequence • record sequence • tree Pig Pig Ant Fox Cat Cow Dog Goat Lion Owl Pony Rat Worm Hen Ibis Lamb (c) (b) (a)

  14. File Access • Sequential access • read all bytes/records from the beginning • cannot jump around, could rewind or back up • convenient when medium was mag tape • Random access • bytes/records read in any order • essential for data base systems • read can be … • move file marker (seek), then read or … • read and then move file marker

  15. 1.open, create, close, read, write, lseek, unlink, remove 2.umask, access, chmod, fchmod, chown,fchown, link,rename, symlink, readlink,stat, fstat 3.mkdir, rmdir,opendir,closedir readdir,chdir,getcwd File Operations

  16. Homework#4 Task1 • Explain the red colored functions of file operations shown in the previous slide and make your own program using each red colored functions. • Submit the execution results of each functions capturing the screen of your computer. • Due: Nov. 17, 23:59. • Submit your report to Joo Kyung Ro <eu8198@kaist.ac.kr>.

  17. Root directory Directories:Single-Level Directory Systems • A single level directory system • contains 4 files • owned by 3 different people, A, B, and C A B C C

  18. Two-level Directory Systems Root directory Letters indicate owners of the directories and files User directory A B C A A B C C C Files

  19. Hierarchical Directory Systems A hierarchical directory system Root directory User directory B A C B B B A C C B C C User subdirectories C C User file C C

  20. Path Names bin Root directory etc lib user A UNIX directory tree tmp etc lib usr tmp bin ast jim lib ast lib jim /user/jim dict.

  21. File System Implementation A possible file system layout Entire disk Disk Partition Partition table MBR Boot block Super block Free space mgmt I-nodes Root dir Files and directories

  22. File System Layout • Sector 0 : MBR to boot the computer • Partition table :Starting and ending address of each partition. • When the computer is booted, the BIOS reads in and executes the MBR. • The first work of the MBR is locating the active partition: reads in its first block(boot block) and execute it. • The program in the boot block loads OS contained in that partition.

  23. Bootloader • CPU initialization • Registers, Memory, Clock seting • Copy bootloader code to RAM Area Bootloader Code p Power ON ROM (Flash) I/O address area copy Bootloader Kernel Start RAM Area

  24. Implementing Files:Contiguous Allocation (a) Contiguous allocation of disk space for 7 files (b) State of the disk after files D and E have been removed

  25. Linked List Allocation Storing a file as a linked list of disk blocks File A 0 File block 1 File block 3 File block 4 Physical block 4 2 7 10 12 File B 0 File block 1 File block 3 Physical block 6 11 3 14 File block 0 File block 2 File block 2 File block 0

  26. File Allocation Table(FAT) Linked list allocation using a file allocation table in RAM Physical block File A starts here File B starts here Unused block

  27. i-node An example i-node

  28. Implementing Directories • When a file is opened , the OS uses the path name supplied by the user to locate the directory entry. • The directory entry provides the information needed to find the disk blocks. • Depending on the systems, the information may be the disk address of the entire files(contiguous allocation), the number of the first block, or the number of the i-node.

  29. Directory • The main function of the directory system is to map the ASCII name of the file onto the information needed to locate the data. • Attribute of a file: • file’s owner, creation time, modified time----

  30. Implementing Directories (1) (a) A simple directory fixed size entries disk addresses and attributes in directory entry (b) Directory in which each entry just refers to an i-node (a) (b) Data structure containing the attributes

  31. Implementing Directories (2) • Two ways of handling long file names in directory • (a) In-line • (b) In a heap

  32. Shared Files File system containing a shared file Root directory B A C B B B A C C B C C ? C C C Shared file

  33. Hard Link and Soft Link • Hard link • A file name included in a directory is called a file hard link (or simply link). • The same file may have several links, so it may have several file names. • ln file1 file2 • Limitations: • Not possible to create hard links for directories. • Links can be created only among files included in the same file system.

  34. Hard Link and Soft Link • soft link ( also called symbolic link) • To overcome the limitations of the hard link. • Symbolic links are short files that contain an abitrary pathname of another file. • ln –s file1 file2

  35. File Types • Regular file • Directory • Symbolic link • Block device file • Character device file • Pipe and names pipe(FIFO) • Socket

  36. Disk Block Size and Disk I/O Speed • Dark line (left hand scale) gives data rate of a disk • Dotted line (right hand scale) gives disk space efficiency • All files 2KB Block size

  37. Linux File System

  38. Filesystem Layout /dev/hda system /dev/hda1 /dev/hda3 /dev/hda2 Ext2

  39. ext2 inode G U r x S w w r r x x Type(4bit) w S_IFSOCK S_IFLNK S_IFREG S_IFBLK S_IFDIR S_IFCHR S_IFIFO ext2_inode 12 direct block 0 0 0 0 0 0 3 indirect block 1023 1023 1023 1023 1023 1023

  40. Size of a file • size of a block : 4KB • Direct Blocks : 12 x 4K=48K • Indirect Blocks : 1 x 1K x 4K=4M • Double Indirect Blocks: 1 x 1K x 1K x 4K =4G • Triple Indirect Blocks : 1 x 1K x 1K x 1K x4K= 4T Maximum size of a file = 4,004,004,048,000Bytes

  41. inode , file and directory inode5 disk block10 i_mode time … 10 … / inode15 i_mode time … 11 12 13 … my_dir my_file.c inode25 i_mode time … 21 …

  42. Virtual File Systems • Virtual File Systems (VFS) provide an object-oriented way of implementing file systems. • VFS allows the same system call interface (the API) to be used for different types of file systems. • The API is to the VFS interface, rather than any specific type of file system.

  43. VFS

  44. common file model Object: a software construct that defines both a data structure and the methods that operate on it It consists of the 4 object types: • superblock object • information about a mounted filesystem. • inode object • information about a specific file • file objects • information about the interaction between an open file and a process • dentry object • information about the linking of a directory entry with the corresponding file.

  45. VFS objects and processes

  46. Without Virtual Layer User App …. fat_file_write(test.c,…); ext2_create(my_file.c,…); …. User level Kernel level …. generic_file_read, fat_file_write, fat_truncat, generic_read_dir, … …. generic_file_read, generic_file_write, ext2_truncate, ext2_readdir, ext2_create, … my_file.c test.c msdos Ext 2 /dev/hda2 /dev/hda3 Disk

  47. Virtual File System User App …. write(test.c,…); create(my_file.c,…); …. User level Kernel level my_file.c test.c …. generic_file_read, fat_file_write, fat_truncat, generic_read_dir, … …. generic_file_read, generic_file_write, ext2_truncate, ext2_readdir, ext2_create, … msdos Ext 2 /dev/hda2 /dev/hda3 Disk

  48. operations in VFS /*fs/open.c*/ sys_open() System call layer • - get_unused_fd_flags() • do_file_open() • fd_install(fd, f) /*fs/namei.c*/ file_open() • struct file initialize • call file ->f_op->open() VFS layer Specific File layer chrdev_open() sock_no_open() blkdev_open() fifo_open()

  49. task_struct and VFS Objects task_struct file_struct/*include/linux/fdtable.h*/ … files fs … file/*include/linux/fs.h*/ fd[0] … f_dentry f_pos f_op … fd[1] dentry/*include/linux/scache.h*/ fd[2] … d_inode d_op … fd[3] inode/*include/linux/fs.h*/ … i_sb i_op … super_block/*include/linux/fs.h*/ … s_bdev s_op … /dev/hda2 ext 2 Disk

  50. New Trend:Storage Class Memory

More Related