os/kernelhwsrv/kerneltest/f32test/shostmassstorage/testclient/usbtestmsclient/inc/drivemanager.h
First public contribution.
1 // Copyright (c) 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.
14 // CDriveManager and CMassStorageDrive classes for USB Mass Storage.
25 #ifndef DRIVEMANAGER_H
26 #define DRIVEMANAGER_H
30 // Forward declarations
32 class RDriveMediaErrorPublisher;
33 class RDriveStateChangedPublisher;
34 class TLocalDriveCapsV4;
42 const TUint32 KDefaultBlockSize = 0x200; //default block size for FAT
44 void Init(TLocalDriveCapsV4& aCaps);
46 TUint32 NumBlocks() const {return iNumBlocks;}
47 TUint64 Size() const {return iSize;};
48 TUint32 BlockSize() const {return KDefaultBlockSize;}
49 TBool IsWriteProtected() const {return iMediaAtt & KMediaAttWriteProtected ? ETrue : EFalse;}
50 TBool IsLocked() const {return iMediaAtt & KMediaAttLocked ? ETrue : EFalse;}
53 TLocalDriveCapsV4 iCaps;
62 A private structure that, when Connected, holds references to
63 the CProxyDrive and the corresponding TBusLocalDrive's Media Changed flag.
69 The Drive Media State Machine.
74 The media is present and ready for access.
78 The media is currently being accessed by Mass Storage.
82 The media is present but is password-protected.
86 The media is not physically present.
96 TLocalDriveRef(CProxyDrive& aProxyDrive,
98 RDriveStateChangedPublisher& aDriveStateChangedPublisher);
100 void SetDriveState(TDriveState aState);
101 TInt Read(const TInt64& aPos, TInt aLength, TDes8& aBuf, TBool aWholeMedia);
102 TInt Write(const TInt64& aPos, TDesC8& aBuf, TBool aWholeMedia);
103 TBool IsMediaChanged(TBool aReset);
104 TInt SetCritical(TBool aCritical);
105 TDriveState DriveState() const;
106 TInt Caps(TLocalDriveCapsV4& aInfo);
109 static TBool IsActive(TDriveState aDriveState);
112 CProxyDrive& iProxyDrive;
114 TBool& iMediaChanged;
116 The Drive Media state machine
118 TDriveState iDriveState;
121 Reference to publisher for tracking drive state changes.
123 RDriveStateChangedPublisher& iDriveStateChangedPublisher;
127 inline TLocalDriveRef::TLocalDriveRef(CProxyDrive& aProxyDrive,
128 TBool& aMediaChanged,
129 RDriveStateChangedPublisher& aDriveStateChangedPublisher)
130 : iProxyDrive(aProxyDrive),
131 iMediaChanged(aMediaChanged),
133 iDriveStateChangedPublisher(aDriveStateChangedPublisher)
138 inline TBool TLocalDriveRef::IsActive(TLocalDriveRef::TDriveState aDriveState)
140 return aDriveState==TLocalDriveRef::EActive;
144 inline TLocalDriveRef::TDriveState TLocalDriveRef::DriveState() const
153 Along with CDriveManager, this provides an interface between the generic SCSI
154 protocol component and the target drive unit. The CMassStorageDrive class is
155 instantiated by the drive manager, and contains a pointer to the associated
156 CProxyDrive that was registered by the Mass Storage File System.
158 class CMassStorageDrive: public CBase
162 The Drive Mount State Machine.
171 Not mounted, but SCSI started
179 Not unmounted, but SCSI stopped
185 static CMassStorageDrive* NewL(RCriticalSection& aCritSec,
186 RDriveStateChangedPublisher& aDriveStateChangedPublisher);
187 ~CMassStorageDrive();
191 CMassStorageDrive(RCriticalSection& aCritSec,
192 RDriveStateChangedPublisher& aDriveStateChangedPublisher);
196 TInt Read(const TInt64& aPos, TInt aLength, TDes8& aBuf, TBool aWholeMedia = ETrue);
197 TInt Write(const TInt64& aPos, TDesC8& aBuf, TBool aWholeMedia = ETrue);
199 TMountState MountState() const;
200 TLocalDriveRef::TDriveState DriveState() const;
201 TLocalDriveRef::TDriveState CheckDriveState();
202 void SetMountDisconnected();
203 void SetMountConnecting();
204 void SetMountDisconnecting();
205 void SetMountConnected();
206 void SetMountConnectedL(CProxyDrive& aProxyDrive, TBool& aMediaChanged, RDriveStateChangedPublisher& aDriveStateChangedPublisher);
207 TInt SetCritical(TBool aCritical);
208 TBool IsMediaChanged(TBool aReset=EFalse);
210 const TMediaParams& MediaParams() const {return iMediaParams;}
213 TInt HandleCriticalError();
214 TInt ClearCriticalError();
215 TInt DoCaps(TLocalDriveCapsV4& aCaps);
216 void SetDriveState(TLocalDriveRef::TDriveState aNewState);
217 void SetMountState(TMountState aNewState, TBool aCriticalSection = EFalse);
221 A Critical Section, shared by all instances of CMassStorageDrive, used to ensure
222 that iMountState and iProxyDrive are changed atomically.
224 RCriticalSection& iCritSec;
226 The Drive Mount state machine
228 TMountState iMountState;
231 When Connected, references to CProxyDrive and TBusLocalDrive's Media Changed flag.
233 TLocalDriveRef* iLocalDrive;
235 Publisher for media errors.
237 RDriveMediaErrorPublisher* iDriveMediaErrorPublisher;
239 Reference to publisher for tracking drive state changes.
241 RDriveStateChangedPublisher& iDriveStateChangedPublisher;
243 TMediaParams iMediaParams;
250 Along with CMassStorageDrive, this provides an interface between the generic SCSI
251 protocol component and the target drive unit. This package is responsible for
252 maintaining the list of registered drives. The owner of the controller registers
253 each drive it wishes to make available to USB Mass Storage along with an
254 associated Logical Drive Unit identifier. The SCSI protocol contains a reference
255 to the drive manager in order to route the incoming request to a drive.
257 class CDriveManager : public CBase
261 The Logical Drive Unit Identifiers (LUN) must be in the range 0..7 due to the
262 fact that the status for all drives is encoded into one 32-bit word.
264 enum { KAllLuns = 0xff };
266 static CDriveManager* NewL(const TLunToDriveMap& aDriveMap);
269 void RegisterDriveL(CProxyDrive& aProxyDrive, TBool& aMediaChanged, TLun aLun);
270 void DeregisterDrive(TLun aLun);
271 CMassStorageDrive* Drive(TLun aLun) const;
274 void Connect(TLun aLun);
277 void Disconnect(TLun aLun);
279 TBool IsMediaChanged(TLun aLun, TBool aReset = EFalse);
280 TInt SetCritical(TLun aLun, TBool aCritical);
285 // private default constructor to ensure that NewL is used
286 CDriveManager(TLun aLun);
287 void ConstructL(const TLunToDriveMap& aDriveMap);
291 The array of drives. The index into the array is a LUN.
293 TMsDriveList iDrives;
296 Publisher for tracking drive state changes.
298 RDriveStateChangedPublisher* iDriveStateChangedPublisher;
302 A resource owned by DriveManager but used by the Drive objects.
304 RCriticalSection iDriveCritSec;
307 #include "drivemanager.inl"
309 #endif // DRIVEMANAGER_H