|
1 // Copyright (c) 1998-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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32test\lffs\loadlffs.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <f32file.h> |
|
19 |
|
20 LOCAL_D RFs TheFs; |
|
21 |
|
22 LOCAL_C void FormatLFFS(TDes &drive) |
|
23 { |
|
24 |
|
25 RFormat format; |
|
26 TInt count; |
|
27 TInt r; |
|
28 |
|
29 RDebug::Print(_L("Format LFFS drive %S\r\n"), &drive); |
|
30 r = format.Open(TheFs, drive, EHighDensity, count); |
|
31 |
|
32 while (count) |
|
33 { |
|
34 format.Next(count); |
|
35 } |
|
36 |
|
37 format.Close(); |
|
38 } |
|
39 |
|
40 |
|
41 //LOCAL_C void ForceMediaRemount( TMediaDevice aMedia ) |
|
42 // // |
|
43 // // Force a remount on next access |
|
44 // // |
|
45 // { |
|
46 // UserSvr::ForceRemountMedia( aMedia ); |
|
47 // } |
|
48 |
|
49 |
|
50 |
|
51 TInt MountLFFS() |
|
52 { |
|
53 RDebug::Print(_L("Read machine information")); |
|
54 |
|
55 TInt LFFSdriveNumber; |
|
56 TBuf<4> LFFSdriveLetter; |
|
57 |
|
58 LFFSdriveLetter.Zero(); |
|
59 LFFSdriveLetter.Append(_L("K:\\")); |
|
60 LFFSdriveNumber = EDriveK; |
|
61 |
|
62 RDebug::Print(_L("Load device driver: MEDLFS")); |
|
63 TInt r=User::LoadPhysicalDevice(_L("MEDLFS")); |
|
64 if(r != KErrNone && r != KErrAlreadyExists) |
|
65 { |
|
66 RDebug::Print(_L("Loading device driver failed")); |
|
67 return(-1); |
|
68 } |
|
69 |
|
70 RDebug::Print(_L("Add file system: ELFFS")); |
|
71 r=TheFs.AddFileSystem(_L("ELFFS")); |
|
72 if(r != KErrNone && r != KErrAlreadyExists) |
|
73 RDebug::Print(_L("Failed to add ELFFS")); |
|
74 |
|
75 |
|
76 TFullName name; |
|
77 r = TheFs.FileSystemName(name, LFFSdriveNumber); |
|
78 |
|
79 if (name.Length() != 0) |
|
80 { |
|
81 RDebug::Print(_L("Dismounting %S on drive %S\r\n"), &name, &LFFSdriveLetter); |
|
82 r=TheFs.DismountFileSystem(name, LFFSdriveNumber); |
|
83 RDebug::Print(_L("Dismount ret=%d"), r); |
|
84 } |
|
85 |
|
86 // ForceMediaRemount( EFixedMedia1 ); |
|
87 |
|
88 RDebug::Print(_L("Mount LFFS on drive %S\r\n"), &LFFSdriveLetter); |
|
89 r=TheFs.MountFileSystem(_L("Lffs"), LFFSdriveNumber); |
|
90 RDebug::Print(_L("Mount r=%d"),r); |
|
91 //uncommented |
|
92 if (r == KErrCorrupt || r == KErrNotReady) |
|
93 { |
|
94 RDebug::Print(_L("FS Corrupt, formatting")); |
|
95 FormatLFFS(LFFSdriveLetter); |
|
96 } |
|
97 ///to here |
|
98 TheFs.SetSessionPath(LFFSdriveLetter); |
|
99 return(LFFSdriveNumber); |
|
100 } |
|
101 |
|
102 GLDEF_C TInt E32Main() |
|
103 // |
|
104 // Load the LFFS on C: |
|
105 // |
|
106 { |
|
107 |
|
108 CTrapCleanup* cleanup; |
|
109 cleanup=CTrapCleanup::New(); |
|
110 |
|
111 TInt r=TheFs.Connect(); |
|
112 RDebug::Print(_L("Connect ret %d"),r); |
|
113 |
|
114 TRAP(r,MountLFFS()); |
|
115 RDebug::Print(_L("Mount LFFS ret %d"),r); |
|
116 |
|
117 TheFs.Close(); |
|
118 delete cleanup; |
|
119 return(KErrNone); |
|
120 } |
|
121 |