📄 fat16 structure information.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0042)http://home.teleport.com/~brainy/fat16.htm -->
<HTML><HEAD><TITLE>FAT16 Structure Information</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2800.1276" name=GENERATOR></HEAD>
<BODY>
<P align=center><STRONG><U><BIG>FAT16 Structure Information - Written by Jack
Dobiash</BIG></U></STRONG></P>
<P align=center><EM><SMALL>Updated : June 17th, 1999</SMALL></EM></P>
<P>Looking for FAT32 Info? Go <A
href="http://www.teleport.com/~brainy/fat32.htm">here</A>.<BR>Looking for
Informaton on how to Read and Write to your Hard Drive? Go <A
href="http://www.teleport.com/~brainy/diskaccess.htm">here</A>.</P>
<P>I've written this page for anyone who wishes to write software that can do
low-level reading and writing of a hard drive, and needs to know what the
underlying structure of a FAT16 Drive is, in order to interpret the information
properly. Basically I've searched all over the web, and have compiled this
information in one spot. Hopefully it can be of use to
someone. I don't guarantee that all of this information is correct or
complete, but so far is seems to have been working for me. </P>
<P>A lot of the number references I've made in this document are in
Hexadecimal. Any that are have an 'h' after them. Also, just in case
my terminology may be different from yours; a 'WORD' is 2 Bytes and a 'DOUBLE
WORD' is 4 Bytes.</P>
<P> </P>
<P><U><STRONG>Master Boot Record</STRONG></U></P>
<BLOCKQUOTE>
<P>The Master Boot Record is the same for pretty much all Operating
Systems. It is located on the first Sector of the Hard Drive, at
Cylinder 0, Head 0, Sector 1. It is the first piece of code that your
computer runs after it has checked all of your hardware (POST) and turned
control of loading software over the hard drive. It also contains the
partition table, which defines the different sections of your hard
drive. Basically if anything happens to this little 512 byte section,
your hard drive is brain dead. Kinda scary, eh? :)</P></BLOCKQUOTE>
<DIV align=left>
<TABLE height=79 width=455 border=1>
<TBODY>
<TR>
<TD width=44 height=25>Offset</TD>
<TD width=269 height=25>Description</TD>
<TD width=52 height=25>Size</TD></TR>
<TR>
<TD width=44 height=25>000h</TD>
<TD width=269 height=25>Executable Code (Boots Computer)</TD>
<TD width=52 height=25>446 Bytes</TD></TR>
<TR>
<TD width=44 height=22>1BEh</TD>
<TD width=269 height=1>1st Partition Entry (See Next Table)</TD>
<TD width=52 height=22>16 Bytes</TD></TR>
<TR>
<TD width=44 height=17>1CEh</TD>
<TD width=269 height=17>2nd Partition Entry</TD>
<TD width=52 height=17>16 Bytes</TD></TR>
<TR>
<TD width=44 height=12>1DEh</TD>
<TD width=269 height=12>3rd Partition Entry</TD>
<TD width=52 height=12>16 Bytes</TD></TR>
<TR>
<TD width=44 height=20>1EEh</TD>
<TD width=269 height=20>4th Partition Entry</TD>
<TD width=52 height=20>16 Bytes</TD></TR>
<TR>
<TD width=44 height=16>1FEh</TD>
<TD width=269 height=16>Executable Marker (55h AAh)</TD>
<TD width=52 height=16>2 Bytes</TD></TR></TBODY></TABLE></DIV>
<P><BR><STRONG>Partition Entry (Part of MBR)</STRONG></P>
<DIV align=left>
<TABLE height=236 width=523 border=1>
<TBODY>
<TR>
<TD width=47 height=7>Offset</TD>
<TD width=328 height=7>Description</TD>
<TD width=130 height=7>Size</TD></TR>
<TR>
<TD width=47 height=8>00h</TD>
<TD width=328 height=8>Current State of Partition (00h=Inactive,
80h=Active)</TD>
<TD width=130 height=8>1 Byte</TD></TR>
<TR>
<TD width=47 height=18>01h</TD>
<TD width=328 height=18>Beginning of Partition - Head</TD>
<TD width=130 height=18>1 Byte</TD></TR>
<TR>
<TD width=47 height=19>02h </TD>
<TD width=328 height=19>Beginning of Partition - Cylinder/Sector (See
Below)</TD>
<TD width=130 height=19>1 Word</TD></TR>
<TR>
<TD width=47 height=15>04h</TD>
<TD width=328 height=15>Type of Partition (See List Below)</TD>
<TD width=130 height=15>1 Byte</TD></TR>
<TR>
<TD width=47 height=13>05h</TD>
<TD width=328 height=13>End of Partition - Head</TD>
<TD width=130 height=13>1 Byte</TD></TR>
<TR>
<TD width=47 height=15>06h</TD>
<TD width=328 height=15>End of Partition - Cylinder/Sector</TD>
<TD width=130 height=15>1 Word</TD></TR>
<TR>
<TD width=47 height=22>08h</TD>
<TD width=328 height=22>Number of Sectors Between the MBR and the First
Sector in the Partition</TD>
<TD width=130 height=22>1 Double Word</TD></TR>
<TR>
<TD width=47 height=22>0Ch</TD>
<TD width=328 height=22>Number of Sectors in the Partition</TD>
<TD width=130 height=22>1 Double Word</TD></TR></TBODY></TABLE></DIV>
<P><BR><STRONG>Cylinder/Sector Encoding</STRONG></P>
<BLOCKQUOTE>
<P>I guess back in the days of 10MB hard drives and 8086's, code was at a
premium. So they did everything they could to preserve space.
Unfortunately now we have to live with it, but luckily they created new ways
of translating the system so the 1024 Cylinder Limit (2^10) isn't too big of a
problem, for newer computers, at least. Older ones usually need some
sort of Disk Overlay program to make them see the whole hard
drive. </P>
<P>Anyway, to get the Sector out of this, you need to apply an AND mask ($3F)
to it. To get the Cylinder, you take the high byte and OR it with the
low byte that has been AND masked with ($C0) and then Shifted Left Two.
It's not very easy to explain, so I'll just show you how I did it with two
routines I made (In Pascal) for Encoding and Decoding the
Cylinder/Sector. Hopefully even if you don't know Pascal you'll be able
to read it.</P>
<P>Function CylSecEncode(Cylinder, Sector : Word) :
Word;<BR>Begin<BR> CylSecEncode := (Lo(Cylinder) shl 8) or
(Hi(Cylinder) shl 6) or Sector;<BR>End;<BR><BR>Procedure CylSecDecode(Var
Cylinder, Sector : Word; CylSec : Word);<BR>Begin<BR>
Cylinder := Hi(CylSec) or ((Lo(CylSec) and $C0) shl 2);<BR>
Sector := (CylSec and $3F);<BR>End;<BR></P></BLOCKQUOTE>
<DIV align=left>
<TABLE height=48 width=418 border=1>
<TBODY>
<TR>
<TD width=10 height=23>15</TD>
<TD width=13 height=23>14</TD>
<TD width=18 height=23>13</TD>
<TD width=7 height=23>12</TD>
<TD width=12 height=23>11</TD>
<TD width=20 height=23>10</TD>
<TD width=19 height=23>9</TD>
<TD width=20 height=23>8</TD>
<TD width=36 height=23>7</TD>
<TD width=29 height=23>6</TD>
<TD width=20 height=23>5</TD>
<TD width=22 height=23>4</TD>
<TD width=21 height=23>3</TD>
<TD width=22 height=23>2</TD>
<TD width=25 height=23>1</TD>
<TD width=23 height=23>0</TD></TR>
<TR>
<TD width=184 colSpan=8 height=13>Cylinder Bits 7 to 0</TD>
<TD width=67 colSpan=2 height=13>Cylinder Bits 9+8</TD>
<TD width=149 colSpan=6 height=13>Sector Bits 5 to
0</TD></TR></TBODY></TABLE></DIV>
<P><BR><STRONG>Partition Type Listing</STRONG></P>
<BLOCKQUOTE>
<P>There are more than just these shown, but I've only included that ones
relevant to MS Operating Systems.</P></BLOCKQUOTE>
<DIV align=left>
<TABLE height=57 width=418 border=1>
<TBODY>
<TR>
<TD width=52 height=23>Value</TD>
<TD width=354 height=23>Description</TD></TR>
<TR>
<TD width=52 height=10>00h</TD>
<TD width=354 height=10>Unknown or Nothing</TD></TR>
<TR>
<TD width=52 height=13>01h</TD>
<TD width=354 height=13>12-bit FAT</TD></TR>
<TR>
<TD width=52 height=0>04h</TD>
<TD width=354 height=0>16-bit FAT (Partition Smaller than 32MB)</TD></TR>
<TR>
<TD width=52 height=8>05h</TD>
<TD width=354 height=8>Extended MS-DOS Partition</TD></TR>
<TR>
<TD width=52 height=7>06h</TD>
<TD width=354 height=7>16-bit FAT (Partition Larger than 32MB)</TD></TR>
<TR>
<TD width=52 height=6>0Bh</TD>
<TD width=354 height=6>32-bit FAT (Partition Up to 2048GB)</TD></TR>
<TR>
<TD width=52 height=10>0Ch</TD>
<TD width=354 height=10>Same as 0BH, but uses LBA<SUB>1</SUB> 13h
Extensions</TD></TR>
<TR>
<TD width=52 height=12>0Eh</TD>
<TD width=354 height=12>Same as 06H, but uses LBA<SUB>1</SUB> 13h
Extensions</TD></TR>
<TR>
<TD width=52 height=1>0Fh</TD>
<TD width=354 height=1>Same as 05H, but uses LBA<SUB>1</SUB> 13h
Extensions</TD></TR></TBODY></TABLE></DIV>
<P><BR><U><STRONG>Reading Multiple Partitions</STRONG></U></P>
<BLOCKQUOTE>
<P>Since FAT16 is limited to 2GB per partition, drives that use it tend to
have multiple partitions. The first partition is the Primary Partition,
and everything else is stored in the Extended Partition. It's a little
tricky when it comes to reading those extra partitions though (not a lot, just
a little). The first record in the partition table shows where the
Primary partition is (how big it is, where it starts, and where it
ends). The second entry in the partition table shows where the Entire
Extended Partition is (which may include more than just one partition).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -