A Focus On Disks-DOS Perspective

Probably you know that to DOS, disk is one of the important resources among other resources it has to manage.

buying viagra in a canadian pharmacy

One important distinction between disk and other resources is that, DOS has to load itself from disk by using the disk boot strap. Yet, the boot strap itself is created by DOS when the disk is formatted.

canadian pharmacy discount

While formatting, DOS makes sure that the disk becomes intelligent enough to load itself. What an interesting interdependency! Let us discuss the storage techniques from DOS perspective in detail.

buy zithromax online

The logical structure of a DOS disk

Logically a DOS disk has four major parts. The first part of a disk contains BIOS parameter block and disk boot strap. This is known as boot sector. The second part of a disk is the FAT (File Allocation Table). This portion keeps a trace of disk uses. The third part contains the file information for all files of the root directory. The data area contains the actual data and sub-directories stored onto a disk.

Physical structure of a DOS-DISK

Boot sector    FAT#1     Root directory     Data area

FAT #2,.

Using DOS’s DEBUG utility

Before going to any farther discussion about disk structure, let us first see how we can use DOS’s DEBUG utility to read from the disk. The knowledge is necessary to tally the information presented here with the information written in any of your disk. To load the DEBUG utility just type in the command in DOS prompt and press the <enter> key. To read (load) sectors from a disk we have to use debug’s L(oad) command. The syntax of the command is, L <memory offset> <disk number> <start sector> <number of sector>. The disk number is 0 for the A drive, 1 for the B drive and so on. So to load the first sector (sector 0) of disk in drive C into memory offset 0, the command will be L 0 3 0 1.

After loading any sector of a disk into the memory, we can use debug’s D(ump) command to display them on the screen. The syntax of the Dump command is, D(starting memory offset> <total bytes to dumpx Remember, all the numbers specified in these commands should be in hex notation. So, to dump the first 160 bytes on the screen from memory offset 0 and in hex notation.

To read and interpret the values dumped by debug you should also know the backward storage technique used by the DOS. DOS stores the low order byte first and then the High order byte is stored. So, if a two byte hex value is shown as 12 34, the actual value is 3412. All the subsequent figures in this article are taken using the DEBUG utility.

The BOOT sector

The first part of a disk, that is, the boot sector contains important information related to the disk’s storage capabilities. This portion is used by DOS to

determine certain parameter of the disk. The first Byte of the boot sector of a DOS disk is a jump instruction to the boot strap. Hex equivalent of’short’jump command is EB and ‘long’jump command is E9. The second byte contains the offset for the disk boot strap. The third byte is a NOP instruction. Which hex equivalent is 90. From the fourth byte the BIOS parameter block begins. A hex dump of the boot sector of a 80 MB boot able hard disk is presented in figure 1.

For this disk, data contained in to BIOS parameter block are:

1.    Jump instruction and boot strap offset (2 Bytes): Here, the offset is hex 3C.

2.    The NOP instruction (1 Byte): Hex equivalent of the code, i.e. 90.

3.    OEM signature (8 Bytes): The name of the manufacturer of the DOS version used to format the disk. This disk was formatted using MSDOS ver 5.0.

4.    Bytes per sectors (2 Bytes): The number tells us the sectors length in bytes. For this disk it is 200 Hex or 512 decimal.

5.    Sector per cluster (1 Byte): It is the number of sector per allocation unit (cluster). Here, the number is 4.

6.    Reserved sector (2 Byte): It is the number of reserve ectors on the disk. Here, it is 1. For more detail see discussion below.

7.    Number of FAT (1 Byte): This byte indicates the number of FAT on the disk. For this disk it is 2.

8.    Maximum root directory entry (2  Bytes): This number stands for the maximum number of files that can be present in the root directory. Here, it is 200 hex or 512 decimal.

9.    Total sectors (2 Bytes): Total number of sectors on the disk. Here, the number is 0. This is because the disk space is more than 32 MB (large partition). See discussion below for detail.

A.    Media descriptor (1 Byte): This byte describes the media type. Here it is F8. See discussion for more detail.

B.   FAT length (2 Bytes): This number indicates the number of sector used to store each FAT. Here, it is hex AA or decimal 170 sectors.

C.   Sector per track (2 Bytes): This number    represents the number of sector. Here it is hex 11 or decimal 17.

D.   Number of heads (2 Bytes): This number represents the number of sides of the disk. Here it is hex A or decimal 10.

E.   Number of hidden sector (4 Bytes): Indicates the number of hidden sector. Here, there is hex 11 or decimal 17 such hidden sectors.

F.    Number of logical sectors (4 Bytes): This parameter is introduced from DOS ver. 4.0. This number

, indicates the number of sectors in a disk which has more than 32MB of storage capacity. Here this is hex 2A745 or decimal 173893 sectors.

G. Physical drive number (1 Byte): Indicates the physical drive number for a disk. Here it is hex 80.

H. Reserved space for future use (1 Byte): The Byte is not used .

I. Extended boot signature (1 Byte): See text for details. Here it is, Hex 29 or decimal 41.

J. Volume serial number (4 Bytes): A special serial number for each disk is recorded here. For this disk itis427212EA.

K. Volume label (11 Bytes): The volume label is set while formatting or with LABEL command. Here it is NO NAME.

In a disk, DOS may keep few sectors for its own use. This is known as reserve sector. The BIOS parameter block has this number at hex E offset. Remember, the boot sector is also included in this area. So, for the 80 MB disk we are examining, the boot sector is the only reserve area.

Descriptor Medium MS-DOS  version first supported
0F0 3V2″ DS, 18 SECTOR 3.3
0F9 57/DS. 15 SECTOR 37a”DS, 9 SECTOR 3.0 3.2
OFC 574″SS, 9 SECTOR 2.0
OFD 574″DS, 9 SECTOR 8″ SS/SD 2.0
OFE 57/DS, 8 SECTOR 8″ SS/SD 8″DS/DD 1.0
OFF 574″DS. 8 SECTOR 1.1

Figure 2 : Media descriptor and their meaning

The BIOS parameter block of this 80 MB hard drive also reveals an interesting feature of MS-DOS version 4.0 or latter. Probably you know, from DOS ver. 4 you can format a hard disk which has more than 32 MB of space in one partition. The old 32 MB limit was there, because DOS use to keep the total number of sectors figure in the BIOS parameter block at offset hex 13 with in a word (2 Bytes). As you know, the highest figure a word can keep is 65535. So, there can be maximum of 35536 sectors, each 512 byte long, or 32 MB in total. However, now DOS uses a 4 Byte double word to keep this figure which can accommodate large disk partitions. For our present disk, the word at offset hex 13 contains 0 to indicate that this disk has large partition, a partition with more than 32 MB of space. At the same time, offset hex 20 tells us that there are 173893 sectors on the disk.

The double word at offset hex 1C contains a number indicating the number of hidden sectors where we can not keep our data. Before DOS 4.0 it was a two byte word. The media descriptor at offset hex 15 tells us about the type of media, i.e. whether it is a 3_ double density disk or a 5_ Quad density disk or a hard disk etc. Figure 2 lists some commonly used media and their media type. The disk we are using is clearly described as a hard disk.

The physical drive number indicates the type of disk. Number 0 through 7F indicates floppy disk and 80 through FF indicates hard drive.

The extended boot signature record is always hex 29. This indicates whether the disk has been formatted with MS-DOS. This feature is also introduced from DOS ver. 4.0

The File Allocation Table (FAT)

As I mentioned before, FAT is used to chain together a record of where a file’s data is stored. Here is how it works. The FAT is divided into fields that corresponds to ach of the assignable clusters on the disk. That is, the FAT contains a field for each of the assignable clusters. These field is either 12 or 16 bit long. If the total number of clusters exceed hex FFF or decimal 4087 then the field length is 16 bit, otherwise it is 12 bit. Whenever we create a file, the file entry in the directory contains a starting cluster number for it. This is the cluster where the file’s data appears first in the data area. The corresponding cluster entry on the FAT is then marked as occupied. This is the entry point into the FAT for the file. As the file grows, more clusters are allocated to the file. Whenever the second cluster is allocated, the first cluster slot on the FAT contains the number of the second. Again, when the third is allocated, the second FAT slot for the file contains the number of the third. If we suppose that the file is just three cluster long, the slot of FAT corresponding to the third cluster allocated contains an end of the chain marker.

The above is the hex dump of the first 224 bytes of the FAT of the 80 MB hard drive we are examining. Let us look at the figure closely. The first two entry of the FAT is dummy. The first entry, that is FFF8 is simply a version of the original media descriptor F8. Normally, the second entry almost always contains FFFF. From the third entry the actual table starts. See, the third entry contains 0003, the number of the fourth cluster, and the fourth entry contains 0004, the number of the fifth cluster and so on. That is, the file which has occupied the third cluster is also spread through fourth and fifth cluster. Actually, the end of chain mark at the 22nd entry tells us that the file is ended at 22nd cluster. Given the cluster size, here it is 2048 Byte, we can say that the file has occupied 44 kilobytes of space on the disk.

Before ending our discussion on FATlet us see, what a FAT entry actually means. Just browse through the following table. The first character in the value field is enclosed inside a pair of brackets. This is done because if the FAT is a 16 bit one then all the four digit is significant while if it a 12 bit one then the first character enclosed inside the brackets is simply isn’t there. As you can see, if FAT entry contain (F)FF7 then may be it indicates a bad cluster. We lay emphasis on the word may be because, the above is true only if (F)FF7 is not a normal entry to the next cluster of the file. So, to be sure, you have to go through the chains to see whether it is a normal entry or a bad cluster mark.

The Root directory

The root directory like any directory of any disk contains information related to files. The only difference is, this is the default directory, and technically ultimate parent of all the sub-directories. Not only that, root directory requires special attention also because it has a specific length which is determined on the basis of disk type. You see, as the disk has 2 FATs and each occupied 170 sectors and there on boot sector, the root directory starts at 342nd sector or at sector number  341. From our discussion on BIOS parameter block, we have learned that the hard disk we are examining is capable of storing information related to 512 files. It takes 32 Bytes of space to store a single file’s information. So, it takes 16 Kilo Bytes of space to store the entire root directory. The following figure depicts the root directory of the disk we are examining so far.

1.  File name (8 Bytes): The first eight bytes of a root directory entry contains the name of the file.

2.  Extension (3 Bytes): These bytes of a root directory entry contains the file name extension. Since, the disk is a bootable one, the first file is IO.SYS.

3.  Attribute (1 Byte): This byte contains the file’s attribute. See text for details.

4.  Reserved (10 Bytes): This space is reserved for future use.

5.  Time stamp (2 Bytes): This word contains the time when the file was created or last updated. See text for detail.

6.  Date stamp (2 Bytes): This word contains the date when the file was created or last updated. See text for details.

7.  Starting  cluster  (2  Bytes):  This word  stores the starting cluster number of the file. This is the  number  of cluster where  the  file’s  data first appears.

8.  File size (4 Bytes): This double word contains a integer representing the file’s actual size in bytes.

9.  The deletion marking: The first character of a file entry contains E5 only if it was deleted. However all the other information remains intact unless the file is overwritten to accommodate new files.

A.  Sub-directory attribute: The attribute of hex 10 or decimal 16 indicates that the corresponding entry is a sub-directory.

B.  Normal archive file: The attribute of hex 20 or decimal 32 indicates normal file with archive BIT on.

As you can see, if we delete a file the first character of the name field becomes ASCII E5 Hex. But if we want to start a file name with E5 then the root directory will contain 05 instead. The attribute Byte of a file entry is mapped using the coding presented in the table.

The Attribute byte of the first file that is IO.SYS is hex 27 or Binary 00100111. That is, the file attribute is read-only, Hidden, System and Archive. The date and time fields of the file entry is coded using the following coding technique.

The Date and Time stamp for IO.SYS file is 1A4C and 3000 respectively. The Binary equivalent of the Date stamp is 0001101001001100. If we divide this binary stamp into parts, then it becomes 01100 for day, 0010 for month and 0001100 for the year. Converting them back to decimal we get 12 for month, 2 for day and 13 for year. Remember the year figure is relative to 1980. That is the actual year becomes 1980+13=1993. Thus the date stamp becomes 12-2-93.

Likewise if we convert the time stamp into Binary then we get 0011000000000000. Dividing the number into parts we get 00110 for hour, 000000 for minutes and 000000 for seconds. That is the time becomes 6:00:00.

With this we like to finish this article. Hope, the above discussion will inspire you to learn more about disks. After all, that was the only intention of this article. *

K. A. M. Morshed

System Analyst

The Developers’ Computer System

Subscribe / Share

Article by nuzhat akhter

Authors bio is coming up shortly.
nuzhat akhter tagged this post with: , , , , , , , , Read 109 articles by