Lecture # 34: Another Example With FAT16 Bit System

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

System Programming Course Code: CS609

Cs609@vu.edu.pk

Lecture # 34

Here is another example which examines the contents of a file for a FAT 16 system.
Firstly the DPB is read as shown In the following slide.

Another Example with FAT16 bit System


DPB Dump
-a
13AD:0100 mov ah,32
13AD:0102 int 21
13AD:0104

-p
AX=3200 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=13AD ES=13AD SS=13AD CS=13AD IP=0102 NV UP EI PL NZ NA PO NC
13AD:0102 CD21 INT 21

-p
AX=3200 BX=13D2 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=00A7 ES=13AD SS=13AD CS=13AD IP=0104 NV UP EI PL NZ NA PO NC
13AD:0104 D3E3 SHL BX,CL

-d a7:13d2
00A7:13D0 05 05 00 02 07 03-08 00 02 00 02 C0 01 B4 ..............
00A7:13E0 CB CC 00 A0 01 56 34 12-00 F8 0A FF FF FF FF 00 .....V4.........
00A7:13F0 00 98 CB 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00A7:1400 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00A7:1410 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00A7:1420 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00A7:1430 00 00 00 00 00 00 00 0C-00 00 80 00 B7 13 10 00 ................
00A7:1440 DF 12 4D 5A 9A 00 29 00-00 00 20 00 C5 00 FF FF ..MZ..)... .....
00A7:1450 A7 05 ..
-q

Once the DPB has been read the blocks reserved for root directory are determined and are
then read to get the contents of the root directory.

Directory Dump
-l 1000 5 1a0 20

-d 1000 4000
13AD:100 0 4E 45 57 20 56 4F 4C 55-4D 45 20 08 00 00 00 00 N EW VOL UME .. ...
13AD:101 0 00 00 00 00 00 00 61 76-2D 33 00 00 00 00 00 00 . .....a v-3... ...
13AD:102 0 41 52 00 65 00 63 00 79-00 63 00 0F 00 21 6C 00 A R.e.c. y.c... !l.
13AD:103 0 65 00 64 00 00 00 FF FF-FF FF 00 00 FF FF FF FF e .d.... ...... ...
13AD:104 0 52 45 43 59 43 4C 45 44-20 20 20 16 00 4E 79 5E R ECYCLE D .. Ny^
13AD:105 0 2F 33 2F 33 00 00 7A 5E-2F 33 02 00 00 00 00 00 / 3/3..z ^/3... ...
13AD:106 0 42 20 00 49 00 6E 00 66-00 6F 00 0F 00 72 72 00 B .I.n. f.o... rr.
13AD:107 0 6D 00 61 00 74 00 69 00-6F 00 00 00 6E 00 00 00 m .a.t.i .o...n ...
13AD:108 0 01 53 00 79 00 73 00 74-00 65 00 0F 00 72 6D 00 . S.y.s. t.e... rm.
13AD:109 0 20 00 56 00 6F 00 6C 00-75 00 00 00 6D 00 65 00 .V.o.l .u...m .e.
13AD:10A 0 53 59 53 54 45 4D 7E 31-20 20 20 16 00 4E 79 5E S YSTEM~ 1 .. Ny^
13AD:10B 0 2F 33 2F 33 00 00 7A 5E-2F 33 03 00 00 00 00 00 / 3/3..z ^/3... ...
13AD:10C 0 41 64 00 50 00 62 00 31-00 2E 00 0F 00 6A 74 00 A d.P.b. 1..... jt.
13AD:10D 0 78 00 74 00 00 00 FF FF-FF FF 00 00 FF FF FF FF x .t.... ...... ...
13AD:10E0 44 50 42 31 20 20 20 20-54 58 54 20 00 57 81 69 DPB1 TXT .W.i
13AD:10F0 36 33 36 33 00 00 07 78-36 33 0A 00 8A 06 00 00 6363...x63......
13AD:1100 44 50 42 32 20 20 20 20-54 58 54 20 18 12 AE 69 DPB2 TXT ...i
13AD:1110 36 33 36 33 00 00 03 75-36 33 0B 00 5F 06 00 00 6363...u63.._...
13AD:1120 46 49 52 53 54 20 20 20-20 20 20 10 08 6F ED 56 FIRST ..o.V
13AD:1130 3C 33 3C 33 00 00 EE 56-3C 33 0C 00 00 00 00 00 <3<3...V<3......
13AD:1140 53 45 43 4F 4E 44 20 20-20 20 20 10 08 50 EF 56 SECOND ..P.V
13AD:1150 3C 33 3C 33 00 00 F0 56-3C 33 12 00 00 00 00 00 <3<3...V<3......

Virtual University of Pakistan 17


System Programming Course Code: CS609
Cs609@vu.edu.pk

The root directory contains a collection of FCBs. The FCB for the file in question is
searched from where the first cluster of the file can be get.

Cont…
13AD:12C0 43 50 41 50 45 52 20 20-54 58 54 20 00 9D 7D 6F CPAPER TXT ..}o
13AD:12D0 3C 33 3C 33 00 00 60 05-72 28 29 00 4F 8F 00 00 <3<3..`.r().O...
13AD:12E0 E5 6D 00 65 00 6E 00 74-00 2E 00 0F 00 9F 74 00 .m.e.n.t......t.
13AD:12F0 78 00 74 00 00 00 FF FF-FF FF 00 00 FF FF FF FF x.t.............
13AD:1300 E5 4E 00 65 00 77 00 20-00 54 00 0F 00 9F 65 00 .N.e.w. .T....e.
13AD:1310 78 00 74 00 20 00 44 00-6F 00 00 00 63 00 75 00 x.t. .D.o...c.u.
13AD:1320 E5 45 57 54 45 58 7E 31-54 58 54 20 00 32 09 73 .EWTEX~1TXT .2.s
13AD:1330 3C 33 3C 33 00 00 0A 73-3C 33 00 00 00 00 00 00 <3<3...s<3......
13AD:1340 54 45 53 54 20 20 20 20-54 58 54 20 18 32 09 73 TEST TXT .2.s
13AD:1350 3C 33 3C 33 00 00 17 73-3C 33 45 00 27 00 00 00 <3<3...s<3E.'...

File Contents
File Size = 39D =27H
File Cluster # = 45H
File Sec # = (45H – 2 )*8 + 01C0 = 3D8H

After calculating the sector number for the cluster the contents of the file can be accessed
by reading all the blocks within the cluster. In this way only the starting cluster will be
read. If the file contains a number of cluster the subsequent clusters numbers within the
file chain can be accessed from the FAT.

File Dump
-l 1000 5 3d8 8

-d 1000

13AD:1000 74 68 69 73 20 69 73 20-61 20 74 65 73 74 20 74 this is a test t


13AD:1010 65 78 74 20 66 69 6C 65-20 66 6F 72 20 31 36 20 ext file for 16
13AD:1020 62 69 74 20 46 41 54 00-00 00 00 00 00 00 00 00 bit FAT.........
13AD:1030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
13AD:1040 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
13AD:1050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
13AD:1060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
13AD:1070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
-q

Virtual University of Pakistan 18


System Programming Course Code: CS609
Cs609@vu.edu.pk

Larger File Contents


• Larger files would be comprised of numerous
clusters.
• The first Cluster # can be read from FCB for rest
of the Cluster, a chain is maintained within the FAT.

FAT12
• FAT is a simple table which contains cluster
number of each file.
• FAT12 will have 12-bit wide entries and can have
2^12 entries maximum.
• Although some of these entries may be reserved.

Virtual University of Pakistan 19


System Programming Course Code: CS609
Cs609@vu.edu.pk

File Organization
12 – bit
0 R
1 R FCB
2
3
4 7
Start Cluster #
5 0
6 11
7 9

Cont…
8
9 6
10
11 EOF

2^12

Above slides show how a cluster chain for a file is maintained in the FAT. The first
cluster number is in the FCB. Subsequent clusters will be accessed from the FAT using
the previous cluster number as index to look up into the FAT for the next cluster number.

Virtual University of Pakistan 20


System Programming Course Code: CS609
Cs609@vu.edu.pk

A FAT theoretically will contain 2n entries where n is 12 for FAT 12 and 16 for FAT16.
But all the entries are not used some of the entries are reserved following slide shows its
detail.

Unused FAT Entries


• Reserved Entries = FF0H ~ FF6H

• EOF value = FF7H ~ FFFH

• First Two Clusters = 0,1

• Free Cluster =0

• Max. range of Cluster # = 2 ~ FEFH

• Total # of Clusters of FAT12 = FEEH

Cluster Size Determination


tempof = size of disk / no. of entries in FAT (FEEH)
if ( temp > 32768)
use higher FAT16 or FAT32
else
{
choose the nearest value + temp greater than
temp, which is a power of 2,
Set this to be the Cluster size = bytes
Size of Cluster in Blocks =
Cluster size in Bytes / Bytes per Block
}
No. of Entries of FAT =
No. of Blocks in disk in User Data Area / Size
of Cluster in Blocks.

There can various volume with various sizes with FAT12 or FAT16. The number of
entries for FAT 12 or FAT16 are limited then the question arises how can a certain volume
with moderate space and another volume with large space can be managed by the same
FAT system. The answer is that the number of entries might be same but the size of
cluster may be different. The cluster size can vary from 512 bytes to 32K in powers of 2
Virtual University of Pakistan 21
System Programming Course Code: CS609
Cs609@vu.edu.pk

depending upon the volume size. The above slide shows how the cluster size and the
exact number of required FAT entries can be determined.

Virtual University of Pakistan 22

You might also like