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 Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating SystemJanki Shah
 
UNIX Operating System
UNIX Operating SystemUNIX Operating System
UNIX Operating SystemFatima Qayyum
 
External memory - Computer Architecture
External memory - Computer ArchitectureExternal memory - Computer Architecture
External memory - Computer ArchitectureBretz Harllynne Moltio
 
Disk allocation methods
Disk allocation methodsDisk allocation methods
Disk allocation methodsajeela mushtaq
 
Fixed partitioning of memory
Fixed partitioning of memoryFixed partitioning of memory
Fixed partitioning of memoryJohn Scott Giini
 
Computer architecture cache memory
Computer architecture cache memoryComputer architecture cache memory
Computer architecture cache memoryMazin Alwaaly
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System ImplementationWayne Jones Jnr
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSKumar Pritam
 
Operating System-Ch8 memory management
Operating System-Ch8 memory managementOperating System-Ch8 memory management
Operating System-Ch8 memory managementSyaiful Ahdan
 
File system.
File system.File system.
File system.elyza12
 
Operating system paging and segmentation
Operating system paging and segmentationOperating system paging and segmentation
Operating system paging and segmentationhamza haseeb
 
Unix memory management
Unix memory managementUnix memory management
Unix memory managementTech_MX
 
Chapter 13 file systems
Chapter 13   file systemsChapter 13   file systems
Chapter 13 file systemsAlvin Chin
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structuresMukesh Chinta
 

What's hot (20)

File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
 
UNIX Operating System
UNIX Operating SystemUNIX Operating System
UNIX Operating System
 
Disk Management
Disk ManagementDisk Management
Disk Management
 
External memory - Computer Architecture
External memory - Computer ArchitectureExternal memory - Computer Architecture
External memory - Computer Architecture
 
Memory management
Memory managementMemory management
Memory management
 
Disk allocation methods
Disk allocation methodsDisk allocation methods
Disk allocation methods
 
Fixed partitioning of memory
Fixed partitioning of memoryFixed partitioning of memory
Fixed partitioning of memory
 
Computer architecture cache memory
Computer architecture cache memoryComputer architecture cache memory
Computer architecture cache memory
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System Implementation
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Operating System-Ch8 memory management
Operating System-Ch8 memory managementOperating System-Ch8 memory management
Operating System-Ch8 memory management
 
File system.
File system.File system.
File system.
 
Operating system paging and segmentation
Operating system paging and segmentationOperating system paging and segmentation
Operating system paging and segmentation
 
Disk structure
Disk structureDisk structure
Disk structure
 
Unix memory management
Unix memory managementUnix memory management
Unix memory management
 
Chapter 13 file systems
Chapter 13   file systemsChapter 13   file systems
Chapter 13 file systems
 
Memory Organization
Memory OrganizationMemory Organization
Memory Organization
 
OS Unit 5 - Memory Management
OS Unit 5 - Memory ManagementOS Unit 5 - Memory Management
OS Unit 5 - Memory Management
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structures
 
Hard drive partitions
Hard drive partitionsHard drive partitions
Hard drive partitions
 

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
 
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
 
Linux System Programming - File I/O
Linux System Programming - File I/O Linux System Programming - File I/O
Linux System Programming - File I/O YourHelper1
 

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
 
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
 
Linux System Programming - File I/O
Linux System Programming - File I/O Linux System Programming - File I/O
Linux System Programming - File I/O
 

Recently uploaded

Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
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
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 

Recently uploaded (20)

NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
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
 
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
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 

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