You are on page 1of 16

UNIX SHELL

PROGRAMMING

Chapter-3

UNIX FILE SYSTEM

1
• Unix File system : A file system is a component Unix that
enables the user to view, organize, secure and interact with
files and directories that are located on storage devices.
Different types of file systems :
•Disk-oriented file system : Physically accessible file systems residing on a hard drive,
CD-ROM, DVD ROM, USB drive or any other device.
• Network-oriented file system : A file system accessed from a remote location. These are
usually disk-oriented on the server side.
•Special file system – A file system that typically doesn’t physically reside on disk such as
Temporary file system (TMPS) and process file system (PROCFS).

Unix Shell Programming - 2


Forouzan
Inode :
A file system relies on data structures about the files, as opposed to the contents of that
file. The former are called metadata—data that describes data. Each file is associated
with an inode, which is identified by an integer, often referred to as an i-number or inode
number.

Inodes store information about files and directories (folders), such as file ownership,
access mode (read, write, execute permissions), and file type.
The inode number indexes a table of
inodes in a known location on the device.
From the inode number, the kernel's file
system driver can access the inode
contents, including the location of the file,
thereby allowing access to the file. A
file's inode number can be found using
the ls -i command. The ls -
i command prints the i-node number in
the first column of the report

File names and directory implications:


•Inodes do not contain its hardlink names, only other file metadata.
•Unix directories are lists of association structures, each of which contains one
filename and one inode number.
•The file system driver must search a directory looking for a particular filename and
then convert the filename to the correct corresponding inode number.
Following contents are stored in the Inode from a file:
User ID of file
Group ID of file
Device ID
File size
Date of creation
Permission
Owner of the file
File protection flag
Link counter to determine number of hard links
• File system Components :
Unix file system is generally divided into
four part
– The Boot Block
– The Super Block
– The inode Table
– The data block

Unix Shell Programming - 6


Forouzan
• The boot block - The first block
– It is located at the beginning of the file
system
– It can be accessed by code
incorporated by computer ROM bios
– The boot block is part of disk label
– It contain a program called bootstrap to boot
the OS

Unix Shell Programming - 7


Forouzan
• The super block
– It contain statistical information to keep
track of the entries in the file system
– Whenever disk manipulation is required the
super block is accessed
– Always the copy kept in RAM

Unix Shell Programming - 8


Forouzan
The super block contain information
• Size of the file system
– The storage size of the device or current partition
• List of storage blocks
– The storage space is divided into series of
standard size block
– When data moved to or from the file system ie
block
• Number of free block on the file system
• A list of free block with their location

Unix Shell Programming - 9


Forouzan
• Size of the inode list
– The inode list is initialized to track the maximum
number of files which cannot be more than
maximum number of storage blocks
• Number of free inode on the file system
• A list of free inodes
• Index to next free inode on the list
• Lock fields for free blocks and free inode
lists
• Flag to indicate modification of super
blocks
Unix Shell Programming - 10
Forouzan
• The inode table
– Information about each file in the file system is kept in a
special kernel structure called inode
– The inode contain pointer to disk block containing data in the file
– It contain other information like file size, file modification time,
permission bit owner, group etc
– It does not contain name of file
– The name of file is listed in directory
– The directory contain the file name and their associated
inode

• A inode size of 64 bytes for a file contain the information


– File owner type
• This is number id used as password to find user of the system
– Group id
• This is group to access the owner file
– File type
• it indicate whether inode represent a file, a directoryor block device
Unix Shell Programming - 11
• If the type value is zeroForouzan
then inode is free
Unix Shell Programming - 12
Forouzan
i-nodes :- A UNIX file is described by an information block called i-
node/inode. For every file on the disc there is a unique i-node and a
copy in kernel memory for every open file. All the information about a
file, other than its name, is stored in the i-node. This information
includes:

Owner :- Indicating who owns the file(s) corresponding to this inode.


Type :- Indicates whether inode represents a file, a directory, a FIFO, a
character device or a block device. There is unique integer number
representing this, if this value is 0 then the inode is free.
Last modified time :- Time when the file was last modified.
Last accessed time :- Time when the file was last accessed.
Last inode modified time :- Time when inode has been last modified.
Access Permissions :- The read/write and executable permission of the
file.
Number of links to the file :- In UNIX we can create links (Soft or Hard
Links) to some files or directories.
Size of the file :- The actual size of the file in KB.
Data blocks owned :- The size of data past of the file.
inode number given to a new file :- If a new file requests for a new inode
number, the kernel searches for free inode in the free inode list of Super Block.
If one free inode is found, that one is returned as inode number of the new file.

Freeing an inode :- If the free inode list in super block has space enough, the
freed one is put there. If the freed inode number is less than the remembered
inode, then the remembered inode is updated with the freed inode
Soft & Hard Links :- In UNIX, a file is required to be accessed by two or more
different directories / or run by two or more different users at the same time. For
example a configuration file required to be accessed by two different software
packages or a document (C Program) that needs to be accessed by different
users. The file could simply be copied, this would mean to replicate the file and
changes in the file simultaneously would then create an administrative
nightmare. The way two (or more) files can have the same data is by using links.
Links are of two type soft link and hard link.
Soft Link:
It is a file containing name of another file.
A soft link (symbolic link) is a pointer pointing to the file's contents.
"In -s" is used to create symbolic link.
If the original file is deleted symbolic file can't be opened.
"rm" can be used to remove a symbolic file.

Hard Link:
• The data block
– It contain the actual data in the file or
directories
– It follow inode table and occupy most
storage space
– The file allotted for one file cannot allotted
for other file unless the two files are linked

Unix Shell Programming - 15


Forouzan
• Advantages
– Data in small files can be accessed directly
from inode
– Larger files can be accessed efficiently
– Disk can be filled completely
• Disadvantage
– Inode information kept separately from data
often requires a long seek when file
accessed
– Inode of files in a common directory are not
kept together so it case low performance
– Original file system uses 512 bytes block
, an inefficientUnixtransfer size
Shell Programming - 16
Forouzan

You might also like