sl@0
|
1 |
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// CDriveManager and CMassStorageDrive classes for USB Mass Storage.
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
/**
|
sl@0
|
21 |
@file
|
sl@0
|
22 |
@internalTechnology
|
sl@0
|
23 |
*/
|
sl@0
|
24 |
|
sl@0
|
25 |
#ifndef DRIVEMANAGER_H
|
sl@0
|
26 |
#define DRIVEMANAGER_H
|
sl@0
|
27 |
|
sl@0
|
28 |
#include "d32locd.h"
|
sl@0
|
29 |
|
sl@0
|
30 |
// Forward declarations
|
sl@0
|
31 |
class CDriveManager;
|
sl@0
|
32 |
class RDriveMediaErrorPublisher;
|
sl@0
|
33 |
class RDriveStateChangedPublisher;
|
sl@0
|
34 |
class TLocalDriveCapsV4;
|
sl@0
|
35 |
class CProxyDrive;
|
sl@0
|
36 |
|
sl@0
|
37 |
|
sl@0
|
38 |
|
sl@0
|
39 |
class TMediaParams
|
sl@0
|
40 |
{
|
sl@0
|
41 |
public:
|
sl@0
|
42 |
const TUint32 KDefaultBlockSize = 0x200; //default block size for FAT
|
sl@0
|
43 |
|
sl@0
|
44 |
void Init(TLocalDriveCapsV4& aCaps);
|
sl@0
|
45 |
|
sl@0
|
46 |
TUint32 NumBlocks() const {return iNumBlocks;}
|
sl@0
|
47 |
TUint64 Size() const {return iSize;};
|
sl@0
|
48 |
TUint32 BlockSize() const {return KDefaultBlockSize;}
|
sl@0
|
49 |
TBool IsWriteProtected() const {return iMediaAtt & KMediaAttWriteProtected ? ETrue : EFalse;}
|
sl@0
|
50 |
TBool IsLocked() const {return iMediaAtt & KMediaAttLocked ? ETrue : EFalse;}
|
sl@0
|
51 |
|
sl@0
|
52 |
private:
|
sl@0
|
53 |
TLocalDriveCapsV4 iCaps;
|
sl@0
|
54 |
|
sl@0
|
55 |
TUint32 iNumBlocks;
|
sl@0
|
56 |
TInt64 iSize;
|
sl@0
|
57 |
TUint iMediaAtt;
|
sl@0
|
58 |
};
|
sl@0
|
59 |
|
sl@0
|
60 |
|
sl@0
|
61 |
/**
|
sl@0
|
62 |
A private structure that, when Connected, holds references to
|
sl@0
|
63 |
the CProxyDrive and the corresponding TBusLocalDrive's Media Changed flag.
|
sl@0
|
64 |
*/
|
sl@0
|
65 |
class TLocalDriveRef
|
sl@0
|
66 |
{
|
sl@0
|
67 |
public:
|
sl@0
|
68 |
/**
|
sl@0
|
69 |
The Drive Media State Machine.
|
sl@0
|
70 |
*/
|
sl@0
|
71 |
enum TDriveState
|
sl@0
|
72 |
{
|
sl@0
|
73 |
/**
|
sl@0
|
74 |
The media is present and ready for access.
|
sl@0
|
75 |
*/
|
sl@0
|
76 |
EIdle,
|
sl@0
|
77 |
/**
|
sl@0
|
78 |
The media is currently being accessed by Mass Storage.
|
sl@0
|
79 |
*/
|
sl@0
|
80 |
EActive,
|
sl@0
|
81 |
/**
|
sl@0
|
82 |
The media is present but is password-protected.
|
sl@0
|
83 |
*/
|
sl@0
|
84 |
ELocked,
|
sl@0
|
85 |
/**
|
sl@0
|
86 |
The media is not physically present.
|
sl@0
|
87 |
*/
|
sl@0
|
88 |
EMediaNotPresent,
|
sl@0
|
89 |
/**
|
sl@0
|
90 |
No drive.
|
sl@0
|
91 |
*/
|
sl@0
|
92 |
EErrDisMounted
|
sl@0
|
93 |
};
|
sl@0
|
94 |
|
sl@0
|
95 |
|
sl@0
|
96 |
TLocalDriveRef(CProxyDrive& aProxyDrive,
|
sl@0
|
97 |
TBool& aMediaChanged,
|
sl@0
|
98 |
RDriveStateChangedPublisher& aDriveStateChangedPublisher);
|
sl@0
|
99 |
|
sl@0
|
100 |
void SetDriveState(TDriveState aState);
|
sl@0
|
101 |
TInt Read(const TInt64& aPos, TInt aLength, TDes8& aBuf, TBool aWholeMedia);
|
sl@0
|
102 |
TInt Write(const TInt64& aPos, TDesC8& aBuf, TBool aWholeMedia);
|
sl@0
|
103 |
TBool IsMediaChanged(TBool aReset);
|
sl@0
|
104 |
TInt SetCritical(TBool aCritical);
|
sl@0
|
105 |
TDriveState DriveState() const;
|
sl@0
|
106 |
TInt Caps(TLocalDriveCapsV4& aInfo);
|
sl@0
|
107 |
|
sl@0
|
108 |
private:
|
sl@0
|
109 |
static TBool IsActive(TDriveState aDriveState);
|
sl@0
|
110 |
|
sl@0
|
111 |
private:
|
sl@0
|
112 |
CProxyDrive& iProxyDrive;
|
sl@0
|
113 |
|
sl@0
|
114 |
TBool& iMediaChanged;
|
sl@0
|
115 |
/**
|
sl@0
|
116 |
The Drive Media state machine
|
sl@0
|
117 |
*/
|
sl@0
|
118 |
TDriveState iDriveState;
|
sl@0
|
119 |
|
sl@0
|
120 |
/**
|
sl@0
|
121 |
Reference to publisher for tracking drive state changes.
|
sl@0
|
122 |
*/
|
sl@0
|
123 |
RDriveStateChangedPublisher& iDriveStateChangedPublisher;
|
sl@0
|
124 |
};
|
sl@0
|
125 |
|
sl@0
|
126 |
|
sl@0
|
127 |
inline TLocalDriveRef::TLocalDriveRef(CProxyDrive& aProxyDrive,
|
sl@0
|
128 |
TBool& aMediaChanged,
|
sl@0
|
129 |
RDriveStateChangedPublisher& aDriveStateChangedPublisher)
|
sl@0
|
130 |
: iProxyDrive(aProxyDrive),
|
sl@0
|
131 |
iMediaChanged(aMediaChanged),
|
sl@0
|
132 |
iDriveState(EIdle),
|
sl@0
|
133 |
iDriveStateChangedPublisher(aDriveStateChangedPublisher)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
}
|
sl@0
|
136 |
|
sl@0
|
137 |
|
sl@0
|
138 |
inline TBool TLocalDriveRef::IsActive(TLocalDriveRef::TDriveState aDriveState)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
return aDriveState==TLocalDriveRef::EActive;
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
|
sl@0
|
144 |
inline TLocalDriveRef::TDriveState TLocalDriveRef::DriveState() const
|
sl@0
|
145 |
{
|
sl@0
|
146 |
return iDriveState;
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
|
sl@0
|
150 |
/**
|
sl@0
|
151 |
@internalTechnology
|
sl@0
|
152 |
|
sl@0
|
153 |
Along with CDriveManager, this provides an interface between the generic SCSI
|
sl@0
|
154 |
protocol component and the target drive unit. The CMassStorageDrive class is
|
sl@0
|
155 |
instantiated by the drive manager, and contains a pointer to the associated
|
sl@0
|
156 |
CProxyDrive that was registered by the Mass Storage File System.
|
sl@0
|
157 |
*/
|
sl@0
|
158 |
class CMassStorageDrive: public CBase
|
sl@0
|
159 |
{
|
sl@0
|
160 |
public:
|
sl@0
|
161 |
/**
|
sl@0
|
162 |
The Drive Mount State Machine.
|
sl@0
|
163 |
*/
|
sl@0
|
164 |
enum TMountState
|
sl@0
|
165 |
{
|
sl@0
|
166 |
/**
|
sl@0
|
167 |
Unmounted
|
sl@0
|
168 |
*/
|
sl@0
|
169 |
EDisconnected,
|
sl@0
|
170 |
/**
|
sl@0
|
171 |
Not mounted, but SCSI started
|
sl@0
|
172 |
*/
|
sl@0
|
173 |
EConnecting,
|
sl@0
|
174 |
/**
|
sl@0
|
175 |
Mounted
|
sl@0
|
176 |
*/
|
sl@0
|
177 |
EConnected,
|
sl@0
|
178 |
/**
|
sl@0
|
179 |
Not unmounted, but SCSI stopped
|
sl@0
|
180 |
*/
|
sl@0
|
181 |
EDisconnecting
|
sl@0
|
182 |
};
|
sl@0
|
183 |
|
sl@0
|
184 |
public:
|
sl@0
|
185 |
static CMassStorageDrive* NewL(RCriticalSection& aCritSec,
|
sl@0
|
186 |
RDriveStateChangedPublisher& aDriveStateChangedPublisher);
|
sl@0
|
187 |
~CMassStorageDrive();
|
sl@0
|
188 |
|
sl@0
|
189 |
private:
|
sl@0
|
190 |
void ConstructL();
|
sl@0
|
191 |
CMassStorageDrive(RCriticalSection& aCritSec,
|
sl@0
|
192 |
RDriveStateChangedPublisher& aDriveStateChangedPublisher);
|
sl@0
|
193 |
|
sl@0
|
194 |
public:
|
sl@0
|
195 |
|
sl@0
|
196 |
TInt Read(const TInt64& aPos, TInt aLength, TDes8& aBuf, TBool aWholeMedia = ETrue);
|
sl@0
|
197 |
TInt Write(const TInt64& aPos, TDesC8& aBuf, TBool aWholeMedia = ETrue);
|
sl@0
|
198 |
|
sl@0
|
199 |
TMountState MountState() const;
|
sl@0
|
200 |
TLocalDriveRef::TDriveState DriveState() const;
|
sl@0
|
201 |
TLocalDriveRef::TDriveState CheckDriveState();
|
sl@0
|
202 |
void SetMountDisconnected();
|
sl@0
|
203 |
void SetMountConnecting();
|
sl@0
|
204 |
void SetMountDisconnecting();
|
sl@0
|
205 |
void SetMountConnected();
|
sl@0
|
206 |
void SetMountConnectedL(CProxyDrive& aProxyDrive, TBool& aMediaChanged, RDriveStateChangedPublisher& aDriveStateChangedPublisher);
|
sl@0
|
207 |
TInt SetCritical(TBool aCritical);
|
sl@0
|
208 |
TBool IsMediaChanged(TBool aReset=EFalse);
|
sl@0
|
209 |
|
sl@0
|
210 |
const TMediaParams& MediaParams() const {return iMediaParams;}
|
sl@0
|
211 |
|
sl@0
|
212 |
private:
|
sl@0
|
213 |
TInt HandleCriticalError();
|
sl@0
|
214 |
TInt ClearCriticalError();
|
sl@0
|
215 |
TInt DoCaps(TLocalDriveCapsV4& aCaps);
|
sl@0
|
216 |
void SetDriveState(TLocalDriveRef::TDriveState aNewState);
|
sl@0
|
217 |
void SetMountState(TMountState aNewState, TBool aCriticalSection = EFalse);
|
sl@0
|
218 |
|
sl@0
|
219 |
private:
|
sl@0
|
220 |
/**
|
sl@0
|
221 |
A Critical Section, shared by all instances of CMassStorageDrive, used to ensure
|
sl@0
|
222 |
that iMountState and iProxyDrive are changed atomically.
|
sl@0
|
223 |
*/
|
sl@0
|
224 |
RCriticalSection& iCritSec;
|
sl@0
|
225 |
/**
|
sl@0
|
226 |
The Drive Mount state machine
|
sl@0
|
227 |
*/
|
sl@0
|
228 |
TMountState iMountState;
|
sl@0
|
229 |
|
sl@0
|
230 |
/**
|
sl@0
|
231 |
When Connected, references to CProxyDrive and TBusLocalDrive's Media Changed flag.
|
sl@0
|
232 |
*/
|
sl@0
|
233 |
TLocalDriveRef* iLocalDrive;
|
sl@0
|
234 |
/**
|
sl@0
|
235 |
Publisher for media errors.
|
sl@0
|
236 |
*/
|
sl@0
|
237 |
RDriveMediaErrorPublisher* iDriveMediaErrorPublisher;
|
sl@0
|
238 |
/**
|
sl@0
|
239 |
Reference to publisher for tracking drive state changes.
|
sl@0
|
240 |
*/
|
sl@0
|
241 |
RDriveStateChangedPublisher& iDriveStateChangedPublisher;
|
sl@0
|
242 |
|
sl@0
|
243 |
TMediaParams iMediaParams;
|
sl@0
|
244 |
};
|
sl@0
|
245 |
|
sl@0
|
246 |
|
sl@0
|
247 |
/**
|
sl@0
|
248 |
@internalTechnology
|
sl@0
|
249 |
|
sl@0
|
250 |
Along with CMassStorageDrive, this provides an interface between the generic SCSI
|
sl@0
|
251 |
protocol component and the target drive unit. This package is responsible for
|
sl@0
|
252 |
maintaining the list of registered drives. The owner of the controller registers
|
sl@0
|
253 |
each drive it wishes to make available to USB Mass Storage along with an
|
sl@0
|
254 |
associated Logical Drive Unit identifier. The SCSI protocol contains a reference
|
sl@0
|
255 |
to the drive manager in order to route the incoming request to a drive.
|
sl@0
|
256 |
*/
|
sl@0
|
257 |
class CDriveManager : public CBase
|
sl@0
|
258 |
{
|
sl@0
|
259 |
public:
|
sl@0
|
260 |
/**
|
sl@0
|
261 |
The Logical Drive Unit Identifiers (LUN) must be in the range 0..7 due to the
|
sl@0
|
262 |
fact that the status for all drives is encoded into one 32-bit word.
|
sl@0
|
263 |
*/
|
sl@0
|
264 |
enum { KAllLuns = 0xff };
|
sl@0
|
265 |
|
sl@0
|
266 |
static CDriveManager* NewL(const TLunToDriveMap& aDriveMap);
|
sl@0
|
267 |
~CDriveManager();
|
sl@0
|
268 |
|
sl@0
|
269 |
void RegisterDriveL(CProxyDrive& aProxyDrive, TBool& aMediaChanged, TLun aLun);
|
sl@0
|
270 |
void DeregisterDrive(TLun aLun);
|
sl@0
|
271 |
CMassStorageDrive* Drive(TLun aLun) const;
|
sl@0
|
272 |
|
sl@0
|
273 |
void Connect();
|
sl@0
|
274 |
void Connect(TLun aLun);
|
sl@0
|
275 |
|
sl@0
|
276 |
void Disconnect();
|
sl@0
|
277 |
void Disconnect(TLun aLun);
|
sl@0
|
278 |
|
sl@0
|
279 |
TBool IsMediaChanged(TLun aLun, TBool aReset = EFalse);
|
sl@0
|
280 |
TInt SetCritical(TLun aLun, TBool aCritical);
|
sl@0
|
281 |
|
sl@0
|
282 |
TLun MaxLun() const;
|
sl@0
|
283 |
|
sl@0
|
284 |
private:
|
sl@0
|
285 |
// private default constructor to ensure that NewL is used
|
sl@0
|
286 |
CDriveManager(TLun aLun);
|
sl@0
|
287 |
void ConstructL(const TLunToDriveMap& aDriveMap);
|
sl@0
|
288 |
|
sl@0
|
289 |
private:
|
sl@0
|
290 |
/**
|
sl@0
|
291 |
The array of drives. The index into the array is a LUN.
|
sl@0
|
292 |
*/
|
sl@0
|
293 |
TMsDriveList iDrives;
|
sl@0
|
294 |
|
sl@0
|
295 |
/**
|
sl@0
|
296 |
Publisher for tracking drive state changes.
|
sl@0
|
297 |
*/
|
sl@0
|
298 |
RDriveStateChangedPublisher* iDriveStateChangedPublisher;
|
sl@0
|
299 |
|
sl@0
|
300 |
TLun iMaxLun;
|
sl@0
|
301 |
/**
|
sl@0
|
302 |
A resource owned by DriveManager but used by the Drive objects.
|
sl@0
|
303 |
*/
|
sl@0
|
304 |
RCriticalSection iDriveCritSec;
|
sl@0
|
305 |
};
|
sl@0
|
306 |
|
sl@0
|
307 |
#include "drivemanager.inl"
|
sl@0
|
308 |
|
sl@0
|
309 |
#endif // DRIVEMANAGER_H
|