Documente Academic
Documente Profesional
Documente Cultură
447
192 Let Us C
B y far the most widely used storage mediums are the floppy
disks and fixed disks (hard disks). Floppy disks and hard
disks come in various sizes and capacities but they all
work basically in the same way—information is magnetically
encoded on their surface in patterns. These patterns are determined
by the disk drive and the software that controls the drive.
13 14 15 13 14 15
12 16 12
F2 F2 F2 D D DS 16
11 F2 F2 11 D DS
17 17
F2 DS F2 D DS DS
10 F1 F2 18 10 D F2 18
9 F1 BS 1
9 D D 1
F1 F1 D D
8 F1 F1 2 8 D D 2
F1 F1 F1 D D D
7 3 7 3
6 4 6 4
5 5
Side 0, Track 1
Side 0, Track 0
BS - Boot Sector F1 - First copy of FAT
F2 - Second copy of FAT D - Root directory structure
DS - Data space
Figure 13.1
As you can observe from Figures 13.2 and 13.3, the boot
parameters basically contain information indicating how the disk
has been organized. Apart from the first 11 bytes in the list of boot
parameters, the rest form the ‘BIOS Parameter Block’ (BPB).
Continued…
Chapter 13: Disk Basics 195
…continued
Media descriptor 1 F0
Sectors per FAT 2 9
Sectors per track 2 18
No. Of sides 2 2
Hidden sectors 4 0
Huge sectors 4 0
BIOS drive number 1 0
Reserved sectors 1 0
Boot signature 1 41
Volume ID 4 349778522
Volume label 11 ICIT
File system type 8 FAT12
Figure 13.2
Figure 13.3
The ‘Volume ID’ entry is the serial number that is recorded on the
disk while formatting it. This is the same number that is shown
when we run the ‘Dir’ command on the disk.
Let us now take a look at the 32-bit FAT system’s boot sector
contents. These are shown in Figure 13.4.
continued…
…continued
Figure 13.4
In the entry ‘File system version number’ the high byte contains
the major version number, whereas, the low byte contains the
minor version number.
Description Length
Figure 13.5
Description Length
Filename 8
Extension 3
Attributes 1
Reserved 1
Number of 10 msec intervals in 2 seconds 1
Creation time 2
Creation date 2
Last access date 2
High word of starting cluster number 2
Last modification time 2
Last modification date 2
Starting cluster of file/directory 2
File size 4
Chapter 13: Disk Basics 201
Figure 13.6
Figure 13.7
Long Filenames
Since the advent of Windows 95 the barrier of 8.3 based filenames
has been lifted. Hence now we can use filenames like ‘This is my
seminar file’. This is all right from the point of view of
convenience, but how do we accommodate such long filenames in
a 32-byte entry? While storing long filenames, the name is
distributed over multiple 32-bytes entries. The last of these entries
contains a short filename (alias). For example, if the long filename
is ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.TXT’,
then out of the several 32-byte entries that would be required to
accommodate such a name the last entry would contain
‘ABCDEF~1.TXT’. Let us now understand what is present in
other entries except the last. The breakup of these entries is shown
in Figure 13.8.
Description Length
Sequence byte 1
Unicode characters of name 10
204 Let Us C
Attributes 1
Long entry type 1
Checksum for matching short name 1
More Unicode characters of name 12
Reserved 2
More Unicode characters of name 4
Figure 13.8
As can be seen from Figure 13.8 every 32-byte entry required for a
long filename can accommodate 13 characters ( (10 + 12 + 4) / 2 ).
These characters are stored as Unicode characters (in Unicode
each character occupies two bytes) and not as ASCII characters.
Thus, to accommodate filename ‘ABCDEFGHIJKLMNOPQ
RSTUVWXYZ1234567890.TXT’ we would need 40/13, i.e. 4
entries (one more entry would be required for a short file name
(alias of the filename). The contents of these entries are shown in
Figure 13.9.
32-byte entry
T FFFF FFFF
12345 67890. TX
NOPQR STUVWX YZ
ABCDE FGHIJK LM
ABCDEF~1 TXT
This means that the space that belongs to a given file is mapped by
a chain of FAT entries. Each FAT entry points to the next entry in
the chain. The first cluster number in the chain is the starting
cluster number in the file’s directory entry. When a file is created
or extended, a cluster is allocated to the file by searching the FAT
for unused clusters and adding them to the chain. Vice versa, when
a file is deleted, the cluster that has been allocated to the file is
freed by clearing corresponding FAT entries (by setting them to
0). The FAT chain for a file ends with an entry FFFFh in the FAT.
Figure 13.10 shows a FAT chain for a file called ICIT.PRG.
Chapter 13: Disk Basics 207
Figure 13.10
Values Meaning
Figure 13.11
Chapter 13: Disk Basics 209
As we saw earlier, two identical copies of FAT are maintained on
the disk. All copies are updated simultaneously whenever files are
modified. If access to a FAT fails due to a read error, the OS tries
the other copy. Thus, if one copy of the FAT becomes unreadable
due to wear or a software accident, the other copy may still make it
possible to salvage the files/directories on the disk.
Since hard disks are typically of high capacity the number of files
stored on it are very high. If all these files were stored in the root
directory then to manage these files would become quite tedious.
Therefore, the files on a hard disk are usually split into various
sub-directories. For example, in the root directory there could be a
sub-directory containing all C++ programs, another sub-directory
containing all C programs, still another containing all MS-Word
files, and so on. Within a sub-directory there can be still more sub-
directories. Each sub-directory is linked to its parent directory,
which can be a root directory or another sub-directory, thus
forming a tree like structure, as shown in Figure 13.12
Root directory
Letters Documents
sub-directory sub-directory
210 Let Us C
Figure 13.12
Compact Disc
Almost every conceivable form of data is making its way to a five-
inch disk called compact Disc, CD in short. One CD is capable of
storing data equivalent to almost 500 floppy diskettes. A CD can
also be used to store data, photographs, music, movies, etc.
Sub4
Sub4 file1,
file1,file2
file2
Directory Structure
Figure 13.13
ISO 9660 also imposes a limit on the length of the path to each
file. The length of the path is the sum of the lengths of all relevant
directories, the length of the File Identifier, and the number of
relevant directories. The length of the path cannot exceed 255.
Summary
In this chapter we learnt the physical and logical formats in which
floppy disks and hard disks and CDs are organized. We also
explored the contents of boot sector, the directory and the file
216 Let Us C
allocation table. We examined the purpose of maintaining sub-
directories and partitions on hard disks.
Exercise
[A] Pick up the correct alternative for each of the following:
(a) The OS identifies the way a disk has been formatted by
(1) Format ID
(2) Media descriptor
(3) Number of tracks on the disk
(4) Number of sectors on the disk
(b) The boot sector of a disk contains
(1) Disk bootstrap program
(2) Bootstrap loader program
(3) Directory entries
(4) Information about when the disk was formatted
(c) Length of each directory entry is
(1) 34 bytes
(2) 32 bytes
(3) 36 bytes
(4) 8 bytes
(d) A cluster represents
(1) A group of tracks
(2) A group of sectors
(3) Total number of tracks present on the disk
(4) Total number of sectors present on the disk
(e) The date field in the directory entry is
(1) 2 bytes long
(2) 8 bytes long
(3) 6 bytes long
(4) None of the above
(f) Maximum length of a volume label entry is
Chapter 13: Disk Basics 217
(1) 8 bytes
(2) 3 bytes
(3) 11 bytes
(4) None of the above
(g) Where a particular file begins in the data space is
indicated by
(1) Starting cluster number
(2) FAT entry of the file
(3) Boot parameters of the file
(4) None of the above
(h) The entry of starting cluster of a file is present in
(1) Boot parameters
(2) Directory
(3) File allocation table
(4) Data space
(i) On hard disk side 0, track 0, sector 1 contains
(1) Disk bootstrap
(2) Directory
(3) File allocation table
(4) Partition table and master boot program
(j) The size of a partition table on hard disk is
(1) 64 bytes
(2) 32 bytes
(3) 16 bytes
(4) 64 bits
(k) Partition table contains information about
(1) Where the different partitions of the disk begin
(2) Where the different partitions of the disk end
(3) Which is the bootable partition
(4) All the above
(l) Which of the following is not present on the floppy disk.
(1) Boot Sector
(2) File Allocation Table (FAT)
218 Let Us C
(3) Directory and Data Space
(4) Partition Table
(m) The maximum cluster number for a 16-bit FAT is
(1) 2048
(2) 4096
(3) 65536
(4) 268435456
(n) The Media Descriptor entry within the boot parameter for
the 1.44 MB floppy disk is
(1) F8
(2) F0
(3) 00
(4) FF
(o) The total number of sectors per cluster for a 32-bit FAT
system is
(1) 1
(2) 2
(3) 4
(4) 8
(p) The new entity added in the Boot Parameters of a 32-bit
FAT System is
(1) Bytes per sector
(2) Number of FAT copies
(3) Midia descriptor
(4) Drive description flag
(q) Which bit of the attribute byte has to be set to 1 in the
Directory entry to make the file read only.
(1) 0th bit
(2) 1st bit
(3) 4th bit
(4) 7th bit
(r) FAT maps the usage of data space and contains the
information about
Chapter 13: Disk Basics 219
(1) the space used by each individual file
(2) the unused disk space
(3) the space that is unusable due to defects in the disk
(4) All the above
(s) Which entry is not a FAT entry.
(1) Unused cluster
(2) Reserved cluster
(3) Bad cluster
(4) Number of sectors in a cluster
(t) How many bytes from the FAT chain are not used for
storing the cluster number for a 16-bit FAT.
(1) First 3 bytes
(2) First 4 bytes
(3) First 8 bytes
(4) First 16 bytes
[B] State whether the following statements are True or False:
(a) BIOS refers to a sector by its logical number whereas
DOS/Windows refers to it by side number, track number and
sector number.
(b) All disk formats are upwardly compatible.
(c) Innermost track on the floppy disk is track number 0.
(d) Like a hard disk, a floppy disk can also be partitioned.
(e) On a hard disk more than one operating system can be
present.
(f) A hard disk must always be partitioned.
(g) Number of sectors occupied by directory and file allocation
table changes from format to format.
(e) FAT contains the information about where the files and
directories are stored in the data space.
(f) The maximum root directory entries within the Boot
Parameter Block indicate the maximum number of files
that can be created for the root directory of the disk.
220 Let Us C
(g) If the boot signature value within the Boot Parameter
Block is 29h then it indicates that the Boot sector
contains BPB.
(h) A 1.44 MB disk supports 12-bit FAT system.
(i) To accommodate the file name of 40 characters in the
FAT entry, 4 directory entries would be needed.
(j) All files and sub-directories are stored in the data space
area.
(k) Cluster is nothing but a group of sectors that OS allocates
to a file at a time.
(l) Each partition of the hard drive can contain its own boot
sector and operating system.
(m) The ROM-BIOS functions accesses sectors with the help
of the track and the sector number only.
[C] Write a program to read the boot parameters from the boot
sector of a floppy disk and display them on the screen.
Hint: Use the standard library function _bios_disk( ) if you
are using Microsoft C and the function absread( ) if you are
using Turbo C.
Chapter 13: Disk Basics 221