Lecture # 38: System Programming Course Code: CS609 Cs609@vu - Edu.pk
Lecture # 38: System Programming Course Code: CS609 Cs609@vu - Edu.pk
Lecture # 38
Following slide shows how the chain of clusters is maintained in a FAT32 based system.
File Organization
32 – 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^28
Fat32 Entry
• Each entry is of 32-bits size but only
lower 28-bits are used.
• Higher 4-bits are not tempered.
• While reading higher 4-bits are
ignored.
• While writing higher 4-bits are not
changed.
FCB in FAT32 system has an enhanced meaning as shown by the slide below.
Anatomy of FAT32 based system differs from FAT16 based systems significantly as
explained by the slide below.
Reserved Blocks
• No fixed space reserved for root
directory.
• FCB of root directory are saved in a
cluster and the cluster # for root directory
is saved in BPB as discussed earlier.
In reflection of the anatomy of FAT32 based system the method used to translate the
cluster # into LSN also varies. The following formula is used for this purpose.
Now we determine all the parameters in the above slide for a certain volume to translate a
cluster number into LSN.
0000 EB 58 90 4D
Reserved Blocks
53 57 49 4E . X . M S W I N 235 88 144 77 83 87 73 78
0008 34 2E 31 00 02 20 24 00 4 . 1 . . $ . 52 46 49 0 2 32 36 0
0010 02 00 00 00 00 F8 00 00 . . . . . . . . 2 0 0 0 0 248 0 0
0018 3F 00 F0 00 3F 00 00 00 ? . . . ? . . . 63 0 240 0 63 0 0 0
0020 41 29 54 02 3E 25 00 00 A ) T . > % . . 65 41 84 2 62 37 0 0
0028 00 00 00 00 02 00 00 00 . . . . . . . . 0 0 0 0 2 0 0 0
0030 01 00 06 00 00 00 00 00 . . . . . . . . 1 0 6 0 0 0 0 0
0038 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 0
0040 80 01 29 F1 17 79 2D 4E . . ) . . y - N 128 1 41 241 23 121 45 78
0048 4F 20 4E 41 4D 45 20 20 O N A M E 79 32 78 65 77 69 32 32
0050 20 20 46 41 54 33 32 20 F A T 3 2 32 32 70 65 84 51 50 32
0058 20 20 33 C9 8E D1 BC F4 3 . . . . . 32 32 51 201 142 209 188 244
0060 7B 8E C1 8E D9 BD 00 7C { . . . . . . | 123 142 193 142 217 189 0 124
0068 88 4E 02 8A 56 40 B4 08 . N . . V @ . . 136 78 2 138 86 64 180 8
0070 CD 13 73 05 B9 FF FF 8A . . s . . . . . 205 19 115 5 185 255 255 138
0078 F1 66 0F B6 C6 40 66 0F . f . . . @ f . 241 102 15 182 198 64 102 15
0080 B6 D1 80 E2 3F F7 E2 86 . . . . ? . . . 182 209 128 226 63 247 226 134
0088 CD C0 ED 06 41 66 0F B7 . . . . A f . . 205 192 237 6 65 102 15 183
0090 C9 66 F7 E1 66 89 46 F8 . f . . f . F . 201 102 247 225 102 137 70 248
0098 83 7E 16 00 75 38 83 7E . ~ . . u 8 . ~ 131 126 22 0 117 56 131 126
0000 EB 58 90 4D 53
Copies of FAT
57 49 4E . X . M S W I N 235 88 144 77 83 87 73 78
0008 34 2E 31 00 02 20 24 00 4 . 1 . . $ . 52 46 49 0 2 32 36 0
0010 02 00 00 00 00 F8 00 00 . . . . . . . . 2 0 0 0 0 248 0 0
0018 3F 00 F0 00 3F 00 00 00 ? . . . ? . . . 63 0 240 0 63 0 0 0
0020 41 29 54 02 3E 25 00 00 A ) T . > % . . 65 41 84 2 62 37 0 0
0028 00 00 00 00 02 00 00 00 . . . . . . . . 0 0 0 0 2 0 0 0
0030 01 00 06 00 00 00 00 00 . . . . . . . . 1 0 6 0 0 0 0 0
0038 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 0
0040 80 01 29 F1 17 79 2D 4E . . ) . . y - N 128 1 41 241 23 121 45 78
0048 4F 20 4E 41 4D 45 20 20 O N A M E 79 32 78 65 77 69 32 32
0050 20 20 46 41 54 33 32 20 F A T 3 2 32 32 70 65 84 51 50 32
0058 20 20 33 C9 8E D1 BC F4 3 . . . . . 32 32 51 201 142 209 188 244
0060 7B 8E C1 8E D9 BD 00 7C { . . . . . . | 123 142 193 142 217 189 0 124
0068 88 4E 02 8A 56 40 B4 08 . N . . V @ . . 136 78 2 138 86 64 180 8
0070 CD 13 73 05 B9 FF FF 8A . . s . . . . . 205 19 115 5 185 255 255 138
0078 F1 66 0F B6 C6 40 66 0F . f . . . @ f . 241 102 15 182 198 64 102 15
0080 B6 D1 80 E2 3F F7 E2 86 . . . . ? . . . 182 209 128 226 63 247 226 134
0088 CD C0 ED 06 41 66 0F B7 . . . . A f . . 205 192 237 6 65 102 15 183
0090 C9 66 F7 E1 66 89 46 F8 . f . . f . F . 201 102 247 225 102 137 70 248
0098 83 7E 16 00 75 38 83 7E . ~ . . u 8 . ~ 131 126 22 0 117 56 131 126
0000 EB 58 90
Sector per FAT copy
4D 53 57 49 4E . X . M S W I N 235 88 144 77 83 87 73 78
0008 34 2E 31 00 02 20 24 00 4 . 1 . . $ . 52 46 49 0 2 32 36 0
0010 02 00 00 00 00 F8 00 00 . . . . . . . . 2 0 0 0 0 248 0 0
0018 3F 00 F0 00 3F 00 00 00 ? . . . ? . . . 63 0 240 0 63 0 0 0
0020 41 29 54 02 3E 25 00 00 A ) T . > % . . 65 41 84 2 62 37 0 0
0028 00 00 00 00 02 00 00 00 . . . . . . . . 0 0 0 0 2 0 0 0
0030 01 00 06 00 00 00 00 00 . . . . . . . . 1 0 6 0 0 0 0 0
0038 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 0
0040 80 01 29 F1 17 79 2D 4E . . ) . . y - N 128 1 41 241 23 121 45 78
0048 4F 20 4E 41 4D 45 20 20 O N A M E 79 32 78 65 77 69 32 32
0050 20 20 46 41 54 33 32 20 F A T 3 2 32 32 70 65 84 51 50 32
0058 20 20 33 C9 8E D1 BC F4 3 . . . . . 32 32 51 201 142 209 188 244
0060 7B 8E C1 8E D9 BD 00 7C { . . . . . . | 123 142 193 142 217 189 0 124
0068 88 4E 02 8A 56 40 B4 08 . N . . V @ . . 136 78 2 138 86 64 180 8
0070 CD 13 73 05 B9 FF FF 8A . . s . . . . . 205 19 115 5 185 255 255 138
0078 F1 66 0F B6 C6 40 66 0F . f . . . @ f . 241 102 15 182 198 64 102 15
0080 B6 D1 80 E2 3F F7 E2 86 . . . . ? . . . 182 209 128 226 63 247 226 134
0088 CD C0 ED 06 41 66 0F B7 . . . . A f . . 205 192 237 6 65 102 15 183
0090 C9 66 F7 E1 66 89 46 F8 . f . . f . F . 201 102 247 225 102 137 70 248
0098 83 7E 16 00 75 38 83 7E . ~ . . u 8 . ~ 131 126 22 0 117 56 131 126
0000
Cluster # for Root Directory
EB 58 90 4D 53 57 49 4E . X . M S W I N 235 88 144 77 83 87 73 78
0008 34 2E 31 00 02 20 24 00 4 . 1 . . $ . 52 46 49 0 2 32 36 0
0010 02 00 00 00 00 F8 00 00 . . . . . . . . 2 0 0 0 0 248 0 0
0018 3F 00 F0 00 3F 00 00 00 ? . . . ? . . . 63 0 240 0 63 0 0 0
0020 41 29 54 02 3E 25 00 00 A ) T . > % . . 65 41 84 2 62 37 0 0
0028 00 00 00 00 02 00 00 00 . . . . . . . . 0 0 0 0 2 0 0 0
0030 01 00 06 00 00 00 00 00 . . . . . . . . 1 0 6 0 0 0 0 0
0038 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 0
0040 80 01 29 F1 17 79 2D 4E . . ) . . y - N 128 1 41 241 23 121 45 78
0048 4F 20 4E 41 4D 45 20 20 O N A M E 79 32 78 65 77 69 32 32
0050 20 20 46 41 54 33 32 20 F A T 3 2 32 32 70 65 84 51 50 32
0058 20 20 33 C9 8E D1 BC F4 3 . . . . . 32 32 51 201 142 209 188 244
0060 7B 8E C1 8E D9 BD 00 7C { . . . . . . | 123 142 193 142 217 189 0 124
0068 88 4E 02 8A 56 40 B4 08 . N . . V @ . . 136 78 2 138 86 64 180 8
0070 CD 13 73 05 B9 FF FF 8A . . s . . . . . 205 19 115 5 185 255 255 138
0078 F1 66 0F B6 C6 40 66 0F . f . . . @ f . 241 102 15 182 198 64 102 15
0080 B6 D1 80 E2 3F F7 E2 86 . . . . ? . . . 182 209 128 226 63 247 226 134
0088 CD C0 ED 06 41 66 0F B7 . . . . A f . . 205 192 237 6 65 102 15 183
0090 C9 66 F7 E1 66 89 46 F8 . f . . f . F . 201 102 247 225 102 137 70 248
0098 83 7E 16 00 75 38 83 7E . ~ . . u 8 . ~ 131 126 22 0 117 56 131 126
0000 EB
Size of Cluster in Sectors
58 90 4D 53 57 49 4E . X . M S W I N 235 88 144 77 83 87 73 78
0008 34 2E 31 00 02 20 24 00 4 . 1 . . $ . 52 46 49 0 2 32 36 0
0010 02 00 00 00 00 F8 00 00 . . . . . . . . 2 0 0 0 0 248 0 0
0018 3F 00 F0 00 3F 00 00 00 ? . . . ? . . . 63 0 240 0 63 0 0 0
0020 41 29 54 02 3E 25 00 00 A ) T . > % . . 65 41 84 2 62 37 0 0
0028 00 00 00 00 02 00 00 00 . . . . . . . . 0 0 0 0 2 0 0 0
0030 01 00 06 00 00 00 00 00 . . . . . . . . 1 0 6 0 0 0 0 0
0038 00 00 00 00 00 00 00 00 . . . . . . . . 0 0 0 0 0 0 0 0
0040 80 01 29 F1 17 79 2D 4E . . ) . . y - N 128 1 41 241 23 121 45 78
0048 4F 20 4E 41 4D 45 20 20 O N A M E 79 32 78 65 77 69 32 32
0050 20 20 46 41 54 33 32 20 F A T 3 2 32 32 70 65 84 51 50 32
0058 20 20 33 C9 8E D1 BC F4 3 . . . . . 32 32 51 201 142 209 188 244
0060 7B 8E C1 8E D9 BD 00 7C { . . . . . . | 123 142 193 142 217 189 0 124
0068 88 4E 02 8A 56 40 B4 08 . N . . V @ . . 136 78 2 138 86 64 180 8
0070 CD 13 73 05 B9 FF FF 8A . . s . . . . . 205 19 115 5 185 255 255 138
0078 F1 66 0F B6 C6 40 66 0F . f . . . @ f . 241 102 15 182 198 64 102 15
0080 B6 D1 80 E2 3F F7 E2 86 . . . . ? . . . 182 209 128 226 63 247 226 134
0088 CD C0 ED 06 41 66 0F B7 . . . . A f . . 205 192 237 6 65 102 15 183
0090 C9 66 F7 E1 66 89 46 F8 . f . . f . F . 201 102 247 225 102 137 70 248
0098 83 7E 16 00 75 38 83 7E . ~ . . u 8 . ~ 131 126 22 0 117 56 131 126
So using all this information we calculate the LSN for cluster number 2 as shown the
slide below for this particular volume.
To examine the contents of a file first a file is created whose contents are also shown in
the slide.
Now we examine the contents of cluster number 2 which contains the root directory as
already seen in the previous slides.
Cluster # 2
From the information from above slides the low and high words of the first cluster
number is obtained and is shown in the slide below. The higher 4 bits of the cluster
number should be ignored as discussed earlier.
Using the cluster number above the LSN for this cluster is determined as shown in the
slide below.
The blocks within the cluster are read and their contents can be seen in the slide below.
File Data
Dump of LSN 19235712
In the FAT32 there is another special reserved block called FSInfo sector. The block
contains some information required by the operating system while cluster
allocation/deallocation to files. This information is also critical for FAT16 based systems.
But in FAT12 and 16 this information is calculated when ever required. This calculation
at the time of allocation is not feasible in FAT32 as the size of FAT32 is very large and
such calculations will consume a lots of time, so to save time this information is stored in
the FSInfo block and is updated at the time of allocation/deallocation.