Sunteți pe pagina 1din 31

13 Disk Basics

The Disk Structure


The Boot Sector
The Root Directory
Long Filenames
The Data Space
The File Allocation Table
How Fixed Disks Differ
One Last Thing about Disks
Compact Disc
Primary Volume Descriptor
The Directory Structure
The Path Table
Exercise

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.

Although the type of storage device is important, it is the way the


stored information is laid out and managed that concerns
programmers most. In this chapter therefore we would focus our
attention on how information is organized and stored on the disk.

The Disk Structure


As most of us know, the disk drives in DOS and Windows are
organized as zero-based drives. That is, drive A is drive number 0,
drive B is drive number 1, drive C is drive number 2, etc. The hard
disk drive can be further partitioned into logical partitions. Each
drive consists of four logical parts—Boot Sector, File Allocation
Table (FAT), Directory and Data space. Of these, the Boot Sector
contains information about how the disk is organized. That is, how
many sides does it contain, how many tracks are there on each
side, how many sectors are there per track, how many bytes are
there per sector, etc. The files and the directories are stored in the
Data Space. The Directory contains information about the files like
its attributes, name, size, etc. The FAT contains information about
where the files and directories are stored in the data space. Figure
13.1 shows the four logical parts of a 1.44 MB disk.
Chapter 13: Disk Basics 193

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

When a file/directory is created on the disk, instead of allocating a


sector for it, a group of sectors is allocated. This group of sectors
is often known as a cluster. How many sectors together form one
cluster depends upon the capacity of the disk. As the capacity goes
on increasing, so also does the maximum cluster number.
Accordingly, we have 12-bit, 16-bit or 32-bit FAT. In a 12-bit
FAT each entry is of 12 bits. Since each entry in FAT represents a
cluster number, the maximum cluster number possible in a 12-bit
FAT is 212 (4096). Similarly, in case of a 16-bit FAT the maximum
cluster number is 216 (65536). Also, for a 32-bit FAT the
maximum cluster number is 228 (268435456. Only 28 of the 32 bits
are used in this FAT). All FAT systems are not supported by all
versions of DOS and Windows. For example, the 32-bit FAT
system is supported only in Win 95 OSR2 version or later. There
are differences in the organization of contents of Boot Sector, FAT
and Directory in FAT12/FAT16 system on one hand and FAT32
on the other. Some of these differences are discussed below.
194 Let Us C
The Boot Sector
The boot sector contains two parts: ‘Boot Parameters’ and ‘Disk
Bootstrap Program’. The Boot Parameters are useful while
performing read/write operations on the disk. Figures 13.2 and
13.3 shows the break up of the boot parameters for the 12-bit and
the16-bit FAT systems along with their typical values.

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).

The entry ‘Maximum root directory entries’ indicates how many


maximum files can we create in the root directory of the disk. If
one of these entries is a sub-directory name then there can be
several more files and sub-sub-directories within it. The ‘Media
descriptor’ byte indicates how the operating system refers to a
particular type of disk internally. For example, a 1.44 MB disk has
a media descriptor F0, whereas, a hard disk has a media descriptor
F8.

Description Length Typical Values

Jump instruction 3 EB3C90


OEM name 8 MSWIN4.1
Bytes per sector 2 512
Sectors per cluster 1 1
Reserved sectors 2 1
Number of FAT copies 1 2
Max. Root directory entries 2 224
Total sectors 2 2880

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

Description Length Typical Values

Jump instruction 3 EB3C90


OEM name 8 MSWIN4.1
Bytes per sector 2 512
Sectors per cluster 1 64
Reserved sectors 2 1
Number of FAT copies 1 2
Max. Root directory entries 2 512
Total sectors 2 0
Media descriptor 1 F8
Sectors per FAT 2 256
196 Let Us C
Continued…
…continued

Sectors per track 2 63


No. of sides 2 255
Hidden sectors 4 63
Huge sectors 4 4192902
BIOS drive number 1 128
Reserved sectors 1 1
Boot signature 1 41
Volume ID 4 4084677574
Volume label 11 ICIT
File system type 8 FAT16

Figure 13.3

Earlier, the BPB comprised of entries only up to the entry ‘Hidden


sectors’ in Figure 13.2. For example, it didn’t contain the ‘Volume
label’ of the disk. This used to get stored as a directory entry in the
directory sectors. However, now the BPB has been extended to
include entries like ‘Volume label, ‘Volume ID’, ‘File system
type’, etc. The BPB is now called ‘Extended BPB’. Whether the
boot sector contains BPB or Extended BPB is indicated by the
value of the entry ‘Boot signature’. If it contains a value 29h then
the disk has an Extended BPB.

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.

A 1.44 MB disk supports a 12-bit FAT system. The total number


of sectors on this disk is 2880. This value is stored in the entry
‘Total Sectors’. There is another entry in the boot parameters
called ‘Huge Sectors’. For a 12-bit FAT System, this entry has a
Chapter 13: Disk Basics 197
value 0. For bigger capacity hard disks the value of total number
of sectors would be much more than what can be accommodated
in the 2-byte entry called ‘Total Sectors’. Hence for such disks this
entry contains a value 0 and the total number of sectors value is
stored in the entry ‘Huge Sectors’.

Let us now take a look at the 32-bit FAT system’s boot sector
contents. These are shown in Figure 13.4.

Description Length Typical Values

Jump instruction 3 EB5890


OEM name 8 MSWIN4.1
Bytes per sector 2 512
Sectors per cluster 1 8
Reserved sectors 2 51
Number of FAT copies 1 2
Root directory entries 2 0
Total sectors 2 0
Media descriptor 1 F8
Sectors per FAT 2 0
Sectors per track 2 63
No. of sides 2 255
Hidden sectors 2 63
High word of hidden sectors 4 63
Huge sectors 4 4192902
High word of huge sectors 2 4192902
Sectors per FAT 2 4095
High word of sectors per FAT 2 4095
Drive description flag 2 0
File system version 2 0
198 Let Us C

continued…
…continued

Root directory starting cluster 2 2


High word of root directory 2 2
starting cluster
File system information sector 2 1
Back up boot sector 2 6
Reserved 6 0
BIOS drive number 1 128
Reserved 1 0
Boot signature 1 41
Volume ID 4 649825316
Volume label 11 ICIT
File system type 8 FAT32

Figure 13.4

There are significant changes in the contents of the boo t sector of


a 32-bit FAT system. The entries ‘Number of hidden sectors’ and
‘Huge sectors’ have now been made 4-byte entries. The first two
bytes contain the low word of the value, whereas, the next two
bytes contain the high word value. The actual value of the entry
can be obtained by using bitwise operators that would be discussed
in Chapter 18.

The number of sectors per FAT in a 32-bit file system is likely to


exceed what can be accommodated in two bytes. Hence the entry
‘Sectors per FAT’ for a disk with a 32-bit file system would
typically have a value 0. The value of ‘Sectors per FAT’ is now
stored as a 4-byte entity, with the similar arrangement of low word
and high word as discussed earlier.
Chapter 13: Disk Basics 199
The boot sector of a 32-bit FAT system also has new entries like
‘Drive description flag’, ‘File system version’ ‘Starting cluster
number of the root directory’, ‘Sector number of the file system
information sector’, and the sector number of the ‘Backup boot
sector’.

The ‘Drive description flag’ is a two-byte entity. Bit 8 of this flag


indicates whether or not the information written to the active FAT
will be written to all copies of the FAT. The low four bits of this
entry contains the 0-based FAT number of the active FAT. These
bits are meaningful only if bit 8 is set.

In the entry ‘File system version number’ the high byte contains
the major version number, whereas, the low byte contains the
minor version number.

The entry ‘File system information sector’ contains a value


indicating the sector number where the file system information is
present. This file system information consists of the fields shown
in Figure 13.5.

Description Length

File system signature 4


Total number of free clusters 4
Sector number of the next free cluster 4
Reserved 6

Figure 13.5

The entry ‘File information sector’ contains a value OFFFFh if


there is no such sector. The entry ‘Backup boot sector’ contains a
value 0FFFFh is there is no backup boot sector. Otherwise this
value is any non-zero value less than the reserved sector count.
200 Let Us C

The Root Directory


The root directory of a 1.44 MB disk containing a 12-bit FAT
system occupies 14 sectors. For other FAT systems this number
may vary. The directory sectors contain 32-byte entries for various
files/sub-directories present in the root directory. Since each entry
is of 32 bytes, one directory sector can accommodate 16 such
entries. As there are 14 directory sectors on a 1.44 MB disk, there
can be a maximum of 224 entries (16 *14) in the root directory.
This value is stored in one of the boot parameters.

Each 32-byte entry contains either a filename or a sub-directory


name. If it is a file entry then it contains information about file’s
name, its size, attributes, starting location on the disk, etc. This
information is organized as shown is Figure 13.6.

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

Note the following points.


(a) File name can be less than or equal to 8 characters. If it is
less than 8 characters long then it is padded with blanks
on the right. Since Windows 95 we are permitted to use
long file names. How these are accommodated is a 32-
byte entry is discussed in the next section.
(b) Extension or the family name can be maximum 3
characters long. If it less than 3 characters it is padded
with blanks. While a filename must have at least one
character, the extension can be all blanks.
(c) In the attribute byte each bit represents either the type of
the file or whether the entry is a sub-directory entry. The
meaning of each bit is given in Figure 13.7.

Bit numbers Meaning


7 6 5 4 3 2 1 0
. . . . . . . 1 Read Only
. . . . . . 1 . Hidden
. . . . . 1 . . System
. . . . 1 . . . Volume label entry
. . . 1 . . . . Sub-directory entry
. . 1 . . . . . Archive bit
. 1 . . . . . . Unused
1 . . . . . . . Unused

Figure 13.7

If bit 0 is set to 1 then the file can only be read, it cannot be


modified or deleted.
202 Let Us C
If bit 1 is 1 then the file is hidden and will not be shown in the
directory. Vice versa, if bit 1 is 0, then the file will be shown
in the directory as a normal file.

If bit 2 is 1, it means the file is an operating system file. Bit 4


identifies the entry as a sub-directory name.

Bit 5 is called an archive bit. It helps avoid taking backups of


files that have already been backed up. OS sets the archive bit
to 1 whenever a file is created or modified. On backing up this
file using the BACKUP command, its archive bit is set to 0.
Suppose we do not modify this file before we take the next
backup. So its archive bit would remain 0. If we now take a
backup, this file won’t be backed up (saving precious time)
since its archive bit is still 0. However, if we modify the file
before the next backup, its archive bit would be set to 1 and
would now qualify for backing up.
(d) Following the attribute byte, there is 1 unused byte set
aside for possible future use. All six bytes are usually set
to 0.
(e) Each directory entry maintains three dates—date of
creation, date of modification and date of last access.
There are also entries showing time of creation or last
modification. All these entries occupy 2 bytes each.
Suppose the date of creation of a file is 10/12/99 and time
of creation is 10:30:45. Such a date and time can be
stored as two strings of 8 bytes each. However, in the 32-
byte entry (refer Figure 13.6) these are shown to occupy
2 bytes each. How do these 8-byte strings get converted
into 2-byte entries? The operating system applies
formulae on the date and time to reduce them to 2-byte
entities. The conversion formula for date and time are
discussed in Chapter 18.
Chapter 13: Disk Basics 203
(f) The starting cluster number indicates the place where the
file begins in the data space of the disk. This field
occupies 2 bytes in the 32-byte directory entry. In a 32-
bit FAT system the starting cluster number is likely to be
bigger than what can be accommodated in a 2-byte entry.
Hence for 32-byte FAT system the starting cluster
number entry is broken up into two parts of two bytes
each. One part is stored in the ‘Starting cluster number’
field. The other part is stored in the 2-byte field
immediately following the field ‘Last access date’. This
field contains the high word of the starting cluster
number.
(g) The file size field contains the exact file size in bytes.

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

Alias for long


filename
Chapter 13: Disk Basics 205
Figure 13.9

While displaying the directory containing a long filename how


would the OS come to know over how many 32-bytes entries is the
filename distributed? This is simple to determine. All the entries
belonging to a long filename would have in their attribute byte a
value Fh. Also, all the entries belonging to this filename would
have the same check sum. In our case, the sequence byte of the
four directory entries required for the filename would have the
values D, 3, 2 and 1 respectively. Note that the first of these values
is obtained by bitwise ORing it with 64.

The Data Space


All files and sub-directories are stored in this area. It occupies the
last and largest part of each disk. OS allocates space to files one
cluster at a time. Remember that a cluster is nothing but a group of
sectors that OS allocates to a file at a time. How many sectors,
form a cluster depends upon how the disk has been formatted.

As a file is being created, or an existing file is extended, the file’s


allocated space grows. When more space is needed, OS allocates
another cluster for the file.

Under ideal conditions a file is stored under one contiguous block


of space. However, a file might be broken into several non-
contiguous blocks. This happens if information is added to an
existing file or a new file is stored in the space left by an erased
file. So don’t be surprised if one file is scattered throughout the
disk. This file fragmentation slows down the access to the file’s
contents to some degree.

The File Allocation Table


The File Allocation Table (FAT) maps the usage of the data space
of the disk. It contains information about the space used by each
206 Let Us C
individual file, the unused disk space and the space that is
unusable due to defects in the disk. Since FAT contains vital
information, two copies of FAT are usually stored on the disk. In
case one gets destroyed, the other can be used. A typical FAT
entry can contain any of the following:
− Unused cluster
− Reserved cluster
− Bad cluster
− Last cluster in the file
− Next cluster number in the file
There is one entry in the FAT for each cluster in the file area. If
the value in a FAT entry doesn’t mark an unused, reserved or
defective cluster, then the cluster corresponding to the FAT entry
is part of a file, and the value in the FAT entry would indicate the
next cluster in the file.

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

32-byte directory entry


ICIT PRG 0003

starting cluster no.

0000 0005 0000 0006 0008 0000 FFFF 0000


0 1 2 3 4 5 6 7 8 9 10 11
FAT Chain

Figure 13.10

This file occupies cluster number 3, 5, 6 and 8 on the disk. Hence


the starting cluster number in the directory entry for the file is 3.
Suppose this file is to be loaded into memory then OS would first
load starting cluster number—3’s contents into memory. To find
out the next cluster belonging to this file OS looks at entry number
3 in FAT where it finds a value 5. Therefore, now it loads the
contents of cluster number 5 into memory. Once again OS looks at
the FAT and finds in entry number 5 a value 6, hence it loads the
contents of cluster 6 into memory. This process goes on till the OS
finds an entry FFFFh in FAT, which indicates that there are no
more clusters belonging to the file. Hence the process stops.

Now that we have understood how the FAT chain is traversed,


let’s dig a little deeper into the FAT. The entries present in FAT
are 12, 16 or 32 bits long depending on the storage capacity of the
disk. Though a 12-bit FAT can handle 4096 clusters only 4078
clusters are available for use since some values are reserved.
Similarly, for a 16-bit FAT out of the possible 65536 clusters that
it can handle only 65518 are available for use.
208 Let Us C
In a 12-bit FAT three bytes form two entries. The first two entries
(0 and 1) in the FAT are reserved for use by the OS. This means
that first 3 bytes in a 12-bit FAT, first 4 bytes in 16-bit FAT and
first 8 bytes in a 32-bit FAT are not used for storing cluster
numbers. Out of these 3 (or 4, or 8) bytes, the first byte is the
media descriptor byte and the balance contain the value FFh.
These balance bytes remain unused. The media descriptor byte
specifies the type of the disk. It typically has a value FDh, F9h,
F0h, F8h for a 360 KB floppy disk, 1.2 MB floppy disk, 1.44 MB
floppy disk and a hard disk respectively. The contents of a FAT
entry are interpreted as shown in Figure13.11.

Values Meaning

12-bit 16-bit 32-bit

000h 0000h 0000000h Cluster available


FF0h–FF6h FFFFh– FFFFFFFh– Reserved cluster
FFFF6h FFFFFF6h
FF7h FFF7h FFFFFF7h Bad cluster if not part
of chain
FF8h–FFFh FFF8h– FFFFFF8h– Last cluster of file
FFFFh FFFFFFFh
xxx xxxx xxxxxxx Next cluster in file

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.

How Fixed Disks Differ


Physically, there is more than one platter in a fixed disk. Still, data
is organized on fixed disks by track (cylinder), head, and sector
number, just as it is on floppy disks.

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

C++ programs MS-Word C programs


sub-directory sub-directory sub-directory

Letters Documents
sub-directory sub-directory
210 Let Us C
Figure 13.12

A sub-directory is stored in the disk’s data space, just like any


other file. The entries in the sub-directory are identical to those in
the root directory, except that a sub-directory is not limited in size.
Like an ordinary file, a sub-directory can grow without bounds as
long as there is disk space available. Sub-directories can be created
with any type of disk. However, since sub-directories take up
precious data space, they are primarily intended for use with high-
capacity hard disks; their use with floppy disks are usually
avoided.

Since the storage capacity of a fixed disk is relatively large, some


users prefer to split the disk into logical parts and then store
different Operating Systems in different logical parts. This is
called partitioning of fixed disk. As many as four partitions are
allowed on a hard disk. Each partition’s data can be kept
completely separate from the data in the other partitions. Each
partition can contain its own boot sector and operating system.

Unlike floppy diskettes, side 0, track 0, sector 1 of the fixed disk


contains a partition table and a master boot program. The partition
table is 64 bytes long. It contains information about where each
partition is located on the disk. The partition table also indicates
which is the bootable partition. If the hard disk is divided into two
partitions—one for DOS/Windows and another for Linux/Unix.
The DOS / Windows partition is divided into Boot Sector, FAT,
Directory and Data Space, whereas, the Unix partition is divided
into four logical parts, namely, Boot Block, Super Block, Inode
Table and Data Blocks. Depending upon which partition has been
marked as bootable in the partition table that partition Boot Sector
contents are used to boot under that partitions operating system.

One Last Thing about Disks


Chapter 13: Disk Basics 211
Just to make our life that much more difficult, the way ROM-
BIOS refers individual sector on a disk is different than the way
DOS/Windows refers it. The ROM-BIOS functions refer sectors
by their three dimensional locations (side number, track number
and sector number), whereas, DOS/Windows refers them by their
sequential logical sector numbers.

While using BIOS services remember that,


− Tracks are numbered from outermost track, increasing
towards the innermost track, starting with 0.
− Sides are also numbered from 0 onwards.
− Sectors are numbered from 1 onwards.
Thus any location on the disk can be referred to by a unique
combination of side, track and sector number.

DOS/Windows however doesn’t recognize sides, tracks and


sectors. Instead, they see a disk as a linear sequence of logical
sectors. The sequence of logical sectors begins with the first sector
on the disk—side 0, track 0, sector 1 (boot sector) is
DOS/Windows logical sector 0. Similarly, side 0, track 0, sector 2
is DOS/Windows logical sector 1 and so on. Note that, the last
sector in side 0, track 0 is followed by first sector in side 1, track 0
and so on.

Conversion of a sector number from BIOS to DOS/Windows or


vice versa can be done using following formulae.

DOS/Win sector number = ( BIOS sector no - 1 )


+ ( BIOS side * sectors / track )
+ ( BIOS track * sectors per track *
sides per disk )

BIOS sector = ( 1 + DOS/Win sector number ) %


( sectors per track )
212 Let Us C
BIOS track = ( DOS/Win sector no. / ( sectors per track
* sides per disk )
BIOS side = ( DOS/Win sector no. / sectors per track ) %
( sides per disk )

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.

There exit different types of CDs. They are:


(a) Audio CD holding only music
(b) Video CD storing movie
(c) Data CD containing files stored in a file system
The audio CD, that you purchase from the market or the CDs that
you get with book/magazine are mass-produced (commercial) CDs
and are made up of aluminum coated plastic. There are dedicated
CD players that play only audio CDs or only video CDs. However,
the CD drive present in computer system is capable of reading
audio, video as well as data CDs.

We can only use the commercially available CDs, we cannot write


anything new on them. If you copy the contents of an audio CD
into a CD-R (R for recordable) type disk (blank disk that you get
in market) then you can play this CD only in those CD drives that
support CD-R type disks. CD drives of computer systems do
support this type. Most CD players present in music systems don’t
support this type. However, some of the newer audio systems have
started supporting this type of disk.

The CD that comes with a book/magazine is a commercial Data


CD. If we copy its contents on a CD-R disk then at a later date we
can copy new data to it. This is facilitated through a concept called
Chapter 13: Disk Basics 213
sessions. Note that when we write new data, earlier data doesn’t
get overwritten. The new data is merely added at the end of
existing data.

There also exist rewritable CDs (CD-RW) that work similar to a


floppy in the sense that we can write data to them any number of
times. We can reformat this disk and overwrite all existing
contents with new contents. The writing on CD-R or CD-RW is
done on a special drive called CD Writer. This drive can also read
a CD. Slowly the CD drives present in computer systems are being
replaced by CD writers.

The information stored on a CD can be organized in a variety of


formats. The different popular formats are:
(a) CD Audio
(b) CD ROM (Compact Disc Read Only Memory)
(c) CD-I (Compact Disc Interactive)
(d) CD-ROM/XA (CD-ROM Extended Architecture)
The data CD uses the CD-ROM format for organizing data. This
format specifies parameters like capacity (usually 650 Mb), sector
size, data transfer rate, rate at which sectors are read (if the reading
is done at the 75 sectors/sec then it is known as a 1X CD, if it is
done at 150 sectors/sec then it is known as 2X CD and so on).

The organization of files and directories on a Data CD is done as


per ISO 9660 format. A Data CD has one single track in the form a
spiral with several blocks (known as sectors) along this track.

ISO 9660 format logically organizes the CD in three main parts—


the Volume Descriptor, the Directory Structure, and the Path
Table. These parts are interrelated as shown in Figure 13.13.
214 Let Us C

PVT Path Table


Root
Path Table
Sub1
Root
RootDirectory
Directory
Sub2
Root Sub3

Sub1 Sub2 Sub3 Sub4


Sub1 Sub2 Sub3

Sub4
Sub4 file1,
file1,file2
file2
Directory Structure

Figure 13.13

Let us now find understand the functionality of each part of the


logical structure of the CD ROM.

Primary Volume Descriptor


The Primary Volume Descriptor begins at sector number 16.
Sectors prior to this sector forms the Boot Record. The Boot
Record can be used for systems that must perform some type of
initialization before the user can access the disk. The Volume
Descriptor tells us where the Directory structure and the Path
Table are located, the Directory tells us where the actual files are
located, and the Path Table gives us shortcuts to each directory.
Chapter 13: Disk Basics 215
The Directory Structure
The ISO 9660 directory structure is organized in a hierarchical
manner. At the top of the hierarchy is the Root Directory, the
location of which is identified in the Primary Volume Descriptor.
When drawn hierarchically, the directory structure resembles the
roots of a tree, with the Root directory at the top of the structure,
as shown in Figure 13.13.

As shown in Figure 13.13, there are distinct levels in this


hierarchy. The Root Directory is the only directory at level 1. In
the example illustrated by Figure 13.13, subdirectories Sub1, Sub2
and Sub3 are at level 2, subdirectory Sub4 and the files file1 and
file2 are at level 3. To ensure compatibility, ISO 9660 imposes a
limit of eight levels to the depth of the directory structure.

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.

The Path Table


The Path Table indicates the shortcut to each directory on the disc
rather than making the program read through each directory to get
to the file it needs. This is done primarily to enhance performance.
For each directory other than the Root directory, the path table
contains a record that identifies the directory, its parent directory,
and its location.

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

S-ar putea să vă placă și