28
 Linux file system l Linux supports large number of file systems. The range of file systems supported by linux is made possible by unified interface to linux kernel. This is Virtual File system. l Virtual file system supplies the applications with the system calls for file management, maintains internal structures and passes tasks on to the appropriate actual file system. l Linux supports the following filesystem types: l Extended Filesystem - ext (Linux) l Second Extended Filesystem - ext2 (Linux) l Third Extended Filesystem - ext3 (Linux, journalling)

Mca Fact About Linux

Embed Size (px)

Citation preview

Page 1: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 1/28

 

Linux file system

l Linux supports large number of file systems. The range

of file systems supported by linux is made possible byunified interface to linux kernel. This is Virtual File

system.

l Virtual file system supplies the applications with the

system calls for file management, maintains internal

structures and passes tasks on to the appropriate actual

file system.

l Linux supports the following filesystem types:

l  Extended Filesystem - ext (Linux)

l Second Extended Filesystem - ext2 (Linux)

l Third Extended Filesystem - ext3 (Linux, journalling)

Page 2: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 2/28

 

Linux file system

l High Performance Filesystem - hpfs

l (OS/2) IS0 9660 Filesystem - iso9660

l (CD-ROM) Minix Filesystem - Minix (Minix. first

filesystem used by Linux)

l FAT 16 bit - msdos (DOS, Windows) file allocationtable

l Virtual Fat Filesystem - vfat (DOS, Windows)

Supports long filenamesl  Network Filesystem - NFS

l  Novell Filesystem - NCPFS (Novell) System V

Filesystem - sysv (System V Unix variants))

Page 3: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 3/28

 

Virtual File system

ext2

Buffer Cache

msdos minix proc

File system

Device Drivers

Process

1

Process

2

Process

n User mode

Systemmode

Layers in file system

Page 4: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 4/28

 

Basic principlesl Two important factors for structuring of file system

are - speed of access of data and facility for randomaccess.

l Random access made possible by block orienteddevices, which are divided into no. of equal sized

 blocks. File system itself must be capable of ensuringunique allocation of the data to hardware blocks.

l Data is stored in hierarchical file system in linuxcontaining files of different types.

l The information required for management is keptstrictly apart from the data and collected in separateinode structure for each file. The informationcontained includes access times, access rights and

allocation of data blocks to physical media.

Page 5: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 5/28

 

l Inode contains a few

 block no.s for efficient

access to small files.Indirect blocks provide

access to larger files.

Every file is represented by just one inode.within

a file system, each node

has a unique no. and file

itself can be accessedusing this number.

Access rights

Owner 

Size

Times

……

Direct references to data blocks

Indirect block 

Two step indirect reference

Three step indirect reference

Page 6: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 6/28

 

l Directories allow file system to be given a hierarchicalstructure. They contain pairs consisting of a file nameand its inode number.

l Each file system starts with a boot block. This block is

reserved for the code required to boot the operatingsystem.

l All information which is necessary for managing the filesystem is held in superblock.

l This is followed by no. of inode blocks containing theinode structures for the file system.

l Remaining blocks for device provide space for data. Theycontain ordinary file along with directory entries &

indirect blocks.

0Boot block  1Super block  2.. Inode blocks Data blocks

Page 7: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 7/28

 

File system representation in kernell VFS calls the file system specific functions for the

various implementations to fill up the structures of thefile system.

l Before a file can be accessed, the file system

containing the file must be mounted. This can be done

using system call mount or the function mount_root( ).

l The mount_root( ) function takes care of mounting the

first file system. It is called by system call setup after 

all file system implementations permanently includedin the kernel have been registered. This system call is

necessary because access to kernel structures is not

allowed from user mode.

Page 8: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 8/28

 

File system representation in kernell Every mounted system is represented by super_block 

structure. The superblock is initialized by the functionread_super( ) in the VFS. When called it contains:-

A superblock structure, a character string containingfurther mount options for file systems and a silent flagindicating whether unsuccessful mounting should bereported. Super block contains information on entirefile system such as block size, access rights and timeof last change.

Another task performed by read_super( ) involvesmaking file system’s root inode available and enteringit in superblock.this can be done using functions of VFS such as iget( ) functions.

Page 9: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 9/28

 

Superblock operationsl Superblock structures provides functions for accessing

the file system. the function transfer the specific

representation of the superblock and inode on the datamedia to their general form in memory and vice versa.This layer therefore completely hides the actualrepresentations.

Page 10: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 10/28

 

The Proc file system

l Proc file system provides information on the current

status of kernel and running processes in a portableway. This explains how VFS interacts with a file

system implementation.

l Each process in the system which is currently running

is assigned a directory /proc/pid. This directory

contains files holding information on certain

characteristics of the process.

l When proc file system is mounted the VFS functionread_super( ) is called by do_mount( ), and in turn

calls the function proc_read_super( ) for proc file

system in the file_systems list.

Page 11: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 11/28

 

The Proc file system

l The following call to iget( ) then uses this structure to

generate the inode for the proc root directory, which isentered in the superblock. The parse_options( )

function then processes the mount options

data(uid,gid etc.) that have been provided and sets the

owner of the root inode.l When this file system is accessed, relevant data are

only generated when they are needed. Accessing is

always done by accessing the root inode of the file

system. First access is made by calling iget( ). After 

this, action depends upon the type of inode.

Page 12: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 12/28

 

The Ext2 file systeml The design of ext2 file system is influenced by BSD’S

fast file system.l A partition is divided into a number of block groups,

with each block group holding a copy of superblock 

and inode and data blocks.

Boot block 

Block group 0

 block group 1

…. block  group n

Super  block 

Groupdescriptors

Block bitmap Inode bitmap

Inodetable

Data blocks

Page 13: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 13/28

 

The Ext2 file system

l This keeps data blocks closer to their inodes and file

inodes closer to their directory node. This reduces positioning time to minimum, thereby speeding upaccess to data. Every group contains a superblock along with information on all the block groups,allowing file system to be restored in emergency.

l Superblock contains control information on the filesystem such as number of inodes and blocks. Block size used is not held directly.

l Super block includes information on the number of inodes and blocks per block group along with the timesof last mount operation. It also holds information on behaviour of the file system in event of errors.

Page 14: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 14/28

 

The Ext2 file systemThe EXT2 Superblock 

l The Superblock contains a description of the basic size andshape of this file system. The information within it allows thefile system manager to use and maintain the file system.Usually only the Superblock in Block Group 0 is read whenthe file system is mounted but each Block Group contains aduplicate copy in case of file system corruption.

q The Ext2 superblock is located 1024 bytes from the startof the file system and is 1024 bytes in size. ( The first twosectors are used to store boot code if necessary)

q Back up copies are typically stored in the first file data block of each block group

q It contains basic information of the file system, such as the

 block size, the total number of blocks, etc.

Page 15: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 15/28

 

Amongst other information it holds the:l  Magic Number 

q This allows the mounting software to check that this is indeedthe Superblock for an EXT2 file system. For the currentversion of EXT2 this is 0xEF53.

l  Revision Level q The major and minor revision levels allow the mounting code

to determine whether or not this file system supports features

that are only available in particular revisions of the filesystem. There are also feature compatibility fields which helpthe mounting code to determine which new features can safely

 be used on this file system,

The Ext2 file system (the EXT2 Superblock)

Page 16: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 16/28

 

The Ext2 file system (the EXT2 Superblock)

l Mount Count and Maximum Mount Count q Together these allow the system to determine if the file system

should be fully checked. The mount count is incremented each

time the file system is mounted and when it equals the maximum

mount count the warning message ``maximal mount count

reached, running e2fsck is recommended'' is displayed,

l Block Group Number q The Block Group number that holds this copy of the Superblock,

l Block Size q The size of the block for this file system in bytes, for example

1024 bytes,

Page 17: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 17/28

 

The Ext2 file system (the EXT2 Superblock)

l Blocks per Group q The number of blocks in a group. Like the block size this

is fixed when the file system is created,

l Free Blocks q The number of free blocks in the file system,

l Free Inodes q The number of free Inodes in the file system,

l First Inode q This is the inode number of the first inode in the file

system. The first inode in an EXT2 root file system would be the directory entry for the '/' directory.

Page 18: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 18/28

 

The Ext2 file system (Group Descriptor )

l Block Group Descriptor Table:q It contains a group descriptor data structure for every block 

group.

q The group descriptor stores the address of block bitmap

and inode bitmap for the block group.

l Bitmaps:q The block bitmap manages the allocation status of the

 blocks in the group.

q The inode bitmap manages the allocation status of the

inodes in the group.

Page 19: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 19/28

 

The Ext2 file system (Group Descriptor )

Group Descripter table

Super 

Block

Block

DescTable

Block

Bitmap

Block

Bitmap

Block

Bitmap

Group 0

Group 1

Group n

Inode

Bitmap

Inode

Table

Inode

Bitmap

Inode

Table

Inode

Bitmap

Inode

Table

Page 20: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 20/28

 

The Ext2 file system(Ext2 Inode)

l Inode Tables:q Inode table contains the inodes that describes the files in the

group

l Inodes:q Each inode corresponds to one file, and it stores file’s primary

metadata, such as file’s size, ownership, and temporal

information.

q Inode is typically 128 bytes in size and is allocated to eachfile and directory

Page 21: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 21/28

 

The Ext2 file system(Ext2 Inode)

Page 22: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 22/28

Page 23: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 23/28

 

The Ext2 file system(Ext2 Inode)

l Owner Information q The user and group identifiers of the owners of this

file or directory. This allows the file system to

correctly allow the right sort of accesses,

l Size 

q The size of the file in bytes,

l Timestamps 

q The time that the inode was created and the last time

that it was modified,

Page 24: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 24/28

 

The Ext2 file system(Ext2 Inode)l Datablocks 

q Pointers to the blocks that contain the data that this inode is describing.The first twelve are pointers to the physical blocks containing the datadescribed by this inode and the last three pointers contain more and morelevels of indirection. For example, the double indirect blocks pointer  points at a block of pointers to blocks of pointers to data blocks. Thismeans that files less than or equal to twelve data blocks in length are

more quickly accessed than larger files.l You should note that EXT2 inodes can describe special device

files. These are not real files but handles that programs can use toaccess devices. All of the device files in /dev are there to allow

 programs to access Linux's devices. For example the mount program takes as an argument the device file that it wishes tomount.

Page 25: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 25/28

 

Ext3 File system(Ext2+Journaling)l A file system journaling records updates to the file

system can be recovered after a crash.

l There are two modes of journaling:

q Only metadata updates are recorded

q All updates are recordedl Journaling in Ext3 is done at block level

l The first block in the journal is journal superblock, and

it contains the first logging data address and itssequence number.

Page 26: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 26/28

 

Journaling

l Updates are done in transactions, and each transactionhas a sequence number.

l Each transaction starts with a descriptor block that

contains the transaction sequence number and a list of what blocks are being updated.

l Following the descriptor block are the updated blocks.

l When the updates have been written to disk, a commit block is written with the same sequence number.

Page 27: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 27/28

Page 28: Mca Fact About Linux

8/14/2019 Mca Fact About Linux

http://slidepdf.com/reader/full/mca-fact-about-linux 28/28

 

Conclusion

l Ext2/3 separates the file system into several

 block groups, and each group has its own

metadata blocks.l Inode is the primary metadata structure for a

file in Ext2.

l Ext3 adds transaction-based journalingmechanism.