1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Framework/frame/DriveInfo.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,360 @@
1.4 +// Copyright (c) 2006-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 "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 +// Implementation for CEComCachedDriveInfo class
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 + @internalComponent
1.24 +*/
1.25 +
1.26 +#include <e32const.h>
1.27 +#include <f32file.h>
1.28 +#include <bsul/bsul.h>
1.29 +#include <ecom/ecomerrorcodes.h>
1.30 +#include "DriveInfo.h"
1.31 +#include "EComPatchDataConstantv2.h"
1.32 +#include "EComInternalErrorCodes.h"
1.33 +const TInt KInvalidIndex = -1;
1.34 +const TInt32 KInvalidDrvNumber = -1;
1.35 +
1.36 +/** static member of CEComCachedDriveInfo */
1.37 +TFixedArray<TEComDrvFlags, KMaxDrives> CEComCachedDriveInfo::iDriveAttr;
1.38 +
1.39 +/** static member of CEComCachedDriveInfo */
1.40 +TInt CEComCachedDriveInfo::iLastIndex = KInvalidIndex;
1.41 +
1.42 +/** static member of CEComCachedDriveInfo */
1.43 +TBool CEComCachedDriveInfo::iInitialized = EFalse;
1.44 +
1.45 +
1.46 +/** Standard factory method to instantiate CEComCachedDriveInfo instances.
1.47 +*/
1.48 +CEComCachedDriveInfo* CEComCachedDriveInfo::NewL(RFs& aFs)
1.49 + {
1.50 + CEComCachedDriveInfo* self = new (ELeave) CEComCachedDriveInfo;
1.51 + CleanupStack::PushL(self);
1.52 + self->ConstructL(aFs, KDiscoveryDisabledDriveList);
1.53 + CleanupStack::Pop(self);
1.54 + return self;
1.55 + }
1.56 +
1.57 +/** Constructor of CEComCachedDriveInfo. Nothing to do. */
1.58 +CEComCachedDriveInfo::CEComCachedDriveInfo()
1.59 + {
1.60 + }
1.61 +
1.62 +/** Standard two-phase construction to complete construction
1.63 +of CEComCachedDriveInfo.
1.64 +
1.65 +@param aFs reference to a connected RFs session.
1.66 +@param aDiscoveryDisabledMask bits set indicate the drives contain no plug-ins
1.67 + and need not be scanned. There is a mechanism to allow licensees to
1.68 + specify this mask at ROM build time.
1.69 +@leave KErrNoMemory if out of memory, or any of the other system wide errors.
1.70 +*/
1.71 +void CEComCachedDriveInfo::ConstructL(RFs& aFs, TUint32 aDiscoveryDisabledMask)
1.72 + {
1.73 + if (iInitialized)
1.74 + {
1.75 + return;
1.76 + }
1.77 +
1.78 + iLastIndex = KInvalidIndex;
1.79 +
1.80 + // Get list of installed drives. This info is not available from
1.81 + // BSUL::CCachedDriveInfo API's.
1.82 + TDriveList drvList;
1.83 + User::LeaveIfError( aFs.DriveList(drvList) );
1.84 +
1.85 + BSUL::CCachedDriveInfo* cachedDrvInfo = BSUL::CCachedDriveInfo::NewL(aFs);
1.86 + CleanupStack::PushL(cachedDrvInfo);
1.87 +
1.88 + // determine attributes of valid drives
1.89 + for (TInt i = EDriveA; i <= EDriveZ; i++)
1.90 + {
1.91 + if (drvList[i])
1.92 + {
1.93 + // drive exist
1.94 + TInt j = ++iLastIndex;
1.95 +
1.96 + iDriveAttr[j].iDrvNumber = i;
1.97 +
1.98 + TDriveUnit drvUnit(i);
1.99 + if (cachedDrvInfo->IsReadOnlyInternalL(drvUnit))
1.100 + {
1.101 + iDriveAttr[j].iFlags = EEComDrvAttrReadOnlyInternal;
1.102 + // RO internal drive does not have any other attributes
1.103 + continue;
1.104 + }
1.105 +
1.106 + iDriveAttr[j].iFlags = 0;
1.107 +
1.108 + // Check if drive is removable
1.109 + if (cachedDrvInfo->IsFlagSetOnDriveL(drvUnit, KDriveAttRemovable))
1.110 + {
1.111 + iDriveAttr[j].iFlags |= EEComDrvAttrRemovable;
1.112 + }
1.113 +
1.114 + // Check if drive is on ReadWrite drive
1.115 + if (! cachedDrvInfo->IsFlagSetOnDriveL(drvUnit, KDriveAttRom))
1.116 + {
1.117 + iDriveAttr[j].iFlags |= EEComDrvAttrWritable;
1.118 + }
1.119 +
1.120 + TUint32 drvBitMask = 1;
1.121 + drvBitMask <<= i;
1.122 + // Three conditions for discovery disable: disabled by licensees,
1.123 + // remote drives and substituted drives
1.124 + if ( (drvBitMask & aDiscoveryDisabledMask) ||
1.125 + cachedDrvInfo->IsFlagSetOnDriveL(drvUnit, KDriveAttSubsted) ||
1.126 + cachedDrvInfo->IsFlagSetOnDriveL(drvUnit, KDriveAttRemote) )
1.127 + {
1.128 + iDriveAttr[j].iFlags |= EEComDrvAttrNoDiscovery;
1.129 + }
1.130 + } // if drvList[i]
1.131 + } // for
1.132 +
1.133 + CleanupStack::PopAndDestroy(cachedDrvInfo);
1.134 + __ASSERT_DEBUG(iLastIndex >= 0, User::Invariant());
1.135 +
1.136 + for (TInt i = iLastIndex + 1; i < KMaxDrives; i++)
1.137 + {
1.138 + iDriveAttr[i].iDrvNumber = KInvalidDrvNumber;
1.139 + }
1.140 +
1.141 + iInitialized = ETrue;
1.142 + }
1.143 +
1.144 +/** Is EEComDrvAttrReadOnlyInternal attribute set on the given drive?
1.145 +@param aDrive the drive number
1.146 +@return ETrue if drive is RO internal. EFalse means either no such drive or
1.147 + not RO internal.
1.148 +@leave KEComErrDriveNotFound if aDrive is not supposed to be scanned,
1.149 + i.e. drive absent or disabled by licensees or subst or remote.
1.150 + Use TEComCachedDriveInfoIterator::SetPos instead if want to test drive
1.151 + attribute.
1.152 +*/
1.153 +TBool CEComCachedDriveInfo::DriveIsReadOnlyInternalL(const TInt aDrive) const
1.154 + {
1.155 + TEComCachedDriveInfoIterator iter(*this);
1.156 +
1.157 + if (! iter.SetPos(aDrive))
1.158 + {
1.159 + // This method is intended to be used on drives that are known
1.160 + // to be valid, e.g. drive extracted from the path of a discovered
1.161 + // DLL.
1.162 + User::Leave(KEComErrDriveNotFound);
1.163 + }
1.164 + return iter.DriveIsReadOnlyInternal();
1.165 + }
1.166 +
1.167 +/** Test if the EEComDrvAttrRemovable attribute for the given drive is set.
1.168 +@param aDrive the drive number
1.169 +@return ETrue if drive is removable. EFalse means either no such drive or
1.170 + not removable.
1.171 +@leave KEComErrDriveNotFound if aDrive is not supposed to be scanned,
1.172 + i.e. drive absent or disabled by licensees or subst or remote.
1.173 + Use TEComCachedDriveInfoIterator::SetPos instead if want to test drive
1.174 + is removable.
1.175 +*/
1.176 +TBool CEComCachedDriveInfo::DriveIsRemovableL(const TInt aDrive) const
1.177 + {
1.178 + TEComCachedDriveInfoIterator iter(*this);
1.179 +
1.180 + if (! iter.SetPos(aDrive))
1.181 + {
1.182 + // This method is intended to be used on drives that are known
1.183 + // to be valid, e.g. drive extracted from the path of a discovered
1.184 + // DLL.
1.185 + User::Leave(KEComErrDriveNotFound);
1.186 + }
1.187 + return iter.DriveIsRemovable();
1.188 + }
1.189 +
1.190 +/** Test if the EEComDrvAttrWritable attribute for the given drive is set.
1.191 +@param aDrive the drive number
1.192 +@return ETrue if drive is writable. EFalse means either no such drive or
1.193 + drive not writable.
1.194 +@leave KEComErrDriveNotFound if aDrive is not supposed to be scanned,
1.195 + i.e. drive absent or disabled by licensees or subst or remote.
1.196 + Use TEComCachedDriveInfoIterator::SetPos instead if want to test drive
1.197 + is removable.
1.198 +*/
1.199 +TBool CEComCachedDriveInfo::DriveIsWritableL(const TInt aDrive) const
1.200 + {
1.201 + TEComCachedDriveInfoIterator iter(*this);
1.202 +
1.203 + if (! iter.SetPos(aDrive))
1.204 + {
1.205 + // This method is intended to be used on drives that are known
1.206 + // to be valid, e.g. drive extracted from the path of a discovered
1.207 + // DLL.
1.208 + User::Leave(KEComErrDriveNotFound);
1.209 + }
1.210 + return iter.DriveIsWritable();
1.211 + }
1.212 +
1.213 +// Implementation for TEComCachedDriveInfoIterator class
1.214 +
1.215 +/** TEComCachedDriveInfoIterator Constructor
1.216 +Note that the object is not yet in valid state. User must first call
1.217 +First() or Last().
1.218 +*/
1.219 +TEComCachedDriveInfoIterator::TEComCachedDriveInfoIterator(const CEComCachedDriveInfo& aCachedDriveInfo)
1.220 + : iDriveAttr(aCachedDriveInfo.iDriveAttr)
1.221 + {
1.222 + iIndex = KInvalidIndex;
1.223 + }
1.224 +
1.225 +/** Check if the drive is enabled for scanning and move index there if true.
1.226 +@param aDrive the drive number of the drive to check.
1.227 +@return ETrue the drive is enabled for scanning. Index is moved to that location.
1.228 + If drive not to be scanned, index is moved out of bound.
1.229 +*/
1.230 +TBool TEComCachedDriveInfoIterator::SetPos(const TInt aDrive)
1.231 + {
1.232 + for (iIndex = CEComCachedDriveInfo::iLastIndex; iIndex >= 0; iIndex--)
1.233 + {
1.234 + if (iDriveAttr[iIndex].iDrvNumber == aDrive)
1.235 + {
1.236 + if (0 == (iDriveAttr[iIndex].iFlags & EEComDrvAttrNoDiscovery))
1.237 + {
1.238 + return ETrue;
1.239 + }
1.240 + iIndex = KInvalidIndex;
1.241 + break;
1.242 + }
1.243 + }
1.244 + return EFalse;
1.245 + }
1.246 +
1.247 +/** Position iterator at first valid drive so as to
1.248 +iterate the drive list in increasing drive number order. */
1.249 +void TEComCachedDriveInfoIterator::First(void)
1.250 + {
1.251 + for (iIndex = 0; iIndex <= CEComCachedDriveInfo::iLastIndex; iIndex++)
1.252 + {
1.253 + if (0 == (iDriveAttr[iIndex].iFlags & EEComDrvAttrNoDiscovery))
1.254 + {
1.255 + return;
1.256 + }
1.257 + }
1.258 + }
1.259 +
1.260 +/** Position iterator at last valid drive so as to
1.261 +iterate the drive list in decreasing drive number order. */
1.262 +void TEComCachedDriveInfoIterator::Last(void)
1.263 + {
1.264 + for (iIndex = CEComCachedDriveInfo::iLastIndex; iIndex >=0; iIndex--)
1.265 + {
1.266 + if (0 == (iDriveAttr[iIndex].iFlags & EEComDrvAttrNoDiscovery))
1.267 + {
1.268 + return;
1.269 + }
1.270 + }
1.271 + }
1.272 +
1.273 +/** To be used in for and while loops to check if iterator
1.274 +has stepped through all posible drives. */
1.275 +TBool TEComCachedDriveInfoIterator::InRange(void) const
1.276 + {
1.277 + return (iIndex >= 0 && iIndex <= CEComCachedDriveInfo::iLastIndex);
1.278 + }
1.279 +
1.280 +/** Increment iterator to next valid drive. */
1.281 +void TEComCachedDriveInfoIterator::Next(void)
1.282 + {
1.283 + if (InRange())
1.284 + {
1.285 + for (++iIndex; iIndex <= CEComCachedDriveInfo::iLastIndex; iIndex++)
1.286 + {
1.287 + if (0 == (iDriveAttr[iIndex].iFlags & EEComDrvAttrNoDiscovery))
1.288 + {
1.289 + return;
1.290 + }
1.291 + }
1.292 + }
1.293 + }
1.294 +
1.295 +/** Decrement iterator to next valid drive. */
1.296 +void TEComCachedDriveInfoIterator::Prev(void)
1.297 + {
1.298 + if (InRange())
1.299 + {
1.300 + for (--iIndex; iIndex >= 0; iIndex--)
1.301 + {
1.302 + if (0 == (iDriveAttr[iIndex].iFlags & EEComDrvAttrNoDiscovery))
1.303 + {
1.304 + return;
1.305 + }
1.306 + }
1.307 + }
1.308 + }
1.309 +
1.310 +/**
1.311 +@panic USER:133 from TFixedArray if iterator is out of bound.
1.312 +*/
1.313 +TDriveNumber TEComCachedDriveInfoIterator::DriveNumber(void) const
1.314 + {
1.315 + return static_cast<TDriveNumber>( iDriveAttr.At(iIndex).iDrvNumber );
1.316 + }
1.317 +
1.318 +/**
1.319 +@panic USER:133 from TFixedArray if iterator is out of bound.
1.320 +*/
1.321 +TDriveUnit TEComCachedDriveInfoIterator::DriveUnit(void) const
1.322 + {
1.323 + return TDriveUnit( DriveNumber() );
1.324 + }
1.325 +
1.326 +/** Test if the EEComDrvAttrReadOnlyInternal attribute for the current
1.327 +drive is set.
1.328 +@panic USER:133 from TFixedArray if iterator is out of bound.
1.329 +*/
1.330 +TBool TEComCachedDriveInfoIterator::DriveIsReadOnlyInternal(void) const
1.331 + {
1.332 + if (EEComDrvAttrReadOnlyInternal & iDriveAttr.At(iIndex).iFlags)
1.333 + {
1.334 + return ETrue;
1.335 + }
1.336 + return EFalse;
1.337 + }
1.338 +
1.339 +/** Test if the EEComDrvAttrRemovable attribute for the current
1.340 +drive is set.
1.341 +@panic USER:133 from TFixedArray if iterator is out of bound.
1.342 +*/
1.343 +TBool TEComCachedDriveInfoIterator::DriveIsRemovable(void) const
1.344 + {
1.345 + if (EEComDrvAttrRemovable & iDriveAttr.At(iIndex).iFlags)
1.346 + {
1.347 + return ETrue;
1.348 + }
1.349 + return EFalse;
1.350 + }
1.351 +
1.352 +/** Test if the EEComDrvAttrWritable attribute for the current drive is set.
1.353 +@return ETrue if drive is writable. EFalse means drive is not writable.
1.354 +@panic USER:133 from TFixedArray if iterator is out of bound.
1.355 +*/
1.356 +TBool TEComCachedDriveInfoIterator::DriveIsWritable(void) const
1.357 + {
1.358 + if (EEComDrvAttrWritable & iDriveAttr.At(iIndex).iFlags)
1.359 + {
1.360 + return ETrue;
1.361 + }
1.362 + return EFalse;
1.363 + }