|
1 // ffstraceplugin.cpp |
|
2 // |
|
3 // Copyright (c) 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "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 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include <fshell/extrabtrace.h> |
|
14 #include <f32plugin.h> |
|
15 #include <f32pluginutils.h> |
|
16 #include <fshell/ltkutils.h> |
|
17 |
|
18 //#define LOG_FUNC() RDebug::Printf(__PRETTY_FUNCTION__) |
|
19 //#define LOG(args...) RDebug::Printf(args) |
|
20 //#define LOGW(args...) RDebug::Print(args) |
|
21 #define LOG_FUNC() |
|
22 #define LOG(args...) |
|
23 #define LOGW(args...) |
|
24 |
|
25 |
|
26 NONSHARABLE_CLASS(CFfsTracerPluginFactory) : public CFsPluginFactory |
|
27 { |
|
28 public: |
|
29 static CFfsTracerPluginFactory* NewL(); |
|
30 |
|
31 // from CFsPluginFactory |
|
32 virtual TInt Install(); |
|
33 virtual CFsPlugin* NewPluginL(); |
|
34 virtual TInt UniquePosition(); |
|
35 |
|
36 private: |
|
37 CFfsTracerPluginFactory(); |
|
38 }; |
|
39 |
|
40 NONSHARABLE_CLASS(CFfsTracerFsPlugin) : public CFsPlugin |
|
41 { |
|
42 public: |
|
43 static CFfsTracerFsPlugin* NewL(); |
|
44 virtual ~CFfsTracerFsPlugin(); |
|
45 |
|
46 // from CFsPlugin |
|
47 virtual void InitialiseL(); |
|
48 TInt SessionDisconnect(CSessionFs* aSession); |
|
49 virtual TInt DoRequestL(TFsPluginRequest& aRequest); |
|
50 virtual CFsPluginConn* NewPluginConnL(); |
|
51 private: |
|
52 CFfsTracerFsPlugin(); |
|
53 }; |
|
54 |
|
55 class CFfsTracerFsPluginConn : public CFsPluginConn |
|
56 { |
|
57 public: |
|
58 CFfsTracerFsPluginConn(); |
|
59 |
|
60 // from CFsPluginConn |
|
61 virtual TInt DoControl(CFsPluginConnRequest& aRequest); |
|
62 virtual void DoRequest(CFsPluginConnRequest& aRequest); |
|
63 virtual void DoCancel(TInt aReqMask); |
|
64 }; |
|
65 |
|
66 extern "C" EXPORT_C CFsPluginFactory* CreateFileSystem() |
|
67 { |
|
68 return CFfsTracerPluginFactory::NewL(); |
|
69 } |
|
70 |
|
71 CFfsTracerPluginFactory* CFfsTracerPluginFactory::NewL() |
|
72 { |
|
73 return(new(ELeave) CFfsTracerPluginFactory()); |
|
74 } |
|
75 |
|
76 CFfsTracerPluginFactory::CFfsTracerPluginFactory() |
|
77 { |
|
78 } |
|
79 |
|
80 _LIT(KFfsTracerPluginName, "FfsTracePlugin"); |
|
81 |
|
82 TInt CFfsTracerPluginFactory::Install() |
|
83 { |
|
84 LOG_FUNC(); |
|
85 iSupportedDrives = 0x7FFFFFF; // KPluginSupportAllDrives | KPluginVersionTwo. Not specified symbolically to be compatible with fileservers that didn't support v2 plugins |
|
86 |
|
87 TInt err; |
|
88 err = SetName(&KFfsTracerPluginName); |
|
89 LOG(" returned %d", err); |
|
90 return err; |
|
91 } |
|
92 |
|
93 CFsPlugin* CFfsTracerPluginFactory::NewPluginL() |
|
94 { |
|
95 return CFfsTracerFsPlugin::NewL(); |
|
96 } |
|
97 |
|
98 TInt CFfsTracerPluginFactory::UniquePosition() |
|
99 { |
|
100 return 1; // Isn't used, apparently |
|
101 } |
|
102 |
|
103 // |
|
104 |
|
105 CFfsTracerFsPluginConn::CFfsTracerFsPluginConn() |
|
106 { |
|
107 } |
|
108 |
|
109 TInt CFfsTracerFsPluginConn::DoControl(CFsPluginConnRequest& /*aRequest*/) |
|
110 { |
|
111 return KErrNone; |
|
112 } |
|
113 |
|
114 void CFfsTracerFsPluginConn::DoRequest(CFsPluginConnRequest& /*aRequest*/) |
|
115 { |
|
116 } |
|
117 |
|
118 void CFfsTracerFsPluginConn::DoCancel(TInt /*aReqMask*/) |
|
119 { |
|
120 } |
|
121 |
|
122 // |
|
123 |
|
124 CFfsTracerFsPlugin* CFfsTracerFsPlugin::NewL() |
|
125 { |
|
126 return new(ELeave) CFfsTracerFsPlugin(); |
|
127 } |
|
128 |
|
129 CFfsTracerFsPlugin::CFfsTracerFsPlugin() |
|
130 { |
|
131 LOG_FUNC(); |
|
132 } |
|
133 |
|
134 static const TFsMessage KMessages[] = |
|
135 { |
|
136 EFsDelete, |
|
137 EFsRename, |
|
138 EFsReplace, |
|
139 EFsEntry, |
|
140 EFsFileSubClose, |
|
141 EFsFileOpen, |
|
142 EFsFileCreate, |
|
143 EFsFileReplace, |
|
144 EFsFileTemp, |
|
145 EFsFileRename, |
|
146 }; |
|
147 static const TInt KMessageCount = sizeof(KMessages) / sizeof(TFsMessage); |
|
148 |
|
149 CFfsTracerFsPlugin::~CFfsTracerFsPlugin() |
|
150 { |
|
151 LOG_FUNC(); |
|
152 for (TInt i = 0; i < KMessageCount; i++) |
|
153 { |
|
154 UnregisterIntercept(KMessages[i], CFsPlugin::EPrePostIntercept); |
|
155 } |
|
156 } |
|
157 |
|
158 void CFfsTracerFsPlugin::InitialiseL() |
|
159 { |
|
160 // intercept all calls at start |
|
161 for (TInt i = 0; i < KMessageCount; i++) |
|
162 { |
|
163 RegisterIntercept(KMessages[i], CFsPlugin::EPrePostIntercept); |
|
164 } |
|
165 } |
|
166 |
|
167 TInt CFfsTracerFsPlugin::SessionDisconnect(CSessionFs* /*aSession*/) |
|
168 { |
|
169 // CSessionFs is a private class! It's in the main file server and |
|
170 // has no exported methods! What's the use of passing it here? |
|
171 return KErrNone; |
|
172 } |
|
173 |
|
174 CFsPluginConn* CFfsTracerFsPlugin::NewPluginConnL() |
|
175 { |
|
176 LOG_FUNC(); |
|
177 return new(ELeave) CFfsTracerFsPluginConn(); |
|
178 } |
|
179 |
|
180 TInt CFfsTracerFsPlugin::DoRequestL(TFsPluginRequest& aRequest) |
|
181 { |
|
182 // This is where it all happens |
|
183 |
|
184 TInt subcat = 0; |
|
185 TInt fn = aRequest.Function(); |
|
186 // Map from FS opcodes to the compacted btrace ones |
|
187 switch (fn) |
|
188 { |
|
189 case EFsDelete: subcat = BTrace::EFfsDelete; break; |
|
190 case EFsRename: subcat = BTrace::EFfsRename; break; |
|
191 case EFsReplace: subcat = BTrace::EFfsReplace; break; |
|
192 case EFsEntry: subcat = BTrace::EFfsEntry; break; |
|
193 case EFsFileSubClose: subcat = BTrace::EFfsFileSubClose; break; |
|
194 case EFsFileOpen: subcat = BTrace::EFfsFileOpen; break; |
|
195 case EFsFileCreate: subcat = BTrace::EFfsFileCreate; break; |
|
196 case EFsFileReplace: subcat = BTrace::EFfsFileReplace; break; |
|
197 case EFsFileTemp: subcat = BTrace::EFfsFileTemp; break; |
|
198 case EFsFileRename: subcat = BTrace::EFfsFileRename; break; |
|
199 default: |
|
200 // An operation we're not interested in |
|
201 return KErrNone; |
|
202 } |
|
203 if (aRequest.IsPostOperation()) subcat |= BTrace::EFfsPost; |
|
204 |
|
205 TBuf<513> name; // Twice as big as a max filename because for renames we need it to fit two TFileNames |
|
206 GetName(&aRequest, name); |
|
207 |
|
208 if (fn == EFsRename || fn == EFsFileRename) |
|
209 { |
|
210 name.Append(TChar(0)); |
|
211 TPtr newName((TUint16*)(name.Ptr() + name.Length()), 0, name.MaxLength() - name.Length()); |
|
212 GetNewName(&aRequest, newName); |
|
213 LOGW(_L("new name is %S"), &newName); |
|
214 name.SetLength(name.Length() + newName.Length()); |
|
215 } |
|
216 |
|
217 // Only try to use request.Message() if it's a valid handle |
|
218 TUint threadId = 0xFFFFFFFFu; |
|
219 if(aRequest.Message().Handle() != KNullHandle) |
|
220 { |
|
221 RThread clientThread; |
|
222 aRequest.Message().Client(clientThread, EOwnerThread); |
|
223 threadId = clientThread.Id(); |
|
224 clientThread.Close(); |
|
225 } |
|
226 |
|
227 BTraceBig(BTrace::EFfsTrace, subcat, threadId, name.Ptr(), name.Size()); |
|
228 |
|
229 return KErrNone; |
|
230 } |