Linux File System: PRAKHER GUPTA (144032) SHISHIR (144045)

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 37

LINUX FILE SYSTEM

PRAKHER GUPTA (144032)


SHISHIR ( 144045)
WHAT IS A FILE SYSTEM ?
 The file system provides the mechanism for on-line
storage of and access to both data and programs of
the operating system and all the users of the computer
system.
 File systems include utilities to initialize, alter
parameters of and remove an instance of the file
system or a directory entries.
 File systems also control access to data.
 The file system consists of two distinct parts:
1. A collection of files, each storing related data.
2. A directory structure, which organizes and provides
information about all the files in the system.
WHY DO WE NEED IT?
 Without a file system, information placed in a
storage medium would be one large body of data with
no way to tell where one piece of information stops and
the next begins.
 By separating the data into pieces and giving each
piece a name, the information is easily isolated and
identified.
 Since only binary data is actually written to disks, the
file systems provide a way to translate the physical
recordings on a disk to the format read by an OS.
LINUX FILE SYSTEM
 Linux retains UNIX’s standard file-system model.
 All data in Unix is organized into files. All files are organized into
directories. UNIX files can be anything capable of handling the input or
output of a stream of data.
 These directories are organized into a tree-like structure called the file
system.
 Files in Unix System organized in multi-level hierarchy structure called a
directory tree.
 At the very top of the file system is a directory called “root” which is
represented by a “/”. All other files are “descendants” of root.
 UNIX files can be anything capable of handling the input or output of a
stream of data.
 Device drivers can appear as files, and inter process communication
channels or network connections also look like files to the user.
 The Linux kernel handles all these types of files by hiding the
implementation details of any single file type behind a layer of software,
the virtual file system (VFS).
VIRTUAL FILE SYSTEM

 To the user, Linux’s file system appears as a hierarchical directory tree obeying UNIX
semantics
 Internally, the kernel hides implementation details and manages the multiple different
file systems via an abstraction layer, that is, the virtual file system (VFS)
 The Linux VFS is designed around object-oriented principles and is composed of four
components:
 A set of definitions that define what a file object is allowed to look like
 The inode object structure represent an individual file
 The file object represents an open file
 The superblock object represents an entire file system
 A dentry object represents an individual directory entry
VIRTUAL FILE SYSTEM (cont.)
 To the user, Linux’s file system appears as a
hierarchical directory tree obeying UNIX semantics
 Internally, the kernel hides implementation details
and manages the multiple different file systems via
an abstraction layer, that is, the virtual file system
(VFS)
 The Linux VFS is designed around object-oriented
principles and layer of software to manipulate
those objects with a set of operations on the objects
 For example for the file object operations include (from
struct file_operations in /usr/include/linux/fs.h
int open(. . .) — Open a file
ssize t read(. . .) — Read from a file
ssize t write(. . .) — Write to a file
int mmap(. . .) — Memory-map a file
JOURNALING

 Journaling is the process in which modifications


to the file system are written sequentially to a
journal.
 A set of operations that performs a specific task
is a transaction.
 Once a transaction is written to the journal, it is
considered to be committed.
 When an entire committed transaction is
completed, it is removed from the journal. The
journal is actually a circular buffer.
JOURNALING (contd.)
JOURNALING (contd.)
 Once in log file, considered committed
l Over time, log file transactions replayed over file system to put
changes in place
n On system crash, some transactions might be in journal but
not yet placed into file system
l Must be completed once system recovers
l No other consistency checking is needed after a crash (much
faster than older methods)
 Journaling file systems may perform some operations
faster than non journaling systems. Improves write
performance on hard disks by turning random I/O into
sequential I/O
JOURNALING (contd.)
 The only problem occurs when a transaction has been
aborted—that is, it was not committed before the
system crashed.
 Any changes from those transactions that were applied
to the file system must be undone, again preserving
the consistency of the file system.
THE LINUX ext3 FILE SYSTEM
 ext3, or third extended file system, is a journaled file
system that is commonly used by the Linux kernel. It used
to be the default file system for many popular Linux
distributions.
 Uses a mechanism similar to that of BSD Fast File System
(FFS) for locating data blocks belonging to a specific file.
 It stores data-block pointers in indirect blocks throughout
the file system with up to three levels of indirection.
 Directory files are stored on disk just like normal files,
although their contents are interpreted differently.
The Linux ext3 File System (Cont.)

 The main differences between ext2fs and FFS concern their disk
allocation policies
 In ffs, the disk is allocated to files in blocks of 8Kb, further sub
divided into 1 KB fragments.
 ext3 does not use fragments; it performs its allocations in
smaller units
 The default block size on ext3 varies as a function of total
size of file system with support for 1, 2, 4 and 8 KB blocks.
 ext3 uses cluster allocation policies designed to place logically
adjacent blocks of a file into physically adjacent blocks on disk, so
that it can submit an I/O request for several disk blocks as a single
operation on a block group.
 Maintains bit map of free blocks in a block group, searches for
free byte to allocate at least 8 blocks at a time
Ext3 Block-Allocation Policies
FEATURES
 ext3 adds the following features to ext2:
1. Journaling
2. Online file system growth
3. HTree indexing for larger directories
There are three levels of journaling available :
1. Journal
2. Ordered
3. Write Back
DISADVANTAGES
 ext3 lacks recent features, such as extents, dynamic
allocation of inodes, and block sub-allocation.
 No defragmentation.
 Cannot undelete.
 Lack of native snapshot support.
 No checksumming in journal.
EXT4
 Ext4 was introduced in 2008 with Linux Kernel 2.6.19 to replace ext3
and overcomes its limitations.
 Supports huge individual file size and overall file system size.
 Maximum individual file size can be from 16 GB to 16 TB.
 Overall maximum ext4 file system size is 1 EB (exabyte). = 1’024 PiB
(petabyte) = 1’048’576 TB (terabyte).
 64’000 subdirectories per directory.
 You can also mount an existing ext3 fs as ext4 fs (without having to
upgrade it).
 In ext4, you also have the option of disabling the journaling.
 ‘fsck’ is always very fast.
 journal checksum.
 pre-allocation of blocks and extents to reserve an adjacent list of block,
helping to reduce fragmentation.
 delayed allocation to improve write performance.
The Linux Proc File System
 The proc file system does not store data, rather, its
contents are computed on demand according to user file
I/O requests
 proc must implement a directory structure, and the file
contents within; it must then define a unique and persistent
inode number for each directory and files it contains
 It uses this inode number to identify just what operation is
required when a user tries to read from a particular file
inode or perform a lookup in a particular directory inode
 When data is read from one of these files, proc collects the
appropriate information, formats it into text form and places
it into the requesting process’s read buffer
• Navigating the File System

 Pwd (Present Working Directory)


 cd
 ls
cd
 If you enter cd at the shell prompt without specifying
a path, it will automatically change directories to the
home directory of the currently logged-in user.
ls
 –a Displays all files, including hidden files.
 –l Displays a long listing of the directory contents. This
is a very useful option. You can use it to see the file
names, ownership, permissions, modification date, and
size.
 –R Displays directory contents recursively; that is, it
displays the contents of the current directory as well
as the contents of all subdirectories.
• Managing files and directories
 Creating files and directories
 Viewing file contents
 Deleting files and directories
 Copying and moving files and directories
 Creating links
Creating Files and Directories

touch new_file
Creating Files and Directories

mkdir new_directory
Viewing Text File Contents

 cat
 less
 head
 tail
cat
 The cat filename command will display the specified
text file on screen. This command doesn’t pause the
output, so if you use it to view a long file, you may
need to append |more to the command to pause the
output a page a time.
less
 The less filename command can also be used to
display the specified text file on screen, much like cat.
However, the less command automatically pauses a
long text file one page at time.
head
 The head filename command is used to display the
first couple of lines of a text file on the screen.
tail
 The tail filename command is used to display the last
couple of lines of a text file on screen. The tail
command is particularly useful when displaying a log
file on screen. When viewing a log file, you probably
only want to see the end of the file.
 The tail command also includes the –f option, which is
very useful. You can use this to monitor the file
specified in the command
Deleting Files and Directories
 rmdir
 rm
rmdir
 This utility can be used to delete an existing
directory. To use it, simply enter rmdir
directory_name—for example, rmdir MyFiles. Be
aware, however, that rmdir requires that the directory
be empty before it will delete it.
rm
 The rm utility is a more powerful deletion utility that
can be used to delete either a file or a populated
directory. To delete a file, simply enter rm filename.
To delete a directory, enter rm –r directory_name.
rm
 Be careful with rm! By default, it won’t prompt you to
confirm a deletion operation. It assumes that you
really meant to delete the file or directory. If you
want rm to prompt you before deleting a file or
directory, include the –i option.
Copying and Moving Files and
Directories
 cp
 mv
cp
 This utility is used to copy files or entire directory
structures from one location in the file system to
another. For example, to copy a file named
/tmp/schedule.txt to your home directory, you could
enter
cp /tmp/schedule.txt ~.
mv
 The mv command is used much like cp. However, it will
copy the specified file to the new location in the file
system and then delete the original. For example, to
move a file named mylog.txt from /tmp to /var/log,
you would enter mv /tmp/mylog.txt /var/log
mv
 The mv command is also used to rename files. Simply
enter mv followed by the file to be renamed and then
the new file name. For example, to rename
schedule.txt to schedule.old, you would enter
mv schedule.txt schedule.old.

You might also like