Update contrib.
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32\sfile\sf_dat.cpp
21 CFsObjectConIx* TheContainer;
22 CFsObjectCon* FileSystems;
24 CFsObjectCon* FileShares;
26 CFsObjectCon* Formats;
27 CFsObjectCon* RawDisks;
28 CFsObjectCon* Extensions;
29 CFsObjectCon* ProxyDrives;
31 CServerFs* TheFileServer;
32 TDrive TheDrives[KMaxDrives];
34 //#ifndef __SECURE_API__
35 TFileName TheDefaultPath;
38 HBufC* TheDriveNames[KMaxDrives];
41 SCapabilitySet AllCapabilities;
42 SCapabilitySet DisabledCapabilities;
44 RThread TheServerThread;
45 RAllocator* ServerThreadAllocator;
46 TBool OpenOnDriveZOnly;
47 TBool LocalFileSystemInitialized;
48 TBool RefreshZDriveCache;
51 TBool StartupInitCompleted;
52 TBool LocalDriveMappingSet;
53 CKernEventNotifier* TheKernEventNotifier;
57 GLDEF_D TCodePageUtils TheCodePage;
59 TBool FatUtilityFunctionsSet = EFalse; //-- Flag. Is set to ETrue when LoadLocale() sets a pointer to TFatUtilityFunctions
60 TBool FatUtilitiesUpdateDrivesNotified = EFalse; //-- Flag. Is set to ETrue when all drives get a notification about locale change
64 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
68 TInt UserHeapAllocFailCount;
69 TInt KernHeapAllocFailCount;
70 TInt DebugNCNotifier=0;
71 TCorruptNameRec* gCorruptFileNameList=NULL;
72 TCorruptLogRec* gCorruptLogRecordList=NULL;
73 TInt gNumberOfCorruptHits=0;
74 HBufC* gCorruptFileNamesListFile=NULL;
78 TBool F32Properties::iInitialised = 0;
79 TInt F32Properties::iRomAddress = 0;
80 TInt F32Properties::iRomLength = 0;
82 EXPORT_C TBusLocalDrive& GetLocalDrive(TInt aDrive)
87 return(LocalDrives::GetLocalDrive(aDrive));
90 EXPORT_C TInt GetProxyDrive(TInt aDrive, CProxyDrive*& aProxyDrive)
92 // Export proxy drives
95 return TheDrives[aDrive].CurrentMount().ProxyDrive(aProxyDrive);
98 EXPORT_C CExtProxyDrive* GetProxyDrive(TInt aDrive)
100 return (LocalDrives::GetProxyDrive(aDrive));
103 EXPORT_C TBool IsProxyDrive(TInt aDrive)
105 return (LocalDrives::IsProxyDrive(aDrive));
108 EXPORT_C TBool IsValidLocalDriveMapping(TInt aDrive)
110 // Is the drive number to local drive mapping valid?
113 return(LocalDrives::IsValidDriveMapping(aDrive));
116 EXPORT_C TInt DriveNumberToLocalDriveNumber(TInt aDrive)
118 // Get the mapping from drive number to local drive
121 return(LocalDrives::DriveNumberToLocalDriveNumber(aDrive));
124 EXPORT_C TInt GetLocalDriveNumber(TBusLocalDrive* aLocDrv)
126 // Get the local drive number from local drive
129 return(LocalDrives::GetLocalDriveNumber(aLocDrv));
132 struct TFatUtilityFunctions;
133 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
134 TBool EnableFatUtilityFunctions = ETrue;
136 EXPORT_C const TFatUtilityFunctions* GetFatUtilityFunctions()
138 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
139 if (!EnableFatUtilityFunctions)
141 return NULL; // Bypass Locale Dll/Codepage FAT converions, use default implementation
144 switch(TheCodePage.CodepageLoaded())
146 case TCodePageUtils::ECodePageDll:
147 return ((TFatUtilityFunctions*)(TheCodePage.CodepageFatUtilityFunctions().iConvertFromUnicodeL));
148 case TCodePageUtils::ELocaleDll:
149 return TheCodePage.LocaleFatUtilityFunctions();
151 return NULL; // if no Locale Dll/Codepage Dll is loaded, use default implementation
155 EXPORT_C const TCodePageUtils& GetCodePage()
162 Helper class for parsing F32 INI files
167 TIniFileReader(const TPtrC8& aData);
169 TBool IsSection(const TDesC8& aSection = KNullDesC8);
170 TBool IsProperty(const TDesC8& aProperty, TBool& aPropVal);
171 TBool IsProperty(const TDesC8& aProperty, TInt32& aPropVal);
172 TBool IsProperty(const TDesC8& aProperty, TDes8& aPropVal);
182 TIniFileReader constructor
184 TIniFileReader::TIniFileReader(const TPtrC8& aData)
186 iCurrentLine(NULL,0,256),
194 Reads the next line from an F32 INI file.
195 - On exit, iCurrentLine represents the current line
196 - On exit, iCurrentPos points to the next line in the INI file
198 TInt TIniFileReader::Next()
200 // Check if we have run into the end of the file
201 TInt bufRemainder = (iData.Length()-iCurrentPos);
207 // Setup the descriptor passed with the next record - don't include the record terminator
208 // The line terminators are CR + LF for DOS
209 // whereas only LF for Unix line endings
210 iCurrentLine.Set(((TUint8*)iData.Ptr()+iCurrentPos),bufRemainder,bufRemainder);
211 TInt len = iCurrentLine.Locate('\n');
212 if (len != KErrNotFound)
215 // Check for DOS line ending to support both DOS and Unix formats
216 if ((len != 0) && (((TUint8*)iData.Ptr())[iCurrentPos-1] == '\r'))
220 iCurrentLine.SetLength(len);
224 iCurrentPos=iData.Length();
227 // Point iCurrentPos to the next non-empty line
228 while (iCurrentPos<iData.Length() && (((TUint8*)iData.Ptr())[iCurrentPos]=='\n' || ((TUint8*)iData.Ptr())[iCurrentPos]=='\r'))
233 // iCurrentLine now describes a single line of the INI file
240 Examines the current INI line, returning ETrue if the line contains the requested INI section
241 - An INI section must be of the form [section_name]
242 - Passing KNullDesC as an argument returns ETrue if the line describes any INI section
244 TBool TIniFileReader::IsSection(const TDesC8& aSection)
246 TInt sectionStart = iCurrentLine.Locate('[');
247 TInt sectionEnd = iCurrentLine.Locate(']');
248 if(sectionStart == 0 && sectionEnd > 1)
250 if(aSection == KNullDesC8)
255 const TInt sectionLength = sectionEnd-sectionStart-1;
256 // Found a start of section marker - does it match what we're interested in?
257 TPtr8 sectionPtr(&iCurrentLine[1+sectionStart], sectionLength, sectionLength);
258 if(sectionPtr == aSection)
269 Examines the current INI line, returning ETrue if the line contains the requested property
271 TBool TIniFileReader::IsProperty(const TDesC8& aProperty, TBool& aPropVal)
274 TLex8 lex(iCurrentLine);
275 token.Set(lex.NextToken());
276 if (token.Length() == 0 || token != aProperty)
284 if (lex.BoundedVal(propVal, 1) == KErrNone)
290 // allow "on" or "off" strings if no integer found
292 _LIT8(KBoolOff,"OFF");
294 if (lex.Remainder().Left(KBoolOn().Length()).CompareF(KBoolOn) == KErrNone)
299 if (lex.Remainder().Left(KBoolOff().Length()).CompareF(KBoolOff) == KErrNone)
311 Examines the current INI line, returning ETrue if the line contains the requested property
313 TBool TIniFileReader::IsProperty(const TDesC8& aProperty, TInt32& aPropVal)
316 TLex8 lex(iCurrentLine);
317 token.Set(lex.NextToken());
318 if (token.Length() == 0 || token != aProperty)
326 if (lex.Val(propVal) != KErrNone)
339 Examines the current INI line, returning ETrue if the line contains the requested property
341 TBool TIniFileReader::IsProperty(const TDesC8& aProperty, TDes8& aPropVal)
344 TLex8 lex(iCurrentLine);
345 token.Set(lex.NextToken());
346 if (token.Length() == 0 || token != aProperty)
353 aPropVal = lex.Remainder().Left(aPropVal.MaxLength());
361 Initialises the F32 properties with a ROM address representing the INI file in ROM
363 @return KErrNone on success
364 @return KErrAlreadyExists if the properties have already been initialised
366 EXPORT_C TInt F32Properties::Initialise(TInt aRomAddress, TInt aLength)
370 // F32 properties have already been initialised
371 return(KErrAlreadyExists);
374 iInitialised = ETrue;
375 iRomAddress = aRomAddress;
376 iRomLength = aLength;
384 Returns the requested F32 property string
386 @param aSection The name of the F32 INI section
387 @param aProperty The name of the F32 propery within the section
388 @param aPropVal Returns the requested property value (unchanged if the property does not exist)
390 @return ETrue if the property exists, EFalse otherwise
392 EXPORT_C TBool F32Properties::GetString(const TDesC8& aSection, const TDesC8& aProperty, TDes8& aPropVal)
399 TPtrC8 iniPtr((TUint8*)iRomAddress, iRomLength);
400 TIniFileReader iniReader(iniPtr);
404 // Read the next line of the INI file
405 if(iniReader.Next() == KErrEof)
410 if(iniReader.IsSection(aSection))
412 // Found the section we're interested in
413 // - look for the property, until we get to EOF or the next section
416 if(iniReader.Next() == KErrEof)
421 if(iniReader.IsSection())
426 if(iniReader.IsProperty(aProperty, aPropVal))
434 // No section found...
441 Returns the requested integer F32 property value
443 @param aSection The name of the F32 INI section
444 @param aProperty The name of the F32 propery within the section
445 @param aPropVal Returns the requested property value (unchanged if the property does not exist)
447 @return ETrue if the property exists, EFalse otherwise
449 EXPORT_C TBool F32Properties::GetInt(const TDesC8& aSection, const TDesC8& aProperty, TInt32& aPropVal)
456 TPtrC8 iniPtr((TUint8*)iRomAddress, iRomLength);
457 TIniFileReader iniReader(iniPtr);
461 // Read the next line of the INI file
462 if(iniReader.Next() == KErrEof)
467 if(iniReader.IsSection(aSection))
469 // Found the section we're interested in
470 // - look for the property, until we get to EOF or the next section
473 if(iniReader.Next() == KErrEof)
479 if(iniReader.IsSection())
484 if(iniReader.IsProperty(aProperty, aPropVal))
492 // No section found...
499 Returns the requested boolean F32 property value
501 @param aSection The name of the F32 INI section
502 @param aProperty The name of the F32 propery within the section
503 @param aPropVal Returns the requested property value (unchanged if the property does not exist)
505 @return ETrue if the property exists, EFalse otherwise
507 EXPORT_C TBool F32Properties::GetBool(const TDesC8& aSection, const TDesC8& aProperty, TBool& aPropVal)
514 TPtrC8 iniPtr((TUint8*)iRomAddress, iRomLength);
515 TIniFileReader iniReader(iniPtr);
519 // Read the next line of the INI file
520 if(iniReader.Next() == KErrEof)
525 if(iniReader.IsSection(aSection))
527 // Found the section we're interested in
528 // - look for the property, until we get to EOF or the next section
531 if(iniReader.Next() == KErrEof)
535 if(iniReader.IsSection())
540 if(iniReader.IsProperty(aProperty, aPropVal))
548 // No section found...
553 Obtain drive information. This function is called by the default implementation of CFileSystem::DriveInfo().
554 @param anInfo out: drive information
555 @param aDriveNumber drive number
557 EXPORT_C void GetDriveInfo(TDriveInfo& anInfo, TInt aDriveNumber)
559 if(!IsValidLocalDriveMapping(aDriveNumber))
562 TLocalDriveCapsBuf localDriveCaps;
566 // is the drive local?
567 if (!IsProxyDrive(aDriveNumber))
569 // if not valid local drive, use default values in localDriveCaps
570 // if valid local drive and not locked, use TBusLocalDrive::Caps() values
571 // if valid drive and locked, hard-code attributes
572 r = GetLocalDrive(aDriveNumber).Caps(localDriveCaps);
576 CExtProxyDrive* pD = GetProxyDrive(aDriveNumber);
577 __ASSERT_ALWAYS(pD != NULL,User::Panic(_L("GetDriveInfo - pProxyDrive == NULL"), -999));
578 r = pD->Caps(localDriveCaps);
581 TLocalDriveCaps& caps = localDriveCaps();
584 anInfo.iMediaAtt=caps.iMediaAtt;
588 anInfo.iMediaAtt = KMediaAttLocked | KMediaAttLockable | KMediaAttHasPassword;
591 anInfo.iType=caps.iType;
592 anInfo.iDriveAtt=caps.iDriveAtt;
593 anInfo.iConnectionBusType=caps.iConnectionBusType;