SlideShare a Scribd company logo
1 of 47
1
INTERNAL REPRESENTATION
OF FILES
Prepared by,
A. V. Surve
2
Contents
 Inodes
 Structure of a regular file
 Directories
 Conversion of a path name to an inode
 Super block
 Inode assignment to a new file
 Allocation of Disk Blocks.
 Other File Types
3
Lower Level File system Algorithms
namei
alloc free ialloc ifree
iget iput bmap
buffer allocation algorithms
getblk brelse bread breada bwrite
4
Inodes
 Contains the information necessary for a process to
access a file.
 Exists in a static form on disk.
 The kernel reads them into an in-core inode to
manipulate them.
 2 Types:
 Disk Inode
 In-core Inode
5
Disk Inodes (1/2)
Consists of following fields:
 File Owner identifier
 Individual owner
 “Group” owner
 Set of users who have access rights to a file
 File Type
 File

Regular, directory, character or block special
 FIFO (pipe)
 File Access permissions
 To protect by three classes(owner, group, other)
 Read, write, execute
6
Disk Inodes (2/2)
 File Access times
 Last modified time, Last access time, Last modification time of Inode
 Number of links to the file
 Represents no. of names the file has in directory hierarchy.
 Table of contents for the disk address of data in a file
 Kernel saves the data in discontiguous disk blocks
 The Inodes identifies the disk blocks that contain file’s data.
 File Size
 The inode does not specify the path name(s) that access the
file.
7
Disk Inodes - Sample
 Distinction between writing the contents of an inode to disk
and writing the contents of a file to disk
8
in-core inode
 Contents in addition to the fields of the disk inode
 Status of the in-core inode
 the inode is locked,
 a process is waiting for the inode to become unlocked,
 the in-core representation of the inode differs from the disk copy as a
result of a change to the data in the inode,
 the in-core representation of the file differs from the disk copy as a result
of a change to the file data,
 The file is a mount point
9
in-core inode
 Logical Device Number of the file system that contains file.
 Inode Number
 Pointers to other in-core inodes
 Reference Count
 Number of instances of the active file..
 The kernel links inodes on hash queues and on a free list in
the same way that it links buffers on buffer hash queues and
on the buffer free list.
 A hash queue is identified according to the inode's logical
device number and inode number.
10
Difference between in-core inode
and buffer header
 In-core inode has In-core reference count.
 If count=0, Inode in inactive. (kernel can reallocate in-core
inode)
 If count = or >= 1, Inode is Active.
 Buffer header don’t have reference count.
 Buffer is locked when it is allocated.
 Buffer is unlocked; it will be in free list.
11
Accessing Inodes (IGET Algo.)
(1/4)
 Kernel
 Identifies particular inodes by their file system and inode number

Allocates in-core inodes
 Using algorithm iget
 Allocates an in-core copy of an inode
 Map the device number and inode number into a hash queue
 Search the queue for the inode
 If not find the inode, allocates one from the free list and locks it
 Read the disk copy of the newly accessed inode into the in-core copy
12
13
Accessing Inodes (2/4)
 Computation of logical disk block
block num = ((inode number –1)/number of
inodes per block) + start block of inode list
Where,
Block num=Disk block number
Start block of inode list=Beginning of Inode List.
Inode number= Inode number to be searched
14
Accessing Inodes (3/4)
 Read the block using the algorithm bread
 Computation of the byte offset of the inode in the
block
((inode number –1) modulo (number of inodes per
block)) * size of disk inode
Where,
Inode number= Inode number.
Size of disk inode = Size of disk inode
Example
 Find the block number and block offset of inode in
the block for following inode number:
 6895
 4258
 Assumptions:
1. Start Block of Inode List: 200
2. Disk Block size: 1024 bytes
3. Size of Disk Inode: 64 bytes
15
16
17
Accessing Inodes (4/4)
 Hold lock during execution of a system call for
possibly consistency
 Release it at the end of system call
 The lock is free between system calls
 To allow processes to share simultaneous access to a file
 The reference count remains set between system
calls
 To prevent the kernel from reallocating an active in-core
inode
18
Release Inodes (IPUT Algo.)
 Using algorithm iput
 decrements in-core reference count
 Write the inode to disk

Reference count is 0

The in-core copy differs from the disk copy
 Add the inode on the free list of inodes

For caching
19
20
Structure of a Regular File
 Table of contents in an inode
 Location of a file’s data on disk
 A set of disk block #

Each block on a disk is addressable by number
 Not contiguous file allocation strategy

Why ?

When a file expand or contract…

Fragmentations occur
21
Sample - Fragmentation
 File B was expanded
 Garbage collection – too high cost
File A File B File C
40 50 60 70
…. …….
File A Free File C
40 50 60 70
…. …….File B
85
22
Structure of a Regular File –
UNIX System V
13 entries in the inode table of contents
 10 Direct, 1 Single Indirect, 1 Double Indirect, 1 Triple Indirect Block
 Assume
 a logical block = 1K bytes
 a block number is addressable by a 32 bit (4 bytes) integer
 a block can hold up to 256 block numbers
 Byte Capacity of a File
10 direct blocks with 1K bytes each= 10K bytes
1 indirect block with 256 direct blocks= 1K*256 = 256K bytes
1 double indirect block with 256 indirect blocks = 256K*256= 64M bytes
1 triple indirect block with 256 double indirect blocks=64M*256= 16G bytes
23
Direct and Indirect Blocks in
Inode – UNIX System V
Inode Data Blocks
direct0
direct1
direct2
direct3
direct4
direct5
direct6
direct7
direct8
direct9
single indirect
double indirect
triple indirect
………..
24
Block Layout of a Sample File
and its Inode
4096
228
45423
0
0
11111
0
101
367
0
428
9156
824
331
3333
9156
331
33330 75
367
1 disk block = 1024 bytes
byte offset 9000, byte offset 350,000
816th
808th
25
Structure of a Regular File
 Processes
 access data in a file by byte offset
 view a file as a stream of bytes
 The kernel
 accesses the inode
 converts the logical file block into the appropriate disk block
26
27
Directories (1/2)
 A directory is a file
 Its data is a sequence of entries
 Contents of each entries

an inode number and the name of a file
 Path name is a null terminated character string divided by
slash (“/”)
 UNIX System V
 Maximum of component name : 14 characters
 Inode # : 2 bytes
 Size of a directory : 16 bytes
28
Directories (2/2)
Directory
layout
for
/etc
29
Conversion of a Path Name
to an Inode
 The initial access to a file is by its path name
 Open, chdir, link system calls
 The kernel works internally with inodes rather than
with path name
 Converting the path names to inodes
 Using algorithm namei

parse the path name one component at a time

convert each component into an inode

finally return the inode of the input path name
30
31
Sample-namei(/etc/passwd)
Encounters “/” and gets the system root inode
Current working inode = root
Permission check
Search root for a file – “etc”
Access data in the root directory block by block
Search each block one entry-”etc”
Finding
Release the inode for root(iput)
Allocate the inode for etc(iget) by inode # found
Permission check for “etc”
Search “etc” block by block for a directory struct. entry for “passwd”
Finding
Relase the the inode for “etc”
Allocate the inode for “passwd”
Return that inode
32
Super Block
 Contents
 the size of the file system.
 the number of free blocks in the file system.
 a list of free blocks available on the file system.
 the index of the next free block in the free block list,
 the size of the inode list.
 the number of free inodes in the file system.
 a list of free inodes in the file system.
 the index of the next free inode in the free inode list.
 lock fields for the free block and free inode lists.
 a flag indicating that the super block has been modified.
33
Inode Assignment to A New File
(1/4)
 a known inode
 Algorithm iget : to allocate
 Algorithm namei : to determine inode #
 Algorithm ialloc
 To assign a disk inode to a newly created file
 Super block contains an array
 To improve performance of searching a free inode
 To cache the numbers of free inodes
34
35
Inode Assignment to a New File
(2/4)
free inodes 83 48 empty
18 19 20 array1
Super Block Free Inode List
index
free inodes 83 empty
18 19 20 array2
Super Block Free Inode List
index
Assigning Free Inode from Middle of List
36
Inode Assignment to a New File
(3/4)
index
Assigning Free Inode – Super Block List Empty
470 empty
array1
Super Block Free Inode List
index
0
535 free inodes 476 475 471
array2Super Block Free Inode List
0
48 49 50
remembered
inode
37
38
Inode Assignment to a New File
(4/4)
535 476 475 471
free inodes
remembered inode
Original Super Block List of Free Inodes
index
Free Inode 499
499 476 475 471
free inodes
remembered inode index
Free Inode 601
499 476 475 471
free inodes
remembered inode index
39
Race Condition
 A Race Condition Scenario in Assigning Inodes
 three processes A, B, and C are acting in time sequence
1. The kernel, acting on behalf of process A, assigns
inode I but goes to sleep before it copies the disk
inode into the in-core copy.
2. While process A is asleep, process B attempts to
assign a new inode but free inode list is empty, and
attempts assign free inode at an inode number lower
than that of the inode that A is assigning.
3. Process C later requests an inode and happens to pick
inode I from the super block free list
40
Race Condition in Assigning
Inodes (1/2)
41
Race Condition in Assigning Inodes
(2/2)
time
…………………………………………….I
Empty
………………………….
free inodes
free inodes
free inodes L
J I
J I K
…………………………………………………………………...
………………………………………………….…………….
……………………………………………………...
(a)
(b)
(c)
(d)
(e)
42
Allocation of Disk Blocks
 When a process writes data to a file, the kernel
must allocate disk blocks
 An array in the file system super block
 To cache the numbers of free disk block in the file
system
 Mkfs

Organize the data blocks of a file system in a linked list
 Each link is a disk block

The block contains an array of free disk block numbers

One array entry is the number of the next block of the linked
list
43
Linked list of free disk block number
109 109 103 100 …………………………...
109
211 208 205 202 ………………… 112
211
310 307 304 301 ………………… 214
310
409 406 403 400 ………………… 313
44
45
Requesting and Freeing Disk
Blocks (1/2)
109 …………………………………………………………
211 208 205 202 …………………………….. 112
109 949 …………………………………………………..
211 208 205 202 ………………………………. 112
super block list
original configuration
109
109
After freeing block number 949
46
Requesting and Freeing Disk
Blocks (2/2)
211 208 205 202 ……………………………… 112
344 341 338 335 ………………………………. 243
After assigning block number(109)
replenish (fill up again) super block free list
211
109 ………………………………………………………..
211 208 205 202 ……………………………….
112
109
After assigning block number(949)
47
Other File Types
 Pipe
 fifo (first-in-first-out)
 its data is transient
 Once data is read from a pipe, it cannot be read again

The data is read in the order that it was written to the pipe, no deviation from
that order
 using only direct block
 Special File (including block device, character device)
 Specifying devices

The inode does not reference any data
 The inode contains the major and minor device number
 major number

a device type such as terminal or disk
 minor number

the unit number of the device

More Related Content

What's hot

file system in operating system
file system in operating systemfile system in operating system
file system in operating systemtittuajay
 
Computer organization memory
Computer organization memoryComputer organization memory
Computer organization memoryDeepak John
 
Unit 4 ca-input-output
Unit 4 ca-input-outputUnit 4 ca-input-output
Unit 4 ca-input-outputBBDITM LUCKNOW
 
Query processing and optimization (updated)
Query processing and optimization (updated)Query processing and optimization (updated)
Query processing and optimization (updated)Ravinder Kamboj
 
Processor Organization and Architecture
Processor Organization and ArchitectureProcessor Organization and Architecture
Processor Organization and ArchitectureVinit Raut
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory managementrprajat007
 
database recovery techniques
database recovery techniques database recovery techniques
database recovery techniques Kalhan Liyanage
 
Design issues of dos
Design issues of dosDesign issues of dos
Design issues of dosvanamali_vanu
 
Pipelining and vector processing
Pipelining and vector processingPipelining and vector processing
Pipelining and vector processingKamal Acharya
 
Information storage and management
Information storage and managementInformation storage and management
Information storage and managementAkash Badone
 
Interconnection Network
Interconnection NetworkInterconnection Network
Interconnection NetworkHeman Pathak
 
CS8461 Operating System Lab Manual S.Selvi
CS8461 Operating System Lab Manual S.SelviCS8461 Operating System Lab Manual S.Selvi
CS8461 Operating System Lab Manual S.SelviSELVI SIVAPERUMAL
 
File organization 1
File organization 1File organization 1
File organization 1Rupali Rana
 
Distributed operating system
Distributed operating systemDistributed operating system
Distributed operating systemudaya khanal
 

What's hot (20)

file system in operating system
file system in operating systemfile system in operating system
file system in operating system
 
Computer organization memory
Computer organization memoryComputer organization memory
Computer organization memory
 
Unit 4 ca-input-output
Unit 4 ca-input-outputUnit 4 ca-input-output
Unit 4 ca-input-output
 
6.distributed shared memory
6.distributed shared memory6.distributed shared memory
6.distributed shared memory
 
Distributed Operating System_1
Distributed Operating System_1Distributed Operating System_1
Distributed Operating System_1
 
Query processing and optimization (updated)
Query processing and optimization (updated)Query processing and optimization (updated)
Query processing and optimization (updated)
 
Processor Organization and Architecture
Processor Organization and ArchitectureProcessor Organization and Architecture
Processor Organization and Architecture
 
Branch prediction
Branch predictionBranch prediction
Branch prediction
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
 
database recovery techniques
database recovery techniques database recovery techniques
database recovery techniques
 
Design issues of dos
Design issues of dosDesign issues of dos
Design issues of dos
 
Pipelining and vector processing
Pipelining and vector processingPipelining and vector processing
Pipelining and vector processing
 
Memory management
Memory managementMemory management
Memory management
 
DMA and DMA controller
DMA and DMA controllerDMA and DMA controller
DMA and DMA controller
 
Information storage and management
Information storage and managementInformation storage and management
Information storage and management
 
Interconnection Network
Interconnection NetworkInterconnection Network
Interconnection Network
 
File system structure
File system structureFile system structure
File system structure
 
CS8461 Operating System Lab Manual S.Selvi
CS8461 Operating System Lab Manual S.SelviCS8461 Operating System Lab Manual S.Selvi
CS8461 Operating System Lab Manual S.Selvi
 
File organization 1
File organization 1File organization 1
File organization 1
 
Distributed operating system
Distributed operating systemDistributed operating system
Distributed operating system
 

Similar to Internal representation of files ppt

Internal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya JyothiInternal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya JyothiSowmya Jyothi
 
Unix file systems 2 in unix internal systems
Unix file systems 2 in unix internal systems Unix file systems 2 in unix internal systems
Unix file systems 2 in unix internal systems senthilamul
 
AOS Lab 10: File system -- Inodes and beyond
AOS Lab 10: File system -- Inodes and beyondAOS Lab 10: File system -- Inodes and beyond
AOS Lab 10: File system -- Inodes and beyondZubair Nabi
 
Root file system
Root file systemRoot file system
Root file systemBindu U
 
Chapter 4 1
Chapter 4 1Chapter 4 1
Chapter 4 1lopjuan
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File SystemAdrian Huang
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh Naik
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsnullowaspmumbai
 
There are 4 part for the project and the question may be long to rea.docx
There are 4 part for the project and the question may be long to rea.docxThere are 4 part for the project and the question may be long to rea.docx
There are 4 part for the project and the question may be long to rea.docxsusannr
 
There are 4 parts for the project. The question may be long to read .docx
There are 4 parts for the project. The question may be long to read .docxThere are 4 parts for the project. The question may be long to read .docx
There are 4 parts for the project. The question may be long to read .docxsusannr
 
There are 4 parts for the project. The question may be long to r.docx
There are 4 parts for the project. The question may be long to r.docxThere are 4 parts for the project. The question may be long to r.docx
There are 4 parts for the project. The question may be long to r.docxsusannr
 
File management
File managementFile management
File managementMohd Arif
 
TLPI Chapter 14 File Systems
TLPI Chapter 14 File SystemsTLPI Chapter 14 File Systems
TLPI Chapter 14 File SystemsShu-Yu Fu
 
Unit 7
Unit 7Unit 7
Unit 7siddr
 
MODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptxMODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptxManasaPJ1
 
Ch 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashingCh 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashingZainab Almugbel
 
file management_part2_os_notes.ppt
file management_part2_os_notes.pptfile management_part2_os_notes.ppt
file management_part2_os_notes.pptHelalMirzad
 

Similar to Internal representation of files ppt (20)

Internal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya JyothiInternal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya Jyothi
 
Unix file systems 2 in unix internal systems
Unix file systems 2 in unix internal systems Unix file systems 2 in unix internal systems
Unix file systems 2 in unix internal systems
 
AOS Lab 10: File system -- Inodes and beyond
AOS Lab 10: File system -- Inodes and beyondAOS Lab 10: File system -- Inodes and beyond
AOS Lab 10: File system -- Inodes and beyond
 
osd - co1 session7.pptx
osd - co1 session7.pptxosd - co1 session7.pptx
osd - co1 session7.pptx
 
Ext2
Ext2Ext2
Ext2
 
Root file system
Root file systemRoot file system
Root file system
 
Chapter 4 1
Chapter 4 1Chapter 4 1
Chapter 4 1
 
Linux Kernel - Virtual File System
Linux Kernel - Virtual File SystemLinux Kernel - Virtual File System
Linux Kernel - Virtual File System
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internals
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internals
 
There are 4 part for the project and the question may be long to rea.docx
There are 4 part for the project and the question may be long to rea.docxThere are 4 part for the project and the question may be long to rea.docx
There are 4 part for the project and the question may be long to rea.docx
 
There are 4 parts for the project. The question may be long to read .docx
There are 4 parts for the project. The question may be long to read .docxThere are 4 parts for the project. The question may be long to read .docx
There are 4 parts for the project. The question may be long to read .docx
 
There are 4 parts for the project. The question may be long to r.docx
There are 4 parts for the project. The question may be long to r.docxThere are 4 parts for the project. The question may be long to r.docx
There are 4 parts for the project. The question may be long to r.docx
 
File management
File managementFile management
File management
 
TLPI Chapter 14 File Systems
TLPI Chapter 14 File SystemsTLPI Chapter 14 File Systems
TLPI Chapter 14 File Systems
 
Unit 7
Unit 7Unit 7
Unit 7
 
MODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptxMODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptx
 
Ch 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashingCh 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashing
 
Unix Administration
Unix AdministrationUnix Administration
Unix Administration
 
file management_part2_os_notes.ppt
file management_part2_os_notes.pptfile management_part2_os_notes.ppt
file management_part2_os_notes.ppt
 

Recently uploaded

The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

Internal representation of files ppt

  • 2. 2 Contents  Inodes  Structure of a regular file  Directories  Conversion of a path name to an inode  Super block  Inode assignment to a new file  Allocation of Disk Blocks.  Other File Types
  • 3. 3 Lower Level File system Algorithms namei alloc free ialloc ifree iget iput bmap buffer allocation algorithms getblk brelse bread breada bwrite
  • 4. 4 Inodes  Contains the information necessary for a process to access a file.  Exists in a static form on disk.  The kernel reads them into an in-core inode to manipulate them.  2 Types:  Disk Inode  In-core Inode
  • 5. 5 Disk Inodes (1/2) Consists of following fields:  File Owner identifier  Individual owner  “Group” owner  Set of users who have access rights to a file  File Type  File  Regular, directory, character or block special  FIFO (pipe)  File Access permissions  To protect by three classes(owner, group, other)  Read, write, execute
  • 6. 6 Disk Inodes (2/2)  File Access times  Last modified time, Last access time, Last modification time of Inode  Number of links to the file  Represents no. of names the file has in directory hierarchy.  Table of contents for the disk address of data in a file  Kernel saves the data in discontiguous disk blocks  The Inodes identifies the disk blocks that contain file’s data.  File Size  The inode does not specify the path name(s) that access the file.
  • 7. 7 Disk Inodes - Sample  Distinction between writing the contents of an inode to disk and writing the contents of a file to disk
  • 8. 8 in-core inode  Contents in addition to the fields of the disk inode  Status of the in-core inode  the inode is locked,  a process is waiting for the inode to become unlocked,  the in-core representation of the inode differs from the disk copy as a result of a change to the data in the inode,  the in-core representation of the file differs from the disk copy as a result of a change to the file data,  The file is a mount point
  • 9. 9 in-core inode  Logical Device Number of the file system that contains file.  Inode Number  Pointers to other in-core inodes  Reference Count  Number of instances of the active file..  The kernel links inodes on hash queues and on a free list in the same way that it links buffers on buffer hash queues and on the buffer free list.  A hash queue is identified according to the inode's logical device number and inode number.
  • 10. 10 Difference between in-core inode and buffer header  In-core inode has In-core reference count.  If count=0, Inode in inactive. (kernel can reallocate in-core inode)  If count = or >= 1, Inode is Active.  Buffer header don’t have reference count.  Buffer is locked when it is allocated.  Buffer is unlocked; it will be in free list.
  • 11. 11 Accessing Inodes (IGET Algo.) (1/4)  Kernel  Identifies particular inodes by their file system and inode number  Allocates in-core inodes  Using algorithm iget  Allocates an in-core copy of an inode  Map the device number and inode number into a hash queue  Search the queue for the inode  If not find the inode, allocates one from the free list and locks it  Read the disk copy of the newly accessed inode into the in-core copy
  • 12. 12
  • 13. 13 Accessing Inodes (2/4)  Computation of logical disk block block num = ((inode number –1)/number of inodes per block) + start block of inode list Where, Block num=Disk block number Start block of inode list=Beginning of Inode List. Inode number= Inode number to be searched
  • 14. 14 Accessing Inodes (3/4)  Read the block using the algorithm bread  Computation of the byte offset of the inode in the block ((inode number –1) modulo (number of inodes per block)) * size of disk inode Where, Inode number= Inode number. Size of disk inode = Size of disk inode
  • 15. Example  Find the block number and block offset of inode in the block for following inode number:  6895  4258  Assumptions: 1. Start Block of Inode List: 200 2. Disk Block size: 1024 bytes 3. Size of Disk Inode: 64 bytes 15
  • 16. 16
  • 17. 17 Accessing Inodes (4/4)  Hold lock during execution of a system call for possibly consistency  Release it at the end of system call  The lock is free between system calls  To allow processes to share simultaneous access to a file  The reference count remains set between system calls  To prevent the kernel from reallocating an active in-core inode
  • 18. 18 Release Inodes (IPUT Algo.)  Using algorithm iput  decrements in-core reference count  Write the inode to disk  Reference count is 0  The in-core copy differs from the disk copy  Add the inode on the free list of inodes  For caching
  • 19. 19
  • 20. 20 Structure of a Regular File  Table of contents in an inode  Location of a file’s data on disk  A set of disk block #  Each block on a disk is addressable by number  Not contiguous file allocation strategy  Why ?  When a file expand or contract…  Fragmentations occur
  • 21. 21 Sample - Fragmentation  File B was expanded  Garbage collection – too high cost File A File B File C 40 50 60 70 …. ……. File A Free File C 40 50 60 70 …. …….File B 85
  • 22. 22 Structure of a Regular File – UNIX System V 13 entries in the inode table of contents  10 Direct, 1 Single Indirect, 1 Double Indirect, 1 Triple Indirect Block  Assume  a logical block = 1K bytes  a block number is addressable by a 32 bit (4 bytes) integer  a block can hold up to 256 block numbers  Byte Capacity of a File 10 direct blocks with 1K bytes each= 10K bytes 1 indirect block with 256 direct blocks= 1K*256 = 256K bytes 1 double indirect block with 256 indirect blocks = 256K*256= 64M bytes 1 triple indirect block with 256 double indirect blocks=64M*256= 16G bytes
  • 23. 23 Direct and Indirect Blocks in Inode – UNIX System V Inode Data Blocks direct0 direct1 direct2 direct3 direct4 direct5 direct6 direct7 direct8 direct9 single indirect double indirect triple indirect ………..
  • 24. 24 Block Layout of a Sample File and its Inode 4096 228 45423 0 0 11111 0 101 367 0 428 9156 824 331 3333 9156 331 33330 75 367 1 disk block = 1024 bytes byte offset 9000, byte offset 350,000 816th 808th
  • 25. 25 Structure of a Regular File  Processes  access data in a file by byte offset  view a file as a stream of bytes  The kernel  accesses the inode  converts the logical file block into the appropriate disk block
  • 26. 26
  • 27. 27 Directories (1/2)  A directory is a file  Its data is a sequence of entries  Contents of each entries  an inode number and the name of a file  Path name is a null terminated character string divided by slash (“/”)  UNIX System V  Maximum of component name : 14 characters  Inode # : 2 bytes  Size of a directory : 16 bytes
  • 29. 29 Conversion of a Path Name to an Inode  The initial access to a file is by its path name  Open, chdir, link system calls  The kernel works internally with inodes rather than with path name  Converting the path names to inodes  Using algorithm namei  parse the path name one component at a time  convert each component into an inode  finally return the inode of the input path name
  • 30. 30
  • 31. 31 Sample-namei(/etc/passwd) Encounters “/” and gets the system root inode Current working inode = root Permission check Search root for a file – “etc” Access data in the root directory block by block Search each block one entry-”etc” Finding Release the inode for root(iput) Allocate the inode for etc(iget) by inode # found Permission check for “etc” Search “etc” block by block for a directory struct. entry for “passwd” Finding Relase the the inode for “etc” Allocate the inode for “passwd” Return that inode
  • 32. 32 Super Block  Contents  the size of the file system.  the number of free blocks in the file system.  a list of free blocks available on the file system.  the index of the next free block in the free block list,  the size of the inode list.  the number of free inodes in the file system.  a list of free inodes in the file system.  the index of the next free inode in the free inode list.  lock fields for the free block and free inode lists.  a flag indicating that the super block has been modified.
  • 33. 33 Inode Assignment to A New File (1/4)  a known inode  Algorithm iget : to allocate  Algorithm namei : to determine inode #  Algorithm ialloc  To assign a disk inode to a newly created file  Super block contains an array  To improve performance of searching a free inode  To cache the numbers of free inodes
  • 34. 34
  • 35. 35 Inode Assignment to a New File (2/4) free inodes 83 48 empty 18 19 20 array1 Super Block Free Inode List index free inodes 83 empty 18 19 20 array2 Super Block Free Inode List index Assigning Free Inode from Middle of List
  • 36. 36 Inode Assignment to a New File (3/4) index Assigning Free Inode – Super Block List Empty 470 empty array1 Super Block Free Inode List index 0 535 free inodes 476 475 471 array2Super Block Free Inode List 0 48 49 50 remembered inode
  • 37. 37
  • 38. 38 Inode Assignment to a New File (4/4) 535 476 475 471 free inodes remembered inode Original Super Block List of Free Inodes index Free Inode 499 499 476 475 471 free inodes remembered inode index Free Inode 601 499 476 475 471 free inodes remembered inode index
  • 39. 39 Race Condition  A Race Condition Scenario in Assigning Inodes  three processes A, B, and C are acting in time sequence 1. The kernel, acting on behalf of process A, assigns inode I but goes to sleep before it copies the disk inode into the in-core copy. 2. While process A is asleep, process B attempts to assign a new inode but free inode list is empty, and attempts assign free inode at an inode number lower than that of the inode that A is assigning. 3. Process C later requests an inode and happens to pick inode I from the super block free list
  • 40. 40 Race Condition in Assigning Inodes (1/2)
  • 41. 41 Race Condition in Assigning Inodes (2/2) time …………………………………………….I Empty …………………………. free inodes free inodes free inodes L J I J I K …………………………………………………………………... ………………………………………………….……………. ……………………………………………………... (a) (b) (c) (d) (e)
  • 42. 42 Allocation of Disk Blocks  When a process writes data to a file, the kernel must allocate disk blocks  An array in the file system super block  To cache the numbers of free disk block in the file system  Mkfs  Organize the data blocks of a file system in a linked list  Each link is a disk block  The block contains an array of free disk block numbers  One array entry is the number of the next block of the linked list
  • 43. 43 Linked list of free disk block number 109 109 103 100 …………………………... 109 211 208 205 202 ………………… 112 211 310 307 304 301 ………………… 214 310 409 406 403 400 ………………… 313
  • 44. 44
  • 45. 45 Requesting and Freeing Disk Blocks (1/2) 109 ………………………………………………………… 211 208 205 202 …………………………….. 112 109 949 ………………………………………………….. 211 208 205 202 ………………………………. 112 super block list original configuration 109 109 After freeing block number 949
  • 46. 46 Requesting and Freeing Disk Blocks (2/2) 211 208 205 202 ……………………………… 112 344 341 338 335 ………………………………. 243 After assigning block number(109) replenish (fill up again) super block free list 211 109 ……………………………………………………….. 211 208 205 202 ………………………………. 112 109 After assigning block number(949)
  • 47. 47 Other File Types  Pipe  fifo (first-in-first-out)  its data is transient  Once data is read from a pipe, it cannot be read again  The data is read in the order that it was written to the pipe, no deviation from that order  using only direct block  Special File (including block device, character device)  Specifying devices  The inode does not reference any data  The inode contains the major and minor device number  major number  a device type such as terminal or disk  minor number  the unit number of the device