1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_dat.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,598 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32\sfile\sf_dat.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include "sf_std.h"
1.22 +
1.23 +
1.24 +CFsObjectConIx* TheContainer;
1.25 +CFsObjectCon* FileSystems;
1.26 +CFsObjectCon* Files;
1.27 +CFsObjectCon* FileShares;
1.28 +CFsObjectCon* Dirs;
1.29 +CFsObjectCon* Formats;
1.30 +CFsObjectCon* RawDisks;
1.31 +CFsObjectCon* Extensions;
1.32 +CFsObjectCon* ProxyDrives;
1.33 +
1.34 +CServerFs* TheFileServer;
1.35 +TDrive TheDrives[KMaxDrives];
1.36 +
1.37 +//#ifndef __SECURE_API__
1.38 +TFileName TheDefaultPath;
1.39 +//#endif
1.40 +
1.41 +HBufC* TheDriveNames[KMaxDrives];
1.42 +
1.43 +
1.44 +SCapabilitySet AllCapabilities;
1.45 +SCapabilitySet DisabledCapabilities;
1.46 +
1.47 +RThread TheServerThread;
1.48 +RAllocator* ServerThreadAllocator;
1.49 +TBool OpenOnDriveZOnly;
1.50 +TBool LocalFileSystemInitialized;
1.51 +TBool RefreshZDriveCache;
1.52 +TBool CompFsMounted;
1.53 +TBool CompFsSync;
1.54 +TBool StartupInitCompleted;
1.55 +TBool LocalDriveMappingSet;
1.56 +CKernEventNotifier* TheKernEventNotifier;
1.57 +RFTrace TheFtrace;
1.58 +
1.59 +
1.60 +GLDEF_D TCodePageUtils TheCodePage;
1.61 +
1.62 +TBool FatUtilityFunctionsSet = EFalse; //-- Flag. Is set to ETrue when LoadLocale() sets a pointer to TFatUtilityFunctions
1.63 +TBool FatUtilitiesUpdateDrivesNotified = EFalse; //-- Flag. Is set to ETrue when all drives get a notification about locale change
1.64 +
1.65 +
1.66 +
1.67 +#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1.68 +TInt ErrorCondition;
1.69 +TInt ErrorCount;
1.70 +TUint32 DebugReg;
1.71 +TInt UserHeapAllocFailCount;
1.72 +TInt KernHeapAllocFailCount;
1.73 +TInt DebugNCNotifier=0;
1.74 +TCorruptNameRec* gCorruptFileNameList=NULL;
1.75 +TCorruptLogRec* gCorruptLogRecordList=NULL;
1.76 +TInt gNumberOfCorruptHits=0;
1.77 +HBufC* gCorruptFileNamesListFile=NULL;
1.78 +
1.79 +#endif
1.80 +
1.81 +TBool F32Properties::iInitialised = 0;
1.82 +TInt F32Properties::iRomAddress = 0;
1.83 +TInt F32Properties::iRomLength = 0;
1.84 +
1.85 +EXPORT_C TBusLocalDrive& GetLocalDrive(TInt aDrive)
1.86 +//
1.87 +// Export localdrives
1.88 +//
1.89 + {
1.90 + return(LocalDrives::GetLocalDrive(aDrive));
1.91 + }
1.92 +
1.93 +EXPORT_C TInt GetProxyDrive(TInt aDrive, CProxyDrive*& aProxyDrive)
1.94 +//
1.95 +// Export proxy drives
1.96 +//
1.97 + {
1.98 + return TheDrives[aDrive].CurrentMount().ProxyDrive(aProxyDrive);
1.99 + }
1.100 +
1.101 +EXPORT_C CExtProxyDrive* GetProxyDrive(TInt aDrive)
1.102 + {
1.103 + return (LocalDrives::GetProxyDrive(aDrive));
1.104 + }
1.105 +
1.106 +EXPORT_C TBool IsProxyDrive(TInt aDrive)
1.107 + {
1.108 + return (LocalDrives::IsProxyDrive(aDrive));
1.109 + }
1.110 +
1.111 +EXPORT_C TBool IsValidLocalDriveMapping(TInt aDrive)
1.112 +//
1.113 +// Is the drive number to local drive mapping valid?
1.114 +//
1.115 + {
1.116 + return(LocalDrives::IsValidDriveMapping(aDrive));
1.117 + }
1.118 +
1.119 +EXPORT_C TInt DriveNumberToLocalDriveNumber(TInt aDrive)
1.120 +//
1.121 +// Get the mapping from drive number to local drive
1.122 +//
1.123 + {
1.124 + return(LocalDrives::DriveNumberToLocalDriveNumber(aDrive));
1.125 + }
1.126 +
1.127 +EXPORT_C TInt GetLocalDriveNumber(TBusLocalDrive* aLocDrv)
1.128 +//
1.129 +// Get the local drive number from local drive
1.130 +//
1.131 + {
1.132 + return(LocalDrives::GetLocalDriveNumber(aLocDrv));
1.133 + }
1.134 +
1.135 +struct TFatUtilityFunctions;
1.136 +#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1.137 +TBool EnableFatUtilityFunctions = ETrue;
1.138 +#endif
1.139 +EXPORT_C const TFatUtilityFunctions* GetFatUtilityFunctions()
1.140 + {
1.141 +#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1.142 + if (!EnableFatUtilityFunctions)
1.143 + {
1.144 + return NULL; // Bypass Locale Dll/Codepage FAT converions, use default implementation
1.145 + }
1.146 +#endif
1.147 + switch(TheCodePage.CodepageLoaded())
1.148 + {
1.149 + case TCodePageUtils::ECodePageDll:
1.150 + return ((TFatUtilityFunctions*)(TheCodePage.CodepageFatUtilityFunctions().iConvertFromUnicodeL));
1.151 + case TCodePageUtils::ELocaleDll:
1.152 + return TheCodePage.LocaleFatUtilityFunctions();
1.153 + default:
1.154 + return NULL; // if no Locale Dll/Codepage Dll is loaded, use default implementation
1.155 + }
1.156 + }
1.157 +
1.158 +EXPORT_C const TCodePageUtils& GetCodePage()
1.159 + {
1.160 + return TheCodePage;
1.161 + }
1.162 +
1.163 +/**
1.164 +@internalTechnology
1.165 +Helper class for parsing F32 INI files
1.166 +*/
1.167 +class TIniFileReader
1.168 + {
1.169 +public:
1.170 + TIniFileReader(const TPtrC8& aData);
1.171 + TInt Next();
1.172 + TBool IsSection(const TDesC8& aSection = KNullDesC8);
1.173 + TBool IsProperty(const TDesC8& aProperty, TBool& aPropVal);
1.174 + TBool IsProperty(const TDesC8& aProperty, TInt32& aPropVal);
1.175 + TBool IsProperty(const TDesC8& aProperty, TDes8& aPropVal);
1.176 +public:
1.177 + const TPtrC8& iData;
1.178 + TPtr8 iCurrentLine;
1.179 + TInt iCurrentPos;
1.180 + };
1.181 +
1.182 +
1.183 +/**
1.184 +@internalTechnology
1.185 +TIniFileReader constructor
1.186 +*/
1.187 +TIniFileReader::TIniFileReader(const TPtrC8& aData)
1.188 + : iData(aData),
1.189 + iCurrentLine(NULL,0,256),
1.190 + iCurrentPos(0)
1.191 + {
1.192 + }
1.193 +
1.194 +/**
1.195 +@internalTechnology
1.196 +
1.197 +Reads the next line from an F32 INI file.
1.198 + - On exit, iCurrentLine represents the current line
1.199 + - On exit, iCurrentPos points to the next line in the INI file
1.200 +*/
1.201 +TInt TIniFileReader::Next()
1.202 + {
1.203 + // Check if we have run into the end of the file
1.204 + TInt bufRemainder = (iData.Length()-iCurrentPos);
1.205 + if (!bufRemainder)
1.206 + {
1.207 + return(KErrEof);
1.208 + }
1.209 +
1.210 + // Setup the descriptor passed with the next record - don't include the record terminator
1.211 + // The line terminators are CR + LF for DOS
1.212 + // whereas only LF for Unix line endings
1.213 + iCurrentLine.Set(((TUint8*)iData.Ptr()+iCurrentPos),bufRemainder,bufRemainder);
1.214 + TInt len = iCurrentLine.Locate('\n');
1.215 + if (len != KErrNotFound)
1.216 + {
1.217 + iCurrentPos += len;
1.218 + // Check for DOS line ending to support both DOS and Unix formats
1.219 + if ((len != 0) && (((TUint8*)iData.Ptr())[iCurrentPos-1] == '\r'))
1.220 + {
1.221 + len--;
1.222 + }
1.223 + iCurrentLine.SetLength(len);
1.224 + }
1.225 + else
1.226 + {
1.227 + iCurrentPos=iData.Length();
1.228 + }
1.229 +
1.230 + // Point iCurrentPos to the next non-empty line
1.231 + while (iCurrentPos<iData.Length() && (((TUint8*)iData.Ptr())[iCurrentPos]=='\n' || ((TUint8*)iData.Ptr())[iCurrentPos]=='\r'))
1.232 + {
1.233 + iCurrentPos++;
1.234 + }
1.235 +
1.236 + // iCurrentLine now describes a single line of the INI file
1.237 + return(KErrNone);
1.238 + }
1.239 +
1.240 +/**
1.241 +@internalTechnology
1.242 +
1.243 +Examines the current INI line, returning ETrue if the line contains the requested INI section
1.244 + - An INI section must be of the form [section_name]
1.245 + - Passing KNullDesC as an argument returns ETrue if the line describes any INI section
1.246 +*/
1.247 +TBool TIniFileReader::IsSection(const TDesC8& aSection)
1.248 + {
1.249 + TInt sectionStart = iCurrentLine.Locate('[');
1.250 + TInt sectionEnd = iCurrentLine.Locate(']');
1.251 + if(sectionStart == 0 && sectionEnd > 1)
1.252 + {
1.253 + if(aSection == KNullDesC8)
1.254 + {
1.255 + return(ETrue);
1.256 + }
1.257 +
1.258 + const TInt sectionLength = sectionEnd-sectionStart-1;
1.259 + // Found a start of section marker - does it match what we're interested in?
1.260 + TPtr8 sectionPtr(&iCurrentLine[1+sectionStart], sectionLength, sectionLength);
1.261 + if(sectionPtr == aSection)
1.262 + {
1.263 + return(ETrue);
1.264 + }
1.265 + }
1.266 + return(EFalse);
1.267 + }
1.268 +
1.269 +/**
1.270 +@internalTechnology
1.271 +
1.272 +Examines the current INI line, returning ETrue if the line contains the requested property
1.273 +*/
1.274 +TBool TIniFileReader::IsProperty(const TDesC8& aProperty, TBool& aPropVal)
1.275 + {
1.276 + TPtrC8 token;
1.277 + TLex8 lex(iCurrentLine);
1.278 + token.Set(lex.NextToken());
1.279 + if (token.Length() == 0 || token != aProperty)
1.280 + {
1.281 + return(EFalse);
1.282 + }
1.283 +
1.284 + lex.SkipSpace();
1.285 +
1.286 + TInt32 propVal;
1.287 + if (lex.BoundedVal(propVal, 1) == KErrNone)
1.288 + {
1.289 + aPropVal = propVal;
1.290 + return(ETrue);
1.291 + }
1.292 +
1.293 + // allow "on" or "off" strings if no integer found
1.294 + _LIT8(KBoolOn,"ON");
1.295 + _LIT8(KBoolOff,"OFF");
1.296 +
1.297 + if (lex.Remainder().Left(KBoolOn().Length()).CompareF(KBoolOn) == KErrNone)
1.298 + {
1.299 + aPropVal = ETrue;
1.300 + return(ETrue);
1.301 + }
1.302 + if (lex.Remainder().Left(KBoolOff().Length()).CompareF(KBoolOff) == KErrNone)
1.303 + {
1.304 + aPropVal = EFalse;
1.305 + return(ETrue);
1.306 + }
1.307 +
1.308 + return(EFalse);
1.309 + }
1.310 +
1.311 +/**
1.312 +@internalTechnology
1.313 +
1.314 +Examines the current INI line, returning ETrue if the line contains the requested property
1.315 +*/
1.316 +TBool TIniFileReader::IsProperty(const TDesC8& aProperty, TInt32& aPropVal)
1.317 + {
1.318 + TPtrC8 token;
1.319 + TLex8 lex(iCurrentLine);
1.320 + token.Set(lex.NextToken());
1.321 + if (token.Length() == 0 || token != aProperty)
1.322 + {
1.323 + return(EFalse);
1.324 + }
1.325 +
1.326 + lex.SkipSpace();
1.327 +
1.328 + TInt32 propVal;
1.329 + if (lex.Val(propVal) != KErrNone)
1.330 + {
1.331 + return(EFalse);
1.332 + }
1.333 +
1.334 + aPropVal = propVal;
1.335 +
1.336 + return(ETrue);
1.337 + }
1.338 +
1.339 +/**
1.340 +@internalTechnology
1.341 +
1.342 +Examines the current INI line, returning ETrue if the line contains the requested property
1.343 +*/
1.344 +TBool TIniFileReader::IsProperty(const TDesC8& aProperty, TDes8& aPropVal)
1.345 + {
1.346 + TPtrC8 token;
1.347 + TLex8 lex(iCurrentLine);
1.348 + token.Set(lex.NextToken());
1.349 + if (token.Length() == 0 || token != aProperty)
1.350 + {
1.351 + return(EFalse);
1.352 + }
1.353 +
1.354 + lex.SkipSpace();
1.355 +
1.356 + aPropVal = lex.Remainder().Left(aPropVal.MaxLength());
1.357 +
1.358 + return(ETrue);
1.359 + }
1.360 +
1.361 +/**
1.362 +@internalTechnology
1.363 +
1.364 +Initialises the F32 properties with a ROM address representing the INI file in ROM
1.365 +
1.366 +@return KErrNone on success
1.367 +@return KErrAlreadyExists if the properties have already been initialised
1.368 +*/
1.369 +EXPORT_C TInt F32Properties::Initialise(TInt aRomAddress, TInt aLength)
1.370 + {
1.371 + if(iInitialised)
1.372 + {
1.373 + // F32 properties have already been initialised
1.374 + return(KErrAlreadyExists);
1.375 + }
1.376 +
1.377 + iInitialised = ETrue;
1.378 + iRomAddress = aRomAddress;
1.379 + iRomLength = aLength;
1.380 +
1.381 + return(KErrNone);
1.382 + }
1.383 +
1.384 +/**
1.385 +@internalTechnology
1.386 +
1.387 +Returns the requested F32 property string
1.388 +
1.389 +@param aSection The name of the F32 INI section
1.390 +@param aProperty The name of the F32 propery within the section
1.391 +@param aPropVal Returns the requested property value (unchanged if the property does not exist)
1.392 +
1.393 +@return ETrue if the property exists, EFalse otherwise
1.394 +*/
1.395 +EXPORT_C TBool F32Properties::GetString(const TDesC8& aSection, const TDesC8& aProperty, TDes8& aPropVal)
1.396 + {
1.397 + if(!iInitialised)
1.398 + {
1.399 + return(EFalse);
1.400 + }
1.401 +
1.402 + TPtrC8 iniPtr((TUint8*)iRomAddress, iRomLength);
1.403 + TIniFileReader iniReader(iniPtr);
1.404 +
1.405 + FOREVER
1.406 + {
1.407 + // Read the next line of the INI file
1.408 + if(iniReader.Next() == KErrEof)
1.409 + {
1.410 + break;
1.411 + }
1.412 +
1.413 + if(iniReader.IsSection(aSection))
1.414 + {
1.415 + // Found the section we're interested in
1.416 + // - look for the property, until we get to EOF or the next section
1.417 + FOREVER
1.418 + {
1.419 + if(iniReader.Next() == KErrEof)
1.420 + {
1.421 + return(EFalse);
1.422 + }
1.423 +
1.424 + if(iniReader.IsSection())
1.425 + {
1.426 + return(EFalse);
1.427 + }
1.428 +
1.429 + if(iniReader.IsProperty(aProperty, aPropVal))
1.430 + {
1.431 + return(ETrue);
1.432 + }
1.433 + }
1.434 + }
1.435 + }
1.436 +
1.437 + // No section found...
1.438 + return(EFalse);
1.439 + }
1.440 +
1.441 +/**
1.442 +@internalTechnology
1.443 +
1.444 +Returns the requested integer F32 property value
1.445 +
1.446 +@param aSection The name of the F32 INI section
1.447 +@param aProperty The name of the F32 propery within the section
1.448 +@param aPropVal Returns the requested property value (unchanged if the property does not exist)
1.449 +
1.450 +@return ETrue if the property exists, EFalse otherwise
1.451 +*/
1.452 +EXPORT_C TBool F32Properties::GetInt(const TDesC8& aSection, const TDesC8& aProperty, TInt32& aPropVal)
1.453 + {
1.454 + if(!iInitialised)
1.455 + {
1.456 + return(EFalse);
1.457 + }
1.458 +
1.459 + TPtrC8 iniPtr((TUint8*)iRomAddress, iRomLength);
1.460 + TIniFileReader iniReader(iniPtr);
1.461 +
1.462 + FOREVER
1.463 + {
1.464 + // Read the next line of the INI file
1.465 + if(iniReader.Next() == KErrEof)
1.466 + {
1.467 + break;
1.468 + }
1.469 +
1.470 + if(iniReader.IsSection(aSection))
1.471 + {
1.472 + // Found the section we're interested in
1.473 + // - look for the property, until we get to EOF or the next section
1.474 + FOREVER
1.475 + {
1.476 + if(iniReader.Next() == KErrEof)
1.477 + {
1.478 + return(EFalse);
1.479 + }
1.480 +
1.481 +
1.482 + if(iniReader.IsSection())
1.483 + {
1.484 + return(EFalse);
1.485 + }
1.486 +
1.487 + if(iniReader.IsProperty(aProperty, aPropVal))
1.488 + {
1.489 + return(ETrue);
1.490 + }
1.491 + }
1.492 + }
1.493 + }
1.494 +
1.495 + // No section found...
1.496 + return(EFalse);
1.497 + }
1.498 +
1.499 +/**
1.500 +@internalTechnology
1.501 +
1.502 +Returns the requested boolean F32 property value
1.503 +
1.504 +@param aSection The name of the F32 INI section
1.505 +@param aProperty The name of the F32 propery within the section
1.506 +@param aPropVal Returns the requested property value (unchanged if the property does not exist)
1.507 +
1.508 +@return ETrue if the property exists, EFalse otherwise
1.509 +*/
1.510 +EXPORT_C TBool F32Properties::GetBool(const TDesC8& aSection, const TDesC8& aProperty, TBool& aPropVal)
1.511 + {
1.512 + if(!iInitialised)
1.513 + {
1.514 + return(EFalse);
1.515 + }
1.516 +
1.517 + TPtrC8 iniPtr((TUint8*)iRomAddress, iRomLength);
1.518 + TIniFileReader iniReader(iniPtr);
1.519 +
1.520 + FOREVER
1.521 + {
1.522 + // Read the next line of the INI file
1.523 + if(iniReader.Next() == KErrEof)
1.524 + {
1.525 + break;
1.526 + }
1.527 +
1.528 + if(iniReader.IsSection(aSection))
1.529 + {
1.530 + // Found the section we're interested in
1.531 + // - look for the property, until we get to EOF or the next section
1.532 + FOREVER
1.533 + {
1.534 + if(iniReader.Next() == KErrEof)
1.535 + {
1.536 + return(EFalse);
1.537 + }
1.538 + if(iniReader.IsSection())
1.539 + {
1.540 + return(EFalse);
1.541 + }
1.542 +
1.543 + if(iniReader.IsProperty(aProperty, aPropVal))
1.544 + {
1.545 + return(ETrue);
1.546 + }
1.547 + }
1.548 + }
1.549 + }
1.550 +
1.551 + // No section found...
1.552 + return(EFalse);
1.553 + }
1.554 +
1.555 +/**
1.556 + Obtain drive information. This function is called by the default implementation of CFileSystem::DriveInfo().
1.557 + @param anInfo out: drive information
1.558 + @param aDriveNumber drive number
1.559 +*/
1.560 +EXPORT_C void GetDriveInfo(TDriveInfo& anInfo, TInt aDriveNumber)
1.561 + {
1.562 + if(!IsValidLocalDriveMapping(aDriveNumber))
1.563 + return;
1.564 +
1.565 + TLocalDriveCapsBuf localDriveCaps;
1.566 +
1.567 + TInt r = KErrNone;
1.568 +
1.569 + // is the drive local?
1.570 + if (!IsProxyDrive(aDriveNumber))
1.571 + {
1.572 + // if not valid local drive, use default values in localDriveCaps
1.573 + // if valid local drive and not locked, use TBusLocalDrive::Caps() values
1.574 + // if valid drive and locked, hard-code attributes
1.575 + r = GetLocalDrive(aDriveNumber).Caps(localDriveCaps);
1.576 + }
1.577 + else
1.578 + {
1.579 + CExtProxyDrive* pD = GetProxyDrive(aDriveNumber);
1.580 + __ASSERT_ALWAYS(pD != NULL,User::Panic(_L("GetDriveInfo - pProxyDrive == NULL"), -999));
1.581 + r = pD->Caps(localDriveCaps);
1.582 + }
1.583 +
1.584 + TLocalDriveCaps& caps = localDriveCaps();
1.585 + if (r != KErrLocked)
1.586 + {
1.587 + anInfo.iMediaAtt=caps.iMediaAtt;
1.588 + }
1.589 + else
1.590 + {
1.591 + anInfo.iMediaAtt = KMediaAttLocked | KMediaAttLockable | KMediaAttHasPassword;
1.592 + }
1.593 +
1.594 + anInfo.iType=caps.iType;
1.595 + anInfo.iDriveAtt=caps.iDriveAtt;
1.596 + anInfo.iConnectionBusType=caps.iConnectionBusType;
1.597 + }
1.598 +
1.599 +
1.600 +
1.601 +