0% found this document useful (0 votes)
2 views

Files&File Systems

The document provides an overview of Linux disk partitions and file systems, detailing the types of partitions, including those containing raw data and file systems. It explains the structure of a file system, including components like boot blocks, super blocks, inode lists, and data blocks, as well as the classification of files into regular, directory, and special files. Additionally, it describes the file hierarchy in Linux, including concepts such as root directory, home directory, working directory, and pathnames.

Uploaded by

Parvathi M.S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Files&File Systems

The document provides an overview of Linux disk partitions and file systems, detailing the types of partitions, including those containing raw data and file systems. It explains the structure of a file system, including components like boot blocks, super blocks, inode lists, and data blocks, as well as the classification of files into regular, directory, and special files. Additionally, it describes the file hierarchy in Linux, including concepts such as root directory, home directory, working directory, and pathnames.

Uploaded by

Parvathi M.S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Files and File Systems

2.1 LINUX DISK PARTITiONS AND FILE SYSTEM


Under the Linux File System, disks are divided into logical sections
of varying sizes called PARTITIONS

2.1.1 Types of Partitions

There types of disk partitions:


are two

Those containing raw data,


-
Those containing entities called file systems.
The partition, which contains raw data, is called the SWAP
AREA. The kernel uses this partition to store information
from applications swapped out of main memory. We wont

deal with these partitions.


Our area of interest lies in the second type, i.e. those
in fig
containing file systems. A sample disk layout is shown
2.1

Fle
System 1 SWAP
AREA

Fle Fle
Systern2 System3

DISK
System form
File to
together
of a
grouped can
D e f i n i t i o n

disk
files on
2.1.2 of partition
c o l l e c t i o n
one
is a
Each
logical
one
and only
System have
A file
s t r u c t u r e .

must
it
it has,
h i e r a r c h i c a l

a
system.
(If
file
have a
to
file system). makes it easy

several
file systems
into
a
disk
Partitioning
there.
stored
data
manage

Layout
2.1.3 File System blocks, of
size
of logical
of a s e q u e n c e
consists
o n the
system (For
A file system of it depending
o r multiples
512 bytes blocks).
V u s e s 1024 byte
Example, System
structure:
the following
A file system has

1) Boot block
2) Super block
3) inode list
4) Data blocks

shown in Fig 2.2


A sample file system is

inode data
boot super
block block block block

Figure 2.2 Linux File System Layouts

A sample file system layout is described below:

1) Boot block

The first sector of a file


system is the boot block. It may
contain the bootstrap code that is
read into the machine to
boot it. Although
only one boot block is needed to boot the
system, every file system has a boot
empty. block, which may be
2) Super block

Super block containsinformation that describes the


particular file system. Super block tells us about the size of
the file system, number of free blocks in the file system, a list
of free blocks available, the index of the next free in the free
block list, size of the inode list, number of free inodes in the
list, a list of free inodes, index of the next free inode in the
free inode list, a flag indicating that the super block has been
modified.

3) Inode List

The inode list starts at the third block. It stores the


inodes(index nodes) for all the files in the corresponding file
file.
system. The inode stores information about a particular
It is described in grater detail in a later section.

4) Data Blocks

Data blocks contain the file data.

FILES IN THE LINUX ENVIRONMENT

A file can be defined as a finite collection of information. This


information may consist of any of the following

a) Text data
b) Source programs in a high-level language
as result of compilation
c) Object and executable code, such
d) Information about other files.

2.2.1 Filenames
like +, ,
symbols

arithmetic

and
like,
! a l l o w e d .

characters
not
are case-

Use of
discouraged.
Spaces
adopts
a
system instance,
LINUX
are For
that
the filenames. named

a file
noted with
to be dealing from
It has in distinct

approach
treated
as
s e n s i t i v e

B I G - O N E
is
name
the
big-one. are:
filenames

of valid
Examples
Some

EMPdate.c
123 file
adcfilehandler

BIG SUN
lil un
(lnode)
Index Node they physically exist
exist
The
2.2 entities,
ii.e.
e. they
physically
exist
on

are physical files always disks,


Files Linux system, hard
On a disks,
s o m e w h e r e .

media like
floppy
storage
secondary
cartridge tapes etc.
information
n
collection of
a file is a
secondary
storage
previously, But
started
As
sequence
of bytes. (read/write)
take
i.e. it is a
data
transfers
bytes devices, i.e. rather than
media are block (collection of bytes),
to blocks written on
to a
with respect data is
place other words
individual bytes. In also read
likewise.
in and data is
a form
of blocks,
disk in

Note:
inode,
of file
a is given by an

The internal representation


the disk layout of the file
a descTiptions of
which contains the file owner,
access
such as
information
data and other inode, but
Every file has
one
accesses
times.
and inode.
permissions which map into the
several names, all of
it may have
Each is called a link.
name

of
consists of 512 bytes of data or multiples
Oné data biock
number of
Hence each file efectively consists of a
512 bytes. hence
stored randomly on disk, and
data blocks. These are
locations have to be made
known (fig 23)
their
How it's actually stored on disk

To a user
Block2

Blocko Block 1 Block n-1


(n =no. of blocks by the data)
Block1

Figure 2.3 File Data Blocks

Also, the size of the file should be known along with


information regarding its ownership, time of last
modification etc.

All the above information exists for each file present in the
Linux system. Hence for each file, all the relevant
information pertaining to it is stored in an entity called index
node or anode. It has to be stressed that each file must have
one and only one anode.

So, if there are 20 files, there must be 20 inodes. Inodes, like


files are also stored on the disk

An inode is 64 bytes long. Each inode contains the following


information about a file

The file type

The number of links

The owner (the user-id number of the owner)

The group (the group -id number)

The file mode (access permission)

The number of bytes in the file

Date and time im a ast mo


LUnUx
file
modification
to the

.Date
and time oflast
to the file
oflast
access

.Date
and time of
blocks
data
addresses for the
disk
A list of physical
the file

:200
userid
:100
gid e***

permission 2:01 PM
:Jan 30 1994
accessed
1:17 PM
modified
:Jan 30 1994
Inode modification
PM
:Jan 30 1:55
date
:2
links
file size
:4090bytes
disk block address ° * * ° °

3 TYPES OF FILES

Linux classifies files under three categories.

a) Regular files
b) Directory files
c) Special files

2.3.1 Regular Files

Regular files are also known as ordinary files. They contain


anything a user wishes to store (text, data, binary files).

2.3.2 Directory Files

Directory files are special forms of files. The


structure
directory
helps in organizing files. Similar files can be
grouped together into a single directory.
This gives the file
system a hierarchical organization with
the top termed the root
a
single directory at
directory.
A directory contains file names (files could be regular files,
directory files or special files), associated
number. Every file has
with the inode
a
unique inode associated ith it hit
can have multiple names. (the inode does not contain the
filename). Directories with in a directory are called 'sub
directories' of that directory.

2.3.3 Special Files

Linux treats devices as files. Special files are files associated


with a device.

Devices are divided into two types,


depending on the way
the data is transmitted.

Data can be transmitted either CHARACTER BY


CHARACTER (making the device a character Device) or BY
BLOCKS OF 512 BYTES OR ITS multiples (making the
device a Block Device)

Example
A character Device:
The Terminal:
Unix File name: /dev/tty05
A Block Device:
Disks:
Unix File name: /dev/

Special files are like regular files stored in a


directory,
usually '/dev'. The directory the file consists of filename like
tty05 and the inode number (the internal representation of
the file).

2.3.4 Terms related to Directory


Consider a sample file hierarchy structure as shown in figure
2.5
LInux
R o o tD i r e c t o r y

tmp

etc
home

usr
bin

shaj
john
renu - codes
raiu
bin C+
Win
bin CGI
Perl xWin
C
user

Structure
File Hierarchy
Figure 2.5 A sample

Root Directory
at the top of the file
Root directory is the apex directory
a "/" (forward slash)
hierarchy structure. It is represented by
symbol.

Home Directory

Home directory is the directory in which the user is


automatically placed when he logs into a Linux system. It
can never change. Name of the home directory is usually the
same as the user's login name.
Example:
A user with login name 'pravin' will be
in the directory 'pravin', under the automatically placea
directory 'users'.
Working Directory
Working directory is the
currently placed Initially, directory where the user
user 1s
the working
directoryisis the
the user's
user
But it carn be changed by using the cd
'cd
home directory. dot (.).
command. It is represented by single

Example:
Initially, the
the user 'pravin' is in his home directory
/home/pravin. But he can change his working directory-to-
bin under his home directory. His working
directory
directory then becomes /home/pravin/bin

Parent Directory
which
Parent directory of a given directory is the directory,
the
is one level in the file hierarchy structure than
higher dots
current directory. It is represented by two consecutive
().

Example
Suppose the working in the directory /home/pravin.
user is
is
Then, the parent .directory is /home and current directory
/usr/pravin

Pathname
Pathname is a name that represents the full name of the path
form the root (or the current directory) through the file tree
structure, to particular file.

A pathname can be either absolute (full) or relative.

Absolute pathnames always start from the root. Hence the


first slash (/) stands the root directory and all subsequent
slashes are separators for delaminating pathname
Components.

You might also like