kernel/eka/drivers/locmedia/locmedia.cpp
changeset 47 46fffbe7b5a7
parent 44 36bfc973b146
child 62 4a8fed1c0ef6
child 90 947f0dc9f7a8
equal deleted inserted replaced
46:0bf4040442f9 47:46fffbe7b5a7
    18 #include "locmedia.h"
    18 #include "locmedia.h"
    19 #include <d32locd.h>
    19 #include <d32locd.h>
    20 #include "dmasupport.h"
    20 #include "dmasupport.h"
    21 #include <kernel/cache.h>
    21 #include <kernel/cache.h>
    22 
    22 
       
    23 #include "OstTraceDefinitions.h"
       
    24 #ifdef OST_TRACE_COMPILER_IN_USE
       
    25 #include "locmedia_ost.h"
       
    26 #ifdef __VC32__
       
    27 #pragma warning(disable: 4127) // disabling warning "conditional expression is constant"
       
    28 #endif
       
    29 #include "locmediaTraces.h"
       
    30 #endif
       
    31 
       
    32 
    23 #if defined(_DEBUG) && defined(__DEMAND_PAGING__)
    33 #if defined(_DEBUG) && defined(__DEMAND_PAGING__)
    24 //#define __DEBUG_DEMAND_PAGING__
    34 //#define __DEBUG_DEMAND_PAGING__
    25 #endif
    35 #endif
    26 
    36 
    27 
    37 
   138 	};
   148 	};
   139 
   149 
   140 
   150 
   141 DPinObjectAllocator::~DPinObjectAllocator()
   151 DPinObjectAllocator::~DPinObjectAllocator()
   142 	{
   152 	{
       
   153 	OstTraceFunctionEntry1( DPINOBJECTALLOCATOR_DPINOBJECTALLOCATOR_ENTRY, this );
   143 	if (iPreAllocatedDataLock)
   154 	if (iPreAllocatedDataLock)
   144 		{
   155 		{
   145 		iPreAllocatedDataLock->Cleanup();
   156 		iPreAllocatedDataLock->Cleanup();
   146 		delete iPreAllocatedDataLock;
   157 		delete iPreAllocatedDataLock;
   147 		}
   158 		}
   152 		if (virtualPinContainer.iObject)
   163 		if (virtualPinContainer.iObject)
   153 			Kern::DestroyVirtualPinObject(virtualPinContainer.iObject);
   164 			Kern::DestroyVirtualPinObject(virtualPinContainer.iObject);
   154 		}
   165 		}
   155 
   166 
   156 	delete [] iVirtualPinContainers;
   167 	delete [] iVirtualPinContainers;
       
   168 	OstTraceFunctionExit1( DPINOBJECTALLOCATOR_DPINOBJECTALLOCATOR_EXIT, this );
   157 	}
   169 	}
   158 
   170 
   159 TInt DPinObjectAllocator::Construct(TInt aObjectCount, TUint aNumPages)
   171 TInt DPinObjectAllocator::Construct(TInt aObjectCount, TUint aNumPages)
   160 	{
   172 	{
       
   173 	OstTraceFunctionEntryExt( DPINOBJECTALLOCATOR_CONSTRUCT_ENTRY, this );
   161 	TInt pageSize = Kern::RoundToPageSize(1);
   174 	TInt pageSize = Kern::RoundToPageSize(1);
   162 	iFragmentGranularity = pageSize * aNumPages;
   175 	iFragmentGranularity = pageSize * aNumPages;
   163 	__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Fragmentation granularity set to 0x%x", iFragmentGranularity));
   176 	__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Fragmentation granularity set to 0x%x", iFragmentGranularity));
   164 
   177 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPINOBJECTALLOCATOR_CONSTRUCT, "Fragmentation granularity=0x%x", iFragmentGranularity);
       
   178 	
   165 	// construct the paging lock containing pre-allocated buffers
   179 	// construct the paging lock containing pre-allocated buffers
   166 
   180 
   167 	iPreAllocatedDataLock = new DFragmentationPagingLock();
   181 	iPreAllocatedDataLock = new DFragmentationPagingLock();
   168 	if(!iPreAllocatedDataLock)
   182 	if(!iPreAllocatedDataLock)
       
   183 	    {
       
   184 		OstTraceFunctionExitExt( DPINOBJECTALLOCATOR_CONSTRUCT_EXIT1, this, KErrNoMemory );
   169 		return KErrNoMemory;
   185 		return KErrNoMemory;
       
   186 	    }
   170 	TInt r = iPreAllocatedDataLock->Construct(aNumPages);
   187 	TInt r = iPreAllocatedDataLock->Construct(aNumPages);
   171 	if (r != KErrNone)
   188 	if (r != KErrNone)
       
   189 	    {
       
   190 		OstTraceFunctionExitExt( DPINOBJECTALLOCATOR_CONSTRUCT_EXIT2, this, r );
   172 		return r;
   191 		return r;
       
   192 	    }
   173 
   193 
   174 
   194 
   175 	SVirtualPinContainer* iVirtualPinContainers = new SVirtualPinContainer[aObjectCount];
   195 	SVirtualPinContainer* iVirtualPinContainers = new SVirtualPinContainer[aObjectCount];
   176 	if (iVirtualPinContainers == NULL)
   196 	if (iVirtualPinContainers == NULL)
       
   197 	    {
       
   198 		OstTraceFunctionExitExt( DPINOBJECTALLOCATOR_CONSTRUCT_EXIT3, this, KErrNoMemory );
   177 		return KErrNoMemory;
   199 		return KErrNoMemory;
       
   200 	    }
   178 	memclr(iVirtualPinContainers, sizeof(SVirtualPinContainer) * aObjectCount);
   201 	memclr(iVirtualPinContainers, sizeof(SVirtualPinContainer) * aObjectCount);
   179 	iObjectCount = aObjectCount;
   202 	iObjectCount = aObjectCount;
   180 
   203 
   181 	// construct the queue of dynamic paging locks
   204 	// construct the queue of dynamic paging locks
   182 	for (TInt n=0; n<aObjectCount; n++)
   205 	for (TInt n=0; n<aObjectCount; n++)
   183 		{
   206 		{
   184 		SVirtualPinContainer& pinContainer = iVirtualPinContainers[n];
   207 		SVirtualPinContainer& pinContainer = iVirtualPinContainers[n];
   185 
   208 
   186 		TInt r = Kern::CreateVirtualPinObject(pinContainer.iObject);
   209 		TInt r = Kern::CreateVirtualPinObject(pinContainer.iObject);
   187 		if (r != KErrNone)
   210 		if (r != KErrNone)
       
   211 		    {
       
   212 			OstTraceFunctionExitExt( DPINOBJECTALLOCATOR_CONSTRUCT_EXIT4, this, KErrNoMemory );
   188 			return KErrNoMemory;
   213 			return KErrNoMemory;
   189 
   214 		    }
   190 
   215 
   191 		iFreeQ.Add(&pinContainer.iLink);
   216 		iFreeQ.Add(&pinContainer.iLink);
   192 		}
   217 		}
       
   218 	
       
   219 	OstTraceFunctionExitExt( DPINOBJECTALLOCATOR_CONSTRUCT_EXIT5, this, KErrNone );
   193 	return KErrNone;
   220 	return KErrNone;
   194 	}
   221 	}
   195 
   222 
   196 /** 
   223 /** 
   197 returns a SVirtualPinContainer object or NULL if NULL available
   224 returns a SVirtualPinContainer object or NULL if NULL available
   198 */
   225 */
   199 DPinObjectAllocator::SVirtualPinContainer* DPinObjectAllocator::AcquirePinObject()
   226 DPinObjectAllocator::SVirtualPinContainer* DPinObjectAllocator::AcquirePinObject()
   200 	{
   227 	{
       
   228 	OstTraceFunctionEntry1( DPINOBJECTALLOCATOR_ACQUIREPINOBJECT_ENTRY, this );
   201 	SVirtualPinContainer* pinContainer = NULL;
   229 	SVirtualPinContainer* pinContainer = NULL;
   202 	
   230 	
   203 	NKern::FMWait(&iLock);
   231 	NKern::FMWait(&iLock);
   204 
   232 
   205 	if (!iFreeQ.IsEmpty())
   233 	if (!iFreeQ.IsEmpty())
   209 		link->Deque();
   237 		link->Deque();
   210 		}
   238 		}
   211 
   239 
   212 
   240 
   213 	NKern::FMSignal(&iLock);
   241 	NKern::FMSignal(&iLock);
       
   242 	OstTraceFunctionExit1( DPINOBJECTALLOCATOR_ACQUIREPINOBJECT_EXIT, this );
   214 	return pinContainer;
   243 	return pinContainer;
   215 	}
   244 	}
   216 
   245 
   217 /** 
   246 /** 
   218 returns a SVirtualPinContainer object to the pool
   247 returns a SVirtualPinContainer object to the pool
   219 */
   248 */
   220 void DPinObjectAllocator::ReleasePinObject(SVirtualPinContainer* aPinContainer)
   249 void DPinObjectAllocator::ReleasePinObject(SVirtualPinContainer* aPinContainer)
   221 	{
   250 	{
       
   251 	OstTraceFunctionEntry1( DPINOBJECTALLOCATOR_RELEASEPINOBJECT_ENTRY, this );
   222 	NKern::FMWait(&iLock);
   252 	NKern::FMWait(&iLock);
   223 
   253 
   224 	iFreeQ.Add(&aPinContainer->iLink);
   254 	iFreeQ.Add(&aPinContainer->iLink);
   225 
   255 
   226 	NKern::FMSignal(&iLock);
   256 	NKern::FMSignal(&iLock);
       
   257 	OstTraceFunctionExit1( DPINOBJECTALLOCATOR_RELEASEPINOBJECT_EXIT, this );
   227 	}
   258 	}
   228 
   259 
   229 #endif	// __DEMAND_PAGING__
   260 #endif	// __DEMAND_PAGING__
   230 
   261 
   231 
   262 
   240 DLocalDriveFactory::DLocalDriveFactory()
   271 DLocalDriveFactory::DLocalDriveFactory()
   241 //
   272 //
   242 // Constructor
   273 // Constructor
   243 //
   274 //
   244 	{
   275 	{
       
   276 	OstTraceFunctionEntry1( DLOCALDRIVEFACTORY_DLOCALDRIVEFACTORY_ENTRY, this );
   245 	iParseMask=KDeviceAllowUnit|KDeviceAllowInfo;
   277 	iParseMask=KDeviceAllowUnit|KDeviceAllowInfo;
   246 	iUnitsMask=~(0xffffffff<<KMaxLocalDrives);
   278 	iUnitsMask=~(0xffffffff<<KMaxLocalDrives);
   247 	iVersion=TVersion(KLocalDriveMajorVersion,KLocalDriveMinorVersion,KLocalDriveBuildVersion);
   279 	iVersion=TVersion(KLocalDriveMajorVersion,KLocalDriveMinorVersion,KLocalDriveBuildVersion);
       
   280 	OstTraceFunctionExit1( DLOCALDRIVEFACTORY_DLOCALDRIVEFACTORY_EXIT, this );
   248 	}
   281 	}
   249 
   282 
   250 TInt DLocalDriveFactory::Install()
   283 TInt DLocalDriveFactory::Install()
   251 //
   284 //
   252 // Install the device driver.
   285 // Install the device driver.
   269 TInt DLocalDriveFactory::Create(DLogicalChannelBase*& aChannel)
   302 TInt DLocalDriveFactory::Create(DLogicalChannelBase*& aChannel)
   270 //
   303 //
   271 // Create a channel on the device.
   304 // Create a channel on the device.
   272 //
   305 //
   273 	{
   306 	{
       
   307 	OstTraceFunctionEntry1( DLOCALDRIVEFACTORY_CREATE_ENTRY, this );
   274 	aChannel=new DLocalDrive;
   308 	aChannel=new DLocalDrive;
   275 	return aChannel?KErrNone:KErrNoMemory;
   309 	return aChannel?KErrNone:KErrNoMemory;
   276 	}
   310 	}
   277 
   311 
   278 /********************************************
   312 /********************************************
   283 //	iLink.iNext=NULL;
   317 //	iLink.iNext=NULL;
   284 	}
   318 	}
   285 
   319 
   286 DLocalDrive::~DLocalDrive()
   320 DLocalDrive::~DLocalDrive()
   287 	{
   321 	{
       
   322 	OstTraceFunctionEntry1( DLOCALDRIVE_DLOCALDRIVE_ENTRY, this );
   288 	if (iDrive)
   323 	if (iDrive)
   289 		{
   324 		{
   290 		__KTRACE_OPT(KLOCDRV,Kern::Printf(">DLocalDrive::DoClose D:%d, M:%08x",iDrive->iDriveNumber,iDrive->iMedia));
   325 		__KTRACE_OPT(KLOCDRV,Kern::Printf(">DLocalDrive::DoClose D:%d, M:%08x",iDrive->iDriveNumber,iDrive->iMedia));
   291 		iDrive->Disconnect(this);
   326 		iDrive->Disconnect(this);
   292 		__KTRACE_OPT(KLOCDRV,Kern::Printf("<DLocalDrive::DoClose D:%d, M:%08x",iDrive->iDriveNumber,iDrive->iMedia));
   327 		__KTRACE_OPT(KLOCDRV,Kern::Printf("<DLocalDrive::DoClose D:%d, M:%08x",iDrive->iDriveNumber,iDrive->iMedia));
   306 			Kern::QueueRequestComplete(pC,iNotifyChangeRequest,KErrCancel);
   341 			Kern::QueueRequestComplete(pC,iNotifyChangeRequest,KErrCancel);
   307 		pC->Close(NULL);	// balances Open() in DoCreate
   342 		pC->Close(NULL);	// balances Open() in DoCreate
   308 		}
   343 		}
   309 	if (iNotifyChangeRequest)
   344 	if (iNotifyChangeRequest)
   310 		Kern::DestroyClientRequest(iNotifyChangeRequest);
   345 		Kern::DestroyClientRequest(iNotifyChangeRequest);
       
   346 	OstTraceFunctionExit1( DLOCALDRIVE_DLOCALDRIVE_EXIT, this );
   311 	}
   347 	}
   312 
   348 
   313 TInt DLocalDrive::DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer)
   349 TInt DLocalDrive::DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer)
   314 	{
   350 	{
       
   351     OstTraceFunctionEntry1( DLOCALDRIVE_DOCREATE_ENTRY, this );
       
   352     
   315 	if(!Kern::CurrentThreadHasCapability(ECapabilityTCB,__PLATSEC_DIAGNOSTIC_STRING("Checked by ELOCD.LDD (Local Media Driver)")))
   353 	if(!Kern::CurrentThreadHasCapability(ECapabilityTCB,__PLATSEC_DIAGNOSTIC_STRING("Checked by ELOCD.LDD (Local Media Driver)")))
       
   354 	    {
       
   355 		OstTraceFunctionExitExt( DLOCALDRIVE_DOCREATE_EXIT1, this, KErrPermissionDenied );
   316 		return KErrPermissionDenied;
   356 		return KErrPermissionDenied;
       
   357 	    }
   317 	if (!Kern::QueryVersionSupported(TVersion(KLocalDriveMajorVersion,KLocalDriveMinorVersion,KLocalDriveBuildVersion),aVer))
   358 	if (!Kern::QueryVersionSupported(TVersion(KLocalDriveMajorVersion,KLocalDriveMinorVersion,KLocalDriveBuildVersion),aVer))
       
   359 	    {
       
   360 		OstTraceFunctionExitExt( DLOCALDRIVE_DOCREATE_EXIT2, this, KErrNotSupported );
   318 		return KErrNotSupported;
   361 		return KErrNotSupported;
       
   362 	    }
   319 
   363 
   320 	NKern::ThreadEnterCS();
   364 	NKern::ThreadEnterCS();
   321 	TInt r = Kern::CreateClientDataRequest(iNotifyChangeRequest);
   365 	TInt r = Kern::CreateClientDataRequest(iNotifyChangeRequest);
   322 	NKern::ThreadLeaveCS();
   366 	NKern::ThreadLeaveCS();
   323 	if (r != KErrNone)
   367 	if (r != KErrNone)
       
   368 	    {
       
   369 		OstTraceFunctionExitExt( DLOCALDRIVE_DOCREATE_EXIT3, this, r );
   324 		return r;
   370 		return r;
   325 
   371 	    }
       
   372 	
   326 	DThread& t=Kern::CurrentThread();
   373 	DThread& t=Kern::CurrentThread();
   327 	NKern::LockSystem();
   374 	NKern::LockSystem();
   328 	t.AddCleanup(&iCleanup);
   375 	t.AddCleanup(&iCleanup);
   329 	NKern::UnlockSystem();
   376 	NKern::UnlockSystem();
   330 	t.Open();
   377 	t.Open();
   331 	iNotifyChangeRequest->SetDestPtr((TBool*) anInfo);
   378 	iNotifyChangeRequest->SetDestPtr((TBool*) anInfo);
   332 
   379 
   333 	iDrive=TheDrives[aUnit];
   380 	iDrive=TheDrives[aUnit];
   334 	if (!iDrive)
   381 	if (!iDrive)
       
   382 	    {
       
   383 		OstTraceFunctionExitExt( DLOCALDRIVE_DOCREATE_EXIT4, this, KErrNotSupported );
   335 		return KErrNotSupported;
   384 		return KErrNotSupported;
       
   385 	    }
   336 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DLocalDrive Create - connect to drive %d, M:%08x",iDrive->iDriveNumber,iDrive->iMedia));
   386 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DLocalDrive Create - connect to drive %d, M:%08x",iDrive->iDriveNumber,iDrive->iMedia));
   337 	r=iDrive->Connect(this);
   387 	r=iDrive->Connect(this);
   338 	__KTRACE_OPT(KLOCDRV,Kern::Printf("<DLocalDrive Create D:%d, M:%08x r:%d",iDrive->iDriveNumber,iDrive->iMedia,r));
   388 	__KTRACE_OPT(KLOCDRV,Kern::Printf("<DLocalDrive Create D:%d, M:%08x r:%d",iDrive->iDriveNumber,iDrive->iMedia,r));
       
   389 
   339 	if (r!=KErrNone)
   390 	if (r!=KErrNone)
   340 		iDrive=NULL;	// didn't connect so don't disconnect
   391 		iDrive=NULL;	// didn't connect so don't disconnect
       
   392 	
       
   393 	OstTraceFunctionExitExt( DLOCALDRIVE_DOCREATE_EXIT5, this, r );
   341 	return r;
   394 	return r;
   342 	}
   395 	}
   343 
   396 
   344 #if defined(_DEBUG)
   397 #if defined(_DEBUG)
   345 void DebugDumpDriveCaps(const TLocDrv* aDrive, const TAny* aCaps)
   398 void DebugDumpDriveCaps(const TLocDrv* aDrive, const TAny* aCaps)
   383  * iArg[8]	= Pointer to TLocDrv
   436  * iArg[8]	= Pointer to TLocDrv
   384  */
   437  */
   385 
   438 
   386 TInt DLocalDrive::Request(TInt aFunction, TAny* a1, TAny* a2)
   439 TInt DLocalDrive::Request(TInt aFunction, TAny* a1, TAny* a2)
   387 	{
   440 	{
       
   441 	OstTraceFunctionEntry1( DLOCALDRIVE_REQUEST_ENTRY, this );
   388 	__TRACE_TIMING(0);
   442 	__TRACE_TIMING(0);
   389 	__KTRACE_OPT(KLOCDRV,Kern::Printf(">DLocalDrive::DoControl D:%d M:%08x F:%d A1:%08x A2:%08x",
   443 	__KTRACE_OPT(KLOCDRV,Kern::Printf(">DLocalDrive::DoControl D:%d M:%08x F:%d A1:%08x A2:%08x",
   390 														iDrive->iDriveNumber, iDrive->iMedia, aFunction, a1, a2));
   444 														iDrive->iDriveNumber, iDrive->iMedia, aFunction, a1, a2));
       
   445 	OstTraceDefExt3( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST, "iMedia=0x%08x; iDriveNumber=%d; Request Id=%d", (TUint) iDrive->iMedia, (TInt) iDrive->iDriveNumber, (TInt) aFunction );
       
   446 	
   391 	TInt r=KErrNotSupported;
   447 	TInt r=KErrNotSupported;
   392 	TLocDrvRequest& m=TLocDrvRequest::Get();
   448 	TLocDrvRequest& m=TLocDrvRequest::Get();
   393 	m.Flags()=0;
   449 	m.Flags()=0;
   394 	m.Drive()=iDrive;
   450 	m.Drive()=iDrive;
   395 	switch (aFunction)
   451 	switch (aFunction)
   400 			r=m.ProcessMessageData(a1);
   456 			r=m.ProcessMessageData(a1);
   401 			__TRACE_TIMING(1);
   457 			__TRACE_TIMING(1);
   402 			if (r==KErrNone)
   458 			if (r==KErrNone)
   403 				{
   459 				{
   404 				__TRACE_TIMING(2);
   460 				__TRACE_TIMING(2);
       
   461 				OstTraceDefExt4( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_READ, "ERead iDriveNumber=%d; length=0x%x; position=0x%x; TLocDrvRequest Object=0x%x", (TInt) iDrive->iDriveNumber, (TUint) m.Length(), (TUint) m.Pos(), (TUint) &m);
   405 				r=iDrive->Request(m);
   462 				r=iDrive->Request(m);
   406 				__TRACE_TIMING(3);
   463 				__TRACE_TIMING(3);
       
   464 				OstTraceDefExt4( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_READ_RETURN, "ERead Return iDriveNumber=%d; length=0x%x; position=0x%x; TLocDrvRequest Object=0x%x", (TInt) iDrive->iDriveNumber, (TUint) m.Length(), (TUint) m.Pos(), (TUint) &m );
   407 				}
   465 				}
   408 			m.CloseRemoteThread();
   466 			m.CloseRemoteThread();
   409 			break;
   467 			break;
   410 			}
   468 			}
   411 		case RLocalDrive::EControlWrite:
   469 		case RLocalDrive::EControlWrite:
   412 			{
   470 			{
   413 			m.Id()=EWrite;
   471 			m.Id()=EWrite;
   414 			r=m.ProcessMessageData(a1);
   472 			r=m.ProcessMessageData(a1);
   415 			if (r==KErrNone)
   473 			if (r==KErrNone)
       
   474 				{
       
   475 				OstTraceDefExt4( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_WRITE, "EWrite iDriveNumber=%d; length=0x%x; position=0x%x; TLocDrvRequest Object=0x%x", (TInt) iDrive->iDriveNumber, (TUint) m.Length(), (TUint) m.Pos(), (TUint) &m );
   416 				r=iDrive->Request(m);
   476 				r=iDrive->Request(m);
       
   477 				OstTraceDefExt4( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_WRITE_RETURN, "EWrite Return iDriveNumber=%d; length=0x%x; position=0x%x; TLocDrvRequest Object=0x%x", (TInt) iDrive->iDriveNumber, (TUint) m.Length(), (TUint) m.Pos(), (TUint) &m );
       
   478 				}
   417 			m.CloseRemoteThread();
   479 			m.CloseRemoteThread();
   418 			break;
   480 			break;
   419 			}
   481 			}
   420 		case RLocalDrive::EControlCaps:
   482 		case RLocalDrive::EControlCaps:
   421 			{
   483 			{
   462 						caps.iNumberOfSectors = I64LOW(totalSizeInSectors);
   524 						caps.iNumberOfSectors = I64LOW(totalSizeInSectors);
   463 						}
   525 						}
   464 					}
   526 					}
   465 				}
   527 				}
   466 
   528 
       
   529 #if defined(OST_TRACE_COMPILER_IN_USE) && defined(_DEBUG)
       
   530 			const TLocalDriveCapsV5& caps=*(const TLocalDriveCapsV5*)capsBuf.Ptr();
       
   531 #endif
       
   532 			
       
   533 			OstTraceExt5( TRACE_INTERNALS, DLOCALDRIVE_REQUEST_CAPS1, "Device caps: iDriveNumber=%d; iSize=0x%x; iType=%d; iDriveAtt=%d; TLocDrvRequest Object=0x%x", (TInt)iDrive->iDriveNumber, (TUint) caps.iSize, (TInt) caps.iType, (TInt) caps.iDriveAtt, (TUint) &m);
       
   534 			OstTraceExt5( TRACE_INTERNALS, DLOCALDRIVE_REQUEST_CAPS2, "Device caps: iBaseAddress=0x%x; iFileSystemId=%d; iPartitionType=%d; iHiddenSectors=0x%x; iEraseBlockSize=0x%x", (TUint) caps.iBaseAddress, (TInt) caps.iFileSystemId, (TUint) caps.iPartitionType, (TUint) caps.iHiddenSectors, (TUint) caps.iEraseBlockSize);
       
   535 			
   467 #if defined(_DEBUG)
   536 #if defined(_DEBUG)
   468 			__KTRACE_OPT(KLOCDRV,DebugDumpDriveCaps(iDrive,capsBuf.Ptr()));
   537 			__KTRACE_OPT(KLOCDRV,DebugDumpDriveCaps(iDrive,capsBuf.Ptr()));
   469 #endif
   538 #endif
   470 			Kern::InfoCopy(*(TDes8*)a1, capsBuf);
   539 			Kern::InfoCopy(*(TDes8*)a1, capsBuf);
   471 			break;
   540 			break;
   473 		case RLocalDrive::EControlFormat:
   542 		case RLocalDrive::EControlFormat:
   474 			{
   543 			{
   475 			m.Id()=EFormat;
   544 			m.Id()=EFormat;
   476 			r=m.ProcessMessageData(a1);
   545 			r=m.ProcessMessageData(a1);
   477 			if (r==KErrNone)
   546 			if (r==KErrNone)
       
   547 			    {
       
   548 			    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_FORMAT, "EFormat; TLocDrvRequest Object=0x%x", (TUint) &m);
   478 				r=iDrive->Request(m);
   549 				r=iDrive->Request(m);
       
   550 				OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_FORMAT_RETURN, "EFormat Return; TLocDrvRequest Object=0x%x", (TUint) &m);
       
   551 			    }
   479 			break;
   552 			break;
   480 			}
   553 			}
   481 		case RLocalDrive::EControlEnlarge:
   554 		case RLocalDrive::EControlEnlarge:
   482 			if ((TInt)a1<0)
   555 			if ((TInt)a1<0)
   483 				{
   556 				{
   484 				r=KErrArgument;
   557 				r=KErrArgument;
   485 				break;
   558 				break;
   486 				}
   559 				}
   487 			m.Length()=(TInt)a1;
   560 			m.Length()=(TInt)a1;
   488 			m.Id()=EEnlarge;
   561 			m.Id()=EEnlarge;
       
   562 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_ENLARGE, "EEnlarge; TLocDrvRequest Object=0x%x", (TUint) &m);
   489 			r=iDrive->Request(m);
   563 			r=iDrive->Request(m);
       
   564 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_ENLARGE_RETURN, "EEnlarge Return; TLocDrvRequest Object=0x%x", (TUint) &m);
   490 			break;
   565 			break;
   491 		case RLocalDrive::EControlReduce:
   566 		case RLocalDrive::EControlReduce:
   492 			{
   567 			{
   493 			if ((TInt)a1<0 || (TInt)a2<0)
   568 			if ((TInt)a1<0 || (TInt)a2<0)
   494 				{
   569 				{
   496 				break;
   571 				break;
   497 				}
   572 				}
   498 			m.Pos()=(TInt)a1;
   573 			m.Pos()=(TInt)a1;
   499 			m.Length()=(TInt)a2;
   574 			m.Length()=(TInt)a2;
   500 			m.Id()=EReduce;
   575 			m.Id()=EReduce;
       
   576 	        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_REDUCE, "EReduce; TLocDrvRequest Object=0x%x", (TUint) &m);
   501 			r=iDrive->Request(m);
   577 			r=iDrive->Request(m);
       
   578 	        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_REDUCE_RETURN, "EReduce Return; TLocDrvRequest Object=0x%x", (TUint) &m);
   502 			break;
   579 			break;
   503 			}
   580 			}
   504 		case RLocalDrive::EControlForceMediaChange:
   581 		case RLocalDrive::EControlForceMediaChange:
   505 			m.Pos()=(TInt)a1;
   582 			m.Pos()=(TInt)a1;
   506 			m.Id()=EForceMediaChange;
   583 			m.Id()=EForceMediaChange;
       
   584 	        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_FORCEMEDIACHANGE, "EForceMediaChange; TLocDrvRequest Object=0x%x", (TUint) &m);
   507 			r = iDrive->Request(m);
   585 			r = iDrive->Request(m);
       
   586 	        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_FORCEMEDIACHANGE_RETURN, "EForceMediaChange Return; TLocDrvRequest Object=0x%x", (TUint) &m);
   508 			break;
   587 			break;
   509 		case RLocalDrive::EControlMediaDevice:
   588 		case RLocalDrive::EControlMediaDevice:
       
   589 	        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_CONTROLMEDIADEVICE, "EControlMediaDevice; TLocDrvRequest Object=0x%x", (TUint) &m);
   510 			r=iDrive->iPrimaryMedia->iDevice;
   590 			r=iDrive->iPrimaryMedia->iDevice;
   511 			break;
   591 			break;
   512 		case RLocalDrive::EControlIsRemovable:
   592 		case RLocalDrive::EControlIsRemovable:
   513 			{
   593 			{
       
   594 	        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_CONTROLISREMOVABLE, "EControlIsRemovable; TLocDrvRequest Object=0x%x", (TUint) &m);
   514 			TInt sockNum;
   595 			TInt sockNum;
   515 			r=iDrive->iPrimaryMedia->IsRemovableDevice(sockNum);
   596 			r=iDrive->iPrimaryMedia->IsRemovableDevice(sockNum);
   516 			if (r)
   597 			if (r)
   517 				kumemput32(a1,&sockNum,sizeof(TInt));
   598 				kumemput32(a1,&sockNum,sizeof(TInt));
   518 			break;	
   599 			break;	
   542 			//We're highjacking fields representing
   623 			//We're highjacking fields representing
   543 			//length and position in a normal message, so
   624 			//length and position in a normal message, so
   544 			//let's not have the dispatcher function attempt
   625 			//let's not have the dispatcher function attempt
   545 			//to adjust for partition size.
   626 			//to adjust for partition size.
   546 			m.Flags() |= TLocDrvRequest::EAdjusted;
   627 			m.Flags() |= TLocDrvRequest::EAdjusted;
   547 
   628 			
       
   629 	        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_CONTROLCONTROLIO, "EControlControlIO; TLocDrvRequest Object=0x%x", (TUint) &m);
   548 			r=iDrive->Request(m);
   630 			r=iDrive->Request(m);
       
   631 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_CONTROLCONTROLIO_RETURN, "EControlControlIO Return; TLocDrvRequest Object=0x%x", (TUint) &m);
   549 			break;
   632 			break;
   550 			}
   633 			}
   551 		case RLocalDrive::EControlSetMountInfo:
   634 		case RLocalDrive::EControlSetMountInfo:
   552 			{
   635 			{
       
   636 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_CONTROLSETMOUNTINFO, "EControlSetMountInfo; TLocDrvRequest Object=0x%x", (TUint) &m);
   553 			m.Id()=ERead;
   637 			m.Id()=ERead;
   554 			r=m.ProcessMessageData(a1);
   638 			r=m.ProcessMessageData(a1);
   555 			DPrimaryMediaBase* pM=iDrive->iPrimaryMedia;
   639 			DPrimaryMediaBase* pM=iDrive->iPrimaryMedia;
   556 			if(!pM || r!=KErrNone)
   640 			if(!pM || r!=KErrNone)
   557 				break;
   641 				break;
   621 			TMediaPassword newPasswd;
   705 			TMediaPassword newPasswd;
   622 			TLocalDrivePasswordData pswData;
   706 			TLocalDrivePasswordData pswData;
   623 			r = ReadPasswordData(m, pswData, oldPasswd, newPasswd);
   707 			r = ReadPasswordData(m, pswData, oldPasswd, newPasswd);
   624 
   708 
   625 			if (r == KErrNone)
   709 			if (r == KErrNone)
       
   710 				{
       
   711 				OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_PASSWORDLOCK, "EPasswordLock; TLocDrvRequest Object=0x%x", (TUint) &m);
   626 				r = iDrive->Request(m);
   712 				r = iDrive->Request(m);
       
   713 				OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_PASSWORDLOCK_RETURN, "EPasswordLock Return; TLocDrvRequest Object=0x%x", (TUint) &m);
       
   714 				}
   627 			break;
   715 			break;
   628 			}
   716 			}
   629 		case RLocalDrive::EControlPasswordUnlock:
   717 		case RLocalDrive::EControlPasswordUnlock:
   630 			{
   718 			{
   631 			m.Id()=EPasswordUnlock;
   719 			m.Id()=EPasswordUnlock;
   635 			TMediaPassword newPasswd;
   723 			TMediaPassword newPasswd;
   636 			TLocalDrivePasswordData pswData;
   724 			TLocalDrivePasswordData pswData;
   637 			r = ReadPasswordData(m, pswData, oldPasswd, newPasswd);
   725 			r = ReadPasswordData(m, pswData, oldPasswd, newPasswd);
   638 
   726 
   639 			if(r == KErrNone)
   727 			if(r == KErrNone)
       
   728 				{
       
   729 				OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_PASSWORDUNLOCK, "EPasswordUnLock; TLocDrvRequest Object=0x%x", (TUint) &m);
   640 				r=iDrive->Request(m);
   730 				r=iDrive->Request(m);
       
   731 				OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_PASSWORDUNLOCK_RETURN, "EPasswordUnLock Return; TLocDrvRequest Object=0x%x", (TUint) &m);
       
   732 				}
   641 			if (r == KErrNone)
   733 			if (r == KErrNone)
   642 				iDrive->iPrimaryMedia->iTotalPartitionsOpened = 0;
   734 				iDrive->iPrimaryMedia->iTotalPartitionsOpened = 0;
   643 			break;
   735 			break;
   644 			}
   736 			}
   645 		case RLocalDrive::EControlPasswordClear:
   737 		case RLocalDrive::EControlPasswordClear:
   651 			TMediaPassword newPasswd;
   743 			TMediaPassword newPasswd;
   652 			TLocalDrivePasswordData pswData;
   744 			TLocalDrivePasswordData pswData;
   653 			r = ReadPasswordData(m, pswData, oldPasswd, newPasswd);
   745 			r = ReadPasswordData(m, pswData, oldPasswd, newPasswd);
   654 
   746 
   655 			if (r == KErrNone)
   747 			if (r == KErrNone)
       
   748 				{
       
   749 				OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_PASSWORDCLEAR, "EPasswordClear; TLocDrvRequest Object=0x%x", (TUint) &m);
   656 				r = iDrive->Request(m);
   750 				r = iDrive->Request(m);
       
   751 				OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_PASSWORDCLEAR_RETURN, "EPasswordClear Return; TLocDrvRequest Object=0x%x", (TUint) &m);
       
   752 				}
   657 			break;
   753 			break;
   658 			}
   754 			}
   659 		case RLocalDrive::EControlPasswordErase:
   755 		case RLocalDrive::EControlPasswordErase:
   660 			{
   756 			{
   661 			m.Id()=EPasswordErase;
   757 			m.Id()=EPasswordErase;
       
   758 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_PASSWORDERASE, "EPasswordErase; TLocDrvRequest Object=0x%x", (TUint) &m);
   662 			r=iDrive->Request(m);
   759 			r=iDrive->Request(m);
       
   760 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_PASSWORDERASE_RETURN, "EPasswordErase Return; TLocDrvRequest Object=0x%x", (TUint) &m);
   663 			if(r == KErrNone)
   761 			if(r == KErrNone)
   664 				iDrive->iPrimaryMedia->iTotalPartitionsOpened = 0;
   762 				iDrive->iPrimaryMedia->iTotalPartitionsOpened = 0;
   665 			break;
   763 			break;
   666 			}
   764 			}
   667 		case RLocalDrive::EControlNotifyChange:
   765 		case RLocalDrive::EControlNotifyChange:
   668 			if (iCleanup.iThread != &Kern::CurrentThread())
   766 			if (iCleanup.iThread != &Kern::CurrentThread())
   669 				Kern::PanicCurrentThread(KLitLocMedia,KErrAccessDenied);
   767 				Kern::PanicCurrentThread(KLitLocMedia,KErrAccessDenied);
   670 			r=KErrNone;
   768 			r=KErrNone;
   671 			if (!iNotifyChangeRequest->StatusPtr())
   769 			if (!iNotifyChangeRequest->StatusPtr())
   672 				r = iNotifyChangeRequest->SetStatus((TRequestStatus*) a1);
   770 				r = iNotifyChangeRequest->SetStatus((TRequestStatus*) a1);
       
   771 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_CONTROLNOTIFYCHANGE, "EControlNotifyChange; TLocDrvRequest Object=0x%x", (TUint) &m);
   673 			break;
   772 			break;
   674 		case RLocalDrive::EControlNotifyChangeCancel:
   773 		case RLocalDrive::EControlNotifyChangeCancel:
   675 			if (iCleanup.iThread != &Kern::CurrentThread())
   774 			if (iCleanup.iThread != &Kern::CurrentThread())
   676 				Kern::PanicCurrentThread(KLitLocMedia,KErrAccessDenied);
   775 				Kern::PanicCurrentThread(KLitLocMedia,KErrAccessDenied);
   677 			Kern::QueueRequestComplete(iCleanup.iThread,iNotifyChangeRequest,KErrCancel);
   776 			Kern::QueueRequestComplete(iCleanup.iThread,iNotifyChangeRequest,KErrCancel);
       
   777 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_CONTROLNOTIFYCHANGECANCEL, "EControlNotifyChangeCancel; TLocDrvRequest Object=0x%x", (TUint) &m);
   678 			break;
   778 			break;
   679 		case RLocalDrive::EControlReadPasswordStore:
   779 		case RLocalDrive::EControlReadPasswordStore:
   680 			{
   780 			{
   681 			TUint8  passData[TPasswordStore::EMaxPasswordLength];
   781 			TUint8  passData[TPasswordStore::EMaxPasswordLength];
   682 			m.RemoteDes() = (TAny*) passData;
   782 			m.RemoteDes() = (TAny*) passData;
   683 			m.Length() = sizeof(passData);
   783 			m.Length() = sizeof(passData);
   684 			m.Id()=EReadPasswordStore;
   784 			m.Id()=EReadPasswordStore;
       
   785 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_READPASSWORDSTORE, "EReadPasswordStore; TLocDrvRequest Object=0x%x", (TUint) &m);
   685 			r=iDrive->Request(m);
   786 			r=iDrive->Request(m);
       
   787 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_READPASSWORDSTORE_RETURN, "EReadPasswordStore Return; TLocDrvRequest Object=0x%x", (TUint) &m);
   686 			if (r==KErrNone)
   788 			if (r==KErrNone)
   687 				{
   789 				{
   688 				TPtr8 pData(passData, (TInt) m.Length(), TPasswordStore::EMaxPasswordLength);
   790 				TPtr8 pData(passData, (TInt) m.Length(), TPasswordStore::EMaxPasswordLength);
   689 				m.RemoteDes()=(TDes8*)a1;
   791 				m.RemoteDes()=(TDes8*)a1;
   690 				r = m.WriteRemote(&pData,0);
   792 				r = m.WriteRemote(&pData,0);
   713 
   815 
   714 
   816 
   715 			m.RemoteDes() = (TAny*) pData.Ptr();
   817 			m.RemoteDes() = (TAny*) pData.Ptr();
   716 			m.Length() = pData.Length();
   818 			m.Length() = pData.Length();
   717 			m.Id()=EWritePasswordStore;
   819 			m.Id()=EWritePasswordStore;
       
   820 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_WRITEPASSWORDSTORE, "EWritePasswordStore; TLocDrvRequest Object=0x%x", (TUint) &m);
   718 			r=iDrive->Request(m);
   821 			r=iDrive->Request(m);
       
   822 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_WRITEPASSWORDSTORE_RETURN, "EReadPasswordStore Return; TLocDrvRequest Object=0x%x", (TUint) &m);
   719 			if(r == KErrNone)
   823 			if(r == KErrNone)
   720 				iDrive->iPrimaryMedia->iTotalPartitionsOpened = 0;
   824 				iDrive->iPrimaryMedia->iTotalPartitionsOpened = 0;
   721 			break;
   825 			break;
   722 			}
   826 			}
   723 		case RLocalDrive::EControlPasswordStoreLengthInBytes:
   827 		case RLocalDrive::EControlPasswordStoreLengthInBytes:
   724 			{
   828 			{
   725 			m.Id()=EPasswordStoreLengthInBytes;
   829 			m.Id()=EPasswordStoreLengthInBytes;
   726 			TInt length;
   830 			TInt length;
   727 			m.RemoteDes() = (TAny*) &length;
   831 			m.RemoteDes() = (TAny*) &length;
       
   832 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_PASSWORDSTORELENGTH, "EPasswordStoreLengthInBytes; TLocDrvRequest Object=0x%x", (TUint) &m);
   728 			r=iDrive->Request(m);
   833 			r=iDrive->Request(m);
       
   834 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_PASSWORDSTORELENGTH_RETURN, "EPasswordStoreLengthInBytes Return; TLocDrvRequest Object=0x%x", (TUint) &m);
   729 
   835 
   730 			if (r == KErrNone)
   836 			if (r == KErrNone)
   731 				{
   837 				{
   732 				m.RemoteDes()=a1;
   838 				m.RemoteDes()=a1;
   733 				r = m.WriteRemoteRaw(&length,sizeof(TInt));
   839 				r = m.WriteRemoteRaw(&length,sizeof(TInt));
   742 			TErrorInfoBuf errorInfoBuf;
   848 			TErrorInfoBuf errorInfoBuf;
   743 			errorInfoBuf.SetMax();
   849 			errorInfoBuf.SetMax();
   744 			errorInfoBuf.FillZ();
   850 			errorInfoBuf.FillZ();
   745 			m.RemoteDes()=(TAny*) errorInfoBuf.Ptr();	// overload this
   851 			m.RemoteDes()=(TAny*) errorInfoBuf.Ptr();	// overload this
   746 			m.Length() = errorInfoBuf.MaxLength();
   852 			m.Length() = errorInfoBuf.MaxLength();
       
   853 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_GETLASTERRORINFO, "EGetLastErrorInfo; TLocDrvRequest Object=0x%x", (TUint) &m);
   747 			r=iDrive->Request(m);
   854 			r=iDrive->Request(m);
       
   855 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_CONTROLGETLASTERRORINFO_RETURN, "EControlGetLastErrorInfo Return; TLocDrvRequest Object=0x%x", (TUint) &m);
   748 			Kern::InfoCopy(*(TDes8*)a1, errorInfoBuf);
   856 			Kern::InfoCopy(*(TDes8*)a1, errorInfoBuf);
   749 			break;
   857 			break;
   750 			}
   858 			}
   751 		case RLocalDrive::EControlDeleteNotify:
   859 		case RLocalDrive::EControlDeleteNotify:
   752 			{
   860 			{
   753 			m.Id()=EDeleteNotify;
   861 			m.Id()=EDeleteNotify;
   754 			r=m.ProcessMessageData(a1);
   862 			r=m.ProcessMessageData(a1);
   755 			if (r==KErrNone)
   863 			if (r==KErrNone)
       
   864 			    {
       
   865 			    OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_DELETENOTIFY, "EDeleteNotify; TLocDrvRequest Object=0x%x", (TUint) &m);
   756 				r=iDrive->Request(m);
   866 				r=iDrive->Request(m);
       
   867 				OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_DELETENOTIFY_RETURN, "EDeleteNotify Return; TLocDrvRequest Object=0x%x", (TUint) &m);
       
   868 			    }
   757 			break;
   869 			break;
   758 			}
   870 			}
   759 
   871 
   760 		case RLocalDrive::EControlQueryDevice:
   872 		case RLocalDrive::EControlQueryDevice:
   761 			{
   873 			{
   762 			TBuf8<KMaxQueryDeviceLength> queryBuf;
   874 			TBuf8<KMaxQueryDeviceLength> queryBuf;
   763 			queryBuf.SetMax();
   875 			queryBuf.SetMax();
   764 			queryBuf.FillZ();
   876 			queryBuf.FillZ();
   765 
   877 			
   766 			m.Id() = EQueryDevice;
   878 			m.Id() = EQueryDevice;
   767 			m.iArg[0] = a1;		// RLocalDrive::TQueryDevice
   879 			m.iArg[0] = a1;		// RLocalDrive::TQueryDevice
   768 			m.RemoteDes() = (TAny*)queryBuf.Ptr();	// overload this
   880 			m.RemoteDes() = (TAny*)queryBuf.Ptr();	// overload this
   769 			m.Length() = KMaxLocalDriveCapsLength;	// for pinning
   881 			m.Length() = KMaxLocalDriveCapsLength;	// for pinning
       
   882 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_QUERYDEVICE, "EQueryDevice; TLocDrvRequest Object=0x%x", (TUint) &m);
   770 			r=iDrive->Request(m);
   883 			r=iDrive->Request(m);
   771 
   884 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DLOCALDRIVE_REQUEST_QUERYDEVICE_RETURN, "EQueryDevice Return; TLocDrvRequest Object=0x%x", (TUint) &m);
   772 			Kern::InfoCopy(*(TDes8*)a2, queryBuf);
   885 			Kern::InfoCopy(*(TDes8*)a2, queryBuf);
   773 			break;
   886 			break;
   774 			}
   887 			}
   775 
   888 
   776 		}
   889 		}
   777 	__KTRACE_OPT(KLOCDRV,Kern::Printf("<DLocalDrive::DoControl D:%d M:%08x ret %d",iDrive->iDriveNumber, iDrive->iMedia, r));
   890 	__KTRACE_OPT(KLOCDRV,Kern::Printf("<DLocalDrive::DoControl D:%d M:%08x ret %d",iDrive->iDriveNumber, iDrive->iMedia, r));
   778 	__TRACE_TIMING(4);
   891 	__TRACE_TIMING(4);
       
   892 	OstTraceFunctionExitExt( DLOCALDRIVE_REQUEST_EXIT, this, r );
   779 	return r;
   893 	return r;
   780 	}
   894 	}
   781 
   895 
   782 TInt DLocalDrive::ReadPasswordData(TLocDrvRequest& aReq, TLocalDrivePasswordData& aPswData, TMediaPassword& aOldPasswd, TMediaPassword& aNewPasswd)
   896 TInt DLocalDrive::ReadPasswordData(TLocDrvRequest& aReq, TLocalDrivePasswordData& aPswData, TMediaPassword& aOldPasswd, TMediaPassword& aNewPasswd)
   783 	{
   897 	{
   806 
   920 
   807 
   921 
   808 #ifdef __DEMAND_PAGING__
   922 #ifdef __DEMAND_PAGING__
   809 TInt DLocalDrive::LockMountInfo(DPrimaryMediaBase& aPrimaryMedia, TLocDrvRequest& aReq)
   923 TInt DLocalDrive::LockMountInfo(DPrimaryMediaBase& aPrimaryMedia, TLocDrvRequest& aReq)
   810 	{
   924 	{
       
   925 	OstTraceExt2(TRACE_FLOW, DLOCALDRIVE_LOCKMOUNTINFO_ENTRY, "> aPrimaryMedia=%x;aReq=%x", (TUint) &aPrimaryMedia, (TUint) &aReq );
   811 	DMediaPagingDevice* pagingDevice = aPrimaryMedia.iBody->iPagingDevice;
   926 	DMediaPagingDevice* pagingDevice = aPrimaryMedia.iBody->iPagingDevice;
   812 	if (pagingDevice == NULL)
   927 	if (pagingDevice == NULL)
       
   928 	    {
       
   929 		OstTraceFunctionExitExt( DLOCALDRIVE_LOCKMOUNTINFO_EXIT1, this, KErrNone );
   813 		return KErrNone;
   930 		return KErrNone;
       
   931 	    }
   814 
   932 
   815 	__ASSERT_DEBUG(pagingDevice->iMountInfoDataLock == NULL, LOCM_FAULT());
   933 	__ASSERT_DEBUG(pagingDevice->iMountInfoDataLock == NULL, LOCM_FAULT());
   816 	__ASSERT_DEBUG(pagingDevice->iMountInfoDescHdrLock == NULL, LOCM_FAULT());
   934 	__ASSERT_DEBUG(pagingDevice->iMountInfoDescHdrLock == NULL, LOCM_FAULT());
   817 	__ASSERT_DEBUG(pagingDevice->iMountInfoDescLenLock == NULL, LOCM_FAULT());
   935 	__ASSERT_DEBUG(pagingDevice->iMountInfoDescLenLock == NULL, LOCM_FAULT());
   818 
   936 
   823 	TInt length = 0;
   941 	TInt length = 0;
   824 	TInt maxLength = 0;
   942 	TInt maxLength = 0;
   825 	TUint8* desAddress = NULL;
   943 	TUint8* desAddress = NULL;
   826 	TInt r = Kern::ThreadGetDesInfo(pT,aReq.RemoteDes(),length,maxLength,desAddress,EFalse);	// get descriptor length, maxlength and desAddress
   944 	TInt r = Kern::ThreadGetDesInfo(pT,aReq.RemoteDes(),length,maxLength,desAddress,EFalse);	// get descriptor length, maxlength and desAddress
   827 	if (r != KErrNone)
   945 	if (r != KErrNone)
       
   946 	    {
       
   947 		OstTraceFunctionExitExt( DLOCALDRIVE_LOCKMOUNTINFO_EXIT2, this, r );
   828 		return r;
   948 		return r;
       
   949 	    }
   829 	if (length == 0)
   950 	if (length == 0)
       
   951 	    {
       
   952 		OstTraceFunctionExitExt( DLOCALDRIVE_LOCKMOUNTINFO_EXIT3, this, KErrNone );
   830 		return KErrNone;
   953 		return KErrNone;
       
   954 	    }
   831 
   955 
   832 
   956 
   833 	static const TUint8 LengthLookup[16]={4,8,12,8,12,0,0,0,0,0,0,0,0,0,0,0};
   957 	static const TUint8 LengthLookup[16]={4,8,12,8,12,0,0,0,0,0,0,0,0,0,0,0};
   834 	TUint32 desHdr;
   958 	TUint32 desHdr;
   835 	r = Kern::ThreadRawRead(pT, aReq.RemoteDes(), &desHdr, sizeof(desHdr));
   959 	r = Kern::ThreadRawRead(pT, aReq.RemoteDes(), &desHdr, sizeof(desHdr));
   836 	if(r!=KErrNone)
   960 	if(r!=KErrNone)
       
   961 	    {
       
   962 		OstTraceFunctionExitExt( DLOCALDRIVE_LOCKMOUNTINFO_EXIT4, this, r );
   837 		return r;
   963 		return r;
       
   964 	    }
   838 	TInt desType = desHdr >>KShiftDesType8;
   965 	TInt desType = desHdr >>KShiftDesType8;
   839 	TInt desHdrLen = LengthLookup[desType];
   966 	TInt desHdrLen = LengthLookup[desType];
   840 	if(!desHdrLen)
   967 	if(!desHdrLen)
       
   968 	    {
       
   969 		OstTraceFunctionExitExt( DLOCALDRIVE_LOCKMOUNTINFO_EXIT5, this, KErrBadDescriptor );
   841 		return KErrBadDescriptor;
   970 		return KErrBadDescriptor;
       
   971 	    }
   842 
   972 
   843 
   973 
   844 	pagingDevice->iMountInfoDataLock = ThePinObjectAllocator->AcquirePinObject();
   974 	pagingDevice->iMountInfoDataLock = ThePinObjectAllocator->AcquirePinObject();
   845 	pagingDevice->iMountInfoDescHdrLock = ThePinObjectAllocator->AcquirePinObject();
   975 	pagingDevice->iMountInfoDescHdrLock = ThePinObjectAllocator->AcquirePinObject();
   846 	pagingDevice->iMountInfoDescLenLock = ThePinObjectAllocator->AcquirePinObject();
   976 	pagingDevice->iMountInfoDescLenLock = ThePinObjectAllocator->AcquirePinObject();
   848 	if (pagingDevice->iMountInfoDataLock == NULL || 
   978 	if (pagingDevice->iMountInfoDataLock == NULL || 
   849 		pagingDevice->iMountInfoDescHdrLock == NULL || 
   979 		pagingDevice->iMountInfoDescHdrLock == NULL || 
   850 		pagingDevice->iMountInfoDescLenLock == NULL)
   980 		pagingDevice->iMountInfoDescLenLock == NULL)
   851 		{
   981 		{
   852 		UnlockMountInfo(aPrimaryMedia);	// tidy up
   982 		UnlockMountInfo(aPrimaryMedia);	// tidy up
       
   983 		OstTraceFunctionExitExt( DLOCALDRIVE_LOCKMOUNTINFO_EXIT6, this, KErrNoMemory );
   853 		return KErrNoMemory;
   984 		return KErrNoMemory;
   854 		}
   985 		}
   855 
   986 
   856 
   987 
   857 	// First pin the descriptor header 
   988 	// First pin the descriptor header 
   859 	lock = (DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDescHdrLock;
   990 	lock = (DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDescHdrLock;
   860 	r = Kern::PinVirtualMemory(lock->iObject, (TLinAddr) (TUint8*) aReq.RemoteDes(), desHdrLen, pT);
   991 	r = Kern::PinVirtualMemory(lock->iObject, (TLinAddr) (TUint8*) aReq.RemoteDes(), desHdrLen, pT);
   861 	if (r != KErrNone)
   992 	if (r != KErrNone)
   862 		{
   993 		{
   863 		UnlockMountInfo(aPrimaryMedia);	// tidy up
   994 		UnlockMountInfo(aPrimaryMedia);	// tidy up
       
   995 		OstTraceFunctionExitExt( DLOCALDRIVE_LOCKMOUNTINFO_EXIT7, this, KErrNoMemory );
   864 		return KErrNoMemory;
   996 		return KErrNoMemory;
   865 		}
   997 		}
   866 
   998 
   867 	
   999 	
   868 	
  1000 	
   873 		TLinAddr extraLenAddr = TLinAddr(desAddress) - aReq.RemoteDesOffset() - sizeof(TUint32);
  1005 		TLinAddr extraLenAddr = TLinAddr(desAddress) - aReq.RemoteDesOffset() - sizeof(TUint32);
   874 		r = Kern::PinVirtualMemory(lock->iObject, (TLinAddr) (TUint8*) extraLenAddr, sizeof(TUint32), pT);
  1006 		r = Kern::PinVirtualMemory(lock->iObject, (TLinAddr) (TUint8*) extraLenAddr, sizeof(TUint32), pT);
   875 		if (r != KErrNone)
  1007 		if (r != KErrNone)
   876 			{
  1008 			{
   877 			UnlockMountInfo(aPrimaryMedia);	// tidy up
  1009 			UnlockMountInfo(aPrimaryMedia);	// tidy up
       
  1010 			OstTraceFunctionExitExt( DLOCALDRIVE_LOCKMOUNTINFO_EXIT8, this, KErrNoMemory );
   878 			return KErrNoMemory;
  1011 			return KErrNoMemory;
   879 			}
  1012 			}
   880 		}
  1013 		}
   881 
  1014 
   882 
  1015 
   884 	lock = (DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDataLock;
  1017 	lock = (DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDataLock;
   885 	r = Kern::PinVirtualMemory(lock->iObject, (TLinAddr) desAddress, length, pT);
  1018 	r = Kern::PinVirtualMemory(lock->iObject, (TLinAddr) desAddress, length, pT);
   886 	if (r != KErrNone)
  1019 	if (r != KErrNone)
   887 		{
  1020 		{
   888 		UnlockMountInfo(aPrimaryMedia);	// tidy up
  1021 		UnlockMountInfo(aPrimaryMedia);	// tidy up
       
  1022 		OstTraceFunctionExitExt( DLOCALDRIVE_LOCKMOUNTINFO_EXIT9, this, KErrNoMemory );
   889 		return KErrNoMemory;
  1023 		return KErrNoMemory;
   890 		}
  1024 		}
   891 
  1025 
   892 
  1026 	OstTraceFunctionExitExt( DLOCALDRIVE_LOCKMOUNTINFO_EXIT10, this, KErrNone );
   893 	return KErrNone;
  1027 	return KErrNone;
   894 	}
  1028 	}
   895 
  1029 
   896 
  1030 
   897 void DLocalDrive::UnlockMountInfo(DPrimaryMediaBase& aPrimaryMedia)
  1031 void DLocalDrive::UnlockMountInfo(DPrimaryMediaBase& aPrimaryMedia)
   898 	{
  1032 	{
       
  1033 	OstTrace1(TRACE_FLOW, DLOCALDRIVE_UNLOCKMOUNTINFO_ENTRY, "> DLocalDrive::UnlockMountInfo;aPrimaryMedia=%x", (TUint) &aPrimaryMedia);
       
  1034 	
   899 	DMediaPagingDevice* pagingDevice = aPrimaryMedia.iBody->iPagingDevice; 
  1035 	DMediaPagingDevice* pagingDevice = aPrimaryMedia.iBody->iPagingDevice; 
   900 	if (pagingDevice == NULL || pagingDevice->iMountInfoDataLock == NULL)
  1036 	if (pagingDevice == NULL || pagingDevice->iMountInfoDataLock == NULL)
       
  1037 	    {
       
  1038 		OstTraceFunctionExit1( DLOCALDRIVE_UNLOCKMOUNTINFO_EXIT1, this );
   901 		return;
  1039 		return;
       
  1040 	    }
   902 
  1041 
   903 
  1042 
   904 	if (pagingDevice->iMountInfoDataLock)
  1043 	if (pagingDevice->iMountInfoDataLock)
   905 		{
  1044 		{
   906 		Kern::UnpinVirtualMemory(((DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDataLock)->iObject);
  1045 		Kern::UnpinVirtualMemory(((DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDataLock)->iObject);
   920 		Kern::UnpinVirtualMemory(((DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDescLenLock)->iObject);
  1059 		Kern::UnpinVirtualMemory(((DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDescLenLock)->iObject);
   921 		ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDescLenLock);
  1060 		ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) pagingDevice->iMountInfoDescLenLock);
   922 		pagingDevice->iMountInfoDescLenLock = NULL;
  1061 		pagingDevice->iMountInfoDescLenLock = NULL;
   923 		}
  1062 		}
   924 	
  1063 	
       
  1064 	OstTraceFunctionExit1( DLOCALDRIVE_UNLOCKMOUNTINFO_EXIT2, this );
   925 	}
  1065 	}
   926 #endif	// __DEMAND_PAGING__
  1066 #endif	// __DEMAND_PAGING__
   927 
  1067 
   928 void DLocalDrive::NotifyChange(DPrimaryMediaBase& aPrimaryMedia, TBool aMediaChange)
  1068 void DLocalDrive::NotifyChange(DPrimaryMediaBase& aPrimaryMedia, TBool aMediaChange)
   929 	{
  1069 	{
       
  1070     OstTraceExt2( TRACE_FLOW, DLOCALDRIVE_NOTIFYCHANGE_ENTRY, "> DLocalDrive::NotifyChange;aPrimaryMedia=%x;aMediaChange=%d", (TUint) &aPrimaryMedia, aMediaChange );
   930 #ifndef __DEMAND_PAGING__
  1071 #ifndef __DEMAND_PAGING__
   931 	aPrimaryMedia;
  1072 	aPrimaryMedia;
   932 #endif
  1073 #endif
   933 
  1074 
   934 	// Complete any notification request on media change or power down
  1075 	// Complete any notification request on media change or power down
   963 				Kern::ThreadRawWrite(pC, iNotifyChangeRequest->DestPtr(), &b, sizeof(b), NULL);
  1104 				Kern::ThreadRawWrite(pC, iNotifyChangeRequest->DestPtr(), &b, sizeof(b), NULL);
   964 				}
  1105 				}
   965 			pC->AsyncClose();
  1106 			pC->AsyncClose();
   966 			}
  1107 			}
   967 		}
  1108 		}
       
  1109 	OstTraceFunctionExit1( DLOCALDRIVE_NOTIFYCHANGE_EXIT, this );
   968 	}
  1110 	}
   969 
  1111 
   970 TLocalDriveCleanup::TLocalDriveCleanup()
  1112 TLocalDriveCleanup::TLocalDriveCleanup()
   971 	{
  1113 	{
   972 	}
  1114 	}
  1009 
  1151 
  1010 @see Kern::ThreadDesRead()
  1152 @see Kern::ThreadDesRead()
  1011 */
  1153 */
  1012 EXPORT_C TInt TLocDrvRequest::ReadRemote(TDes8* aDes, TInt anOffset)
  1154 EXPORT_C TInt TLocDrvRequest::ReadRemote(TDes8* aDes, TInt anOffset)
  1013 	{
  1155 	{
       
  1156 	OstTraceFunctionEntry1( TLOCDRVREQUEST_READREMOTE_ENTRY, this );
       
  1157 	TInt r;
  1014 	DThread* pT=RemoteThread();
  1158 	DThread* pT=RemoteThread();
  1015 	if (!pT)
  1159 	if (!pT)
  1016 		pT=Client();
  1160 		pT=Client();
  1017 
  1161 
  1018 #ifdef __DEMAND_PAGING__	// only if driver has its own thread, we don't support paging in MD which run in the context of their clients
  1162 #ifdef __DEMAND_PAGING__	// only if driver has its own thread, we don't support paging in MD which run in the context of their clients
  1019 	if (Flags() & ETClientBuffer)
  1163 	if (Flags() & ETClientBuffer)
  1020 		return Kern::ThreadBufRead(pT, (TClientBuffer*) RemoteDes(),*aDes,anOffset+RemoteDesOffset(),KChunkShiftBy0);
  1164 	    {
  1021 
  1165         r = Kern::ThreadBufRead(pT, (TClientBuffer*) RemoteDes(),*aDes,anOffset+RemoteDesOffset(),KChunkShiftBy0);
       
  1166 		OstTraceFunctionExitExt( TLOCDRVREQUEST_READREMOTE_EXIT1, this, r );
       
  1167 		return r; 
       
  1168 	    }
       
  1169 	
  1022 	__ASSERT_ALWAYS((Flags() & ETClientBuffer) == 0, LOCM_FAULT());
  1170 	__ASSERT_ALWAYS((Flags() & ETClientBuffer) == 0, LOCM_FAULT());
  1023 #endif
  1171 #endif
  1024 
  1172 	r = Kern::ThreadDesRead(pT,RemoteDes(),*aDes,anOffset+RemoteDesOffset(),KChunkShiftBy0);
  1025 	return Kern::ThreadDesRead(pT,RemoteDes(),*aDes,anOffset+RemoteDesOffset(),KChunkShiftBy0);
  1173 	OstTraceFunctionExitExt( TLOCDRVREQUEST_READREMOTE_EXIT2, this, r );
       
  1174 	return r;
  1026 	}
  1175 	}
  1027 
  1176 
  1028 
  1177 
  1029 
  1178 
  1030 
  1179 
  1050 
  1199 
  1051 @see Kern::ThreadDesRead()
  1200 @see Kern::ThreadDesRead()
  1052 */
  1201 */
  1053 EXPORT_C TInt TLocDrvRequest::ReadRemote(const TAny* aSrc, TDes8* aDes)
  1202 EXPORT_C TInt TLocDrvRequest::ReadRemote(const TAny* aSrc, TDes8* aDes)
  1054 	{
  1203 	{
       
  1204 	OstTraceFunctionEntry1( TLOCDRVREQUEST_READ_REMOTE_ENTRY, this );
  1055 	if (Flags() & TLocDrvRequest::EKernelBuffer)
  1205 	if (Flags() & TLocDrvRequest::EKernelBuffer)
  1056 		{
  1206 		{
  1057 		aDes->Copy(* (TDesC8*) aSrc);
  1207 		aDes->Copy(* (TDesC8*) aSrc);
  1058 		return KErrNone;
  1208 		return KErrNone;
  1059 		}
  1209 		}
  1060 
  1210 
       
  1211 	TInt r;
  1061 	DThread* pT=RemoteThread();
  1212 	DThread* pT=RemoteThread();
  1062 	if (!pT)
  1213 	if (!pT)
  1063 		pT=Client();
  1214 		pT=Client();
  1064 
  1215 
  1065 #ifdef __DEMAND_PAGING__
  1216 #ifdef __DEMAND_PAGING__
  1066 	__ASSERT_DEBUG(!DataPagingDfcQ(Drive()->iPrimaryMedia), LOCM_FAULT());
  1217 	__ASSERT_DEBUG(!DataPagingDfcQ(Drive()->iPrimaryMedia), LOCM_FAULT());
  1067 
  1218 
  1068 	if (DataPagingDfcQ(Drive()->iPrimaryMedia))
  1219 	if (DataPagingDfcQ(Drive()->iPrimaryMedia))
       
  1220 		{
       
  1221 		OstTraceFunctionExitExt( TLOCDRVREQUEST_READ_REMOTE_EXIT1, this, KErrNotSupported );
  1069 		return KErrNotSupported;
  1222 		return KErrNotSupported;
  1070 #endif
  1223 	    }
  1071 
  1224 #endif
  1072 	return Kern::ThreadDesRead(pT,aSrc,*aDes,0,KChunkShiftBy0);
  1225 	
       
  1226 	r = Kern::ThreadDesRead(pT,aSrc,*aDes,0,KChunkShiftBy0);
       
  1227 	OstTraceFunctionExitExt( TLOCDRVREQUEST_READ_REMOTE_EXIT2, this, r );
       
  1228 	return r;
  1073 	}
  1229 	}
  1074 
  1230 
  1075 
  1231 
  1076 
  1232 
  1077 
  1233 
  1090 
  1246 
  1091 @see Kern::ThreadRawRead()
  1247 @see Kern::ThreadRawRead()
  1092 */
  1248 */
  1093 EXPORT_C TInt TLocDrvRequest::ReadRemoteRaw(TAny* aDest, TInt aSize)
  1249 EXPORT_C TInt TLocDrvRequest::ReadRemoteRaw(TAny* aDest, TInt aSize)
  1094 	{
  1250 	{
       
  1251 	OstTraceFunctionEntry1( TLOCDRVREQUEST_READREMOTERAW_ENTRY, this );
  1095 	if (Flags() & TLocDrvRequest::EKernelBuffer)
  1252 	if (Flags() & TLocDrvRequest::EKernelBuffer)
  1096 		{
  1253 		{
  1097 		(void)memcpy(aDest, (TAny*) RemoteDes(), aSize);
  1254 		(void)memcpy(aDest, (TAny*) RemoteDes(), aSize);
  1098 		return KErrNone;
  1255 		return KErrNone;
  1099 		}
  1256 		}
  1100 
  1257 
       
  1258 	TInt r;
  1101 	DThread* pT=RemoteThread();
  1259 	DThread* pT=RemoteThread();
  1102 	if (!pT)
  1260 	if (!pT)
  1103 		pT=Client();
  1261 		pT=Client();
  1104 
  1262 
  1105 #ifdef __DEMAND_PAGING__
  1263 #ifdef __DEMAND_PAGING__
  1106 	__ASSERT_ALWAYS((Flags() & ETClientBuffer) == 0, LOCM_FAULT());
  1264 	__ASSERT_ALWAYS((Flags() & ETClientBuffer) == 0, LOCM_FAULT());
  1107 #endif
  1265 #endif
  1108 
  1266 	
  1109 	return Kern::ThreadRawRead(pT,RemoteDes(),aDest,aSize);
  1267 	r = Kern::ThreadRawRead(pT,RemoteDes(),aDest,aSize);
       
  1268 	OstTraceFunctionExitExt( TLOCDRVREQUEST_READREMOTERAW_EXIT, this, r );
       
  1269 	return r;
  1110 	}
  1270 	}
  1111 
  1271 
  1112 
  1272 
  1113 /**
  1273 /**
  1114 Writes data to a descriptor in the requesting thread's process.
  1274 Writes data to a descriptor in the requesting thread's process.
  1130 
  1290 
  1131 @see Kern::ThreadDesWrite()
  1291 @see Kern::ThreadDesWrite()
  1132 */
  1292 */
  1133 EXPORT_C TInt TLocDrvRequest::WriteRemote(const TDesC8* aDes, TInt anOffset)
  1293 EXPORT_C TInt TLocDrvRequest::WriteRemote(const TDesC8* aDes, TInt anOffset)
  1134 	{
  1294 	{
       
  1295     OstTraceFunctionEntry1( TLOCDRVREQUEST_WRITEREMOTE_ENTRY, this );
       
  1296     TInt r;
  1135 	DThread* pC=Client();
  1297 	DThread* pC=Client();
  1136 	DThread* pT=RemoteThread();
  1298 	DThread* pT=RemoteThread();
  1137 	if (!pT)
  1299 	if (!pT)
  1138 		pT=pC;
  1300 		pT=pC;
  1139 
  1301 
  1140 #ifdef __DEMAND_PAGING__
  1302 #ifdef __DEMAND_PAGING__
  1141 	if (Flags() & ETClientBuffer)
  1303 	if (Flags() & ETClientBuffer)
  1142 		return Kern::ThreadBufWrite(pT, (TClientBuffer*) RemoteDes(),*aDes,anOffset+RemoteDesOffset(),KChunkShiftBy0,pC);
  1304 	    {
  1143 #endif
  1305         r = Kern::ThreadBufWrite(pT, (TClientBuffer*) RemoteDes(),*aDes,anOffset+RemoteDesOffset(),KChunkShiftBy0,pC);
  1144 
  1306 		OstTraceFunctionExitExt( TLOCDRVREQUEST_WRITEREMOTE_EXIT1, this, r );
  1145 	return Kern::ThreadDesWrite(pT,RemoteDes(),*aDes,anOffset+RemoteDesOffset(),KChunkShiftBy0,pC);
  1307 		return r;
       
  1308 	    }
       
  1309 #endif
       
  1310 	r = Kern::ThreadDesWrite(pT,RemoteDes(),*aDes,anOffset+RemoteDesOffset(),KChunkShiftBy0,pC);
       
  1311 	OstTraceFunctionExitExt( TLOCDRVREQUEST_WRITEREMOTE_EXIT2, this, r );
       
  1312 	return r;
  1146 	}
  1313 	}
  1147 
  1314 
  1148 
  1315 
  1149 /**
  1316 /**
  1150 Writes raw data to the requesting thread's process.
  1317 Writes raw data to the requesting thread's process.
  1162 
  1329 
  1163 @see Kern::ThreadRawWrite()
  1330 @see Kern::ThreadRawWrite()
  1164 */
  1331 */
  1165 EXPORT_C TInt TLocDrvRequest::WriteRemoteRaw(const TAny* aSrc, TInt aSize)
  1332 EXPORT_C TInt TLocDrvRequest::WriteRemoteRaw(const TAny* aSrc, TInt aSize)
  1166 	{
  1333 	{
       
  1334     OstTraceFunctionEntry1( TLOCDRVREQUEST_WRITEREMOTERAW_ENTRY, this );
       
  1335     TInt r;
  1167 	DThread* pC=Client();
  1336 	DThread* pC=Client();
  1168 	DThread* pT=RemoteThread();
  1337 	DThread* pT=RemoteThread();
  1169 	if (!pT)
  1338 	if (!pT)
  1170 		pT=pC;
  1339 		pT=pC;
  1171 
  1340 
  1172 #ifdef __DEMAND_PAGING__
  1341 #ifdef __DEMAND_PAGING__
  1173 	__ASSERT_ALWAYS((Flags() & ETClientBuffer) == 0, LOCM_FAULT());
  1342 	__ASSERT_ALWAYS((Flags() & ETClientBuffer) == 0, LOCM_FAULT());
  1174 #endif
  1343 #endif
  1175 
  1344 	r = Kern::ThreadRawWrite(pT,RemoteDes(),aSrc,aSize,pC);
  1176 	return Kern::ThreadRawWrite(pT,RemoteDes(),aSrc,aSize,pC);
  1345 	OstTraceFunctionExitExt( TLOCDRVREQUEST_WRITEREMOTERAW_EXIT, this, r );
       
  1346 	return r;
  1177 	}
  1347 	}
  1178 
  1348 
  1179 
  1349 
  1180 TInt TLocDrvRequest::ProcessMessageData(TAny* aPtr)
  1350 TInt TLocDrvRequest::ProcessMessageData(TAny* aPtr)
  1181 //
  1351 //
  1182 // Get read/write parameters from client and open remote thread
  1352 // Get read/write parameters from client and open remote thread
  1183 //
  1353 //
  1184 	{
  1354 	{
       
  1355 	OstTraceFunctionEntry1( TLOCDRVREQUEST_PROCESSMESSAGEDATA_ENTRY, this );
  1185 	RemoteThread()=NULL;
  1356 	RemoteThread()=NULL;
  1186 	DThread& t=Kern::CurrentThread();
  1357 	DThread& t=Kern::CurrentThread();
  1187 	TLocalDriveMessageData d;
  1358 	TLocalDriveMessageData d;
  1188 	kumemget32(&d,aPtr,sizeof(d));
  1359 	kumemget32(&d,aPtr,sizeof(d));
       
  1360 	OstTrace1( TRACE_INTERNALS, TLOCDRVREQUEST_PROCESSMESSAGEDATA, "Message handle=%d", d.iHandle );
  1189 	if (d.iHandle!=KLocalMessageHandle && Id()!=DLocalDrive::EFormat)
  1361 	if (d.iHandle!=KLocalMessageHandle && Id()!=DLocalDrive::EFormat)
  1190 		{
  1362 		{
  1191 		NKern::LockSystem();
  1363 		NKern::LockSystem();
  1192 		DThread* pT = RMessageK::MessageK(d.iHandle)->iClient;
  1364 		DThread* pT = RMessageK::MessageK(d.iHandle)->iClient;
  1193 		if (!pT || pT->Open()!=KErrNone)
  1365 		if (!pT || pT->Open()!=KErrNone)
  1194 			{
  1366 			{
  1195 			NKern::UnlockSystem();
  1367 			NKern::UnlockSystem();
       
  1368 			OstTraceFunctionExitExt( TLOCDRVREQUEST_PROCESSMESSAGEDATA_EXIT1, this, KErrBadHandle );
  1196 			return KErrBadHandle;
  1369 			return KErrBadHandle;
  1197 			}
  1370 			}
  1198 		t.iExtTempObj=pT;
  1371 		t.iExtTempObj=pT;
  1199 		RemoteThread()=pT;
  1372 		RemoteThread()=pT;
  1200 		NKern::UnlockSystem();
  1373 		NKern::UnlockSystem();
  1203 	Length()=d.iLength;
  1376 	Length()=d.iLength;
  1204 	RemoteDes()=(TAny*)d.iPtr;
  1377 	RemoteDes()=(TAny*)d.iPtr;
  1205 	RemoteDesOffset()=d.iOffset;
  1378 	RemoteDesOffset()=d.iOffset;
  1206 	DriverFlags()=d.iFlags;
  1379 	DriverFlags()=d.iFlags;
  1207 	if (Pos()<0 || Length()<0)
  1380 	if (Pos()<0 || Length()<0)
       
  1381 	    {
       
  1382 		OstTraceFunctionExitExt( TLOCDRVREQUEST_PROCESSMESSAGEDATA_EXIT2, this, KErrArgument );
  1208 		return KErrArgument;
  1383 		return KErrArgument;
       
  1384 	    }
       
  1385 	OstTraceFunctionExitExt( TLOCDRVREQUEST_PROCESSMESSAGEDATA_EXIT3, this, KErrNone );
  1209 	return KErrNone;
  1386 	return KErrNone;
  1210 	}
  1387 	}
  1211 
  1388 
  1212 void TLocDrvRequest::CloseRemoteThread()
  1389 void TLocDrvRequest::CloseRemoteThread()
  1213 	{
  1390 	{
       
  1391     OstTraceFunctionEntry1( TLOCDRVREQUEST_CLOSEREMOTETHREAD_ENTRY, this );
       
  1392     
  1214 	if (!RemoteThread())
  1393 	if (!RemoteThread())
       
  1394 	    {
       
  1395 		OstTraceFunctionExit1( TLOCDRVREQUEST_CLOSEREMOTETHREAD_EXIT1, this );
  1215 		return;
  1396 		return;
       
  1397 	    }
  1216 	NKern::ThreadEnterCS();
  1398 	NKern::ThreadEnterCS();
  1217 	DThread& t=Kern::CurrentThread();
  1399 	DThread& t=Kern::CurrentThread();
  1218 	RemoteThread()=NULL;
  1400 	RemoteThread()=NULL;
  1219 	Kern::SafeClose((DObject*&)t.iExtTempObj,NULL);
  1401 	Kern::SafeClose((DObject*&)t.iExtTempObj,NULL);
  1220 	NKern::ThreadLeaveCS();
  1402 	NKern::ThreadLeaveCS();
       
  1403 	OstTraceFunctionExit1( TLOCDRVREQUEST_CLOSEREMOTETHREAD_EXIT2, this );
  1221 	}
  1404 	}
  1222 
  1405 
  1223 EXPORT_C TInt TLocDrvRequest::CheckAndAdjustForPartition()
  1406 EXPORT_C TInt TLocDrvRequest::CheckAndAdjustForPartition()
  1224 	{
  1407 	{
       
  1408 	OstTraceFunctionEntry1( TLOCDRVREQUEST_CHECKANDADJUSTFORPARTITION_ENTRY, this );
  1225 	TLocDrv& d=*Drive();
  1409 	TLocDrv& d=*Drive();
  1226 	__KTRACE_OPT(KLOCDRV,Kern::Printf("CheckAndAdjustForPartition drive %d partition len %lx",d.iDriveNumber,d.iPartitionLen));
  1410 	__KTRACE_OPT(KLOCDRV,Kern::Printf("CheckAndAdjustForPartition drive %d partition len %lx",d.iDriveNumber,d.iPartitionLen));
       
  1411 	OstTraceExt2( TRACE_INTERNALS, TLOCDRVREQUEST_CHECKANDADJUSTFORPARTITION1, "iDriveNumber=%d; partition length=0x%lx", d.iDriveNumber, (TInt) d.iPartitionLen );
  1227 	Flags() |= EAdjusted;
  1412 	Flags() |= EAdjusted;
       
  1413 	TInt r;
  1228 	switch (Id())
  1414 	switch (Id())
  1229 		{
  1415 		{
  1230 		case DLocalDrive::ECaps:
  1416 		case DLocalDrive::ECaps:
  1231 		case DLocalDrive::EForceMediaChange:
  1417 		case DLocalDrive::EForceMediaChange:
  1232 		case DLocalDrive::EPasswordLock:
  1418 		case DLocalDrive::EPasswordLock:
  1235 		case DLocalDrive::EPasswordErase:
  1421 		case DLocalDrive::EPasswordErase:
  1236 		case DLocalDrive::EReadPasswordStore:
  1422 		case DLocalDrive::EReadPasswordStore:
  1237  		case DLocalDrive::EWritePasswordStore:
  1423  		case DLocalDrive::EWritePasswordStore:
  1238  		case DLocalDrive::EPasswordStoreLengthInBytes:
  1424  		case DLocalDrive::EPasswordStoreLengthInBytes:
  1239 		case DLocalDrive::EQueryDevice:
  1425 		case DLocalDrive::EQueryDevice:
  1240 			return KErrNone;
  1426 		    {
       
  1427 			r = KErrNone;
       
  1428 			break;
       
  1429 		    }
  1241 		case DLocalDrive::EEnlarge:
  1430 		case DLocalDrive::EEnlarge:
  1242 			__KTRACE_OPT(KLOCDRV,Kern::Printf("Enlarge request %lx",Length()));
  1431 			__KTRACE_OPT(KLOCDRV,Kern::Printf("Enlarge request %lx",Length()));
       
  1432 			OstTrace1( TRACE_INTERNALS, TLOCDRVREQUEST_CHECKANDADJUSTFORPARTITION2, "Enlarge request=0x%lx", Length() );
  1243 			if (Length()>KMaxTInt)
  1433 			if (Length()>KMaxTInt)
  1244 				return KErrArgument;
  1434 				r = KErrArgument;
  1245 			return KErrNone;
  1435 			else
       
  1436 			    r = KErrNone;
       
  1437 			break;
  1246 		case DLocalDrive::EReduce:
  1438 		case DLocalDrive::EReduce:
  1247 			__KTRACE_OPT(KLOCDRV,Kern::Printf("Reduce request %lx@%lx",Length(),Pos()));
  1439 			__KTRACE_OPT(KLOCDRV,Kern::Printf("Reduce request %lx@%lx",Length(),Pos()));
       
  1440 			OstTraceExt2( TRACE_INTERNALS, TLOCDRVREQUEST_CHECKANDADJUSTFORPARTITION3, "Reduce request length=0x%lx; position=0x%lx", (TUint) Length(), (TUint) Pos() );
  1248 			if (Pos()+Length()>d.iPartitionLen)
  1441 			if (Pos()+Length()>d.iPartitionLen)
  1249 				return KErrArgument;
  1442 				r = KErrArgument;
  1250 			return KErrNone;
  1443 			else
       
  1444                 r = KErrNone;
       
  1445 			break;
  1251 		case DLocalDrive::EFormat:
  1446 		case DLocalDrive::EFormat:
  1252 			__KTRACE_OPT(KLOCDRV,Kern::Printf("Format request %lx@%lx",Length(),Pos()));
  1447 			__KTRACE_OPT(KLOCDRV,Kern::Printf("Format request %lx@%lx",Length(),Pos()));
       
  1448 			OstTraceExt2( TRACE_INTERNALS, TLOCDRVREQUEST_CHECKANDADJUSTFORPARTITION4, "Format request length=0x%lx; position=0x%lx", (TUint) Length(), (TUint) Pos() );
  1253 			if (!(DriverFlags() & RLocalDrive::ELocDrvWholeMedia))
  1449 			if (!(DriverFlags() & RLocalDrive::ELocDrvWholeMedia))
  1254 				{
  1450 				{
  1255 				if (Pos()>d.iPartitionLen)
  1451 				if (Pos()>d.iPartitionLen)
  1256 					{
  1452 					{
  1257 					Length()=0;
  1453 					Length()=0;
  1258 					return KErrEof;
  1454 					r = KErrEof;
       
  1455 					break;
  1259 					}
  1456 					}
  1260 				Int64 left=d.iPartitionLen-Pos();
  1457 				Int64 left=d.iPartitionLen-Pos();
  1261 				if (left<Length())
  1458 				if (left<Length())
  1262 					Length()=left;
  1459 					Length()=left;
  1263 				Pos()+=d.iPartitionBaseAddr;
  1460 				Pos()+=d.iPartitionBaseAddr;
  1264 				if (Length()==0)
  1461 				if (Length()==0)
  1265 					return KErrEof;
  1462 				    {
       
  1463 					r = KErrEof;
       
  1464 					break;
       
  1465 				    }
  1266 				}
  1466 				}
  1267 			return KErrNone;
  1467 			r = KErrNone;
       
  1468 			break;
  1268 
  1469 
  1269 #ifdef __DEMAND_PAGING__
  1470 #ifdef __DEMAND_PAGING__
  1270 		case DMediaPagingDevice::ERomPageInRequest:
  1471 		case DMediaPagingDevice::ERomPageInRequest:
  1271 //          if the ROM was reported to LOCM then it will also need to be adjusted.... 
  1472 //          if the ROM was reported to LOCM then it will also need to be adjusted.... 
  1272 //		    Otherwise the media driver adjust it internally
  1473 //		    Otherwise the media driver adjust it internally
  1273 		case DMediaPagingDevice::ECodePageInRequest:
  1474 		case DMediaPagingDevice::ECodePageInRequest:
  1274 			__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Adjusted Paging read request %lx@%lx",Length(),Pos()));
  1475 			__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Adjusted Paging read request %lx@%lx",Length(),Pos()));
       
  1476 			OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, TLOCDRVREQUESTCHECKANDADJUSTFORPARTITION5, "Adjusted Paging read request length=0x%lx; position=0x%lx", (TUint) Length(),  (TUint) Pos());
  1275 			if (Pos()+Length()>d.iPartitionLen)
  1477 			if (Pos()+Length()>d.iPartitionLen)
  1276 				return KErrArgument;
  1478 			    {
       
  1479 				r = KErrArgument;
       
  1480 				break;
       
  1481 			    }
  1277 			Pos()+=d.iPartitionBaseAddr;
  1482 			Pos()+=d.iPartitionBaseAddr;
  1278 			return KErrNone;
  1483 			r = KErrNone;
       
  1484 			break;
  1279 #endif
  1485 #endif
  1280 		
  1486 		
  1281 		default:	// read or write or fragment
  1487 		default:	// read or write or fragment
  1282 			__KTRACE_OPT(KLOCDRV,Kern::Printf("R/W request %lx@%lx",Length(),Pos()));
  1488 			__KTRACE_OPT(KLOCDRV,Kern::Printf("R/W request %lx@%lx",Length(),Pos()));
  1283 
  1489 			OstTraceExt2( TRACE_INTERNALS, TLOCDRVREQUEST_CHECKANDADJUSTFORPARTITION6, "Read/Write request length=0x%x; position=0x%x", (TUint) Length(), (TUint) Pos() );
  1284 			if (DriverFlags() & RLocalDrive::ELocDrvWholeMedia)
  1490 			if (DriverFlags() & RLocalDrive::ELocDrvWholeMedia)
  1285 				{
  1491 				{
  1286 				if (d.iMedia && d.iMedia->iDriver && Pos()+Length() > d.iMedia->iDriver->iTotalSizeInBytes)
  1492 				if (d.iMedia && d.iMedia->iDriver && Pos()+Length() > d.iMedia->iDriver->iTotalSizeInBytes)
  1287 					return KErrArgument;
  1493 				    {
       
  1494 					r = KErrArgument;
       
  1495 					break;
       
  1496 				    }
  1288 				}
  1497 				}
  1289 			else
  1498 			else
  1290 				{
  1499 				{
  1291 				if (Pos()+Length() > d.iPartitionLen)
  1500 				if (Pos()+Length() > d.iPartitionLen)
  1292 					return KErrArgument;
  1501 				    {
       
  1502 					r = KErrArgument;
       
  1503 					break;
       
  1504 				    }
  1293 				Pos()+=d.iPartitionBaseAddr;
  1505 				Pos()+=d.iPartitionBaseAddr;
  1294 				}
  1506 				}
  1295 			return KErrNone;
  1507 		r = KErrNone;
  1296 		}
  1508 		}
       
  1509 	OstTraceFunctionExitExt( TLOCDRVREQUEST_CHECKANDADJUSTFORPARTITION_EXIT, this, r );
       
  1510 	return r;
  1297 	}
  1511 	}
  1298 
  1512 
  1299 /********************************************
  1513 /********************************************
  1300  * Local drive class
  1514  * Local drive class
  1301  ********************************************/
  1515  ********************************************/
  1302 TLocDrv::TLocDrv(TInt aDriveNumber)
  1516 TLocDrv::TLocDrv(TInt aDriveNumber)
  1303 	{
  1517 	{
       
  1518 	OstTraceFunctionEntryExt( TLOCDRV_TLOCDRV_ENTRY, this );
  1304 	memclr(this, sizeof(TLocDrv));
  1519 	memclr(this, sizeof(TLocDrv));
  1305 	iDriveNumber=aDriveNumber;
  1520 	iDriveNumber=aDriveNumber;
  1306 	iPartitionNumber=-1;
  1521 	iPartitionNumber=-1;
       
  1522 	OstTraceFunctionExit1( TLOCDRV_TLOCDRV_EXIT, this );
  1307 	}
  1523 	}
  1308 
  1524 
  1309 /**
  1525 /**
  1310 Initialises the DMedia entity with the media device number and ID.
  1526 Initialises the DMedia entity with the media device number and ID.
  1311  
  1527  
  1319 
  1535 
  1320 @see	TMediaDevice
  1536 @see	TMediaDevice
  1321 */
  1537 */
  1322 EXPORT_C TInt DMedia::Create(TMediaDevice aDevice, TInt aMediaId, TInt)
  1538 EXPORT_C TInt DMedia::Create(TMediaDevice aDevice, TInt aMediaId, TInt)
  1323 	{
  1539 	{
       
  1540 	OstTraceFunctionEntry1( DMEDIA_CREATE_ENTRY, this );
  1324 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DMedia::Create media %d device %d",aMediaId,aDevice));
  1541 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DMedia::Create media %d device %d",aMediaId,aDevice));
       
  1542 	OstTraceExt2(TRACE_INTERNALS, DMEDIA_CREATE, "media=%d; device=%d", aMediaId, (TUint) aDevice);
  1325 	iMediaId=aMediaId;
  1543 	iMediaId=aMediaId;
  1326 	iDevice=aDevice;
  1544 	iDevice=aDevice;
       
  1545 	OstTraceFunctionExitExt( DMEDIA_CREATE_EXIT, this, KErrNone );
  1327 	return KErrNone;
  1546 	return KErrNone;
  1328 	}
  1547 	}
  1329 
  1548 
  1330 /********************************************
  1549 /********************************************
  1331  * Primary Media Class
  1550  * Primary Media Class
  1332  ********************************************/
  1551  ********************************************/
  1333 void asyncDfc(TAny* aPtr)
  1552 void asyncDfc(TAny* aPtr)
  1334 	{
  1553 	{
       
  1554 	OstTraceFunctionEntry0( _ASYNCDFC_ENTRY );
  1335 	DPrimaryMediaBase* pM=(DPrimaryMediaBase*)aPtr;
  1555 	DPrimaryMediaBase* pM=(DPrimaryMediaBase*)aPtr;
  1336 	if (pM->iState==DMedia::EOpening)
  1556 	if (pM->iState==DMedia::EOpening)
  1337 		pM->DoOpenMediaDriverComplete(pM->iAsyncErrorCode);
  1557 		pM->DoOpenMediaDriverComplete(pM->iAsyncErrorCode);
  1338 	else if (pM->iState==DMedia::EReadPartitionInfo)
  1558 	else if (pM->iState==DMedia::EReadPartitionInfo)
  1339 		pM->DoPartitionInfoComplete(pM->iAsyncErrorCode);
  1559 		pM->DoPartitionInfoComplete(pM->iAsyncErrorCode);
       
  1560 	OstTraceFunctionExit0( _ASYNCDFC_EXIT );
  1340 	}
  1561 	}
  1341 
  1562 
  1342 void handleMsg(TAny* aPtr)
  1563 void handleMsg(TAny* aPtr)
  1343 	{
  1564 	{
       
  1565 	OstTraceFunctionEntry0( _HANDLEMSG_ENTRY );
  1344 	DPrimaryMediaBase* primaryMedia=(DPrimaryMediaBase*)aPtr;
  1566 	DPrimaryMediaBase* primaryMedia=(DPrimaryMediaBase*)aPtr;
  1345 
  1567 
  1346 	for(TLocDrvRequest* m = (TLocDrvRequest*) primaryMedia->iMsgQ.iMessage; 
  1568 	for(TLocDrvRequest* m = (TLocDrvRequest*) primaryMedia->iMsgQ.iMessage; 
  1347 		m != NULL; 
  1569 		m != NULL; 
  1348 		m = (TLocDrvRequest*) primaryMedia->iMsgQ.Poll())
  1570 		m = (TLocDrvRequest*) primaryMedia->iMsgQ.Poll())
  1361 #endif
  1583 #endif
  1362 		}
  1584 		}
  1363 
  1585 
  1364 
  1586 
  1365 	primaryMedia->iMsgQ.Receive();	// allow reception of more messages
  1587 	primaryMedia->iMsgQ.Receive();	// allow reception of more messages
       
  1588 	OstTraceFunctionExit0( _HANDLEMSG_EXIT );
  1366 	}
  1589 	}
  1367 
  1590 
  1368 EXPORT_C DPrimaryMediaBase::DPrimaryMediaBase()
  1591 EXPORT_C DPrimaryMediaBase::DPrimaryMediaBase()
  1369 	:	iMsgQ(handleMsg, this, NULL, 1),
  1592 	:	iMsgQ(handleMsg, this, NULL, 1),
  1370 		iDeferred(NULL, NULL, NULL, 0),			// callback never used
  1593 		iDeferred(NULL, NULL, NULL, 0),			// callback never used
  1373 /**
  1596 /**
  1374 Constructor of DPrimaryMediaBase class.
  1597 Constructor of DPrimaryMediaBase class.
  1375 Initialises the media state as closed.
  1598 Initialises the media state as closed.
  1376 */
  1599 */
  1377 	{
  1600 	{
       
  1601 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_DPRIMARYMEDIABASE_ENTRY, this );
  1378 	iState = EClosed;
  1602 	iState = EClosed;
  1379 	}
  1603 	}
  1380 
  1604 
  1381 
  1605 
  1382 
  1606 
  1392 @return KErrNone
  1616 @return KErrNone
  1393 @see TMediaDevice 
  1617 @see TMediaDevice 
  1394 
  1618 
  1395 */
  1619 */
  1396 	{
  1620 	{
       
  1621 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_CREATE_ENTRY, this );
  1397 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase::Create media %d-%d device %d",aMediaId,aLastMediaId,aDevice));
  1622 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase::Create media %d-%d device %d",aMediaId,aLastMediaId,aDevice));
       
  1623 	OstTraceExt3( TRACE_INTERNALS, DPRIMARYMEDIABASE_CREATE, "aMediaId=%d; aLastMediaId=%d; aDevice=%d ", aMediaId, aLastMediaId, (TUint) aDevice );
  1398 	TInt r=DMedia::Create(aDevice,aMediaId,0);
  1624 	TInt r=DMedia::Create(aDevice,aMediaId,0);
       
  1625 	
  1399 	if (r != KErrNone)
  1626 	if (r != KErrNone)
       
  1627 	    {
       
  1628 		OstTraceFunctionExitExt( DPRIMARYMEDIABASE_CREATE_EXIT1, this, r );
  1400 		return r;
  1629 		return r;
       
  1630 	    }
  1401 	iBody = new DBody;
  1631 	iBody = new DBody;
  1402 	if (iBody == NULL)
  1632 	if (iBody == NULL)
       
  1633 	    {
       
  1634 		OstTraceFunctionExitExt( DPRIMARYMEDIABASE_CREATE_EXIT2, this, KErrNoMemory );
  1403 		return KErrNoMemory;
  1635 		return KErrNoMemory;
       
  1636 	    }
       
  1637 	
       
  1638 	
  1404 
  1639 
  1405 #ifdef __DEMAND_PAGING__
  1640 #ifdef __DEMAND_PAGING__
  1406 	TInt pageSize = Kern::RoundToPageSize(1);
  1641 	TInt pageSize = Kern::RoundToPageSize(1);
  1407 	iBody->iPageSizeMsk = pageSize-1;
  1642 	iBody->iPageSizeMsk = pageSize-1;
  1408 #endif
  1643 #endif
  1413 		iMsgQ.SetDfcQ(iDfcQ);
  1648 		iMsgQ.SetDfcQ(iDfcQ);
  1414 		iDeferred.SetDfcQ(iDfcQ);
  1649 		iDeferred.SetDfcQ(iDfcQ);
  1415 		iWaitMedChg.SetDfcQ(iDfcQ);
  1650 		iWaitMedChg.SetDfcQ(iDfcQ);
  1416 		iAsyncDfc.SetDfcQ(iDfcQ);
  1651 		iAsyncDfc.SetDfcQ(iDfcQ);
  1417 		}
  1652 		}
       
  1653 	OstTraceFunctionExitExt( DPRIMARYMEDIABASE_CREATE_EXIT3, this, KErrNone );
  1418 	return KErrNone;
  1654 	return KErrNone;
  1419 	}
  1655 	}
  1420 
  1656 
  1421 
  1657 
  1422 EXPORT_C TInt DPrimaryMediaBase::Connect(DLocalDrive* aLocalDrive)
  1658 EXPORT_C TInt DPrimaryMediaBase::Connect(DLocalDrive* aLocalDrive)
  1437 		otherwise, one of the other system wide error codes.
  1673 		otherwise, one of the other system wide error codes.
  1438 
  1674 
  1439 @see DLocalDrive
  1675 @see DLocalDrive
  1440 */
  1676 */
  1441 	{
  1677 	{
       
  1678 	OstTraceFunctionEntryExt( DPRIMARYMEDIABASE_CONNECT_ENTRY, this );
  1442 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::Connect %O",iMediaId,aLocalDrive));
  1679 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::Connect %O",iMediaId,aLocalDrive));
       
  1680 	OstTraceExt2( TRACE_MEDIACHANGE, DPRIMARYMEDIABASE_CONNECT, "iMediaId=%d; iDriveNumber=%d", iMediaId, aLocalDrive->iDrive->iDriveNumber );
       
  1681 	
       
  1682 	TInt r=KErrNone;
       
  1683 	
  1443 	if (iDfcQ)
  1684 	if (iDfcQ)
  1444 		{
  1685 		{
  1445 		TThreadMessage& m=Kern::Message();
  1686 		TThreadMessage& m=Kern::Message();
  1446 		m.iValue=EConnect;
  1687 		m.iValue=EConnect;
  1447 		m.iArg[0]=aLocalDrive;
  1688 		m.iArg[0]=aLocalDrive;
  1448 		return m.SendReceive(&iMsgQ);
  1689 		r=m.SendReceive(&iMsgQ);
       
  1690 		OstTraceFunctionExitExt( DPRIMARYMEDIABASE_CONNECT_EXIT1, this, r );
       
  1691 		return r;
  1449 		}
  1692 		}
  1450 
  1693 
  1451 	// If no DFC queue, must be a fixed media device
  1694 	// If no DFC queue, must be a fixed media device
  1452 	// If this is the first connection, open media driver now
  1695 	// If this is the first connection, open media driver now
  1453 	// Assume no non-primary media exist on this device
  1696 	// Assume no non-primary media exist on this device
  1454 	TInt r=KErrNone;
  1697 	
  1455 	NKern::LockSystem();
  1698 	NKern::LockSystem();
  1456 	TBool first=iConnectionQ.IsEmpty();
  1699 	TBool first=iConnectionQ.IsEmpty();
  1457 	iConnectionQ.Add(&aLocalDrive->iLink);
  1700 	iConnectionQ.Add(&aLocalDrive->iLink);
  1458 	NKern::UnlockSystem();
  1701 	NKern::UnlockSystem();
  1459 	if (first)
  1702 	if (first)
  1464 			NKern::LockSystem();
  1707 			NKern::LockSystem();
  1465 			aLocalDrive->Deque();
  1708 			aLocalDrive->Deque();
  1466 			NKern::UnlockSystem();
  1709 			NKern::UnlockSystem();
  1467 			}
  1710 			}
  1468 		}
  1711 		}
       
  1712 	
  1469 	if (r==KErrNone)
  1713 	if (r==KErrNone)
  1470 		aLocalDrive->iDrive->iMedia=this;
  1714 		aLocalDrive->iDrive->iMedia=this;
       
  1715 	OstTraceFunctionExitExt( DPRIMARYMEDIABASE_CONNECT_EXIT2, this, r );
  1471 	return r;
  1716 	return r;
  1472 	}
  1717 	}
  1473 
  1718 
  1474 
  1719 
  1475 
  1720 
  1486 @post Kernel must be unlocked
  1731 @post Kernel must be unlocked
  1487 @see DLocalDrive
  1732 @see DLocalDrive
  1488 */
  1733 */
  1489 
  1734 
  1490 	{
  1735 	{
       
  1736 	OstTraceFunctionEntryExt( DPRIMARYMEDIABASE_DISCONNECT_ENTRY, this );
  1491 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::Disconnect %O",iMediaId,aLocalDrive));
  1737 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::Disconnect %O",iMediaId,aLocalDrive));
       
  1738 	OstTraceExt2( TRACE_MEDIACHANGE, DPRIMARYMEDIABASE_DISCONNECT, "iMediaId=%d; iDriveNumber=%d", iMediaId, aLocalDrive->iDrive->iDriveNumber );
       
  1739 	
  1492 	if (iDfcQ)
  1740 	if (iDfcQ)
  1493 		{
  1741 		{
  1494 		TThreadMessage& m=Kern::Message();
  1742 		TThreadMessage& m=Kern::Message();
  1495 		m.iValue=EDisconnect;
  1743 		m.iValue=EDisconnect;
  1496 		m.iArg[0]=aLocalDrive;
  1744 		m.iArg[0]=aLocalDrive;
  1497 		m.SendReceive(&iMsgQ);
  1745 		m.SendReceive(&iMsgQ);
       
  1746 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_DISCONNECT_EXIT1, this );
  1498 		return;
  1747 		return;
  1499 		}
  1748 		}
  1500 
  1749 
  1501 	// If no DFC queue, must be a fixed media device
  1750 	// If no DFC queue, must be a fixed media device
  1502 	// If this is the last connection, close media driver now
  1751 	// If this is the last connection, close media driver now
  1511 		iDriver=NULL;
  1760 		iDriver=NULL;
  1512 		}
  1761 		}
  1513 	NKern::UnlockSystem();
  1762 	NKern::UnlockSystem();
  1514 	if (pD)
  1763 	if (pD)
  1515 		pD->Close();
  1764 		pD->Close();
       
  1765 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_DISCONNECT_EXIT2, this );
  1516 	}
  1766 	}
  1517 
  1767 
  1518 EXPORT_C TInt DPrimaryMediaBase::Request(TLocDrvRequest& aReq)
  1768 EXPORT_C TInt DPrimaryMediaBase::Request(TLocDrvRequest& aReq)
  1519 /**
  1769 /**
  1520 Issues a local drive request. It is called from TLocDrv::Request() function .
  1770 Issues a local drive request. It is called from TLocDrv::Request() function .
  1533 	Otherwise, one of the other system wide error codes.
  1783 	Otherwise, one of the other system wide error codes.
  1534 
  1784 
  1535 @see TLocDrvRequest
  1785 @see TLocDrvRequest
  1536 */
  1786 */
  1537 	{
  1787 	{
       
  1788 OstTraceFunctionEntry1( DPRIMARYMEDIABASE_REQUEST_ENTRY, this );
  1538 
  1789 
  1539 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::Request(%08x)",iMediaId,&aReq));
  1790 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::Request(%08x)",iMediaId,&aReq));
  1540 	__KTRACE_OPT(KLOCDRV,Kern::Printf("this=%x, ReqId=%d, Pos=%lx, Len=%lx, remote thread %O",this,aReq.Id(),aReq.Pos(),aReq.Length(),aReq.RemoteThread()));
  1791 	__KTRACE_OPT(KLOCDRV,Kern::Printf("this=%x, ReqId=%d, Pos=%lx, Len=%lx, remote thread %O",this,aReq.Id(),aReq.Pos(),aReq.Length(),aReq.RemoteThread()));
  1541 
  1792 
       
  1793 	OstTraceDefExt4(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DPRIMARYMEDIABASE_REQUEST, "reqId=%d; length=0x%lx; position=0x%lx; remote thread=0x%x", (TInt) aReq.Id(), (TUint) aReq.Length(),  (TUint) aReq.Pos(), (TUint) aReq.RemoteThread());
       
  1794 	
  1542 	TInt reqId = aReq.Id();
  1795 	TInt reqId = aReq.Id();
  1543 
  1796 
  1544 	if (reqId == DLocalDrive::ECaps)
  1797 	if (reqId == DLocalDrive::ECaps)
  1545 		DefaultDriveCaps(*(TLocalDriveCapsV2*)aReq.RemoteDes());	// fill in stuff we know even if no media present
  1798 		DefaultDriveCaps(*(TLocalDriveCapsV2*)aReq.RemoteDes());	// fill in stuff we know even if no media present
  1546 
  1799 
  1548 	if (r != KErrNone && aReq.Id()!=DLocalDrive::EForceMediaChange &&			// EForceMediaChange, and 
  1801 	if (r != KErrNone && aReq.Id()!=DLocalDrive::EForceMediaChange &&			// EForceMediaChange, and 
  1549  			 			 aReq.Id()!=DLocalDrive::EReadPasswordStore &&			// Password store operations 
  1802  			 			 aReq.Id()!=DLocalDrive::EReadPasswordStore &&			// Password store operations 
  1550  						 aReq.Id()!=DLocalDrive::EWritePasswordStore &&			// do not require the media 
  1803  						 aReq.Id()!=DLocalDrive::EWritePasswordStore &&			// do not require the media 
  1551  						 aReq.Id()!=DLocalDrive::EPasswordStoreLengthInBytes)	// to be ready.)
  1804  						 aReq.Id()!=DLocalDrive::EPasswordStoreLengthInBytes)	// to be ready.)
  1552  	 	{
  1805  	 	{
       
  1806 		OstTraceFunctionExitExt( DPRIMARYMEDIABASE_REQUEST_EXIT, this, r );
  1553 		return r;
  1807 		return r;
  1554  	  	}
  1808  	  	}
  1555  	  	
  1809  	  	
  1556 
  1810 
  1557 	// for ERead & EWrite requests, get the linear address for pinning & DMA
  1811 	// for ERead & EWrite requests, get the linear address for pinning & DMA
  1574 			if (reqId == DLocalDrive::ERead)
  1828 			if (reqId == DLocalDrive::ERead)
  1575 				{
  1829 				{
  1576 				TPtrC8 ptr(NULL, 0);
  1830 				TPtrC8 ptr(NULL, 0);
  1577 				r = Kern::ThreadDesWrite(pT, aReq.RemoteDes(), ptr, aReq.RemoteDesOffset(), KChunkShiftBy0,pC);
  1831 				r = Kern::ThreadDesWrite(pT, aReq.RemoteDes(), ptr, aReq.RemoteDesOffset(), KChunkShiftBy0,pC);
  1578 				}
  1832 				}
       
  1833 			OstTraceFunctionExitExt( DPRIMARYMEDIABASE_REQUEST_EXIT2, this, r );
  1579 			return r;
  1834 			return r;
  1580 			}
  1835 			}
  1581 
  1836 
  1582 		clientBuffer.SetFromDescriptor(aReq.RemoteDes(), pT);
  1837 		clientBuffer.SetFromDescriptor(aReq.RemoteDes(), pT);
  1583 
  1838 
  1584 		TInt length = 0;
  1839 		TInt length = 0;
  1585 		TInt maxLength = 0;
  1840 		TInt maxLength = 0;
  1586 		TInt r = Kern::ThreadGetDesInfo(pT,aReq.RemoteDes(),length,maxLength,linAddress,EFalse);	// get descriptor length, maxlength and linAddress
  1841 		TInt r = Kern::ThreadGetDesInfo(pT,aReq.RemoteDes(),length,maxLength,linAddress,EFalse);	// get descriptor length, maxlength and linAddress
  1587 		if (r != KErrNone)
  1842 		if (r != KErrNone)
       
  1843 		    {
       
  1844 			OstTraceFunctionExitExt( DPRIMARYMEDIABASE_REQUEST_EXIT3, this, r );
  1588 			return r;
  1845 			return r;
       
  1846 		    }
  1589 		linAddress+= aReq.RemoteDesOffset();
  1847 		linAddress+= aReq.RemoteDesOffset();
  1590 
  1848 
  1591 #ifdef __DEMAND_PAGING__
  1849 #ifdef __DEMAND_PAGING__
  1592 		// NB change in behavior IF DATA PAGING IS ENABLED: TLocDrvRequest::RemoteDes() points 
  1850 		// NB change in behavior IF DATA PAGING IS ENABLED: TLocDrvRequest::RemoteDes() points 
  1593 		// to a TClientBuffer rather than the client's remote descriptor
  1851 		// to a TClientBuffer rather than the client's remote descriptor
  1606 
  1864 
  1607 #ifdef __DEMAND_PAGING__
  1865 #ifdef __DEMAND_PAGING__
  1608 		// If this is a ROM/Code paging media, pin writes 
  1866 		// If this is a ROM/Code paging media, pin writes 
  1609 		// If there is a Data paging media registered, pin all requests with descriptors 
  1867 		// If there is a Data paging media registered, pin all requests with descriptors 
  1610 		if ( (DataPagingDeviceRegistered) || (reqId == DLocalDrive::EWrite && RomPagingDfcQ(this)) )
  1868 		if ( (DataPagingDeviceRegistered) || (reqId == DLocalDrive::EWrite && RomPagingDfcQ(this)) )
       
  1869 		    {	    
  1611 			r = PinSendReceive(aReq, (TLinAddr) linAddress);
  1870 			r = PinSendReceive(aReq, (TLinAddr) linAddress);
       
  1871 		    }
  1612 		else
  1872 		else
  1613 #endif	// __DEMAND_PAGING__
  1873 #endif	// __DEMAND_PAGING__
  1614 
       
  1615 			r = SendReceive(aReq, (TLinAddr) linAddress);
  1874 			r = SendReceive(aReq, (TLinAddr) linAddress);
  1616 		}
  1875 		}
  1617 	else
  1876 	else
  1618 		{
  1877 		{
  1619 		// If no DFC queue, must be a fixed media device
  1878 		// If no DFC queue, must be a fixed media device
  1620 		// Media driver must already have been opened
  1879 		// Media driver must already have been opened
  1621 		// Assume no non-primary media exist on this device
  1880 		// Assume no non-primary media exist on this device
  1622 		// Just pass request straight through to media driver
  1881 		// Just pass request straight through to media driver
  1623 		r = aReq.CheckAndAdjustForPartition();
  1882 		r = aReq.CheckAndAdjustForPartition();
  1624 		if (r == KErrNone)
  1883 		if (r == KErrNone)
  1625 			r = iDriver->Request(aReq);
  1884 			r = iDriver->Request(aReq);		
  1626 		}
  1885 		}
  1627 
  1886 
  1628 #ifdef __DEMAND_PAGING__
  1887 #ifdef __DEMAND_PAGING__
  1629 		// NB change in behavior IF DATA PAGING IS ENABLED: TLocDrvRequest::RemoteDes() points 
  1888 		// NB change in behavior IF DATA PAGING IS ENABLED: TLocDrvRequest::RemoteDes() points 
  1630 		// to a TClientBuffer rather than the client's remote descriptor
  1889 		// to a TClientBuffer rather than the client's remote descriptor
  1631 	if (reqId == DLocalDrive::ERead && DataPagingDeviceRegistered && r == KErrNone)
  1890 	if (reqId == DLocalDrive::ERead && DataPagingDeviceRegistered && r == KErrNone)
  1632 		{
  1891 		{
  1633 		r = clientBuffer.UpdateDescriptorLength(pT);
  1892 		r = clientBuffer.UpdateDescriptorLength(pT);
  1634 		}
  1893 		}
  1635 #endif
  1894 #endif
  1636 
  1895 	OstTraceFunctionExitExt( DPRIMARYMEDIABASE_REQUEST_EXIT4, this, r );
  1637 	return r;
  1896 	return r;
  1638 	}
  1897 	}
  1639 
  1898 
  1640 
  1899 
  1641 #ifdef __DEMAND_PAGING__
  1900 #ifdef __DEMAND_PAGING__
  1642 TInt DPrimaryMediaBase::PinSendReceive(TLocDrvRequest& aReq, TLinAddr aLinAddress)
  1901 TInt DPrimaryMediaBase::PinSendReceive(TLocDrvRequest& aReq, TLinAddr aLinAddress)
  1643 	{
  1902 	{
       
  1903     OstTraceExt2(TRACE_FLOW, DPRIMARYMEDIABASE_PINSENDRECEIVE_ENTRY, "> DPrimaryMediaBase::PinSendReceive;aReq=%x;aLinAddress=%x;", (TUint) &aReq, (TUint) &aLinAddress );
       
  1904 
  1644 	__ASSERT_DEBUG(ThePinObjectAllocator, LOCM_FAULT());
  1905 	__ASSERT_DEBUG(ThePinObjectAllocator, LOCM_FAULT());
  1645 
  1906 
  1646 
  1907 
  1647 	TInt msgId = aReq.Id();
  1908 	TInt msgId = aReq.Id();
  1648 
  1909 	TInt r;
  1649 
  1910 
  1650 	switch(msgId)
  1911 	switch(msgId)
  1651 		{
  1912 		{
  1652 		case DLocalDrive::EControlIO:
  1913 		case DLocalDrive::EControlIO:
  1653 			{
  1914 			{
  1658 					// ControlIo is not supported if either of the two bare (TAny*) pointers are non-NULL 
  1919 					// ControlIo is not supported if either of the two bare (TAny*) pointers are non-NULL 
  1659 					// as it's not possible to determine what the pointers are pointing at...
  1920 					// as it's not possible to determine what the pointers are pointing at...
  1660 					if (aReq.Int1() || aReq.Int2())
  1921 					if (aReq.Int1() || aReq.Int2())
  1661 						{
  1922 						{
  1662 						__KTRACE_OPT(KDATAPAGEWARN, Kern::Printf("Data paging: Naked EControlIO not supported on paging device: fn=%x", aReq.Int0()));
  1923 						__KTRACE_OPT(KDATAPAGEWARN, Kern::Printf("Data paging: Naked EControlIO not supported on paging device: fn=%x", aReq.Int0()));
  1663 						return KErrNotSupported;
  1924 						r = KErrNotSupported;
       
  1925 						break;
  1664 						}
  1926 						}
  1665 					// fall into...
  1927 					// fall into...
  1666 				case 0:
  1928 				case 0:
  1667 					return SendReceive(aReq);
  1929 					r = SendReceive(aReq);
       
  1930 					break;
  1668 
  1931 
  1669 				default:
  1932 				default:
  1670 					// if Int3() is > 0, Int1() is a data pointer, and Int3() is a length
  1933 					// if Int3() is > 0, Int1() is a data pointer, and Int3() is a length
  1671 					if (controlIoType > (TInt) ThePinObjectAllocator->iFragmentGranularity)
  1934 					if (controlIoType > (TInt) ThePinObjectAllocator->iFragmentGranularity)
  1672 						return KErrTooBig;
  1935 					    {
       
  1936 						r = KErrTooBig;
       
  1937 						break;
       
  1938 					    }
  1673 					if (controlIoType < 0)
  1939 					if (controlIoType < 0)
  1674 						return KErrArgument;
  1940 					    {
  1675 					return PinFragmentSendReceive(aReq, (TLinAddr) aReq.Ptr1(), controlIoType);
  1941 						r = KErrArgument;
       
  1942 						break;
       
  1943 					    }
       
  1944 					r = PinFragmentSendReceive(aReq, (TLinAddr) aReq.Ptr1(), controlIoType);
       
  1945 					break;
  1676 				}
  1946 				}
       
  1947 			break;
  1677 			}
  1948 			}
  1678 
  1949 
  1679 		case DLocalDrive::ERead:
  1950 		case DLocalDrive::ERead:
  1680 		case DLocalDrive::EWrite:
  1951 		case DLocalDrive::EWrite:
  1681 			{
  1952 			{
  1682 			return PinFragmentSendReceive(aReq, aLinAddress, aReq.Length());
  1953 			r = PinFragmentSendReceive(aReq, aLinAddress, aReq.Length());
       
  1954 			break;
  1683 			}
  1955 			}
  1684 		
  1956 		
  1685 		// For all these requests, aReq.RemoteDes() points to a buffer on the stack in DLocalDrive::Request()
  1957 		// For all these requests, aReq.RemoteDes() points to a buffer on the stack in DLocalDrive::Request()
  1686 		// This is a kernel stack & so should be unpaged & not require pinning...
  1958 		// This is a kernel stack & so should be unpaged & not require pinning...
  1687 		case DLocalDrive::ECaps:
  1959 		case DLocalDrive::ECaps:
  1694 		case DLocalDrive::EWritePasswordStore:
  1966 		case DLocalDrive::EWritePasswordStore:
  1695 		case DLocalDrive::EPasswordStoreLengthInBytes:
  1967 		case DLocalDrive::EPasswordStoreLengthInBytes:
  1696 		case DLocalDrive::EPasswordErase:
  1968 		case DLocalDrive::EPasswordErase:
  1697 
  1969 
  1698 		default:		
  1970 		default:		
  1699 			return SendReceive(aReq);
  1971 			r = SendReceive(aReq);
  1700 		}
  1972 		}
       
  1973 	OstTraceFunctionExitExt( DPRIMARYMEDIABASE_PINSENDRECEIVE_EXIT, this, r );
       
  1974 	return r;
  1701 	}
  1975 	}
  1702 
  1976 
  1703 TInt DPrimaryMediaBase::PinFragmentSendReceive(TLocDrvRequest& aReq, TLinAddr aLinAddress, TInt aLength)
  1977 TInt DPrimaryMediaBase::PinFragmentSendReceive(TLocDrvRequest& aReq, TLinAddr aLinAddress, TInt aLength)
  1704 	{
  1978 	{
       
  1979 	OstTraceExt3(TRACE_FLOW, DPRIMARYMEDIABASE_PINFRAGMENTSENDRECEIVE_ENTRY, "> DPrimaryMediaBase::PinFragmentSendReceive;aReq=%x;aLinAddress=%x;aLength=%d;", (TUint) &aReq, (TUint) &aLinAddress, aLength );
       
  1980 	
  1705 	TLocDrvRequest fragment = aReq;		// create a request on the stack for use during fragmentation, pre-fill with the original req args, leave original Kernel message as repository (thread will block, message contents won't change)
  1981 	TLocDrvRequest fragment = aReq;		// create a request on the stack for use during fragmentation, pre-fill with the original req args, leave original Kernel message as repository (thread will block, message contents won't change)
  1706 	TInt r = KErrNone;
  1982 	TInt r = KErrNone;
  1707 
  1983 
  1708 //	Kern::Printf(">PFSR %02X aReq %08X aLinAddress %08X aLen %08X offset %08X", aReq.Id(), &aReq, aLinAddress, aLength, aReq.RemoteDesOffset());
  1984 //	Kern::Printf(">PFSR %02X aReq %08X aLinAddress %08X aLen %08X offset %08X", aReq.Id(), &aReq, aLinAddress, aLength, aReq.RemoteDesOffset());
  1709 
  1985 
  1711 	if (!pT)
  1987 	if (!pT)
  1712 		pT=&Kern::CurrentThread();	// e.g. when using TBusLocalDrive directly
  1988 		pT=&Kern::CurrentThread();	// e.g. when using TBusLocalDrive directly
  1713 
  1989 
  1714 	__KTRACE_OPT2(KLOCDPAGING,KLOCDRV,Kern::Printf("Fragmenting Read/Write Request(0x%08x) on drive(%d), remote des(0x%x), offset into des(0x%x), original req Length(0x%x)",&aReq,aReq.Drive()->iDriveNumber,(TInt)(aReq.RemoteDes()),aReq.RemoteDesOffset(),aLength));
  1990 	__KTRACE_OPT2(KLOCDPAGING,KLOCDRV,Kern::Printf("Fragmenting Read/Write Request(0x%08x) on drive(%d), remote des(0x%x), offset into des(0x%x), original req Length(0x%x)",&aReq,aReq.Drive()->iDriveNumber,(TInt)(aReq.RemoteDes()),aReq.RemoteDesOffset(),aLength));
  1715 	__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Remote thread(0x%08x), current thread(0x%08x), start of data to write(0x%08x)",aReq.RemoteThread(),&Kern::CurrentThread(),(TInt)aLinAddress));
  1991 	__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Remote thread(0x%08x), current thread(0x%08x), start of data to write(0x%08x)",aReq.RemoteThread(),&Kern::CurrentThread(),(TInt)aLinAddress));
  1716 
  1992 	OstTraceDefExt5(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_PINFRAGMENTSENDRECEIVE1, "Fragmenting Read/Write Request=0x%08x; drive=%d; remote des=0x%x; offset into des=0x%x; original length=0x%x", (TUint) &aReq, (TUint) aReq.Drive()->iDriveNumber, (TInt) (aReq.RemoteDes()), (TInt) aReq.RemoteDesOffset(), (TInt) aLength );
       
  1993 	OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_PINFRAGMENTSENDRECEIVE2, "Remote Thread=0x%08x; current Thread=0x%x; start of data to write=0x%08x", (TUint) aReq.RemoteThread(), (TUint) &Kern::CurrentThread(),(TUint)aLinAddress );
       
  1994 	
  1717 	// don't want this thread to be terminated until last fragment is sent to MD and mem can be free'd up
  1995 	// don't want this thread to be terminated until last fragment is sent to MD and mem can be free'd up
  1718 	NKern::ThreadEnterCS();			
  1996 	NKern::ThreadEnterCS();			
  1719 
  1997 
  1720 	__ASSERT_DEBUG(ThePinObjectAllocator, LOCM_FAULT());
  1998 	__ASSERT_DEBUG(ThePinObjectAllocator, LOCM_FAULT());
  1721 
  1999 
  1784 			// otherwise (dataLockResult > 0) release it after calling SendReceive()
  2062 			// otherwise (dataLockResult > 0) release it after calling SendReceive()
  1785 			if (dataLockResult <= 0)
  2063 			if (dataLockResult <= 0)
  1786 				ThePinObjectAllocator->PreAllocatedDataLock().UnlockFragmentation();
  2064 				ThePinObjectAllocator->PreAllocatedDataLock().UnlockFragmentation();
  1787 
  2065 
  1788 #ifdef __DEBUG_DEMAND_PAGING__
  2066 #ifdef __DEBUG_DEMAND_PAGING__
  1789 				if (dataLockResult < 0) 
  2067 				if (dataLockResult < 0)
  1790 					Kern::Printf("DFragmentationPagingLock::Lock() %d", dataLockResult);
  2068 					Kern::Printf("DFragmentationPagingLock::Lock() %d", dataLockResult);			
  1791 #endif
  2069 #endif
  1792 
  2070 
  1793 			if (dataLockResult < 0)	// if lock returned an error then give up
  2071 			if (dataLockResult < 0)	// if lock returned an error then give up
  1794 				{
  2072 				{
  1795 				r = dataLockResult;
  2073 				r = dataLockResult;
  1803 		fragment.RemoteDesOffset() = aReq.RemoteDesOffset() + pos;
  2081 		fragment.RemoteDesOffset() = aReq.RemoteDesOffset() + pos;
  1804 		fragment.Pos() = aReq.Pos() + pos;
  2082 		fragment.Pos() = aReq.Pos() + pos;
  1805 		fragment.Flags() = aReq.Flags();
  2083 		fragment.Flags() = aReq.Flags();
  1806 
  2084 
  1807 		__KTRACE_OPT2(KLOCDPAGING,KLOCDRV,Kern::Printf("Send fragment (0x%08x) type(%d), length(0x%x), offset within original req(0x%x), pos in media(0x%lx)",&fragment,fragment.Id(), pinnedLen, pos, fragment.Pos()));
  2085 		__KTRACE_OPT2(KLOCDPAGING,KLOCDRV,Kern::Printf("Send fragment (0x%08x) type(%d), length(0x%x), offset within original req(0x%x), pos in media(0x%lx)",&fragment,fragment.Id(), pinnedLen, pos, fragment.Pos()));
  1808 
  2086 		OstTraceDefExt5(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_PINFRAGMENTSENDRECEIVE3, "Send fragment 0x%08x; type=%d; length=0x%x; offset within original req=0x%x; position in media=0x%lx", (TUint) &fragment, (TInt) fragment.Id(), (TUint) pinnedLen, (TUint) pos, (TUint) fragment.Pos());
       
  2087 		
  1809 #ifdef BTRACE_PAGING_MEDIA
  2088 #ifdef BTRACE_PAGING_MEDIA
  1810 		TInt buf[4];
  2089 		TInt buf[4];
  1811 		buf[0] = pinnedLen;	// fragment length
  2090 		buf[0] = pinnedLen;	// fragment length
  1812 		buf[1] = pos;		// offset within original request
  2091 		buf[1] = pos;		// offset within original request
  1813 		buf[2] = fragment.Pos(); // offset in media
  2092 		buf[2] = fragment.Pos(); // offset in media
  1814 		buf[3] = (TInt)&pT->iNThread;	// thread that issued the original write req
  2093 		buf[3] = (TInt)&pT->iNThread;	// thread that issued the original write req
  1815 		BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedFragmentBegin,&fragment,fragment.Id(),buf,sizeof(buf));
  2094 		BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedFragmentBegin,&fragment,fragment.Id(),buf,sizeof(buf));
  1816 #endif
  2095 #endif
  1817 
       
  1818 		r = SendReceive(fragment, aLinAddress);	// only come back here when message (fragment) has been completed
  2096 		r = SendReceive(fragment, aLinAddress);	// only come back here when message (fragment) has been completed
  1819 
  2097 		
  1820 		// unpin memory
  2098 		// unpin memory
  1821 		if (pinDataObject)
  2099 		if (pinDataObject)
  1822 			{
  2100 			{
  1823 			Kern::UnpinVirtualMemory(pinDataObject->iObject);
  2101 			Kern::UnpinVirtualMemory(pinDataObject->iObject);
  1824 			ThePinObjectAllocator->ReleasePinObject(pinDataObject);
  2102 			ThePinObjectAllocator->ReleasePinObject(pinDataObject);
  1840 
  2118 
  1841 	NKern::ThreadLeaveCS();
  2119 	NKern::ThreadLeaveCS();
  1842 
  2120 
  1843 //	Kern::Printf("<PFSR %02X aReq %08X aLinAddress %08X aLen %08X offset %08X", aReq.Id(), &aReq, aLinAddress, aLength, aReq.RemoteDesOffset());
  2121 //	Kern::Printf("<PFSR %02X aReq %08X aLinAddress %08X aLen %08X offset %08X", aReq.Id(), &aReq, aLinAddress, aLength, aReq.RemoteDesOffset());
  1844 
  2122 
       
  2123 	OstTraceFunctionExitExt( DPRIMARYMEDIABASE_PINFRAGMENTSENDRECEIVE_EXIT, this, r );
  1845 	return r;
  2124 	return r;
  1846 	}
  2125 	}
  1847 
  2126 
  1848 #endif	// __DEMAND_PAGING__
  2127 #endif	// __DEMAND_PAGING__
  1849 
  2128 
  1858  * 
  2137  * 
  1859  * @see TLocDrvRequest::SendReceive()
  2138  * @see TLocDrvRequest::SendReceive()
  1860  * @see DDmaHelper::SendReceive()
  2139  * @see DDmaHelper::SendReceive()
  1861  */
  2140  */
  1862 	{
  2141 	{
       
  2142 	OstTraceExt2( TRACE_FLOW, DPRIMARYMEDIABASE_SENDRECEIVE_ENTRY, "> DPrimaryMediaBase::SendReceive;aReq=%x;aLinAddress=%x", (TUint) &aReq, (TUint) &aLinAddress );
       
  2143 	
  1863 	DDmaHelper* dmaHelper = aReq.Drive()->iDmaHelper;
  2144 	DDmaHelper* dmaHelper = aReq.Drive()->iDmaHelper;
  1864 
  2145 
  1865 #ifdef __DEMAND_PAGING__
  2146 #ifdef __DEMAND_PAGING__
  1866 	RequestCountInc();
  2147 	RequestCountInc();
  1867 #endif
  2148 #endif
  1869 	TInt r;
  2150 	TInt r;
  1870 
  2151 
  1871 	if (dmaHelper)
  2152 	if (dmaHelper)
  1872 		r = dmaHelper->SendReceive(aReq, aLinAddress);
  2153 		r = dmaHelper->SendReceive(aReq, aLinAddress);
  1873 	else
  2154 	else
       
  2155 	    { 
  1874 		r = aReq.SendReceive(&iMsgQ);
  2156 		r = aReq.SendReceive(&iMsgQ);
  1875 
  2157 	    }
  1876 #ifdef __DEMAND_PAGING__
  2158 #ifdef __DEMAND_PAGING__
  1877 	RequestCountDec();
  2159 	RequestCountDec();
  1878 #endif
  2160 #endif
  1879 
  2161 
       
  2162 	OstTraceFunctionExitExt( DPRIMARYMEDIABASE_SENDRECEIVE_EXIT, this, r );
  1880 	return r;
  2163 	return r;
  1881 	}
  2164 	}
  1882 
  2165 
  1883 
  2166 
  1884 
  2167 
  1958 
  2241 
  1959 @param aRequest Encapsulates the request information received from the client
  2242 @param aRequest Encapsulates the request information received from the client
  1960 @see TLocDrvRequest
  2243 @see TLocDrvRequest
  1961 */
  2244 */
  1962 	{
  2245 	{
       
  2246 	OstTrace1( TRACE_FLOW, DPRIMARYMEDIABASE_HANDLEMSG_ENTRY, "> DPrimaryMediaBase::HandleMsg;m=%x;", (TUint) &m);
       
  2247 	
  1963 	switch (m.iValue)
  2248 	switch (m.iValue)
  1964 		{
  2249 		{
  1965 		case EConnect:
  2250 		case EConnect:
  1966 			{
  2251 			{
  1967 			DLocalDrive* pD=(DLocalDrive*)m.Ptr0();
  2252 			DLocalDrive* pD=(DLocalDrive*)m.Ptr0();
  1968 			iConnectionQ.Add(&pD->iLink);
  2253 			iConnectionQ.Add(&pD->iLink);
  1969 			m.Complete(KErrNone, EFalse);
  2254 			m.Complete(KErrNone, EFalse);
       
  2255 			OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT1, this );
  1970 			return;
  2256 			return;
  1971 			}
  2257 			}
  1972 		case EDisconnect:
  2258 		case EDisconnect:
  1973 			{
  2259 			{
  1974 			DLocalDrive* pD=(DLocalDrive*)m.Ptr0();
  2260 			DLocalDrive* pD=(DLocalDrive*)m.Ptr0();
  1979 			else
  2265 			else
  1980 				{
  2266 				{
  1981 				pD->Deque();
  2267 				pD->Deque();
  1982 				m.Complete(KErrNone, EFalse);
  2268 				m.Complete(KErrNone, EFalse);
  1983 				}
  2269 				}
       
  2270 			OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT2, this );
  1984 			return;
  2271 			return;
  1985 			}
  2272 			}
  1986 		case DLocalDrive::EForceMediaChange:
  2273 		case DLocalDrive::EForceMediaChange:
  1987 			{
  2274 			{
  1988 			TUint flags = (TUint) m.Pos();
  2275 			TUint flags = (TUint) m.Pos();
  1994 				{
  2281 				{
  1995 				TInt sock;
  2282 				TInt sock;
  1996 				if (!IsRemovableDevice(sock))
  2283 				if (!IsRemovableDevice(sock))
  1997 					{
  2284 					{
  1998 					CompleteRequest(m, KErrNotSupported);
  2285 					CompleteRequest(m, KErrNotSupported);
       
  2286 					OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT3, this );
  1999 					return;
  2287 					return;
  2000 					}
  2288 					}
  2001 				// wait for power up and then call DPrimaryMediaBase::DoRequest()
  2289 				// wait for power up and then call DPrimaryMediaBase::DoRequest()
  2002 				break;
  2290 				break;
  2003 				}
  2291 				}
  2012 				{
  2300 				{
  2013 				if (r==KErrNotSupported || r==KErrCompletion)
  2301 				if (r==KErrNotSupported || r==KErrCompletion)
  2014 					r=KErrNone;
  2302 					r=KErrNone;
  2015 				CompleteRequest(m, r);
  2303 				CompleteRequest(m, r);
  2016 				}
  2304 				}
       
  2305 			OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT4, this );
  2017 			return;
  2306 			return;
  2018 			}
  2307 			}
  2019 		case DLocalDrive::ECaps:
  2308 		case DLocalDrive::ECaps:
  2020 			if (iState==EPoweredDown)
  2309 			if (iState==EPoweredDown)
  2021 				{
  2310 				{
  2022 				// The media is powered down, but the media driver still exists.
  2311 				// The media is powered down, but the media driver still exists.
  2023 				//  - Issue the ECaps request without powering the media back up.
  2312 				//  - Issue the ECaps request without powering the media back up.
  2024 				DoRequest(m);
  2313 				DoRequest(m);
  2025 				__TRACE_TIMING(0x101);
  2314 				__TRACE_TIMING(0x101);
       
  2315 				OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT5, this );
  2026 				return;
  2316 				return;
  2027 				}
  2317 				}
  2028 			break;
  2318 			break;
  2029 
  2319 
  2030 		case DLocalDrive::ERead:
  2320 		case DLocalDrive::ERead:
  2049 			{
  2339 			{
  2050 			DLocalDrive* pD=(DLocalDrive*)m.Ptr0();
  2340 			DLocalDrive* pD=(DLocalDrive*)m.Ptr0();
  2051 			TLocDrv* pL=pD->iDrive;
  2341 			TLocDrv* pL=pD->iDrive;
  2052 			*((TErrorInfo*) m.RemoteDes()) = pL->iLastErrorInfo;
  2342 			*((TErrorInfo*) m.RemoteDes()) = pL->iLastErrorInfo;
  2053 			CompleteRequest(m, KErrNone);
  2343 			CompleteRequest(m, KErrNone);
       
  2344 			OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT6, this );
  2054 			return;
  2345 			return;
  2055 			}
  2346 			}
  2056 		case DLocalDrive::EReadPasswordStore:
  2347 		case DLocalDrive::EReadPasswordStore:
  2057 			{
  2348 			{
  2058 			TPtr8 pswData ((TUint8*) m.RemoteDes(), (TInt) m.Length());
  2349 			TPtr8 pswData ((TUint8*) m.RemoteDes(), (TInt) m.Length());
  2059 			TInt r = ThePasswordStore->ReadPasswordData(pswData);
  2350 			TInt r = ThePasswordStore->ReadPasswordData(pswData);
  2060 			m.Length() = pswData.Length();
  2351 			m.Length() = pswData.Length();
  2061 			CompleteRequest(m, r);
  2352 			CompleteRequest(m, r);
       
  2353 			OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT7, this );
  2062 			return;
  2354 			return;
  2063 			}
  2355 			}
  2064 		case DLocalDrive::EWritePasswordStore:
  2356 		case DLocalDrive::EWritePasswordStore:
  2065 			{
  2357 			{
  2066 			TPtrC8 pData((TUint8*) m.RemoteDes(), (TInt) m.Length());
  2358 			TPtrC8 pData((TUint8*) m.RemoteDes(), (TInt) m.Length());
  2067 			TInt r = ThePasswordStore->WritePasswordData(pData);
  2359 			TInt r = ThePasswordStore->WritePasswordData(pData);
  2068 
  2360 
  2069 			if(r != KErrNone)
  2361 			if(r != KErrNone)
  2070 				{
  2362 				{
  2071 				CompleteRequest(m, r);
  2363 				CompleteRequest(m, r);
       
  2364 				OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT8, this );
  2072 				return;
  2365 				return;
  2073 				}
  2366 				}
  2074 
  2367 
  2075 			r = QuickCheckStatus();
  2368 			r = QuickCheckStatus();
  2076 			if(r != KErrNone)
  2369 			if(r != KErrNone)
  2077 				{
  2370 				{
  2078 				// Don't try to power up the device if it's not ready.
  2371 				// Don't try to power up the device if it's not ready.
  2079 				// - Note that this isn't an error that needs to be returned to the client.
  2372 				// - Note that this isn't an error that needs to be returned to the client.
  2080 				CompleteRequest(m, KErrNone);
  2373 				CompleteRequest(m, KErrNone);
       
  2374 				OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT9, this );
  2081 				return;
  2375 				return;
  2082 				}
  2376 				}
  2083 
  2377 
  2084 			break;
  2378 			break;
  2085 			}
  2379 			}
  2086 		case DLocalDrive::EPasswordStoreLengthInBytes:
  2380 		case DLocalDrive::EPasswordStoreLengthInBytes:
  2087 			{
  2381 			{
  2088 			TInt length = ThePasswordStore->PasswordStoreLengthInBytes();
  2382 			TInt length = ThePasswordStore->PasswordStoreLengthInBytes();
  2089 			*(TInt*) m.RemoteDes() = length;
  2383 			*(TInt*) m.RemoteDes() = length;
  2090 			CompleteRequest(m, KErrNone);
  2384 			CompleteRequest(m, KErrNone);
       
  2385 			OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT10, this );
  2091 			return;
  2386 			return;
  2092 			}
  2387 			}
  2093 		default:
  2388 		default:
  2094 			CHECK_RET(KErrNotSupported);
  2389 			CHECK_RET(KErrNotSupported);
  2095 			CompleteRequest(m, KErrNotSupported);
  2390 			CompleteRequest(m, KErrNotSupported);
       
  2391 			OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT11, this );
  2096 			return;
  2392 			return;
  2097 		}
  2393 		}
  2098 
  2394 
  2099 	__KTRACE_OPT(KFAIL,Kern::Printf("mdrq %d",m.Id()));
  2395 	__KTRACE_OPT(KFAIL,Kern::Printf("mdrq %d",m.Id()));
  2100 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::HandleMsg state %d req %d",iMediaId,iState,m.Id()));
  2396 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::HandleMsg state %d req %d",iMediaId,iState,m.Id()));
  2101 
  2397 
       
  2398 	OstTraceDefExt3( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DPRIMARYMEDIABASE_HANDLEMSG2, "iMediaId=%d; iState=%d; req Id=%d", iMediaId, iState, m.Id());
       
  2399 	
  2102 	// if media driver already open, pass request through
  2400 	// if media driver already open, pass request through
  2103 	if (iState==EReady)
  2401 	if (iState==EReady)
  2104 		{
  2402 		{
  2105 		DoRequest(m);
  2403 		DoRequest(m);
  2106 		__TRACE_TIMING(0x101);
  2404 		__TRACE_TIMING(0x101);
       
  2405 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT12, this );
  2107 		return;
  2406 		return;
  2108 		}
  2407 		}
  2109 
  2408 
  2110 	// if open or close in progress, defer this message
  2409 	// if open or close in progress, defer this message
  2111 	if (iState!=EClosed && iState!=EPoweredDown)
  2410 	if (iState!=EClosed && iState!=EPoweredDown)
  2116 			__ASSERT_ALWAYS(iPagingMedia,LOCM_FAULT());
  2415 			__ASSERT_ALWAYS(iPagingMedia,LOCM_FAULT());
  2117 			__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT());
  2416 			__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT());
  2118 			__ASSERT_ALWAYS( ((m.Flags() & TLocDrvRequest::ECodePaging) == 0) || (m.Drive()->iPagingDrv), LOCM_FAULT());
  2417 			__ASSERT_ALWAYS( ((m.Flags() & TLocDrvRequest::ECodePaging) == 0) || (m.Drive()->iPagingDrv), LOCM_FAULT());
  2119 
  2418 
  2120 			__KTRACE_OPT2(KLOCDPAGING,KLOCDRV,Kern::Printf("Deferring PageIn request 0x%08x because opening or closing",&m));
  2419 			__KTRACE_OPT2(KLOCDPAGING,KLOCDRV,Kern::Printf("Deferring PageIn request 0x%08x because opening or closing",&m));
       
  2420 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_HANDLEMSG3, "Deferring PageIn request 0x%08x because opening or closing", &m);
  2121 			iBody->iPagingDevice->SendToDeferredQ(&m);
  2421 			iBody->iPagingDevice->SendToDeferredQ(&m);
  2122 			}
  2422 			}
  2123 		else
  2423 		else
  2124 #endif
  2424 #endif
  2125 		m.Forward(&iDeferred,EFalse);
  2425 		m.Forward(&iDeferred,EFalse);
       
  2426 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT13, this );
  2126 		return;
  2427 		return;
  2127 		}
  2428 		}
  2128 
  2429 
  2129 	// nothing is open, so try to open something
  2430 	// nothing is open, so try to open something
  2130 	__ASSERT_ALWAYS(!iCurrentReq,LOCM_FAULT());
  2431 	__ASSERT_ALWAYS(!iCurrentReq,LOCM_FAULT());
  2142 	if (DMediaPagingDevice::PagingRequest(m))
  2443 	if (DMediaPagingDevice::PagingRequest(m))
  2143 		{
  2444 		{
  2144 		__ASSERT_DEBUG(iPagingMedia,LOCM_FAULT());
  2445 		__ASSERT_DEBUG(iPagingMedia,LOCM_FAULT());
  2145 		__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT());
  2446 		__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT());
  2146 		__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Page request 0x%08x received -> opening MD",&m));
  2447 		__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Page request 0x%08x received -> opening MD",&m));
       
  2448 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_HANDLEMSG4, "Page request 0x%08x received; opening MD", &m);
  2147 		}
  2449 		}
  2148 #endif	// _DEBUG
  2450 #endif	// _DEBUG
  2149 
  2451 
  2150 #endif	// __DEMAND_PAGING__
  2452 #endif	// __DEMAND_PAGING__
  2151 
  2453 
  2161 
  2463 
  2162 	TInt r=InitiatePowerUp();
  2464 	TInt r=InitiatePowerUp();
  2163 	if (r==KErrNone || r==KErrServerBusy)
  2465 	if (r==KErrNone || r==KErrServerBusy)
  2164 		{
  2466 		{
  2165 		// wait for completion of power up request
  2467 		// wait for completion of power up request
       
  2468 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT14, this );
  2166 		return;
  2469 		return;
  2167 		}
  2470 		}
  2168 	if (r==KErrCompletion)
  2471 	if (r==KErrCompletion)
  2169 		r=KErrNone;		// device already powered up
  2472 		r=KErrNone;		// device already powered up
  2170 	PowerUpComplete(r);
  2473 	PowerUpComplete(r);
       
  2474 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_HANDLEMSG_EXIT15, this );
  2171 	}
  2475 	}
  2172 
  2476 
  2173 EXPORT_C TInt DPrimaryMediaBase::DoRequest(TLocDrvRequest& m)
  2477 EXPORT_C TInt DPrimaryMediaBase::DoRequest(TLocDrvRequest& m)
  2174 /**
  2478 /**
  2175 If the media exists, it tries to get the partition information if not there. 
  2479 If the media exists, it tries to get the partition information if not there. 
  2186 	KErrBadDescriptor, if request encapsulates a bad descriptor
  2490 	KErrBadDescriptor, if request encapsulates a bad descriptor
  2187 	Otherwise, one of the other system wide error codes.
  2491 	Otherwise, one of the other system wide error codes.
  2188 
  2492 
  2189 */
  2493 */
  2190 	{
  2494 	{
       
  2495 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_DOREQUEST_ENTRY, this );
  2191 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DPrimaryMediaBase::DoRequest %d",m.Id()));
  2496 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DPrimaryMediaBase::DoRequest %d",m.Id()));
  2192 	TLocDrv* pL=m.Drive();
  2497 	TLocDrv* pL=m.Drive();
  2193 	DMedia* media=pL->iMedia;
  2498 	DMedia* media=pL->iMedia;
  2194 	TInt r=KErrNone;
  2499 	TInt r=KErrNone;
  2195 
  2500 	
       
  2501 	OstTraceDefExt3( OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DPRIMARYMEDIABASE_DOREQUEST, "req Id=%d; length=0x%x; position=0x%x", (TInt) m.Id(), (TInt) m.Length(), (TInt) m.Pos());
       
  2502 	
  2196 	// re-open this drive's media driver ?
  2503 	// re-open this drive's media driver ?
  2197 	if (m.iValue == DLocalDrive::EForceMediaChange)
  2504 	if (m.iValue == DLocalDrive::EForceMediaChange)
  2198 		{
  2505 		{
  2199 		__ASSERT_DEBUG(((TUint) m.Pos()) == (TUint) KForceMediaChangeReOpenMediaDriver, LOCM_FAULT());
  2506 		__ASSERT_DEBUG(((TUint) m.Pos()) == (TUint) KForceMediaChangeReOpenMediaDriver, LOCM_FAULT());
  2200 
  2507 
  2208 		iState=EOpening;
  2515 		iState=EOpening;
  2209 		StartOpenMediaDrivers();
  2516 		StartOpenMediaDrivers();
  2210 
  2517 
  2211 		NotifyClients(ETrue,pL);
  2518 		NotifyClients(ETrue,pL);
  2212 		CompleteRequest(m, r);
  2519 		CompleteRequest(m, r);
       
  2520 		OstTraceFunctionExitExt( DPRIMARYMEDIABASE_DOREQUEST_EXIT, this, r );
  2213 		return r;
  2521 		return r;
  2214 		}
  2522 		}
  2215 
  2523 
  2216 	if (!media || !media->iDriver || iState == EClosed)
  2524 	if (!media || !media->iDriver || iState == EClosed)
  2217 		{
  2525 		{
  2226 	if (r==KErrNone)
  2534 	if (r==KErrNone)
  2227 		{
  2535 		{
  2228 		if(iTotalPartitionsOpened == 0)
  2536 		if(iTotalPartitionsOpened == 0)
  2229 			{
  2537 			{
  2230 			UpdatePartitionInfo();
  2538 			UpdatePartitionInfo();
       
  2539 			OstTraceFunctionExitExt( DPRIMARYMEDIABASE_DOREQUEST_EXIT2, this, KErrNone );
  2231 			return KErrNone;
  2540 			return KErrNone;
  2232 			}
  2541 			}
  2233 		if (!(m.Flags() & TLocDrvRequest::EAdjusted))
  2542 		if (!(m.Flags() & TLocDrvRequest::EAdjusted))
  2234 			{
  2543 			{
  2235 			// If this isn't the only partition, don't allow access to the whole media 
  2544 			// If this isn't the only partition, don't allow access to the whole media 
  2237 				m.DriverFlags() &= ~RLocalDrive::ELocDrvWholeMedia;
  2546 				m.DriverFlags() &= ~RLocalDrive::ELocDrvWholeMedia;
  2238 			r=m.CheckAndAdjustForPartition();
  2547 			r=m.CheckAndAdjustForPartition();
  2239 			}
  2548 			}
  2240 		if (r==KErrNone)
  2549 		if (r==KErrNone)
  2241 			{
  2550 			{
       
  2551 			OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_INTERNALS, DPRIMARYMEDIABASE_DOREQUEST_START, "req Id=%d; Remote Thread=0x%x", (TInt) m.Id(), (TUint) m.RemoteThread());
  2242 			r=media->iDriver->Request(m);
  2552 			r=media->iDriver->Request(m);
  2243 			if (r>0)
  2553 			if (r>0)
  2244 				{
  2554 				{
  2245 				// defer request
  2555 				// defer request
  2246 #ifdef __DEMAND_PAGING__
  2556 #ifdef __DEMAND_PAGING__
  2248 					{
  2558 					{
  2249 					__ASSERT_ALWAYS(iPagingMedia,LOCM_FAULT());
  2559 					__ASSERT_ALWAYS(iPagingMedia,LOCM_FAULT());
  2250 					__ASSERT_ALWAYS( ((m.Flags() & TLocDrvRequest::ECodePaging) == 0) || (m.Drive()->iPagingDrv), LOCM_FAULT());
  2560 					__ASSERT_ALWAYS( ((m.Flags() & TLocDrvRequest::ECodePaging) == 0) || (m.Drive()->iPagingDrv), LOCM_FAULT());
  2251 					__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT());
  2561 					__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT());
  2252 					__KTRACE_OPT2(KLOCDPAGING,KLOCDRV,Kern::Printf("Defer PageIn request 0x%08x",&m));
  2562 					__KTRACE_OPT2(KLOCDPAGING,KLOCDRV,Kern::Printf("Defer PageIn request 0x%08x",&m));
       
  2563 					OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_DOREQUEST2, "Defer PageIn request 0x%08x", &m);
  2253 					DMediaPagingDevice* pagingdevice=iBody->iPagingDevice; 
  2564 					DMediaPagingDevice* pagingdevice=iBody->iPagingDevice; 
  2254 
  2565 
  2255 #ifdef __CONCURRENT_PAGING_INSTRUMENTATION__
  2566 #ifdef __CONCURRENT_PAGING_INSTRUMENTATION__
  2256 					TInt id=m.iValue;
  2567 					TInt id=m.iValue;
  2257 					if (id==DMediaPagingDevice::ERomPageInRequest)
  2568 					if (id==DMediaPagingDevice::ERomPageInRequest)
  2289 					m.Forward(&iDeferred,EFalse);
  2600 					m.Forward(&iDeferred,EFalse);
  2290 				r=KErrNone;
  2601 				r=KErrNone;
  2291 				}
  2602 				}
  2292 #if defined(__DEMAND_PAGING__) && defined(_DEBUG)
  2603 #if defined(__DEMAND_PAGING__) && defined(_DEBUG)
  2293 			else if (r == KErrNone && DMediaPagingDevice::PagingRequest(m))
  2604 			else if (r == KErrNone && DMediaPagingDevice::PagingRequest(m))
       
  2605 			    {
  2294 				__KTRACE_OPT(KLOCDPAGING,Kern::Printf("PageIn req 0x%08x completing asynchronously",&m));
  2606 				__KTRACE_OPT(KLOCDPAGING,Kern::Printf("PageIn req 0x%08x completing asynchronously",&m));
       
  2607                 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_DOREQUEST3, "PageIn req 0x%08x completing asynchronously", &m);
       
  2608 			    }
  2295 #endif
  2609 #endif
  2296 			}
  2610 			}
  2297 		}
  2611 		}
  2298 
  2612 
  2299 	if (r!=KErrNone && iCurrentReq)
  2613 	if (r!=KErrNone && iCurrentReq)
  2307 			{
  2621 			{
  2308 			__ASSERT_ALWAYS(iPagingMedia,LOCM_FAULT());
  2622 			__ASSERT_ALWAYS(iPagingMedia,LOCM_FAULT());
  2309 			__ASSERT_ALWAYS( ((m.Flags() & TLocDrvRequest::ECodePaging) == 0) || (m.Drive()->iPagingDrv), LOCM_FAULT());
  2623 			__ASSERT_ALWAYS( ((m.Flags() & TLocDrvRequest::ECodePaging) == 0) || (m.Drive()->iPagingDrv), LOCM_FAULT());
  2310 			__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT());
  2624 			__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT());
  2311 			__KTRACE_OPT(KLOCDPAGING,Kern::Printf("media driver cannot service or defer PageIn request 0x%08x or serviced it synchronously (%d)",&m, s));
  2625 			__KTRACE_OPT(KLOCDPAGING,Kern::Printf("media driver cannot service or defer PageIn request 0x%08x or serviced it synchronously (%d)",&m, s));
       
  2626 			OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_DOREQUEST4, "Media driver cannot service or defer PageIn request 0x%08x or serviced it synchronously; retval=%d",(TUint) &m, s);
  2312 			iBody->iPagingDevice->CompleteRequest(&m, s);
  2627 			iBody->iPagingDevice->CompleteRequest(&m, s);
  2313 			}
  2628 			}
  2314 		else
  2629 		else
  2315 #endif
  2630 #endif
  2316 
  2631 
  2317 		CompleteRequest(m, s);
  2632 		CompleteRequest(m, s);
  2318 
  2633 		OstTraceDefExt3( OST_TRACE_CATEGORY_RND, TRACE_INTERNALS, DPRIMARYMEDIABASE_DOREQUEST_RETURN, "Return req Id=%d; Remote Thread=0x%x; retval=%d", (TInt) m.Id(), (TUint) m.RemoteThread(), (TInt) s);
  2319 		}
  2634 		}
  2320 
  2635 
  2321 	iCurrentReq=NULL;
  2636 	iCurrentReq=NULL;
       
  2637 	OstTraceFunctionExitExt( DPRIMARYMEDIABASE_DOREQUEST_EXIT3, this, r );
  2322 	return r;
  2638 	return r;
  2323 	}
  2639 	}
  2324 
  2640 
  2325 EXPORT_C void DPrimaryMediaBase::PowerUpComplete(TInt anError)
  2641 EXPORT_C void DPrimaryMediaBase::PowerUpComplete(TInt anError)
  2326 /**
  2642 /**
  2331 and if they are already open then it handles the current/pending requests.
  2647 and if they are already open then it handles the current/pending requests.
  2332 
  2648 
  2333 @param anError Error code to be passed on while completing outstanding requests.
  2649 @param anError Error code to be passed on while completing outstanding requests.
  2334 */
  2650 */
  2335 	{
  2651 	{
       
  2652 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_POWERUPCOMPLETE_ENTRY, this );
  2336 	__KTRACE_OPT(KLOCDRV,Kern::Printf(">DPrimaryMediaBase(%d)::PowerUpComplete err %d iState %d",iMediaId,anError,iState));
  2653 	__KTRACE_OPT(KLOCDRV,Kern::Printf(">DPrimaryMediaBase(%d)::PowerUpComplete err %d iState %d",iMediaId,anError,iState));
       
  2654 	
       
  2655 	OstTraceExt3( TRACE_INTERNALS, DPRIMARYMEDIABASE_POWERUPCOMPLETE, "iMediaId=%d; anError=%d; iState=%d", iMediaId, anError, iState );
       
  2656 	
  2337 	if (anError!=KErrNone)
  2657 	if (anError!=KErrNone)
  2338 		{
  2658 		{
  2339 		// error powering up device
  2659 		// error powering up device
  2340 		if (iState==EPoweringUp1 || iState==EPoweringUp2)
  2660 		if (iState==EPoweringUp1 || iState==EPoweringUp2)
  2341 			SetClosed(anError);
  2661 			SetClosed(anError);
       
  2662 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_POWERUPCOMPLETE_EXIT, this );
  2342 		return;
  2663 		return;
  2343 		}
  2664 		}
  2344 
  2665 
  2345 	// Powered up OK - now open media drivers
  2666 	// Powered up OK - now open media drivers
  2346 	if (iState==EPoweringUp1)
  2667 	if (iState==EPoweringUp1)
  2351 	else if (iState==EPoweringUp2)
  2672 	else if (iState==EPoweringUp2)
  2352 		{
  2673 		{
  2353 		// media is powered up and ready, so handle the current/pending requests
  2674 		// media is powered up and ready, so handle the current/pending requests
  2354 		MediaReadyHandleRequest();
  2675 		MediaReadyHandleRequest();
  2355 		}
  2676 		}
       
  2677 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_POWERUPCOMPLETE_EXIT2, this );
  2356 	}
  2678 	}
  2357 
  2679 
  2358 void DPrimaryMediaBase::CloseMediaDrivers(DMedia* aMedia)
  2680 void DPrimaryMediaBase::CloseMediaDrivers(DMedia* aMedia)
  2359 	{
  2681 	{
       
  2682 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_CLOSEMEDIADRIVERS_ENTRY, this );
  2360 	__KTRACE_OPT(KLOCDRV,Kern::Printf(">DPrimaryMediaBase(%d)::CloseMediaDrivers",iMediaId));
  2683 	__KTRACE_OPT(KLOCDRV,Kern::Printf(">DPrimaryMediaBase(%d)::CloseMediaDrivers",iMediaId));
  2361 
  2684 	OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_MEDIACHANGE, DPRIMARYMEDIABASE_CLOSEMEDIADRIVERS1, "DPrimaryMediaBase iMediaId=%d", iMediaId );
       
  2685 	
  2362 	// we mustn't ever close the media driver if it's responsible for data paging as re-opening the drive
  2686 	// we mustn't ever close the media driver if it's responsible for data paging as re-opening the drive
  2363 	// would involve memory allocation which might cause deadlock if the kernel heap were to grow
  2687 	// would involve memory allocation which might cause deadlock if the kernel heap were to grow
  2364 #ifdef __DEMAND_PAGING__
  2688 #ifdef __DEMAND_PAGING__
  2365 	if (DataPagingDfcQ(this))
  2689 	if (DataPagingDfcQ(this))
  2366 		{
  2690 		{
  2367 		__KTRACE_OPT(KLOCDRV,Kern::Printf("CloseMediaDrivers aborting for data paging media %08X", this));
  2691 		__KTRACE_OPT(KLOCDRV,Kern::Printf("CloseMediaDrivers aborting for data paging media %08X", this));
       
  2692 		OstTrace1(TRACE_FLOW, DPRIMARYMEDIABASE_CLOSEMEDIADRIVERS_EXIT1, "CloseMediaDrivers aborting for data paging media 0x%08x", this);
  2368 		return;
  2693 		return;
  2369 		}
  2694 		}
  2370 #endif
  2695 #endif
  2371 
  2696 
  2372 	TInt i;
  2697 	TInt i;
  2374 		{
  2699 		{
  2375 		TLocDrv* pL=TheDrives[i];
  2700 		TLocDrv* pL=TheDrives[i];
  2376 		if (pL && pL->iPrimaryMedia==this)
  2701 		if (pL && pL->iPrimaryMedia==this)
  2377 			{
  2702 			{
  2378 			__KTRACE_OPT(KLOCDRV,Kern::Printf("Drive %d",i));
  2703 			__KTRACE_OPT(KLOCDRV,Kern::Printf("Drive %d",i));
       
  2704 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_MEDIACHANGE, DPRIMARYMEDIABASE_CLOSEMEDIADRIVERS2, "Drive=%d", i );
  2379 			if (aMedia == NULL || pL->iMedia == aMedia)
  2705 			if (aMedia == NULL || pL->iMedia == aMedia)
  2380 				{
  2706 				{
  2381 				pL->iMedia=NULL;
  2707 				pL->iMedia=NULL;
  2382 				}
  2708 				}
  2383 			}
  2709 			}
  2388 		if (aMedia == NULL || pM == aMedia)
  2714 		if (aMedia == NULL || pM == aMedia)
  2389 			{
  2715 			{
  2390 			DMediaDriver* pD=pM->iDriver;
  2716 			DMediaDriver* pD=pM->iDriver;
  2391 			pM->iDriver=NULL;
  2717 			pM->iDriver=NULL;
  2392 			__KTRACE_OPT(KLOCDRV,Kern::Printf("DMedia[%d] @ %08x Driver @ %08x",i,pM,pD));
  2718 			__KTRACE_OPT(KLOCDRV,Kern::Printf("DMedia[%d] @ %08x Driver @ %08x",i,pM,pD));
       
  2719 			OstTraceDefExt3( OST_TRACE_CATEGORY_RND, TRACE_MEDIACHANGE, DPRIMARYMEDIABASE_CLOSEMEDIADRIVERS3, "MediaId=%d; DMedia=0x%08x; MediaDriver=0x%08x", (TInt) i, (TUint) pM, (TUint) pD );
  2393 			if (pD)
  2720 			if (pD)
  2394 				pD->Close();
  2721 				pD->Close();
  2395 			}
  2722 			}
  2396 		}
  2723 		}
  2397 	__KTRACE_OPT(KLOCDRV,Kern::Printf("<DPrimaryMediaBase(%d)::CloseMediaDrivers",iMediaId));
  2724 	__KTRACE_OPT(KLOCDRV,Kern::Printf("<DPrimaryMediaBase(%d)::CloseMediaDrivers",iMediaId));
       
  2725 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_CLOSEMEDIADRIVERS_EXIT2, this );
  2398 	}
  2726 	}
  2399 
  2727 
  2400 void DPrimaryMediaBase::StartOpenMediaDrivers()
  2728 void DPrimaryMediaBase::StartOpenMediaDrivers()
  2401 	{
  2729 	{
       
  2730 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_STARTOPENMEDIADRIVERS_ENTRY, this );
  2402 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::StartOpenMediaDrivers",iMediaId));
  2731 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::StartOpenMediaDrivers",iMediaId));
       
  2732 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_MEDIACHANGE, DPRIMARYMEDIABASE_STARTOPENMEDIADRIVERS, "DPrimaryMediaBase iMediaId=%d ",iMediaId);
  2403 	TVersion ver(KMediaDriverInterfaceMajorVersion,KMediaDriverInterfaceMinorVersion,KMediaDriverInterfaceBuildVersion);
  2733 	TVersion ver(KMediaDriverInterfaceMajorVersion,KMediaDriverInterfaceMinorVersion,KMediaDriverInterfaceBuildVersion);
  2404 
  2734 
  2405 	// Get a list of all currently loaded media drivers
  2735 	// Get a list of all currently loaded media drivers
  2406 	// Most media drivers do not make use of the pointer iMountInfo.iInfo when 
  2736 	// Most media drivers do not make use of the pointer iMountInfo.iInfo when 
  2407 	// their Validate() procedures are called from RPhysicalDeviceArray::GetDriverList(). 
  2737 	// their Validate() procedures are called from RPhysicalDeviceArray::GetDriverList(). 
  2412 	TInt r=iPhysDevArray.GetDriverList(KLitMediaDriverName,iDevice,iMountInfo.iInfo,ver);
  2742 	TInt r=iPhysDevArray.GetDriverList(KLitMediaDriverName,iDevice,iMountInfo.iInfo,ver);
  2413 	if (r!=KErrNone)
  2743 	if (r!=KErrNone)
  2414 		{
  2744 		{
  2415 		// out of memory or no driver exists
  2745 		// out of memory or no driver exists
  2416 		SetClosed(r);
  2746 		SetClosed(r);
       
  2747 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_STARTOPENMEDIADRIVERS_EXIT1, this );
  2417 		return;
  2748 		return;
  2418 		}
  2749 		}
  2419 
  2750 
  2420 	// Go through them starting with highest priority
  2751 	// Go through them starting with highest priority
  2421 	iNextMediaId=iMediaId;
  2752 	iNextMediaId=iMediaId;
  2422 	iBody->iPhysDevIndex=iPhysDevArray.Count()-1;
  2753 	iBody->iPhysDevIndex=iPhysDevArray.Count()-1;
  2423 	iTotalPartitionsOpened=0;
  2754 	iTotalPartitionsOpened=0;
  2424 	iMediaDriversOpened=0;
  2755 	iMediaDriversOpened=0;
  2425 	iNextMediaDriver=NULL;
  2756 	iNextMediaDriver=NULL;
  2426 	OpenNextMediaDriver();
  2757 	OpenNextMediaDriver();
       
  2758 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_STARTOPENMEDIADRIVERS_EXIT2, this );
  2427 	}
  2759 	}
  2428 
  2760 
  2429 void DPrimaryMediaBase::OpenNextMediaDriver()
  2761 void DPrimaryMediaBase::OpenNextMediaDriver()
  2430 	{
  2762 	{
       
  2763 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_OPENNEXTMEDIADRIVER_ENTRY, this );
  2431 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::OpenNextMediaDriver, this %x mediaId %d iBody->iPhysDevIndex %d",iNextMediaId, this, iMediaId, iBody->iPhysDevIndex));
  2764 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::OpenNextMediaDriver, this %x mediaId %d iBody->iPhysDevIndex %d",iNextMediaId, this, iMediaId, iBody->iPhysDevIndex));
  2432 
  2765 	OstTraceDefExt4(OST_TRACE_CATEGORY_RND, TRACE_MEDIACHANGE, DPRIMARYMEDIABASE_OPENNEXTMEDIADRIVER, "DPrimaryMediaBase iNextMediaId=%d; this=%x; imediaId=%d; iBody->iPhysDevIndex=%d",iNextMediaId, (TUint) this, iMediaId, iBody->iPhysDevIndex);
       
  2766 	
  2433 	TVersion ver(KMediaDriverInterfaceMajorVersion,KMediaDriverInterfaceMinorVersion,KMediaDriverInterfaceBuildVersion);
  2767 	TVersion ver(KMediaDriverInterfaceMajorVersion,KMediaDriverInterfaceMinorVersion,KMediaDriverInterfaceBuildVersion);
  2434 	SPhysicalDeviceEntry& e=iPhysDevArray[iBody->iPhysDevIndex];
  2768 	SPhysicalDeviceEntry& e=iPhysDevArray[iBody->iPhysDevIndex];
  2435 	DPhysicalDevice* pD=e.iPhysicalDevice;
  2769 	DPhysicalDevice* pD=e.iPhysicalDevice;
  2436 
  2770 
  2437 	iState = EOpening;
  2771 	iState = EOpening;
  2439 	DMedia* pM=TheMedia[iNextMediaId];
  2773 	DMedia* pM=TheMedia[iNextMediaId];
  2440 	if (pM && pM->iDriver != NULL)
  2774 	if (pM && pM->iDriver != NULL)
  2441 		{
  2775 		{
  2442 		iNextMediaDriver = pM->iDriver;
  2776 		iNextMediaDriver = pM->iDriver;
  2443 		DoOpenMediaDriverComplete(KErrNone);
  2777 		DoOpenMediaDriverComplete(KErrNone);
       
  2778 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_OPENNEXTMEDIADRIVER_EXIT1, this );
  2444 		return;
  2779 		return;
  2445 		}
  2780 		}
  2446 
  2781 
  2447 	// this may be asynchronous
  2782 	// this may be asynchronous
  2448 	TInt s=pD->Create( (DBase*&)iNextMediaDriver, iMediaId,  (TDesC8*) &iMountInfo, ver);
  2783 	TInt s=pD->Create( (DBase*&)iNextMediaDriver, iMediaId,  (TDesC8*) &iMountInfo, ver);
  2449 
  2784 	
  2450 	__KTRACE_OPT(KLOCDRV,Kern::Printf("Media:Open-Opening %o(PRI:%d)-%d",pD,e.iPriority,s));
  2785 	__KTRACE_OPT(KLOCDRV,Kern::Printf("Media:Open-Opening %o(PRI:%d)-%d",pD,e.iPriority,s));
  2451 	if (s!=KErrNone)
  2786 	if (s!=KErrNone)
  2452 		{
  2787 		{
  2453 		iAsyncErrorCode=s;
  2788 		iAsyncErrorCode=s;
  2454 		iAsyncDfc.Enque();
  2789 		iAsyncDfc.Enque();
  2455 		}
  2790 		}
       
  2791 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_OPENNEXTMEDIADRIVER_EXIT2, this );
  2456 	}
  2792 	}
  2457 
  2793 
  2458 // Called when a media driver has responded to the Open request
  2794 // Called when a media driver has responded to the Open request
  2459 void DPrimaryMediaBase::DoOpenMediaDriverComplete(TInt anError)
  2795 void DPrimaryMediaBase::DoOpenMediaDriverComplete(TInt anError)
  2460 	{
  2796 	{
       
  2797 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_DOOPENMEDIADRIVERCOMPLETE_ENTRY, this );
  2461 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::DoOpenMediaDriverComplete error %d iNextMediaDriver %x",iNextMediaId,anError,iNextMediaDriver));
  2798 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::DoOpenMediaDriverComplete error %d iNextMediaDriver %x",iNextMediaId,anError,iNextMediaDriver));
  2462 
  2799     OstTraceDefExt3( OST_TRACE_CATEGORY_RND, TRACE_MEDIACHANGE, DPRIMARYMEDIABASE_DOOPENMEDIADRIVERCOMPLETE, "iMediaId=%d; anError=%d; iNextMediaDriver=0x%x", (TInt) iNextMediaId, (TInt) anError, (TUint) iNextMediaDriver);
       
  2800 
       
  2801 	
  2463 	if (anError!=KErrNone)
  2802 	if (anError!=KErrNone)
  2464 		{
  2803 		{
  2465 		DMediaDriver* md = iNextMediaDriver;
  2804 		DMediaDriver* md = iNextMediaDriver;
  2466 		iNextMediaDriver = NULL;
  2805 		iNextMediaDriver = NULL;
  2467 		if (md)
  2806 		if (md)
  2470 	if (anError==KErrNotReady || anError==KErrNoMemory)
  2809 	if (anError==KErrNotReady || anError==KErrNoMemory)
  2471 		{
  2810 		{
  2472 		// if it's not ready or we're out of memory, abort
  2811 		// if it's not ready or we're out of memory, abort
  2473 		CloseMediaDrivers();
  2812 		CloseMediaDrivers();
  2474 		SetClosed(anError);
  2813 		SetClosed(anError);
       
  2814 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_DOOPENMEDIADRIVERCOMPLETE_EXIT1, this );
  2475 		return;
  2815 		return;
  2476 		}
  2816 		}
  2477 	if (anError==KErrNone)
  2817 	if (anError==KErrNone)
  2478 		{
  2818 		{
  2479 		DMedia* pM=TheMedia[iNextMediaId];
  2819 		DMedia* pM=TheMedia[iNextMediaId];
  2482 		iNextMediaDriver->iPhysicalDevice=pD;
  2822 		iNextMediaDriver->iPhysicalDevice=pD;
  2483 		pD=NULL;	// so it won't be closed when we tidy up
  2823 		pD=NULL;	// so it won't be closed when we tidy up
  2484 		++iMediaDriversOpened;
  2824 		++iMediaDriversOpened;
  2485 		}
  2825 		}
  2486 
  2826 
       
  2827 	
  2487 	// if no error, read partition info on media
  2828 	// if no error, read partition info on media
  2488 	iState = EReadPartitionInfo;
  2829 	iState = EReadPartitionInfo;
  2489 
  2830 
  2490 	if (anError == KErrNone)
  2831 	if (anError == KErrNone)
  2491 		{
  2832 		{
  2500 		}
  2841 		}
  2501 	else
  2842 	else
  2502 		{
  2843 		{
  2503 		DoPartitionInfoComplete(anError);
  2844 		DoPartitionInfoComplete(anError);
  2504 		}
  2845 		}
       
  2846 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_DOOPENMEDIADRIVERCOMPLETE_EXIT2, this );
  2505 	}
  2847 	}
  2506 
  2848 
  2507 void DPrimaryMediaBase::DoPartitionInfoComplete(TInt anError)
  2849 void DPrimaryMediaBase::DoPartitionInfoComplete(TInt anError)
  2508 	{
  2850 	{
       
  2851 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_DOPARTITIONINFOCOMPLETE_ENTRY, this );
  2509 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::DoPartitionInfoComplete error %d",iNextMediaId,anError));
  2852 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::DoPartitionInfoComplete error %d",iNextMediaId,anError));
  2510 
  2853 
       
  2854 	OstTraceExt2( TRACE_INTERNALS, DPRIMARYMEDIABASE_DOPARTITIONINFOCOMPLETE1, "iNextMediaId=%d; anError=%d", iNextMediaId, anError );
       
  2855 	
  2511 	DMedia* pM=TheMedia[iNextMediaId];
  2856 	DMedia* pM=TheMedia[iNextMediaId];
  2512 	if (anError==KErrNone || anError == KErrLocked)
  2857 	if (anError==KErrNone || anError == KErrLocked)
  2513 		{
  2858 		{
  2514 		// successfully read partition info
  2859 		// successfully read partition info
  2515 		iTotalPartitionsOpened+=pM->PartitionCount();
  2860 		iTotalPartitionsOpened+=pM->PartitionCount();
  2521 			{
  2866 			{
  2522 #ifdef __DEMAND_PAGING__
  2867 #ifdef __DEMAND_PAGING__
  2523 			if (DataPagingDfcQ(this))
  2868 			if (DataPagingDfcQ(this))
  2524 				{
  2869 				{
  2525 				__KTRACE_OPT(KLOCDRV,Kern::Printf("DoPartitionInfoComplete(%d) Close Media Driver aborted for data paging media %08X", this));
  2870 				__KTRACE_OPT(KLOCDRV,Kern::Printf("DoPartitionInfoComplete(%d) Close Media Driver aborted for data paging media %08X", this));
       
  2871 				OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_DOPARTITIONINFOCOMPLETE2, "Close Media Driver for data paging media 0x%08x", this);
  2526 				}
  2872 				}
  2527 			else
  2873 			else
  2528 #endif
  2874 #endif
  2529 				{
  2875 				{
  2530 				pM->iDriver->Close();
  2876 				pM->iDriver->Close();
  2534 		if (anError==KErrNotReady || anError==KErrNoMemory)
  2880 		if (anError==KErrNotReady || anError==KErrNoMemory)
  2535 			{
  2881 			{
  2536 			// if it's not ready or we're out of memory, or the drive is locked, abort
  2882 			// if it's not ready or we're out of memory, or the drive is locked, abort
  2537 			CloseMediaDrivers();
  2883 			CloseMediaDrivers();
  2538 			SetClosed(anError);
  2884 			SetClosed(anError);
       
  2885 			OstTraceFunctionExit1( DPRIMARYMEDIABASE_DOPARTITIONINFOCOMPLETE_EXIT, this );
  2539 			return;
  2886 			return;
  2540 			}
  2887 			}
  2541 		}
  2888 		}
  2542 
  2889 
  2543 	// Open next media driver, if there is one
  2890 	// Open next media driver, if there is one
  2549 	else
  2896 	else
  2550 		iBody->iPhysDevIndex--;
  2897 		iBody->iPhysDevIndex--;
  2551 	if (!complete)
  2898 	if (!complete)
  2552 		{
  2899 		{
  2553 		OpenNextMediaDriver();
  2900 		OpenNextMediaDriver();
       
  2901 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_DOPARTITIONINFOCOMPLETE_EXIT2, this );
  2554 		return;
  2902 		return;
  2555 		}
  2903 		}
  2556 
  2904 
  2557 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase %d All media drivers open & partitions read",iMediaId));
  2905 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase %d All media drivers open & partitions read",iMediaId));
  2558 	__KTRACE_OPT(KLOCDRV,Kern::Printf("%d media drivers opened",iMediaDriversOpened));
  2906 	__KTRACE_OPT(KLOCDRV,Kern::Printf("%d media drivers opened",iMediaDriversOpened));
       
  2907 	OstTrace1( TRACE_INTERNALS, DPRIMARYMEDIABASE_DOPARTITIONINFOCOMPLETE3, "iMediaDriversOpened=%d", iMediaDriversOpened );
  2559 	if (iMediaDriversOpened==0)
  2908 	if (iMediaDriversOpened==0)
  2560 		{
  2909 		{
  2561 		SetClosed(KErrNotSupported);
  2910 		SetClosed(KErrNotSupported);
       
  2911 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_DOPARTITIONINFOCOMPLETE_EXIT3, this );
  2562 		return;
  2912 		return;
  2563 		}
  2913 		}
  2564 
  2914 
  2565 	// we are now finished with media driver list
  2915 	// we are now finished with media driver list
  2566 	iPhysDevArray.Close();
  2916 	iPhysDevArray.Close();
  2567 
  2917 
  2568 	// Finished reading partition info
  2918 	// Finished reading partition info
  2569 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase %d Read partition info complete",iMediaId));
  2919 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase %d Read partition info complete",iMediaId));
  2570 	__KTRACE_OPT(KLOCDRV,Kern::Printf("%d total partitions",iTotalPartitionsOpened));
  2920 	__KTRACE_OPT(KLOCDRV,Kern::Printf("%d total partitions",iTotalPartitionsOpened));
       
  2921 	OstTraceExt2( TRACE_INTERNALS, DPRIMARYMEDIABASE_DOPARTITIONINFOCOMPLETE4, "Read partition info complete iMediaId=%d; iPartitionsOpened=%d", iMediaId, iTotalPartitionsOpened );
  2571 	if (iTotalPartitionsOpened==0)
  2922 	if (iTotalPartitionsOpened==0)
  2572 		{
  2923 		{
  2573 		SetClosed(KErrNotSupported);
  2924 		SetClosed(KErrNotSupported);
       
  2925 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_DOPARTITIONINFOCOMPLETE_EXIT4, this );
  2574 		return;
  2926 		return;
  2575 		}
  2927 		}
  2576 
  2928 	
  2577 	// work out mapping of drives to partitions/media
  2929 	// work out mapping of drives to partitions/media
  2578 	TInt totalPartitions=iTotalPartitionsOpened;
  2930 	TInt totalPartitions=iTotalPartitionsOpened;
  2579 	TInt id=iMediaId;	// start with primary media
  2931 	TInt id=iMediaId;	// start with primary media
  2580 	TInt partitionsOnThisMedia=PartitionCount();
  2932 	TInt partitionsOnThisMedia=PartitionCount();
  2581 	TInt partition=0;
  2933 	TInt partition=0;
  2595 				id++;
  2947 				id++;
  2596 				partition=0;
  2948 				partition=0;
  2597 				partitionsOnThisMedia=TheMedia[id]->PartitionCount();
  2949 				partitionsOnThisMedia=TheMedia[id]->PartitionCount();
  2598 				}
  2950 				}
  2599 			__KTRACE_OPT(KLOCDRV,Kern::Printf("Drive %d = Media %d Partition %d",j,id,partition));
  2951 			__KTRACE_OPT(KLOCDRV,Kern::Printf("Drive %d = Media %d Partition %d",j,id,partition));
       
  2952 			OstTraceExt3( TRACE_INTERNALS, DPRIMARYMEDIABASE_DOPARTITIONINFOCOMPLETE5, "Local Drive=%d; iMediaId=%d; partition=%d", j, id, partition );
       
  2953 			
  2600 			pD->iMedia=TheMedia[id];
  2954 			pD->iMedia=TheMedia[id];
  2601 			pD->iPartitionNumber=partition;
  2955 			pD->iPartitionNumber=partition;
  2602 			memcpy(pD, pD->iMedia->iPartitionInfo.iEntry+partition, sizeof(TPartitionEntry));
  2956 			memcpy(pD, pD->iMedia->iPartitionInfo.iEntry+partition, sizeof(TPartitionEntry));
  2603 			partition++;
  2957 			partition++;
  2604 			totalPartitions--;
  2958 			totalPartitions--;
  2605 			}
  2959 			}
  2606 		}
  2960 		}
  2607 
  2961 
  2608 	// media is now ready - handle current or deferred requests
  2962 	// media is now ready - handle current or deferred requests
  2609 	MediaReadyHandleRequest();
  2963 	MediaReadyHandleRequest();
       
  2964 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_DOPARTITIONINFOCOMPLETE_EXIT5, this );
  2610 	}
  2965 	}
  2611 
  2966 
  2612 void DPrimaryMediaBase::MediaReadyHandleRequest()
  2967 void DPrimaryMediaBase::MediaReadyHandleRequest()
  2613 	{
  2968 	{
       
  2969 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_MEDIAREADYHANDLEREQUEST_ENTRY, this );
  2614 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase::MediaReadyHandleRequest() this %x", this));
  2970 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase::MediaReadyHandleRequest() this %x", this));
  2615 	iState = EReady;
  2971 	iState = EReady;
  2616 
  2972 
  2617 	// now we can process the current request
  2973 	// now we can process the current request
  2618 	// careful - thread may have exited while we were powering up
  2974 	// careful - thread may have exited while we were powering up
  2621 		DoRequest(*iCurrentReq);	// this sets iCurrentReq=NULL
  2977 		DoRequest(*iCurrentReq);	// this sets iCurrentReq=NULL
  2622 		}
  2978 		}
  2623 
  2979 
  2624 	// see if we can process any other requests concurrently
  2980 	// see if we can process any other requests concurrently
  2625 	RunDeferred();
  2981 	RunDeferred();
       
  2982 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_MEDIAREADYHANDLEREQUEST_EXIT, this );
  2626 	}
  2983 	}
  2627 
  2984 
  2628 void DPrimaryMediaBase::UpdatePartitionInfo()
  2985 void DPrimaryMediaBase::UpdatePartitionInfo()
  2629 	{
  2986 	{
       
  2987 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_UPDATEPARTITIONINFO_ENTRY, this );
  2630 	iState=EReadPartitionInfo;
  2988 	iState=EReadPartitionInfo;
  2631 	iNextMediaId=iMediaId;
  2989 	iNextMediaId=iMediaId;
  2632 	DMedia* pM=TheMedia[iNextMediaId];
  2990 	DMedia* pM=TheMedia[iNextMediaId];
  2633 	TInt r=pM->iDriver->PartitionInfo(pM->iPartitionInfo);
  2991 	TInt r=pM->iDriver->PartitionInfo(pM->iPartitionInfo);
  2634 	if (r!=KErrNone)
  2992 	if (r!=KErrNone)
  2635 		{
  2993 		{
  2636 		if (r==KErrCompletion)
  2994 		if (r==KErrCompletion)
  2637 			r=KErrNone;
  2995 			r=KErrNone;
  2638 		DoPartitionInfoComplete(r);
  2996 		DoPartitionInfoComplete(r);
  2639 		}
  2997 		}
       
  2998 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_UPDATEPARTITIONINFO_EXIT, this );
  2640 	}
  2999 	}
  2641 
  3000 
  2642 void DPrimaryMediaBase::CompleteCurrent(TInt anError)
  3001 void DPrimaryMediaBase::CompleteCurrent(TInt anError)
  2643 	{
  3002 	{
       
  3003 	OstTraceFunctionEntryExt( DPRIMARYMEDIABASE_COMPLETECURRENT_ENTRY, this );
  2644 	if (iCurrentReq)
  3004 	if (iCurrentReq)
  2645 		{
  3005 		{
  2646 		CHECK_RET(anError);
  3006 		CHECK_RET(anError);
  2647 #ifdef __DEMAND_PAGING__
  3007 #ifdef __DEMAND_PAGING__
  2648 		// got here because it was powered down when powering up, or failed powering up or failed opening MD or got media change
  3008 		// got here because it was powered down when powering up, or failed powering up or failed opening MD or got media change
  2651 			__ASSERT_ALWAYS(iPagingMedia,LOCM_FAULT());
  3011 			__ASSERT_ALWAYS(iPagingMedia,LOCM_FAULT());
  2652 			__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT());
  3012 			__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT());
  2653 			__ASSERT_ALWAYS( ((iCurrentReq->Flags() & TLocDrvRequest::ECodePaging) == 0) || (iCurrentReq->Drive()->iPagingDrv), LOCM_FAULT());
  3013 			__ASSERT_ALWAYS( ((iCurrentReq->Flags() & TLocDrvRequest::ECodePaging) == 0) || (iCurrentReq->Drive()->iPagingDrv), LOCM_FAULT());
  2654 
  3014 
  2655 			__KTRACE_OPT2(KLOCDPAGING,KFAIL,Kern::Printf("Got here because it was powered down when powering up, or failed powering up or failed opening MD or got media change"));
  3015 			__KTRACE_OPT2(KLOCDPAGING,KFAIL,Kern::Printf("Got here because it was powered down when powering up, or failed powering up or failed opening MD or got media change"));
       
  3016 			OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_COMPLETECURRENT, "Completed request due to powered down when powering up, or failed powering up or failed opening MD or got media change");
  2656 			iBody->iPagingDevice->CompleteRequest(iCurrentReq, anError);
  3017 			iBody->iPagingDevice->CompleteRequest(iCurrentReq, anError);
  2657 			}
  3018 			}
  2658 		else
  3019 		else
  2659 #endif
  3020 #endif
  2660 		CompleteRequest(*iCurrentReq, anError);
  3021 		CompleteRequest(*iCurrentReq, anError);
  2661 		iCurrentReq=NULL;
  3022 		iCurrentReq=NULL;
  2662 		}
  3023 		}
       
  3024 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_COMPLETECURRENT_EXIT, this );
  2663 	}
  3025 	}
  2664 
  3026 
  2665 
  3027 
  2666 void DPrimaryMediaBase::CompleteRequest(TLocDrvRequest& aMsg, TInt aResult)
  3028 void DPrimaryMediaBase::CompleteRequest(TLocDrvRequest& aMsg, TInt aResult)
  2667 	{
  3029 	{
       
  3030 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_COMPLETEREQUEST_ENTRY, this );
       
  3031 	OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_REQUEST, DPRIMARYMEDIABASE_COMPLETEREQUEST1, "TLocDrvRequest Object=0x%x; aResult=%d", (TUint) &aMsg, aResult);
  2668 	aMsg.Complete(aResult,EFalse);
  3032 	aMsg.Complete(aResult,EFalse);
       
  3033 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_COMPLETEREQUEST_EXIT, this );
  2669 	}
  3034 	}
  2670 
  3035 
  2671 EXPORT_C void DPrimaryMediaBase::RunDeferred()
  3036 EXPORT_C void DPrimaryMediaBase::RunDeferred()
  2672 /**
  3037 /**
  2673 Runs deferred Requests. Initiated from DPrimaryMediaBase::PowerUpComplete() function 
  3038 Runs deferred Requests. Initiated from DPrimaryMediaBase::PowerUpComplete() function 
  2674 to see if any other requests can be processed concurrently. 
  3039 to see if any other requests can be processed concurrently. 
  2675 Can also be called from DPrimaryMediaBase::NotifyPowerDown 
  3040 Can also be called from DPrimaryMediaBase::NotifyPowerDown 
  2676 or DPrimaryMediaBase::NotifyEmergencyPowerDown() function or DMediaDriver::Complete()
  3041 or DPrimaryMediaBase::NotifyEmergencyPowerDown() function or DMediaDriver::Complete()
  2677 */
  3042 */
  2678 	{
  3043 	{
       
  3044 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_RUNDEFERRED_ENTRY, this );
  2679 	// Do nothing if an open or close is in progress - this might be the case, for example, 
  3045 	// Do nothing if an open or close is in progress - this might be the case, for example, 
  2680 	// if a EForceMediaChange request (with the  KForceMediaChangeReOpenMediaDriver flag) 
  3046 	// if a EForceMediaChange request (with the  KForceMediaChangeReOpenMediaDriver flag) 
  2681 	// has recently been processed
  3047 	// has recently been processed
  2682 	if (iState!=EReady && iState!=EClosed && iState!=EPoweredDown)
  3048 	if (iState!=EReady && iState!=EClosed && iState!=EPoweredDown)
       
  3049 	    {
       
  3050 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_RUNDEFERRED_EXIT1, this );
  2683 		return;
  3051 		return;
  2684 
  3052 	    }
       
  3053 	
  2685 	// rerun deferred requests;
  3054 	// rerun deferred requests;
  2686 #ifdef __DEMAND_PAGING__
  3055 #ifdef __DEMAND_PAGING__
  2687 #ifdef __CONCURRENT_PAGING_INSTRUMENTATION__
  3056 #ifdef __CONCURRENT_PAGING_INSTRUMENTATION__
  2688 	TInt countROM=0;
  3057 	TInt countROM=0;
  2689 	TInt countCode=0;
  3058 	TInt countCode=0;
  2693 		{
  3062 		{
  2694 		__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT());
  3063 		__ASSERT_DEBUG(iBody->iPagingDevice,LOCM_FAULT());
  2695 		if(iBody->iPagingDevice->iEmptyingQ & DMediaPagingDevice::EDeferredQ)		// if already emptying deferred page in queue, don't reenter
  3064 		if(iBody->iPagingDevice->iEmptyingQ & DMediaPagingDevice::EDeferredQ)		// if already emptying deferred page in queue, don't reenter
  2696 			{
  3065 			{
  2697 			__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Already emptying deferred queue"));
  3066 			__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Already emptying deferred queue"));
       
  3067 			OstTrace0(TRACE_FLOW, DPRIMARYMEDIABASE_RUNDEFERRED_EXIT2, "< Already emptying deferred queue");
  2698 			return;
  3068 			return;
  2699 			}
  3069 			}
  2700 
  3070 
  2701 		DMediaPagingDevice* pagingdevice=iBody->iPagingDevice;
  3071 		DMediaPagingDevice* pagingdevice=iBody->iPagingDevice;
  2702 		TLocDrvRequest* pL = (TLocDrvRequest*) pagingdevice->iDeferredQ.Last();
  3072 		TLocDrvRequest* pL = (TLocDrvRequest*) pagingdevice->iDeferredQ.Last();
  2721 							pagingdevice->iDataStats.iMaxReqsInDeferred=countCode;
  3091 							pagingdevice->iDataStats.iMaxReqsInDeferred=countCode;
  2722 					NKern::FMSignal(&pagingdevice->iInstrumentationLock);
  3092 					NKern::FMSignal(&pagingdevice->iInstrumentationLock);
  2723 					}
  3093 					}
  2724 #endif
  3094 #endif
  2725 				__KTRACE_OPT(KLOCDPAGING,Kern::Printf("RunDeferred: process req 0x%08x, last in deferred queue 0x%08x",pM,pL));
  3095 				__KTRACE_OPT(KLOCDPAGING,Kern::Printf("RunDeferred: process req 0x%08x, last in deferred queue 0x%08x",pM,pL));
       
  3096 				OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_RUNDEFERRED2, "process req=0x%08x; last in deferred queue=0x%08x",(TUint) pM, (TUint) pL);
  2726 #ifdef BTRACE_PAGING_MEDIA
  3097 #ifdef BTRACE_PAGING_MEDIA
  2727 				BTraceContext8(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInDeferredReposted,pM,pM->iValue);
  3098 				BTraceContext8(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInDeferredReposted,pM,pM->iValue);
  2728 #endif
  3099 #endif
  2729 				// if Page In requests are synchronous this services them all in sequence, 
  3100 				// if Page In requests are synchronous this services them all in sequence, 
  2730 				// if they're asynch it re-defers them
  3101 				// if they're asynch it re-defers them
  2741 		// all requests synchronously, but runs background tasks that cannot be interrupted. In this last case the 
  3112 		// all requests synchronously, but runs background tasks that cannot be interrupted. In this last case the 
  2742 		// normal deferred queue may have some very long latency requests.
  3113 		// normal deferred queue may have some very long latency requests.
  2743 		if(pagingdevice->iEmptyingQ & DMediaPagingDevice::EMainQ)	// already emptying main Page In queue, skip (any Page In requests will be deferred)
  3114 		if(pagingdevice->iEmptyingQ & DMediaPagingDevice::EMainQ)	// already emptying main Page In queue, skip (any Page In requests will be deferred)
  2744 			{
  3115 			{
  2745 			__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Already emptying main queue"));
  3116 			__KTRACE_OPT(KLOCDPAGING,Kern::Printf("Already emptying main queue"));
       
  3117 			OstTrace0(TRACE_FLOW, DPRIMARYMEDIABASE_RUNDEFERRED_EXIT3, "< Already emptying main queue");
  2746 			return;
  3118 			return;
  2747 			}
  3119 			}
  2748 	
  3120 	
  2749 		TLocDrvRequest* pM=NULL;
  3121 		TLocDrvRequest* pM=NULL;
  2750 		if (!pagingdevice->iMainQ.iReady)	// if it's ready, then queue is empty
  3122 		if (!pagingdevice->iMainQ.iReady)	// if it's ready, then queue is empty
  2771 #ifdef __CONCURRENT_PAGING_INSTRUMENTATION__
  3143 #ifdef __CONCURRENT_PAGING_INSTRUMENTATION__
  2772 				(pM->iValue==DMediaPagingDevice::ERomPageInRequest)?(countROM++):(countCode++);
  3144 				(pM->iValue==DMediaPagingDevice::ERomPageInRequest)?(countROM++):(countCode++);
  2773 #endif
  3145 #endif
  2774 
  3146 
  2775 				__KTRACE_OPT(KLOCDPAGING,Kern::Printf("RunDeferred: process req 0x%08x",pM));
  3147 				__KTRACE_OPT(KLOCDPAGING,Kern::Printf("RunDeferred: process req 0x%08x",pM));
       
  3148 				OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_RUNDEFERRED4, "process req=0x%08x", pM);
  2776 				DoRequest(*(TLocDrvRequest*)pM);	// if Page In requests are synchronous this services them all in sequence, if they're asynch it defers them
  3149 				DoRequest(*(TLocDrvRequest*)pM);	// if Page In requests are synchronous this services them all in sequence, if they're asynch it defers them
  2777 				}
  3150 				}
  2778 
  3151 
  2779 			pagingdevice->iEmptyingQ&= ~DMediaPagingDevice::EMainQ;
  3152 			pagingdevice->iEmptyingQ&= ~DMediaPagingDevice::EMainQ;
  2780 
  3153 
  2791 #endif
  3164 #endif
  2792 			}	// if (pM)
  3165 			}	// if (pM)
  2793 		}	// 	if(iPagingMedia)
  3166 		}	// 	if(iPagingMedia)
  2794 #endif
  3167 #endif
  2795 	if (iRunningDeferred)
  3168 	if (iRunningDeferred)
       
  3169 	    {
       
  3170 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_RUNDEFERRED_EXIT4, this );
  2796 		return;
  3171 		return;
       
  3172 	    }
  2797 	TMessageBase* pL = iDeferred.Last();
  3173 	TMessageBase* pL = iDeferred.Last();
  2798 	if (!pL)
  3174 	if (!pL)
       
  3175 	    {
       
  3176 		OstTraceFunctionExit1( DPRIMARYMEDIABASE_RUNDEFERRED_EXIT5, this );
  2799 		return;	// no deferred requests
  3177 		return;	// no deferred requests
       
  3178 	    }
  2800 	iRunningDeferred=1;
  3179 	iRunningDeferred=1;
  2801 	TMessageBase* pM=NULL;
  3180 	TMessageBase* pM=NULL;
  2802 
  3181 
  2803 	while( pM != pL && (pM=iDeferred.Poll()) != NULL)	// stop after processing last one (requests may be re-deferred)
  3182 	while( pM != pL && (pM=iDeferred.Poll()) != NULL)	// stop after processing last one (requests may be re-deferred)
  2804 		DoRequest(*(TLocDrvRequest*)pM);
  3183 		DoRequest(*(TLocDrvRequest*)pM);
  2805 	iRunningDeferred=0;
  3184 	iRunningDeferred=0;
       
  3185 	
       
  3186 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_RUNDEFERRED_EXIT6, this );
  2806 	}
  3187 	}
  2807 
  3188 
  2808 void DPrimaryMediaBase::SetClosed(TInt anError)
  3189 void DPrimaryMediaBase::SetClosed(TInt anError)
  2809 	{
  3190 	{
       
  3191 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_SETCLOSED_ENTRY, this );
  2810 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::SetClosed error %d",iMediaId,anError));
  3192 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::SetClosed error %d",iMediaId,anError));
       
  3193 	OstTraceExt2( TRACE_MEDIACHANGE, DPRIMARYMEDIABASE_SETCLOSED, "iMediaId=%d; anError=%d", iMediaId, anError );
  2811 	CHECK_RET(anError);
  3194 	CHECK_RET(anError);
  2812 
  3195 
  2813 	// cancel DMediaDriver::OpenMediaDriverComplete() / DMediaDriver::PartitionInfoComplete() DFC
  3196 	// cancel DMediaDriver::OpenMediaDriverComplete() / DMediaDriver::PartitionInfoComplete() DFC
  2814 	iAsyncDfc.Cancel();
  3197 	iAsyncDfc.Cancel();
  2815 
  3198 
  2828 		iPhysDevArray.Close();
  3211 		iPhysDevArray.Close();
  2829 
  3212 
  2830 	iState = EClosed;
  3213 	iState = EClosed;
  2831 
  3214 
  2832 	iWaitMedChg.CompleteAll(KErrNone);
  3215 	iWaitMedChg.CompleteAll(KErrNone);
       
  3216 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_SETCLOSED_EXIT, this );
  2833 	}
  3217 	}
  2834 
  3218 
  2835 void DPrimaryMediaBase::NotifyClients(TBool aMediaChange,TLocDrv* aLocDrv)
  3219 void DPrimaryMediaBase::NotifyClients(TBool aMediaChange,TLocDrv* aLocDrv)
  2836 
  3220 
  2837 //
  3221 //
  2838 // Notify all clients of a media change or power-down event
  3222 // Notify all clients of a media change or power-down event
  2839 //
  3223 //
  2840 	{
  3224 	{
       
  3225 	OstTraceFunctionEntryExt( DPRIMARYMEDIABASE_NOTIFYCLIENTS_ENTRY, this );
       
  3226 	
  2841 	SDblQueLink* pL=iConnectionQ.iA.iNext;
  3227 	SDblQueLink* pL=iConnectionQ.iA.iNext;
  2842 	while (pL!=&iConnectionQ.iA)
  3228 	while (pL!=&iConnectionQ.iA)
  2843 		{
  3229 		{
  2844 		DLocalDrive* pD=_LOFF(pL,DLocalDrive,iLink);
  3230 		DLocalDrive* pD=_LOFF(pL,DLocalDrive,iLink);
  2845 		// Issue the notification if the caller wants to notify all drives (aLocDrv == NULL) or 
  3231 		// Issue the notification if the caller wants to notify all drives (aLocDrv == NULL) or 
  2846 		// the specified drive matches this one
  3232 		// the specified drive matches this one
  2847 		if (aLocDrv == NULL || aLocDrv == pD->iDrive)
  3233 		if (aLocDrv == NULL || aLocDrv == pD->iDrive)
  2848 			pD->NotifyChange(*this, aMediaChange);
  3234 			pD->NotifyChange(*this, aMediaChange);
  2849 		pL=pL->iNext;
  3235 		pL=pL->iNext;
  2850 		}
  3236 		}
       
  3237 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_NOTIFYCLIENTS_EXIT, this );
  2851 	}
  3238 	}
  2852 
  3239 
  2853 EXPORT_C void DPrimaryMediaBase::NotifyMediaChange()
  3240 EXPORT_C void DPrimaryMediaBase::NotifyMediaChange()
  2854 /**
  3241 /**
  2855 Closes all media drivers on this device and notifies all connections that media change has occurred 
  3242 Closes all media drivers on this device and notifies all connections that media change has occurred 
  2856 and completes any outstanding requests with KErrNotReady. 
  3243 and completes any outstanding requests with KErrNotReady. 
  2857 This also completes any force media change requests with KErrNone.
  3244 This also completes any force media change requests with KErrNone.
  2858 */
  3245 */
  2859 	{
  3246 	{
       
  3247 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_NOTIFYMEDIACHANGE_ENTRY, this );
  2860 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::NotifyMediaChange state %d",iMediaId,iState));
  3248 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::NotifyMediaChange state %d",iMediaId,iState));
  2861 
  3249 
       
  3250 	OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_MEDIACHANGE, DPRIMARYMEDIABASE_NOTIFYMEDIACHANGE, "iMediaId=%d; iState=%d", iMediaId, iState );
       
  3251 	
  2862 	TInt state=iState;
  3252 	TInt state=iState;
  2863 
  3253 
  2864 	__ASSERT_DEBUG(iBody, LOCM_FAULT());
  3254 	__ASSERT_DEBUG(iBody, LOCM_FAULT());
  2865 
  3255 
  2866 #ifdef __DEMAND_PAGING__
  3256 #ifdef __DEMAND_PAGING__
  2886 	// notify all connections that media change has occurred
  3276 	// notify all connections that media change has occurred
  2887 	NotifyClients(ETrue);
  3277 	NotifyClients(ETrue);
  2888 
  3278 
  2889 	// complete any force media change requests
  3279 	// complete any force media change requests
  2890 	iWaitMedChg.CompleteAll(KErrNone);
  3280 	iWaitMedChg.CompleteAll(KErrNone);
       
  3281 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_NOTIFYMEDIACHANGE_EXIT, this );
  2891 	}
  3282 	}
  2892 
  3283 
  2893 
  3284 
  2894 EXPORT_C void DPrimaryMediaBase::NotifyPowerDown()
  3285 EXPORT_C void DPrimaryMediaBase::NotifyPowerDown()
  2895 /**
  3286 /**
  2897 If device is not ready then it completes current requests but leaves other outstanding requests
  3288 If device is not ready then it completes current requests but leaves other outstanding requests
  2898 If ready, media driver should complete current request.
  3289 If ready, media driver should complete current request.
  2899 
  3290 
  2900 */
  3291 */
  2901 	{
  3292 	{
       
  3293 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_NOTIFYPOWERDOWN_ENTRY, this );
  2902 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::NotifyPowerDown state %d",iMediaId,iState));
  3294 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::NotifyPowerDown state %d",iMediaId,iState));
  2903 
  3295 	
       
  3296 	OstTraceExt2( TRACE_INTERNALS, DPRIMARYMEDIABASE_NOTIFYPOWERDOWN, "iMediaId=%d; iState=%d", iMediaId, iState );
       
  3297 	
  2904 	TInt id;
  3298 	TInt id;
  2905 	TBool allPersistent = ETrue;
  3299 	TBool allPersistent = ETrue;
  2906 	TBool allOpen = ETrue;
  3300 	TBool allOpen = ETrue;
  2907 
  3301 
  2908 	 // notify all media drivers on this device
  3302 	 // notify all media drivers on this device
  2926 			allPersistent = EFalse;
  3320 			allPersistent = EFalse;
  2927 			}
  3321 			}
  2928 		}
  3322 		}
  2929 
  3323 
  2930 	__KTRACE_OPT(KLOCDRV,Kern::Printf("allPersistent(%d)::allOpen %d",allPersistent, allOpen));
  3324 	__KTRACE_OPT(KLOCDRV,Kern::Printf("allPersistent(%d)::allOpen %d",allPersistent, allOpen));
       
  3325 	OstTraceExt2( TRACE_INTERNALS, DPRIMARYMEDIABASE_NOTIFYPOWERDOWN2, "allPersistent=%d; allOpen=%d", allPersistent, allOpen );
  2931 
  3326 
  2932 	if (allPersistent && allOpen && iState == EReady)
  3327 	if (allPersistent && allOpen && iState == EReady)
  2933 		{
  3328 		{
  2934 		//
  3329 		//
  2935 		// The EPoweredDown state indicates that the media is powered down, but the media driver still exists.
  3330 		// The EPoweredDown state indicates that the media is powered down, but the media driver still exists.
  2948 		CloseMediaDrivers();
  3343 		CloseMediaDrivers();
  2949 		SetClosed(KErrNotReady);
  3344 		SetClosed(KErrNotReady);
  2950 		}
  3345 		}
  2951 
  3346 
  2952 	NotifyClients(EFalse);
  3347 	NotifyClients(EFalse);
       
  3348 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_NOTIFYPOWERDOWN_EXIT, this );
  2953 	}
  3349 	}
  2954 
  3350 
  2955 
  3351 
  2956 EXPORT_C void DPrimaryMediaBase::NotifyPsuFault(TInt anError)
  3352 EXPORT_C void DPrimaryMediaBase::NotifyPsuFault(TInt anError)
  2957 /**
  3353 /**
  2958 Closes all media drivers on this device and completes any outstanding requests with error code.
  3354 Closes all media drivers on this device and completes any outstanding requests with error code.
  2959 @param anError Error code to be passed on while closing media drivers and completing outstanding requests.
  3355 @param anError Error code to be passed on while closing media drivers and completing outstanding requests.
  2960 */
  3356 */
  2961 
  3357 
  2962 	{
  3358 	{
       
  3359 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_NOTIFYPSUFAULT_ENTRY, this );
  2963 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::NotifyPsuFault state %d, err %d",iMediaId,iState,anError));
  3360 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::NotifyPsuFault state %d, err %d",iMediaId,iState,anError));
  2964 
  3361 	OstTraceExt3( TRACE_INTERNALS, DPRIMARYMEDIABASE_NOTIFYPSUFAULT, "iMediaId=%d; iState=%d; anError=%d", iMediaId, iState, anError );
       
  3362 	
  2965 	if (iState>=EOpening)
  3363 	if (iState>=EOpening)
  2966 		{
  3364 		{
  2967 		CloseMediaDrivers();
  3365 		CloseMediaDrivers();
  2968 		}
  3366 		}
  2969 
  3367 
  2970 	// complete any outstanding requests with error
  3368 	// complete any outstanding requests with error
  2971 	SetClosed(anError);
  3369 	SetClosed(anError);
       
  3370 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_NOTIFYPSUFAULT_EXIT, this );
  2972 	}
  3371 	}
  2973 
  3372 
  2974 EXPORT_C void DPrimaryMediaBase::NotifyEmergencyPowerDown()
  3373 EXPORT_C void DPrimaryMediaBase::NotifyEmergencyPowerDown()
  2975 /**
  3374 /**
  2976 Called on emergency power down. Notifies all media drivers on this device. 
  3375 Called on emergency power down. Notifies all media drivers on this device. 
  2977 If it is not in a ready state then it completes the current request but leaves other outstanding requests.
  3376 If it is not in a ready state then it completes the current request but leaves other outstanding requests.
  2978 If it is ready then the media driver should complete the current request. 
  3377 If it is ready then the media driver should complete the current request. 
  2979 It closes all media drivers and notifies all clients of a power down event.
  3378 It closes all media drivers and notifies all clients of a power down event.
  2980 */
  3379 */
  2981 	{
  3380 	{
       
  3381 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_NOTIFYEMERGENCYPOWERDOWN_ENTRY, this );
  2982 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::NotifyEmergencyPowerDown state %d",iMediaId,iState));
  3382 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPrimaryMediaBase(%d)::NotifyEmergencyPowerDown state %d",iMediaId,iState));
       
  3383 	OstTraceExt2( TRACE_INTERNALS, DPRIMARYMEDIABASE_NOTIFYEMERGENCYPOWERDOWN, "iMediaId=%d; iState=%d", iMediaId, iState );
       
  3384 	
  2983 	TBool recover=EFalse;
  3385 	TBool recover=EFalse;
  2984 	if (iState==EReady && iCritical!=0)
  3386 	if (iState==EReady && iCritical!=0)
  2985 		{
  3387 		{
  2986 		// check if emergency power recovery supported
  3388 		// check if emergency power recovery supported
  2987 		;
  3389 		;
  3011 		CompleteCurrent(KErrNotReady);
  3413 		CompleteCurrent(KErrNotReady);
  3012 		}
  3414 		}
  3013 	CloseMediaDrivers();
  3415 	CloseMediaDrivers();
  3014 	SetClosed(KErrNotReady);
  3416 	SetClosed(KErrNotReady);
  3015 	NotifyClients(EFalse);
  3417 	NotifyClients(EFalse);
       
  3418 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_NOTIFYEMERGENCYPOWERDOWN_EXIT, this );
  3016 	}
  3419 	}
  3017 
  3420 
  3018 EXPORT_C void DPrimaryMediaBase::NotifyMediaPresent()
  3421 EXPORT_C void DPrimaryMediaBase::NotifyMediaPresent()
  3019 /**
  3422 /**
  3020 Notifies clients of a media change by calling NotifyClients ( ) function to indicate that media is present.
  3423 Notifies clients of a media change by calling NotifyClients ( ) function to indicate that media is present.
  3021 */
  3424 */
  3022 	{
  3425 	{
       
  3426 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_NOTIFYMEDIAPRESENT_ENTRY, this );
  3023 	NotifyClients(ETrue);
  3427 	NotifyClients(ETrue);
       
  3428 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_NOTIFYMEDIAPRESENT_EXIT, this );
  3024 	}
  3429 	}
  3025 
  3430 
  3026 EXPORT_C TInt DPrimaryMediaBase::DoInCritical()
  3431 EXPORT_C TInt DPrimaryMediaBase::DoInCritical()
  3027 /**
  3432 /**
  3028 Flags the media driver as entering a critical part of its processing.
  3433 Flags the media driver as entering a critical part of its processing.
  3052 	{
  3457 	{
  3053 	}
  3458 	}
  3054 
  3459 
  3055 TInt DPrimaryMediaBase::InCritical()
  3460 TInt DPrimaryMediaBase::InCritical()
  3056 	{
  3461 	{
       
  3462 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_INCRITICAL_ENTRY, this );
  3057 	if (iCritical==0)
  3463 	if (iCritical==0)
  3058 		{
  3464 		{
  3059 		TInt r=DoInCritical();
  3465 		TInt r=DoInCritical();
  3060 		if (r!=KErrNone)
  3466 		if (r!=KErrNone)
       
  3467 		    {
       
  3468 			OstTraceFunctionExitExt( DPRIMARYMEDIABASE_INCRITICAL_EXIT1, this, r );
  3061 			return r;
  3469 			return r;
       
  3470 		    }
  3062 		}
  3471 		}
  3063 	++iCritical;
  3472 	++iCritical;
       
  3473 	OstTraceFunctionExitExt( DPRIMARYMEDIABASE_INCRITICAL_EXIT2, this, KErrNone );
  3064 	return KErrNone;
  3474 	return KErrNone;
  3065 	}
  3475 	}
  3066 
  3476 
  3067 void DPrimaryMediaBase::EndInCritical()
  3477 void DPrimaryMediaBase::EndInCritical()
  3068 	{
  3478 	{
       
  3479 	OstTraceFunctionEntry1( DPRIMARYMEDIABASE_ENDINCRITICAL_ENTRY, this );
  3069 	if (--iCritical==0)
  3480 	if (--iCritical==0)
  3070 		DoEndInCritical();
  3481 		DoEndInCritical();
       
  3482 	OstTraceFunctionExit1( DPRIMARYMEDIABASE_ENDINCRITICAL_EXIT, this );
  3071 	}
  3483 	}
  3072 
  3484 
  3073 EXPORT_C void DPrimaryMediaBase::DeltaCurrentConsumption(TInt /*aCurrent*/)
  3485 EXPORT_C void DPrimaryMediaBase::DeltaCurrentConsumption(TInt /*aCurrent*/)
  3074 /**
  3486 /**
  3075 Sets the incremental value of current consumption to aCurrent.
  3487 Sets the incremental value of current consumption to aCurrent.
  3084 TInt DPrimaryMediaBase::OpenMediaDriver()
  3496 TInt DPrimaryMediaBase::OpenMediaDriver()
  3085 //
  3497 //
  3086 // Synchronous open for devices with no DFC queue (e.g. IRAM)
  3498 // Synchronous open for devices with no DFC queue (e.g. IRAM)
  3087 //
  3499 //
  3088 	{
  3500 	{
       
  3501     OstTraceFunctionEntry1( DPRIMARYMEDIABASE_OPENMEDIADRIVER_ENTRY, this );
       
  3502     
  3089 	__KTRACE_OPT(KLOCDRV,Kern::Printf(">DPrimaryMediaBase:OpenMediaDriver-%d",iMediaId));
  3503 	__KTRACE_OPT(KLOCDRV,Kern::Printf(">DPrimaryMediaBase:OpenMediaDriver-%d",iMediaId));
       
  3504 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_MEDIACHANGE, DPRIMARYMEDIABASE_OPENMEDIADRIVER1, "iMediaId=%d", iMediaId);
       
  3505 	
  3090 	TVersion ver(KMediaDriverInterfaceMajorVersion,KMediaDriverInterfaceMinorVersion,KMediaDriverInterfaceBuildVersion);
  3506 	TVersion ver(KMediaDriverInterfaceMajorVersion,KMediaDriverInterfaceMinorVersion,KMediaDriverInterfaceBuildVersion);
  3091 
  3507 
  3092 	// Get a list of all currently loaded media drivers
  3508 	// Get a list of all currently loaded media drivers
  3093 	// Most media drivers do not make use of the pointer iMountInfo.iInfo when 
  3509 	// Most media drivers do not make use of the pointer iMountInfo.iInfo when 
  3094 	// their Validate() procedures are called from RPhysicalDeviceArray::GetDriverList(). 
  3510 	// their Validate() procedures are called from RPhysicalDeviceArray::GetDriverList(). 
  3096 	// the additional information pointed to by iMountInfo.iInfo to distinguish 
  3512 	// the additional information pointed to by iMountInfo.iInfo to distinguish 
  3097 	// group members. This information is passed when the media driver is registered 
  3513 	// group members. This information is passed when the media driver is registered 
  3098 	// using LocDrv::RegisterMediaDevice().
  3514 	// using LocDrv::RegisterMediaDevice().
  3099 	TInt r=iPhysDevArray.GetDriverList(KLitMediaDriverName,iDevice,iMountInfo.iInfo,ver);
  3515 	TInt r=iPhysDevArray.GetDriverList(KLitMediaDriverName,iDevice,iMountInfo.iInfo,ver);
  3100 	if (r!=KErrNone)
  3516 	if (r!=KErrNone)
       
  3517 	    {
       
  3518 		OstTraceFunctionExitExt( DPRIMARYMEDIABASE_OPENMEDIADRIVER_EXIT1, this, r );
  3101 		return r;
  3519 		return r;
  3102 
  3520 	    }
  3103 	// Go through them starting with highest priority
  3521 	// Go through them starting with highest priority
  3104 	TInt totalPartitions=0;
  3522 	TInt totalPartitions=0;
  3105 	TInt c=iPhysDevArray.Count();	// can't be zero
  3523 	TInt c=iPhysDevArray.Count();	// can't be zero
  3106 	TInt i=c-1;
  3524 	TInt i=c-1;
  3107 	r=KErrNotSupported;
  3525 	r=KErrNotSupported;
  3112 
  3530 
  3113 		// try to open media driver
  3531 		// try to open media driver
  3114 		TInt s=pD->Create( (DBase*&)pM, iMediaId, NULL, ver); 
  3532 		TInt s=pD->Create( (DBase*&)pM, iMediaId, NULL, ver); 
  3115 
  3533 
  3116 		__KTRACE_OPT(KLOCDRV,Kern::Printf("Media:Open-Opening %o(PRI:%d)-%d",pD,iPhysDevArray[i].iPriority,s));
  3534 		__KTRACE_OPT(KLOCDRV,Kern::Printf("Media:Open-Opening %o(PRI:%d)-%d",pD,iPhysDevArray[i].iPriority,s));
       
  3535 		OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_MEDIACHANGE, DPRIMARYMEDIABASE_OPENMEDIADRIVER2, "Media:Open-Opening 0x%x iPriority=%d; retval=%d", (TUint) pD, (TUint) iPhysDevArray[i].iPriority, (TUint) s);
  3117 		if (s!=KErrNone && pM)
  3536 		if (s!=KErrNone && pM)
  3118 			{
  3537 			{
  3119 			pM->Close();
  3538 			pM->Close();
  3120 			pM=NULL;
  3539 			pM=NULL;
  3121 			}
  3540 			}
  3181 				}
  3600 				}
  3182 			}
  3601 			}
  3183 		}
  3602 		}
  3184 
  3603 
  3185 	__KTRACE_OPT(KLOCDRV,Kern::Printf("<DPrimaryMediaBase:OpenMediaDriver-%d",r));
  3604 	__KTRACE_OPT(KLOCDRV,Kern::Printf("<DPrimaryMediaBase:OpenMediaDriver-%d",r));
       
  3605 	OstTraceFunctionExitExt( DPRIMARYMEDIABASE_OPENMEDIADRIVER_EXIT2, this, r );
  3186 	return r;
  3606 	return r;
  3187 	}
  3607 	}
  3188 
  3608 
  3189 #ifdef __DEMAND_PAGING__
  3609 #ifdef __DEMAND_PAGING__
  3190 // RequestCountInc()
  3610 // RequestCountInc()
  3195 void DPrimaryMediaBase::RequestCountInc()
  3615 void DPrimaryMediaBase::RequestCountInc()
  3196 	{
  3616 	{
  3197 	__ASSERT_DEBUG(iBody, LOCM_FAULT());
  3617 	__ASSERT_DEBUG(iBody, LOCM_FAULT());
  3198 	TInt oldVal = (TInt) __e32_atomic_add_ord32(&iBody->iRequestCount, (TUint) 1);
  3618 	TInt oldVal = (TInt) __e32_atomic_add_ord32(&iBody->iRequestCount, (TUint) 1);
  3199 //Kern::Printf("RCINC: this %x cnt %d, old %d", this, iBody->iRequestCount, oldVal);
  3619 //Kern::Printf("RCINC: this %x cnt %d, old %d", this, iBody->iRequestCount, oldVal);
       
  3620 	
       
  3621 	OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_REQUESTCOUNTINC, "new count=%d; old count=%d", iBody->iRequestCount, oldVal );
       
  3622 	
  3200 	if (oldVal == 0 && iBody->iPagingDevice)
  3623 	if (oldVal == 0 && iBody->iPagingDevice)
  3201 		{
  3624 		{
  3202 //Kern::Printf("RCINC: NotifyBusy()");
  3625 //Kern::Printf("RCINC: NotifyBusy()");
  3203 		iBody->iPagingDevice->NotifyBusy();
  3626 		iBody->iPagingDevice->NotifyBusy();
  3204 		}
  3627 		}
  3212 void DPrimaryMediaBase::RequestCountDec()
  3635 void DPrimaryMediaBase::RequestCountDec()
  3213 	{
  3636 	{
  3214 	__ASSERT_DEBUG(iBody, LOCM_FAULT());
  3637 	__ASSERT_DEBUG(iBody, LOCM_FAULT());
  3215 	TInt oldVal = (TInt) __e32_atomic_add_ord32(&iBody->iRequestCount, (TUint) -1);
  3638 	TInt oldVal = (TInt) __e32_atomic_add_ord32(&iBody->iRequestCount, (TUint) -1);
  3216 //Kern::Printf("RCDEC: this %x cnt %d, old %d", this, iBody->iRequestCount, oldVal);
  3639 //Kern::Printf("RCDEC: this %x cnt %d, old %d", this, iBody->iRequestCount, oldVal);
       
  3640 	
       
  3641 	OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_REQUESTCOUNTDEC, "new count=%d; old count=%d", iBody->iRequestCount, oldVal );
       
  3642 	
  3217 	if (oldVal == 1 && iBody->iPagingDevice)
  3643 	if (oldVal == 1 && iBody->iPagingDevice)
  3218 		{
  3644 		{
  3219 //Kern::Printf("RCDEC: NotifyIdle()");
  3645 //Kern::Printf("RCDEC: NotifyIdle()");
  3220 		iBody->iPagingDevice->NotifyIdle();
  3646 		iBody->iPagingDevice->NotifyIdle();
  3221 		}
  3647 		}
  3222 	__ASSERT_DEBUG(iBody->iRequestCount >= 0, LOCM_FAULT());
  3648 	__ASSERT_DEBUG(iBody->iRequestCount >= 0, LOCM_FAULT());
  3223 	}
  3649 	}
  3224 #endif	// __DEMAND_PAGING__
  3650 #endif	// __DEMAND_PAGING__
  3225 
       
  3226 
  3651 
  3227 TPartitionInfo::TPartitionInfo()
  3652 TPartitionInfo::TPartitionInfo()
  3228 //
  3653 //
  3229 // Constructor
  3654 // Constructor
  3230 //
  3655 //
  3234 
  3659 
  3235 #ifdef __DEMAND_PAGING__
  3660 #ifdef __DEMAND_PAGING__
  3236 
  3661 
  3237 void pageInDfc(TAny* aPtr)
  3662 void pageInDfc(TAny* aPtr)
  3238 	{
  3663 	{
       
  3664 	OstTraceFunctionEntry0( _PAGEINDFC_ENTRY );
  3239 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("pageInDfc"));
  3665 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("pageInDfc"));
  3240 	DPrimaryMediaBase* primaryMedia=(DPrimaryMediaBase*)aPtr;
  3666 	DPrimaryMediaBase* primaryMedia=(DPrimaryMediaBase*)aPtr;
  3241 	__ASSERT_ALWAYS(primaryMedia && primaryMedia->iPagingMedia && primaryMedia->iBody->iPagingDevice,LOCM_FAULT());
  3667 	__ASSERT_ALWAYS(primaryMedia && primaryMedia->iPagingMedia && primaryMedia->iBody->iPagingDevice,LOCM_FAULT());
  3242 	DMediaPagingDevice* pagingdevice=primaryMedia->iBody->iPagingDevice;
  3668 	DMediaPagingDevice* pagingdevice=primaryMedia->iBody->iPagingDevice;
  3243 
  3669 
  3260 
  3686 
  3261 #ifdef __CONCURRENT_PAGING_INSTRUMENTATION__
  3687 #ifdef __CONCURRENT_PAGING_INSTRUMENTATION__
  3262 		(m->iValue == DMediaPagingDevice::ERomPageInRequest)?(countROM++):(countCode++);
  3688 		(m->iValue == DMediaPagingDevice::ERomPageInRequest)?(countROM++):(countCode++);
  3263 #endif
  3689 #endif
  3264 		__KTRACE_OPT(KLOCDPAGING, Kern::Printf("pageInDfc: process request 0x%08x, last in queue 0x%08x",m, pagingdevice->iMainQ.Last()) );
  3690 		__KTRACE_OPT(KLOCDPAGING, Kern::Printf("pageInDfc: process request 0x%08x, last in queue 0x%08x",m, pagingdevice->iMainQ.Last()) );
       
  3691 		OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, PAGEINDFC2, "process request=0x%08x; last in queue=0x%08x",(TUint) m, (TUint) pagingdevice->iMainQ.Last());
  3265 
  3692 
  3266 		primaryMedia->HandleMsg(*m);
  3693 		primaryMedia->HandleMsg(*m);
  3267 		}
  3694 		}
  3268 
  3695 
  3269 #ifdef __CONCURRENT_PAGING_INSTRUMENTATION__
  3696 #ifdef __CONCURRENT_PAGING_INSTRUMENTATION__
  3274 		pagingdevice->iCodeStats.iMaxReqsInPending=countCode;
  3701 		pagingdevice->iCodeStats.iMaxReqsInPending=countCode;
  3275 	NKern::FMSignal(&pagingdevice->iInstrumentationLock);
  3702 	NKern::FMSignal(&pagingdevice->iInstrumentationLock);
  3276 #endif
  3703 #endif
  3277 
  3704 
  3278 	pagingdevice->iMainQ.Receive();	// allow reception of more messages
  3705 	pagingdevice->iMainQ.Receive();	// allow reception of more messages
       
  3706 	OstTraceFunctionExit0( _PAGEINDFC_EXIT );
  3279 	}
  3707 	}
  3280 
  3708 
  3281 DMediaPagingDevice::DMediaPagingDevice(DPrimaryMediaBase* aPtr)
  3709 DMediaPagingDevice::DMediaPagingDevice(DPrimaryMediaBase* aPtr)
  3282 	:	iMainQ(pageInDfc, aPtr, NULL, KMaxDfcPriority),
  3710 	:	iMainQ(pageInDfc, aPtr, NULL, KMaxDfcPriority),
  3283 		iDeferredQ(NULL, NULL, NULL, 0),			// callback never used
  3711 		iDeferredQ(NULL, NULL, NULL, 0),			// callback never used
  3285 		iInstrumentationLock()
  3713 		iInstrumentationLock()
  3286 #ifdef __CONCURRENT_PAGING_INSTRUMENTATION__
  3714 #ifdef __CONCURRENT_PAGING_INSTRUMENTATION__
  3287 		,iServicingROM(NULL), iServicingCode(NULL)
  3715 		,iServicingROM(NULL), iServicingCode(NULL)
  3288 #endif
  3716 #endif
  3289 	{
  3717 	{
       
  3718 	OstTraceFunctionEntry1( DMEDIAPAGINGDEVICE_DMEDIAPAGINGDEVICE_CONSTRUCTOR_ENTRY, this );
  3290 	iPrimaryMedia = aPtr;
  3719 	iPrimaryMedia = aPtr;
  3291 	if (iPrimaryMedia->iDfcQ)	// media driver has its own thread
  3720 	if (iPrimaryMedia->iDfcQ)	// media driver has its own thread
  3292 		{
  3721 		{
  3293 		iMainQ.SetDfcQ(iPrimaryMedia->iDfcQ);
  3722 		iMainQ.SetDfcQ(iPrimaryMedia->iDfcQ);
  3294 		}
  3723 		}
  3305 	iDataOutBenchmarkData.iCount=iDataOutBenchmarkData.iTotalTime=iDataOutBenchmarkData.iMaxTime=0;
  3734 	iDataOutBenchmarkData.iCount=iDataOutBenchmarkData.iTotalTime=iDataOutBenchmarkData.iMaxTime=0;
  3306 	iDataOutBenchmarkData.iMinTime = KMaxTInt;
  3735 	iDataOutBenchmarkData.iMinTime = KMaxTInt;
  3307 #endif
  3736 #endif
  3308 
  3737 
  3309 	iMainQ.Receive();
  3738 	iMainQ.Receive();
       
  3739 	OstTraceFunctionExit1( DMEDIAPAGINGDEVICE_DMEDIAPAGINGDEVICE_CONSTRUCTOR_EXIT, this );
  3310 	}
  3740 	}
  3311 
  3741 
  3312 DMediaPagingDevice::~DMediaPagingDevice()
  3742 DMediaPagingDevice::~DMediaPagingDevice()
  3313 	{
  3743 	{
       
  3744 OstTraceFunctionEntry1( DMEDIAPAGINGDEVICE_DMEDIAPAGINGDEVICE_DESTRUCTOR_ENTRY, this );
  3314 
  3745 
  3315 	if (iMountInfoDataLock)
  3746 	if (iMountInfoDataLock)
  3316 		ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) iMountInfoDataLock);
  3747 		ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) iMountInfoDataLock);
  3317 	
  3748 	
  3318 	if (iMountInfoDescHdrLock)
  3749 	if (iMountInfoDescHdrLock)
  3319 		ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) iMountInfoDescHdrLock);
  3750 		ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) iMountInfoDescHdrLock);
  3320 	
  3751 	
  3321 	if (iMountInfoDescLenLock)
  3752 	if (iMountInfoDescLenLock)
  3322 		ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) iMountInfoDescLenLock);
  3753 		ThePinObjectAllocator->ReleasePinObject((DPinObjectAllocator::SVirtualPinContainer*) iMountInfoDescLenLock);
       
  3754 	OstTraceFunctionExit1( DMEDIAPAGINGDEVICE_DMEDIAPAGINGDEVICE_DESTRUCTOR_EXIT, this );
  3323 	}
  3755 	}
  3324 
  3756 
  3325 
  3757 
  3326 void DMediaPagingDevice::SendToMainQueueDfcAndBlock(TThreadMessage* aMsg)
  3758 void DMediaPagingDevice::SendToMainQueueDfcAndBlock(TThreadMessage* aMsg)
  3327 	{
  3759 	{
       
  3760 	OstTraceFunctionEntryExt( DMEDIAPAGINGDEVICE_SENDTOMAINQUEUEDFCANDBLOCK_ENTRY, this );
  3328 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("Send request 0x%08x to main queue",aMsg));
  3761 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("Send request 0x%08x to main queue",aMsg));
  3329 	__ASSERT_ALWAYS(aMsg->iState==TMessageBase::EFree,LOCM_FAULT());	// check that message was previously completed or never queued
  3762 	__ASSERT_ALWAYS(aMsg->iState==TMessageBase::EFree,LOCM_FAULT());	// check that message was previously completed or never queued
  3330 
  3763 
  3331 	// if drive supports DMA, turn on Physical memory flag & sync memory
  3764 	// if drive supports DMA, turn on Physical memory flag & sync memory
  3332 	TLocDrvRequest& m=*(TLocDrvRequest*)(aMsg);
  3765 	TLocDrvRequest& m=*(TLocDrvRequest*)(aMsg);
  3351 
  3784 
  3352 	// Count the number of outstanding requests if this is the data-paging media, so that
  3785 	// Count the number of outstanding requests if this is the data-paging media, so that
  3353 	// we can call DPagingDevice::NotifyBusy() / DPagingDevice::NotifyIdle()
  3786 	// we can call DPagingDevice::NotifyBusy() / DPagingDevice::NotifyIdle()
  3354 	if ((m.Flags() & TLocDrvRequest::EBackgroundPaging) == 0)
  3787 	if ((m.Flags() & TLocDrvRequest::EBackgroundPaging) == 0)
  3355 		iPrimaryMedia->RequestCountInc();
  3788 		iPrimaryMedia->RequestCountInc();
  3356 
  3789 	
  3357 	aMsg->SendReceive(&iMainQ);
  3790 	aMsg->SendReceive(&iMainQ);
  3358 
  3791 
  3359 #ifdef __DEMAND_PAGING__
  3792 #ifdef __DEMAND_PAGING__
  3360 	if ((m.Flags() & TLocDrvRequest::EBackgroundPaging) == 0)
  3793 	if ((m.Flags() & TLocDrvRequest::EBackgroundPaging) == 0)
  3361 		iPrimaryMedia->RequestCountDec();
  3794 		iPrimaryMedia->RequestCountDec();
  3367 		}
  3800 		}
  3368 
  3801 
  3369 	
  3802 	
  3370 	// come back here when request is completed
  3803 	// come back here when request is completed
  3371 	__ASSERT_DEBUG(aMsg->iState==TMessageBase::EFree,LOCM_FAULT());		// check message has been completed
  3804 	__ASSERT_DEBUG(aMsg->iState==TMessageBase::EFree,LOCM_FAULT());		// check message has been completed
       
  3805 	OstTraceFunctionExit1( DMEDIAPAGINGDEVICE_SENDTOMAINQUEUEDFCANDBLOCK_EXIT, this );
  3372 	}
  3806 	}
  3373 
  3807 
  3374 void DMediaPagingDevice::SendToDeferredQ(TThreadMessage* aMsg)
  3808 void DMediaPagingDevice::SendToDeferredQ(TThreadMessage* aMsg)
  3375 	{
  3809 	{
       
  3810 	OstTraceFunctionEntryExt( DMEDIAPAGINGDEVICE_SENDTODEFERREDQ_ENTRY, this );
  3376 	// This queue is only accessed from MD thread
  3811 	// This queue is only accessed from MD thread
  3377 	__ASSERT_ALWAYS(aMsg->iState==TMessageBase::EAccepted,LOCM_FAULT());	// check that message was previously dequeued
  3812 	__ASSERT_ALWAYS(aMsg->iState==TMessageBase::EAccepted,LOCM_FAULT());	// check that message was previously dequeued
  3378 #ifdef BTRACE_PAGING_MEDIA
  3813 #ifdef BTRACE_PAGING_MEDIA
  3379 	if(iEmptyingQ&DMediaPagingDevice::EDeferredQ)		// already deferring
  3814 	if(iEmptyingQ&DMediaPagingDevice::EDeferredQ)		// already deferring
  3380 		BTraceContext8(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInReDeferred,aMsg,aMsg->iValue);
  3815 		BTraceContext8(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInReDeferred,aMsg,aMsg->iValue);
  3381 	else
  3816 	else
  3382 		BTraceContext8(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInDeferred,aMsg,aMsg->iValue);
  3817 		BTraceContext8(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInDeferred,aMsg,aMsg->iValue);
  3383 #endif
  3818 #endif
  3384 
  3819 
  3385 	aMsg->Forward(&iDeferredQ, EFalse);
  3820 	aMsg->Forward(&iDeferredQ, EFalse);
       
  3821 	OstTraceFunctionExit1( DMEDIAPAGINGDEVICE_SENDTODEFERREDQ_EXIT, this );
  3386 	}
  3822 	}
  3387 
  3823 
  3388 
  3824 
  3389 void DMediaPagingDevice::CompleteRequest(TThreadMessage* aMsg, TInt aResult)
  3825 void DMediaPagingDevice::CompleteRequest(TThreadMessage* aMsg, TInt aResult)
  3390 	{
  3826 	{
       
  3827 	OstTraceFunctionEntryExt( DMEDIAPAGINGDEVICE_COMPLETEREQUEST_ENTRY, this );
  3391 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DMediaPagingDevice::CompleteRequest, request 0x%08x result %d", aMsg, aResult));
  3828 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DMediaPagingDevice::CompleteRequest, request 0x%08x result %d", aMsg, aResult));
  3392 	__ASSERT_DEBUG(aMsg->iState==TMessageBase::EAccepted,LOCM_FAULT());
  3829 	__ASSERT_DEBUG(aMsg->iState==TMessageBase::EAccepted,LOCM_FAULT());
  3393 
  3830 
  3394 #ifdef BTRACE_PAGING_MEDIA
  3831 #ifdef BTRACE_PAGING_MEDIA
  3395 	BTraceContext12(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInPagedIn,aMsg,aResult,aMsg->iValue);
  3832 	BTraceContext12(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInPagedIn,aMsg,aResult,aMsg->iValue);
  3396 #endif
  3833 #endif
  3397 
  3834 
  3398 	iPrimaryMedia->CompleteRequest(*((TLocDrvRequest*) aMsg), aResult);
  3835 	iPrimaryMedia->CompleteRequest(*((TLocDrvRequest*) aMsg), aResult);
       
  3836 	OstTraceFunctionExit1( DMEDIAPAGINGDEVICE_COMPLETEREQUEST_EXIT, this );
  3399 	}
  3837 	}
  3400 
  3838 
  3401 TInt DMediaPagingDevice::Read(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize,TInt aDrvNumber)
  3839 TInt DMediaPagingDevice::Read(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize,TInt aDrvNumber)
  3402 	{
  3840 	{
       
  3841 	OstTraceFunctionEntry1( DMEDIAPAGINGDEVICE_READ_ENTRY, this );
  3403 	__ASSERT_ALWAYS(NKern::CurrentThread()!=iPrimaryMedia->iDfcQ->iThread,LOCM_FAULT());	// that would lock up the system, thus better die now
  3842 	__ASSERT_ALWAYS(NKern::CurrentThread()!=iPrimaryMedia->iDfcQ->iThread,LOCM_FAULT());	// that would lock up the system, thus better die now
  3404 	__ASSERT_ALWAYS(aReq,LOCM_FAULT());
  3843 	__ASSERT_ALWAYS(aReq,LOCM_FAULT());
  3405 	__ASSERT_CRITICAL
  3844 	__ASSERT_CRITICAL
  3406 
  3845 
  3407 #ifdef __DEMAND_PAGING_BENCHMARKS__
  3846 #ifdef __DEMAND_PAGING_BENCHMARKS__
  3466 	buf[2]=(TInt)aReq;	// address of request object
  3905 	buf[2]=(TInt)aReq;	// address of request object
  3467 	BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInBegin,aBuffer,offset,buf,sizeof(buf));
  3906 	BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageInBegin,aBuffer,offset,buf,sizeof(buf));
  3468 #endif
  3907 #endif
  3469 
  3908 
  3470 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DMediaPagingDevice::Read, Req(0x%08x), Buff(0x%x),Offset(%d),Size(%d),DrvNo(%d)",aReq,aBuffer,offset,size,aDrvNumber));
  3909 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DMediaPagingDevice::Read, Req(0x%08x), Buff(0x%x),Offset(%d),Size(%d),DrvNo(%d)",aReq,aBuffer,offset,size,aDrvNumber));
       
  3910 	OstTraceDefExt5(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DMEDIAPAGINGDEVICE_READ1, "req=0x%08x; aBuffer=0x%x; offset=%d; size=%d; aDrvNumber=%d", (TUint) aReq, (TInt) aBuffer, (TInt) offset, (TUint) size, (TUint) aDrvNumber);
  3471 	
  3911 	
  3472 	// no DFCQ, media driver executes in the context of calling thread
  3912 	// no DFCQ, media driver executes in the context of calling thread
  3473 	if (!iPrimaryMedia->iDfcQ)
  3913 	if (!iPrimaryMedia->iDfcQ)
  3474 		{
  3914 		{
  3475 		LOCM_FAULT();		// don't allow paging
  3915 		LOCM_FAULT();		// don't allow paging
       
  3916 		OstTraceFunctionExitExt( DMEDIAPAGINGDEVICE_READ_EXIT, this, KErrNone );
  3476 		return KErrNone;	// keep compiler happy
  3917 		return KErrNone;	// keep compiler happy
  3477 		}
  3918 		}
  3478 
  3919 
  3479 
  3920 
  3480 	TLocDrvRequest& m=*(TLocDrvRequest*)(aReq);
  3921 	TLocDrvRequest& m=*(TLocDrvRequest*)(aReq);
       
  3922 	
  3481 
  3923 
  3482 #ifdef __DEMAND_PAGING_BENCHMARKS__
  3924 #ifdef __DEMAND_PAGING_BENCHMARKS__
  3483 	SPagingBenchmarkInfo* info = NULL;
  3925 	SPagingBenchmarkInfo* info = NULL;
  3484 #endif
  3926 #endif
  3485 
  3927 
  3543 		m.Length()=Int64(size);
  3985 		m.Length()=Int64(size);
  3544 		m.RemoteDes()=(TAny*)aBuffer;
  3986 		m.RemoteDes()=(TAny*)aBuffer;
  3545 		m.RemoteDesOffset()=0;		// pre-aligned
  3987 		m.RemoteDesOffset()=0;		// pre-aligned
  3546 		m.DriverFlags()=0;
  3988 		m.DriverFlags()=0;
  3547 		__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("ReqId=%d, Pos=0x%lx, Len=0x%lx, remote Des 0x%x",m.Id(),m.Pos(),m.Length(),m.RemoteDes()));
  3989 		__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("ReqId=%d, Pos=0x%lx, Len=0x%lx, remote Des 0x%x",m.Id(),m.Pos(),m.Length(),m.RemoteDes()));
  3548 
  3990 		OstTraceDefExt4(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DMEDIAPAGINGDEVICE_READ2, "reqId=%d; position=0x%lx; length=0x%x; remote Des=0x%x", (TInt) m.Id(), (TUint) m.Pos(), (TUint) m.Length(), (TUint) m.RemoteDes());
       
  3991 		
  3549 		__ASSERT_DEBUG(iPrimaryMedia->iBody, LOCM_FAULT());
  3992 		__ASSERT_DEBUG(iPrimaryMedia->iBody, LOCM_FAULT());
  3550 		TInt mediaChanges = iPrimaryMedia->iBody->iMediaChanges;
  3993 		TInt mediaChanges = iPrimaryMedia->iBody->iMediaChanges;
  3551 
  3994 
  3552 		SendToMainQueueDfcAndBlock(&m);		// queues request, sets and opens client thread, queues dfc and blocks thread until request is completed
  3995 		SendToMainQueueDfcAndBlock(&m);		// queues request, sets and opens client thread, queues dfc and blocks thread until request is completed
  3553 		retVal = m.iValue;
  3996 		retVal = m.iValue;
  3554 
  3997 
  3555 #ifdef __DEBUG_DEMAND_PAGING__
  3998 #ifdef __DEBUG_DEMAND_PAGING__
  3556 		if (retVal != KErrNone)
  3999 		if (retVal != KErrNone)
       
  4000 		    {
  3557 			Kern::Printf("Pagin Failure %d, retry %d", retVal, i);
  4001 			Kern::Printf("Pagin Failure %d, retry %d", retVal, i);
       
  4002 		    }
  3558 #endif
  4003 #endif
  3559 
  4004 
  3560 		// reset retry count if there's ben a media change
  4005 		// reset retry count if there's ben a media change
  3561 		if (retVal != KErrNone && mediaChanges != iPrimaryMedia->iBody->iMediaChanges)
  4006 		if (retVal != KErrNone && mediaChanges != iPrimaryMedia->iBody->iMediaChanges)
  3562 			i = 0;
  4007 			i = 0;
  3581 	if (elapsed > info->iMaxTime)
  4026 	if (elapsed > info->iMaxTime)
  3582 		info->iMaxTime = elapsed;
  4027 		info->iMaxTime = elapsed;
  3583 	if (elapsed < info->iMinTime)
  4028 	if (elapsed < info->iMinTime)
  3584 		info->iMinTime = elapsed;
  4029 		info->iMinTime = elapsed;
  3585 #endif // __DEMAND_PAGING_BENCHMARKS__
  4030 #endif // __DEMAND_PAGING_BENCHMARKS__
  3586 
  4031 	OstTraceFunctionExitExt( DMEDIAPAGINGDEVICE_READ_EXIT2, this, retVal );
  3587 	return retVal;
  4032 	return retVal;
  3588 	}
  4033 	}
  3589 
  4034 
  3590 TInt DMediaPagingDevice::Write(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize,TBool aBackground)
  4035 TInt DMediaPagingDevice::Write(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize,TBool aBackground)
  3591 	{
  4036 	{
       
  4037 	OstTraceFunctionEntry1( DMEDIAPAGINGDEVICE_WRITE_ENTRY, this );
  3592 	__ASSERT_ALWAYS(NKern::CurrentThread()!=iPrimaryMedia->iDfcQ->iThread,LOCM_FAULT());	// that would lock up the system, thus better die now
  4038 	__ASSERT_ALWAYS(NKern::CurrentThread()!=iPrimaryMedia->iDfcQ->iThread,LOCM_FAULT());	// that would lock up the system, thus better die now
  3593 	__ASSERT_ALWAYS(aReq,LOCM_FAULT());
  4039 	__ASSERT_ALWAYS(aReq,LOCM_FAULT());
  3594 	__ASSERT_CRITICAL
  4040 	__ASSERT_CRITICAL
  3595 
  4041 
  3596 #ifdef __DEMAND_PAGING_BENCHMARKS__
  4042 #ifdef __DEMAND_PAGING_BENCHMARKS__
  3621 	buf[1] = (TInt)aReq;		// address of request object
  4067 	buf[1] = (TInt)aReq;		// address of request object
  3622 	BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageOutBegin,aBuffer,offset,buf,sizeof(buf));
  4068 	BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedPageOutBegin,aBuffer,offset,buf,sizeof(buf));
  3623 #endif
  4069 #endif
  3624 
  4070 
  3625 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DMediaPagingDevice::Write, Req(0x%08x), Buff(0x%x),Offset(%d),Size(%d)",aReq,aBuffer,offset,size));
  4071 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DMediaPagingDevice::Write, Req(0x%08x), Buff(0x%x),Offset(%d),Size(%d)",aReq,aBuffer,offset,size));
       
  4072 	OstTraceDefExt4(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DMEDIAPAGINGDEVICE_WRITE1, "req=0x%08x; aBuffer=0x%x; offset=%d; size=%d", (TUint) aReq, (TUint) aBuffer, offset, size);
  3626 	
  4073 	
  3627 	// no DFCQ, media driver executes in the context of calling thread
  4074 	// no DFCQ, media driver executes in the context of calling thread
  3628 	if (!iPrimaryMedia->iDfcQ)
  4075 	if (!iPrimaryMedia->iDfcQ)
  3629 		{
  4076 		{
  3630 		LOCM_FAULT();		// don't allow paging
  4077 		LOCM_FAULT();		// don't allow paging
       
  4078 		OstTraceFunctionExitExt( DMEDIAPAGINGDEVICE_WRITE_EXIT, this, KErrNone );
  3631 		return KErrNone;	// keep compiler happy
  4079 		return KErrNone;	// keep compiler happy
  3632 		}
  4080 		}
  3633 
  4081 
  3634 
  4082 
  3635 	TLocDrvRequest& m=*(TLocDrvRequest*)(aReq);
  4083 	TLocDrvRequest& m=*(TLocDrvRequest*)(aReq);
  3636 
  4084 	
  3637 #ifdef __DEMAND_PAGING_BENCHMARKS__
  4085 #ifdef __DEMAND_PAGING_BENCHMARKS__
  3638 	__e32_atomic_add_ord32(&iMediaPagingInfo.iDataPageOutCount, (TUint) 1);
  4086 	__e32_atomic_add_ord32(&iMediaPagingInfo.iDataPageOutCount, (TUint) 1);
  3639 	if (aBackground)
  4087 	if (aBackground)
  3640 		__e32_atomic_add_ord32(&iMediaPagingInfo.iDataPageOutBackgroundCount, (TUint) 1);
  4088 		__e32_atomic_add_ord32(&iMediaPagingInfo.iDataPageOutBackgroundCount, (TUint) 1);
  3641 #endif
  4089 #endif
  3655 		m.Length()=Int64(size);
  4103 		m.Length()=Int64(size);
  3656 		m.RemoteDes()=(TAny*)aBuffer;
  4104 		m.RemoteDes()=(TAny*)aBuffer;
  3657 		m.RemoteDesOffset()=0;		// pre-aligned
  4105 		m.RemoteDesOffset()=0;		// pre-aligned
  3658 		m.DriverFlags()=0;
  4106 		m.DriverFlags()=0;
  3659 		__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("ReqId=%d, Pos=0x%lx, Len=0x%lx, remote Des 0x%x",m.Id(),m.Pos(),m.Length(),m.RemoteDes()));
  4107 		__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("ReqId=%d, Pos=0x%lx, Len=0x%lx, remote Des 0x%x",m.Id(),m.Pos(),m.Length(),m.RemoteDes()));
  3660 
  4108 		OstTraceDefExt4(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DMEDIAPAGINGDEVICE_WRITE2, "reqId=%d; position=0x%lx; length=0x%lx; remote Des=0x%x", (TInt) m.Id(), (TUint) m.Pos(), (TUint) m.Length(), (TUint) m.RemoteDes());
       
  4109 		
  3661 		__ASSERT_DEBUG(iPrimaryMedia->iBody, LOCM_FAULT());
  4110 		__ASSERT_DEBUG(iPrimaryMedia->iBody, LOCM_FAULT());
  3662 		TInt mediaChanges = iPrimaryMedia->iBody->iMediaChanges;
  4111 		TInt mediaChanges = iPrimaryMedia->iBody->iMediaChanges;
  3663 
  4112 
  3664 		SendToMainQueueDfcAndBlock(&m);		// queues request, sets and opens client thread, queues dfc and blocks thread until request is completed
  4113 		SendToMainQueueDfcAndBlock(&m);		// queues request, sets and opens client thread, queues dfc and blocks thread until request is completed
       
  4114 		
  3665 		retVal = m.iValue;
  4115 		retVal = m.iValue;
  3666 
  4116 
  3667 #ifdef __DEBUG_DEMAND_PAGING__
  4117 #ifdef __DEBUG_DEMAND_PAGING__
  3668 		if (retVal != KErrNone)
  4118 		if (retVal != KErrNone)
  3669 			Kern::Printf("Pagout Failure %d, retry %d", retVal, i);
  4119 			Kern::Printf("Pagout Failure %d, retry %d", retVal, i);
  3693 	if (elapsed > info.iMaxTime)
  4143 	if (elapsed > info.iMaxTime)
  3694 		info.iMaxTime = elapsed;
  4144 		info.iMaxTime = elapsed;
  3695 	if (elapsed < info.iMinTime)
  4145 	if (elapsed < info.iMinTime)
  3696 		info.iMinTime = elapsed;
  4146 		info.iMinTime = elapsed;
  3697 #endif // __DEMAND_PAGING_BENCHMARKS__
  4147 #endif // __DEMAND_PAGING_BENCHMARKS__
  3698 
  4148 	
       
  4149 	OstTraceFunctionExitExt( DMEDIAPAGINGDEVICE_WRITE_EXIT2, this, retVal );
  3699 	return retVal;
  4150 	return retVal;
  3700 	}
  4151 	}
  3701 
  4152 
  3702 
  4153 
  3703 TInt DMediaPagingDevice::DeleteNotify(TThreadMessage* aReq,TUint aOffset,TUint aSize)
  4154 TInt DMediaPagingDevice::DeleteNotify(TThreadMessage* aReq,TUint aOffset,TUint aSize)
  3704 	{
  4155 	{
       
  4156 	OstTraceFunctionEntry1( DMEDIAPAGINGDEVICE_DELETENOTIFY_ENTRY, this );
  3705 	if (iDeleteNotifyNotSupported)
  4157 	if (iDeleteNotifyNotSupported)
       
  4158 	    {
       
  4159 		OstTraceFunctionExitExt( DMEDIAPAGINGDEVICE_DELETENOTIFY_EXIT1, this, KErrNotSupported );
  3706 		return KErrNotSupported;
  4160 		return KErrNotSupported;
       
  4161 	    }
  3707 
  4162 
  3708 	__ASSERT_ALWAYS(NKern::CurrentThread()!=iPrimaryMedia->iDfcQ->iThread,LOCM_FAULT());	// that would lock up the system, thus better die now
  4163 	__ASSERT_ALWAYS(NKern::CurrentThread()!=iPrimaryMedia->iDfcQ->iThread,LOCM_FAULT());	// that would lock up the system, thus better die now
  3709 	__ASSERT_ALWAYS(aReq,LOCM_FAULT());
  4164 	__ASSERT_ALWAYS(aReq,LOCM_FAULT());
  3710 	__ASSERT_ALWAYS(DataPagingDfcQ(iPrimaryMedia),LOCM_FAULT());
  4165 	__ASSERT_ALWAYS(DataPagingDfcQ(iPrimaryMedia),LOCM_FAULT());
  3711 	__ASSERT_CRITICAL
  4166 	__ASSERT_CRITICAL
  3719 	buf[1] = (TInt)aReq;	// address of request object
  4174 	buf[1] = (TInt)aReq;	// address of request object
  3720 	BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedDeleteNotifyBegin,NULL,offset,buf,sizeof(buf));
  4175 	BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaLocMedDeleteNotifyBegin,NULL,offset,buf,sizeof(buf));
  3721 #endif
  4176 #endif
  3722 
  4177 
  3723 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DMediaPagingDevice::Write, Req(0x%08x), Offset(%d),Size(%d)",aReq,offset,size));
  4178 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("DMediaPagingDevice::Write, Req(0x%08x), Offset(%d),Size(%d)",aReq,offset,size));
       
  4179 	OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DMEDIAPAGINGDEVICE_DELETENOTIFY1 , "req=0x%08x; offset=%d; size=%d", (TUint) aReq, offset, size);
  3724 	
  4180 	
  3725 	// no DFCQ, media driver executes in the context of calling thread
  4181 	// no DFCQ, media driver executes in the context of calling thread
  3726 	if (!iPrimaryMedia->iDfcQ)
  4182 	if (!iPrimaryMedia->iDfcQ)
  3727 		{
  4183 		{
  3728 		LOCM_FAULT();		// don't allow paging
  4184 		LOCM_FAULT();		// don't allow paging
       
  4185 		OstTraceFunctionExitExt( DMEDIAPAGINGDEVICE_DELETENOTIFY_EXIT2, this, KErrNone );
  3729 		return KErrNone;	// keep compiler happy
  4186 		return KErrNone;	// keep compiler happy
  3730 		}
  4187 		}
  3731 
  4188 
  3732 	TLocDrvRequest& m=*(TLocDrvRequest*)(aReq);
  4189 	TLocDrvRequest& m=*(TLocDrvRequest*)(aReq);
  3733 
  4190 
  3741 	m.Length() = Int64(size);
  4198 	m.Length() = Int64(size);
  3742 	m.RemoteDes() = NULL;
  4199 	m.RemoteDes() = NULL;
  3743 	m.RemoteDesOffset() = 0;		// pre-aligned
  4200 	m.RemoteDesOffset() = 0;		// pre-aligned
  3744 	m.DriverFlags()=0;
  4201 	m.DriverFlags()=0;
  3745 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("ReqId=%d, Pos=0x%lx, Len=0x%lx, remote Des 0x%x",m.Id(),m.Pos(),m.Length(),m.RemoteDes()));
  4202 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("ReqId=%d, Pos=0x%lx, Len=0x%lx, remote Des 0x%x",m.Id(),m.Pos(),m.Length(),m.RemoteDes()));
  3746 
  4203 	OstTraceDefExt4(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DMEDIAPAGINGDEVICE_DELETENOTIFY2 , "reqId=%d; position=0x%lx; length=0x%lx; remote Des=0x%x", m.Id(), m.Pos(), m.Length(), (TUint) m.RemoteDes());
  3747 
  4204 
  3748 	// send request aynchronously as we don't particularly care about the result 
  4205 	// send request aynchronously as we don't particularly care about the result 
  3749 	// and waiting would slow down the thread taking the page fault
  4206 	// and waiting would slow down the thread taking the page fault
  3750 	iPrimaryMedia->RequestCountInc();
  4207 	iPrimaryMedia->RequestCountInc();
  3751 
  4208 
  3758 	TInt retVal = m.iValue;
  4215 	TInt retVal = m.iValue;
  3759 
  4216 
  3760 	if (retVal == KErrNotSupported)
  4217 	if (retVal == KErrNotSupported)
  3761 		iDeleteNotifyNotSupported = ETrue;
  4218 		iDeleteNotifyNotSupported = ETrue;
  3762 
  4219 
       
  4220 	OstTraceFunctionExitExt( DMEDIAPAGINGDEVICE_DELETENOTIFY_EXIT3, this, retVal );
  3763 	return retVal;
  4221 	return retVal;
  3764 	}
  4222 	}
  3765 
  4223 
  3766 
  4224 
  3767 
  4225 
  3768 EXPORT_C TInt TLocDrvRequest::WriteToPageHandler(const TAny* aSrc, TInt aSize, TInt anOffset)
  4226 EXPORT_C TInt TLocDrvRequest::WriteToPageHandler(const TAny* aSrc, TInt aSize, TInt anOffset)
  3769 	{
  4227 	{
       
  4228 	OstTraceFunctionEntry1( TLOCDRVREQUEST_WRITETOPAGEHANDLER_ENTRY, this );
  3770 #ifdef BTRACE_PAGING_MEDIA
  4229 #ifdef BTRACE_PAGING_MEDIA
  3771 	TMediaDevice medDev=Drive()->iMedia->iDevice;
  4230 	TMediaDevice medDev=Drive()->iMedia->iDevice;
  3772 	TInt buf[3];
  4231 	TInt buf[3];
  3773 	buf[0]=(TUint32)RemoteDes();
  4232 	buf[0]=(TUint32)RemoteDes();
  3774 	buf[1]=anOffset;
  4233 	buf[1]=anOffset;
  3775 	buf[2]=aSize;
  4234 	buf[2]=aSize;
  3776 	BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaMedDrvWriteBack,medDev,this,buf,sizeof(buf));
  4235 	BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaMedDrvWriteBack,medDev,this,buf,sizeof(buf));
  3777 #endif
  4236 #endif
  3778 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("TLocDrvRequest::WriteToPageHandler, memcpy((aTrg)%08x, (aSrc)%08x, (aLength)%08x)",(TUint32)RemoteDes()+anOffset,aSrc,aSize));
  4237 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("TLocDrvRequest::WriteToPageHandler, memcpy((aTrg)%08x, (aSrc)%08x, (aLength)%08x)",(TUint32)RemoteDes()+anOffset,aSrc,aSize));
  3779 	(void)memcpy((TAny*)((TUint32)RemoteDes()+anOffset), aSrc, aSize);	// maybe in later versions this could be something else
  4238 	(void)memcpy((TAny*)((TUint32)RemoteDes()+anOffset), aSrc, aSize);	// maybe in later versions this could be something else
       
  4239 	OstTraceFunctionExitExt( TLOCDRVREQUEST_WRITETOPAGEHANDLER_EXIT, this, KErrNone );
  3780 	return KErrNone;
  4240 	return KErrNone;
  3781 	}
  4241 	}
  3782 
  4242 
  3783 EXPORT_C TInt TLocDrvRequest::ReadFromPageHandler(TAny* aDst, TInt aSize, TInt anOffset)
  4243 EXPORT_C TInt TLocDrvRequest::ReadFromPageHandler(TAny* aDst, TInt aSize, TInt anOffset)
  3784 	{
  4244 	{
       
  4245 	OstTraceFunctionEntry1( TLOCDRVREQUEST_READFROMPAGEHANDLER_ENTRY, this );
  3785 #ifdef BTRACE_PAGING_MEDIA
  4246 #ifdef BTRACE_PAGING_MEDIA
  3786 	TMediaDevice medDev=Drive()->iMedia->iDevice;
  4247 	TMediaDevice medDev=Drive()->iMedia->iDevice;
  3787 	TInt buf[3];
  4248 	TInt buf[3];
  3788 	buf[0]=(TUint32)RemoteDes();
  4249 	buf[0]=(TUint32)RemoteDes();
  3789 	buf[1]=anOffset;
  4250 	buf[1]=anOffset;
  3790 	buf[2]=aSize;
  4251 	buf[2]=aSize;
  3791 	BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaMedDrvRead,medDev,this,buf,sizeof(buf));
  4252 	BTraceContextN(BTrace::EPagingMedia,BTrace::EPagingMediaMedDrvRead,medDev,this,buf,sizeof(buf));
  3792 #endif
  4253 #endif
  3793 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("TLocDrvRequest::ReadFromPageHandler, memcpy((aDst)%08x, (aTrg)%08x, (aLength)%08x)",aDst,(TUint32)RemoteDes()+anOffset,aSize));
  4254 	__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("TLocDrvRequest::ReadFromPageHandler, memcpy((aDst)%08x, (aTrg)%08x, (aLength)%08x)",aDst,(TUint32)RemoteDes()+anOffset,aSize));
  3794 	(void)memcpy(aDst, (TAny*)((TUint32)RemoteDes()+anOffset), aSize);	// maybe in later versions this could be something else
  4255 	(void)memcpy(aDst, (TAny*)((TUint32)RemoteDes()+anOffset), aSize);	// maybe in later versions this could be something else
       
  4256 	OstTraceFunctionExitExt( TLOCDRVREQUEST_READFROMPAGEHANDLER_EXIT, this, KErrNone );
  3795 	return KErrNone;
  4257 	return KErrNone;
  3796 	}
  4258 	}
  3797 
  4259 
  3798 _LIT(KLitFragmentationMutexName, "FRAGMENTATION_MUTEX");
  4260 _LIT(KLitFragmentationMutexName, "FRAGMENTATION_MUTEX");
  3799 
  4261 
  3800 TInt DFragmentationPagingLock::Construct(TUint aNumPages)
  4262 TInt DFragmentationPagingLock::Construct(TUint aNumPages)
  3801 	{
  4263 	{
       
  4264 	OstTraceFunctionEntryExt( DFRAGMENTATIONPAGINGLOCK_CONSTRUCT_ENTRY, this );
  3802 	TInt r=KErrNone;
  4265 	TInt r=KErrNone;
  3803 	__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Fragmentation Lock: creating Mutex"));
  4266 	__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Fragmentation Lock: creating Mutex"));
  3804 	r=Kern::MutexCreate(this->iFragmentationMutex, KLitFragmentationMutexName, KMutexOrdNone);
  4267 	r=Kern::MutexCreate(this->iFragmentationMutex, KLitFragmentationMutexName, KMutexOrdNone);
  3805 	if (r!=KErrNone)
  4268 	if (r!=KErrNone)
       
  4269 	    {
       
  4270 		OstTraceFunctionExitExt( DFRAGMENTATIONPAGINGLOCK_CONSTRUCT_EXIT1, this, r );
  3806 		return r;
  4271 		return r;
       
  4272 	    }
  3807 	__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Fragmentation Lock: Mutex created OK"));
  4273 	__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Fragmentation Lock: Mutex created OK"));
       
  4274 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DFRAGMENTATIONPAGINGLOCK_CONSTRUCT1 , "Fragmentation Lock: Mutex created OK");
  3808 
  4275 
  3809 	iFragmentGranularity = 0;
  4276 	iFragmentGranularity = 0;
  3810 	if (aNumPages == 0)
  4277 	if (aNumPages == 0)
       
  4278 	    {
       
  4279 		OstTraceFunctionExitExt( DFRAGMENTATIONPAGINGLOCK_CONSTRUCT_EXIT2, this, KErrNone );
  3811 		return KErrNone;
  4280 		return KErrNone;
  3812 
  4281 	    }
       
  4282 	
  3813 	// in CS
  4283 	// in CS
  3814 	TInt pageSize=Kern::RoundToPageSize(1);
  4284 	TInt pageSize=Kern::RoundToPageSize(1);
  3815 	LockFragmentation();
  4285 	LockFragmentation();
  3816 	r=Alloc(pageSize*aNumPages);	// alloc pages
  4286 	r=Alloc(pageSize*aNumPages);	// alloc pages
  3817 	UnlockFragmentation();
  4287 	UnlockFragmentation();
  3818 
  4288 
  3819 	if(r==KErrNone)
  4289 	if(r==KErrNone)
  3820 		{
  4290 		{
  3821 		iFragmentGranularity = pageSize * aNumPages;
  4291 		iFragmentGranularity = pageSize * aNumPages;
  3822 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Fragmentation granularity set to 0x%x", iFragmentGranularity));
  4292 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Fragmentation granularity set to 0x%x", iFragmentGranularity));
  3823 		}
  4293 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DFRAGMENTATIONPAGINGLOCK_CONSTRUCT2, "Fragmentation granularity=0x%x", iFragmentGranularity);
  3824 
  4294 		}
       
  4295 
       
  4296 	OstTraceFunctionExitExt( DFRAGMENTATIONPAGINGLOCK_CONSTRUCT_EXIT3, this, r );
  3825 	return r;
  4297 	return r;
  3826 	}
  4298 	}
  3827 
  4299 
  3828 void DFragmentationPagingLock::Cleanup()
  4300 void DFragmentationPagingLock::Cleanup()
  3829 	{
  4301 	{
       
  4302 	OstTraceFunctionEntry1( DFRAGMENTATIONPAGINGLOCK_CLEANUP_ENTRY, this );
  3830 	// in CS
  4303 	// in CS
  3831 	if (iFragmentationMutex)
  4304 	if (iFragmentationMutex)
  3832 		{
  4305 		{
  3833 		LockFragmentation();
  4306 		LockFragmentation();
  3834 		Free();					// at last!
  4307 		Free();					// at last!
  3835 		UnlockFragmentation();
  4308 		UnlockFragmentation();
  3836 		Kern::SafeClose((DObject*&)iFragmentationMutex,NULL);
  4309 		Kern::SafeClose((DObject*&)iFragmentationMutex,NULL);
  3837 		}
  4310 		}
       
  4311 	OstTraceFunctionExit1( DFRAGMENTATIONPAGINGLOCK_CLEANUP_EXIT, this );
  3838 	}
  4312 	}
  3839 
  4313 
  3840 #else
  4314 #else
  3841 #if !defined(__WINS__)
  4315 #if !defined(__WINS__)
  3842 EXPORT_C TInt TLocDrvRequest::WriteToPageHandler(const TAny* , TInt , TInt)
  4316 EXPORT_C TInt TLocDrvRequest::WriteToPageHandler(const TAny* , TInt , TInt)
  3862                 
  4336                 
  3863 @see LocDrv::RegisterMediaDevice()                
  4337 @see LocDrv::RegisterMediaDevice()                
  3864 */
  4338 */
  3865 EXPORT_C DMediaDriver::DMediaDriver(TInt aMediaId)
  4339 EXPORT_C DMediaDriver::DMediaDriver(TInt aMediaId)
  3866 	{
  4340 	{
       
  4341 	OstTraceFunctionEntryExt( DMEDIADRIVER_DMEDIADRIVER_ENTRY, this );
       
  4342 	
  3867 //	iPhysicalDevice=NULL;
  4343 //	iPhysicalDevice=NULL;
  3868 //	iTotalSizeInBytes=0;
  4344 //	iTotalSizeInBytes=0;
  3869 //	iCurrentConsumption=0;
  4345 //	iCurrentConsumption=0;
  3870 //	iPrimaryMedia=NULL;
  4346 //	iPrimaryMedia=NULL;
  3871 //	iCritical=EFalse;
  4347 //	iCritical=EFalse;
  3872 	iPrimaryMedia=(DPrimaryMediaBase*)TheMedia[aMediaId];
  4348 	iPrimaryMedia=(DPrimaryMediaBase*)TheMedia[aMediaId];
       
  4349 	OstTraceFunctionExit1( DMEDIADRIVER_DMEDIADRIVER_EXIT, this );
  3873 	}
  4350 	}
  3874 
  4351 
  3875 
  4352 
  3876 
  4353 
  3877 
  4354 
  3883 
  4360 
  3884 @see DObject::Close()
  4361 @see DObject::Close()
  3885 */
  4362 */
  3886 EXPORT_C DMediaDriver::~DMediaDriver()
  4363 EXPORT_C DMediaDriver::~DMediaDriver()
  3887 	{
  4364 	{
       
  4365 	OstTraceFunctionEntry1( DMEDIADRIVER_DMEDIADRIVER_DESTRUCTOR_ENTRY, this );
  3888 	SetCurrentConsumption(0);
  4366 	SetCurrentConsumption(0);
  3889 	Kern::SafeClose((DObject*&)iPhysicalDevice,NULL);
  4367 	Kern::SafeClose((DObject*&)iPhysicalDevice,NULL);
       
  4368 	OstTraceFunctionExit1( DMEDIADRIVER_DMEDIADRIVER_DESTRUCTOR_EXIT, this );
  3890 	}
  4369 	}
  3891 
  4370 
  3892 
  4371 
  3893 
  4372 
  3894 
  4373 
  3922 
  4401 
  3923 @see DMediaDriver::PartitionInfo()
  4402 @see DMediaDriver::PartitionInfo()
  3924 */
  4403 */
  3925 EXPORT_C void DMediaDriver::SetTotalSizeInBytes(Int64 aTotalSizeInBytes, TLocDrv* aLocDrv)
  4404 EXPORT_C void DMediaDriver::SetTotalSizeInBytes(Int64 aTotalSizeInBytes, TLocDrv* aLocDrv)
  3926 	{
  4405 	{
       
  4406 	OstTraceFunctionEntry1( DMEDIADRIVER_SETTOTALSIZEINBYTES_ENTRY, this );
  3927 	iTotalSizeInBytes=aTotalSizeInBytes;
  4407 	iTotalSizeInBytes=aTotalSizeInBytes;
  3928 	if (aLocDrv)
  4408 	if (aLocDrv)
  3929 		aLocDrv->iPartitionLen=aTotalSizeInBytes;
  4409 		aLocDrv->iPartitionLen=aTotalSizeInBytes;
       
  4410 	OstTraceFunctionExit1( DMEDIADRIVER_SETTOTALSIZEINBYTES_EXIT, this );
  3930 	}
  4411 	}
  3931 
  4412 
  3932 
  4413 
  3933 
  4414 
  3934 
  4415 
  3960         
  4441         
  3961 @see DMediaDriver::EndInCritical()
  4442 @see DMediaDriver::EndInCritical()
  3962 */
  4443 */
  3963 EXPORT_C TInt DMediaDriver::InCritical()
  4444 EXPORT_C TInt DMediaDriver::InCritical()
  3964 	{
  4445 	{
       
  4446 	OstTraceFunctionEntry1( DMEDIADRIVER_INCRITICAL_ENTRY, this );
  3965 	if (!iCritical)
  4447 	if (!iCritical)
  3966 		{
  4448 		{
  3967 		TInt r=iPrimaryMedia->InCritical();
  4449 		TInt r=iPrimaryMedia->InCritical();
  3968 		if (r!=KErrNone)
  4450 		if (r!=KErrNone)
       
  4451 		    {
       
  4452 			OstTraceFunctionExitExt( DMEDIADRIVER_INCRITICAL_EXIT, this, r );
  3969 			return r;
  4453 			return r;
       
  4454 		    }
  3970 		iCritical=ETrue;
  4455 		iCritical=ETrue;
  3971 		}
  4456 		}
       
  4457 	OstTraceFunctionExitExt( DMEDIADRIVER_INCRITICAL_EXIT2, this, KErrNone );
  3972 	return KErrNone;
  4458 	return KErrNone;
  3973 	}
  4459 	}
  3974 
  4460 
  3975 
  4461 
  3976 
  4462 
  3980 
  4466 
  3981 @see DMediaDriver::InCritical()
  4467 @see DMediaDriver::InCritical()
  3982 */
  4468 */
  3983 EXPORT_C void DMediaDriver::EndInCritical()
  4469 EXPORT_C void DMediaDriver::EndInCritical()
  3984 	{
  4470 	{
       
  4471 	OstTraceFunctionEntry1( DMEDIADRIVER_ENDINCRITICAL_ENTRY, this );
  3985 	if (iCritical)
  4472 	if (iCritical)
  3986 		{
  4473 		{
  3987 		iCritical=EFalse;
  4474 		iCritical=EFalse;
  3988 		iPrimaryMedia->EndInCritical();
  4475 		iPrimaryMedia->EndInCritical();
  3989 		}
  4476 		}
       
  4477 	OstTraceFunctionExit1( DMEDIADRIVER_ENDINCRITICAL_EXIT, this );
  3990 	}
  4478 	}
  3991 
  4479 
  3992 
  4480 
  3993 
  4481 
  3994 
  4482 
  3995 /**
  4483 /**
  3996 @internalComponent
  4484 @internalComponent
  3997 */
  4485 */
  3998 EXPORT_C void DMediaDriver::SetCurrentConsumption(TInt aValue)
  4486 EXPORT_C void DMediaDriver::SetCurrentConsumption(TInt aValue)
  3999 	{
  4487 	{
       
  4488 	OstTraceFunctionEntryExt( DMEDIADRIVER_SETCURRENTCONSUMPTION_ENTRY, this );
  4000 	TInt old = (TInt)__e32_atomic_swp_ord32(&iCurrentConsumption, aValue);
  4489 	TInt old = (TInt)__e32_atomic_swp_ord32(&iCurrentConsumption, aValue);
  4001 	TInt delta = aValue - old;
  4490 	TInt delta = aValue - old;
  4002 	iPrimaryMedia->DeltaCurrentConsumption(delta);
  4491 	iPrimaryMedia->DeltaCurrentConsumption(delta);
       
  4492 	OstTraceFunctionExit1( DMEDIADRIVER_SETCURRENTCONSUMPTION_EXIT, this );
  4003 	}
  4493 	}
  4004 
  4494 
  4005 
  4495 
  4006 
  4496 
  4007 
  4497 
  4013                is KErrNone to report success, or one of the other system-wide
  4503                is KErrNone to report success, or one of the other system-wide
  4014                error codes to report failure or other problems.
  4504                error codes to report failure or other problems.
  4015 */
  4505 */
  4016 EXPORT_C void DMediaDriver::Complete(TLocDrvRequest& m, TInt aResult)
  4506 EXPORT_C void DMediaDriver::Complete(TLocDrvRequest& m, TInt aResult)
  4017 	{
  4507 	{
       
  4508 	OstTraceExt2( TRACE_FLOW, DMEDIADRIVER_COMPLETE_ENTRY, "m=%x;aResult=%d", (TUint) &m, aResult );
  4018 	CHECK_RET(aResult);
  4509 	CHECK_RET(aResult);
  4019 #ifdef __DEMAND_PAGING__
  4510 #ifdef __DEMAND_PAGING__
  4020 	if (DMediaPagingDevice::PagingRequest(m))
  4511 	if (DMediaPagingDevice::PagingRequest(m))
  4021 		{
  4512 		{
  4022 		__ASSERT_ALWAYS(iPrimaryMedia && iPrimaryMedia->iPagingMedia && iPrimaryMedia->iBody->iPagingDevice,LOCM_FAULT());
  4513 		__ASSERT_ALWAYS(iPrimaryMedia && iPrimaryMedia->iPagingMedia && iPrimaryMedia->iBody->iPagingDevice,LOCM_FAULT());
  4030 	
  4521 	
  4031 	if (&m == iPrimaryMedia->iCurrentReq)	// Complete() called on request serviced synchronously
  4522 	if (&m == iPrimaryMedia->iCurrentReq)	// Complete() called on request serviced synchronously
  4032 		iPrimaryMedia->iCurrentReq = NULL;
  4523 		iPrimaryMedia->iCurrentReq = NULL;
  4033 
  4524 
  4034 	iPrimaryMedia->RunDeferred();
  4525 	iPrimaryMedia->RunDeferred();
       
  4526 	OstTraceFunctionExit1( DMEDIADRIVER_COMPLETE_EXIT, this );
  4035 	}
  4527 	}
  4036 
  4528 
  4037 
  4529 
  4038 
  4530 
  4039  
  4531  
  4049 @param anError KErrNone if successful, otherwise one of the other system wide
  4541 @param anError KErrNone if successful, otherwise one of the other system wide
  4050        error codes.
  4542        error codes.
  4051 */
  4543 */
  4052 EXPORT_C void DMediaDriver::OpenMediaDriverComplete(TInt anError)
  4544 EXPORT_C void DMediaDriver::OpenMediaDriverComplete(TInt anError)
  4053 	{
  4545 	{
       
  4546 	OstTraceFunctionEntry1( DMEDIADRIVER_OPENMEDIADRIVERCOMPLETE_ENTRY, this );
  4054 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DMediaDriver::OpenMediaDriverComplete(%d) this %x iPrimaryMedia %x", anError, this, iPrimaryMedia));
  4547 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DMediaDriver::OpenMediaDriverComplete(%d) this %x iPrimaryMedia %x", anError, this, iPrimaryMedia));
       
  4548 	OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_MEDIACHANGE, DMEDIADRIVER_OPENMEDIADRIVERCOMPLETE, "anError %d this 0x%x iPrimaryMedia 0x%x", anError, (TUint) this, (TUint) iPrimaryMedia);
  4055 	DPrimaryMediaBase* pM=iPrimaryMedia;
  4549 	DPrimaryMediaBase* pM=iPrimaryMedia;
  4056 	pM->iAsyncErrorCode=anError;
  4550 	pM->iAsyncErrorCode=anError;
  4057 	pM->iAsyncDfc.Enque();
  4551 	pM->iAsyncDfc.Enque();
       
  4552 	OstTraceFunctionExit1( DMEDIADRIVER_OPENMEDIADRIVERCOMPLETE_EXIT, this );
  4058 	}
  4553 	}
  4059 
  4554 
  4060 
  4555 
  4061 
  4556 
  4062 
  4557 
  4072 
  4567 
  4073 @see DMediaDriver::PartitionInfo()
  4568 @see DMediaDriver::PartitionInfo()
  4074 */
  4569 */
  4075 EXPORT_C void DMediaDriver::PartitionInfoComplete(TInt anError)
  4570 EXPORT_C void DMediaDriver::PartitionInfoComplete(TInt anError)
  4076 	{
  4571 	{
       
  4572 	OstTraceFunctionEntry1( DMEDIADRIVER_PARTITIONINFOCOMPLETE_ENTRY, this );
  4077 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DMediaDriver::PartitionInfoComplete(%d) anError %d this %x iPrimaryMedia %x", anError, this, iPrimaryMedia));
  4573 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DMediaDriver::PartitionInfoComplete(%d) anError %d this %x iPrimaryMedia %x", anError, this, iPrimaryMedia));
       
  4574 	OstTraceExt3( TRACE_INTERNALS, DMDEDIADRIVER_PARTITIONINFOCOMPLETE, "anError=%d; this=%x; iPrimaryMedia=%x", anError, (TUint) this, (TUint) iPrimaryMedia );
  4078 	DPrimaryMediaBase* pM=iPrimaryMedia;
  4575 	DPrimaryMediaBase* pM=iPrimaryMedia;
  4079 	pM->iAsyncErrorCode=anError;
  4576 	pM->iAsyncErrorCode=anError;
  4080 	pM->iAsyncDfc.Enque();
  4577 	pM->iAsyncDfc.Enque();
       
  4578 	OstTraceFunctionExit1( DMEDIADRIVER_PARTITIONINFOCOMPLETE_EXIT, this );
  4081 	}
  4579 	}
  4082 
  4580 
  4083 
  4581 
  4084 
  4582 
  4085 
  4583 
  4087 @internalComponent
  4585 @internalComponent
  4088 */
  4586 */
  4089 // Default implementation
  4587 // Default implementation
  4090 EXPORT_C void DMediaDriver::Disconnect(DLocalDrive* aLocalDrive, TThreadMessage* aMsg)
  4588 EXPORT_C void DMediaDriver::Disconnect(DLocalDrive* aLocalDrive, TThreadMessage* aMsg)
  4091 	{
  4589 	{
       
  4590 	OstTraceFunctionEntryExt( DMEDIADRIVER_DISCONNECT_ENTRY, this );
  4092 	// don't need to worry about DLocalDrive going away
  4591 	// don't need to worry about DLocalDrive going away
  4093 	aLocalDrive->Deque();
  4592 	aLocalDrive->Deque();
  4094 
  4593 
  4095 	aMsg->Complete(KErrNone, EFalse);
  4594 	aMsg->Complete(KErrNone, EFalse);
       
  4595 	OstTraceFunctionExit1( DMEDIADRIVER_DISCONNECT_EXIT, this );
  4096 	}
  4596 	}
  4097 
  4597 
  4098 
  4598 
  4099 
  4599 
  4100 
  4600 
  4135                      KErrNoMemory, if there is insufficient memory;
  4635                      KErrNoMemory, if there is insufficient memory;
  4136                      or one of the other system-wide error codes.  
  4636                      or one of the other system-wide error codes.  
  4137 */
  4637 */
  4138 EXPORT_C TInt LocDrv::RegisterMediaDevice(TMediaDevice aDevice, TInt aDriveCount, const TInt* aDriveList, DPrimaryMediaBase* aPrimaryMedia, TInt aNumMedia, const TDesC& aName)
  4638 EXPORT_C TInt LocDrv::RegisterMediaDevice(TMediaDevice aDevice, TInt aDriveCount, const TInt* aDriveList, DPrimaryMediaBase* aPrimaryMedia, TInt aNumMedia, const TDesC& aName)
  4139 	{
  4639 	{
       
  4640 	OstTraceFunctionEntry0( LOCDRV_REGISTERMEDIADEVICE_ENTRY );
  4140 	// Create TLocDrv / DMedia objects to handle a media device
  4641 	// Create TLocDrv / DMedia objects to handle a media device
  4141 	__KTRACE_OPT(KBOOT,Kern::Printf("RegisterMediaDevice %lS dev=%1d #drives=%d 1st=%d PM=%08x #media=%d",&aName,aDevice,aDriveCount,*aDriveList,aPrimaryMedia,aNumMedia));
  4642 	__KTRACE_OPT(KBOOT,Kern::Printf("RegisterMediaDevice %lS dev=%1d #drives=%d 1st=%d PM=%08x #media=%d",&aName,aDevice,aDriveCount,*aDriveList,aPrimaryMedia,aNumMedia));
       
  4643 	OstTraceExt5( TRACE_INTERNALS, LOCDRV_REGISTERMEDIADEVICE1, "aDevice=%d; aDriveCount=%d; aDriveList=%d; aPrimaryMedia=0x%08x; aNumMedia=%d", (TInt) aDevice, (TInt) aDriveCount, (TInt) *aDriveList, (TUint) aPrimaryMedia, (TInt) aNumMedia );
       
  4644 	
  4142 	const TInt* p=aDriveList;
  4645 	const TInt* p=aDriveList;
  4143 	TInt i;
  4646 	TInt i;
  4144 	TInt r=0;
  4647 	TInt r=0;
  4145 	if (UsedMedia+aNumMedia>KMaxLocalDrives)
  4648 	if (UsedMedia+aNumMedia>KMaxLocalDrives)
       
  4649 	    {
       
  4650 		OstTrace0(TRACE_FLOW, LOCDRV_REGISTERMEDIADEVICE_EXIT1, "< KErrInUse");
  4146 		return KErrInUse;
  4651 		return KErrInUse;
       
  4652 	    }
  4147 	for (i=0; i<aDriveCount; ++i)
  4653 	for (i=0; i<aDriveCount; ++i)
  4148 		{
  4654 		{
  4149 		TInt drv = *p++;
  4655 		TInt drv = *p++;
  4150 		// -1 means not used; this is to enable Dual-slot MMC support 
  4656 		// -1 means not used; this is to enable Dual-slot MMC support 
  4151 		if (drv == -1)
  4657 		if (drv == -1)
  4152 			continue;
  4658 			continue;
  4153 		__KTRACE_OPT(KBOOT,Kern::Printf("Registering drive %d", drv));
  4659 		__KTRACE_OPT(KBOOT,Kern::Printf("Registering drive %d", drv));
       
  4660 		OstTrace1( TRACE_INTERNALS, LOCDRV_REGISTERMEDIADEVICE2, "Registering drive=%d", drv );
  4154 		if (TheDrives[drv])
  4661 		if (TheDrives[drv])
  4155 			{
  4662 			{
  4156 			__KTRACE_OPT(KBOOT,Kern::Printf("Drive %d already in use", drv));
  4663 			__KTRACE_OPT(KBOOT,Kern::Printf("Drive %d already in use", drv));
       
  4664 			OstTrace1( TRACE_FLOW, LOCDRV_REGISTERMEDIADEVICE_EXIT2, "< Drive %d already in use; KErrInUse", drv);
  4157 			return KErrInUse;
  4665 			return KErrInUse;
  4158 			}
  4666 			}
  4159 		}
  4667 		}
  4160 	HBuf* pN=HBuf::New(aName);
  4668 	HBuf* pN=HBuf::New(aName);
  4161 	if (!pN)
  4669 	if (!pN)
       
  4670 	    {
       
  4671         OstTrace0(TRACE_FLOW, LOCDRV_REGISTERMEDIADEVICE_EXIT3, "< KErrNoMemory");
  4162 		return KErrNoMemory;
  4672 		return KErrNoMemory;
       
  4673 	    }
  4163 	TInt lastMedia=UsedMedia+aNumMedia-1;
  4674 	TInt lastMedia=UsedMedia+aNumMedia-1;
  4164 	for (i=UsedMedia; i<=lastMedia; ++i)
  4675 	for (i=UsedMedia; i<=lastMedia; ++i)
  4165 		{
  4676 		{
  4166 		if (i==UsedMedia)
  4677 		if (i==UsedMedia)
  4167 			TheMedia[i]=aPrimaryMedia;
  4678 			TheMedia[i]=aPrimaryMedia;
  4168 		else
  4679 		else
  4169 			TheMedia[i]=new DMedia;
  4680 			TheMedia[i]=new DMedia;
  4170 		if (!TheMedia[i])
  4681 		if (!TheMedia[i])
       
  4682 		    {
       
  4683              OstTrace0(TRACE_FLOW, LOCDRV_REGISTERMEDIADEVICE_EXIT4, "< KErrNoMemory");
  4171 			return KErrNoMemory;
  4684 			return KErrNoMemory;
       
  4685 		    }
  4172 		r=TheMedia[i]->Create(aDevice,i,lastMedia);
  4686 		r=TheMedia[i]->Create(aDevice,i,lastMedia);
  4173 		__KTRACE_OPT(KBOOT,Kern::Printf("Media %d Create() returns %d",i,r));
  4687 		__KTRACE_OPT(KBOOT,Kern::Printf("Media %d Create() returns %d",i,r));
       
  4688 		OstTraceExt2( TRACE_INTERNALS, LOCDRV_REGISTERMEDIADEVICE3, "Media=%d Create(); retval=%d", i, r );
  4174 		if (r!=KErrNone)
  4689 		if (r!=KErrNone)
       
  4690 		    {
       
  4691             OstTrace1(TRACE_FLOW, LOCDRV_REGISTERMEDIADEVICE_EXIT5, "< retval=%d", r);
  4175 			return r;
  4692 			return r;
       
  4693 		    }
  4176 		}
  4694 		}
  4177 
  4695 
  4178 	__KTRACE_OPT(KBOOT,Kern::Printf("FirstMedia %d LastMedia %d",UsedMedia,lastMedia));
  4696 	__KTRACE_OPT(KBOOT,Kern::Printf("FirstMedia %d LastMedia %d",UsedMedia,lastMedia));
       
  4697 	OstTraceExt2( TRACE_INTERNALS, LOCDRV_REGISTERMEDIADEVICE4, "FirstMedia=%d; LastMedia=%d", UsedMedia, lastMedia );
  4179 	UsedMedia+=aNumMedia;
  4698 	UsedMedia+=aNumMedia;
  4180 	p=aDriveList;
  4699 	p=aDriveList;
  4181 	for (i=0; i<aDriveCount; ++i)
  4700 	for (i=0; i<aDriveCount; ++i)
  4182 		{
  4701 		{
  4183 		TInt drv=*p++;
  4702 		TInt drv=*p++;
  4184 		if (drv == -1)
  4703 		if (drv == -1)
  4185 			continue;
  4704 			continue;
  4186 		TLocDrv* pL=new TLocDrv(drv);
  4705 		TLocDrv* pL=new TLocDrv(drv);
  4187 		if (!pL)
  4706 		if (!pL)
       
  4707 		    {
       
  4708             OstTrace0(TRACE_FLOW, LOCDRV_REGISTERMEDIADEVICE_EXIT6, "< KErrNoMemory");
  4188 			return KErrNoMemory;
  4709 			return KErrNoMemory;
       
  4710 		    }
  4189 		TheDrives[drv]=pL;
  4711 		TheDrives[drv]=pL;
  4190 		DriveNames[drv]=pN;
  4712 		DriveNames[drv]=pN;
  4191 		pL->iPrimaryMedia=aPrimaryMedia;
  4713 		pL->iPrimaryMedia=aPrimaryMedia;
  4192 		__KTRACE_OPT(KBOOT,Kern::Printf("Drive %d: TLocDrv @ %08x",drv,pL));
  4714 		__KTRACE_OPT(KBOOT,Kern::Printf("Drive %d: TLocDrv @ %08x",drv,pL));
  4193 		}
  4715 		OstTraceExt2( TRACE_INTERNALS, LOCDRV_REGISTERMEDIADEVICE5, "Drive=%d; TLocDrv 0x%08x;", (TInt) drv, (TUint) pL );
       
  4716 		}
       
  4717 
       
  4718 	OstTraceFunctionExit0( LOCDRV_REGISTERMEDIADEVICE_EXIT7 );
  4194 	return KErrNone;
  4719 	return KErrNone;
  4195 	}
  4720 	}
  4196 
  4721 
  4197 
  4722 
  4198 
  4723 
  4208 @return KErrNone, if successful;
  4733 @return KErrNone, if successful;
  4209         KErrAlreadyExists, if a password store has already been registered.
  4734         KErrAlreadyExists, if a password store has already been registered.
  4210 */ 
  4735 */ 
  4211 EXPORT_C TInt LocDrv::RegisterPasswordStore(TPasswordStore* aStore)
  4736 EXPORT_C TInt LocDrv::RegisterPasswordStore(TPasswordStore* aStore)
  4212 	{
  4737 	{
       
  4738 	OstTraceFunctionEntry0( LOCDRV_REGISTERPASSWORDSTORE_ENTRY );
  4213 	// Create TLocDrv / DMedia objects to handle a media device
  4739 	// Create TLocDrv / DMedia objects to handle a media device
  4214 	__KTRACE_OPT(KBOOT,Kern::Printf("RegisterPasswordStore"));
  4740 	__KTRACE_OPT(KBOOT,Kern::Printf("RegisterPasswordStore"));
  4215 
  4741 	
  4216 	TInt r = KErrNone;
  4742 	TInt r = KErrNone;
  4217 
  4743 
  4218 	if(ThePasswordStore == NULL)
  4744 	if(ThePasswordStore == NULL)
  4219 		ThePasswordStore = aStore;
  4745 		ThePasswordStore = aStore;
  4220 	else
  4746 	else
  4221 		r = KErrAlreadyExists;
  4747 		r = KErrAlreadyExists;
  4222 
  4748 	OstTrace1(TRACE_INTERNALS, LOCDRV_REGISTERPASSWORDSTORE, "retval=%d", r);
       
  4749 	OstTraceFunctionExit0( LOCDRV_REGISTERPASSWORDSTORE_EXIT );
  4223 	return r;
  4750 	return r;
  4224 	}
  4751 	}
  4225 
  4752 
  4226 /**
  4753 /**
  4227 Returns a pointer to the registered password store.
  4754 Returns a pointer to the registered password store.
  4232 */ 
  4759 */ 
  4233 EXPORT_C TPasswordStore* LocDrv::PasswordStore()
  4760 EXPORT_C TPasswordStore* LocDrv::PasswordStore()
  4234 	{
  4761 	{
  4235 	return ThePasswordStore;
  4762 	return ThePasswordStore;
  4236 	}
  4763 	}
  4237 
       
  4238 
  4764 
  4239 #ifdef __DEMAND_PAGING__
  4765 #ifdef __DEMAND_PAGING__
  4240 /**
  4766 /**
  4241 Registers a paging device with the Local Media Subsystem, and provides
  4767 Registers a paging device with the Local Media Subsystem, and provides
  4242 information about drive numbers used in Code Paging.
  4768 information about drive numbers used in Code Paging.
  4270                      KErrNoMemory, if there is insufficient memory;
  4796                      KErrNoMemory, if there is insufficient memory;
  4271                      or one of the other system-wide error codes.  
  4797                      or one of the other system-wide error codes.  
  4272 */
  4798 */
  4273 EXPORT_C TInt LocDrv::RegisterPagingDevice(DPrimaryMediaBase* aPrimaryMedia, const TInt* aPagingDriveList, TInt aDriveCount, TUint aPagingType, TInt aReadShift, TUint aNumPages)
  4799 EXPORT_C TInt LocDrv::RegisterPagingDevice(DPrimaryMediaBase* aPrimaryMedia, const TInt* aPagingDriveList, TInt aDriveCount, TUint aPagingType, TInt aReadShift, TUint aNumPages)
  4274 	{
  4800 	{
       
  4801 	OstTraceFunctionEntry0( LOCDRV_REGISTERPAGINGDEVICE_ENTRY );
       
  4802 	
  4275 	__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf(">RegisterPagingDevice: paging type=%d PM=0x%x read shift=%d",aPagingType,aPrimaryMedia,aReadShift));
  4803 	__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf(">RegisterPagingDevice: paging type=%d PM=0x%x read shift=%d",aPagingType,aPrimaryMedia,aReadShift));
       
  4804 	OstTraceDefExt3( OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, LOCDRV_REGISTERPAGINGDEVICE1, "aPagingType=%d; aPrimaryMedia=0x%x; aReadShift=%d", (TInt) aPagingType, (TUint) aPrimaryMedia, (TInt) aReadShift);
       
  4805 	
  4276 	TInt i;
  4806 	TInt i;
  4277 
  4807 
  4278 	if(!aPagingType || (aPagingType&~(DPagingDevice::ERom | DPagingDevice::ECode | DPagingDevice::EData)))
  4808 	if(!aPagingType || (aPagingType&~(DPagingDevice::ERom | DPagingDevice::ECode | DPagingDevice::EData)))
  4279 		{
  4809 		{
  4280 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Unsupported paging type, exiting"));
  4810 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Unsupported paging type, exiting"));
       
  4811 		OstTrace0(TRACE_FLOW, LOVDRV_REGISTERPAGINGDEVICE_EXIT1, "< Unsupported paging type; KErrArgument");
  4281 		return KErrArgument;
  4812 		return KErrArgument;
  4282 		}
  4813 		}
  4283 
  4814 
  4284 
  4815 
  4285 
  4816 
  4302 
  4833 
  4303 	if (aPagingType == 0)
  4834 	if (aPagingType == 0)
  4304 		{
  4835 		{
  4305 		// there's already a ROM or Data paging device & this doesn't support code paging so quietly exit without further addo
  4836 		// there's already a ROM or Data paging device & this doesn't support code paging so quietly exit without further addo
  4306 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Nothing left to register on locdrv no %d, exiting",i));
  4837 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Nothing left to register on locdrv no %d, exiting",i));
       
  4838 		OstTrace1(TRACE_FLOW, LOVDRV_REGISTERPAGINGDEVICE_EXIT2, "< Nothing left to register on locdrv no %d; KErrNone",i);
  4307 		return KErrNone;
  4839 		return KErrNone;
  4308 		}
  4840 		}
  4309 
  4841 
  4310 	const TInt* p=aPagingDriveList;
  4842 	const TInt* p=aPagingDriveList;
  4311 	if(aPagingType&DPagingDevice::ECode)	// supports code paging, do argument check
  4843 	if(aPagingType&DPagingDevice::ECode)	// supports code paging, do argument check
  4312 		{
  4844 		{
  4313 		if(!aDriveCount || (aDriveCount>=KMaxLocalDrives))
  4845 		if(!aDriveCount || (aDriveCount>=KMaxLocalDrives))
  4314 			{
  4846 			{
  4315 			__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Invalid code paging drive count: %d", aDriveCount));
  4847 			__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Invalid code paging drive count: %d", aDriveCount));
       
  4848 			OstTrace1(TRACE_FLOW, LOVDRV_REGISTERPAGINGDEVICE_EXIT3, "< Invalid code paging drive count=%d; KErrArgument", aDriveCount);
  4316 			return KErrArgument;
  4849 			return KErrArgument;
  4317 			}
  4850 			}
  4318 
  4851 
  4319 		TInt drvCount=0;
  4852 		TInt drvCount=0;
  4320 		for(i=0; i<KMaxLocalDrives; i++)
  4853 		for(i=0; i<KMaxLocalDrives; i++)
  4321 			if(TheDrives[i] && TheDrives[i]->iPrimaryMedia==aPrimaryMedia)
  4854 			if(TheDrives[i] && TheDrives[i]->iPrimaryMedia==aPrimaryMedia)
  4322 				drvCount++;
  4855 				drvCount++;
  4323 		if(aDriveCount>drvCount)	// can't exceed number of drives registered by this device
  4856 		if(aDriveCount>drvCount)	// can't exceed number of drives registered by this device
  4324 			{
  4857 			{
  4325 			__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Invalid code paging drive count: %d total %d", aDriveCount, drvCount));
  4858 			__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Invalid code paging drive count=%d; total=%d", aDriveCount, drvCount));
       
  4859 			OstTraceExt2(TRACE_FLOW, LOVDRV_REGISTERPAGINGDEVICE_EXIT4, "< Invalid code paging drive count=%d; total=%d; KErrArgument", aDriveCount, drvCount);
  4326 			return KErrArgument;
  4860 			return KErrArgument;
  4327 			}
  4861 			}
  4328 
  4862 
  4329 		for (i=0; i<aDriveCount; ++i)
  4863 		for (i=0; i<aDriveCount; ++i)
  4330 			{
  4864 			{
  4331 			__KTRACE_OPT(KBOOT,Kern::Printf("RegisterPagingDevice: registering drive=%d ",*p));
  4865 			__KTRACE_OPT(KBOOT,Kern::Printf("RegisterPagingDevice: registering drive=%d ",*p));
       
  4866 			OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, LOCDRV_REGISTERPAGINGDEVICE2, "Registering Drive=%d", *p );
  4332 			TInt drv=*p++;
  4867 			TInt drv=*p++;
  4333 			if(drv>=KMaxLocalDrives)
  4868 			if(drv>=KMaxLocalDrives)
  4334 				{
  4869 				{
  4335 				__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Invalid code paging drive number: %d", drv));
  4870 				__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("Invalid code paging drive number: %d", drv));
       
  4871 				OstTrace1(TRACE_FLOW, LOVDRV_REGISTERPAGINGDEVICE_EXIT5, "< Invalid code paging drive number=%d; KErrArgument", drv);
  4336 				return KErrArgument;
  4872 				return KErrArgument;
  4337 				}
  4873 				}
  4338 			TLocDrv* pD=TheDrives[drv];
  4874 			TLocDrv* pD=TheDrives[drv];
  4339 			if (!pD)
  4875 			if (!pD)
       
  4876 			    {
       
  4877                 OstTrace0(TRACE_FLOW, LOCRV_REGISTERPAGINGDEVICE_EXIT6, "< KErrNotFound");
  4340 				return KErrNotFound;
  4878 				return KErrNotFound;
       
  4879 			    }
  4341 			if (pD->iPrimaryMedia!=aPrimaryMedia)
  4880 			if (pD->iPrimaryMedia!=aPrimaryMedia)
       
  4881 			    {
       
  4882                 OstTrace0(TRACE_FLOW, LOCRV_REGISTERPAGINGDEVICE_EXIT7, "< KErrNotSupported");
  4342 				return KErrNotSupported;
  4883 				return KErrNotSupported;
       
  4884 			    }
  4343 			}
  4885 			}
  4344 		}
  4886 		}
  4345 
  4887 
  4346 
  4888 
  4347 	TInt firstLocalDriveNumber = KErrNotFound; 
  4889 	TInt firstLocalDriveNumber = KErrNotFound; 
  4358 			firstLocalDriveNumber = i;
  4900 			firstLocalDriveNumber = i;
  4359 			break;
  4901 			break;
  4360 			}
  4902 			}
  4361 		}
  4903 		}
  4362 	__ASSERT_ALWAYS(i < KMaxLocalDrives, LOCM_FAULT());
  4904 	__ASSERT_ALWAYS(i < KMaxLocalDrives, LOCM_FAULT());
  4363 	__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("DMediaPagingDevice(), firstLocalDriveNumber %d", firstLocalDriveNumber)); 
  4905 	__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("DMediaPagingDevice(), firstLocalDriveNumber %d", firstLocalDriveNumber));
  4364 
  4906 	OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, LOCDRV_REGISTERPAGINGDEVICE3, "firstLocalDriveNumber=%d", firstLocalDriveNumber );
  4365 
  4907 	
  4366 	// Send an ECaps message to wake up the media driver & ensure all partitions are 
  4908 	// Send an ECaps message to wake up the media driver & ensure all partitions are 
  4367 	// reported, then search for paged-data or paged-ROM partitions
  4909 	// reported, then search for paged-data or paged-ROM partitions
  4368 	if ((aPagingType & DPagingDevice::EData) ||
  4910 	if ((aPagingType & DPagingDevice::EData) ||
  4369 		(aPagingType & DPagingDevice::ERom && aPrimaryMedia->iDfcQ && aPrimaryMedia->iMsgQ.iReady))
  4911 		(aPagingType & DPagingDevice::ERom && aPrimaryMedia->iDfcQ && aPrimaryMedia->iMsgQ.iReady))
  4370 		{
  4912 		{
  4371 		// the message queue must have been started already (by the media driver calling iMsgQ.Receive())
  4913 		// the message queue must have been started already (by the media driver calling iMsgQ.Receive())
  4372 		// otherwise we can't send the DLocalDrive::EQueryDevice request
  4914 		// otherwise we can't send the DLocalDrive::EQueryDevice request
  4373 		if (aPrimaryMedia->iDfcQ && !aPrimaryMedia->iMsgQ.iReady)
  4915 		if (aPrimaryMedia->iDfcQ && !aPrimaryMedia->iMsgQ.iReady)
  4374 			{
  4916 			{
  4375 			__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: Message queue not started"));
  4917 			__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: Message queue not started"));
       
  4918 			OstTrace0(TRACE_FLOW, LOVDRV_REGISTERPAGINGDEVICE_EXIT8, "< RegisterPagingDevice: Message queue not started; KErrNotReady");
  4376 			return KErrNotReady;
  4919 			return KErrNotReady;
  4377 			}
  4920 			}
  4378 
  4921 
  4379 
  4922 
  4380 		TLocDrvRequest m;
  4923 		TLocDrvRequest m;
  4397 			m.Length() = KMaxLocalDriveCapsLength;	// for pinning
  4940 			m.Length() = KMaxLocalDriveCapsLength;	// for pinning
  4398 			r = aPrimaryMedia->Request(m);
  4941 			r = aPrimaryMedia->Request(m);
  4399 
  4942 
  4400 //Kern::Printf("EQueryPageDeviceInfo: i %d: r %d ", i, r);
  4943 //Kern::Printf("EQueryPageDeviceInfo: i %d: r %d ", i, r);
  4401 			__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("Paging device ECaps: i %d: r %d ", i, r));
  4944 			__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("Paging device ECaps: i %d: r %d ", i, r));
       
  4945 			OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, LOCDRV_REGISTERPAGINGDEVICE4, "Paging device ECaps: i %d retval=%d", i, r);
  4402 			}
  4946 			}
  4403 
  4947 
  4404 		if (r != KErrNone)
  4948 		if (r != KErrNone)
       
  4949 		    {
       
  4950             OstTrace1(TRACE_FLOW, LOCRV_REGISTERPAGINGDEVICE_EXIT9, "< retval=%d",r);
  4405 			return r;
  4951 			return r;
       
  4952 		    }
  4406 
  4953 
  4407 		TLocDrv* drive;
  4954 		TLocDrv* drive;
  4408 		for (i=0; i<KMaxLocalDrives; ++i)
  4955 		for (i=0; i<KMaxLocalDrives; ++i)
  4409 			{
  4956 			{
  4410 			drive = TheDrives[i];
  4957 			drive = TheDrives[i];
  4413 				__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("RegisterPagingDevice: local drive %d, partition type %x size %x", i, drive->iPartitionType, I64LOW(drive->iPartitionLen)));
  4960 				__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("RegisterPagingDevice: local drive %d, partition type %x size %x", i, drive->iPartitionType, I64LOW(drive->iPartitionLen)));
  4414 				// ROM partition ?
  4961 				// ROM partition ?
  4415 				if ((romPagingDriveNumber == KErrNotFound) && (drive->iPartitionType == KPartitionTypeROM))
  4962 				if ((romPagingDriveNumber == KErrNotFound) && (drive->iPartitionType == KPartitionTypeROM))
  4416 					{
  4963 					{
  4417 					__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("Found ROM partition on local drive %d, size %x", i, I64LOW(drive->iPartitionLen)));
  4964 					__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("Found ROM partition on local drive %d, size %x", i, I64LOW(drive->iPartitionLen)));
       
  4965 					OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, LOCDRV_REGISTERPAGINGDEVICE5, "Found ROM partition on local drive=%d; size=0x%x", (TInt) i, (TUint) I64LOW(drive->iPartitionLen));
  4418 					romPagingDriveNumber = i;
  4966 					romPagingDriveNumber = i;
  4419 					}
  4967 					}
  4420 			    // swap partition ?
  4968 			    // swap partition ?
  4421 				else if ((dataPagingDriveNumber == KErrNotFound) && (drive->iPartitionType == KPartitionTypePagedData))
  4969 				else if ((dataPagingDriveNumber == KErrNotFound) && (drive->iPartitionType == KPartitionTypePagedData))
  4422 					{
  4970 					{
  4423 					__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("Found swap partition on local drive %d, size %x", i, I64LOW(drive->iPartitionLen)));
  4971 					__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("Found swap partition on local drive %d, size %x", i, I64LOW(drive->iPartitionLen)));
       
  4972 					OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, LOCDRV_REGISTERPAGINGDEVICE6, "Found SWAP partition on local drive=%d; size=0x%x", (TInt) i, (TUint) I64LOW(drive->iPartitionLen) );			
  4424 					dataPagingDriveNumber = i;
  4973 					dataPagingDriveNumber = i;
  4425 					swapSize = drive->iPartitionLen >> aReadShift;
  4974 					swapSize = drive->iPartitionLen >> aReadShift;
  4426 					}
  4975 					}
  4427 				}
  4976 				}
  4428 			}
  4977 			}
  4429 
  4978 
  4430 		if (swapSize == 0)
  4979 		if (swapSize == 0)
  4431 			{
  4980 			{
  4432 			__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("Disabling data paging"));
  4981 			__KTRACE_OPT2(KBOOT,KLOCDPAGING, Kern::Printf("Disabling data paging"));
       
  4982 			OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, LOCDRV_REGISTERPAGINGDEVICE7, "Disabling data paging");
  4433 			aPagingType &= ~DPagingDevice::EData;
  4983 			aPagingType &= ~DPagingDevice::EData;
  4434 			}
  4984 			}
  4435 
  4985 
  4436 		}
  4986 		}
  4437 
  4987 
  4439 	// create and set up a DPagingDevice to allow PageIn request servicing
  4989 	// create and set up a DPagingDevice to allow PageIn request servicing
  4440 	DMediaPagingDevice* pagingDevice = new DMediaPagingDevice(aPrimaryMedia);
  4990 	DMediaPagingDevice* pagingDevice = new DMediaPagingDevice(aPrimaryMedia);
  4441 	if(!pagingDevice)
  4991 	if(!pagingDevice)
  4442 		{
  4992 		{
  4443 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: could not create paging device"));
  4993 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: could not create paging device"));
       
  4994 		OstTrace0(TRACE_FLOW, LOVDRV_REGISTERPAGINGDEVICE_EXIT_EXIT10, "< RegisterPagingDevice: could not create paging device; KErrNoMemory");
  4444 		return KErrNoMemory;
  4995 		return KErrNoMemory;
  4445 		}
  4996 		}
  4446 
  4997 
  4447 	pagingDevice->iType = aPagingType;
  4998 	pagingDevice->iType = aPagingType;
  4448 	pagingDevice->iReadUnitShift = aReadShift;
  4999 	pagingDevice->iReadUnitShift = aReadShift;
  4459 	Kern::Printf("iReadUnitShift 0x%x\n", pagingDevice->iReadUnitShift);
  5010 	Kern::Printf("iReadUnitShift 0x%x\n", pagingDevice->iReadUnitShift);
  4460 	Kern::Printf("iFirstLocalDriveNumber 0x%x\n", pagingDevice->iFirstLocalDriveNumber);
  5011 	Kern::Printf("iFirstLocalDriveNumber 0x%x\n", pagingDevice->iFirstLocalDriveNumber);
  4461 	Kern::Printf("iRomPagingDriveNumber 0x%x\n", pagingDevice->iRomPagingDriveNumber);
  5012 	Kern::Printf("iRomPagingDriveNumber 0x%x\n", pagingDevice->iRomPagingDriveNumber);
  4462 	Kern::Printf("iDataPagingDriveNumber 0x%x\n", pagingDevice->iDataPagingDriveNumber);
  5013 	Kern::Printf("iDataPagingDriveNumber 0x%x\n", pagingDevice->iDataPagingDriveNumber);
  4463 	Kern::Printf("iSwapSize 0x%x\n", pagingDevice->iSwapSize);
  5014 	Kern::Printf("iSwapSize 0x%x\n", pagingDevice->iSwapSize);
  4464 #endif
  5015 	#endif
  4465 
  5016 
  4466 
  5017 
  4467 	// This table is indexed by DPagingDevice::TType
  5018 	// This table is indexed by DPagingDevice::TType
  4468 	const char* DeviceName[] = 
  5019 	const char* DeviceName[] = 
  4469 		{
  5020 		{
  4488 	if (ThePinObjectAllocator == NULL)
  5039 	if (ThePinObjectAllocator == NULL)
  4489 		ThePinObjectAllocator = new DPinObjectAllocator();
  5040 		ThePinObjectAllocator = new DPinObjectAllocator();
  4490 	if(!ThePinObjectAllocator)
  5041 	if(!ThePinObjectAllocator)
  4491 		{
  5042 		{
  4492 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: could not create ThePinObjectAllocator"));
  5043 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: could not create ThePinObjectAllocator"));
       
  5044 		OstTrace0(TRACE_FLOW, LOVDRV_REGISTERPAGINGDEVICE_EXIT11, "RegisterPagingDevice: could not create ThePinObjectAllocator; KErrNoMemory");
  4493 		return KErrNoMemory;
  5045 		return KErrNoMemory;
  4494 		}
  5046 		}
  4495 	TInt r = ThePinObjectAllocator->Construct(KDynamicPagingLockCount, aNumPages);
  5047 	TInt r = ThePinObjectAllocator->Construct(KDynamicPagingLockCount, aNumPages);
  4496 	if (r != KErrNone)
  5048 	if (r != KErrNone)
  4497 		{
  5049 		{
  4498 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: could not construct ThePinObjectAllocator"));
  5050 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: could not construct ThePinObjectAllocator"));
       
  5051 		OstTrace1(TRACE_FLOW, LOVDRV_REGISTERPAGINGDEVICE_EXIT12, "< RegisterPagingDevice: could not construct ThePinObjectAllocator; retval=%d",r);
  4499 		return r;
  5052 		return r;
  4500 		}
  5053 		}
  4501 
  5054 
  4502 
  5055 
  4503 	// Register our DPagingDevice with the Kernel
  5056 	// Register our DPagingDevice with the Kernel
  4508 #endif
  5061 #endif
  4509 
  5062 
  4510 	if (r!=KErrNone)
  5063 	if (r!=KErrNone)
  4511 		{
  5064 		{
  4512 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: could not install paging device"));
  5065 		__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("RegisterPagingDevice: could not install paging device"));
       
  5066 		OstTrace1(TRACE_FLOW, LOVDRV_REGISTERPAGINGDEVICE_EXIT13, "< RegisterPagingDevice: could not install paging device; retval=%d", r);
  4513 		delete pagingDevice;
  5067 		delete pagingDevice;
  4514 		return r;
  5068 		return r;
  4515 		}
  5069 		}
  4516 
  5070 
  4517 	// all hunky dory, save paging device and mark our media as pageable
  5071 	// all hunky dory, save paging device and mark our media as pageable
  4550 #endif
  5104 #endif
  4551 	if (!dataPagingSupported)
  5105 	if (!dataPagingSupported)
  4552 		{
  5106 		{
  4553 #ifdef __DEBUG_DEMAND_PAGING__
  5107 #ifdef __DEBUG_DEMAND_PAGING__
  4554 		if (aPagingType & DPagingDevice::EData)
  5108 		if (aPagingType & DPagingDevice::EData)
       
  5109 		    {
  4555 			Kern::Printf("Disabling data paging, not supported in this ROM");
  5110 			Kern::Printf("Disabling data paging, not supported in this ROM");
       
  5111 		    }
  4556 #endif
  5112 #endif
  4557 		aPagingType&= ~DPagingDevice::EData;
  5113 		aPagingType&= ~DPagingDevice::EData;
  4558 		}
  5114 		}
  4559 
  5115 
  4560 
  5116 
  4563 		DataPagingDeviceRegistered = ETrue;
  5119 		DataPagingDeviceRegistered = ETrue;
  4564 		aPrimaryMedia->iDataPagingMedia = 1;
  5120 		aPrimaryMedia->iDataPagingMedia = 1;
  4565 		TheDataPagingMedia = aPrimaryMedia;
  5121 		TheDataPagingMedia = aPrimaryMedia;
  4566 		}
  5122 		}
  4567 
  5123 
  4568 	__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("<RegisterPagingDevice"));
  5124 	__KTRACE_OPT2(KBOOT,KLOCDPAGING,Kern::Printf("< RegisterPagingDevice"));
       
  5125 	OstTraceFunctionExit0( LOCDRV_REGISTERPAGINGDEVICE_EXIT14 );
  4569 	return KErrNone;
  5126 	return KErrNone;
  4570 	}
  5127 	}
  4571 
  5128 
  4572 #else //__DEMAND_PAGING__
  5129 #else //__DEMAND_PAGING__
  4573 
  5130 
  4596 EXPORT_C TInt LocDrv::RegisterDmaDevice(DPrimaryMediaBase* aPrimaryMedia, 
  5153 EXPORT_C TInt LocDrv::RegisterDmaDevice(DPrimaryMediaBase* aPrimaryMedia, 
  4597 										TInt aMediaBlockSize,				// Minimum transfer size (bytes) for the media
  5154 										TInt aMediaBlockSize,				// Minimum transfer size (bytes) for the media
  4598 										TInt aDmaMaxAddressable,			// Max Addressing Range for DMA controller, 0 if None.
  5155 										TInt aDmaMaxAddressable,			// Max Addressing Range for DMA controller, 0 if None.
  4599 										TInt aDmaAlignment)					// DMA Alignment e.g. word alignment required = 2
  5156 										TInt aDmaAlignment)					// DMA Alignment e.g. word alignment required = 2
  4600 	{
  5157 	{
       
  5158 	OstTraceFunctionEntry0( LOCDRV_REGISTERDMADEVICE_ENTRY );
       
  5159 	
  4601 	__KTRACE_OPT(KBOOT ,Kern::Printf("RegisterPhysicalAddrDevice: PM=0x%x BS=%d MaxAddr=%d DMA=%d", 
  5160 	__KTRACE_OPT(KBOOT ,Kern::Printf("RegisterPhysicalAddrDevice: PM=0x%x BS=%d MaxAddr=%d DMA=%d", 
  4602 									aPrimaryMedia, aMediaBlockSize, aDmaMaxAddressable, aDmaAlignment));
  5161 									aPrimaryMedia, aMediaBlockSize, aDmaMaxAddressable, aDmaAlignment));
  4603 
  5162 	OstTraceExt4( TRACE_INTERNALS, LOCDRV_REGISTERDMADEVICE, "aPrimaryMedia=0x%x; aMediaBlockSize=%d; aDmaMaxAddressable=%d; aDmaAlignment=%d", (TUint) aPrimaryMedia, (TInt) aMediaBlockSize, (TInt) aDmaMaxAddressable, (TInt) aDmaAlignment );
       
  5163 	
  4604 	for (TInt i=0; i<KMaxLocalDrives; ++i)
  5164 	for (TInt i=0; i<KMaxLocalDrives; ++i)
  4605 		{
  5165 		{
  4606 		TLocDrv* pL=TheDrives[i];
  5166 		TLocDrv* pL=TheDrives[i];
  4607 		if (pL && pL->iPrimaryMedia == aPrimaryMedia && pL->iDmaHelper == NULL)
  5167 		if (pL && pL->iPrimaryMedia == aPrimaryMedia && pL->iDmaHelper == NULL)
  4608 			{
  5168 			{
  4615 			TInt r = pL->iDmaHelper->Construct(MaxAddress, aMediaBlockSize, aDmaAlignment);
  5175 			TInt r = pL->iDmaHelper->Construct(MaxAddress, aMediaBlockSize, aDmaAlignment);
  4616 			__ASSERT_ALWAYS(r == KErrNone, LOCM_FAULT());
  5176 			__ASSERT_ALWAYS(r == KErrNone, LOCM_FAULT());
  4617 			}
  5177 			}
  4618 		}
  5178 		}
  4619 
  5179 
       
  5180 	OstTraceFunctionExit0( LOCDRV_REGISTERDMADEVICE_EXIT );
  4620 	return KErrNone;
  5181 	return KErrNone;
  4621 	}
  5182 	}
  4622 
  5183 
  4623 void GetDriveInfo(TDriveInfoV1& info)
  5184 void GetDriveInfo(TDriveInfoV1& info)
  4624 	{
  5185 	{
       
  5186 	OstTraceFunctionEntry1( GETDRIVEINFO_ENTRY, ( TUint )&( info ) );
  4625 	TInt i;
  5187 	TInt i;
  4626 	TInt drives=0;
  5188 	TInt drives=0;
  4627 	TUint32 sock_mask=0;
  5189 	TUint32 sock_mask=0;
  4628 	TInt sockets=0;
  5190 	TInt sockets=0;
  4629 
  5191 
  4643 				{
  5205 				{
  4644 				if (!(sock_mask & (1<<sockNum)))
  5206 				if (!(sock_mask & (1<<sockNum)))
  4645 					{
  5207 					{
  4646 					info.iSocketName[sockNum]=*DriveNames[i];
  5208 					info.iSocketName[sockNum]=*DriveNames[i];
  4647 					__KTRACE_OPT(KLOCDRV,Kern::Printf("Socket %d device %d name %lS", sockNum, pM->iDevice, DriveNames[i]));
  5209 					__KTRACE_OPT(KLOCDRV,Kern::Printf("Socket %d device %d name %lS", sockNum, pM->iDevice, DriveNames[i]));
       
  5210 					OstTraceExt2( TRACE_INTERNALS, GETDRIVEINFO1, "Socket=%d; device=%d", sockNum, (TUint) pM->iDevice );
  4648 					if ( (sockNum + 1) > sockets )
  5211 					if ( (sockNum + 1) > sockets )
  4649 						sockets = sockNum + 1;
  5212 						sockets = sockNum + 1;
  4650 					}
  5213 					}
  4651 				sock_mask |= (1<<sockNum);
  5214 				sock_mask |= (1<<sockNum);
  4652 				}
  5215 				}
  4653 			info.iDriveName[i]=*DriveNames[i];
  5216 			info.iDriveName[i]=*DriveNames[i];
  4654 			__KTRACE_OPT(KLOCDRV,Kern::Printf("Drive %d device %d name %lS",i,pM->iDevice,DriveNames[i]));
  5217 			__KTRACE_OPT(KLOCDRV,Kern::Printf("Drive %d device %d name %lS",i,pM->iDevice,DriveNames[i]));
       
  5218 			OstTraceExt2( TRACE_INTERNALS, GETDRIVEINFO2, "Drive=%d; device=%d", i, (TUint) pM->iDevice );
  4655 			
  5219 			
  4656 			info.iRegisteredDriveBitmask |= (0x01 << i);
  5220 			info.iRegisteredDriveBitmask |= (0x01 << i);
  4657 			}
  5221 			}
  4658 		}
  5222 		}
  4659 	info.iTotalSupportedDrives=drives;
  5223 	info.iTotalSupportedDrives=drives;
  4660 	info.iTotalSockets=sockets;
  5224 	info.iTotalSockets=sockets;
  4661 	info.iRuggedFileSystem=ETrue;
  5225 	info.iRuggedFileSystem=ETrue;
  4662 	__KTRACE_OPT(KLOCDRV,Kern::Printf("Total drives=%d, sockets=%d",drives,sockets));
  5226 	__KTRACE_OPT(KLOCDRV,Kern::Printf("Total drives=%d, sockets=%d",drives,sockets));
       
  5227 	OstTraceExt2( TRACE_INTERNALS, GETDRIVEINFO3, "Total drives=%d; sockets=%d", drives, sockets );
       
  5228 	OstTraceFunctionExit0( GETDRIVEINFO_EXIT );
  4663 	}
  5229 	}
  4664 
  5230 
  4665 #if defined(__DEMAND_PAGING__) && defined(__CONCURRENT_PAGING_INSTRUMENTATION__)
  5231 #if defined(__DEMAND_PAGING__) && defined(__CONCURRENT_PAGING_INSTRUMENTATION__)
  4666 void ResetConcurrencyStats(DMediaPagingDevice* aDevice, TMediaPagingStats aStats)
  5232 void ResetConcurrencyStats(DMediaPagingDevice* aDevice, TMediaPagingStats aStats)
  4667 	{
  5233 	{
  4964 
  5530 
  4965 EXPORT_C void TPartitionTableScanner::Set(TUint8* aSectorBuffer, TPartitionEntry* aEntry, TInt aMaxPartitions, TInt64 aMediaSize)
  5531 EXPORT_C void TPartitionTableScanner::Set(TUint8* aSectorBuffer, TPartitionEntry* aEntry, TInt aMaxPartitions, TInt64 aMediaSize)
  4966 	{
  5532 	{
  4967 	__KTRACE_OPT(KLOCDRV, Kern::Printf("TPartitionTableScanner @ %08x : buf %08x entry %08x max %d sz %08x %08x",
  5533 	__KTRACE_OPT(KLOCDRV, Kern::Printf("TPartitionTableScanner @ %08x : buf %08x entry %08x max %d sz %08x %08x",
  4968 								this, aSectorBuffer, aEntry, aMaxPartitions, I64HIGH(aMediaSize), I64LOW(aMediaSize)));
  5534 								this, aSectorBuffer, aEntry, aMaxPartitions, I64HIGH(aMediaSize), I64LOW(aMediaSize)));
       
  5535 	OstTraceExt4( TRACE_INTERNALS, TPARTITIONTABLESCANNER_SET, "TPartitionTableScanner at 0x%08x; aSectorBuffer=0x%08x; aEntry=0x%08x; aMaxPartitions=%d", (TUint) this, (TUint) aSectorBuffer, (TUint) aEntry, aMaxPartitions );
  4969 	__ASSERT_ALWAYS(aMaxPartitions>0, LOCM_FAULT());
  5536 	__ASSERT_ALWAYS(aMaxPartitions>0, LOCM_FAULT());
  4970 	memclr(this, sizeof(TPartitionTableScanner));
  5537 	memclr(this, sizeof(TPartitionTableScanner));
  4971 	iLBA = -1;
  5538 	iLBA = -1;
  4972 	iSectorBuffer = aSectorBuffer;
  5539 	iSectorBuffer = aSectorBuffer;
  4973 	iFirstEntry = aEntry;
  5540 	iFirstEntry = aEntry;
  4978 
  5545 
  4979 EXPORT_C TInt TPartitionTableScanner::NumberOfPartitionsFound() const
  5546 EXPORT_C TInt TPartitionTableScanner::NumberOfPartitionsFound() const
  4980 	{
  5547 	{
  4981 	TInt n = iNextEntry - iFirstEntry;
  5548 	TInt n = iNextEntry - iFirstEntry;
  4982 	__KTRACE_OPT(KLOCDRV, Kern::Printf("TPartitionTableScanner N=%d", n));
  5549 	__KTRACE_OPT(KLOCDRV, Kern::Printf("TPartitionTableScanner N=%d", n));
       
  5550 	OstTrace1( TRACE_INTERNALS, TPARTITIONTABLESCANNER_NUMBERPARTITIONS, "Number of partitions=%d", n );
  4983 	return n;
  5551 	return n;
  4984 	}
  5552 	}
  4985 
  5553 
  4986 TPartitionTableScanner::SPart::SPart(const TUint8* a)
  5554 TPartitionTableScanner::SPart::SPart(const TUint8* a)
  4987 	{
  5555 	{
  4988 	iBootInd = a[0];
  5556 	iBootInd = a[0];
  4989 	iType = a[4];
  5557 	iType = a[4];
  4990 	iRSS = a[8]|(a[9]<<8)|(a[10]<<16)|(a[11]<<24);
  5558 	iRSS = a[8]|(a[9]<<8)|(a[10]<<16)|(a[11]<<24);
  4991 	iSectors = a[12]|(a[13]<<8)|(a[14]<<16)|(a[15]<<24);
  5559 	iSectors = a[12]|(a[13]<<8)|(a[14]<<16)|(a[15]<<24);
  4992 	__KTRACE_OPT(KLOCDRV, Kern::Printf("SPart: BI=%02x TYPE=%02x RSS=%08x SIZE=%08x", iBootInd, iType, iRSS, iSectors));
  5560 	__KTRACE_OPT(KLOCDRV, Kern::Printf("SPart: BI=%02x TYPE=%02x RSS=%08x SIZE=%08x", iBootInd, iType, iRSS, iSectors));
       
  5561 	OstTraceExt4(TRACE_INTERNALS, TPARTITIONTABLESCANNER_SPART_SPART, "SPart: iBootInd=%02x; iType=%02x; iRSS=%08x; iSectors=%08x", (TUint) iBootInd, (TUint) iType, (TUint) iRSS, (TUint) iSectors);
  4993 	}
  5562 	}
  4994 
  5563 
  4995 TInt TPartitionTableScanner::MakeEntry(const SPart& a)
  5564 TInt TPartitionTableScanner::MakeEntry(const SPart& a)
  4996 	{
  5565 	{
       
  5566 	OstTraceFunctionEntry1( TPARTITIONTABLESCANNER_MAKEENTRY_ENTRY, this );
  4997 	if (iNextEntry == iLimit)
  5567 	if (iNextEntry == iLimit)
       
  5568 	    {
       
  5569 		OstTraceFunctionExitExt( TPARTITIONTABLESCANNER_MAKEENTRY_EXIT1, this, KErrOverflow );
  4998 		return KErrOverflow;
  5570 		return KErrOverflow;
       
  5571 	    }
  4999 	if (a.iRSS<=0 || a.iSectors<=0 || a.iRSS>=iMediaSize)
  5572 	if (a.iRSS<=0 || a.iSectors<=0 || a.iRSS>=iMediaSize)
       
  5573 	    {
       
  5574 		OstTraceFunctionExitExt( TPARTITIONTABLESCANNER_MAKEENTRY_EXIT2, this, KErrCorrupt );
  5000 		return KErrCorrupt;
  5575 		return KErrCorrupt;
       
  5576 	    }
  5001 	if (TUint64(a.iRSS) + TUint64(a.iSectors) > TUint64(iMediaSize))
  5577 	if (TUint64(a.iRSS) + TUint64(a.iSectors) > TUint64(iMediaSize))
       
  5578 	    {
       
  5579 		OstTraceFunctionExitExt( TPARTITIONTABLESCANNER_MAKEENTRY_EXIT3, this, KErrCorrupt );
  5002 		return KErrCorrupt;
  5580 		return KErrCorrupt;
       
  5581 	    }
  5003 	iNextEntry->iBootIndicator = a.iBootInd;
  5582 	iNextEntry->iBootIndicator = a.iBootInd;
  5004 	iNextEntry->iPartitionType = a.iType;
  5583 	iNextEntry->iPartitionType = a.iType;
  5005 	iNextEntry->iPartitionBaseAddr = TInt64(a.iRSS)<<ESectorShift;
  5584 	iNextEntry->iPartitionBaseAddr = TInt64(a.iRSS)<<ESectorShift;
  5006 	iNextEntry->iPartitionLen = TInt64(a.iSectors)<<ESectorShift;
  5585 	iNextEntry->iPartitionLen = TInt64(a.iSectors)<<ESectorShift;
  5007 	++iNextEntry;
  5586 	++iNextEntry;
       
  5587 	OstTraceFunctionExitExt( TPARTITIONTABLESCANNER_MAKEENTRY_EXIT4, this, KErrNone );
  5008 	return KErrNone;
  5588 	return KErrNone;
  5009 	}
  5589 	}
  5010 
  5590 
  5011 EXPORT_C TInt64 TPartitionTableScanner::NextLBA()
  5591 EXPORT_C TInt64 TPartitionTableScanner::NextLBA()
  5012 	{
  5592 	{
       
  5593 	OstTraceFunctionEntry0( TPARTITIONTABLESCANNER_NEXTLBA_ENTRY );
  5013 	__KTRACE_OPT(KLOCDRV, Kern::Printf(">TPartitionTableScanner iLBA=%08x %08x", I64HIGH(iLBA), I64LOW(iLBA)));
  5594 	__KTRACE_OPT(KLOCDRV, Kern::Printf(">TPartitionTableScanner iLBA=%08x %08x", I64HIGH(iLBA), I64LOW(iLBA)));
       
  5595 	OstTraceExt2( TRACE_INTERNALS, TPARTITIONTABLESCANNER_NEXTLBA1, "TPartitionTableScanner iLBA=%08x %08x", I64HIGH(iLBA), I64LOW(iLBA) );
  5014 	TInt r;
  5596 	TInt r;
  5015 	TUint8* b = iSectorBuffer;
  5597 	TUint8* b = iSectorBuffer;
  5016 	TUint8* pS = b + 0x1be;
  5598 	TUint8* pS = b + 0x1be;
  5017 	TUint8* pE = pS + 64;
  5599 	TUint8* pE = pS + 64;
  5018 	TUint8* p = pS;
  5600 	TUint8* p = pS;
  5025 		}
  5607 		}
  5026 	__KTRACE_OPT(KLOCDRV,DMEMDUMP(b, ESectorSize));
  5608 	__KTRACE_OPT(KLOCDRV,DMEMDUMP(b, ESectorSize));
  5027 	if (b[ESectorSize-2]!=0x55 || b[ESectorSize-1]!=0xaa)
  5609 	if (b[ESectorSize-2]!=0x55 || b[ESectorSize-1]!=0xaa)
  5028 		{
  5610 		{
  5029 		__KTRACE_OPT(KLOCDRV, Kern::Printf("Bad signature"));
  5611 		__KTRACE_OPT(KLOCDRV, Kern::Printf("Bad signature"));
       
  5612 		OstTrace0( TRACE_INTERNALS, TPARTITIONTABLESCANNER_NEXTLBA2, "Bad signature" );
  5030 		iLBA = KErrCorrupt;
  5613 		iLBA = KErrCorrupt;
  5031 		goto end;
  5614 		goto end;
  5032 		}
  5615 		}
  5033 	if (iLBA==0 && iNextEntry==iFirstEntry)
  5616 	if (iLBA==0 && iNextEntry==iFirstEntry)
  5034 		{
  5617 		{
  5072 				{
  5655 				{
  5073 				const TInt64& rss = iStack[sp].iRSS;
  5656 				const TInt64& rss = iStack[sp].iRSS;
  5074 				const TInt64& size = iStack[sp].iSectors;
  5657 				const TInt64& size = iStack[sp].iSectors;
  5075 				__KTRACE_OPT(KLOCDRV, Kern::Printf("Stack[%d] RSS %08x %08x SIZE %08x %08x", sp,
  5658 				__KTRACE_OPT(KLOCDRV, Kern::Printf("Stack[%d] RSS %08x %08x SIZE %08x %08x", sp,
  5076 					I64HIGH(rss), I64LOW(rss), I64HIGH(size), I64LOW(size) ));
  5659 					I64HIGH(rss), I64LOW(rss), I64HIGH(size), I64LOW(size) ));
       
  5660 				OstTraceExt5(TRACE_INTERNALS, PARTITIONTABLESCANNER_NEXTLBA3, "Stack[%d] RSS 0x%x 0x%x SIZE 0x%08x 0x%08x", (TInt) sp, (TUint) I64HIGH(rss), (TUint) I64LOW(rss), (TUint) I64HIGH(size), (TUint) I64LOW(size));
  5077 				}
  5661 				}
  5078 #endif
  5662 #endif
  5079 			}
  5663 			}
  5080 		}
  5664 		}
  5081 	// Look for other data partitions
  5665 	// Look for other data partitions
  5104 	else
  5688 	else
  5105 		iLBA = KErrEof;	// finished
  5689 		iLBA = KErrEof;	// finished
  5106 
  5690 
  5107 end:
  5691 end:
  5108 	__KTRACE_OPT(KLOCDRV, Kern::Printf("<TPartitionTableScanner iLBA=%08x %08x", I64HIGH(iLBA), I64LOW(iLBA)));
  5692 	__KTRACE_OPT(KLOCDRV, Kern::Printf("<TPartitionTableScanner iLBA=%08x %08x", I64HIGH(iLBA), I64LOW(iLBA)));
       
  5693 	OstTraceExt2( TRACE_INTERNALS, TPARTITIONTABLESCANNER_NEXTLBA3, "TPartitionTableScanner iLBA=0x%08x 0x%08x", I64HIGH(iLBA), I64LOW(iLBA) );
       
  5694 	OstTraceFunctionExit0( TPARTITIONTABLESCANNER_NEXTLBA_EXIT );
  5109 	return iLBA;
  5695 	return iLBA;
  5110 	}
  5696 	}
  5111 
  5697 
  5112 /**
  5698 /**
  5113  * Returns Address and Length of next contiguous Physical memory fragment
  5699  * Returns Address and Length of next contiguous Physical memory fragment
  5119  * 		   KErrNoMemory, if no more memory fragments left.
  5705  * 		   KErrNoMemory, if no more memory fragments left.
  5120  * 		   KErrNotSupported, if Physical Memory addressing is not supported by this Media.
  5706  * 		   KErrNotSupported, if Physical Memory addressing is not supported by this Media.
  5121  */
  5707  */
  5122 EXPORT_C TInt TLocDrvRequest::GetNextPhysicalAddress(TPhysAddr& aAddr, TInt& aLen)
  5708 EXPORT_C TInt TLocDrvRequest::GetNextPhysicalAddress(TPhysAddr& aAddr, TInt& aLen)
  5123 	{
  5709 	{
       
  5710 	OstTraceExt2(TRACE_FLOW, TLOCDRVREQUEST_GETNEXTPHYSICALADDRESS_ENTRY, "> TLocDrvRequest::GetNextPhysicalAddress;aAddr=%x;aLen=%d;", (TUint) &aAddr, aLen );
  5124 	if (Flags() & EPhysAddr) 
  5711 	if (Flags() & EPhysAddr) 
  5125 		{
  5712 		{
  5126 
       
  5127 #ifdef __DEMAND_PAGING__
  5713 #ifdef __DEMAND_PAGING__
  5128 		if (DMediaPagingDevice::PagingRequest(*this))
  5714 		if (DMediaPagingDevice::PagingRequest(*this))
  5129 			{
  5715 			{
  5130 			return DDmaHelper::GetPhysicalAddress(*this, aAddr, aLen);
  5716 			return DDmaHelper::GetPhysicalAddress(*this, aAddr, aLen);
  5131 			}
  5717 			}
  5132 #endif
  5718 #endif
  5133 		return Drive()->iDmaHelper->GetPhysicalAddress(aAddr, aLen);
  5719 		return Drive()->iDmaHelper->GetPhysicalAddress(aAddr, aLen);
  5134 		}
  5720 		}
  5135 	else
  5721 	else
  5136 		{
  5722 		{
       
  5723 		OstTraceFunctionExitExt( TLOCDRVREQUEST_GETNEXTPHYSICALADDRESS_EXIT, this, KErrNotSupported );
  5137 		return KErrNotSupported;
  5724 		return KErrNotSupported;
  5138 		}
  5725 		}
  5139 	}
  5726 	}
  5140 
  5727 
  5141 
  5728