imgtools/imglib/filesystem/source/fat16bootsector.cpp
changeset 2 39c28ec933dd
equal deleted inserted replaced
1:820b22e13ff1 2:39c28ec933dd
       
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * This class represents the boot sector of a FAT16 image. 
       
    16 * This class is derived from basebootsector class which is constitutes 
       
    17 * the common boot sector fields for FAT16 and FAT32 class. 	
       
    18 * @internalComponent
       
    19 * @released
       
    20 *
       
    21 */
       
    22 
       
    23 #include "fat16bootsector.h"
       
    24 #include <cstring>
       
    25 
       
    26 /**
       
    27 Constructor of the fat16 boot sector class
       
    28 
       
    29 @internalComponent
       
    30 @released
       
    31 */
       
    32 TFAT16BootSector::TFAT16BootSector()
       
    33 {
       
    34 }
       
    35 
       
    36 /**
       
    37 Destructor of the fat16 boot sector class
       
    38 
       
    39 @internalComponent
       
    40 @released
       
    41 */
       
    42 TFAT16BootSector::~TFAT16BootSector()
       
    43 {
       
    44 }
       
    45 
       
    46 /**
       
    47 Set the file system type
       
    48 
       
    49 @internalComponent
       
    50 @released
       
    51 */
       
    52 void TFAT16BootSector::SetFileSysType()
       
    53 {
       
    54 	strcpy(reinterpret_cast<char*>(iFileSysType),"FAT16   ");
       
    55 }	
       
    56 /**
       
    57 returns the file system type
       
    58 @return file system type 
       
    59 
       
    60 @internalComponent
       
    61 @released
       
    62 */
       
    63 unsigned char* TFAT16BootSector::FileSysType()
       
    64 {
       
    65 	return iFileSysType;
       
    66 }
       
    67 
       
    68 /**
       
    69 Number of entries allowed in the root directory,specific to Fat12/16,
       
    70 zero for FAT32
       
    71 
       
    72 @internalComponent
       
    73 @released
       
    74 */
       
    75 void TFAT16BootSector::SetRootDirEntries()
       
    76 {
       
    77 	iRootDirEntries = KDefaultRootDirEntries;;		
       
    78 }
       
    79 
       
    80 /**
       
    81 Sets the number of reserved sectors on the volume
       
    82 
       
    83 @internalComponent
       
    84 @released
       
    85 */
       
    86 void TFAT16BootSector::SetReservedSectors()
       
    87 {
       
    88 	iReservedSectors = KDefaultFat16ReservedSectors;
       
    89 }
       
    90 
       
    91 /**
       
    92 Computes the sectors per cluster ratio
       
    93 To refer this mathematical computation, Please see:
       
    94 Microsoft Extensible Firmware Initiative FAT32 File 
       
    95 System Specification document
       
    96 
       
    97 @internalComponent
       
    98 @released
       
    99 
       
   100 @param aPartitionSize partition size in bytes
       
   101 */
       
   102 void TFAT16BootSector::ComputeSectorsPerCluster(Long64 aPartitionSize)
       
   103 {
       
   104 	
       
   105 	if(aPartitionSize > K1GB)
       
   106 	{
       
   107 		iSectorsPerCluster = K64SectorsPerCluster;
       
   108 	}
       
   109 	else if(aPartitionSize > K512MB)
       
   110 	{
       
   111 		iSectorsPerCluster = K32SectorsPerCluster;
       
   112 	}
       
   113 	else if(aPartitionSize > K256MB)
       
   114 	{
       
   115 		iSectorsPerCluster = K16SectorsPerCluster;
       
   116 	}
       
   117 	else if(aPartitionSize > K128MB)
       
   118 	{
       
   119 		iSectorsPerCluster = K8SectorsPerCluster;
       
   120 	}
       
   121 	else if(aPartitionSize > K16MB)
       
   122 	{
       
   123 		iSectorsPerCluster = K4SectorsPerCluster;
       
   124 	}
       
   125 	else 
       
   126 	{
       
   127 		iSectorsPerCluster = K2SectorsPerCluster;
       
   128 	}
       
   129 }
       
   130 
       
   131 /**
       
   132 Sectors used for the Fat table
       
   133 To refer this mathematical formulae, Please see:
       
   134 Microsoft Extensible Firmware Initiative FAT32 File System Specification 
       
   135 document
       
   136 
       
   137 @internalComponent
       
   138 @released
       
   139 
       
   140 @param aPartitionSize partition size
       
   141 */
       
   142 void TFAT16BootSector::ComputeFatSectors(Long64 aPartitionSize)
       
   143 {
       
   144 	int iRootDirSectors = ((iRootDirEntries * 32) + (iBytesPerSector - 1)) / iBytesPerSector;
       
   145 	int Log2OfBytesPerSector = Log2(iBytesPerSector);
       
   146 	unsigned long TotalSectors64 = (unsigned long)(aPartitionSize >> Log2OfBytesPerSector);
       
   147 	unsigned int tmpval1 = TotalSectors64 - (iReservedSectors + iRootDirSectors);
       
   148 	unsigned int tmpval2 =(256 * iSectorsPerCluster) + iNumberOfFats;
       
   149 	unsigned int FatSectors =(tmpval1 + (tmpval2 - 1)) / tmpval2;
       
   150 	iFatSectors = (unsigned short)FatSectors;	
       
   151 	iFatSectors32 = 0;
       
   152 }