Notes<\/strong><\/td>\n<\/tr>\n\n00h<\/td>\n | Jump Code<\/td>\n | 3 Bytes<\/td>\n | Contains executable Machine code to allow the Host System to jump past the BSE<\/td>\n<\/tr>\n |
\n03h<\/td>\n | OEM ID<\/td>\n | 8 Bytes<\/td>\n | The system name which formatted the device<\/td>\n<\/tr>\n |
\n0Bh<\/td>\n | Bytes Per Sector<\/td>\n | 2 Bytes<\/td>\n | Normally 0x2000 (512 )<\/td>\n<\/tr>\n |
\n0Dh<\/td>\n | Sectors Per Cluster<\/td>\n | 1 Byte<\/td>\n | \u00a0<\/td>\n<\/tr>\n |
\n0Eh<\/td>\n | No of Reserved Sectors<\/td>\n | 2 Bytes<\/td>\n | \u00a0<\/td>\n<\/tr>\n |
\n10h<\/td>\n | No of FATs<\/td>\n | 1 Byte<\/td>\n | The Number of FAT Entries<\/td>\n<\/tr>\n |
\n11h<\/td>\n | Max Root Directory Entries<\/td>\n | 2 Bytes<\/td>\n | For SD Cards this is usually 0x2000 (512)<\/td>\n<\/tr>\n |
\n13h<\/td>\n | Total Sectors in Partition<\/td>\n | 2 Bytes<\/td>\n | Only set if the device is < 32Mb. Will likely be unset 0x0000<\/td>\n<\/tr>\n |
\n15h<\/td>\n | Media Type<\/td>\n | 1 Byte<\/td>\n | 0xF8 = Hard Drive<\/td>\n<\/tr>\n |
\n16h<\/td>\n | Sectors Per FAT<\/td>\n | 2 Bytes<\/td>\n | Used for reaching the Root Directory<\/td>\n<\/tr>\n |
\n18h<\/td>\n | Sectors Per Track<\/td>\n | 2 Bytes<\/td>\n | \u00a0<\/td>\n<\/tr>\n |
\n1Ah<\/td>\n | No of Heads<\/td>\n | 2 Bytes<\/td>\n | \u00a0<\/td>\n<\/tr>\n |
\n1Ch<\/td>\n | No of Hidden Sectors<\/td>\n | 4 Bytes<\/td>\n | Number of hidden sectors between the start of the disk and the BSE<\/td>\n<\/tr>\n |
\n20h<\/td>\n | No of Sectors in a Partition<\/td>\n | 4 Bytes<\/td>\n | Total number of Sectors in the Partition<\/td>\n<\/tr>\n |
\n24h<\/td>\n | Logical Drive No<\/td>\n | 1 Byte<\/td>\n | 0x80 for Hard Drives<\/td>\n<\/tr>\n |
\n25h<\/td>\n | Head No<\/td>\n | 1 Byte<\/td>\n | Usually 0x00<\/td>\n<\/tr>\n |
\n26h<\/td>\n | Extended Boot Signature<\/td>\n | 1 Byte<\/td>\n | Always 0x29 denoting that Serial No, Label and Type fields are valid<\/td>\n<\/tr>\n |
\n27h<\/td>\n | Serial No<\/td>\n | 4 Bytes<\/td>\n | Serial No of the Device<\/td>\n<\/tr>\n |
\n2Bh<\/td>\n | Partition Name<\/td>\n | 11 Bytes<\/td>\n | \u00a0<\/td>\n<\/tr>\n |
\n36h<\/td>\n | FAT Type<\/td>\n | 8 Bytes<\/td>\n | \u00a0<\/td>\n<\/tr>\n |
\n3Eh<\/td>\n | Executable Boot Code<\/td>\n | 448 Bytes<\/td>\n | Allows the host to find the first file which boots the system<\/td>\n<\/tr>\n |
\n0x01FE<\/td>\n | Executable Signature<\/td>\n | 2 Bytes<\/td>\n | End of BSE<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\nFAT Entries (FAT): <\/h3>\n\n\n\nOffset<\/strong><\/td>\nFAT1 = 1st sector after Reserved Sectors<\/td>\n<\/tr>\n | \nSize<\/strong><\/td>\nSectors Per FAT (From BSE)<\/sup><\/em><\/td>\n<\/tr>\n\nAddress Location Calculation<\/strong><\/td>\nFAT1 = (Partition Start Sector(From MBR) +<\/sup><\/em> Reserved Sectors(From BSE)<\/sup><\/em>) * Bytes \/ Sector<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n The FAT Entries lay out how the Partitions\u2019 identically sized clusters are laid out. There are normally two FAT Entries in order to help prevent FAT corruption problems.<\/p>\n The FAT is located in the first sector after the Reserved Sectors. All sectors between Partition Start Sector and the FAT, which includes the Boot Sector Entry, are contained within the Reserved Sectors Allocation.<\/p>\n So, to find the first FAT we navigate from the beginning of the Device, adding together the Partition Start Sector and the Number of bytes contained in the Reserved Sectors section.<\/p>\n Root Directory Entry (RDE): <\/h3>\n\n\n\nOffset<\/strong><\/td>\nAfter last FAT<\/td>\n<\/tr>\n | \nSize<\/strong><\/td>\nNo of Root Entries(From BSE)<\/sup><\/em> * 32<\/td>\n<\/tr>\n\nAddress Location Calculation<\/strong><\/td>\nRDE = FAT1 Start Address + ((No of FATS(From BSE)<\/sup><\/em> * Sectors Per FAT(From BSE)<\/sup><\/em>) * Bytes Per Sector)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\nThe Root Directory contains the Main Directory and File Structure for the entire Partition<\/p>\n The Root directory is almost identical to a standard File System Directory with only a few differences, namely; The first byte is the first character of the Partition Name. The Create Date and Time are set to 0x00.<\/p>\n The Root directory appears after the last FAT, and so can be found by adding the Start Address of the first FAT to the number of Bytes occupied by all FAT\u2019s, which is invariably 2 for SD Cards. Thus the formula can be simplifed to;<\/p>\n \nRDE = FAT1 Start Address + \u00a0\u00a0\u00a0\u00a0\u00a0 ((2 * Sectors Per FAT) * 512)<\/em><\/p>\n<\/blockquote>\nEach entry in the Root Directory consumes a total of 32 Bytes as shown below;<\/p>\n \n\n\nOffset<\/strong><\/td>\nItem<\/strong><\/td>\nLength<\/strong><\/td>\nNotes<\/strong><\/td>\n<\/tr>\n\n00h<\/td>\n | DOS Filename<\/td>\n | 8 Bytes<\/td>\n | For all other Directories the first byte has special values.<\/td>\n<\/tr>\n | \n08h<\/td>\n | DOS File Extension<\/td>\n | 3 Bytes<\/td>\n | \u00a0<\/td>\n<\/tr>\n | \n0Bh<\/td>\n | File Attributes<\/td>\n | 1 Byte<\/td>\n | 8 bits to denote various attributes<\/td>\n<\/tr>\n | \n0Ch<\/td>\n | NT Case Info<\/td>\n | 1 Byte<\/td>\n | Used for Windows NT Casing Info<\/td>\n<\/tr>\n | \n0Dh<\/td>\n | Create Time (ms)<\/td>\n | 1 Byte<\/td>\n | 10ms Units<\/td>\n<\/tr>\n | \n0Eh<\/td>\n | Create Time (Hrs\/Mins\/Secs)<\/td>\n | 2 Bytes<\/td>\n | \u00a0<\/td>\n<\/tr>\n | \n10h<\/td>\n | Create Date<\/td>\n | 2 Bytes<\/td>\n | \u00a0<\/td>\n<\/tr>\n | \n12h<\/td>\n | Last Access Date<\/td>\n | 2 Bytes<\/td>\n | \u00a0<\/td>\n<\/tr>\n | \n14h<\/td>\n | File \/ Folder Start Cluster (High)<\/td>\n | 2 Bytes<\/td>\n | Only used in FAT32 Systems<\/td>\n<\/tr>\n | \n16h<\/td>\n | Last Modified Time<\/td>\n | 2 Bytes<\/td>\n | \u00a0<\/td>\n<\/tr>\n | \n18h<\/td>\n | Last Modified Date<\/td>\n | 2 Bytes<\/td>\n | \u00a0<\/td>\n<\/tr>\n | \n1Ah<\/td>\n | File \/ Folder Start Cluster (Low)<\/td>\n | 2 Bytes<\/td>\n | \u00a0<\/td>\n<\/tr>\n | \n1Ch<\/td>\n | File Size (Bytes)<\/td>\n | 4 Bytes<\/td>\n | Folders will have a File Size of 0x0000<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\nSub Directory \/ Files: <\/h3>\n\n\n\nOffset<\/strong><\/td>\nAfter Root Directory<\/td>\n<\/tr>\n | \nSize<\/strong><\/td>\nN\/a<\/td>\n<\/tr>\n | \nAddress Location Calculation<\/strong><\/td>\nRoot Folder Address + (Max Root Directory Entries(From BSE) <\/sup><\/em>* 32) + ((( File \/ Folder Start Cluster(From RDE) <\/sup><\/em>\u2013 2) * Sectors Per Cluster(From BSE) <\/sup><\/em>) * Bytes Per Sector(From BSE) <\/sup><\/em>)<\/p>\nNormally For SD Cards using FAT16;<\/p>\n Max Root Directory Entries = 512 Bytes Per Sector = 512 <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n A Sub Directory takes on almost exactly the same format as the root Directory above.<\/p>\n All data stored after the Root Directory is located in the third Data Cluster, thus in order to find the location of all data we must subtract these two clusters from the Start Cluster given in the File \/ Folder Start Cluster Field.<\/p>\n The first data is found using the formula above, however for SD Cards using FAT16, the maximum Root Directory Entries and Bytes Per Sector are invariably 512. Thus the formula can be simplified to the following;<\/p>\n \nFirst Data = Root Folder Address + 16384 + \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (((File\/Folder St Cluster \u2013 2) * \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Sectors Per Cluster) * 512)<\/em><\/p>\n<\/blockquote>\nA Worked Example: <\/h3>\n\n\n\nCard Type<\/strong><\/td>\nSandisk 2Gb SD<\/td>\n<\/tr>\n | \nMBR Length<\/strong><\/td>\n512<\/td>\n<\/tr>\n | \nPartition 1 Start Sector<\/strong><\/td>\n129<\/td>\n<\/tr>\n | \nBytes Per Sector<\/strong><\/td>\n512<\/td>\n<\/tr>\n | \nSectors Per Cluster<\/strong><\/td>\n64<\/td>\n<\/tr>\n | \nReserved Sectors<\/strong><\/td>\n2<\/td>\n<\/tr>\n | \nNumber of FAT\u2019s<\/strong><\/td>\n2<\/td>\n<\/tr>\n | \nSectors Per FAT<\/strong><\/td>\n239<\/td>\n<\/tr>\n | \nHidden Sectors<\/strong><\/td>\n129<\/td>\n<\/tr>\n | \nBSE Length<\/strong><\/td>\n512<\/td>\n<\/tr>\n | \nNumber of Root Entries<\/strong><\/td>\n512<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n The table above gives all the information taken from the MBR and BSE of the Card.<\/p>\n Calculating the BSE Address:<\/h3>\n\nBSE = Partition Start Sector * \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/em>Bytes Per Sector<\/em><\/p>\nBSE = 129 * 512<\/em><\/p>\nBSE = 66048 = 0x10200<\/em><\/p>\n<\/blockquote>\nCalculating the FAT1 Address:<\/h3>\n\nFAT1 = (Partition Start Sector + \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/em>Reserved Sectors) * Bytes Per Sector) <\/em><\/p>\nFAT1 = (129 + 2) * 512<\/em><\/p>\nFAT1 = 131 * 512<\/em><\/p>\nFAT1 = 67072 = 0x10600<\/em><\/p>\n<\/blockquote>\nCalculating the Root Directory Address:<\/h3>\n\nRDE = FAT1 Start Address + \u00a0\u00a0\u00a0\u00a0\u00a0 ((No of FATS * Sectors Per FAT) * \u00a0\u00a0\u00a0\u00a0\u00a0 <\/em>Bytes Per Sector)<\/em><\/p>\nRDE = 67072 + \u00a0\u00a0\u00a0\u00a0\u00a0 ((2 * 239) * \u00a0\u00a0\u00a0\u00a0\u00a0 512)<\/em><\/p>\nRDE = 67072 + (478 * 512)<\/em><\/p>\nRDE = 67072 + 244736<\/em><\/p>\nRDE = 311808 = 0x4C200<\/em><\/p>\n<\/blockquote>\nCalculating the First File Address:<\/h3>\nFor a file or folder which has a starting cluster value of 0x04, then the following will locate the start address;<\/p>\n \nFile = Root Folder Address + \u00a0\u00a0\u00a0\u00a0\u00a0 (Max Root Entries * 32) + \u00a0\u00a0\u00a0\u00a0\u00a0 (((File\/Folder St Cluster \u2013 2) * \u00a0\u00a0\u00a0\u00a0\u00a0 Sectors Per Cluster) * \u00a0\u00a0\u00a0\u00a0\u00a0 Bytes Per sector)<\/em><\/p>\nFile = 311808 + \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (512 * 32) + \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (((4 \u2013 2) * \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 64) * \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 512)<\/em><\/p>\nFile = 311808 + \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 16384 + \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ((2 * 64) * 512)<\/em><\/p>\nFile = 311808 + 16384 + (128 * 512)<\/em><\/p>\nFile = 311808 + 16384 + 65536<\/em><\/p>\nFile = 393728 = 0x60200 <\/em><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"I have been working on a\u00a0 project where the client requires their device to have it\u2019s firmware updated from a Secure Digital (SD) Card. The standard way to store and access data on SD cards is to use the MS FAT File System. There are several libraries available dotted around the Internet which allow developers […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[78,79,80,81],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.pjgcreations.co.uk\/wp-json\/wp\/v2\/posts\/1686"}],"collection":[{"href":"https:\/\/www.pjgcreations.co.uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pjgcreations.co.uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pjgcreations.co.uk\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pjgcreations.co.uk\/wp-json\/wp\/v2\/comments?post=1686"}],"version-history":[{"count":0,"href":"https:\/\/www.pjgcreations.co.uk\/wp-json\/wp\/v2\/posts\/1686\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pjgcreations.co.uk\/wp-json\/wp\/v2\/media?parent=1686"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pjgcreations.co.uk\/wp-json\/wp\/v2\/categories?post=1686"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pjgcreations.co.uk\/wp-json\/wp\/v2\/tags?post=1686"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}} | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |