0% found this document useful (0 votes)
30 views29 pages

Inode

Uploaded by

Himani Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views29 pages

Inode

Uploaded by

Himani Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

AMITY INSTITUTE OF INFORMATION

TECHNOLOGY

UNIX OPERATING SYSTEM AND SHELL PROGRAMMING


What is Inode In UNIX
• UNIX is OS it uses Inode file system

• An Inode is a data structure in UNIX that denotes a file or a directory on


file system. It contains information about file like-location of file on the
disk, access mode,ownership,file type etc(specifically the file’s metada)

• INODE stands for Index Node

• Each Inode has a number that is used in the index table. UNIX kernel
uses Inode number to access the contents of an Inode

• We can use ls –Ii command to get the inode number of a file.

• Everything’s a file in UNIX directories,hard drives,network devices,pipes


Cont..
• But in the UNIX shell we spend lot of our time interacting with
Inodes,not with files

• i.e data which is there in files and to store that data properly and
maintained in files --we use INODE

• I --index
• node---block

• Stored on disk, references the actual location of file


UNIX File System

• A file system is a group of Files and relevant information regarding them

• Hard Disk may comprise a single file system or it may be partitioned to house several
file systems.

• Disk Space allotted to Unix file system is made up of blocks each of which are
typically of 512 bytes. Some file systems may have block of 1024 or 2048 bytes

• Block size depends upon how the file system has been implemented on a particular
installation.

• It may also change from Unix version to another.

• cmchk command is used to find out the block size on the file system. This command
reports the block size---- $ cmchk
• BSIZE =1024
• Inodes are used to keep track of broken up pieces of files

• Disk is divided into equal size blocks each of which can be


assigned to a file.If the file is ordered then a single block

• Each file has inode associated with it that store which block
make up the file

• Inode store more than data i.e. METADATA


Metadata Fields
• User and group Ownership

• Type Regular, directory, character device, block device or FIFO pipe

• Access Permissions

• Access times ,file accessed, file modified, inode modified

• No of hard links to the file

• Addresses of disk blocks containing the data

• File size
Note: Inode does not include the file paths
Example Inode
Owner: hra

Group g1

Type regular file

Permissions -rwx-w-r-x

Accessed jan 02 2020 1:30 PM

Modified Dec 31 2021 2:45 PM

Size 6030 bytes


(disk addresses)
Storage of Files

• Each Inode entry in the Inode table consists of 13 addresses each, which specify
where the contents of the file are stored on the disk

• These addresses may be numbered through 0 to 12

• First 10 addresses i.e. 0 through 9 points to first free blocks on the disk

• Example If file of size 3 KB may have its entries like this i.e. The address of 4970
signifies where the first 1 kilobyte of the file are stored. The next 1 KB chunk is at
5231 and next at 3401.These addresses may be scattered throughout the disk
Cont….
• These addresses may be scattered throughout the disk,
as files are stored in chunks wherever empty blocks of
disk are available especially with large files.

• Address 0 to 9 can handle a file of maximum size of 10


KB.

• For Files larger than 10 KB


mode
owner I-node Structure
timestamp
Data block Data block
Size
Reference count Data block Data block

Block count ... ...


Data block Data block
Direct blocks
0-9

Single indirect Indirect block


Indirect block ...
Double indirect Indirect block
Indirect block
Triple indirect
Typical Inode
Entry

OWNER

GROUP

File Type

PERMISSIONS

ACCESS TIME
4970
MODIFICATION TIME

Inode Modi. Time

File Size

0 4970
5231
1 5231

2 3401

3 7654 3401
4 8765

5 9877

6 7666

7 4444

8 7665

9 8771

10 7717

11 8888

12 9999
Cont…
• Kernel’s file sybsystem regulates data flow between the
kernel and secondary storage devices.
• Each UNIX file system contains four major parts
A. boot block:
B. superblock:
C. i-node table:
D. data block: file storage
Cont…
• All the blocks belonging to the file system are logically divided into
four parts
• First Block of a File system is called “BOOT BLOCK” which is
followed by SUPER BLOCK,INODE BLOCK and DATA BLOCKS.

• BOOT BLOCK: This block represents the beginning of the file


system. It contains a program called “Bootstrap Loader". This
program is executed when we boot the host machine. Only one boot
block is needed to start up the system, all the file system contain one
(possibly empty)boot block.
File System Layout
Block 0: bootstrap
Block 1: superblock
Block 2
...
Block n
Block n+1
...
The last Block
Boot Block
• A boot block may contains several physical blocks.
• Note that a physical block contains 512 bytes
• (or 1K or 2KB)
• A boot block contains a short loader program for
• booting
• It is blank on other file systems.
Superblock
• Superblock contains key information about a file system
• Superblock information:
• A. Size of a file system and status:
• label: name of this file system
• size: the number of logic blocks
• date: the last modification date of super block.
• B. information of i-nodes
• the number of i-nodes
• the number of free i-nodes
• C. information of data block: free data blocks.
• The information of a superblock is loaded into memory.
SUPER BLOCK
This block describes the state of the file system—how large it is,
how many maximum files can it accommodate, how many more files
can be created etc.
INODE BLOCK
• All entities in UNIX are treated as files.
• Information related to all these files is stored in an Inode table on the disk.
• For each file there is an Inode entry in the table.
• Each entry is made up of 64 bytes and contain the relevant details for that
file like:
• Owner of the file
• Group to which owner belongs.
• Type of File
• File Access Permission
• Date and time of last Access
• Date and time of last Modifications
• Number of links to the File
• Size of the File
• Address of blocks where the file is physically present
I-nodes
• i-node: index node (information node)
• i-list: the list of i-nodes
• i-number: the index of i-list.
• The size of an i-node: 64 bytes.
• i-node 0 is reserved.
• i-node 1 is the root directory.
• i-node structure: next page
I-node structure
• mode: A. type: file, directory, pipe, symbolic link
• B. Access: read/write/execute (owner, group,)
• owner: who own this I-node (file, directory, ...)
• timestamp: creation, modification, access time
• size: the number of bytes
• block count: the number of data blocks
• direct blocks: pointers to the data
• single indirect: pointer to a data block which
• pointers to the data blocks (128 data blocks).
• Double indirect: (128*128=16384 data blocks)
• Triple indirect: (128*128*128 data blocks)
DATA BLOCK

• This Block contains the actual contents.

• An allocated block can belong to only one file in the file system

• This block cannot be used for storing any other file’s contents
unless the file to which it originally belonged is deleted
HOW DOES UNIX ACCESS FILES
• Internally a file is identified by UNIX by a unique Inode
Number associated with it.
• Inode number can be obtained by command
ls –li

$ ls –l file1

file1 12342
If several slots available in the Inode table slot no
12342 contains information about file1
LINKS—HARD Links and SOFT Link
Links
• Soft Links are similar to MS Windows shortcuts

• Only file can have many shortcuts pointing to it

• Hard links are just different names for the same file

• One file can have many different names or


hard links
Soft Link Example ln-s targetfile
srcfile
ls –li test

13647 and having one link

ln –s test myshortcut—It creates shortcut to test file

ls –li test myshortcut ---It will display both the files but myshortcut->test(myshorcut is a soft link and
having two different file

myShorcut is softlink that points back to the test and soft link that is created have different inode
number and this number would be different from file test

Here myshortcut is a special file and test is a stand alone file and first letter in permissions caontain l
that means it’s a link whereas in test it’s a regular file
Test contains data and myshortcut just points to test file
Cat test
Cat myshortcut----gets same output
mv test test1
ls –li test myshortcut-----see the output
ls –li test1 myshortcut—see output
Cat myshortcut
Practical Session

You might also like