userlibandfileserver/fileserver/sfat32/sl_fmt.cpp
branchRCL_3
changeset 87 2f92ad2dc5db
parent 15 4122176ea935
child 269 d57b86b1867a
equal deleted inserted replaced
81:e7d2d738d3c2 87:2f92ad2dc5db
    49 	__PRINT1(_L("CFatFormatCB::~CFatFormatCB() [%x]"),this);
    49 	__PRINT1(_L("CFatFormatCB::~CFatFormatCB() [%x]"),this);
    50     iBadSectors.Close();
    50     iBadSectors.Close();
    51 	iBadClusters.Close();
    51 	iBadClusters.Close();
    52 	}
    52 	}
    53 
    53 
    54 TInt CFatFormatCB::MaxFat16Sectors() const
    54 /**
    55 //
    55     Calculate the size of a 16 bit FAT
    56 // Calculate the size of a 16 bit FAT
    56 */
    57 //
    57 TUint CFatFormatCB::MaxFat16Sectors() const
    58 	{
    58 	{
       
    59 	const TUint32 fatSizeInBytes=(2*iMaxDiskSectors)/iSectorsPerCluster+(iBytesPerSector-1);
       
    60 	return(fatSizeInBytes/iBytesPerSector);
       
    61 	}
       
    62 
       
    63 
       
    64 /**
       
    65     Calculate the size of a 12 bit FAT
       
    66 */
       
    67 TUint CFatFormatCB::MaxFat12Sectors() const
       
    68 	{
       
    69 	const TUint32 maxDiskClusters=iMaxDiskSectors/iSectorsPerCluster;
       
    70 	const TUint32 fatSizeInBytes=maxDiskClusters+(maxDiskClusters>>1)+(iBytesPerSector-1);
    59 	
    71 	
    60 	TInt fatSizeInBytes=(2*iMaxDiskSectors)/iSectorsPerCluster+(iBytesPerSector-1);
       
    61 	return(fatSizeInBytes/iBytesPerSector);
       
    62 	}
       
    63 
       
    64 TInt CFatFormatCB::MaxFat12Sectors() const
       
    65 //
       
    66 // Calculate the size of a 12 bit FAT
       
    67 //
       
    68 	{
       
    69 	
       
    70 	TInt maxDiskClusters=iMaxDiskSectors/iSectorsPerCluster;
       
    71 	TInt fatSizeInBytes=maxDiskClusters+(maxDiskClusters>>1)+(iBytesPerSector-1);
       
    72 	return(fatSizeInBytes/iBytesPerSector);
    72 	return(fatSizeInBytes/iBytesPerSector);
    73 	}
    73 	}
    74 
    74 
    75 //-------------------------------------------------------------------------------------------------------------------
    75 //-------------------------------------------------------------------------------------------------------------------
    76 /**
    76 /**
   203     Initialize the format parameters for a variable sized disk
   203     Initialize the format parameters for a variable sized disk
   204     
   204     
   205     @param  aDiskSizeInSectors volume size in sectors
   205     @param  aDiskSizeInSectors volume size in sectors
   206     @return standard error code
   206     @return standard error code
   207 */
   207 */
   208 TInt  CFatFormatCB::InitFormatDataForVariableSizeDisk(TInt aDiskSizeInSectors)
   208 TInt  CFatFormatCB::InitFormatDataForVariableSizeDisk(TUint aDiskSizeInSectors)
   209 	{
   209 	{
   210 	iNumberOfFats=2; // 1 FAT 1 Indirection table (FIT)
   210 	iNumberOfFats=2; // 1 FAT 1 Indirection table (FIT)
   211 	iReservedSectors=1;
   211 	iReservedSectors=1;
   212 	iRootDirEntries=2*(4*KDefaultSectorSize)/sizeof(SFatDirEntry);
   212 	iRootDirEntries=2*(4*KDefaultSectorSize)/sizeof(SFatDirEntry);
   213 	TInt minSectorsPerCluster=(aDiskSizeInSectors+KMaxFAT16Entries-1)/KMaxFAT16Entries;
   213 	TUint minSectorsPerCluster=(aDiskSizeInSectors+KMaxFAT16Entries-1)/KMaxFAT16Entries;
   214 	iSectorsPerCluster=1;
   214 	iSectorsPerCluster=1;
       
   215 
   215 	while (minSectorsPerCluster>iSectorsPerCluster)
   216 	while (minSectorsPerCluster>iSectorsPerCluster)
   216 		iSectorsPerCluster<<=1;
   217 		iSectorsPerCluster<<=1;
       
   218 
   217 	__PRINT1(_L("iSectorsPerCluster = %d"),iSectorsPerCluster);
   219 	__PRINT1(_L("iSectorsPerCluster = %d"),iSectorsPerCluster);
   218 	iSectorsPerFat=MaxFat16Sectors();
   220 	iSectorsPerFat=MaxFat16Sectors();
   219 	__PRINT1(_L("iSectorsPerFat = %d"),iSectorsPerFat);
   221 	__PRINT1(_L("iSectorsPerFat = %d"),iSectorsPerFat);
   220 	iFileSystemName=KFileSystemName16;
   222 	iFileSystemName=KFileSystemName16;
   221 
   223 
   275     TInt size = 1 << FatMount().ClusterSizeLog2();
   277     TInt size = 1 << FatMount().ClusterSizeLog2();
   276     TUint8* readBuf = new(ELeave) TUint8[size];
   278     TUint8* readBuf = new(ELeave) TUint8[size];
   277     TPtr8 readBufPtr(readBuf, size);
   279     TPtr8 readBufPtr(readBuf, size);
   278     RArray<TInt> newArray;
   280     RArray<TInt> newArray;
   279     TInt r = DoTranslate(readBufPtr, newArray);
   281     TInt r = DoTranslate(readBufPtr, newArray);
       
   282     
   280     delete[] readBuf;
   283     delete[] readBuf;
       
   284     readBuf = NULL;
       
   285 
   281     newArray.Close();
   286     newArray.Close();
   282     User::LeaveIfError(r);
   287     User::LeaveIfError(r);
   283     }
   288     }
   284 
   289 
   285 #define calcSector(n) (n+oFirstFreeSector-nFirstFreeSector)
   290 #define calcSector(n) (n+oFirstFreeSector-nFirstFreeSector)