Sunday, September 11, 2011

Booting

Today let's discuss about booting and what actually happens when a system boots.

During the early days of computers, the boot program is made read only and is put in hardware chips. This boot program is called a bootstrap in computer terminology. The bootstrap initiates all the CPU registers, device controllers and finally loads the operating system into memory. The advantage of this scheme is that, since the bootstrap is read only, no virus can effect it. But the disadvantages outweigh this. First, if we want to add any external hardware,  it's device driver needs to be loaded when the system starts. But, since the bootstrap is read only, we need to change the hardware chips. Also, the operating system must be in a fixed location as specified in the boot strap, if we install the operating system in a different area, then also there is a need to change the chip.


So our computer scientists thought over this and came up with a simple solution. Instead of making ROM's with complete bootstrap program in them, they started making ROM's with tiny bootstrap program's called bootstrap loader. And the main bootstrap program is stored in the disk. Since changing the bootstrap program simply requires a write to the disk, our problem is solved. The bootstrap program on the disk is generally stored in first sector of the hard disk called boot sector.

But... a new problem arrived -- Boot sector virus

Enough of computer terminology, now I will explain in simple terms. BIOS is generally present in non-volatile ROM chips as you know, and this generally initiates the main memory, CPU registers, device controllers and starts the tiny bootstrap loader that is present in it. The BIOS is built at the time of manufacture of a PC and when you start the PC, it is the first software that normally executes, even before the main memory or disk gets initialised. It looks as below


The full bootstrap program as I told earlier, is stored in first sector of harddisk called boot sector. After initialisation of all aspects, the BIOS loads this program to main memory and hands the baton to it for execution. This boot sector in windows computers is called Master Boot Record or simply MBR. MBR contains the full boot code, along with a partition table. This partition table contains the information of partitions along with information whether an Operating system is present in each one or not. If only one OS is present, it is shown or by default it's loaded since there is no need for user to make choice. If more than one OS is present, the user is presented with options to load what ever operating system he wants to be loaded.


Last, about boot sector virus. To prevent boot sector virus, there is an option in BIOS, which makes the bootstrap program on the disk read-only. When ever you think you are not going to install any more OS, check it on and when you want to change your OS, check it off. Happy now...virus problem also solved

Friday, September 9, 2011

Formatting of disk

In the previous post, we have seen that a Hard disk drive or a magnetic disk is a collection of platters covered with magnetic material which are grouped into cylinders. Today let's see how the formatting of disk is done.

Initially when the disk is manufactured in industry, it contains nothing except platters with some magnetic material on them. In the factory itself, low level format or physical format happens. First each platter is divided into sectors and appropriate data structures are written into them to enable the disk controller to read or write data. These data structures contain a header, trailer and a data area where the data is read/written. The header and trailer contain information about how to read/write data, along with a ECC(Error Correcting Code). When ever the data is first written on to the sector, from the bytes present in the blocks of sector, the ECC is calculated and updated. When another read/write happens it's ECC is recalculated and compared with the previous one. If both are different, then the ECC may give two kinds of errors in regard to the corrupted bits

1. Soft error which can be treated by correcting code
2. Hard error which cannot be treated in any way. Normally those bits are ignored and no read/write happens to them. The information about these bits need to be stored in header/trailer to make sure no disk I/O happens to them.


Now the disk is fitted into the computer system and sold to vendor, who tries to install Operating system in it. Here is the place where cylinders come into picture. First he partitions the disk, like one disk for Operating system, the other for user files and so on. Each partition is a group of one or more cylinders. These partitions are nothing but your c: drive, d: drive, e: drive etc., In the next step the Operating system needs to install file system in each of these partitions (NTFS, FAT etc.,). Installing of file systems is called Logical formatting which is similar to physical formatting except here, the data structures related to file system I/O are written into sectors.

If you are a user of Linux, you must have already encountered something like "Swap" space. The swap space is created as a partition but no logical formatting is done to it. It is entirely treated as a sequential array of logical blocks, used when ever needed. Most database systems also tend to use swap spaces since these are free from from file system related overhead.

Also the partitioned disk with a file system is called a Cooked disk and the one with out any file system is called a raw disk.

Sunday, September 4, 2011

Hard Disk Drive

Most of us have hard disks in our computers now which are used as a secondary storage devices. As you know that secondary storage devices have non-volatile memory while Primary storage devices like D-RAM have volatile memory.




Ever wondered what lies inside the plastic case of your HDD and how it works. I will show you how..



The above figure is the internal structure of a typical hard disk drive. The hard disk doesn't contain a single disk but a bulk of them which look like CD's and are called Platters. The surface of each platter is logically divided into tracks which are inturn divided into sectors. The both sides of platter are covered with magnetic material. The information is magnetically stored on these materials. There will also be read-write heads used for reading or writing data. These are attached to a disk arm, that moves all the heads as a unit. All the tracks at one arm position form a cylinder.

Transfer time is the time needed for transferring of data between the hard drive and computer. It has two parts

1. The time needed to move the disk arm to the desired cylinder called seek time and
2. The time needed for the desired sector to rotate under the read-write head called rotational latency

Did you ever come across a term called head crash. Head crach occurs when the read-write head makes contact with the disk surface actually. The read-write head just flies on a thin cushion of air above the platter. Although the platters are covered with a thin protective layer, there may be times, when the head damages the magnetic surface. Head crash is irrepairable and the disk must be replaced.

Wednesday, August 31, 2011

Text editor - Visual basic

Today, let's see the making of our first system software - text editor. We will create it using Visual basic language and Visual Studio IDE. Incase, you don't have Visual Studio, download a free version of Visual Studio or Visual basic express from the below link

http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express

I have made it using Visual Studio 2010, so it may be compatible with 2008 edition, but before that I cannot guarantee. Below is the download link for my project. If you know Visual Basic, it's very easy and intuitive to understand the commands and if you have any doubts, please post them as comments

http://www.filefactory.com/file/cd55136/n/Dileepad.zip

It does all the things that a notepad does, along with good exception handling. The only change is that, it uses " Rich text " files, instead of traditional notepad files. And one more thing, it's name is Dileepad

I have tried to implement spell checker functionality in it, by using "Keyoti Rapid spell Desktop", but it's a paid version and since the version expired, I have to remove the functionality. It's just a single one line in Form_Load, that makes the rich tex box we are using, to gain the spell checker functionality. Try to do it, if you couldn't comment, I will help you. The Dileepad looks as the one shown below

Click to enlarge

If you know Visual basic, skip the remaining post.

If you don't know Visual Basic, don't bother yourself, it's one of the easiest languages to learn and with .net frame work, it has become more subtle. Just go through the code and try to understand it. If you got doubts, clarify them by going through the msdn blog. It has hundreds of articles and forums dedicated to Visual Basic. Or alternatively you can post them over here.


I will give some hints for the beginners to grasp the code. Unzip the file. Open Visual Studio. File->open->Project/Solution. Navigate to the unzipped folder. If the unzipped folder's name is dileepad, go to dileepad->dileepad->dileepad and now you must be seeing a folder with the first subfolder as bin. If not  navigate into one more dileepad subfolder. Finally there will be a Visual Studio Project file named "Dileepad" in the same folder which contains "bin" subfolder. Click on it and the whole project get's opened.


Form1.vb is the heart of the system and it contains the main interface of notepad while form2 is just created to tell about the software for "About" or "Credits". Form1.vb contains usable controls that I dragged and dropped from the tool box on the left hand side. And the things that the control does when a user presses it, is presented in the code behind it. Just double click the control and you can see the code behind it. Very simple and easy to grasp. To run the file, just press "F5".


I have two more system software codes to give you, they are of pure C-language and what those softwares are is a suspense for now.