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

Tutorial 8 FileSystem

The document discusses Linux file systems and inodes. It explains how files are organized and stored in Linux using inodes. It also provides examples of commands to view file system information and manipulate inodes like stat(), find, ls -i etc. The document contains challenges involving locating files based on inode number and exploring mounted file systems.

Uploaded by

Subhas Chandra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Tutorial 8 FileSystem

The document discusses Linux file systems and inodes. It explains how files are organized and stored in Linux using inodes. It also provides examples of commands to view file system information and manipulate inodes like stat(), find, ls -i etc. The document contains challenges involving locating files based on inode number and exploring mounted file systems.

Uploaded by

Subhas Chandra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Tutorial 8 File Systems in Linux

The objective in this tutorial is to make the students aware about block
based storage and file systems.

Files systems form the basic identity of data in any kind of storage device. The Linux file systems is
special because it supports a large number of files systems ranging from journaling to clustering to
cryptographic. Linux is a wonderful platform for using standard and more exotic file systems and
also for developing file systems.
The Linux file system architecture is an interesting example of abstracting complexity. Using a
common set of API functions, a large variety of file systems can be supported on a large variety of
storage devices. Take, for example, the read function call, which allows some number of bytes to be
read from a given file descriptor. The read function is unaware of file system types, such as ext3 or
NFS. It is also unaware of the particular storage medium upon which the file system is mounted,
such as AT Attachment Packet Interface (ATAPI) disk, Serial- Attached SCSI (SAS) disk, or Serial
Advanced Technology Attachment (SATA) disk. Yet, when the read function is called for an open
file, the data is returned as expected.
A file system is an organization of data and metadata on a storage device. As mentioned, there are
many types of file systems and media. With all of this variation, you can expect that the Linux file
system interface is implemented as a layered architecture, separating the user interface layer from
the file system implementation from the drivers that manipulate the storage devices. The inode
( also known as Index Node) is a very basic concept related to Linux and UNIX filesystem. Each
and every object/element in the filesystem is associated with an inode. Just like these identification
numbers for people, there is a unique identity of every member of a Linux filesystem which is
known as Inode number and it uniquely exists for each and every individual file on Linux or Unix
filesystems. In any Linux/Unix filesystem, inodes occupy only up to 1% of the available disk space,
whether it is the hard disk itself or a partition present on it. The inode space is helpful to "track" the
files saved in the hard disk memory. Size of each inode entry is 128 bytes. The inode entries store
metadata about each object of the filesystem (file or directory) that just points to these structures
and does not store any kind of data.
Accessing inode numbers :
1) ls -i : displays the inode numbers associated with each file.
2) df -i : displays the inode information.
3) stat [filename] : displays the file statistics including the inode number.
4) You can locate a file based on its inode number using :
find . -inum [inode-number]
The stat() system call :
stat() is a system call that is used to determine the information about a file based on its file path.
int stat(const char *path, struct stat *buf);
An example code to use stat() is as follows :
#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
int main(int argc, char **argv)
{
if(argc != 2)
return 1;
struct stat fileStat;
if(stat(argv[1],&fileStat) < 0)
return 1;
printf("Information for %s\n",argv[1]);
printf("---------------------------\n");
printf("File Size: \t\t%d bytes\n",fileStat.st_size);
printf("Number of Links: \t%d\n",fileStat.st_nlink);
printf("File inode: \t\t%d\n",fileStat.st_ino);
printf("File Permissions: \t");
printf( (S_ISDIR(fileStat.st_mode)) ? "d" : "-");
printf( (fileStat.st_mode & S_IRUSR) ? "r" : "-");
printf( (fileStat.st_mode & S_IWUSR) ? "w" : "-");
printf( (fileStat.st_mode & S_IXUSR) ? "x" : "-");
printf( (fileStat.st_mode & S_IRGRP) ? "r" : "-");
printf( (fileStat.st_mode & S_IWGRP) ? "w" : "-");
printf( (fileStat.st_mode & S_IXGRP) ? "x" : "-");
printf( (fileStat.st_mode & S_IROTH) ? "r" : "-");
printf( (fileStat.st_mode & S_IWOTH) ? "w" : "-");
printf( (fileStat.st_mode & S_IXOTH) ? "x" : "-");
printf("\n\n");
printf("The file %s a symbolic link\n",
(S_ISLNK(fileStat.st_mode)) ?
"is" : "is not");
return 0;
}
Challenge Problem: Take input of an inode number from user and locate the file and print all its
contents using a C program. Initially search under the current folder. Later explore across all folders
and file systems under root folder (/).
Part 2 Exploring file systems:
1. Use mount command to find currently mounted devices and folders.
2. Connect a pen drive (USB flash drive) and see how the output of mount changes.
3. Use sudo umount xxxx to unmount (eject) the pen drive.
4. Look at the content from /etc/fstab.
5. Follow the reference from http://www.jamescoyle.net/how-to/943-create-a-ram-disk-in-
linux
6. If you modify some of the files under the mounted location of step 5 above and then reboot
the machine, what happens to the modified content? Why?

Challenge Problems:

Use dmesg to figure out how ramdisk image is being used during Linux boot up
process.
Identify the ramdisk file and try to uncompress it for further analysis.
Trace the steps that are used during Linux bootup starting from Grub to Linux Kernel
to initial services and ramdisk image and finally to fully mounted disks from the internal
hard disk drives.
Should we use similar file system formats for mechanical hard disk drives and solid state
drives? Why / Why-not.

You might also like