Linux File System: PRAKHER GUPTA (144032) SHISHIR (144045)
Linux File System: PRAKHER GUPTA (144032) SHISHIR (144045)
Linux File System: PRAKHER GUPTA (144032) SHISHIR (144045)
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
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
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.