Thursday, July 8, 2010

Understanding Filesystems Part-1

For the past few days, I am trying to understand the memory fundamentals behind the Filesystems. I will not say it a complete description of filesystems, but my worth notable observations on my current filesystem.
Experimental Setup:
Hardware:
1. A PC running both Windows and Linux [Fedora13].
2. An Experimental Pendrive. Please dont have any valuable information in it. We are going to format it.
3. Another pendrive to transfer data between Linux and Windows. I did not find a safe and better way to do this, since I am still a newbie to linux.
Software Tools:
1. HexEdit [http://www.physics.ohio-state.edu/~prewett/hexedit/]. A tool to display the raw data.
2. dd Utility for Windows [http://www.chrysocome.net/download]. Utility to take image of source to destination. I use to call it a "PHOTOGRAPH TOOL" ;).

Though Windows is a sophisticated operating system, it hides all the micro level details from the users. So user may not be aware of what exactly is happening inside the Computer box. So take an Operating System like linux, that will open up things if demanded by the user.
Now lets start our experiment.
Let us understand how my computer interprets a pendrive memory.
I booted into Linux. Pendrive got automounted. Following are commands to be executed and their responses.

[root@localhost ~]# cat /proc/partitions
major minor #blocks name

8 0 20971520 sda
8 1 19921920 sda1
8 2 1048576 sda2
8 16 7831552 sdb
8 17 7825423 sdb1
8 32 976762584 sdc
8 33 976762552 sdc1

In the above response, /dev/sdb is Experimental Pendrive and /dev/sdc is Data Transfer Pendrive.
Now issue the following command in the terminal.

[root@localhost ~]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): p

Disk /dev/sdb: 8019 MB, 8019509248 bytes
247 heads, 62 sectors/track, 1022 cylinders
Units = cylinders of 15314 * 512 = 7840768 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc3072e18

Device Boot Start End Blocks Id System
/dev/sdb1 1 1022 7825423 83 Linux

Command (m for help): q


In this post, I am going to dissect the above response that I got from my linux machine.
When I give a fdisk /dev/sdb, it entered a command response mode.
I gave the command 'p'. It returned me the partition details in CHS [Cylinder Head Sector] format [which is conventional in case of harddisks]. Lets take some observations.

Disk /dev/sdb: 8019 MB, 8019509248 bytes
247 heads, 62 sectors/track, 1022 cylinders
Units = cylinders of 15314 * 512 = 7840768 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc3072e18

Observation-1: Disk is detected as /dev/sdb.
Observation-2: Size of disk is 8019MB = 8019*1024*1024 Bytes = 8019509248 bytes. Yes its an 8GB Pendrive.
Observation-3: How is it interpreted in the system? What is this "247 heads, 62 sectors/track, 1022 cylinders"?
Head: Data is written to read from a device called "Platter". A Platter comprises of two heads one on each side.
Track: The track is a thin concentric circular strip on a Platter surface which actually contain the magnetic regions of data written to a disk drive.
Cylinders: A set of tracks with same track no (ie. on the same platter surface) are called Cylinders.
Sector : A track is divided into 512 byte segment called Sectors.

Now lets do the calculation.
247 heads, 62 sectors/track, 1022 cylinders

means there are 247 heads to read the tracks.
There are 62 sectors per track. Seems like only one track per cylinder.
There are 1022 such cylinders are available in my pendrive.

Total Size of Pendrive (in Bytes) = No. of Heads * No of Sectors/track * No. of Cylinders * 512 Bytes.
Total Size of Pendrive (in Bytes) = 247 * 62 * 1022 * 512 Bytes
Total Size of Pendrive (in Bytes) = 8013264896 bytes
Total Size of Pendrive (in Bytes) = 8013264896 / (1024 * 1024 *1024) Gigabytes
Total Size of Pendrive (in Bytes) = 7.4629344940185546875 Gigabytes

This is how the calculation goes.

In my next post, let us see what exactly a "formatting of Pendrive" means and use the tools above.

Search Google

Books that I refer to...

  • The Complete Reference C, Fourth Edition
  • The C Programming Language