os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/server/controller/cusbhostmslogicalunit.cpp
First public contribution.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
24 #include "msgservice.h"
27 #include "mprotocol.h"
28 #include "mblocktransferprotocol.h"
29 #include "tspcclientinterface.h"
30 #include "cscsiprotocol.h"
32 #include "cusbhostmslogicalunit.h"
33 #include "usbmshostpanic.h"
38 CUsbHostMsLogicalUnit* CUsbHostMsLogicalUnit::NewL(TLun aLun)
41 CUsbHostMsLogicalUnit* r = new (ELeave) CUsbHostMsLogicalUnit(aLun);
42 CleanupStack::PushL(r);
49 void CUsbHostMsLogicalUnit::ConstructL()
52 const TInt KInitialDataBufSize = 0x200;
53 iDataBuf.CreateL(KInitialDataBufSize);
57 CUsbHostMsLogicalUnit::CUsbHostMsLogicalUnit(TLun aLun)
60 iSuspendRequest(EFalse)
65 CUsbHostMsLogicalUnit::~CUsbHostMsLogicalUnit()
73 void CUsbHostMsLogicalUnit::InitL()
76 iProtocol->InitialiseUnitL();
79 void CUsbHostMsLogicalUnit::UnInitL()
82 iProtocol->UninitialiseUnitL();
85 void CUsbHostMsLogicalUnit::ReadL(const RMessage2& aMessage)
89 TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
90 aMessage.ReadL(0, pReadWrite);
91 __HOSTPRINT2(_L("pos = 0x%lx len = %08x"), p.iPos, p.iLen);
93 User::LeaveIfError(CheckPosition(p));
95 // check if buffer can hold requested data and resize if not
96 if (iDataBuf.MaxLength() < p.iLen)
97 iDataBuf.ReAllocL(p.iLen);
99 iProtocol->ReadL(p.iPos, iDataBuf, p.iLen);
100 aMessage.WriteL(1, iDataBuf);
104 void CUsbHostMsLogicalUnit::WriteL(const RMessage2& aMessage)
108 TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
109 aMessage.ReadL(1, pReadWrite);
110 __HOSTPRINT2(_L("pos = 0x%lx len = %08x"), p.iPos, p.iLen);
112 User::LeaveIfError(CheckPosition(p));
114 // check if buffer can hold requested data and resize if not
115 if (iDataBuf.MaxLength() < p.iLen)
116 iDataBuf.ReAllocL(p.iLen);
118 aMessage.ReadL(0, iDataBuf);
119 iProtocol->WriteL(p.iPos, iDataBuf, p.iLen);
123 void CUsbHostMsLogicalUnit::EraseL(const RMessage2& aMessage)
127 TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
128 aMessage.ReadL(0, pReadWrite);
129 __HOSTPRINT2(_L("pos = 0x%lx len = %08x"), p.iPos, p.iLen);
131 User::LeaveIfError(CheckPosition(p));
133 // check if buffer can hold requested data and resize if not
134 if (iDataBuf.MaxLength() < p.iLen)
135 iDataBuf.ReAllocL(p.iLen);
137 iDataBuf.FillZ(p.iLen);
138 iProtocol->WriteL(p.iPos, iDataBuf, p.iLen);
142 void CUsbHostMsLogicalUnit::CapsL(const RMessage2& aMessage)
147 TPckg<TCapsInfo> pckg(capsInfo);
148 iProtocol->GetCapacityL(capsInfo);
149 iSize = static_cast<TInt64>(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength;
150 aMessage.WriteL(0, pckg);
153 void CUsbHostMsLogicalUnit::NotifyChange(const RMessage2& aMessage)
156 iProtocol->NotifyChange(aMessage);
160 void CUsbHostMsLogicalUnit::ForceCompleteNotifyChangeL()
163 iProtocol->ForceCompleteNotifyChangeL();
166 void CUsbHostMsLogicalUnit::CancelChangeNotifierL()
169 iProtocol->CancelChangeNotifierL();
172 TBool CUsbHostMsLogicalUnit::IsConnected()
174 return iProtocol->IsConnected() ? ETrue : EFalse;
177 TBool CUsbHostMsLogicalUnit::IsReadyToSuspend()
180 return iSuspendRequest ? ETrue : EFalse;
183 void CUsbHostMsLogicalUnit::ReadyToSuspend()
186 iSuspendRequest = ETrue;
189 void CUsbHostMsLogicalUnit::CancelReadyToSuspend()
192 iSuspendRequest = EFalse;
195 void CUsbHostMsLogicalUnit::SuspendL()
198 iProtocol->SuspendL();
201 void CUsbHostMsLogicalUnit::ResumeL()
204 // We do not cancel iSuspendRequest here
205 iProtocol->ResumeL();
208 void CUsbHostMsLogicalUnit::DoLunReadyCheckL()
211 iProtocol->DoScsiReadyCheckEventL();
214 TInt CUsbHostMsLogicalUnit::InitialiseProtocolL(TLun aLun,
215 THostMassStorageConfig& aConfig,
216 MTransport& aTransport)
219 __ASSERT_DEBUG(iProtocol == NULL, User::Panic(KUsbMsHostPanicCat, EProtocolNotFree));
220 switch(aConfig.iProtocolId)
223 iProtocol = CScsiProtocol::NewL(aLun, aTransport);
226 __HOSTPRINT(_L("Unsupported Transport class requested"));
228 return KErrNotSupported;
233 TInt CUsbHostMsLogicalUnit::CheckPosition(const TReadWrite& aReadWrite)
235 if (aReadWrite.iLen == 0)
237 if (aReadWrite.iPos == iSize)
243 // detect drive not present
247 if (aReadWrite.iPos >= iSize)