kernel/eka/drivers/locmedia/locmedia.cpp
changeset 44 36bfc973b146
parent 43 96e5fb8b040d
child 39 5d2844f35677
equal deleted inserted replaced
43:96e5fb8b040d 44:36bfc973b146
   346 	{
   346 	{
   347 	const TLocalDriveCapsV5& c=*(const TLocalDriveCapsV5*)aCaps;
   347 	const TLocalDriveCapsV5& c=*(const TLocalDriveCapsV5*)aCaps;
   348 	Kern::Printf("Drive %d Caps:", aDrive->iDriveNumber);
   348 	Kern::Printf("Drive %d Caps:", aDrive->iDriveNumber);
   349 	Kern::Printf("Size: %lx", c.iSize);
   349 	Kern::Printf("Size: %lx", c.iSize);
   350 	Kern::Printf("Type: %08x", c.iType);
   350 	Kern::Printf("Type: %08x", c.iType);
   351 	Kern::Printf("Batt: %08x", c.iBattery);
   351 	Kern::Printf("Bus : %08x", c.iConnectionBusType);
   352 	Kern::Printf("DAtt: %08x", c.iDriveAtt);
   352 	Kern::Printf("DAtt: %08x", c.iDriveAtt);
   353 	Kern::Printf("MAtt: %08x", c.iMediaAtt);
   353 	Kern::Printf("MAtt: %08x", c.iMediaAtt);
   354 	Kern::Printf("Base: %08x", c.iBaseAddress);
   354 	Kern::Printf("Base: %08x", c.iBaseAddress);
   355 	Kern::Printf("FSID: %04x", c.iFileSystemId);
   355 	Kern::Printf("FSID: %04x", c.iFileSystemId);
   356 	Kern::Printf("PTYP: %04x", c.iPartitionType);
   356 	Kern::Printf("PTYP: %04x", c.iPartitionType);
   613 			break;
   613 			break;
   614 			}
   614 			}
   615 		case RLocalDrive::EControlPasswordLock:
   615 		case RLocalDrive::EControlPasswordLock:
   616 			{
   616 			{
   617 			m.Id()=EPasswordLock;
   617 			m.Id()=EPasswordLock;
   618 			TLocalDrivePasswordData* ppd = (TLocalDrivePasswordData*)a1;
   618 			m.RemoteDes() = a1;
   619 			m.RemoteDes()=(TAny*)ppd;
   619 
   620 			r=iDrive->Request(m);
   620 			TMediaPassword oldPasswd;
       
   621 			TMediaPassword newPasswd;
       
   622 			TLocalDrivePasswordData pswData;
       
   623 			r = ReadPasswordData(m, pswData, oldPasswd, newPasswd);
       
   624 
       
   625 			if (r == KErrNone)
       
   626 				r = iDrive->Request(m);
   621 			break;
   627 			break;
   622 			}
   628 			}
   623 		case RLocalDrive::EControlPasswordUnlock:
   629 		case RLocalDrive::EControlPasswordUnlock:
   624 			{
   630 			{
   625 			m.Id()=EPasswordUnlock;
   631 			m.Id()=EPasswordUnlock;
   626 			TLocalDrivePasswordData* ppd = (TLocalDrivePasswordData*)a1;
   632 			m.RemoteDes() = a1;
   627 			m.RemoteDes()=(TAny*)ppd;
   633 
   628 			r=iDrive->Request(m);
   634 			TMediaPassword oldPasswd;
       
   635 			TMediaPassword newPasswd;
       
   636 			TLocalDrivePasswordData pswData;
       
   637 			r = ReadPasswordData(m, pswData, oldPasswd, newPasswd);
       
   638 
   629 			if(r == KErrNone)
   639 			if(r == KErrNone)
       
   640 				r=iDrive->Request(m);
       
   641 			if (r == KErrNone)
   630 				iDrive->iPrimaryMedia->iTotalPartitionsOpened = 0;
   642 				iDrive->iPrimaryMedia->iTotalPartitionsOpened = 0;
   631 			break;
   643 			break;
   632 			}
   644 			}
   633 		case RLocalDrive::EControlPasswordClear:
   645 		case RLocalDrive::EControlPasswordClear:
   634 			{
   646 			{
   635 			m.Id()=EPasswordClear;
   647 			m.Id()=EPasswordClear;
   636 			TLocalDrivePasswordData* ppd = (TLocalDrivePasswordData*)a1;
   648 			m.RemoteDes() = a1;
   637 			m.RemoteDes()=(TAny*)ppd;
   649 
   638 			r=iDrive->Request(m);
   650 			TMediaPassword oldPasswd;
       
   651 			TMediaPassword newPasswd;
       
   652 			TLocalDrivePasswordData pswData;
       
   653 			r = ReadPasswordData(m, pswData, oldPasswd, newPasswd);
       
   654 
       
   655 			if (r == KErrNone)
       
   656 				r = iDrive->Request(m);
   639 			break;
   657 			break;
   640 			}
   658 			}
   641 		case RLocalDrive::EControlPasswordErase:
   659 		case RLocalDrive::EControlPasswordErase:
   642 			{
   660 			{
   643 			m.Id()=EPasswordErase;
   661 			m.Id()=EPasswordErase;
   658 				Kern::PanicCurrentThread(KLitLocMedia,KErrAccessDenied);
   676 				Kern::PanicCurrentThread(KLitLocMedia,KErrAccessDenied);
   659 			Kern::QueueRequestComplete(iCleanup.iThread,iNotifyChangeRequest,KErrCancel);
   677 			Kern::QueueRequestComplete(iCleanup.iThread,iNotifyChangeRequest,KErrCancel);
   660 			break;
   678 			break;
   661 		case RLocalDrive::EControlReadPasswordStore:
   679 		case RLocalDrive::EControlReadPasswordStore:
   662 			{
   680 			{
       
   681 			TUint8  passData[TPasswordStore::EMaxPasswordLength];
       
   682 			m.RemoteDes() = (TAny*) passData;
       
   683 			m.Length() = sizeof(passData);
   663 			m.Id()=EReadPasswordStore;
   684 			m.Id()=EReadPasswordStore;
   664 			m.RemoteDes()=(TDes8*)a1;
       
   665 			r=iDrive->Request(m);
   685 			r=iDrive->Request(m);
       
   686 			if (r==KErrNone)
       
   687 				{
       
   688 				TPtr8 pData(passData, (TInt) m.Length(), TPasswordStore::EMaxPasswordLength);
       
   689 				m.RemoteDes()=(TDes8*)a1;
       
   690 				r = m.WriteRemote(&pData,0);
       
   691 				}
   666 			break;
   692 			break;
   667 			}
   693 			}
   668 		case RLocalDrive::EControlWritePasswordStore:
   694 		case RLocalDrive::EControlWritePasswordStore:
   669 			{
   695 			{
       
   696 			TUint8  passData[TPasswordStore::EMaxPasswordLength];
       
   697 			TPtr8 pData(passData, TPasswordStore::EMaxPasswordLength);
       
   698 
       
   699 			DThread* pT=m.RemoteThread();
       
   700 			if (!pT)
       
   701 				pT=m.Client();
       
   702 
       
   703 			m.RemoteDes() = (TDes8*)a1;
       
   704 			r = Kern::ThreadGetDesLength(pT, m.RemoteDes());
       
   705 			if ( r > pData.MaxLength() )
       
   706 				r = KErrOverflow;
       
   707 			if ( r < KErrNone)
       
   708 				break;
       
   709 
       
   710 			r = m.ReadRemote(&pData,0);
       
   711 			if (r != KErrNone)
       
   712 				break;
       
   713 
       
   714 
       
   715 			m.RemoteDes() = (TAny*) pData.Ptr();
       
   716 			m.Length() = pData.Length();
   670 			m.Id()=EWritePasswordStore;
   717 			m.Id()=EWritePasswordStore;
   671 			m.RemoteDes()=(TDes8*)a1;
       
   672 			r=iDrive->Request(m);
   718 			r=iDrive->Request(m);
   673 			if(r == KErrNone)
   719 			if(r == KErrNone)
   674 				iDrive->iPrimaryMedia->iTotalPartitionsOpened = 0;
   720 				iDrive->iPrimaryMedia->iTotalPartitionsOpened = 0;
   675 			break;
   721 			break;
   676 			}
   722 			}
   677 		case RLocalDrive::EControlPasswordStoreLengthInBytes:
   723 		case RLocalDrive::EControlPasswordStoreLengthInBytes:
   678 			{
   724 			{
   679 			m.Id()=EPasswordStoreLengthInBytes;
   725 			m.Id()=EPasswordStoreLengthInBytes;
   680 			m.RemoteDes()=a1;
   726 			TInt length;
       
   727 			m.RemoteDes() = (TAny*) &length;
   681 			r=iDrive->Request(m);
   728 			r=iDrive->Request(m);
       
   729 
       
   730 			if (r == KErrNone)
       
   731 				{
       
   732 				m.RemoteDes()=a1;
       
   733 				r = m.WriteRemoteRaw(&length,sizeof(TInt));
       
   734 				}
       
   735 			
   682 			break;
   736 			break;
   683 			}
   737 			}
   684 		case RLocalDrive::EControlGetLastErrorInfo:
   738 		case RLocalDrive::EControlGetLastErrorInfo:
   685 			{
   739 			{
   686 			m.Id()=EGetLastErrorInfo;
   740 			m.Id()=EGetLastErrorInfo;
   722 		}
   776 		}
   723 	__KTRACE_OPT(KLOCDRV,Kern::Printf("<DLocalDrive::DoControl D:%d M:%08x ret %d",iDrive->iDriveNumber, iDrive->iMedia, r));
   777 	__KTRACE_OPT(KLOCDRV,Kern::Printf("<DLocalDrive::DoControl D:%d M:%08x ret %d",iDrive->iDriveNumber, iDrive->iMedia, r));
   724 	__TRACE_TIMING(4);
   778 	__TRACE_TIMING(4);
   725 	return r;
   779 	return r;
   726 	}
   780 	}
       
   781 
       
   782 TInt DLocalDrive::ReadPasswordData(TLocDrvRequest& aReq, TLocalDrivePasswordData& aPswData, TMediaPassword& aOldPasswd, TMediaPassword& aNewPasswd)
       
   783 	{
       
   784 	TLocalDrivePasswordData clientData;
       
   785 	TInt r = aReq.ReadRemoteRaw(&clientData, sizeof(TLocalDrivePasswordData));
       
   786 
       
   787 	DThread* pT = aReq.RemoteThread();
       
   788 	if (!pT)
       
   789 		pT = aReq.Client();
       
   790 
       
   791 	if (r == KErrNone)
       
   792 		r = Kern::ThreadDesRead(pT, clientData.iOldPasswd, aOldPasswd, 0 ,KChunkShiftBy0);
       
   793 	if (r == KErrNone)
       
   794 		r = Kern::ThreadDesRead(pT, clientData.iNewPasswd, aNewPasswd, 0 ,KChunkShiftBy0);
       
   795 	
       
   796 	aPswData.iStorePasswd = clientData.iStorePasswd;
       
   797 	aPswData.iOldPasswd = &aOldPasswd;
       
   798 	aPswData.iNewPasswd = &aNewPasswd;
       
   799 
       
   800 
       
   801 	aReq.RemoteDes() = (TAny*) &aPswData;
       
   802 	aReq.Flags()|= TLocDrvRequest::EKernelBuffer;
       
   803 
       
   804 	return r;
       
   805 	}
       
   806 
   727 
   807 
   728 #ifdef __DEMAND_PAGING__
   808 #ifdef __DEMAND_PAGING__
   729 TInt DLocalDrive::LockMountInfo(DPrimaryMediaBase& aPrimaryMedia, TLocDrvRequest& aReq)
   809 TInt DLocalDrive::LockMountInfo(DPrimaryMediaBase& aPrimaryMedia, TLocDrvRequest& aReq)
   730 	{
   810 	{
   731 	DMediaPagingDevice* pagingDevice = aPrimaryMedia.iBody->iPagingDevice;
   811 	DMediaPagingDevice* pagingDevice = aPrimaryMedia.iBody->iPagingDevice;
   952 Reads data from an arbitrary descriptor in the requesting thread's process.
  1032 Reads data from an arbitrary descriptor in the requesting thread's process.
   953 
  1033 
   954 This is used by the media driver to read data from a descriptor in the
  1034 This is used by the media driver to read data from a descriptor in the
   955 requesting thread.  
  1035 requesting thread.  
   956 
  1036 
   957 NB This is NOT supported in a datapaging environment as there is no guarantee 
  1037 NB This is NOT supported on datapaging media as there is no guarantee 
   958 that the remote descriptor won't be paged out. If this function is called and
  1038 that the remote descriptor won't be paged out. If this function is called and
   959 data-paging is enabled the kernel will fault in debug mode and return 
  1039 data-paging is enabled the kernel will fault in debug mode and return 
   960 KErrNotSupported in release mode.
  1040 KErrNotSupported in release mode.
   961 
  1041 
   962 @param aSrc     A pointer to the source descriptor in the requesting thread's
  1042 @param aSrc     A pointer to the source descriptor in the requesting thread's
   970 
  1050 
   971 @see Kern::ThreadDesRead()
  1051 @see Kern::ThreadDesRead()
   972 */
  1052 */
   973 EXPORT_C TInt TLocDrvRequest::ReadRemote(const TAny* aSrc, TDes8* aDes)
  1053 EXPORT_C TInt TLocDrvRequest::ReadRemote(const TAny* aSrc, TDes8* aDes)
   974 	{
  1054 	{
       
  1055 	if (Flags() & TLocDrvRequest::EKernelBuffer)
       
  1056 		{
       
  1057 		aDes->Copy(* (TDesC8*) aSrc);
       
  1058 		return KErrNone;
       
  1059 		}
       
  1060 
   975 	DThread* pT=RemoteThread();
  1061 	DThread* pT=RemoteThread();
   976 	if (!pT)
  1062 	if (!pT)
   977 		pT=Client();
  1063 		pT=Client();
   978 
  1064 
   979 #ifdef __DEMAND_PAGING__
  1065 #ifdef __DEMAND_PAGING__
   980 	__ASSERT_DEBUG(!DataPagingDeviceRegistered, LOCM_FAULT());
  1066 	__ASSERT_DEBUG(!DataPagingDfcQ(Drive()->iPrimaryMedia), LOCM_FAULT());
   981 	if (DataPagingDeviceRegistered)
  1067 
       
  1068 	if (DataPagingDfcQ(Drive()->iPrimaryMedia))
   982 		return KErrNotSupported;
  1069 		return KErrNotSupported;
   983 #endif
  1070 #endif
   984 
  1071 
   985 	return Kern::ThreadDesRead(pT,aSrc,*aDes,0,KChunkShiftBy0);
  1072 	return Kern::ThreadDesRead(pT,aSrc,*aDes,0,KChunkShiftBy0);
   986 	}
  1073 	}
  1003 
  1090 
  1004 @see Kern::ThreadRawRead()
  1091 @see Kern::ThreadRawRead()
  1005 */
  1092 */
  1006 EXPORT_C TInt TLocDrvRequest::ReadRemoteRaw(TAny* aDest, TInt aSize)
  1093 EXPORT_C TInt TLocDrvRequest::ReadRemoteRaw(TAny* aDest, TInt aSize)
  1007 	{
  1094 	{
       
  1095 	if (Flags() & TLocDrvRequest::EKernelBuffer)
       
  1096 		{
       
  1097 		(void)memcpy(aDest, (TAny*) RemoteDes(), aSize);
       
  1098 		return KErrNone;
       
  1099 		}
       
  1100 
  1008 	DThread* pT=RemoteThread();
  1101 	DThread* pT=RemoteThread();
  1009 	if (!pT)
  1102 	if (!pT)
  1010 		pT=Client();
  1103 		pT=Client();
  1011 
  1104 
  1012 #ifdef __DEMAND_PAGING__
  1105 #ifdef __DEMAND_PAGING__
  1581 						return KErrArgument;
  1674 						return KErrArgument;
  1582 					return PinFragmentSendReceive(aReq, (TLinAddr) aReq.Ptr1(), controlIoType);
  1675 					return PinFragmentSendReceive(aReq, (TLinAddr) aReq.Ptr1(), controlIoType);
  1583 				}
  1676 				}
  1584 			}
  1677 			}
  1585 
  1678 
       
  1679 		case DLocalDrive::ERead:
       
  1680 		case DLocalDrive::EWrite:
       
  1681 			{
       
  1682 			return PinFragmentSendReceive(aReq, aLinAddress, aReq.Length());
       
  1683 			}
       
  1684 		
       
  1685 		// 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...
  1586 		case DLocalDrive::ECaps:
  1687 		case DLocalDrive::ECaps:
  1587 		case DLocalDrive::EGetLastErrorInfo:
  1688 		case DLocalDrive::EGetLastErrorInfo:
  1588 		case DLocalDrive::EQueryDevice:
  1689 		case DLocalDrive::EQueryDevice:
  1589 			{
       
  1590 			TInt len = aReq.Length();
       
  1591 
       
  1592 			if (len > (TInt) ThePinObjectAllocator->iFragmentGranularity)
       
  1593 				return KErrTooBig;
       
  1594 
       
  1595 			return PinFragmentSendReceive(aReq, (TLinAddr) aReq.RemoteDes(), len);
       
  1596 			}
       
  1597 
       
  1598 		case DLocalDrive::ERead:
       
  1599 		case DLocalDrive::EWrite:
       
  1600 			{
       
  1601 			return PinFragmentSendReceive(aReq, aLinAddress, aReq.Length());
       
  1602 			}
       
  1603 		
       
  1604 
       
  1605 
       
  1606 		// For the time being, don't support any password requests to the data paging device.
       
  1607 		// This shouldn't be a problem as the device should be flagged as non-removable...
       
  1608 		// This would be difficult to do anyway as it would involve pinning up to 3 buffers - 
       
  1609 		// TLocalDrivePasswordData itself, iOldPasswd & iNewPasswd
       
  1610 		case DLocalDrive::EPasswordLock:
  1690 		case DLocalDrive::EPasswordLock:
  1611 		case DLocalDrive::EPasswordUnlock:
  1691 		case DLocalDrive::EPasswordUnlock:
  1612 		case DLocalDrive::EPasswordClear:
  1692 		case DLocalDrive::EPasswordClear:
  1613 		case DLocalDrive::EReadPasswordStore:
  1693 		case DLocalDrive::EReadPasswordStore:
  1614 		case DLocalDrive::EWritePasswordStore:
  1694 		case DLocalDrive::EWritePasswordStore:
  1615 		case DLocalDrive::EPasswordStoreLengthInBytes:
  1695 		case DLocalDrive::EPasswordStoreLengthInBytes:
  1616 		case DLocalDrive::EPasswordErase:
  1696 		case DLocalDrive::EPasswordErase:
  1617 			return KErrNotSupported;
       
  1618 
  1697 
  1619 		default:		
  1698 		default:		
  1620 			return SendReceive(aReq);
  1699 			return SendReceive(aReq);
  1621 		}
  1700 		}
  1622 	}
  1701 	}
  1856 
  1935 
  1857 	{
  1936 	{
  1858 	// default implementation
  1937 	// default implementation
  1859 	// aCaps is zeroed beforehand
  1938 	// aCaps is zeroed beforehand
  1860 	aCaps.iType = EMediaUnknown;
  1939 	aCaps.iType = EMediaUnknown;
  1861 	//	aCaps.iBattery = EBatNotSupported;
       
  1862 	}
  1940 	}
  1863 	
  1941 	
  1864 EXPORT_C TBool DPrimaryMediaBase::IsRemovableDevice(TInt& /*aSocketNum*/)
  1942 EXPORT_C TBool DPrimaryMediaBase::IsRemovableDevice(TInt& /*aSocketNum*/)
  1865 /**
  1943 /**
  1866 Checks whether it is a removable device or not
  1944 Checks whether it is a removable device or not
  1975 			CompleteRequest(m, KErrNone);
  2053 			CompleteRequest(m, KErrNone);
  1976 			return;
  2054 			return;
  1977 			}
  2055 			}
  1978 		case DLocalDrive::EReadPasswordStore:
  2056 		case DLocalDrive::EReadPasswordStore:
  1979 			{
  2057 			{
  1980 			TUint8  passData[TPasswordStore::EMaxPasswordLength];
  2058 			TPtr8 pswData ((TUint8*) m.RemoteDes(), (TInt) m.Length());
  1981 			TPtr8 pData(passData, TPasswordStore::EMaxPasswordLength);
  2059 			TInt r = ThePasswordStore->ReadPasswordData(pswData);
  1982 			TInt r = ThePasswordStore->ReadPasswordData(pData);
  2060 			m.Length() = pswData.Length();
  1983 			if (r==KErrNone)
       
  1984 				r = m.WriteRemote(&pData,0);
       
  1985 			CompleteRequest(m, r);
  2061 			CompleteRequest(m, r);
  1986 			return;
  2062 			return;
  1987 			}
  2063 			}
  1988 		case DLocalDrive::EWritePasswordStore:
  2064 		case DLocalDrive::EWritePasswordStore:
  1989 			{
  2065 			{
  1990 			TUint8  passData[TPasswordStore::EMaxPasswordLength];
  2066 			TPtrC8 pData((TUint8*) m.RemoteDes(), (TInt) m.Length());
  1991 			TPtr8 pData(passData, TPasswordStore::EMaxPasswordLength);
  2067 			TInt r = ThePasswordStore->WritePasswordData(pData);
  1992 
  2068 
  1993 			DThread* pT=m.RemoteThread();
       
  1994 			if (!pT)
       
  1995 				pT=m.Client();
       
  1996 
       
  1997 			TInt lengthOrError = Kern::ThreadGetDesLength(pT, m.RemoteDes() );
       
  1998 			if ( lengthOrError > pData.MaxLength() )
       
  1999 				{
       
  2000 				CompleteRequest(m, KErrOverflow);
       
  2001 				return;
       
  2002 				}
       
  2003 			else if ( lengthOrError < KErrNone)
       
  2004 				{
       
  2005 				CompleteRequest(m, lengthOrError);
       
  2006 				return;
       
  2007 				}	
       
  2008 
       
  2009 			TInt r = m.ReadRemote(&pData,0);
       
  2010 			if (r==KErrNone)
       
  2011 				r = ThePasswordStore->WritePasswordData(pData);
       
  2012 			if(r != KErrNone)
  2069 			if(r != KErrNone)
  2013 				{
  2070 				{
  2014 				CompleteRequest(m, r);
  2071 				CompleteRequest(m, r);
  2015 				return;
  2072 				return;
  2016 				}
  2073 				}
  2027 			break;
  2084 			break;
  2028 			}
  2085 			}
  2029 		case DLocalDrive::EPasswordStoreLengthInBytes:
  2086 		case DLocalDrive::EPasswordStoreLengthInBytes:
  2030 			{
  2087 			{
  2031 			TInt length = ThePasswordStore->PasswordStoreLengthInBytes();
  2088 			TInt length = ThePasswordStore->PasswordStoreLengthInBytes();
  2032 			TInt r = m.WriteRemoteRaw(&length,sizeof(TInt));
  2089 			*(TInt*) m.RemoteDes() = length;
  2033 			CompleteRequest(m, r);
  2090 			CompleteRequest(m, KErrNone);
  2034 			return;
  2091 			return;
  2035 			}
  2092 			}
  2036 		default:
  2093 		default:
  2037 			CHECK_RET(KErrNotSupported);
  2094 			CHECK_RET(KErrNotSupported);
  2038 			CompleteRequest(m, KErrNotSupported);
  2095 			CompleteRequest(m, KErrNotSupported);