userlibandfileserver/fileserver/sfat32/sl_fatmisc32.cpp
branchRCL_3
changeset 80 597aaf25e343
parent 0 a41df078684a
child 87 2f92ad2dc5db
equal deleted inserted replaced
62:4a8fed1c0ef6 80:597aaf25e343
   140 		iRootClusterNum=2;						//As recomended in the document
   140 		iRootClusterNum=2;						//As recomended in the document
   141 		iSectorsPerFat=MaxFat32Sectors();
   141 		iSectorsPerFat=MaxFat32Sectors();
   142 		
   142 		
   143 		}
   143 		}
   144 
   144 
       
   145 	const TFatType fatType = SuggestFatType();
       
   146 
   145 	// Ensure cluster size is a multiple of the block size
   147 	// Ensure cluster size is a multiple of the block size
   146 	TInt blockSizeInSectors = aCaps.iBlockSize >> iSectorSizeLog2;
   148 	TInt blockSizeInSectors = aCaps.iBlockSize >> iSectorSizeLog2;
   147 	__PRINT1(_L("blockSizeInSectors: %d"),blockSizeInSectors);
   149 	__PRINT1(_L("blockSizeInSectors: %d"),blockSizeInSectors);
   148 	ASSERT(blockSizeInSectors == 0 || IsPowerOf2(blockSizeInSectors));
   150 	ASSERT(blockSizeInSectors == 0 || IsPowerOf2(blockSizeInSectors));
   149 	if (blockSizeInSectors != 0 && IsPowerOf2(blockSizeInSectors))
   151 	if (blockSizeInSectors != 0 && IsPowerOf2(blockSizeInSectors))
   150 		{
   152 		{
   151 		__PRINT1(_L("iSectorsPerCluster	(old): %d"),iSectorsPerCluster);
   153 		__PRINT1(_L("iSectorsPerCluster    (old): %d"),iSectorsPerCluster);
   152 		AdjustClusterSize(blockSizeInSectors);
   154 		AdjustClusterSize(blockSizeInSectors);
   153 		__PRINT1(_L("iSectorsPerCluster	(new): %d"),iSectorsPerCluster);
   155 		__PRINT1(_L("iSectorsPerCluster    (new): %d"),iSectorsPerCluster);
   154 		}
   156 		}
   155 
   157 
   156 	// Align first data sector on an erase block boundary if
   158 
   157 	// (1) the iEraseBlockSize is specified
   159 	for (; iSectorsPerCluster>1; iSectorsPerCluster>>= 1)
   158 	// (2) the start of the partition is already aligned to an erase block boundary, 
   160 		{
   159 	//     i.e. iHiddenSectors is zero or a multiple of iEraseBlockSize
   161 		// Align first data sector on an erase block boundary if
   160 	__PRINT1(_L("iHiddenSectors: %d"),iHiddenSectors);
   162 		// (1) the iEraseBlockSize is specified
   161 	TInt eraseblockSizeInSectors = aCaps.iEraseBlockSize >> iSectorSizeLog2;
   163 		// (2) the start of the partition is already aligned to an erase block boundary, 
   162 	__PRINT1(_L("eraseblockSizeInSectors: %d"),eraseblockSizeInSectors);
   164 		//     i.e. iHiddenSectors is zero or a multiple of iEraseBlockSize
   163 	ASSERT(eraseblockSizeInSectors == 0 || IsPowerOf2(eraseblockSizeInSectors));	
   165 		__PRINT1(_L("iHiddenSectors: %d"),iHiddenSectors);
   164 	ASSERT(eraseblockSizeInSectors == 0 || eraseblockSizeInSectors >= blockSizeInSectors);
   166 		TInt eraseblockSizeInSectors = aCaps.iEraseBlockSize >> iSectorSizeLog2;
   165 	if ((eraseblockSizeInSectors != 0) &&
   167 		__PRINT1(_L("eraseblockSizeInSectors: %d"),eraseblockSizeInSectors);
   166 		(iHiddenSectors % eraseblockSizeInSectors == 0) &&	
   168 		ASSERT(eraseblockSizeInSectors == 0 || IsPowerOf2(eraseblockSizeInSectors));	
   167 		(IsPowerOf2(eraseblockSizeInSectors)) &&
   169 		ASSERT(eraseblockSizeInSectors == 0 || eraseblockSizeInSectors >= blockSizeInSectors);
   168 		(eraseblockSizeInSectors >= blockSizeInSectors))
   170 		if ((eraseblockSizeInSectors != 0) &&
   169 		{
   171 			(iHiddenSectors % eraseblockSizeInSectors == 0) &&	
   170 		TInt r = AdjustFirstDataSectorAlignment(eraseblockSizeInSectors);
   172 			(IsPowerOf2(eraseblockSizeInSectors)) &&
   171 		ASSERT(r == KErrNone);
   173 			(eraseblockSizeInSectors >= blockSizeInSectors))
   172 		(void) r;
   174 			{
   173 		}
   175 			TInt r = AdjustFirstDataSectorAlignment(eraseblockSizeInSectors);
   174 	__PRINT1(_L("iReservedSectors: %d"),iReservedSectors);
   176 			ASSERT(r == KErrNone);
   175 	__PRINT1(_L("FirstDataSector: %d"), FirstDataSector());
   177 			(void) r;
       
   178 			}
       
   179 		__PRINT1(_L("iReservedSectors: %d"),iReservedSectors);
       
   180 		__PRINT1(_L("FirstDataSector: %d"), FirstDataSector());
       
   181 
       
   182 		// If we've shrunk the number of clusters by so much that it's now invalid for this FAT type
       
   183 		// then we need to decrease the cluster size and try again, otherwise we're finshed.
       
   184 		if (SuggestFatType() == fatType)
       
   185 			break;
       
   186 		}
       
   187 	__PRINT1(_L("iSectorsPerCluster  (final): %d"),iSectorsPerCluster);
   176 
   188 
   177     return KErrNone;
   189     return KErrNone;
   178 	}
   190 	}
   179 
   191 
   180 TInt CFatFormatCB::FirstDataSector() const
   192 TInt CFatFormatCB::FirstDataSector() const