1 /* |
|
2 * Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0"" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Drive info storage |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <coreapplicationuisdomainpskeys.h> |
|
21 #include "TFileManagerDriveInfo.h" |
|
22 #include "CFileManagerEngine.h" |
|
23 #include "FileManagerDebug.h" |
|
24 #include "CFileManagerCommonDefinitions.h" |
|
25 #include "CFileManagerFeatureManager.h" |
|
26 #ifdef RD_MULTIPLE_DRIVE |
|
27 #include <driveinfo.h> |
|
28 #endif // RD_MULTIPLE_DRIVE |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // TFileManagerDriveInfo::TFileManagerDriveInfo |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 EXPORT_C TFileManagerDriveInfo::TFileManagerDriveInfo() |
|
37 { |
|
38 Reset(); |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // TFileManagerDriveInfo::TFileManagerDriveInfo |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 EXPORT_C void TFileManagerDriveInfo::Reset() |
|
46 { |
|
47 iName.Zero(); |
|
48 iCapacity = 0; |
|
49 iSpaceFree = 0; |
|
50 iUid = 0; |
|
51 iDrive = 0; |
|
52 iState = 0; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // TFileManagerDriveInfo::GetInfoL |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 void TFileManagerDriveInfo::GetInfoL( |
|
60 const CFileManagerEngine& aEngine, const TInt aDrive ) |
|
61 { |
|
62 FUNC_LOG |
|
63 |
|
64 INFO_LOG1( "TFileManagerDriveInfo::GetInfoL - aDrive %d", aDrive ) |
|
65 |
|
66 Reset(); |
|
67 iDrive = aDrive; |
|
68 |
|
69 RFs& fs( aEngine.Fs() ); |
|
70 CheckMountL( fs, aDrive ); |
|
71 TInt err( FillStateFromVolumeInfo( fs, aDrive ) ); |
|
72 if ( err == KErrInUse ) |
|
73 { |
|
74 iState |= EDriveInUse; |
|
75 } |
|
76 else if ( err == KErrCorrupt ) |
|
77 { |
|
78 iState |= EDrivePresent | EDriveCorrupted; |
|
79 } |
|
80 else if ( err == KErrLocked ) |
|
81 { |
|
82 iState |= EDrivePresent | EDriveLocked | EDriveFormatted | |
|
83 EDrivePasswordProtected | EDriveLockable; |
|
84 } |
|
85 else if ( err == KErrNone ) |
|
86 { |
|
87 if ( iState & EDriveRemote ) |
|
88 { |
|
89 if ( aEngine.IsRemoteDriveConnected( aDrive ) ) |
|
90 { |
|
91 iState |= EDriveConnected; |
|
92 } |
|
93 } |
|
94 |
|
95 #ifndef RD_FILE_MANAGER_BACKUP |
|
96 if ( iState & EDriveRemovable ) |
|
97 { |
|
98 if ( aEngine.BackupFileExistsL( aDrive ) ) |
|
99 { |
|
100 iState |= EDriveBackupped; |
|
101 } |
|
102 } |
|
103 #endif // RD_FILE_MANAGER_BACKUP |
|
104 |
|
105 } |
|
106 |
|
107 INFO_LOG3( "TFileManagerDriveInfo::GetInfoL - aDrive %d, err %d, iState 0x%x", |
|
108 aDrive, err, iState ) |
|
109 |
|
110 if ( aEngine.FeatureManager().IsEmbedded() ) |
|
111 { |
|
112 // Disable format in embedded mode, because it messes up |
|
113 // operations since embedded apps are closed. |
|
114 iState &= ~EDriveFormattable; |
|
115 } |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // TFileManagerDriveInfo::CheckMountL() |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 void TFileManagerDriveInfo::CheckMountL( |
|
123 RFs& aFs, const TInt aDrive ) const |
|
124 { |
|
125 FUNC_LOG |
|
126 |
|
127 HBufC* fullname = HBufC::NewLC( KMaxFullName ); |
|
128 TPtr name( fullname->Des() ); |
|
129 TInt err( aFs.FileSystemName( name, aDrive ) ); |
|
130 if ( err == KErrNone && !name.Length() ) |
|
131 { |
|
132 // Drive isn't mounted at present, so try it now.... |
|
133 // Returns KErrLocked, if locked and the password |
|
134 // is not in store |
|
135 err = aFs.MountFileSystem( KFmgrFatFSName, aDrive ); |
|
136 } |
|
137 CleanupStack::PopAndDestroy( fullname ); |
|
138 |
|
139 LOG_IF_ERROR1( err, "TFileManagerDriveInfo::CheckMountL-err=%d", err ) |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // TFileManagerDriveInfo::FillStateFromDriveInfo() |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TInt TFileManagerDriveInfo::FillStateFromDriveInfo( |
|
147 #ifdef RD_MULTIPLE_DRIVE |
|
148 RFs& aFs, |
|
149 #else // RD_MULTIPLE_DRIVE |
|
150 RFs& /*aFs*/, |
|
151 #endif // RD_MULTIPLE_DRIVE |
|
152 const TInt aDrive, |
|
153 const TDriveInfo& aDrvInfo ) |
|
154 { |
|
155 FUNC_LOG |
|
156 |
|
157 TInt ret( KErrNone ); |
|
158 |
|
159 #ifdef RD_MULTIPLE_DRIVE |
|
160 TUint drvStatus( 0 ); |
|
161 TInt err( DriveInfo::GetDriveStatus( aFs, aDrive, drvStatus ) ); |
|
162 if ( err != KErrNone ) |
|
163 { |
|
164 ERROR_LOG2( "TFileManagerDriveInfo::FillStateFromDriveInfo - aDrive %d, Status err %d", |
|
165 aDrive, err ) |
|
166 } |
|
167 INFO_LOG2( "TFileManagerDriveInfo::FillStateFromDriveInfo - Media type %d, drvStatus 0x%x", |
|
168 aDrvInfo.iType, drvStatus ) |
|
169 if ( aDrvInfo.iType != EMediaNotPresent && ( drvStatus & DriveInfo::EDriveInUse ) ) |
|
170 { |
|
171 ret = KErrInUse; // Drive is reserved for exclusive usage like file transfer |
|
172 } |
|
173 if ( ( drvStatus & DriveInfo::EDriveInternal ) && |
|
174 ( drvStatus & DriveInfo::EDriveExternallyMountable ) ) |
|
175 { |
|
176 // Handle mass storage bits here |
|
177 iState |= EDriveMassStorage | EDriveRemovable; |
|
178 if ( aDrvInfo.iMediaAtt & KMediaAttFormattable ) |
|
179 { |
|
180 iState |= EDriveFormattable; |
|
181 } |
|
182 if ( aDrvInfo.iMediaAtt & KMediaAttLocked ) |
|
183 { |
|
184 // Locking internal drives is not supported |
|
185 iState |= EDriveCorrupted; |
|
186 ret = KErrCorrupt; |
|
187 } |
|
188 return ret; |
|
189 } |
|
190 if ( drvStatus & DriveInfo::EDriveUsbMemory ) |
|
191 { |
|
192 iState |= EDriveUsbMemory; |
|
193 } |
|
194 #endif // RD_MULTIPLE_DRIVE |
|
195 |
|
196 // Setup flags from drive info |
|
197 if ( aDrvInfo.iMediaAtt & KMediaAttWriteProtected ) |
|
198 { |
|
199 iState |= EDriveWriteProtected; |
|
200 } |
|
201 if ( aDrvInfo.iMediaAtt & KMediaAttLocked ) |
|
202 { |
|
203 iState |= EDriveLocked; |
|
204 ret = KErrLocked; |
|
205 } |
|
206 if ( aDrvInfo.iMediaAtt & KMediaAttFormattable ) |
|
207 { |
|
208 iState |= EDriveFormattable; |
|
209 } |
|
210 if ( aDrvInfo.iMediaAtt & KMediaAttLockable ) |
|
211 { |
|
212 iState |= EDriveLockable; |
|
213 } |
|
214 if ( aDrvInfo.iMediaAtt & KMediaAttHasPassword ) |
|
215 { |
|
216 iState |= EDrivePasswordProtected; |
|
217 } |
|
218 if ( ( aDrvInfo.iDriveAtt & KDriveAttRemovable ) || |
|
219 aDrive == KFmgrMemoryCardDrive ) |
|
220 { |
|
221 iState |= EDriveRemovable; |
|
222 #ifdef RD_MULTIPLE_DRIVE |
|
223 if ( drvStatus & DriveInfo::EDriveSwEjectable ) |
|
224 { |
|
225 iState |= EDriveEjectable; |
|
226 } |
|
227 #else // RD_MULTIPLE_DRIVE |
|
228 // Eject is possible for external memory cards |
|
229 if ( !( aDrvInfo.iDriveAtt & KDriveAttInternal ) || |
|
230 aDrive == KFmgrMemoryCardDrive ) |
|
231 { |
|
232 iState |= EDriveEjectable; |
|
233 } |
|
234 #endif // RD_MULTIPLE_DRIVE |
|
235 } |
|
236 if ( aDrvInfo.iDriveAtt & KDriveAttRemote ) |
|
237 { |
|
238 iState |= EDriveRemote; |
|
239 } |
|
240 |
|
241 return ret; |
|
242 } |
|
243 |
|
244 // ----------------------------------------------------------------------------- |
|
245 // TFileManagerDriveInfo::FillStateFromVolumeInfo() |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 TInt TFileManagerDriveInfo::FillStateFromVolumeInfo( |
|
249 RFs& aFs, const TInt aDrive ) |
|
250 { |
|
251 FUNC_LOG |
|
252 |
|
253 TVolumeInfo volInfo; |
|
254 TInt ret( aFs.Volume( volInfo, aDrive ) ); |
|
255 LOG_IF_ERROR1( ret, |
|
256 "TFileManagerDriveInfo::FillStateFromVolumeInfo - Volume err %d", ret ); |
|
257 if ( ret == KErrNone ) |
|
258 { |
|
259 // Get all information from volume info |
|
260 TInt maxLen( Min( volInfo.iName.Length(), KMaxVolumeName ) ); |
|
261 |
|
262 iName = volInfo.iName.Left( maxLen ); |
|
263 iUid = volInfo.iUniqueID; |
|
264 iCapacity = volInfo.iSize; |
|
265 iSpaceFree = volInfo.iFree; |
|
266 |
|
267 iState |= EDrivePresent; |
|
268 |
|
269 if ( volInfo.iSize ) |
|
270 { |
|
271 iState |= EDriveFormatted; |
|
272 } |
|
273 |
|
274 ret = FillStateFromDriveInfo( aFs, aDrive, volInfo.iDrive ); |
|
275 } |
|
276 else |
|
277 { |
|
278 // Get all information from drive info |
|
279 TDriveInfo& drvInfo( volInfo.iDrive ); |
|
280 TInt err( aFs.Drive( drvInfo, aDrive ) ); |
|
281 LOG_IF_ERROR1( err, |
|
282 "TFileManagerDriveInfo::FillStateFromVolumeInfo - Drive err %d", err ); |
|
283 if ( err == KErrNone ) |
|
284 { |
|
285 err = FillStateFromDriveInfo( aFs, aDrive, drvInfo ); |
|
286 |
|
287 // If memory card is not ready but type is present, |
|
288 // then check if it is reserved. |
|
289 if( err == KErrNone && |
|
290 ret == KErrNotReady && |
|
291 drvInfo.iType != EMediaNotPresent ) |
|
292 { |
|
293 // Check USB file transfer state |
|
294 TInt prop( ECoreAppUIsUSBFileTransferUninitialized ); |
|
295 RProperty::Get( |
|
296 KPSUidCoreApplicationUIs, |
|
297 KCoreAppUIsUSBFileTransfer, prop ); |
|
298 if ( prop == ECoreAppUIsUSBFileTransferActive ) |
|
299 { |
|
300 ret = KErrInUse; // Reserved for file transfer |
|
301 } |
|
302 INFO_LOG2( "TFileManagerDriveInfo::FillStateFromVolumeInfo-prop=%d,ret=%d", |
|
303 prop, ret ) |
|
304 } |
|
305 } |
|
306 if ( err != KErrNone ) |
|
307 { |
|
308 ret = err; |
|
309 } |
|
310 } |
|
311 |
|
312 LOG_IF_ERROR2( ret, |
|
313 "TFileManagerDriveInfo::FillStateFromVolumeInfo - aDrive %d, Ret %d", |
|
314 aDrive, ret ) |
|
315 |
|
316 return ret; |
|
317 } |
|
318 |
|
319 // End of File |
|