author | hgs |
Mon, 11 Oct 2010 17:54:41 +0100 | |
changeset 286 | 48e57fb1237e |
parent 254 | 1560c419b176 |
permissions | -rw-r--r-- |
0 | 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 |
// f32\sfile\sf_sys.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include "sf_std.h" |
|
19 |
#include <e32uid.h> |
|
20 |
#include "sf_file_cache.h" |
|
134 | 21 |
#include <kernel/localise.h> |
0 | 22 |
#include <f32file.h> |
23 |
||
134 | 24 |
#ifdef OST_TRACE_COMPILER_IN_USE |
25 |
#include "sf_sysTraces.h" |
|
26 |
#endif |
|
27 |
||
0 | 28 |
typedef CFileSystem*(*TFileSystemNew)(); |
29 |
extern CProxyDriveFactory* GetExtension(const TDesC& aName); |
|
30 |
||
31 |
#ifndef __WINS__ |
|
32 |
extern TBool gInitCacheCheckDrivesAndAddNotifications; |
|
33 |
#endif |
|
34 |
||
35 |
GLREF_D TCodePageUtils TheCodePage; |
|
36 |
||
37 |
/** |
|
38 |
Default constructor. |
|
39 |
*/ |
|
40 |
EXPORT_C CFileSystem::CFileSystem() |
|
41 |
{ |
|
134 | 42 |
OstTrace0(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMCONSTRUCTOR, ""); |
43 |
OstTrace0(TRACE_FILESYSTEM,FILESYS_ECFILESYSTEMCONSTRUCTORRETURN, ""); |
|
0 | 44 |
} |
45 |
||
46 |
/** |
|
47 |
Destructor. |
|
48 |
*/ |
|
49 |
EXPORT_C CFileSystem::~CFileSystem() |
|
50 |
{ |
|
134 | 51 |
OstTrace0(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMDESTRUCTOR, ""); |
52 |
OstTrace0(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMDESTRUCTORRETURN, ""); |
|
0 | 53 |
} |
54 |
||
55 |
/** |
|
56 |
Uninstalls the file system. |
|
57 |
||
58 |
This is called just before the file system object is destroyed, and allows |
|
59 |
any clean up to be carried out. |
|
60 |
||
61 |
The default implementation does nothing except return KErrNone. |
|
62 |
Implementations should return an error code on error detection. |
|
63 |
||
64 |
@return KErrNone if successful, otherwise one of the other system wide error |
|
65 |
codes. |
|
66 |
*/ |
|
67 |
EXPORT_C TInt CFileSystem::Remove() |
|
68 |
{ |
|
69 |
||
70 |
return(KErrNone); |
|
71 |
} |
|
72 |
||
73 |
/** |
|
74 |
Tests whether a version is supported. |
|
75 |
||
76 |
This is done decided by comparing the supplied version with iVersion. |
|
77 |
||
78 |
The default implementation uses User::QueryVersionSupported() to |
|
79 |
determine this. |
|
80 |
||
81 |
@param aVer The version to be tested. |
|
82 |
||
83 |
@return True, if aVer is supported; false otherwise |
|
84 |
||
85 |
@see User::QueryVersionSupported |
|
86 |
@see CFileSystem::iVersion |
|
87 |
*/ |
|
88 |
EXPORT_C TBool CFileSystem::QueryVersionSupported(const TVersion& aVer) const |
|
89 |
{ |
|
90 |
||
91 |
return(User::QueryVersionSupported(iVersion,aVer)); |
|
92 |
} |
|
93 |
||
94 |
//#ifndef __DATA_CAGING__ |
|
95 |
/** |
|
96 |
Retrieves the default path for the file system. |
|
97 |
||
98 |
Each session with the file server has a current session path. |
|
99 |
When a new session is opened, its session path is set to the default path |
|
100 |
of the file server. |
|
101 |
At file server start-up, this default path is set to the default path returned |
|
102 |
by the local file system. |
|
103 |
||
104 |
The function should return an appropriate error code when the default path |
|
105 |
cannot be supplied. |
|
106 |
||
107 |
The derived class should override this base class function. |
|
108 |
||
109 |
This default implementation raises an "Fserv fault" 31 panic. |
|
110 |
||
111 |
@param aPath On return, contains the default path for the file system for derived classes. |
|
112 |
||
113 |
@return KErrNone if successful, otherwise one of the other system wide error codes. |
|
114 |
||
115 |
@panic Fserv fault 31 if the default implementation |
|
116 |
for CFileSystem::DefaultPath() is not overridden. |
|
117 |
*/ |
|
118 |
TInt CFileSystem::DefaultPath(TDes& /*aPath*/) const |
|
119 |
{ |
|
120 |
||
121 |
Fault(ESysDefaultPathNotSupported); |
|
122 |
return(KErrNone); |
|
123 |
} |
|
124 |
//#endif |
|
125 |
||
126 |
/** |
|
127 |
Sets the file system's resource library. |
|
128 |
||
129 |
This library represents the loaded file system. |
|
130 |
||
131 |
This is called internally by InstallFileSystem(). |
|
132 |
||
133 |
@param aLib The resource library to be set. |
|
134 |
*/ |
|
135 |
EXPORT_C void CFileSystem::SetLibrary(RLibrary aLib) |
|
136 |
{ |
|
137 |
||
138 |
iLibrary=aLib; |
|
139 |
} |
|
140 |
||
141 |
/** |
|
142 |
Gets the file system's resource library. |
|
143 |
||
144 |
@return The file system's resource library. |
|
145 |
*/ |
|
146 |
EXPORT_C RLibrary CFileSystem::Library() const |
|
147 |
{ |
|
148 |
return(iLibrary); |
|
149 |
} |
|
150 |
||
151 |
/** |
|
152 |
Tests whether the file system supports extensions. |
|
153 |
||
154 |
@return True, if the file system supports extensions, false otherwise. |
|
155 |
The defualt implementation returns false. |
|
156 |
*/ |
|
157 |
EXPORT_C TBool CFileSystem::IsExtensionSupported() const |
|
158 |
{ |
|
159 |
return(EFalse); |
|
160 |
} |
|
161 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
EXPORT_C void CFileSystem::DriveInfo(TDriveInfo& aInfo, TInt aDriveNumber) const |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
GetDriveInfo(aInfo, aDriveNumber); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
166 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
167 |
|
0 | 168 |
EXPORT_C TInt CFileSystem::GetInterface(TInt /*aInterfaceId*/,TAny*& /*aInterface*/,TAny* /*aInput*/) |
169 |
{ |
|
170 |
return(KErrNotSupported); |
|
171 |
} |
|
172 |
||
173 |
EXPORT_C TBool CFileSystem::IsProxyDriveSupported() |
|
174 |
{ |
|
175 |
TAny* dummyInterface; |
|
176 |
if(GetInterface(EProxyDriveSupport, dummyInterface, NULL) == KErrNone) |
|
177 |
return ETrue; |
|
178 |
||
179 |
return EFalse; |
|
180 |
} |
|
181 |
||
182 |
//----------------------------------------------------------------------------- |
|
183 |
/** |
|
184 |
Extended CMountCB factory interface. |
|
185 |
Produces the CMountCB object which can be associated with another CFileSystem owner. |
|
186 |
Used mostly with "automounter" file system |
|
187 |
||
188 |
@param apDrive in: pointer to TDrive, producing right CMountCB can require media access ("automounter" recognising the file system) |
|
189 |
@param apFileSystem out: pointer to the CFileSystem object that actually produced CMountCB instance (might be different from "this") |
|
190 |
@param aForceMount in: ETrue if it is necessarily to force mounting (formatting the media, for example) |
|
191 |
@param aFsNameHash in: desired file system name hash (optional). Specifies which file system will be used to produce appropriate CMountCB object. |
|
192 |
The file system that implements NewMountExL() shall decide how to process it. 0 means "default/not specified". |
|
193 |
||
194 |
@return pointer to the instantiated CMountCB object. |
|
195 |
*/ |
|
196 |
CMountCB* CFileSystem::NewMountExL(TDrive* apDrive, CFileSystem** apFileSystem, TBool aForceMount, TUint32 aFsNameHash) |
|
197 |
{ |
|
198 |
TAny* pa; |
|
199 |
||
200 |
if(GetInterface(EExtendedFunctionality, pa, NULL) == KErrNone) |
|
201 |
{//-- special interface for the case, when CMountCB object will be produced by not _this_ CFileSystem object, but some different. |
|
202 |
//-- in this case apFileSystem will contain a pointer to the real factory. |
|
203 |
MFileSystemExtInterface* pExtIf = (CFileSystem::MFileSystemExtInterface*)pa; |
|
204 |
ASSERT(pExtIf); |
|
205 |
||
206 |
return pExtIf->NewMountExL(apDrive, apFileSystem, aForceMount, aFsNameHash); |
|
207 |
} |
|
208 |
else |
|
209 |
{//--This interface is not supported by current CFileSystem implementation, call normal legacy factory method |
|
210 |
//-- and make _this_ object of CFileSystem produce a new CMountCB |
|
211 |
ASSERT(aFsNameHash == 0); //-- it is impossible to specify the particular FS to be used |
|
212 |
*apFileSystem = this; |
|
213 |
return NewMountL(); |
|
214 |
} |
|
215 |
||
216 |
} |
|
217 |
||
218 |
||
219 |
//----------------------------------------------------------------------------- |
|
220 |
/** |
|
221 |
Get the name of a filesystem from the list of supported on this drive. |
|
222 |
Some filesystems (e.g. "automounter" can support more than one real "child" filesystems. |
|
223 |
For the normal case, only one filesystem is supported (a mouned one). |
|
224 |
||
225 |
@param aFsNumber used to enumerate supported filesystems can be: |
|
226 |
special value KRootFileSystem, or |
|
227 |
0,1,2... - the sequence number of a "child" FS. |
|
228 |
||
229 |
@param aFsName out: buffer for the returned file system name |
|
230 |
||
231 |
@return KErrNone Ok, aFsName contains valid value for the given aFsNumber |
|
232 |
KErrNotFound There is no supported filesystem for the given aFsNumber |
|
233 |
*/ |
|
234 |
TInt CFileSystem::GetSupportedFileSystemName(TInt aFsNumber, TDes& aFsName) |
|
235 |
{ |
|
236 |
TAny* pa; |
|
237 |
||
238 |
//-- we need a special interface to find out the name of the supported file system number "aFsNumber" |
|
239 |
if(GetInterface(EExtendedFunctionality, pa, NULL) == KErrNone) |
|
240 |
{ |
|
241 |
MFileSystemExtInterface* pExtIf = (CFileSystem::MFileSystemExtInterface*)pa; |
|
242 |
ASSERT(pExtIf); |
|
243 |
return pExtIf->GetSupportedFileSystemName(aFsNumber, aFsName); |
|
244 |
} |
|
245 |
else |
|
246 |
{//--This interface is not supported by current CFileSystem implementation, but in this case "Root" and first "child" filesystem mean |
|
247 |
//-- the same and this is "this" filesystem |
|
248 |
||
249 |
if(aFsNumber == RFs::KRootFileSystem || aFsNumber == RFs::KFirstChildFileSystem) |
|
250 |
{ |
|
251 |
aFsName = Name(); |
|
252 |
return KErrNone; |
|
253 |
} |
|
254 |
else |
|
255 |
{ |
|
256 |
return KErrNotFound; |
|
257 |
} |
|
258 |
} |
|
259 |
} |
|
260 |
||
261 |
//----------------------------------------------------------------------------- |
|
262 |
||
263 |
TInt InstallFileSystem(CFileSystem* aSys,RLibrary aLib) |
|
264 |
// |
|
265 |
// Install a file system. |
|
266 |
// |
|
267 |
{ |
|
268 |
||
134 | 269 |
OstTrace1(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMINSTALL, "this %x", aSys); |
270 |
||
0 | 271 |
TInt r=aSys->Install(); |
134 | 272 |
|
273 |
OstTraceData(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMINSTALLYS_EFILESYSTEMNAME, "FileSystemName %S", aSys->Name().Ptr(), aSys->Name().Length()<<1); |
|
274 |
OstTrace1(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMINSTALLRET, "r %d", r); |
|
0 | 275 |
|
276 |
__PRINT1TEMP(_L("InstallFileSystem %S"),aSys->Name()); |
|
277 |
if (r==KErrNone) |
|
278 |
{TRAP(r,FileSystems->AddL(aSys,ETrue))} |
|
279 |
if (r!=KErrNone) |
|
280 |
{ |
|
134 | 281 |
OstTrace1(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMREMOVE1, "this %x", aSys); |
282 |
#ifdef OST_TRACE_COMPILER_IN_USE |
|
0 | 283 |
TInt r = |
284 |
#endif |
|
285 |
aSys->Remove(); |
|
286 |
||
134 | 287 |
OstTrace1(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMREMOVE1RET, "r %d", r); |
0 | 288 |
} |
289 |
if (r==KErrNone) |
|
290 |
aSys->SetLibrary(aLib); |
|
291 |
else |
|
292 |
aSys->Close(); |
|
293 |
return(r); |
|
294 |
} |
|
295 |
||
296 |
EXPORT_C CFileSystem* GetFileSystem(const TDesC& aName) |
|
297 |
// |
|
298 |
// Lookup a file system by name. |
|
299 |
// |
|
300 |
{ |
|
301 |
||
302 |
TInt h=0; |
|
303 |
TInt r=FileSystems->FindByName(h,aName); |
|
304 |
if (r!=KErrNone) |
|
305 |
return(NULL); |
|
306 |
return((CFileSystem*)FileSystems->At(h)); |
|
307 |
} |
|
308 |
||
309 |
TInt TFsAddFileSystem::DoRequestL(CFsRequest* aRequest) |
|
310 |
// |
|
311 |
// Add a file system. |
|
312 |
// |
|
313 |
{ |
|
314 |
||
315 |
__PRINT(_L("TFsAddFileSystem::DoRequestL(CFsRequest* aRequest)")); |
|
316 |
||
317 |
RLibrary lib; |
|
318 |
lib.SetHandle(aRequest->Message().Int0()); // Get library handle |
|
319 |
if (lib.Type()[1]!=TUid::Uid(KFileSystemUidValue)) |
|
320 |
return KErrNotSupported; |
|
321 |
||
322 |
TFileSystemNew f=(TFileSystemNew)lib.Lookup(1); |
|
323 |
if (!f) |
|
324 |
return KErrCorrupt; |
|
325 |
||
134 | 326 |
OstTrace1(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEW, "handle %x", lib.Handle()); |
0 | 327 |
CFileSystem* pS=(*f)(); |
134 | 328 |
OstTrace1(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMNEWRET, "fileSystem %x", pS); |
0 | 329 |
if (!pS) |
330 |
return KErrNoMemory; |
|
331 |
TInt r=InstallFileSystem(pS,lib); |
|
332 |
if (r==KErrNone && !LocalFileSystemInitialized) |
|
333 |
{ |
|
334 |
_LIT(KLocFSY, "ELOCAL.FSY"); |
|
335 |
TFileName fn(lib.FileName()); |
|
336 |
TParsePtrC ppc(fn); |
|
337 |
||
338 |
if (ppc.NameAndExt().CompareF(KLocFSY) == 0) |
|
339 |
r = InitializeLocalFileSystem(pS->Name()); |
|
340 |
} |
|
341 |
return r; |
|
342 |
} |
|
343 |
||
344 |
TInt TFsAddFileSystem::Initialise(CFsRequest* aRequest) |
|
345 |
// |
|
346 |
// |
|
347 |
// |
|
348 |
{ |
|
349 |
TSecurityPolicy policy(RProcess().SecureId(), ECapabilityTCB); |
|
350 |
if (!policy.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Add File System"))) |
|
351 |
return KErrPermissionDenied; |
|
254 | 352 |
|
0 | 353 |
return KErrNone; |
354 |
} |
|
355 |
||
356 |
TInt TFsRemoveFileSystem::DoRequestL(CFsRequest* aRequest) |
|
357 |
// |
|
358 |
// Remove a file system. |
|
359 |
// |
|
360 |
{ |
|
361 |
||
362 |
TFullName name; |
|
363 |
aRequest->ReadL(KMsgPtr0,name); |
|
364 |
CFileSystem* pF=GetFileSystem(name); |
|
365 |
if (pF==NULL) |
|
366 |
return(KErrNotFound); |
|
367 |
||
368 |
CFileSystem* pFs = NULL; |
|
369 |
for(TInt drvNum=0; drvNum<KMaxDrives; drvNum++) |
|
370 |
{ |
|
371 |
FsThreadManager::LockDrive(drvNum); |
|
372 |
pFs=TheDrives[drvNum].GetFSys(); |
|
373 |
FsThreadManager::UnlockDrive(drvNum); |
|
374 |
if(!pFs) |
|
375 |
continue; |
|
376 |
||
377 |
if(name.CompareF(pFs->Name()) == 0) |
|
378 |
return KErrInUse; |
|
379 |
} |
|
380 |
||
134 | 381 |
OstTrace1(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMREMOVE2, "this %x", pF); |
382 |
||
0 | 383 |
TInt r=pF->Remove(); |
134 | 384 |
|
385 |
OstTrace1(TRACE_FILESYSTEM, FSYS_ECFILESYSTEMREMOVE2RET, "r %d", r); |
|
386 |
||
0 | 387 |
if (r!=KErrNone) |
388 |
return(r); |
|
389 |
||
390 |
RLibrary lib=pF->Library(); |
|
391 |
pF->Close(); |
|
392 |
lib.Close(); |
|
393 |
||
394 |
return KErrNone; |
|
395 |
} |
|
396 |
||
397 |
TInt TFsRemoveFileSystem::Initialise(CFsRequest* aRequest) |
|
398 |
{ |
|
399 |
if (!KCapFsRemoveFileSystem.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Remove File System"))) |
|
400 |
return KErrPermissionDenied; |
|
254 | 401 |
|
402 |
//-- check file system name length. It should not exceed KMaxFSNameLength (32 characters) |
|
403 |
TInt r = aRequest->GetDesLength(KMsgPtr0); |
|
404 |
if(r <=0 || r >KMaxFSNameLength) |
|
405 |
return KErrArgument; |
|
406 |
||
0 | 407 |
return KErrNone; |
408 |
} |
|
409 |
||
410 |
LOCAL_C TInt DoMountFileSystem(CFsRequest* aRequest) |
|
411 |
// |
|
412 |
// |
|
413 |
// |
|
414 |
{ |
|
415 |
TInt r = TFileCacheSettings::ReadPropertiesFile(aRequest->Drive()->DriveNumber()); |
|
416 |
if (r != KErrNone) |
|
417 |
return r; |
|
418 |
||
419 |
return(aRequest->Drive()->CheckMount()); |
|
420 |
} |
|
421 |
||
254 | 422 |
//----------------------------------------------------------------------------- |
423 |
/** |
|
424 |
Read optional drive setting from estart.txt that may contain additional drive attributes, like KDRIVEATTLOGICALLYREMOVABLE, KDRIVEATTHIDDEN |
|
425 |
and process them. |
|
426 |
This may lead to addding/removing some attributes to the existing drive's ones. |
|
427 |
N.B Implementation of this is quite strange, it knows only about 2 specific additional attributes.. |
|
0 | 428 |
|
254 | 429 |
@param aDrvNum drive number |
430 |
@param aDrvAtt in: original drive attributes, out: altered drive attributes. |
|
431 |
||
432 |
||
433 |
*/ |
|
434 |
static void DoProcessAdditionalDriveAttributes(TInt aDrvNum, TUint& aDrvAtt) |
|
435 |
{ |
|
436 |
TUint add_Att= 0; //-- additional drive attributes to be added |
|
437 |
TUint remove_Att = 0; //-- additional drive attributes to be removed |
|
438 |
||
439 |
_LIT8( KAddAtt, "AddDriveAttributes"); |
|
440 |
_LIT8( KRemoveAtt, "RemoveDriveAttributes"); |
|
441 |
_LIT8( KLogicallyRemovableAtt, "KDRIVEATTLOGICALLYREMOVABLE"); |
|
442 |
_LIT8( KHiddenAtt, "KDRIVEATTHIDDEN"); |
|
443 |
_LIT8( KLogicallyRemovableAttHex, "0X200"); |
|
444 |
_LIT8( KHiddenAttHex, "0X400"); |
|
445 |
||
446 |
TBuf8<0x100> buf; |
|
447 |
TBuf8<8> sectionName; |
|
448 |
F32Properties::GetDriveSection(aDrvNum, sectionName); |
|
449 |
||
450 |
//-- read and parse "AddDriveAttributes" string |
|
451 |
buf.Zero(); |
|
452 |
TBool bSectFound = F32Properties::GetString(sectionName, KAddAtt, buf); |
|
453 |
||
454 |
if(bSectFound && buf.Length() > 0) |
|
455 |
{ |
|
456 |
TInt pos = 0; |
|
457 |
TInt length = 0; |
|
458 |
TPtrC8 ptr; |
|
459 |
TBool endOfFlag=EFalse; |
|
460 |
||
461 |
while(!endOfFlag) |
|
462 |
{ |
|
463 |
ptr.Set(buf.Mid(pos)); |
|
464 |
length = ptr.Locate(','); |
|
465 |
||
466 |
if(length == KErrNotFound) |
|
467 |
{ |
|
468 |
endOfFlag = ETrue; |
|
469 |
} |
|
470 |
else{ |
|
471 |
ptr.Set(ptr.Left(length)); |
|
472 |
pos += (length +1); |
|
473 |
} |
|
474 |
||
475 |
if(((ptr.MatchF(KLogicallyRemovableAtt)) != KErrNotFound) || ((ptr.MatchF(KLogicallyRemovableAttHex)) != KErrNotFound)) |
|
476 |
add_Att |= KDriveAttLogicallyRemovable; |
|
477 |
||
478 |
if(((ptr.MatchF(KHiddenAtt)) != KErrNotFound) || ((ptr.MatchF(KHiddenAttHex)) != KErrNotFound)) |
|
479 |
add_Att |= KDriveAttHidden; |
|
480 |
||
481 |
}//while(!endOfFlag) |
|
482 |
} |
|
483 |
||
484 |
//-- read and parse "RemoveDriveAttributes" string |
|
485 |
buf.Zero(); |
|
486 |
bSectFound = F32Properties::GetString(sectionName, KRemoveAtt, buf); //oldAtt now contains value of the attributes to be removed from iDriveAtt. |
|
487 |
||
488 |
if(bSectFound && buf.Length() > 0) |
|
489 |
{ |
|
490 |
TInt pos = 0; |
|
491 |
TInt length = 0; |
|
492 |
TPtrC8 ptr; |
|
493 |
TBool endOfFlag=EFalse; |
|
494 |
||
495 |
while(!endOfFlag) |
|
496 |
{ |
|
497 |
ptr.Set(buf.Mid(pos)); |
|
498 |
length = ptr.Locate(','); |
|
499 |
||
500 |
if(length == KErrNotFound) |
|
501 |
{ |
|
502 |
endOfFlag = ETrue; |
|
503 |
} |
|
504 |
else |
|
505 |
{ |
|
506 |
ptr.Set(ptr.Left(length)); |
|
507 |
pos += (length +1); |
|
508 |
} |
|
509 |
||
510 |
if(((ptr.MatchF(KLogicallyRemovableAtt)) != KErrNotFound) || ((ptr.MatchF(KLogicallyRemovableAttHex)) != KErrNotFound)) |
|
511 |
remove_Att |= KDriveAttLogicallyRemovable; |
|
512 |
||
513 |
if(((ptr.MatchF(KHiddenAtt)) != KErrNotFound) || ((ptr.MatchF(KHiddenAttHex)) != KErrNotFound)) |
|
514 |
remove_Att |= KDriveAttHidden; |
|
515 |
||
516 |
}//while(!endOfFlag) |
|
517 |
||
518 |
} |
|
519 |
||
520 |
if ((add_Att & KDriveAttLogicallyRemovable)) |
|
521 |
{ |
|
522 |
add_Att |= KDriveAttRemovable; //KDriveAttLogicallyRemovale should always set KDriveAttRemovale |
|
523 |
} |
|
524 |
||
525 |
if ((remove_Att & KDriveAttRemovable)) |
|
526 |
{ |
|
527 |
remove_Att |= KDriveAttLogicallyRemovable; |
|
528 |
} |
|
529 |
||
530 |
||
531 |
aDrvAtt |= add_Att; //-- add new attributes to drive's ones |
|
532 |
aDrvAtt &= ~remove_Att; //-- remove drive attributes if there are soem indicated |
|
533 |
} |
|
534 |
||
535 |
//----------------------------------------------------------------------------- |
|
536 |
/** |
|
537 |
Try to find and process "ForceRugged" key in the drive section. It looks like: |
|
538 |
[DriveX] |
|
539 |
ForceRugged N |
|
540 |
||
541 |
where when N==0, the drive forced to be non-rugged, when N==1, the drive forced to be rugged, |
|
542 |
otherwise the original value is not overridden. |
|
543 |
||
544 |
@param aDrvNum drive number |
|
545 |
@param aRugged out: true/false if the setting is found, not changed if there is no such a key in the config file |
|
546 |
*/ |
|
547 |
static void DoProcessForceRuggedSetting(TInt aDrvNum, TBool& aRugged) |
|
548 |
{ |
|
549 |
_LIT8(KKeyname, "ForceRugged"); |
|
550 |
TBuf8<8> sectionName; |
|
551 |
F32Properties::GetDriveSection(aDrvNum, sectionName); |
|
552 |
||
553 |
TInt32 val=-1; |
|
554 |
if(F32Properties::GetInt(sectionName, KKeyname, val)) |
|
555 |
{ |
|
556 |
if(val == 0) |
|
557 |
aRugged = EFalse; |
|
558 |
else if(val == 1) |
|
559 |
aRugged = ETrue; |
|
560 |
//else the value is considered to be invalid and nothing changed |
|
561 |
} |
|
562 |
} |
|
563 |
||
564 |
//----------------------------------------------------------------------------- |
|
565 |
/** |
|
566 |
A helper function that binds a file system to the drive along with the optional primary extension etc. |
|
567 |
||
568 |
@param aRequest FS request object |
|
569 |
@param aFsName file system name to be bound to the drive |
|
570 |
@param aIsExtension if true, this means that it's necessary to mount aprimary extension as well |
|
571 |
@param aIsSync specifies if this drive is synchronous one or not |
|
572 |
||
573 |
@return standard error code |
|
574 |
*/ |
|
575 |
static TInt DoMountFsInitialise(CFsRequest* aRequest, TDesC& aFsName, TBool aIsExtension, TBool aIsSync) |
|
0 | 576 |
{ |
577 |
if (!KCapFsMountFileSystem.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Mount File System"))) |
|
578 |
return KErrPermissionDenied; |
|
579 |
||
580 |
TInt r=ValidateDrive(aRequest->Message().Int1(),aRequest); |
|
581 |
if(r!=KErrNone) |
|
582 |
return(r); |
|
583 |
||
254 | 584 |
const TBool driveThreadExists = FsThreadManager::IsDriveAvailable(aRequest->DriveNumber(), ETrue); |
585 |
TDrive& drive = *aRequest->Drive(); |
|
586 |
||
0 | 587 |
if(driveThreadExists) |
588 |
{ |
|
589 |
// A drive thread already exists for this drive.This could be because a filesystem |
|
590 |
// is already mounted, or a proxy drive is loaded. Check the mount to be sure... |
|
254 | 591 |
if(drive.GetFSys()) |
0 | 592 |
{ |
593 |
// Yes, a mount already exists so we can't mount another one! |
|
594 |
return(KErrAccessDenied); |
|
595 |
} |
|
596 |
||
597 |
__ASSERT_DEBUG(IsProxyDrive(aRequest->DriveNumber()), User::Panic(_L("Bad thread state - No Mount or Proxy Drive Exists!"), -999)); |
|
598 |
} |
|
599 |
||
600 |
// ...therefore no drive thread can be present |
|
254 | 601 |
__ASSERT_DEBUG(! &drive.FSys(),Fault(EMountFileSystemFSys)); |
0 | 602 |
|
254 | 603 |
if(drive.IsSubsted()) |
0 | 604 |
return(KErrAccessDenied); |
605 |
||
606 |
CFileSystem* pF = GetFileSystem(aFsName); |
|
254 | 607 |
if(!pF) |
0 | 608 |
return(KErrNotFound); |
609 |
||
254 | 610 |
|
0 | 611 |
// Check that if the drive is a proxy drive (not using TBusLocalDrive) then the filesystem supports these... |
254 | 612 |
const TInt driveNumber = aRequest->DriveNumber(); |
0 | 613 |
if(IsProxyDrive(driveNumber)) |
614 |
{ |
|
615 |
if(!pF->IsProxyDriveSupported()) |
|
616 |
return KErrNotSupported; |
|
617 |
||
618 |
r = LocalDrives::SetupMediaChange(driveNumber); |
|
619 |
} |
|
620 |
||
254 | 621 |
|
622 |
//-- get drive information from the file system |
|
0 | 623 |
TDriveInfo driveInfo; |
624 |
driveInfo.iDriveAtt=0; |
|
254 | 625 |
pF->DriveInfo(driveInfo, driveNumber); //-- the file system can override some driveInfo properties |
0 | 626 |
if(!driveInfo.iDriveAtt) |
627 |
r = KErrArgument; |
|
628 |
||
629 |
if(r == KErrNone && !driveThreadExists) |
|
254 | 630 |
{// determine whether file system synchronous or not not by flag passed in |
0 | 631 |
r=FsThreadManager::InitDrive(driveNumber, aIsSync); |
632 |
} |
|
633 |
||
634 |
if(r!=KErrNone) |
|
635 |
return(r); |
|
636 |
||
637 |
||
254 | 638 |
//-- add a primary drive extension if it is specified |
0 | 639 |
if(aIsExtension && aRequest->Message().Ptr2()!=NULL) |
640 |
{ |
|
254 | 641 |
//-- check extension name length. It should not exceed KMaxFSNameLength (32 characters) |
642 |
r = aRequest->GetDesLength(KMsgPtr2); |
|
643 |
if(r <=0 || r >KMaxFSNameLength) |
|
644 |
return KErrArgument; |
|
645 |
||
646 |
TFSName extName; |
|
647 |
||
0 | 648 |
r = aRequest->Read(KMsgPtr2,extName); |
649 |
if (r!=KErrNone) |
|
650 |
return r; |
|
254 | 651 |
|
0 | 652 |
CProxyDriveFactory* pE=GetExtension(extName); |
653 |
if(pE==NULL) |
|
654 |
return(KErrNotFound); |
|
254 | 655 |
|
656 |
r=drive.MountExtension(pE,ETrue); |
|
0 | 657 |
if(r!=KErrNone) |
658 |
return(r); |
|
659 |
} |
|
660 |
||
254 | 661 |
//-- process optional additional drive attributes that can be specified in estart.txt |
662 |
DoProcessAdditionalDriveAttributes(driveNumber, driveInfo.iDriveAtt); |
|
0 | 663 |
|
254 | 664 |
if(driveInfo.iDriveAtt & KDriveAttLogicallyRemovable) |
665 |
{ |
|
666 |
ASSERT(driveInfo.iDriveAtt & KDriveAttRemovable); |
|
667 |
} |
|
0 | 668 |
|
254 | 669 |
|
670 |
//-- process 'rugged drive' property |
|
671 |
TBool bRuggedDrive = drive.IsRugged(); |
|
672 |
||
673 |
//-- reset 'Rugged drive' attribute if this drive is removable. Having 'rugged' file system on a removable drive |
|
674 |
//-- doesn't make any sense and leads only to the performance degradation |
|
675 |
if(bRuggedDrive && (driveInfo.iDriveAtt & KDriveAttRemovable)) |
|
676 |
{ |
|
677 |
__PRINT1(_L("DoMountFsInitialise() drv:%d is removable. resetting 'Rugged' flag!"), driveNumber); |
|
678 |
bRuggedDrive = EFalse; |
|
679 |
} |
|
0 | 680 |
|
254 | 681 |
DoProcessForceRuggedSetting(driveNumber, bRuggedDrive); //-- setting in estart.txt can override this flag |
682 |
drive.SetRugged(bRuggedDrive); |
|
683 |
||
684 |
||
685 |
//-- let TDrive object know if the drive is synchronous |
|
686 |
drive.SetSynchronous(aIsSync); |
|
687 |
||
688 |
drive.SetAtt(driveInfo.iDriveAtt); //-- finally set drive attributes |
|
689 |
drive.GetFSys()=pF; //-- bind a file system to the drive |
|
690 |
||
0 | 691 |
|
254 | 692 |
TClosedFileUtils::Remove(driveNumber); // empty the closed file queue |
0 | 693 |
|
254 | 694 |
return KErrNone; |
0 | 695 |
} |
696 |
||
254 | 697 |
//----------------------------------------------------------------------------- |
0 | 698 |
TInt TFsMountFileSystem::DoRequestL(CFsRequest* aRequest) |
699 |
// |
|
700 |
// Mount a filesystem on a drive. |
|
701 |
// |
|
702 |
{ |
|
703 |
TInt r=DoMountFileSystem(aRequest); |
|
704 |
if( KErrNone == r ) |
|
705 |
{ |
|
706 |
FsNotify::DiskChange(aRequest->DriveNumber()); |
|
707 |
} |
|
708 |
||
709 |
// Refresh the loader cache to ensure that the new drive is monitored. |
|
710 |
#ifndef __WINS__ |
|
711 |
gInitCacheCheckDrivesAndAddNotifications = EFalse; |
|
712 |
#endif |
|
713 |
||
714 |
return r; |
|
715 |
} |
|
716 |
||
254 | 717 |
//----------------------------------------------------------------------------- |
0 | 718 |
TInt TFsMountFileSystem::Initialise(CFsRequest* aRequest) |
719 |
{ |
|
254 | 720 |
TInt r; |
721 |
||
722 |
//-- check file system name length. It should not exceed KMaxFSNameLength (32 characters) |
|
723 |
r = aRequest->GetDesLength(KMsgPtr0); |
|
724 |
if(r <=0 || r >KMaxFSNameLength) |
|
725 |
return KErrArgument; |
|
726 |
||
727 |
TFSName name; |
|
728 |
r = aRequest->Read(KMsgPtr0, name); |
|
729 |
||
0 | 730 |
if (r == KErrNone) |
731 |
r = DoMountFsInitialise(aRequest,name,ETrue,aRequest->Message().Int3()); |
|
254 | 732 |
|
0 | 733 |
return r; |
734 |
} |
|
735 |
||
254 | 736 |
//----------------------------------------------------------------------------- |
0 | 737 |
TInt TFsMountFileSystemScan::DoRequestL(CFsRequest* aRequest) |
738 |
// |
|
739 |
// mount file system and then call scandrive |
|
740 |
// |
|
741 |
{ |
|
742 |
TInt r=DoMountFileSystem(aRequest); |
|
743 |
// run scandrive if successful mount |
|
744 |
TBool isMountSuccess=(KErrNone==r); |
|
745 |
if(isMountSuccess) |
|
746 |
{ |
|
747 |
r=aRequest->Drive()->ScanDrive(); |
|
748 |
FsNotify::DiskChange(aRequest->DriveNumber()); |
|
749 |
} |
|
254 | 750 |
|
0 | 751 |
TPtrC8 pMS((TUint8*)&isMountSuccess,sizeof(TBool)); |
752 |
aRequest->WriteL(KMsgPtr3,pMS); |
|
753 |
return(r); |
|
754 |
} |
|
755 |
||
756 |
||
254 | 757 |
//----------------------------------------------------------------------------- |
0 | 758 |
TInt TFsMountFileSystemScan::Initialise(CFsRequest* aRequest) |
759 |
{ |
|
254 | 760 |
TInt r; |
761 |
||
762 |
//-- check file system name length. It should not exceed KMaxFSNameLength (32 characters) |
|
763 |
r = aRequest->GetDesLength(KMsgPtr0); |
|
764 |
if(r <=0 || r >KMaxFSNameLength) |
|
765 |
return KErrArgument; |
|
766 |
||
767 |
TFSName name; |
|
768 |
r = aRequest->Read(KMsgPtr0,name); |
|
0 | 769 |
if (r == KErrNone) |
770 |
r = DoMountFsInitialise(aRequest,name,ETrue,EFalse); |
|
254 | 771 |
|
0 | 772 |
return r; |
773 |
} |
|
774 |
||
254 | 775 |
//----------------------------------------------------------------------------- |
776 |
static TInt DoDismountFileSystem(const TDesC& aName, TDrive* aDrive, TBool aAllowRom, TBool aForceDismount) |
|
0 | 777 |
// |
778 |
// Do file system dismount |
|
779 |
// |
|
780 |
{ |
|
781 |
TInt drvNumber=aDrive->DriveNumber(); |
|
782 |
||
783 |
FsThreadManager::LockDrive(drvNumber); |
|
784 |
CFileSystem* pF=GetFileSystem(aName); |
|
785 |
if(pF==NULL) |
|
786 |
{ |
|
787 |
FsThreadManager::UnlockDrive(drvNumber); |
|
788 |
return(KErrNotFound); |
|
789 |
} |
|
790 |
if(aDrive->IsRom() && !aAllowRom) |
|
791 |
{ |
|
792 |
FsThreadManager::UnlockDrive(drvNumber); |
|
793 |
return(KErrAccessDenied); |
|
794 |
} |
|
795 |
||
796 |
if(!aForceDismount) |
|
797 |
{ |
|
798 |
if(aDrive->IsMounted() && aDrive->CurrentMount().LockStatus()!=0) |
|
799 |
{ |
|
800 |
FsThreadManager::UnlockDrive(drvNumber); |
|
801 |
return(KErrInUse); |
|
802 |
} |
|
803 |
if(aDrive->ActiveMounts() > 1) |
|
804 |
{ |
|
805 |
FsThreadManager::UnlockDrive(drvNumber); |
|
806 |
return(KErrInUse); |
|
807 |
} |
|
808 |
||
809 |
aDrive->ReactivateMounts(); |
|
810 |
} |
|
811 |
||
812 |
// ensure that current mount is dismounted |
|
813 |
if(aForceDismount) |
|
814 |
{ |
|
815 |
TInt r = aDrive->FlushCachedFileInfo(ETrue); |
|
816 |
||
817 |
// Dismount the file system even if the flush fails for some reason (media permanently removed, user cancels notifier etc |
|
818 |
if (r!=KErrNone && r!=KErrAbort) |
|
819 |
{ |
|
820 |
FsThreadManager::UnlockDrive(drvNumber); |
|
821 |
return(r); |
|
822 |
} |
|
823 |
aDrive->ForceDismount(); |
|
824 |
} |
|
825 |
else |
|
826 |
{ |
|
827 |
aDrive->Dismount(); |
|
828 |
} |
|
829 |
||
830 |
aDrive->GetFSys()=NULL; |
|
831 |
aDrive->SetAtt(0); |
|
832 |
aDrive->ExtInfo().iCount=0; |
|
833 |
||
834 |
// no need to cancel requests if synchronous since queued |
|
835 |
if(!FsThreadManager::IsDriveSync(drvNumber,EFalse)) |
|
836 |
{ |
|
837 |
CDriveThread* pT=NULL; |
|
838 |
TInt r=FsThreadManager::GetDriveThread(drvNumber,&pT); |
|
839 |
__ASSERT_ALWAYS(r==KErrNone && pT,Fault(EDismountFsDriveThread)); |
|
840 |
pT->CompleteAllRequests(KErrNotReady); |
|
841 |
} |
|
842 |
||
843 |
if(!IsProxyDrive(drvNumber)) |
|
844 |
{ |
|
845 |
// Proxy drives are responsible for managing the drive threads... |
|
846 |
FsThreadManager::CloseDrive(drvNumber); |
|
847 |
} |
|
848 |
||
849 |
FsThreadManager::UnlockDrive(drvNumber); |
|
850 |
FsNotify::DiskChange(drvNumber); |
|
851 |
return(KErrNone); |
|
852 |
} |
|
853 |
||
254 | 854 |
//----------------------------------------------------------------------------- |
0 | 855 |
TInt TFsDismountFileSystem::DoRequestL(CFsRequest* aRequest) |
856 |
// |
|
857 |
// Dismount a filesystem from a drive. |
|
858 |
// |
|
859 |
{ |
|
860 |
TDrive* drive=aRequest->Drive(); |
|
861 |
__ASSERT_DEBUG(&aRequest->Drive()->FSys() && !drive->IsSubsted(),Fault(EDisMountFileSystemFSys)); |
|
254 | 862 |
|
863 |
TFSName name; |
|
0 | 864 |
aRequest->ReadL(KMsgPtr0,name); |
865 |
||
866 |
if(drive->DismountDeferred()) |
|
867 |
return KErrInUse; |
|
868 |
||
869 |
return DoDismountFileSystem(name, drive, EFalse, EFalse); |
|
870 |
} |
|
871 |
||
254 | 872 |
//----------------------------------------------------------------------------- |
0 | 873 |
TInt TFsDismountFileSystem::Initialise(CFsRequest* aRequest) |
874 |
// |
|
875 |
// |
|
876 |
// |
|
877 |
{ |
|
254 | 878 |
TInt r; |
879 |
||
0 | 880 |
if (!KCapFsDismountFileSystem.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Dismount File System"))) |
881 |
return KErrPermissionDenied; |
|
254 | 882 |
|
883 |
//-- check file system name length. It should not exceed KMaxFSNameLength (32 characters) |
|
884 |
r = aRequest->GetDesLength(KMsgPtr0); |
|
885 |
if(r <=0 || r >KMaxFSNameLength) |
|
886 |
return KErrArgument; |
|
887 |
||
888 |
||
889 |
r = ValidateDrive(aRequest->Message().Int1(),aRequest); |
|
0 | 890 |
if(r == KErrNone) |
891 |
{ |
|
892 |
TInt driveNumber = aRequest->DriveNumber(); |
|
893 |
if(IsProxyDrive(driveNumber)) |
|
894 |
{ |
|
895 |
LocalDrives::NotifyChangeCancel(driveNumber); |
|
896 |
} |
|
897 |
} |
|
898 |
return r; |
|
899 |
} |
|
900 |
||
901 |
/** |
|
902 |
Return name of file system mounted on a specified drive or one of the file system names if |
|
903 |
the drive supports several of them. |
|
904 |
*/ |
|
905 |
TInt TFsFileSystemName::DoRequestL(CFsRequest* aRequest) |
|
906 |
{ |
|
907 |
//-- ipc parameters: |
|
908 |
//-- 0 out: file system name decriptor |
|
909 |
//-- 1 drive number |
|
910 |
//-- 2 file system enumerator |
|
911 |
||
912 |
const TInt driveNumber = aRequest->Message().Int1(); |
|
913 |
if (driveNumber < 0 || driveNumber >= KMaxDrives) |
|
914 |
return KErrArgument; |
|
915 |
||
916 |
const TInt fsNumber = aRequest->Message().Int2(); //-- file system number; for RFs::FileSystemName() it is "-1" |
|
917 |
||
918 |
TFullName fsName; |
|
919 |
// lock drive to synchronise with dismounting a file system |
|
920 |
FsThreadManager::LockDrive(driveNumber); |
|
921 |
CFileSystem* pF=TheDrives[driveNumber].GetFSys(); |
|
922 |
FsThreadManager::UnlockDrive(driveNumber); |
|
923 |
||
924 |
TInt err = KErrNone; |
|
925 |
||
926 |
if(pF) |
|
927 |
{ |
|
928 |
if(fsNumber == -1) |
|
929 |
fsName = pF->Name(); //-- this is RFs::FileSystemName() call |
|
930 |
else |
|
931 |
err = pF->GetSupportedFileSystemName(fsNumber, fsName); //-- this is RFs::SupportedFileSystemName() call |
|
932 |
} |
|
933 |
else |
|
934 |
{//-- the drive doesn't have file system installed |
|
935 |
fsName=_L(""); |
|
936 |
err = KErrNotFound; |
|
937 |
} |
|
938 |
||
939 |
aRequest->WriteL(KMsgPtr0, fsName); |
|
940 |
||
941 |
return err; |
|
942 |
} |
|
943 |
||
944 |
TInt TFsFileSystemName::Initialise(CFsRequest* /*aRequest*/) |
|
945 |
{ |
|
946 |
return KErrNone; |
|
947 |
} |
|
948 |
||
949 |
TInt TFsRemountDrive::DoRequestL(CFsRequest* aRequest) |
|
950 |
// |
|
951 |
// Force a remount of the specified drive |
|
952 |
// |
|
953 |
{ |
|
954 |
const TDesC8 *mountInfo=REINTERPRET_CAST(const TDesC8*,aRequest->Message().Ptr1()); |
|
955 |
return(aRequest->Drive()->ForceRemountDrive(mountInfo,aRequest->Message().Handle(),aRequest->Message().Int2()));//changed from thread to message handle |
|
956 |
} |
|
957 |
||
958 |
TInt TFsRemountDrive::Initialise(CFsRequest* aRequest) |
|
959 |
// |
|
960 |
// |
|
961 |
// |
|
962 |
{ |
|
963 |
||
964 |
TInt r=ValidateDriveDoSubst(aRequest->Message().Int0(),aRequest); |
|
965 |
return(r); |
|
966 |
} |
|
967 |
||
968 |
TInt TFsSetLocalDriveMapping::DoRequestL(CFsRequest* aRequest) |
|
969 |
// |
|
970 |
// set up drive letter to local drive mapping |
|
971 |
// |
|
972 |
{ |
|
973 |
return(LocalDrives::SetDriveMappingL(aRequest)); |
|
974 |
} |
|
975 |
||
976 |
TInt TFsSetLocalDriveMapping::Initialise(CFsRequest* /*aRequest*/) |
|
977 |
// |
|
978 |
// |
|
979 |
// |
|
980 |
{ |
|
981 |
return KErrNone; |
|
982 |
} |
|
983 |
||
984 |
_LIT(KCompositeFsName,"Composite"); |
|
985 |
||
986 |
TInt TFsSwapFileSystem::DoRequestL(CFsRequest* aRequest) |
|
987 |
// |
|
988 |
// Swap a filesystem on a drive |
|
989 |
// Should always leave a filesystem mounted on the drive |
|
990 |
// |
|
991 |
{ |
|
254 | 992 |
TFSName newName; |
0 | 993 |
aRequest->ReadL(KMsgPtr0,newName); |
994 |
CFileSystem* pF=GetFileSystem(newName); |
|
995 |
if (pF==NULL) |
|
996 |
return(KErrNotFound); |
|
254 | 997 |
|
998 |
TFSName oldName; |
|
0 | 999 |
aRequest->ReadL(KMsgPtr2,oldName); |
1000 |
TInt drvNumber=aRequest->Message().Int1(); |
|
1001 |
TBool newFsIsComposite = (newName.CompareF(KCompositeFsName) == 0); |
|
1002 |
||
1003 |
if (newFsIsComposite) |
|
1004 |
{ |
|
1005 |
if(CompFsMounted) |
|
1006 |
return(KErrAlreadyExists); |
|
1007 |
if(EDriveZ!=drvNumber) |
|
1008 |
return(KErrNotSupported); |
|
1009 |
} |
|
1010 |
else |
|
1011 |
// swapping filesystem on z: only allow for romfs + compfs |
|
1012 |
if(EDriveZ==drvNumber) |
|
1013 |
return(KErrNotSupported); |
|
1014 |
||
1015 |
TDrive& drive=TheDrives[drvNumber]; |
|
1016 |
||
1017 |
if(drive.DismountDeferred()) |
|
1018 |
return KErrInUse; |
|
1019 |
||
1020 |
TBool clamps=drive.ClampFlag(); |
|
1021 |
if(clamps) |
|
1022 |
return KErrInUse; |
|
1023 |
||
1024 |
// Return an error if the drive is asynchronous. |
|
1025 |
// This function is only supported on synchronous drives. |
|
1026 |
TBool isSync = FsThreadManager::IsDriveSync(drvNumber,EFalse); |
|
1027 |
if(!isSync) |
|
1028 |
return KErrNotSupported; |
|
1029 |
||
1030 |
TInt r=DoDismountFileSystem(oldName,&drive,ETrue,EFalse); |
|
1031 |
if(r!=KErrNone) |
|
1032 |
return(r); |
|
1033 |
||
1034 |
__ASSERT_ALWAYS(drive.GetFSys()==NULL,Fault(ESwapFileSystemNull)); |
|
1035 |
||
1036 |
r=DoMountFsInitialise(aRequest,newName,EFalse,isSync); |
|
1037 |
if(r==KErrNone) |
|
1038 |
r=DoMountFileSystem(aRequest); |
|
1039 |
||
1040 |
if(drive.GetFSys()==NULL || (newFsIsComposite && r!=KErrNone)) |
|
1041 |
{ |
|
1042 |
// remounting of the original filesystem should not fail |
|
1043 |
if(drive.GetFSys()!=NULL) |
|
1044 |
r=DoDismountFileSystem(newName,&drive,ETrue,EFalse); |
|
1045 |
||
1046 |
r=DoMountFsInitialise(aRequest,oldName,EFalse,isSync); |
|
1047 |
if(r==KErrNone) |
|
1048 |
r=DoMountFileSystem(aRequest); |
|
1049 |
||
1050 |
__ASSERT_ALWAYS(r==KErrNone && drive.GetFSys()!=NULL,Fault(ESwapFileSystemMount)); |
|
1051 |
} |
|
1052 |
else if (newFsIsComposite) |
|
1053 |
{ |
|
1054 |
FsThreadManager::ChangeSync(drvNumber,CompFsSync); |
|
1055 |
CompFsMounted=ETrue; |
|
1056 |
} |
|
1057 |
||
1058 |
if(drvNumber==EDriveZ) |
|
1059 |
{ |
|
1060 |
__ASSERT_ALWAYS(r==KErrNone,Fault(ESwapFileSystemRom)); |
|
1061 |
RefreshZDriveCache=ETrue; |
|
1062 |
} |
|
1063 |
return(r); |
|
1064 |
} |
|
1065 |
||
254 | 1066 |
TInt TFsSwapFileSystem::Initialise(CFsRequest* aRequest) |
0 | 1067 |
{ |
254 | 1068 |
TInt len; |
1069 |
||
1070 |
//-- check file system name length. It should not exceed KMaxFSNameLength (32 characters) |
|
1071 |
len = aRequest->GetDesLength(KMsgPtr0); //-- new name |
|
1072 |
if(len <=0 || len >KMaxFSNameLength) |
|
1073 |
return KErrArgument; |
|
1074 |
||
1075 |
len = aRequest->GetDesLength(KMsgPtr2); //-- old name |
|
1076 |
if(len <=0 || len >KMaxFSNameLength) |
|
1077 |
return KErrArgument; |
|
1078 |
||
0 | 1079 |
return KErrNone; |
1080 |
} |
|
1081 |
||
1082 |
||
1083 |
TInt TFsAddCompositeMount::DoRequestL(CFsRequest* aRequest) |
|
1084 |
// |
|
1085 |
// Input fsyName, localDriveNUmber, CompositeDriveNumber |
|
1086 |
// |
|
1087 |
// |
|
1088 |
{ |
|
1089 |
__PRINT(_L("TFsAddCompositeMount::DoRequestL")); |
|
1090 |
||
1091 |
TFileName fsyName; |
|
1092 |
aRequest->ReadL(KMsgPtr0,fsyName); |
|
1093 |
CFileSystem* pNewFileSystem=GetFileSystem(fsyName); |
|
1094 |
||
1095 |
if (pNewFileSystem==NULL) |
|
1096 |
return KErrNotFound; |
|
1097 |
||
1098 |
const TInt localDriveNumber=aRequest->Message().Int1(); |
|
1099 |
const TInt compositeDriveNumber=aRequest->Message().Int2(); |
|
1100 |
const TInt sync=aRequest->Message().Int3(); |
|
1101 |
||
1102 |
__PRINT3(_L("TFsAddCompositeMount::DoRequestL fsy:%S, locDrv:%d, compDrv:%d"),&fsyName, localDriveNumber,compositeDriveNumber); |
|
1103 |
||
1104 |
// Currently, compFS assumed its mounting on romfs, on z: |
|
1105 |
if (compositeDriveNumber!=EDriveZ) |
|
1106 |
return KErrNotSupported; |
|
1107 |
||
1108 |
// Mounts can only be added to the compfs, before it is mounted. |
|
1109 |
if (CompFsMounted) |
|
1110 |
return KErrInUse; |
|
1111 |
||
1112 |
// The drive is needed, so the new sub mount, can be mounted |
|
1113 |
// on it temporarily. ROMFS doest care if we do this as it |
|
1114 |
// has no local mapping. |
|
1115 |
FsThreadManager::LockDrive(compositeDriveNumber); |
|
1116 |
||
1117 |
TRAPD(err, AddFsToCompositeMountL(compositeDriveNumber, *pNewFileSystem, localDriveNumber)); |
|
1118 |
if (err!=KErrNone) |
|
1119 |
{ |
|
1120 |
FsThreadManager::UnlockDrive(compositeDriveNumber); |
|
1121 |
return err; |
|
1122 |
} |
|
1123 |
// Fault(EMountFileSystemFSys); |
|
1124 |
||
1125 |
FsThreadManager::UnlockDrive(compositeDriveNumber); |
|
1126 |
||
1127 |
// The drive will end up asynchronous if any sub mounts are. |
|
1128 |
if (!sync) |
|
1129 |
CompFsSync=EFalse; |
|
1130 |
||
1131 |
return KErrNone; |
|
1132 |
} |
|
1133 |
||
1134 |
||
1135 |
TInt TFsAddCompositeMount::Initialise(CFsRequest* aRequest) |
|
1136 |
// |
|
1137 |
// |
|
1138 |
// |
|
1139 |
{ |
|
1140 |
if (!KCapFsAddCompositeMount.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Add Composite Mount"))) |
|
1141 |
return KErrPermissionDenied; |
|
1142 |
return KErrNone; |
|
1143 |
} |
|
1144 |
||
1145 |
void TFsAddCompositeMount::AddFsToCompositeMountL(TInt aDriveNumber, CFileSystem& aFileSystem, TInt aLocalDriveNumber) |
|
1146 |
{ |
|
1147 |
__PRINT3(_L("TFsAddCompositeMount::AddFsToCompositeMountL() FS:0x%x, drv:%d, local drive:%d"),&aFileSystem, aDriveNumber,aLocalDriveNumber); |
|
1148 |
TInt err; |
|
1149 |
||
1150 |
TDrive& theDrive=TheDrives[aDriveNumber]; |
|
1151 |
CFileSystem* pFs = theDrive.GetFSys(); |
|
1152 |
||
1153 |
CFileSystem* pCompFS = GetFileSystem(_L("Composite")); |
|
1154 |
if ((pCompFS == NULL) || (pFs==NULL)) |
|
1155 |
User::Leave(KErrNotReady); |
|
1156 |
||
1157 |
CMountCB* pMount = pCompFS->NewMountL(); //-- pMount is, actually, a singleton. |
|
1158 |
pMount->InitL(theDrive, pCompFS); |
|
1159 |
||
1160 |
||
1161 |
// invalidate the drive previously used by the local drive just added, and swap with a DriveNumber |
|
1162 |
TInt drv; |
|
1163 |
drv = LocalDrives::GetDriveFromLocalDrive(aLocalDriveNumber); |
|
1164 |
__ASSERT_ALWAYS(drv!=KDriveInvalid, User::Leave(KErrNotSupported)); |
|
1165 |
//__PRINT1(_L("TFsAddCompositeMount::AddFsToCompositeMountL : drive to invalidate %d"),drv); |
|
1166 |
LocalDrives::iMapping[drv] = KDriveInvalid; |
|
1167 |
LocalDrives::iMapping[aDriveNumber] = aLocalDriveNumber; |
|
1168 |
||
1169 |
// Ask the composite mount to mount the new filesystem. |
|
1170 |
TAny* dummy=NULL; |
|
1171 |
err = pMount->GetInterfaceTraced(CMountCB::EAddFsToCompositeMount, dummy, &aFileSystem); |
|
1172 |
if(err != KErrNone) |
|
1173 |
User::Leave(err); |
|
1174 |
} |
|
1175 |
||
1176 |
||
1177 |
TInt TDrive::DeferredDismount() |
|
1178 |
{ |
|
1179 |
// Dismount |
|
1180 |
TInt err = DoDismountFileSystem(GetFSys()->Name(), this, EFalse, ETrue); |
|
1181 |
if (err == CFsRequest::EReqActionBusy) |
|
1182 |
return err; |
|
1183 |
||
286 | 1184 |
// Complete, remove and delete notification requests |
1185 |
FsNotify::HandleDismount(EFsDismountNotifyClients, iDriveNumber, ETrue, err); |
|
1186 |
FsNotify::HandleDismount(EFsDismountForceDismount, iDriveNumber, ETrue, err); |
|
0 | 1187 |
|
1188 |
SetDismountDeferred(EFalse); |
|
1189 |
||
1190 |
return err; |
|
1191 |
} |
|
1192 |
||
1193 |
TInt TFsNotifyDismount::Initialise(CFsRequest* aRequest) |
|
1194 |
// |
|
1195 |
// Initialise a dismount notifier. |
|
1196 |
// - All clients may register with EFsDismountRegisterClient. |
|
1197 |
// - DiskAdmin is required for EFsDismountNotifyClients and EFsDismountForceDismount |
|
1198 |
// |
|
1199 |
{ |
|
1200 |
const RMessage2& m=aRequest->Message(); |
|
1201 |
const TNotifyDismountMode mode = (TNotifyDismountMode)m.Int1(); |
|
1202 |
||
1203 |
switch(mode) |
|
1204 |
{ |
|
1205 |
case EFsDismountForceDismount: |
|
1206 |
case EFsDismountNotifyClients: |
|
1207 |
{ |
|
1208 |
// Capabilities are required to dismount a file system |
|
1209 |
if(!KCapFsDismountFileSystem.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Notify Dismount"))) |
|
1210 |
return KErrPermissionDenied; |
|
1211 |
break; |
|
1212 |
} |
|
1213 |
||
1214 |
case EFsDismountRegisterClient: |
|
1215 |
{ |
|
1216 |
// No capabilities are required for a client to register for notification |
|
1217 |
break; |
|
1218 |
} |
|
1219 |
||
1220 |
default: |
|
1221 |
{ |
|
1222 |
return KErrArgument; |
|
1223 |
//break; |
|
1224 |
} |
|
1225 |
} |
|
1226 |
||
1227 |
return ValidateDrive(aRequest->Message().Int0() ,aRequest); |
|
1228 |
} |
|
1229 |
||
1230 |
TInt TFsNotifyDismount::DoRequestL(CFsRequest* aRequest) |
|
1231 |
// |
|
1232 |
// Register for notification of pending dismount [EFsDismountRegisterClient] |
|
1233 |
// or notify clients of a pending dismount [EFsDismountNotifyClients] |
|
1234 |
// or forcibly dismount the file system [EFsDismountForceDismount] |
|
1235 |
// |
|
1236 |
{ |
|
1237 |
__ASSERT_DEBUG(&aRequest->Drive()->FSys() && !aRequest->Drive()->IsSubsted(), Fault(ENotifyDismount)); |
|
1238 |
||
1239 |
TInt err = KErrNone; |
|
1240 |
||
1241 |
const RMessage2& m=aRequest->Message(); |
|
1242 |
const TNotifyDismountMode mode = (TNotifyDismountMode)m.Int1(); |
|
1243 |
TDrive* theDrive = aRequest->Drive(); |
|
1244 |
const TInt driveNumber = theDrive->DriveNumber(); |
|
1245 |
||
1246 |
switch(mode) |
|
1247 |
{ |
|
1248 |
case EFsDismountRegisterClient: |
|
1249 |
{ |
|
1250 |
err = RegisterNotify(aRequest); |
|
1251 |
break; |
|
1252 |
} |
|
1253 |
||
1254 |
case EFsDismountNotifyClients: |
|
1255 |
{ |
|
1256 |
if(aRequest->Drive()->DismountLocked()) |
|
1257 |
{ |
|
1258 |
err = RegisterNotify(aRequest); |
|
1259 |
if (err != KErrNone) |
|
1260 |
return err; |
|
1261 |
// Complete outstanding client dismount notifiers and flag the drive as pending dismount. |
|
1262 |
FsNotify::HandleDismount(EFsDismountRegisterClient, driveNumber, EFalse, KErrNone); |
|
1263 |
theDrive->SetDismountDeferred(ETrue); |
|
1264 |
} |
|
1265 |
else |
|
1266 |
{ |
|
1267 |
// There are no interested clients, so dismount immediately - if no clamps are present |
|
1268 |
err = theDrive->ClampsOnDrive(); |
|
1269 |
||
1270 |
// If there are no clamps or clamping is not supported, proceed with the enforced dismount |
|
1271 |
// If there are clamps, wait for the clamps to be removed |
|
1272 |
if (err > 0) |
|
1273 |
{ |
|
1274 |
err = RegisterNotify(aRequest); |
|
1275 |
theDrive->SetDismountDeferred(ETrue); |
|
1276 |
} |
|
1277 |
else if (err == 0 || err == KErrNotSupported) |
|
1278 |
{ |
|
1279 |
// No clamps to worry about, so dismount immediately and complete the request |
|
1280 |
err = DoDismountFileSystem(theDrive->GetFSys()->Name(), theDrive, EFalse, ETrue); |
|
1281 |
if (err == CFsRequest::EReqActionBusy) |
|
1282 |
return err; |
|
1283 |
m.Complete(err); |
|
1284 |
} |
|
1285 |
} |
|
1286 |
break; |
|
1287 |
} |
|
1288 |
||
1289 |
case EFsDismountForceDismount: |
|
1290 |
{ |
|
1291 |
// Prepare for deferred dismount due to the presence of file clamps |
|
1292 |
err = theDrive->ClampsOnDrive(); |
|
1293 |
||
1294 |
// If there are no clamps or clamping is not supported, proceed with the enforced dismount |
|
1295 |
// If there are clamps, wait for the clamps to be removed |
|
1296 |
if(err > 0) |
|
1297 |
{ |
|
1298 |
err = RegisterNotify(aRequest); |
|
1299 |
theDrive->SetDismountDeferred(ETrue); |
|
1300 |
} |
|
1301 |
else if (err == 0 || err == KErrNotSupported) |
|
1302 |
{ |
|
1303 |
// Forced dismount - notify/remove all client notifiers and complete immediately |
|
1304 |
err = theDrive->DeferredDismount(); |
|
1305 |
if (err == CFsRequest::EReqActionBusy) |
|
1306 |
return err; |
|
1307 |
m.Complete(err); |
|
1308 |
} |
|
1309 |
break; |
|
1310 |
} |
|
1311 |
||
1312 |
default: |
|
1313 |
{ |
|
1314 |
// We shouldn't ever get here |
|
1315 |
Fault(ENotifyDismount); |
|
1316 |
break; |
|
1317 |
} |
|
1318 |
} |
|
1319 |
||
1320 |
return err; |
|
1321 |
} |
|
1322 |
||
1323 |
TInt TFsNotifyDismount::RegisterNotify(CFsRequest* aRequest) |
|
1324 |
// |
|
1325 |
// Register for notification of pending dismount [EFsDismountRegisterClient] |
|
1326 |
// or notify clients of a pending dismount [EFsDismountNotifyClients] |
|
1327 |
// or forcibly dismount the file system [EFsDismountForceDismount] |
|
1328 |
// |
|
1329 |
{ |
|
1330 |
const RMessage2& m=aRequest->Message(); |
|
1331 |
const TNotifyDismountMode mode = (TNotifyDismountMode)m.Int1(); |
|
1332 |
TDrive* theDrive = aRequest->Drive(); |
|
1333 |
const TInt driveNumber = theDrive->DriveNumber(); |
|
1334 |
||
1335 |
if (mode == EFsDismountNotifyClients && theDrive->DismountDeferred()) |
|
1336 |
{ |
|
1337 |
return KErrInUse; |
|
1338 |
} |
|
1339 |
||
1340 |
CDismountNotifyInfo* info = new CDismountNotifyInfo; |
|
1341 |
if(info == NULL) |
|
1342 |
{ |
|
1343 |
return KErrNoMemory; |
|
1344 |
} |
|
1345 |
||
1346 |
info->Initialise(mode, driveNumber, (TRequestStatus*)m.Ptr2(), m, aRequest->Session()); |
|
1347 |
TInt err = FsNotify::AddDismountNotify(info); |
|
1348 |
if(err != KErrNone) |
|
1349 |
{ |
|
1350 |
delete info; |
|
1351 |
return err; |
|
1352 |
} |
|
1353 |
||
1354 |
return KErrNone; |
|
1355 |
} |
|
1356 |
||
1357 |
TInt TFsNotifyDismountCancel::DoRequestL(CFsRequest* aRequest) |
|
1358 |
// |
|
1359 |
// Cancel a pending dismount notifier - Request |
|
1360 |
// |
|
1361 |
{ |
|
1362 |
CSessionFs* session = aRequest->Session(); |
|
286 | 1363 |
FsNotify::CancelDismountNotifySession(session, (TRequestStatus*)aRequest->Message().Ptr0()); |
1364 |
||
0 | 1365 |
return KErrNone; |
1366 |
} |
|
1367 |
||
1368 |
TInt TFsNotifyDismountCancel::Initialise(CFsRequest* /*aRequest*/) |
|
1369 |
// |
|
1370 |
// Cancel a pending dismount notifier - Initialise |
|
1371 |
// |
|
1372 |
{ |
|
1373 |
return KErrNone; |
|
1374 |
} |
|
1375 |
||
1376 |
TInt TFsAllowDismount::DoRequestL(CFsRequest* aRequest) |
|
1377 |
// |
|
1378 |
// Notifies the file server that the client is finished with the drive. |
|
1379 |
// The last client to allow the dismount signals the dismounting thread. |
|
1380 |
// |
|
1381 |
{ |
|
1382 |
TDrive* theDrive = aRequest->Drive(); |
|
1383 |
const TInt driveNumber = theDrive->DriveNumber(); |
|
1384 |
||
1385 |
// Verify that the client has registered for notification |
|
1386 |
if(!FsNotify::HandlePendingDismount(aRequest->Session(), driveNumber)) |
|
1387 |
return KErrNotFound; |
|
1388 |
||
286 | 1389 |
return theDrive->DeferredDismountCheck(); |
0 | 1390 |
} |
1391 |
||
1392 |
TInt TFsAllowDismount::Initialise(CFsRequest* aRequest) |
|
1393 |
// |
|
1394 |
// Notifies the file server that the client is finished with the drive |
|
1395 |
// |
|
1396 |
{ |
|
1397 |
return ValidateDrive(aRequest->Message().Int0(),aRequest); |
|
1398 |
} |
|
1399 |
||
1400 |
||
286 | 1401 |
TInt TFsDeferredDismount::Initialise(CFsRequest* /*aRequest*/) |
1402 |
{ |
|
1403 |
return KErrNone; |
|
1404 |
} |
|
1405 |
||
1406 |
/* |
|
1407 |
Dismount the file system - this internal request is queued when one client issues a EFsDismountNotifyClients |
|
1408 |
request and another client with an outstanding EFsDismountRegisterClient closes their session (in the context |
|
1409 |
of the main file server thread) without sending a EFsAllowDismount request. |
|
1410 |
||
1411 |
*/ |
|
1412 |
TInt TFsDeferredDismount::DoRequestL(CFsRequest* aRequest) |
|
1413 |
{ |
|
1414 |
return TheDrives[aRequest->DriveNumber()].DeferredDismountCheck(); |
|
1415 |
} |
|
1416 |
||
1417 |
||
0 | 1418 |
TInt TFsMountProxyDrive::DoRequestL(CFsRequest* aRequest) |
1419 |
{ |
|
1420 |
return LocalDrives::MountProxyDrive(aRequest); |
|
1421 |
} |
|
1422 |
||
1423 |
TInt TFsMountProxyDrive::Initialise(CFsRequest* aRequest) |
|
1424 |
{ |
|
1425 |
if (!KCapFsMountProxyDrive.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("Mount Proxy Drive"))) |
|
1426 |
return KErrPermissionDenied; |
|
1427 |
||
1428 |
TInt err = LocalDrives::InitProxyDrive(aRequest); |
|
1429 |
if(err == KErrNone) |
|
1430 |
{ |
|
1431 |
// Now create the drive thread - proxy extensions are always asynchronous... |
|
1432 |
err = FsThreadManager::InitDrive(aRequest->DriveNumber(), EFalse); |
|
1433 |
} |
|
1434 |
||
1435 |
return err; |
|
1436 |
} |
|
1437 |
||
1438 |
TInt TFsLoadCodePage::DoRequestL(CFsRequest* aRequest) |
|
1439 |
// |
|
1440 |
// Installs a code page |
|
1441 |
// |
|
1442 |
{ |
|
1443 |
__PRINT(_L("TFsLoadCodePage::DoRequestL(CFsRequest* aRequest)")); |
|
1444 |
||
1445 |
RLibrary lib; |
|
1446 |
lib.SetHandle(aRequest->Message().Int0()); |
|
1447 |
if (lib.Type()[1]!=TUid::Uid(KLocaleDllUidValue16)) |
|
1448 |
return(KErrNotSupported); |
|
1449 |
||
1450 |
if(TheCodePage.CodepageLoaded() == TCodePageUtils::ECodePageDll) |
|
1451 |
{ |
|
1452 |
return(KErrAlreadyExists); |
|
1453 |
} |
|
1454 |
||
1455 |
/* |
|
1456 |
// Actual Functions form the Codepage Dll (fatCnvU.def) |
|
1457 |
1 : void UnicodeConv::ConvertFromUnicodeL(class TDes8 &, class TDesC16 const &) |
|
1458 |
2 : void UnicodeConv::ConvertToUnicodeL(class TDes16 &, class TDesC8 const &) |
|
1459 |
3 : int UnicodeConv::IsLegalShortNameCharacter(unsigned int) |
|
1460 |
4 : int UnicodeConv::ConvertFromUnicodeL(class TDes8 &, class TDesC16 const &, int) |
|
1461 |
5 : int UnicodeConv::ConvertToUnicodeL(class TDes16 &, class TDesC8 const &, int) |
|
1462 |
*/ |
|
1463 |
||
1464 |
/* |
|
1465 |
Read only the following fns from Codepage Dll ( lib.Lookup(1) and lib.Lookup(2) retained in cpnnn.dll for backward compatibility) |
|
1466 |
3 : int UnicodeConv::IsLegalShortNameCharacter(unsigned int) |
|
1467 |
4 : int UnicodeConv::ConvertFromUnicodeL(class TDes8 &, class TDesC16 const &, int) |
|
1468 |
5 : int UnicodeConv::ConvertToUnicodeL(class TDes16 &, class TDesC8 const &, int) |
|
1469 |
*/ |
|
1470 |
||
1471 |
TheCodePage.iCodePageFunctions.iIsLegalShortNameCharacter = (TCodePageFunctions::TIsLegalShortNameCharacter)(lib.Lookup(3)); |
|
1472 |
TheCodePage.iCodePageFunctions.iConvertFromUnicodeL = (TCodePageFunctions::TConvertFromUnicodeL)(lib.Lookup(4)); |
|
1473 |
TheCodePage.iCodePageFunctions.iConvertToUnicodeL = (TCodePageFunctions::TConvertToUnicodeL)(lib.Lookup(5)); |
|
1474 |
||
1475 |
if( TheCodePage.iCodePageFunctions.iIsLegalShortNameCharacter == NULL || |
|
1476 |
TheCodePage.iCodePageFunctions.iConvertFromUnicodeL == NULL || |
|
1477 |
TheCodePage.iCodePageFunctions.iConvertToUnicodeL == NULL ) |
|
1478 |
{ |
|
1479 |
return(KErrCorrupt); |
|
1480 |
} |
|
1481 |
TheCodePage.iCodepageLoaded = TCodePageUtils::ECodePageDll; |
|
1482 |
||
1483 |
return(KErrNone); |
|
1484 |
} |
|
1485 |
||
1486 |
TInt TFsLoadCodePage::Initialise(CFsRequest* aRequest) |
|
1487 |
// |
|
1488 |
// Installs a code page |
|
1489 |
// |
|
1490 |
{ |
|
1491 |
__PRINT(_L("TFsLoadCodePage::Initialise(CFsRequest* aRequest)")); |
|
1492 |
||
1493 |
// Set the drive |
|
1494 |
TInt drive = aRequest->Session()->CurrentDrive(); |
|
1495 |
aRequest->SetDrive(&TheDrives[drive]); |
|
1496 |
||
1497 |
TSecurityPolicy policy(RProcess().SecureId(), ECapabilityDiskAdmin); |
|
1498 |
if (!policy.CheckPolicy(aRequest->Message(), __PLATSEC_DIAGNOSTIC_STRING("TFsLoadCodePage::Initialise"))) |
|
1499 |
{ |
|
1500 |
return KErrPermissionDenied; |
|
1501 |
} |
|
1502 |
||
1503 |
return KErrNone; |
|
1504 |
} |
|
1505 |
||
1506 |
// use second half of ISO Latin 1 character set for extended chars |
|
1507 |
const TUint KExtendedCharStart=0x80; |
|
1508 |
const TUint KExtendedCharEnd=0xff; |
|
1509 |
||
1510 |
_LIT8(KLit8ReplacementForUnconvertibleUnicodeCharacters, "_"); |
|
1511 |
||
1512 |
TCodePageUtils::TCodePageUtils() |
|
1513 |
// |
|
1514 |
// Constructor |
|
1515 |
// |
|
1516 |
: iCodePageFunctions(), |
|
1517 |
iLocaleFatUtilityFunctions(NULL), |
|
1518 |
iCodepageLoaded(ENone) |
|
1519 |
{ |
|
1520 |
} |
|
1521 |
||
1522 |
TBool TCodePageUtils::IsCodepageLoaded() const |
|
1523 |
// |
|
1524 |
// Returns ETrue if a codepage is loaded |
|
1525 |
// |
|
1526 |
{ |
|
1527 |
return(iCodepageLoaded != ENone); |
|
1528 |
} |
|
1529 |
||
1530 |
TCodePageUtils::TCodepageLoaded TCodePageUtils::CodepageLoaded() const |
|
1531 |
// |
|
1532 |
// Returns the type of active codepage |
|
1533 |
// |
|
1534 |
{ |
|
1535 |
return(iCodepageLoaded); |
|
1536 |
} |
|
1537 |
||
1538 |
void TCodePageUtils::SetLocaleCodePage(TFatUtilityFunctions* aFunctions) |
|
1539 |
// |
|
1540 |
// Sets the current codepage to that provided by the current Locale DLL |
|
1541 |
// |
|
1542 |
{ |
|
1543 |
if(iCodepageLoaded == ENone && aFunctions) |
|
1544 |
{ |
|
1545 |
iLocaleFatUtilityFunctions = aFunctions; |
|
1546 |
iCodepageLoaded = ELocaleDll; |
|
1547 |
} |
|
1548 |
} |
|
1549 |
||
1550 |
TFatUtilityFunctions* TCodePageUtils::LocaleFatUtilityFunctions() const |
|
1551 |
// |
|
1552 |
// Returns function pointer to the read Locale conversions functions |
|
1553 |
// |
|
1554 |
{ |
|
1555 |
return(iLocaleFatUtilityFunctions); |
|
1556 |
} |
|
1557 |
||
1558 |
TCodePageFunctions TCodePageUtils::CodepageFatUtilityFunctions() const |
|
1559 |
// |
|
1560 |
// Returns structure to function pointers to the read Codepage conversions functions |
|
1561 |
// |
|
1562 |
{ |
|
1563 |
return(iCodePageFunctions); |
|
1564 |
} |
|
1565 |
||
1566 |
TBool TCodePageUtils::ConvertFromUnicode(TDes8& aForeign, const TDesC16& aUnicode, TOverflowAction aOverflowAction) const |
|
1567 |
/** |
|
1568 |
Convert from Unicode, truncating if there is not enough room in the output. |
|
1569 |
||
1570 |
@param aForeign The output is appended here. |
|
1571 |
@param aUnicode The input. |
|
1572 |
||
1573 |
@return False if and only if aForeign has not enough space remaining. |
|
1574 |
*/ |
|
1575 |
{ |
|
1576 |
TBool allConverted = ETrue; |
|
1577 |
const TInt maximumLength=aForeign.MaxLength(); |
|
1578 |
TInt lengthToCopy=aUnicode.Length(); |
|
1579 |
// do not cross the maximum foreign length |
|
1580 |
if (maximumLength<lengthToCopy) |
|
1581 |
{ |
|
1582 |
if (aOverflowAction==TCodePageUtils::EOverflowActionLeave) |
|
1583 |
{ |
|
1584 |
allConverted = EFalse; |
|
1585 |
return allConverted; |
|
1586 |
} |
|
1587 |
lengthToCopy=maximumLength; |
|
1588 |
} |
|
1589 |
||
1590 |
aForeign.SetLength(lengthToCopy); |
|
1591 |
||
1592 |
TInt j=0; // offset for aForeign[] |
|
1593 |
TInt i=0; // offset for aUnicode[] |
|
1594 |
for (i=0; i<lengthToCopy; ++i) |
|
1595 |
{ |
|
1596 |
const TDesC8& replacementChar = KLit8ReplacementForUnconvertibleUnicodeCharacters; |
|
1597 |
TUint32 unicodeChar = aUnicode[i]; |
|
1598 |
||
1599 |
// if High Surrogate |
|
1600 |
if (IsHighSurrogate((TText16)unicodeChar)) |
|
1601 |
{ |
|
1602 |
// check for low surrogate |
|
1603 |
if (!IsLowSurrogate(aUnicode[++i])) |
|
1604 |
{ |
|
1605 |
aForeign[j++] = (TUint8)replacementChar[0]; |
|
1606 |
continue; |
|
1607 |
} |
|
1608 |
unicodeChar = JoinSurrogate((TText16)unicodeChar, (TText16)aUnicode[i]); |
|
1609 |
} |
|
1610 |
||
1611 |
// if Low Surrogate |
|
1612 |
if (IsLowSurrogate((TText16)unicodeChar)) |
|
1613 |
{ |
|
1614 |
aForeign[j++] = (TUint8)replacementChar[0]; |
|
1615 |
continue; |
|
1616 |
} |
|
1617 |
// if Supplementary - Non BMP |
|
1618 |
if (IsSupplementary(unicodeChar)) |
|
1619 |
{ |
|
1620 |
aForeign[j++] = (TUint8)replacementChar[0]; |
|
1621 |
} |
|
1622 |
else |
|
1623 |
{ |
|
1624 |
// ASCII support |
|
1625 |
if((TUint)unicodeChar>=0x100) |
|
1626 |
{ |
|
1627 |
aForeign[j++] = (TUint8)replacementChar[0]; |
|
1628 |
} |
|
1629 |
else |
|
1630 |
{ |
|
1631 |
aForeign[j++] = (TUint8)unicodeChar; |
|
1632 |
} |
|
1633 |
} |
|
1634 |
} |
|
1635 |
||
1636 |
// if any replacementChar used, aForeign offset(j) shall be less than |
|
1637 |
// lengthToCopy aUnicode offset(i) |
|
1638 |
if(j<i) |
|
1639 |
{ |
|
1640 |
aForeign.SetLength(j); |
|
1641 |
} |
|
1642 |
||
1643 |
return(allConverted); |
|
1644 |
} |
|
1645 |
||
1646 |
EXPORT_C void TCodePageUtils::ConvertFromUnicodeL(TDes8& aForeign, const TDesC16& aUnicode, TOverflowAction aOverflowAction) const |
|
1647 |
/** |
|
1648 |
Convert from Unicode, truncating if there is not enough room in the output. |
|
1649 |
||
1650 |
@param aForeign The output is appended here. |
|
1651 |
@param aUnicode The input. |
|
1652 |
||
1653 |
@leave KErrOverflow if aForeign is too short for the output. |
|
1654 |
*/ |
|
1655 |
{ |
|
1656 |
TInt r = KErrNone; |
|
1657 |
TBool LeaveWhenError = (TBool)((aOverflowAction==TCodePageUtils::EOverflowActionLeave)?(TBool)ETrue:(TBool)EFalse); |
|
1658 |
// if CodePage dll |
|
1659 |
if(GetFatUtilityFunctions() && iCodepageLoaded == ECodePageDll && iCodePageFunctions.iConvertFromUnicodeL) |
|
1660 |
{ |
|
1661 |
r = (*iCodePageFunctions.iConvertFromUnicodeL)(aForeign, aUnicode, LeaveWhenError); |
|
1662 |
} |
|
1663 |
// if Locale dll |
|
1664 |
else if(GetFatUtilityFunctions() && iCodepageLoaded == ELocaleDll && iLocaleFatUtilityFunctions->iConvertFromUnicodeL) |
|
1665 |
{ |
|
1666 |
if(aOverflowAction == TCodePageUtils::EOverflowActionLeave) |
|
1667 |
{ |
|
1668 |
(*iLocaleFatUtilityFunctions->iConvertFromUnicodeL)(aForeign, aUnicode, KLit8ReplacementForUnconvertibleUnicodeCharacters, TFatUtilityFunctions::EOverflowActionLeave); |
|
1669 |
} |
|
1670 |
else |
|
1671 |
{ |
|
1672 |
(*iLocaleFatUtilityFunctions->iConvertFromUnicodeL)(aForeign, aUnicode, KLit8ReplacementForUnconvertibleUnicodeCharacters, TFatUtilityFunctions::EOverflowActionTruncate); |
|
1673 |
} |
|
1674 |
} |
|
1675 |
// default implementation |
|
1676 |
else if (!ConvertFromUnicode(aForeign, aUnicode, aOverflowAction)) |
|
1677 |
{ |
|
1678 |
if (aOverflowAction==TCodePageUtils::EOverflowActionLeave) |
|
1679 |
{ |
|
1680 |
User::Leave(KErrBadName); |
|
1681 |
} |
|
1682 |
} |
|
1683 |
||
1684 |
r = r; // remove warning |
|
1685 |
// File Server do not use this error code so do not send this error code right to File Server |
|
1686 |
// rather suppress it. Can be used in future. |
|
1687 |
return; |
|
1688 |
} |
|
1689 |
||
1690 |
TBool TCodePageUtils::ConvertToUnicode(TDes16& aUnicode, const TDesC8& aForeign) const |
|
1691 |
/* |
|
1692 |
Convert to Unicode, truncating if there is not enough room in the output. |
|
1693 |
||
1694 |
@param aUnicode The output is appended here. |
|
1695 |
@param aForeign The input. |
|
1696 |
||
1697 |
@return False if and only if aUnicode has not enough space remaining. |
|
1698 |
*/ |
|
1699 |
{ |
|
254 | 1700 |
const TInt KMaxLengthShortNameWithDot = 12; |
1701 |
const TUint8 KLeadingE5Replacement = 0x05; |
|
1702 |
const TUint8 KEntryErasedMarker=0xE5; ///< Erased entry marker for a directory entry |
|
1703 |
||
0 | 1704 |
// A workaround to handle leading 'E5' byte in short file names |
1705 |
TBuf8<KMaxLengthShortNameWithDot> shortFileNameWithLeadingE5; |
|
1706 |
TBool convertedLeading05toE5 = EFalse; |
|
1707 |
||
1708 |
if (0 < aForeign.Length() && aForeign.Length() <= 12 && aForeign[0] == KLeadingE5Replacement) |
|
1709 |
{ |
|
1710 |
shortFileNameWithLeadingE5 = aForeign; |
|
1711 |
shortFileNameWithLeadingE5[0] = KEntryErasedMarker; |
|
1712 |
convertedLeading05toE5 = ETrue; |
|
1713 |
} |
|
1714 |
||
1715 |
const TInt maximumLength=aUnicode.MaxLength(); |
|
1716 |
if (maximumLength>=aForeign.Length()) |
|
1717 |
{ |
|
1718 |
if (convertedLeading05toE5) |
|
1719 |
{ |
|
1720 |
aUnicode.Copy(shortFileNameWithLeadingE5); |
|
1721 |
} |
|
1722 |
else |
|
1723 |
{ |
|
1724 |
aUnicode.Copy(aForeign); |
|
1725 |
} |
|
1726 |
return ETrue; |
|
1727 |
} |
|
1728 |
else |
|
1729 |
{ |
|
1730 |
if (convertedLeading05toE5) |
|
1731 |
{ |
|
1732 |
aUnicode.Copy(shortFileNameWithLeadingE5.Left(maximumLength)); |
|
1733 |
} |
|
1734 |
else |
|
1735 |
{ |
|
1736 |
aUnicode.Copy(aForeign.Left(maximumLength)); |
|
1737 |
} |
|
1738 |
return EFalse; |
|
1739 |
} |
|
1740 |
} |
|
1741 |
||
1742 |
EXPORT_C void TCodePageUtils::ConvertToUnicodeL(TDes16& aUnicode, const TDesC8& aForeign, TOverflowAction aOverflowAction) const |
|
1743 |
/* |
|
1744 |
Convert to Unicode, leaving if there is not enough room in the output. |
|
1745 |
||
1746 |
@param aUnicode The output is appended here. |
|
1747 |
@param aForeign The input. |
|
1748 |
||
1749 |
@leave KErrOverflow if aUnicode is too short for the output. |
|
1750 |
*/ |
|
1751 |
{ |
|
1752 |
TInt r = KErrNone; |
|
1753 |
TBool LeaveWhenError = (TBool)((aOverflowAction==TCodePageUtils::EOverflowActionLeave)?(TBool)ETrue:(TBool)EFalse); |
|
1754 |
// if CodePage dll |
|
1755 |
if(GetFatUtilityFunctions() && iCodepageLoaded == ECodePageDll && iCodePageFunctions.iConvertToUnicodeL) |
|
1756 |
{ |
|
1757 |
r = (*iCodePageFunctions.iConvertToUnicodeL)(aUnicode, aForeign, LeaveWhenError); |
|
1758 |
} |
|
1759 |
// if Locale dll |
|
1760 |
else if(GetFatUtilityFunctions() && iCodepageLoaded == ELocaleDll && iLocaleFatUtilityFunctions->iConvertToUnicodeL) |
|
1761 |
{ |
|
1762 |
if(aOverflowAction == TCodePageUtils::EOverflowActionLeave) |
|
1763 |
{ |
|
1764 |
(*iLocaleFatUtilityFunctions->iConvertToUnicodeL)(aUnicode, aForeign, TFatUtilityFunctions::EOverflowActionLeave); |
|
1765 |
} |
|
1766 |
else |
|
1767 |
{ |
|
1768 |
(*iLocaleFatUtilityFunctions->iConvertToUnicodeL)(aUnicode, aForeign, TFatUtilityFunctions::EOverflowActionTruncate); |
|
1769 |
} |
|
1770 |
} |
|
1771 |
// default implementation |
|
1772 |
else if (!ConvertToUnicode(aUnicode, aForeign)) |
|
1773 |
{ |
|
1774 |
if (aOverflowAction==TCodePageUtils::EOverflowActionLeave) |
|
1775 |
{ |
|
1776 |
User::Leave(KErrBadName); |
|
1777 |
} |
|
1778 |
} |
|
1779 |
||
1780 |
r = r; // remove warning |
|
1781 |
// File Server do not use this error code so do not send this error code right to File Server |
|
1782 |
// rather suppress it. Can be used in future. |
|
1783 |
return; |
|
1784 |
} |
|
1785 |
||
1786 |
EXPORT_C TBool TCodePageUtils::IsLegalShortNameCharacter(TUint aCharacter,TBool aUseExtendedChars) const |
|
1787 |
/** |
|
1788 |
Returns true if the input character is legal in a short name. |
|
1789 |
||
1790 |
@param aCharacter Character, in the foreign character encoding. |
|
1791 |
||
1792 |
@return true if aCharacter is legal in a FAT short name. |
|
1793 |
*/ |
|
1794 |
{ |
|
1795 |
if(GetFatUtilityFunctions() && iCodepageLoaded == ECodePageDll && iCodePageFunctions.iIsLegalShortNameCharacter) |
|
1796 |
{ |
|
1797 |
return (*iCodePageFunctions.iIsLegalShortNameCharacter)(aCharacter); |
|
1798 |
} |
|
1799 |
||
1800 |
if(GetFatUtilityFunctions() && iCodepageLoaded == ELocaleDll && iLocaleFatUtilityFunctions->iIsLegalShortNameCharacter) |
|
1801 |
{ |
|
1802 |
return (*iLocaleFatUtilityFunctions->iIsLegalShortNameCharacter)(aCharacter); |
|
1803 |
} |
|
1804 |
||
1805 |
// For most common cases: |
|
1806 |
// Note: lower case characters are considered legal DOS char here. |
|
1807 |
if ((aCharacter>='a' && aCharacter<='z') || |
|
1808 |
(aCharacter>='A' && aCharacter<='Z') || |
|
1809 |
(aCharacter>='0' && aCharacter<='9')) |
|
1810 |
{ |
|
1811 |
return ETrue; |
|
1812 |
} |
|
1813 |
||
1814 |
// Default Implmentation |
|
1815 |
// Checking for illegal chars: |
|
1816 |
// 1. aCharacter <= 0x20 |
|
1817 |
// Note: leading 0x05 byte should be guarded by callers of this function |
|
1818 |
// as the information of the position of the character is required. |
|
1819 |
if (aCharacter < 0x20) |
|
1820 |
return EFalse; |
|
1821 |
// Space (' ') is not considered as a legal DOS char here. |
|
1822 |
if (aCharacter == 0x20) |
|
1823 |
return EFalse; |
|
1824 |
||
1825 |
// 2. 0x20 < aCharacter < 0x80 |
|
1826 |
if (0x20 < aCharacter && aCharacter < KExtendedCharStart) |
|
1827 |
{ |
|
1828 |
// According to FAT Spec, "following characters are not legal in any bytes of DIR_Name": |
|
1829 |
switch (aCharacter) |
|
1830 |
{ |
|
1831 |
case 0x22: // '"' |
|
1832 |
case 0x2A: // '*' |
|
1833 |
case 0x2B: // '+' |
|
1834 |
case 0x2C: // ',' |
|
1835 |
// case 0x2E: // '.' // Although '.' is not allowed in any bytes of DIR_Name, it |
|
1836 |
// is a valid character in short file names. |
|
1837 |
case 0x2F: // '/' |
|
1838 |
case 0x3A: // ':' |
|
1839 |
case 0x3B: // ';' |
|
1840 |
case 0x3C: // '<' |
|
1841 |
case 0x3D: // '=' |
|
1842 |
case 0x3E: // '>' |
|
1843 |
case 0x3F: // '?' |
|
1844 |
case 0x5B: // '[' |
|
1845 |
case 0x5C: // '\' |
|
1846 |
case 0x5D: // ']' |
|
1847 |
case 0x7C: // '|' |
|
1848 |
return EFalse; |
|
1849 |
default: |
|
1850 |
return ETrue; |
|
1851 |
} |
|
1852 |
} |
|
1853 |
||
1854 |
// 3. 0x80 <= aCharacter <= 0xFF |
|
1855 |
if (KExtendedCharStart <= aCharacter && aCharacter <= KExtendedCharEnd) |
|
1856 |
{ |
|
1857 |
if(aUseExtendedChars) |
|
1858 |
return(ETrue); |
|
1859 |
else |
|
1860 |
return EFalse; |
|
1861 |
} |
|
1862 |
||
1863 |
// 4. aCharacter => 0xFF |
|
1864 |
return EFalse; |
|
1865 |
} |