os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_dat.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // f32\sfile\sf_dat.cpp
    15 // 
    16 //
    17 
    18 #include "sf_std.h"
    19 
    20 
    21 CFsObjectConIx* TheContainer;
    22 CFsObjectCon* FileSystems;
    23 CFsObjectCon* Files;
    24 CFsObjectCon* FileShares;
    25 CFsObjectCon* Dirs;
    26 CFsObjectCon* Formats;
    27 CFsObjectCon* RawDisks;
    28 CFsObjectCon* Extensions;
    29 CFsObjectCon* ProxyDrives;
    30 
    31 CServerFs* TheFileServer;
    32 TDrive TheDrives[KMaxDrives];
    33 
    34 //#ifndef __SECURE_API__
    35 TFileName TheDefaultPath;
    36 //#endif
    37 
    38 HBufC* TheDriveNames[KMaxDrives];
    39 
    40 
    41 SCapabilitySet AllCapabilities;
    42 SCapabilitySet DisabledCapabilities;
    43 
    44 RThread TheServerThread;
    45 RAllocator* ServerThreadAllocator;
    46 TBool OpenOnDriveZOnly;
    47 TBool LocalFileSystemInitialized;
    48 TBool RefreshZDriveCache;
    49 TBool CompFsMounted;
    50 TBool CompFsSync;
    51 TBool StartupInitCompleted;
    52 TBool LocalDriveMappingSet;
    53 CKernEventNotifier* TheKernEventNotifier;
    54 RFTrace TheFtrace;
    55 
    56 
    57 GLDEF_D TCodePageUtils TheCodePage;
    58 
    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
    61 
    62 
    63 
    64 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
    65 TInt ErrorCondition;
    66 TInt ErrorCount;
    67 TUint32 DebugReg;
    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;
    75 
    76 #endif
    77 
    78 TBool F32Properties::iInitialised = 0;
    79 TInt  F32Properties::iRomAddress  = 0;
    80 TInt  F32Properties::iRomLength   = 0;
    81 
    82 EXPORT_C TBusLocalDrive& GetLocalDrive(TInt aDrive)
    83 //
    84 // Export localdrives
    85 //
    86 	{
    87 	return(LocalDrives::GetLocalDrive(aDrive));
    88 	}
    89 
    90 EXPORT_C TInt GetProxyDrive(TInt aDrive, CProxyDrive*& aProxyDrive)
    91 //
    92 // Export proxy drives
    93 //
    94 	{
    95 	return TheDrives[aDrive].CurrentMount().ProxyDrive(aProxyDrive);
    96 	}
    97 
    98 EXPORT_C CExtProxyDrive* GetProxyDrive(TInt aDrive)
    99 	{
   100 	return (LocalDrives::GetProxyDrive(aDrive));
   101 	}
   102 
   103 EXPORT_C TBool IsProxyDrive(TInt aDrive)
   104 	{
   105 	return (LocalDrives::IsProxyDrive(aDrive));
   106 	}
   107 
   108 EXPORT_C TBool IsValidLocalDriveMapping(TInt aDrive)
   109 //
   110 // Is the drive number to local drive mapping valid?
   111 //
   112 	{
   113 	return(LocalDrives::IsValidDriveMapping(aDrive));
   114 	}
   115 
   116 EXPORT_C TInt DriveNumberToLocalDriveNumber(TInt aDrive)
   117 //
   118 // Get the mapping from drive number to local drive
   119 //
   120 	{
   121 	return(LocalDrives::DriveNumberToLocalDriveNumber(aDrive));
   122 	}
   123 
   124 EXPORT_C TInt GetLocalDriveNumber(TBusLocalDrive* aLocDrv)
   125 //
   126 // Get the local drive number from local drive
   127 //
   128 	{
   129 	return(LocalDrives::GetLocalDriveNumber(aLocDrv));
   130 	}
   131 
   132 struct TFatUtilityFunctions;
   133 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   134 TBool EnableFatUtilityFunctions = ETrue;
   135 #endif
   136 EXPORT_C const TFatUtilityFunctions* GetFatUtilityFunctions()
   137 	{
   138 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   139 	if (!EnableFatUtilityFunctions)
   140 		{
   141 		return NULL; // Bypass Locale Dll/Codepage FAT converions, use default implementation
   142 		}
   143 #endif
   144 	switch(TheCodePage.CodepageLoaded())
   145 		{
   146 		case TCodePageUtils::ECodePageDll:
   147 			return ((TFatUtilityFunctions*)(TheCodePage.CodepageFatUtilityFunctions().iConvertFromUnicodeL));
   148 		case TCodePageUtils::ELocaleDll:
   149 			return TheCodePage.LocaleFatUtilityFunctions();
   150 		default:
   151 			return NULL; // if no Locale Dll/Codepage Dll is loaded, use default implementation
   152 		}
   153 	}
   154 
   155 EXPORT_C const TCodePageUtils& GetCodePage()
   156 	{
   157 	return TheCodePage;
   158 	}
   159 
   160 /**
   161 @internalTechnology
   162 Helper class for parsing F32 INI files
   163 */
   164 class TIniFileReader
   165 	{
   166 public:
   167 	TIniFileReader(const TPtrC8& aData);
   168 	TInt Next();
   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);
   173 public:
   174 	const TPtrC8& iData;
   175 	TPtr8 iCurrentLine;
   176 	TInt iCurrentPos;
   177 	};	
   178 
   179 
   180 /**
   181 @internalTechnology
   182 TIniFileReader constructor
   183 */
   184 TIniFileReader::TIniFileReader(const TPtrC8& aData)
   185   : iData(aData),
   186 	iCurrentLine(NULL,0,256),
   187     iCurrentPos(0)
   188 	{
   189 	}
   190 
   191 /**
   192 @internalTechnology
   193 
   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
   197 */
   198 TInt TIniFileReader::Next()
   199 	{
   200 	// Check if we have run into the end of the file	
   201 	TInt bufRemainder = (iData.Length()-iCurrentPos);
   202 	if (!bufRemainder)
   203 		{
   204 		return(KErrEof);
   205 		}
   206 		
   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)
   213 		{
   214 		iCurrentPos += len;
   215 		// Check for DOS line ending to support both DOS and Unix formats
   216 		if ((len != 0) && (((TUint8*)iData.Ptr())[iCurrentPos-1] == '\r'))
   217 			{
   218 			len--;
   219 			}
   220 		iCurrentLine.SetLength(len);
   221 		}
   222 	else
   223 		{
   224 		iCurrentPos=iData.Length();
   225 		}
   226 	
   227 	// Point iCurrentPos to the next non-empty line
   228 	while (iCurrentPos<iData.Length() && (((TUint8*)iData.Ptr())[iCurrentPos]=='\n' || ((TUint8*)iData.Ptr())[iCurrentPos]=='\r'))
   229 		{
   230 		iCurrentPos++;
   231 		}
   232 	
   233 	// iCurrentLine now describes a single line of the INI file
   234 	return(KErrNone);
   235 	}
   236 
   237 /**
   238 @internalTechnology
   239 
   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
   243 */
   244 TBool TIniFileReader::IsSection(const TDesC8& aSection)
   245 	{
   246 	TInt sectionStart = iCurrentLine.Locate('[');
   247 	TInt sectionEnd   = iCurrentLine.Locate(']');
   248 	if(sectionStart == 0 && sectionEnd > 1)
   249 		{
   250 		if(aSection == KNullDesC8)
   251 			{
   252 			return(ETrue);
   253 			} 
   254 
   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)
   259 			{
   260 			return(ETrue);
   261 			}
   262 		}
   263 	return(EFalse);
   264 	}
   265 
   266 /**
   267 @internalTechnology
   268 
   269 Examines the current INI line, returning ETrue if the line contains the requested property
   270 */
   271 TBool TIniFileReader::IsProperty(const TDesC8& aProperty, TBool& aPropVal)
   272 	{
   273 	TPtrC8 token;
   274 	TLex8 lex(iCurrentLine);
   275 	token.Set(lex.NextToken());
   276 	if (token.Length() == 0 || token != aProperty)
   277 		{
   278 		return(EFalse);
   279 		}
   280 
   281 	lex.SkipSpace();
   282 
   283 	TInt32 propVal;
   284 	if (lex.BoundedVal(propVal, 1) == KErrNone)
   285 		{
   286 		aPropVal = propVal;
   287 		return(ETrue);
   288 		}
   289 
   290 	// allow "on" or "off" strings if no integer found
   291 	_LIT8(KBoolOn,"ON");
   292 	_LIT8(KBoolOff,"OFF");
   293 
   294 	if (lex.Remainder().Left(KBoolOn().Length()).CompareF(KBoolOn) == KErrNone)
   295 		{
   296 		aPropVal = ETrue;
   297 		return(ETrue);
   298 		}
   299 	if (lex.Remainder().Left(KBoolOff().Length()).CompareF(KBoolOff) == KErrNone)
   300 		{
   301 		aPropVal = EFalse;
   302 		return(ETrue);
   303 		}
   304 
   305 	return(EFalse);
   306 	}
   307 
   308 /**
   309 @internalTechnology
   310 
   311 Examines the current INI line, returning ETrue if the line contains the requested property
   312 */
   313 TBool TIniFileReader::IsProperty(const TDesC8& aProperty, TInt32& aPropVal)
   314 	{
   315 	TPtrC8 token;
   316 	TLex8 lex(iCurrentLine);
   317 	token.Set(lex.NextToken());
   318 	if (token.Length() == 0 || token != aProperty)
   319 		{
   320 		return(EFalse);
   321 		}
   322 
   323 	lex.SkipSpace();
   324 
   325 	TInt32 propVal;
   326 	if (lex.Val(propVal) != KErrNone)
   327 		{
   328 		return(EFalse);
   329 		}
   330 
   331 	aPropVal = propVal;
   332 
   333 	return(ETrue);
   334 	}
   335 
   336 /**
   337 @internalTechnology
   338 
   339 Examines the current INI line, returning ETrue if the line contains the requested property
   340 */
   341 TBool TIniFileReader::IsProperty(const TDesC8& aProperty, TDes8& aPropVal)
   342 	{
   343 	TPtrC8 token;
   344 	TLex8 lex(iCurrentLine);
   345 	token.Set(lex.NextToken());
   346 	if (token.Length() == 0 || token != aProperty)
   347 		{
   348 		return(EFalse);
   349 		}
   350 
   351 	lex.SkipSpace();
   352 
   353 	aPropVal = lex.Remainder().Left(aPropVal.MaxLength());
   354 
   355 	return(ETrue);
   356 	}
   357 
   358 /**
   359 @internalTechnology
   360 
   361 Initialises the F32 properties with a ROM address representing the INI file in ROM
   362 
   363 @return KErrNone on success
   364 @return KErrAlreadyExists if the properties have already been initialised
   365 */
   366 EXPORT_C TInt F32Properties::Initialise(TInt aRomAddress, TInt aLength)
   367 	{
   368 	if(iInitialised)
   369 		{
   370 		// F32 properties have already been initialised
   371 		return(KErrAlreadyExists);
   372 		}
   373 
   374 	iInitialised = ETrue;
   375 	iRomAddress  = aRomAddress;
   376 	iRomLength   = aLength;
   377 
   378 	return(KErrNone);
   379 	}
   380 
   381 /**
   382 @internalTechnology
   383 
   384 Returns the requested F32 property string
   385 
   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)
   389 
   390 @return ETrue if the property exists, EFalse otherwise
   391 */
   392 EXPORT_C TBool F32Properties::GetString(const TDesC8& aSection, const TDesC8& aProperty, TDes8& aPropVal)
   393 	{
   394 	if(!iInitialised)
   395 		{
   396 		return(EFalse);
   397 		}
   398 
   399 	TPtrC8 iniPtr((TUint8*)iRomAddress, iRomLength);
   400 	TIniFileReader iniReader(iniPtr);
   401 
   402 	FOREVER
   403 		{
   404 		// Read the next line of the INI file
   405 		if(iniReader.Next() == KErrEof)
   406 			{
   407 			break;
   408 			}		
   409 
   410 		if(iniReader.IsSection(aSection))
   411 			{
   412 			// Found the section we're interested in
   413 			//  - look for the property, until we get to EOF or the next section
   414 			FOREVER
   415 				{
   416 				if(iniReader.Next() == KErrEof)
   417 					{
   418 					return(EFalse);
   419 					}
   420 				
   421 				if(iniReader.IsSection())
   422 					{
   423 					return(EFalse);
   424 					}
   425 
   426 				if(iniReader.IsProperty(aProperty, aPropVal))
   427 					{
   428 					return(ETrue);
   429 					}
   430 				}
   431 			}
   432 		}
   433 
   434 	// No section found...
   435 	return(EFalse);
   436 	}
   437 
   438 /**
   439 @internalTechnology
   440 
   441 Returns the requested integer F32 property value
   442 
   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)
   446 
   447 @return ETrue if the property exists, EFalse otherwise
   448 */
   449 EXPORT_C TBool F32Properties::GetInt(const TDesC8& aSection, const TDesC8& aProperty, TInt32& aPropVal)
   450 	{
   451 	if(!iInitialised)
   452 		{
   453 		return(EFalse);
   454 		}
   455 
   456 	TPtrC8 iniPtr((TUint8*)iRomAddress, iRomLength);
   457 	TIniFileReader iniReader(iniPtr);
   458 
   459 	FOREVER
   460 		{
   461 		// Read the next line of the INI file
   462 		if(iniReader.Next() == KErrEof)
   463 			{
   464 			break;
   465 			}		
   466 
   467 		if(iniReader.IsSection(aSection))
   468 			{
   469 			// Found the section we're interested in
   470 			//  - look for the property, until we get to EOF or the next section
   471 			FOREVER
   472 				{
   473 				if(iniReader.Next() == KErrEof)
   474 					{
   475 					return(EFalse);
   476 					}
   477 				
   478 				
   479 				if(iniReader.IsSection())
   480 					{
   481 					return(EFalse);
   482 					}
   483 
   484 				if(iniReader.IsProperty(aProperty, aPropVal))
   485 					{
   486 					return(ETrue);
   487 					}
   488 				}
   489 			}
   490 		}
   491 
   492 	// No section found...
   493 	return(EFalse);
   494 	}
   495 
   496 /**
   497 @internalTechnology
   498 
   499 Returns the requested boolean F32 property value
   500 
   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)
   504 
   505 @return ETrue if the property exists, EFalse otherwise
   506 */
   507 EXPORT_C TBool F32Properties::GetBool(const TDesC8& aSection, const TDesC8& aProperty, TBool& aPropVal)
   508 	{
   509 	if(!iInitialised)
   510 		{
   511 		return(EFalse);
   512 		}
   513 
   514 	TPtrC8 iniPtr((TUint8*)iRomAddress, iRomLength);
   515 	TIniFileReader iniReader(iniPtr);
   516 
   517 	FOREVER
   518 		{
   519 		// Read the next line of the INI file
   520 		if(iniReader.Next() == KErrEof)
   521 			{
   522 			break;
   523 			}		
   524 
   525 		if(iniReader.IsSection(aSection))
   526 			{
   527 			// Found the section we're interested in
   528 			//  - look for the property, until we get to EOF or the next section
   529 			FOREVER
   530 				{
   531 				if(iniReader.Next() == KErrEof)
   532 					{
   533 					return(EFalse);
   534 					}
   535 				if(iniReader.IsSection())
   536 					{
   537 					return(EFalse);
   538 					}
   539 
   540 				if(iniReader.IsProperty(aProperty, aPropVal))
   541 					{
   542 					return(ETrue);
   543 					}
   544 				}
   545 			}
   546 		}
   547 
   548 	// No section found...
   549 	return(EFalse);
   550 	}
   551 
   552 /**
   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
   556 */
   557 EXPORT_C void GetDriveInfo(TDriveInfo& anInfo, TInt aDriveNumber)
   558     {
   559 	if(!IsValidLocalDriveMapping(aDriveNumber))
   560 		return;
   561 
   562     TLocalDriveCapsBuf localDriveCaps;
   563 
   564 	TInt r = KErrNone;
   565 
   566 	// is the drive local?
   567 	if (!IsProxyDrive(aDriveNumber))
   568 		{
   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);
   573 		}
   574 	else
   575 		{
   576 		CExtProxyDrive* pD = GetProxyDrive(aDriveNumber);
   577         __ASSERT_ALWAYS(pD != NULL,User::Panic(_L("GetDriveInfo - pProxyDrive == NULL"), -999));
   578 		r = pD->Caps(localDriveCaps);
   579 		}
   580 
   581     TLocalDriveCaps& caps = localDriveCaps();
   582 	if (r != KErrLocked)
   583 		{
   584 		anInfo.iMediaAtt=caps.iMediaAtt;
   585 		}
   586 	else
   587 		{
   588 		anInfo.iMediaAtt = KMediaAttLocked | KMediaAttLockable | KMediaAttHasPassword;
   589 		}
   590 
   591 	anInfo.iType=caps.iType;
   592 	anInfo.iDriveAtt=caps.iDriveAtt;
   593     anInfo.iConnectionBusType=caps.iConnectionBusType;
   594     }
   595 
   596 
   597 
   598