|
1 // Copyright (c) 1995-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 // |
|
15 |
|
16 #include "sf_std.h" |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 Default constructor. |
|
23 */ |
|
24 EXPORT_C CMountCB::CMountCB() |
|
25 :iMountQ(_FOFF(CFileCB,iMountLink)) |
|
26 { |
|
27 __PRINT1(_L("CMountCB::CMountCB()[0x%x]"),this); |
|
28 } |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 EXPORT_C CMountCB::~CMountCB() |
|
34 { |
|
35 __PRINT1(_L("CMountCB::~CMountCB()[0x%x]"),this); |
|
36 delete iBody; |
|
37 delete iVolumeName; |
|
38 } |
|
39 |
|
40 |
|
41 //----------------------------------------------------------------------------- |
|
42 |
|
43 /** |
|
44 Compares the specified mount control block with this one for inequality. |
|
45 |
|
46 Two mount control blocks are different if either the addresses of |
|
47 the mount control blocks ar different, or their iMountNumber values |
|
48 are different. |
|
49 |
|
50 @param aMount The mount control block to be compared. |
|
51 |
|
52 @return True, if the mount control blocks are different, false otherwise. |
|
53 */ |
|
54 EXPORT_C TBool CMountCB::operator!=(const CMountCB& aMount) const |
|
55 { |
|
56 |
|
57 if (this==(&aMount) && MountNumber()==aMount.MountNumber()) |
|
58 return(FALSE); |
|
59 return(TRUE); |
|
60 } |
|
61 |
|
62 |
|
63 //----------------------------------------------------------------------------- |
|
64 |
|
65 /** |
|
66 Tests whether the given attribute mask matches given criteria (specified |
|
67 in another mask). |
|
68 |
|
69 This function is used when filtering entries. aMatt specifies the criteria |
|
70 to be matched by anAtt. |
|
71 |
|
72 Volumes are ignored, so if anAtt has the volume attribute set then |
|
73 the function returns false. |
|
74 |
|
75 If aMatt does not have a hidden (KEntryAttHidden), system (KEntryAttSystem), |
|
76 or directory (KEntryAttDir) attribute set and anAtt does have |
|
77 the corresponding attribute set, then the function returns false. |
|
78 Alternatively, if aMatt has KEntryAttMustBeFile set and anAtt has |
|
79 the directory attribute set, then the function also returns EFalse. |
|
80 |
|
81 Further matching behaviour can be implemented using |
|
82 KEntryAttMatchExclusive and KEntryAttMatchExclude. |
|
83 |
|
84 @param anAtt Attribute mask to be tested. |
|
85 @param aMatt The attribute match mask. |
|
86 |
|
87 @return True, if the anAtt entry attributes match, false otherwise. |
|
88 |
|
89 @see KEntryAttHidden |
|
90 @see KEntryAttSystem |
|
91 @see KEntryAttDir |
|
92 @see KEntryAttMustBeFile |
|
93 @see KEntryAttMatchExclusive |
|
94 @see KEntryAttMatchExclude |
|
95 */ |
|
96 EXPORT_C TBool CMountCB::MatchEntryAtt(TUint anAtt,TUint aMatt) const |
|
97 { |
|
98 if (aMatt&KEntryAttMatchExclude) |
|
99 { // Include any except |
|
100 if ((anAtt&aMatt)==0) |
|
101 return(ETrue); |
|
102 return(EFalse); |
|
103 } |
|
104 |
|
105 anAtt&=KEntryAttMaskSupported; |
|
106 if ((aMatt&KEntryAttMustBeFile) && (anAtt&KEntryAttIllegal)) |
|
107 return(EFalse); // Not a file |
|
108 |
|
109 if ((aMatt&KEntryAttHidden)==0 && (anAtt&KEntryAttHidden)) |
|
110 return(EFalse); // Ignore hidden unless requested |
|
111 if ((aMatt&KEntryAttSystem)==0 && (anAtt&KEntryAttSystem)) |
|
112 return(EFalse); // Ignore system unless requested |
|
113 if ((aMatt&KEntryAttDir)==0 && (anAtt&KEntryAttDir)) |
|
114 return(EFalse); // Ignore directory unless requested |
|
115 if (anAtt&KEntryAttVolume) |
|
116 return(EFalse); // Ignore volumes |
|
117 |
|
118 anAtt&=(~(KEntryAttHidden|KEntryAttSystem)); // remove hidden and system |
|
119 |
|
120 if (aMatt&KEntryAttMatchExclusive) |
|
121 { // Exclude all except |
|
122 if ((anAtt&aMatt)!=0) |
|
123 return(ETrue); |
|
124 return(EFalse); |
|
125 } |
|
126 return(ETrue); |
|
127 } |
|
128 |
|
129 |
|
130 |
|
131 //----------------------------------------------------------------------------- |
|
132 /** |
|
133 Gets the address of the specified file if it is found in ROM. |
|
134 |
|
135 The default implementation sets aFileStart to NULL, and this should only |
|
136 be overridden by ROM file systems. |
|
137 |
|
138 @param aFileName A reference to a descriptor containing the full file name. |
|
139 @param aFileStart On return, the address of the file, aFileName. |
|
140 The default implementation returns NULL. |
|
141 */ |
|
142 EXPORT_C void CMountCB::IsFileInRom(const TDesC& /*aFileName*/,TUint8*& aFileStart) |
|
143 { |
|
144 |
|
145 aFileStart=NULL; |
|
146 } |
|
147 |
|
148 |
|
149 //----------------------------------------------------------------------------- |
|
150 |
|
151 /** |
|
152 Notifies the file server that the free disk space of the mounted volume |
|
153 has changed outside of the standard file system operations. |
|
154 |
|
155 For example, the background thread of the log flash file system will call |
|
156 this function after a background roll-forward. |
|
157 |
|
158 @param aFreeSpace New free disk space value. |
|
159 */ |
|
160 EXPORT_C void CMountCB::SetDiskSpaceChange(TInt64 aFreeSpace) |
|
161 { |
|
162 const TInt drv=Drive().DriveNumber(); |
|
163 __ASSERT_ALWAYS(aFreeSpace>=0,Fault(ESvrFreeDiskSpace)); |
|
164 __PRINT3(_L("CMountCB::SetDiskSpaceChange(%LU) drv:%d, %dKB"), aFreeSpace, drv, (TUint32)(aFreeSpace>>10)); |
|
165 |
|
166 // Notifying involves memory de-allocation on the file server's heap - |
|
167 // check if we need to switch heaps. |
|
168 RAllocator* current_alloc = &User::Heap(); |
|
169 RAllocator* svr_alloc = ServerThreadAllocator; |
|
170 if (current_alloc != svr_alloc) |
|
171 User::SwitchHeap(svr_alloc); |
|
172 |
|
173 FsNotify::HandleDiskSpace(drv, aFreeSpace); |
|
174 |
|
175 if (current_alloc != svr_alloc) |
|
176 User::SwitchHeap(current_alloc); |
|
177 } |
|
178 |
|
179 //----------------------------------------------------------------------------- |
|
180 /** |
|
181 Initialize the MountCB object. |
|
182 |
|
183 @param aDrive TDrive object that will be used by the mount for drive access |
|
184 @param apFileSystem pointer to the File System object that has produced this CMountCB |
|
185 */ |
|
186 EXPORT_C void CMountCB::InitL(TDrive& aDrive, CFileSystem* apFileSystem) |
|
187 { |
|
188 __PRINT3(_L("CMountCB::InitL()[0x%x] drv:%d, FS:0x%x"), this, aDrive.DriveNumber(), apFileSystem); |
|
189 ASSERT(apFileSystem); |
|
190 |
|
191 |
|
192 SetDrive(&aDrive); |
|
193 DoInitL(aDrive.DriveNumber()); |
|
194 |
|
195 // see whether the file system supports the CFileCB extended API |
|
196 MFileAccessor* fileAccessor = NULL; |
|
197 |
|
198 GetInterfaceTraced(CMountCB::EFileAccessor, (void*&) fileAccessor, NULL); |
|
199 |
|
200 MFileExtendedInterface* fileExtInterface = NULL; |
|
201 GetInterface(CMountCB::EFileExtendedInterface, (void*&) fileExtInterface, NULL); |
|
202 |
|
203 if(!iBody) |
|
204 { |
|
205 iBody = new(ELeave)CMountBody(this, fileAccessor, fileExtInterface); |
|
206 } |
|
207 else |
|
208 { |
|
209 //-- some file systems can call this method several times for the same mount. |
|
210 //-- composite FS, for example. |
|
211 __PRINT1(_L("CMountCB::InitL !!re-initialisation!! iBody:0x%x"), iBody); |
|
212 } |
|
213 |
|
214 SetFileSystem(apFileSystem); //-- associate MountCB object with the file system it belongs to; this relies on iBody |
|
215 } |
|
216 |
|
217 /** |
|
218 Reports whether the specified interface is supported - if it is, |
|
219 the a supplied interface object is modified to it |
|
220 |
|
221 @param aInterfaceId The interface of interest |
|
222 @param aInterface The interface object |
|
223 @return KErrNone if the interface is supported, otherwise KErrNotFound |
|
224 */ |
|
225 EXPORT_C TInt CMountCB::GetInterface(TInt /*aInterfaceId*/,TAny*& /*aInterface*/,TAny* /*aInput*/) |
|
226 { |
|
227 return(KErrNotSupported); |
|
228 } |
|
229 |
|
230 /** |
|
231 Creates a clamp for the named file, and provides clamp handle data to the caller. |
|
232 |
|
233 @param aDriveNo The number of the drive on which the file can be found |
|
234 @param aName Name of the file to clamp |
|
235 @param aHandle Pointer to the clamp handle data |
|
236 @return KErrNone if successful, otherwise one of the systme-wide eror codes. |
|
237 */ |
|
238 TInt CMountCB::ClampFile(const TInt aDriveNo, const TDesC& aName, TAny* aHandle) |
|
239 { |
|
240 return(iBody?iBody->ClampFile(aDriveNo,aName,aHandle):KErrNotSupported); |
|
241 }; |
|
242 |
|
243 /** |
|
244 Reports whether the named file is clamped. |
|
245 |
|
246 @param aName Name of the file to clamp |
|
247 @return 0 if the file is not clamped, 1 if it is, or a system-wide error code. |
|
248 */ |
|
249 EXPORT_C TInt CMountCB::IsFileClamped(/*const TDesC& aName,*/ const TInt64 aUniqueId) |
|
250 { |
|
251 return(iBody?iBody->IsFileClamped(aUniqueId):KErrNotSupported); |
|
252 }; |
|
253 |
|
254 /** |
|
255 Removes the clamp indicated by the specified handle. |
|
256 If this was the last clamp for the drive, any pending dismount is performed. |
|
257 |
|
258 @param aHandle Pointer to the clamp handle data |
|
259 @return KErrNone if successful, a system-wide error code otherwise |
|
260 */ |
|
261 TInt CMountCB::UnclampFile(RFileClamp* aHandle) |
|
262 { |
|
263 return(iBody?iBody->UnclampFile(aHandle):KErrNotSupported); |
|
264 }; |
|
265 |
|
266 /** |
|
267 Returns the current number of clamps |
|
268 |
|
269 @return the number of clamps |
|
270 */ |
|
271 TInt CMountCB::NoOfClamps() |
|
272 { |
|
273 return(iBody?iBody->NoOfClamps():KErrNotSupported); |
|
274 } |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 /** |
|
280 Gets the sub type name of mounted file system (e.g. FAT12, FAT16 or FAT32 of Fat file system). |
|
281 Uses GetInterface() API to avoid binary compatibility break while providing polymorphism. |
|
282 The real implementations is done by classes multiple inherited from both CMountCB and |
|
283 MFileSystemSubType that have implemented MFileSystemSubType::SubType() virtual function. |
|
284 File system that do not support sub types will have KErrNotSupported returned. |
|
285 |
|
286 @param aSubTypeName A descriptor contains return of the sub type name. |
|
287 @return KErrNone if successful; otherwise another of the system wide error codes; |
|
288 KErrNotSupported if sub type is not supported by mounted file system; |
|
289 |
|
290 @see MFileSystemSubType::SubType() |
|
291 */ |
|
292 TInt CMountCB::FileSystemSubType(TDes& aName) |
|
293 { |
|
294 MFileSystemSubType* interface = NULL; |
|
295 TAny* dummy = NULL; |
|
296 TInt rel = GetInterfaceTraced(EGetFileSystemSubType, (TAny*&)(interface), dummy); |
|
297 if((interface != NULL) && (rel == KErrNone)) |
|
298 { |
|
299 rel = interface->SubType(aName); |
|
300 } |
|
301 |
|
302 return rel; |
|
303 } |
|
304 |
|
305 /** |
|
306 Gets the cluster size of mounted file system. |
|
307 Uses GetInterface() API to avoid binary compatibility break while providing polymorphism. |
|
308 The real implementation is done by classes multiple inherited from both CMountCB and |
|
309 MFileSystemClusterSize that have implemented MFileSystemClusterSize::ClusterSize() function. |
|
310 File system that do not support concept of 'clusters' will have the default KErrNotSupported returned. |
|
311 |
|
312 @return Cluster size value if successful; otherwise another of the system wide error codes; |
|
313 KErrNotSupported if cluster is not supported by mounted file system; |
|
314 |
|
315 @see MFileSystemClusterSize::ClusterSize() |
|
316 */ |
|
317 TInt CMountCB::FileSystemClusterSize() |
|
318 { |
|
319 MFileSystemClusterSize* interface = NULL; |
|
320 TAny* dummy = NULL; |
|
321 TInt rel = GetInterfaceTraced(EGetClusterSize, (TAny*&)(interface), dummy); |
|
322 if((interface != NULL) && (rel == KErrNone)) |
|
323 { |
|
324 rel = interface->ClusterSize(); |
|
325 } |
|
326 |
|
327 return rel; |
|
328 } |
|
329 |
|
330 |
|
331 /** |
|
332 @prototype |
|
333 |
|
334 Reads a specified section of the file, regardless of the file's lock state. |
|
335 |
|
336 Uses GetInterface() API to avoid binary compatibility break while providing polymorphism. |
|
337 The real implementation is done by classes multiple inherited from both CMountCB and |
|
338 MFileSystemExtendedInterface that have implemented MFileSystemExtendedInterface::ExtendedReadSectionL() function. |
|
339 File system that do not support large file will implement the default CMountCB::ReadSectionL() function. |
|
340 |
|
341 @see CMountCB::ReadSectionL() |
|
342 |
|
343 @see MFileSystemExtendedInterface::ExtendedReadSectionL() |
|
344 */ |
|
345 void CMountCB::ReadSection64L(const TDesC& aName,TInt64 aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage) |
|
346 { |
|
347 iBody->iFileExtendedInterface->ReadSection64L(aName, aPos, aTrg, aLength, aMessage); |
|
348 } |
|
349 |
|
350 TInt CMountCB::GetFileUniqueId(const TDesC& aName, TInt64& aUniqueId) |
|
351 { |
|
352 return (iBody->iFileAccessor->GetFileUniqueId(aName, aUniqueId)); |
|
353 } |
|
354 |
|
355 TInt CMountCB::Spare3(TInt aVal, TAny* aPtr1, TAny* aPtr2) |
|
356 { |
|
357 return (iBody->iFileAccessor->Spare3(aVal, aPtr1, aPtr2)); |
|
358 } |
|
359 |
|
360 TInt CMountCB::Spare2(TInt aVal, TAny* aPtr1, TAny* aPtr2) |
|
361 { |
|
362 return (iBody->iFileAccessor->Spare2(aVal, aPtr1, aPtr2)); |
|
363 } |
|
364 |
|
365 TInt CMountCB::Spare1(TInt aVal, TAny* aPtr1, TAny* aPtr2) |
|
366 { |
|
367 return (iBody->iFileAccessor->Spare1(aVal, aPtr1, aPtr2)); |
|
368 } |
|
369 |
|
370 TInt CMountCB::GetInterfaceTraced(TInt aInterfaceId, TAny*& aInterface, TAny* aInput) |
|
371 { |
|
372 TRACE3(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetInterface, EF32TraceUidFileSys, |
|
373 DriveNumber(), aInterfaceId, aInput); |
|
374 |
|
375 TInt r = GetInterface(aInterfaceId, aInterface, aInput); |
|
376 |
|
377 TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetInterfaceRet, EF32TraceUidFileSys, r, aInterface); |
|
378 |
|
379 return r; |
|
380 } |
|
381 |
|
382 //----------------------------------------------------------------------------- |
|
383 /** |
|
384 Get the file system name. I.e. The name of the file system that produced this object of CMountCB |
|
385 @param aName buffer for the name |
|
386 */ |
|
387 void CMountCB::FileSystemName(TDes& aName) |
|
388 { |
|
389 aName = FileSystem()->Name(); |
|
390 } |
|
391 |
|
392 |
|
393 |
|
394 //----------------------------------------------------------------------------- |
|
395 /** |
|
396 Associate CFileSystem object (the factory) and the produced CMountCB object. |
|
397 @param aFS pointer to the file system that produced this mount. |
|
398 */ |
|
399 void CMountCB::SetFileSystem(CFileSystem* aFS) |
|
400 { |
|
401 ASSERT(iBody); |
|
402 iBody->SetFileSystem(aFS); |
|
403 } |
|
404 |
|
405 /** |
|
406 Get reference to the filesystem, associated with this mount. |
|
407 */ |
|
408 EXPORT_C CFileSystem* CMountCB::FileSystem() const |
|
409 { |
|
410 ASSERT(iBody); |
|
411 CFileSystem* pFSys = iBody->GetFileSystem(); |
|
412 ASSERT(pFSys); |
|
413 return pFSys; |
|
414 } |
|
415 |
|
416 void CMountCB::SetProxyDriveDismounted() |
|
417 { |
|
418 iBody->SetProxyDriveDismounted(); |
|
419 } |
|
420 |
|
421 TBool CMountCB::ProxyDriveDismounted() |
|
422 { |
|
423 return iBody->ProxyDriveDismounted(); |
|
424 } |
|
425 |
|
426 |
|
427 /** |
|
428 Factory method. Produces CFileCB object. |
|
429 */ |
|
430 CFileCB* CMountCB::NewFileL() const |
|
431 { |
|
432 return FileSystem()->NewFileL(); |
|
433 } |
|
434 |
|
435 /** |
|
436 Factory method. Produces CDirCB object. |
|
437 */ |
|
438 CDirCB* CMountCB::NewDirL() const |
|
439 { |
|
440 return FileSystem()->NewDirL(); |
|
441 } |
|
442 |
|
443 |
|
444 /** |
|
445 Factory method. Produces CFormatCB object. |
|
446 */ |
|
447 CFormatCB* CMountCB::NewFormatL() const |
|
448 { |
|
449 return FileSystem()->NewFormatL(); |
|
450 } |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |