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