|
1 /* |
|
2 * Copyright (c) 2006-2009 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: Implementation of CFormatterRFSPlugin class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // SYSTEM INCLUDE |
|
20 #include <centralrepository.h> |
|
21 #include <driveinfo.h> |
|
22 #include <swi\sisregistrysession.h> |
|
23 #include <swi\sisregistryentry.h> |
|
24 #include <swi\sisregistrypackage.h> |
|
25 #include <mmf\common\mmfcontrollerpluginresolver.h> |
|
26 // USER INCLUDE |
|
27 #include "formatterrfsplugin.h" |
|
28 #include "formatterrfspluginprivatecrkeys.h" |
|
29 #include "formatterrfsplugincommon.h" |
|
30 #include "trace.h" |
|
31 |
|
32 // LOCAL CONSTANTS |
|
33 const TUid KCRUidCommsDb = { 0xcccccc00 }; |
|
34 |
|
35 _LIT(KDelimeter, ":"); |
|
36 _LIT(KPathDelimeter, "\\"); |
|
37 |
|
38 |
|
39 // ================= LOCAL FUNCTIONS ======================= |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // ExcludeListNameL |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 static void FileWriteL(RPointerArray<HBufC> &files) |
|
46 { |
|
47 RFs iFs; |
|
48 RFile iFile; |
|
49 User::LeaveIfError(iFs.Connect()); |
|
50 TInt err = iFile.Open(iFs,_L("c:\\private\\100059C9\\excludelistcache.txt"),EFileWrite); |
|
51 |
|
52 if ( err != KErrNone ) |
|
53 { |
|
54 RDebug::Print(_L("CFormatterRFSPlugin::ExcludeListNameL , FileWrite : Failed to open the file")); |
|
55 return; |
|
56 } |
|
57 TBuf8 <1> newLine; |
|
58 newLine.Append('\n'); |
|
59 TInt pos = 0; |
|
60 iFile.Seek(ESeekEnd,pos); |
|
61 TInt size = files.Count(); |
|
62 for ( TInt i=0; i < size; i++) |
|
63 { |
|
64 HBufC8* fileName = HBufC8::NewLC(files[i]->Size()); |
|
65 TPtr8 fileNamePtr(fileName->Des()); |
|
66 fileNamePtr.Copy(*files[i]); |
|
67 iFile.Write(*fileName); |
|
68 iFile.Write(newLine); |
|
69 CleanupStack::PopAndDestroy();//Filename |
|
70 iFile.Flush(); |
|
71 } |
|
72 iFile.Close(); |
|
73 iFs.Close(); |
|
74 |
|
75 } |
|
76 |
|
77 static void MergeFilesL() |
|
78 { |
|
79 |
|
80 RFs iSession; |
|
81 RFile iExclude; |
|
82 |
|
83 RFs iFs; |
|
84 RFile iFile; |
|
85 TInt pos = 0; |
|
86 TInt size_of_script( 0 ); |
|
87 TInt buffer_size( sizeof(TText) ); |
|
88 TInt number_of_chars; |
|
89 |
|
90 User::LeaveIfError(iSession.Connect()); |
|
91 TInt ret = iExclude.Open(iSession,_L("c:\\private\\100059C9\\excludelist.txt"),EFileRead); |
|
92 |
|
93 User::LeaveIfError(iFs.Connect()); |
|
94 TInt err1 = iFile.Open(iFs,_L("c:\\private\\100059C9\\excludelistcache.txt"),EFileWrite); |
|
95 |
|
96 iFile.Seek(ESeekEnd,pos); |
|
97 if ( ret != KErrNone || err1 != KErrNone) |
|
98 { |
|
99 RDebug::Print(_L("CFormatterRFSPlugin::ExcludeListNameL , MergeFiles : Failed to open the file")); |
|
100 return; |
|
101 } |
|
102 HBufC* buffer = HBufC::NewMaxLC( buffer_size ); |
|
103 TPtr8 bufferPtr( (TUint8*)buffer->Ptr(), buffer_size); |
|
104 |
|
105 TInt err(0); |
|
106 err = iExclude.Size( size_of_script ); |
|
107 number_of_chars = size_of_script / sizeof(TText); |
|
108 |
|
109 TInt i(0); |
|
110 for (i = 0; i < number_of_chars; i++) |
|
111 { |
|
112 if ( err == KErrNone ) |
|
113 { |
|
114 err = iExclude.Read( bufferPtr); |
|
115 } |
|
116 iFile.Write(bufferPtr); |
|
117 } |
|
118 iFile.Flush(); |
|
119 iFile.Close(); |
|
120 iFs.Close(); |
|
121 |
|
122 iExclude.Close(); |
|
123 iSession.Close(); |
|
124 |
|
125 CleanupStack::PopAndDestroy();//buffer |
|
126 |
|
127 } |
|
128 |
|
129 static HBufC* ExcludeListNameL( TChar aSystemDrive ) |
|
130 { |
|
131 FUNC_LOG; |
|
132 |
|
133 RDebug::Print(_L("CFormatterRFSPlugin::ExcludeListNameL")); |
|
134 |
|
135 RFs iFs; |
|
136 RFile iFile; |
|
137 |
|
138 _LIT8(KFileName, "c:\\private\\100059C9\\excludelistcache.txt\n"); |
|
139 TBuf8 <50> fileName; |
|
140 fileName.Copy(KFileName); |
|
141 |
|
142 User::LeaveIfError(iFs.Connect()); |
|
143 |
|
144 RDir dir; |
|
145 if(dir.Open(iFs,_L("c:\\private\\100059C9\\"),KEntryAttNormal) != KErrNone) |
|
146 { |
|
147 iFs.MkDir(_L("c:\\private\\100059C9\\")); |
|
148 } |
|
149 |
|
150 TInt rev = iFile.Replace(iFs,_L("c:\\private\\100059C9\\excludelistcache.txt"),EFileWrite); |
|
151 |
|
152 RDebug::Print(_L("CFormatterRFSPlugin::ExcludeListNameL, Replace returned %d"),rev); |
|
153 |
|
154 iFile.Write(fileName); |
|
155 iFile.Flush(); |
|
156 iFile.Close(); |
|
157 iFs.Close(); |
|
158 |
|
159 Swi::RSisRegistrySession session; |
|
160 CleanupClosePushL(session); |
|
161 User::LeaveIfError(session.Connect()); |
|
162 |
|
163 // Get the installed application UIDs |
|
164 RArray<TUid> uids; |
|
165 CleanupClosePushL(uids); |
|
166 session.InstalledUidsL(uids); |
|
167 TInt uidcount = uids.Count(); |
|
168 |
|
169 Swi::RSisRegistryEntry entry; |
|
170 Swi::RSisRegistryEntry entry2; |
|
171 CleanupClosePushL(entry); |
|
172 CleanupClosePushL(entry2); |
|
173 |
|
174 |
|
175 //No issues until here |
|
176 RPointerArray<HBufC> allfiles; |
|
177 RPointerArray<HBufC> nonRemovableFiles; |
|
178 RPointerArray<HBufC> nonRemovableAugmentedFiles; |
|
179 CleanupResetAndDestroyPushL(allfiles); |
|
180 CleanupResetAndDestroyPushL(nonRemovableFiles); |
|
181 CleanupResetAndDestroyPushL(nonRemovableAugmentedFiles); |
|
182 |
|
183 //Logic starts |
|
184 TInt count; |
|
185 RPointerArray<Swi::CSisRegistryPackage> augmentationPackages; |
|
186 CleanupResetAndDestroyPushL(augmentationPackages); |
|
187 for ( TInt iter=0; iter<uidcount; iter++) |
|
188 { |
|
189 User::LeaveIfError(entry.Open(session,uids[iter])); |
|
190 if(EFalse == entry.RemovableL()) |
|
191 { |
|
192 entry.FilesL(nonRemovableFiles); |
|
193 TInt fileCount = nonRemovableFiles.Count(); |
|
194 for (TInt z=fileCount-1; z>=0;z--) |
|
195 { |
|
196 TPtr firstChar(nonRemovableFiles[z]->Des()); |
|
197 if(firstChar.Mid(0,1) == _L("z")) |
|
198 { |
|
199 delete nonRemovableFiles[z]; |
|
200 nonRemovableFiles.Remove(z); |
|
201 } |
|
202 } |
|
203 // Look for augmentations. |
|
204 if(entry.IsAugmentationL()) |
|
205 { |
|
206 entry.AugmentationsL(augmentationPackages); |
|
207 count = entry.AugmentationsNumberL(); |
|
208 for (TInt i=0; i < count; ++i) |
|
209 { |
|
210 User::LeaveIfError(entry2.OpenL(session,*augmentationPackages[i])); |
|
211 if(EFalse == entry2.RemovableL()) |
|
212 { |
|
213 entry2.FilesL(nonRemovableAugmentedFiles); |
|
214 for (TInt c=0; c<nonRemovableAugmentedFiles.Count();c++) |
|
215 { |
|
216 TPtr firstChar(nonRemovableAugmentedFiles[c]->Des()); |
|
217 if(firstChar.Mid(0,1) == _L("z")) |
|
218 { |
|
219 delete nonRemovableAugmentedFiles[c]; |
|
220 nonRemovableAugmentedFiles.Remove(c); |
|
221 } |
|
222 } |
|
223 } |
|
224 entry2.Close(); |
|
225 } |
|
226 } |
|
227 } |
|
228 entry.Close(); |
|
229 } |
|
230 RDebug::Print(_L("CFormatterRFSPlugin::ExcludeListNameL Writing the file names to the excludelist.txt")); |
|
231 |
|
232 FileWriteL(nonRemovableFiles); |
|
233 FileWriteL(nonRemovableAugmentedFiles); |
|
234 MergeFilesL(); |
|
235 |
|
236 CleanupStack::PopAndDestroy(8,&session); |
|
237 |
|
238 HBufC* buf = HBufC::NewLC( KExcludeListcache().Length() + KExcludeListPathNameLenExt ); |
|
239 TPtr bufPtr = buf->Des(); |
|
240 bufPtr.Append( aSystemDrive ); |
|
241 bufPtr.Append( KDriveDelimiter ); |
|
242 bufPtr.Append( KExcludeListcache ); |
|
243 CleanupStack::Pop( buf ); |
|
244 return buf; |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // CheckFileExist |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 static TBool CheckFileExist( RFs& aFs, const TDesC& aFullPath ) |
|
252 { |
|
253 FUNC_LOG; |
|
254 |
|
255 TBool ret( EFalse ); |
|
256 RDir dir; |
|
257 TEntry entry; |
|
258 |
|
259 if ( dir.Open( aFs, aFullPath, KEntryAttNormal ) != KErrNone ) |
|
260 { |
|
261 INFO_1( "Application exclude list '%S' does not exist", &aFullPath ); |
|
262 return EFalse; |
|
263 } |
|
264 if ( dir.Read( entry ) == KErrNone ) |
|
265 { |
|
266 ret = ETrue; |
|
267 } |
|
268 dir.Close(); |
|
269 return ret; |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // CheckAppExcludeLists |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 static TBool CheckAppExcludeListsL( RFs& aFs, TChar aSystemDrive, TChar aRomDrive ) |
|
277 { |
|
278 FUNC_LOG; |
|
279 TBool ret( EFalse ); |
|
280 HBufC* buf = HBufC::NewLC( KMaxPath ); |
|
281 TPtr bufPtr = buf->Des(); |
|
282 |
|
283 // Create search pattern and dir scanner |
|
284 bufPtr.Append( KApplicationExcludeListPath ); |
|
285 bufPtr.Append( KApplicationExcludeListFileSearchPattern ); |
|
286 |
|
287 // Check system drive first |
|
288 bufPtr[0] = aSystemDrive; |
|
289 |
|
290 ret = CheckFileExist( aFs, bufPtr ); |
|
291 |
|
292 if( !ret ) |
|
293 { |
|
294 bufPtr[0] = aRomDrive; |
|
295 ret = CheckFileExist( aFs, bufPtr ); |
|
296 } |
|
297 |
|
298 CleanupStack::PopAndDestroy( buf ); |
|
299 |
|
300 return ret; |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // ResetRepository |
|
305 // --------------------------------------------------------------------------- |
|
306 // |
|
307 static void ResetRepository( const TUid& aRepositoryUid ) |
|
308 { |
|
309 FUNC_LOG; |
|
310 |
|
311 //enforce central repository to re-read setting from .cre file… |
|
312 //in next phase try to modify CentRep setting. Because .cre file is locked by CRepositorySession |
|
313 //CentRep cannot make update and causes that repository goes to inconsistent state. Inconsistent |
|
314 //state ensures that new security settings are readed from drive before any other operation |
|
315 CRepository* repository( NULL ); |
|
316 TRAPD( err, repository = CRepository::NewL( aRepositoryUid ) ); |
|
317 ERROR_1( err, "Failed to open repository 0x%08x (continue)", aRepositoryUid.iUid ); |
|
318 if ( err == KErrNone ) |
|
319 { |
|
320 err = repository->Reset(); |
|
321 ERROR_1( err, "Failed to reset repository 0x%08x (continue)", aRepositoryUid.iUid ); |
|
322 err = repository->Create( 0, 0 ); |
|
323 ERROR_1( err, "Failed to create repository 0x%08x (continue)", aRepositoryUid.iUid ); |
|
324 if ( err == KErrAlreadyExists ) |
|
325 { |
|
326 err = repository->Set( 0, 0 ); |
|
327 ERROR_1( err, "Failed to set value in repository 0x%08x (continue)", aRepositoryUid.iUid ); |
|
328 } |
|
329 } |
|
330 delete repository; |
|
331 } |
|
332 |
|
333 // --------------------------------------------------------------------------- |
|
334 // CFormatterRFSPlugin::NewL |
|
335 // --------------------------------------------------------------------------- |
|
336 // |
|
337 CFormatterRFSPlugin* CFormatterRFSPlugin::NewL( TAny* /*aInitParams*/ ) |
|
338 { |
|
339 FUNC_LOG; |
|
340 |
|
341 CFormatterRFSPlugin* self = new ( ELeave ) CFormatterRFSPlugin; |
|
342 CleanupStack::PushL( self ); |
|
343 self->ConstructL(); |
|
344 CleanupStack::Pop( self ); |
|
345 return self; |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------------------------- |
|
349 // Destructor |
|
350 // --------------------------------------------------------------------------- |
|
351 // |
|
352 CFormatterRFSPlugin::~CFormatterRFSPlugin() |
|
353 { |
|
354 FUNC_LOG; |
|
355 |
|
356 delete iExcludeListName; |
|
357 iFs.Close(); |
|
358 } |
|
359 |
|
360 // --------------------------------------------------------------------------- |
|
361 // CFormatterRFSPlugin::RestoreFactorySettingsL |
|
362 // --------------------------------------------------------------------------- |
|
363 // |
|
364 void CFormatterRFSPlugin::RestoreFactorySettingsL( const TRfsReason /*aType*/ ) |
|
365 { |
|
366 FUNC_LOG; |
|
367 |
|
368 if(iDriveCountInt > 0) |
|
369 { |
|
370 for( TInt i = EDriveA; i <= EDriveZ; ++i ) |
|
371 { |
|
372 if(iDriveListInt[i]) |
|
373 { |
|
374 RDebug::Print(_L("CFormatterRFSPlugin::RestoreFactorySettingsL Performing format on drive = %d"), i); |
|
375 TChar driveChar; |
|
376 User::LeaveIfError( iFs.DriveToChar( i, driveChar ) ); |
|
377 TBuf<3> driveLetter; |
|
378 driveLetter.Append( driveChar); |
|
379 driveLetter.Append( KDelimeter); |
|
380 driveLetter.Append( KPathDelimeter); |
|
381 // perform format on the drive |
|
382 PerformFormat(driveLetter); |
|
383 } |
|
384 } |
|
385 } |
|
386 |
|
387 if ( iExcludeListName || iAppExcludeList ) |
|
388 { |
|
389 RDebug::Print(_L("CFormatterRFSPlugin::RestoreFactorySettingsL Performing selective RFS on System Drive")); |
|
390 |
|
391 TIMESTAMP( "RFS begin" ); |
|
392 |
|
393 TRAPD( err, DoSecureFormatL() ); |
|
394 |
|
395 if( err == KErrInvalidExcList ) |
|
396 { |
|
397 if( iExcludeListName ) |
|
398 { |
|
399 delete iExcludeListName; |
|
400 iExcludeListName = NULL; |
|
401 } |
|
402 iAppExcludeList = EFalse; |
|
403 return; |
|
404 } |
|
405 else |
|
406 { |
|
407 User::LeaveIfError( err ); |
|
408 } |
|
409 |
|
410 // Create directory structure for Central Repository |
|
411 CreateDirectory( KCenRepPrivatePath ); |
|
412 CreateDirectory( KCenRepPersistsPath ); |
|
413 CreateDirectory( KCenRepBurPath ); |
|
414 |
|
415 ResetRepository( KCRUidCommsDb ); |
|
416 |
|
417 TIMESTAMP( "RFS end" ); |
|
418 } |
|
419 } |
|
420 |
|
421 // --------------------------------------------------------------------------- |
|
422 // CFormatterRFSPlugin::GetScriptL |
|
423 // --------------------------------------------------------------------------- |
|
424 // |
|
425 void CFormatterRFSPlugin::GetScriptL( const TRfsReason /*aType*/, TDes& aPath ) |
|
426 { |
|
427 FUNC_LOG; |
|
428 |
|
429 if ( !iExcludeListName && !iAppExcludeList ) |
|
430 { |
|
431 // Add CenRep UID and key |
|
432 aPath.Zero(); |
|
433 aPath.AppendNumFixedWidthUC( KCRUidFormatterRFSPlugin.iUid, EHex, KHexLength ); |
|
434 aPath.Append( KScriptKeySeparator ); |
|
435 aPath.AppendNumFixedWidthUC( KDeepFormatterRFSPlugin, EHex, KHexLength ); |
|
436 aPath.Append( KScriptUidSeparator ); |
|
437 INFO_1( "Script = '%S'", &aPath ); |
|
438 } |
|
439 } |
|
440 |
|
441 // --------------------------------------------------------------------------- |
|
442 // CFormatterRFSPlugin::ExecuteCustomCommandL |
|
443 // --------------------------------------------------------------------------- |
|
444 // |
|
445 void CFormatterRFSPlugin::ExecuteCustomCommandL(const TRfsReason /*aType*/, TDesC& /*aCommand*/ ) |
|
446 { |
|
447 FUNC_LOG; |
|
448 } |
|
449 |
|
450 // --------------------------------------------------------------------------- |
|
451 // CFormatterRFSPlugin::ConstructL |
|
452 // --------------------------------------------------------------------------- |
|
453 // |
|
454 void CFormatterRFSPlugin::ConstructL() |
|
455 { |
|
456 FUNC_LOG; |
|
457 |
|
458 User::LeaveIfError( iFs.Connect() ); |
|
459 |
|
460 User::LeaveIfError(DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, iSystemDrive ) ); |
|
461 |
|
462 |
|
463 // Get the list of drives which have attribute of either internal or removable |
|
464 User::LeaveIfError( DriveInfo::GetUserVisibleDrives(iFs, iDriveListInt, iDriveCountInt, KDriveAttInternal | KDriveAttRemovable )); |
|
465 RDebug::Print(_L("CFormatterRFSPlugin::ConstructL The number of internal/removable drives found = %d"), iDriveCountInt); |
|
466 for( TInt i = EDriveA; i <= EDriveZ; ++i ) |
|
467 { |
|
468 // Filter in the list of drives that are internal mass memory and are externally mountable i.e. are user accessible |
|
469 if (iDriveListInt[i]) |
|
470 { |
|
471 TUint drvStatus( 0 ); |
|
472 User::LeaveIfError( DriveInfo::GetDriveStatus( iFs, i, drvStatus ) ); |
|
473 if ( !((drvStatus & DriveInfo::EDriveInternal)&& (drvStatus & DriveInfo::EDriveExternallyMountable ))) |
|
474 { |
|
475 iDriveCountInt--; |
|
476 iDriveListInt[ i ] = NULL; |
|
477 RDebug::Print(_L("CFormatterRFSPlugin::ConstructL() drive excluded = %d"), i); |
|
478 } |
|
479 } |
|
480 } |
|
481 RDebug::Print(_L("CFormatterRFSPlugin::ConstructL The number of internal/removable drives left after filtering = %d"), iDriveCountInt); |
|
482 |
|
483 iExcludeListName = ExcludeListNameL( iSystemDrive ); |
|
484 |
|
485 RFile file; |
|
486 TInt err = file.Open( iFs, *iExcludeListName, EFileRead ); |
|
487 if ( err == KErrNone ) |
|
488 { |
|
489 TInt fileSize( 0 ); |
|
490 err = file.Size( fileSize ); |
|
491 if ( err != KErrNone || fileSize == 0 ) |
|
492 { |
|
493 // Empty file |
|
494 INFO_1( "Exclude list '%S' is empty", iExcludeListName ); |
|
495 delete iExcludeListName; |
|
496 iExcludeListName = NULL; |
|
497 } |
|
498 } |
|
499 else |
|
500 { |
|
501 // File not found |
|
502 INFO_1( "Exclude list '%S' does not exist", iExcludeListName ); |
|
503 delete iExcludeListName; |
|
504 iExcludeListName = NULL; |
|
505 } |
|
506 file.Close(); |
|
507 |
|
508 User::LeaveIfError( DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRom, iDefaultRomDrive ) ); |
|
509 |
|
510 iAppExcludeList = CheckAppExcludeListsL( iFs, iSystemDrive, iDefaultRomDrive ); |
|
511 |
|
512 if( iAppExcludeList && !iExcludeListName ) |
|
513 { |
|
514 iExcludeListName = KEmptyParameter().AllocL(); |
|
515 } |
|
516 } |
|
517 |
|
518 // --------------------------------------------------------------------------- |
|
519 // CFormatterRFSPlugin::DoSecureFormatL |
|
520 // --------------------------------------------------------------------------- |
|
521 // |
|
522 void CFormatterRFSPlugin::DoSecureFormatL() const |
|
523 { |
|
524 FUNC_LOG; |
|
525 |
|
526 TIMESTAMP( "Secure format begin" ); |
|
527 |
|
528 // check the exclude list file is present |
|
529 if( NULL == iExcludeListName ) |
|
530 { |
|
531 TInt error = KErrNotFound; |
|
532 ERROR( error, "Exclude list file is not found. Secure formatter failed" ); |
|
533 User::LeaveIfError( error ); |
|
534 } |
|
535 |
|
536 HBufC* arg = HBufC::NewLC(iExcludeListName->Length() + KSecureFormatterArgLenExt ); |
|
537 TPtr argPtr = arg->Des(); |
|
538 argPtr.Format(KSecureFormatterArgFmt, iExcludeListName,static_cast<TUint>( iSystemDrive ), KDriveDelimiter, KPathDelimiter ); |
|
539 |
|
540 RProcess process; |
|
541 CleanupClosePushL( process ); |
|
542 TInt err = process.Create( KSecureFormatter, *arg ); |
|
543 ERROR( err, "Failed to create process" ); |
|
544 User::LeaveIfError( err ); |
|
545 |
|
546 TRequestStatus status; |
|
547 process.Logon( status ); |
|
548 process.Resume(); |
|
549 User::WaitForRequest( status ); |
|
550 ERROR( status.Int(), "secure formatter failed" ); |
|
551 // Continue |
|
552 |
|
553 CleanupStack::PopAndDestroy( &process ); |
|
554 CleanupStack::PopAndDestroy( arg ); |
|
555 |
|
556 TIMESTAMP( "Secure format end" ); |
|
557 } |
|
558 |
|
559 // --------------------------------------------------------------------------- |
|
560 // CFormatterRFSPlugin::CreateDirectory |
|
561 // --------------------------------------------------------------------------- |
|
562 // |
|
563 void CFormatterRFSPlugin::CreateDirectory( const TDesC& aDirName ) |
|
564 { |
|
565 FUNC_LOG; |
|
566 |
|
567 TBuf<KMaxPath> path; |
|
568 path.Append( iSystemDrive ); |
|
569 path.Append( KDriveDelimiter ); |
|
570 path.Append( aDirName ); |
|
571 iFs.MkDirAll( path ); // Ignore errors |
|
572 } |
|
573 |
|
574 // --------------------------------------------------------------------------- |
|
575 // CFormatterRFSPlugin::ExecuteFormatCommand |
|
576 // --------------------------------------------------------------------------- |
|
577 // |
|
578 TInt CFormatterRFSPlugin::PerformFormat(const TDesC& aDriveLetter) |
|
579 { |
|
580 RDebug::Print(_L("CRfsCommand::ExecuteFormatCommand()")); |
|
581 RFormat formatter; |
|
582 TInt ret( KErrNone ); |
|
583 |
|
584 TInt count(0); |
|
585 // Open formatter |
|
586 ret = formatter.Open(iFs, aDriveLetter, EHighDensity | EFullFormat, count ); |
|
587 RDebug::Print(_L("CFormatterRFSPlugin::ExecuteFormatCommand(): Formatter open returned : %d"), ret); |
|
588 if ( ret == KErrInUse ) // Locked files in drive |
|
589 { |
|
590 TInt driveNumber = iMassStorageDrive; |
|
591 |
|
592 // Shouldn't assume it's the internal mass storage drive is E:, check the parameter |
|
593 ret = iFs.CharToDrive( aDriveLetter[ 0 ], driveNumber ); |
|
594 RDebug::Print(_L("CFormatterRFSPlugin::ExecuteFormatCommand(): drive numer %d"), driveNumber); |
|
595 |
|
596 // Get the file system name from the drive before dismounting it |
|
597 TFullName name; |
|
598 ret = iFs.FileSystemName(name, driveNumber); |
|
599 RDebug::Print(_L("CFormatterRFSPlugin::ExecuteFormatCommand(): FileSystemName returned : %d, name %S"), ret, &name); |
|
600 |
|
601 // Force a dismount |
|
602 TRequestStatus dummyStat; |
|
603 RDebug::Print(_L("CFormatterRFSPlugin::ExecuteFormatCommand(): Setting notifier")); |
|
604 iFs.NotifyDismount( driveNumber, dummyStat, EFsDismountForceDismount ); |
|
605 iFs.DismountFileSystem( name, driveNumber ); |
|
606 |
|
607 RDebug::Print(_L("CFormatterRFSPlugin::ExecuteFormatCommand(): Waiting for request complete")); |
|
608 User::WaitForRequest(dummyStat); |
|
609 RDebug::Print(_L("CFormatterRFSPlugin::ExecuteFormatCommand(): Request completed")); |
|
610 |
|
611 // Now mount the file system again |
|
612 ret = iFs.MountFileSystem(name, driveNumber); |
|
613 RDebug::Print(_L("CFormatterRFSPlugin::ExecuteFormatCommand(): MountFileSystem returned : %d"), ret); |
|
614 |
|
615 // Try to open formatter second time |
|
616 ret = formatter.Open(iFs, aDriveLetter, EHighDensity | EFullFormat, count ); |
|
617 RDebug::Print(_L("CFormatterRFSPlugin::ExecuteFormatCommand(): Second try: Formatter open returned : %d"), ret); |
|
618 } |
|
619 |
|
620 if ( ret == KErrNone ) |
|
621 { |
|
622 while ( count > 0 ) |
|
623 { |
|
624 ret = formatter.Next( count ); |
|
625 RDebug::Print(_L("CFormatterRFSPlugin::ExecuteFormatCommand(): Format status: %d, tracks remaining %d"), ret, count); |
|
626 } |
|
627 } |
|
628 |
|
629 formatter.Close(); |
|
630 |
|
631 RDebug::Print(_L("CFormatterRFSPlugin::ExecuteFormatCommand(): End: returns %d"), ret); |
|
632 return ret; |
|
633 } |