Understanding Basics of FileSystem

Understanding Basics of File-system

Lets try to understand what is a FileSystem and whats the need for one .

Examples of a FileSystem are ext2, ext3, ext4, XFS,  NTFS, Fat32, Fat16

 

Lets begin by examining  Human reading and writing skills .

Page1

Honesty is the best policy.
You should Always be honest.

 

Lets examine .

  •  How did you figure out the words (Honesty, best, Always )
  •  How did you figure out how many lines are there
  •  How did u figure out the alphabets .  H, O, N, E, S, T.

 

Human brain has been taught the semantics of reading and writing .   The semantics goes by

  •  Group of alphabet together with space as delimiter is a word .
  •  A new Line is how we discover the start of a line .
  •  To read a word one needs to read from left to Right(HONESTY) and not vice Versa(YTSENOH)
  •   To read a line we read from left to right and not vice versa.
  •   Each alphabet has been associated with a specific sound and a specific way of writing it.   How you pronounce “a” differs from “h” and same for writing it.

 

 

[addToAppearHere]

Lets try to understand from CPU perspective how does the world look like .

  • Everything is represented as 0 and 1 .
  • 0 and 1 themselves are state representation. can be represented as   Voltage +10v => 1 ,   +5v=>0
  • CPU  sees no difference at all between different kind of files.
  • CPU has no idea of how to read a word , line , sentence paragraph
  • All it knows is Binary form of OPCODE PARAM PARAM

 

 

Lets try to understand from Hard-disk (Storage ) perspective  how does the world look like

  • There are two state it is aware of Magnetized and demagnetized
  • The state can be translated to 0 and 1   by some external translator like Drive of the hard-disk.
  •  Hard disk is aware of track and sectors.
  •  It has no clue of what is a file a directory.
  •  It has no clue what is a text file , a c file , a binary file , a java file , a php file .
  •  It  just magnetizes , demagnetize tracks and sectors based on the request made by the driver.

 

 

Lets try to understand from Operating System (OS ) perspective  how does the world look like

  • Operating system interacts with CPU, Hard-disk , Humans and all other resources.
  • Operating System takes care of saving a file and retrieving back the info of the file in the same format.
  • Operating System understand which application to open for which specific type of file.
  • Operating system needs to provide humans view of file and directories
  • Operating system needs to interact with CPU in terms of 0 and 1 .
  • Operating system  Provides ASCII translation
The catch is Operating System can be shutdown and still it needs to retrieve all info saved in the hard-disk And OS needs to provide the same view of File and directories as it was before shutdown .

 

[addToAppearHere]

Here comes the part where OS maintains the semantics just like Humans to differentiate file and directories, The semantics in detail cover everything

  • How to distinguish file from a directory
  • How to differentiate where a file starts and where it ends on hard-disk.
  • Just realize its not a human but some code with some logic which can understand the boundaries .
  • From hard-disk perspective OS is just getting back a stream of 0 an1 (demagnetized , magnetized)
  • Along with actual file some meta info is also being saved this constitutes the data of the File system

File system is the logical semantics to maintain data on a storage system . It also has a physical representation in terms of meta info (Example ext4 layout) .

FileSystem logic is also extended to maintain a in memory fileSystem known as /proc fileSystem in linux.

 

Linux Provides a variety of commands to explore and work on file system

Command Usage
ls  list content inside a directory
mkdir create directory
vim fileName create a file
df -hk usage of directories
lsblk In detail info of all Hard-disk attached
iostat -d -x 5 Live I/O info of the hard-disk