author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 15 Sep 2010 13:42:27 +0300 | |
branch | RCL_3 |
changeset 268 | 345b1ca54e88 |
parent 257 | 3e88ff8f41d5 |
child 294 | 039a3e647356 |
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_drv.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include "sf_std.h" |
|
19 |
#include "sf_file_cache.h" |
|
257 | 20 |
|
21 |
||
0 | 22 |
//const TInt KMaxNotifierAttempts=4; // not used anywhere |
23 |
||
24 |
static TPtrC StripBackSlash(const TDesC& aName) |
|
25 |
// |
|
26 |
// If aName ends in a backslash, strip it. |
|
27 |
// |
|
28 |
{ |
|
29 |
||
30 |
__ASSERT_DEBUG(aName.Length(),Fault(EStripBackSlashBadName)); |
|
31 |
if (aName[aName.Length()-1]==KPathDelimiter) |
|
32 |
return(aName.Left(aName.Length()-1)); |
|
33 |
return(aName); |
|
34 |
} |
|
35 |
||
36 |
static void CheckSubClose(CFsObject* anObj,TInt aHandle, CSessionFs* aSession) |
|
37 |
// |
|
38 |
// Close anObj if its not NULL. |
|
39 |
// |
|
40 |
{ |
|
41 |
__PRINT1(_L("CheckSubClose() session 0x0%x"),aSession); |
|
42 |
__PRINT1(_L("CheckSubClose() anObj 0x0%x"),anObj); |
|
43 |
||
44 |
if(!anObj) |
|
45 |
return; |
|
46 |
||
47 |
if(aHandle==0) |
|
48 |
{ |
|
49 |
// can't have been added to the object index |
|
50 |
__ASSERT_DEBUG(KErrNotFound==aSession->Handles().At(anObj,ETrue),Fault(ESubOpenBadHandle)); |
|
51 |
anObj->Close(); |
|
52 |
} |
|
53 |
else |
|
54 |
aSession->Handles().Remove(aHandle,ETrue); |
|
55 |
} |
|
56 |
||
57 |
TInt ValidateDrive(TInt aDriveNumber,CFsRequest* aRequest) |
|
58 |
// |
|
59 |
// Validate a drive number and set iTheDrive. |
|
60 |
// |
|
61 |
{ |
|
62 |
if (aDriveNumber==KDefaultDrive) |
|
63 |
aDriveNumber=aRequest->Session()->CurrentDrive(); |
|
64 |
if (!RFs::IsValidDrive(aDriveNumber)) |
|
65 |
return(KErrBadName); |
|
66 |
aRequest->SetDrive(&TheDrives[aDriveNumber]); |
|
67 |
return(KErrNone); |
|
68 |
} |
|
69 |
||
70 |
TInt ValidateDriveDoSubst(TInt aDriveNumber,CFsRequest* aRequest) |
|
71 |
// |
|
72 |
// Validate a drive number and set iTheDrive. |
|
73 |
// |
|
74 |
{ |
|
75 |
||
76 |
TInt r=ValidateDrive(aDriveNumber,aRequest); |
|
77 |
if (r!=KErrNone) |
|
78 |
return(r); |
|
79 |
if (aRequest->Drive()->IsSubsted()) |
|
80 |
{ |
|
81 |
aRequest->SetSubstedDrive(aRequest->Drive()); |
|
82 |
aRequest->SetDrive(&aRequest->Drive()->SubstedDrive()); |
|
83 |
} |
|
84 |
return(KErrNone); |
|
85 |
} |
|
86 |
||
248
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
87 |
void ValidateAtts(TUint& aSetAttMask,TUint& aClearAttMask) |
0 | 88 |
// |
89 |
// Do not allow the entry type to be changed |
|
90 |
// |
|
91 |
{ |
|
249
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
92 |
const TUint KReadOnlyAtts = KEntryAttVolume | |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
93 |
KEntryAttDir | |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
94 |
KEntryAttRemote | |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
95 |
KEntryAttModified; |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
96 |
|
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
97 |
aSetAttMask &= ~KReadOnlyAtts; |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
98 |
aClearAttMask &= ~KReadOnlyAtts; |
0 | 99 |
} |
100 |
||
101 |
void CheckForLeaveAfterOpenL(TInt leaveError, CFsRequest* aRequest, TInt aHandle) |
|
102 |
// |
|
103 |
// Tidy up in the event of a leave after opening a file or directory |
|
104 |
{ |
|
105 |
if (leaveError) |
|
106 |
{ |
|
107 |
CFsObject* anObj=(CFsObject* )aRequest->ScratchValue(); |
|
108 |
CheckSubClose(anObj,aHandle,aRequest->Session()); |
|
109 |
User::Leave(leaveError); |
|
110 |
} |
|
111 |
} |
|
112 |
||
113 |
TDrive::TDrive() |
|
114 |
// |
|
115 |
// Constructor. |
|
116 |
// |
|
117 |
: iDriveNumber(0),iAtt(0),iChanged(EFalse), |
|
118 |
iFSys(NULL),iCurrentMount(NULL),iSubstedDrive(NULL),iSubst(NULL), |
|
119 |
iMount(NULL),iDriveFlags(0),iMountFailures(0) |
|
120 |
{} |
|
121 |
||
122 |
void TDrive::CreateL(TInt aDriveNumber) |
|
123 |
// |
|
124 |
// Allocate the drive number and any resources. |
|
125 |
// |
|
126 |
{ |
|
127 |
__PRINT1(_L("TDrive::CreateL(%d)"),aDriveNumber); |
|
128 |
iDriveNumber=aDriveNumber; |
|
129 |
iMount=TheContainer->CreateL(); |
|
130 |
TInt r=iLock.CreateLocal(); |
|
131 |
User::LeaveIfError(r); |
|
132 |
} |
|
133 |
||
134 |
TInt TDrive::CheckMountAndEntryName(const TDesC& aName) |
|
135 |
// |
|
136 |
// Check drive is mounted then check aName is legal |
|
137 |
// |
|
138 |
{ |
|
139 |
||
140 |
__PRINT1(_L("TDrive::CheckMountAndEntryName Drive%d"),DriveNumber()); |
|
141 |
TInt r=CheckMount(); |
|
142 |
if (r==KErrNone && IsIllegalFullName(aName)) |
|
143 |
return(KErrBadName); |
|
144 |
return(r); |
|
145 |
} |
|
146 |
||
147 |
void TDrive::MultiSlotDriveCheck() |
|
148 |
{ |
|
149 |
// Check whether the current drive is a dual-slot/multi-slot |
|
150 |
// if so, we need to check which drive is connected now and |
|
151 |
// swap the mapping in LocalDrives::iMapping such that the |
|
152 |
// mapping of driveNumber to localDriveNumber is correct. |
|
153 |
||
154 |
Lock(); |
|
155 |
//Is this a multislot drive? |
|
156 |
if(LocalDrives::iIsMultiSlotDrive[iDriveNumber]) |
|
157 |
{ |
|
158 |
for(TInt localDrvNum=0; localDrvNum<KMaxLocalDrives; localDrvNum++) |
|
159 |
{ |
|
160 |
// ensure that this local drive is a multi-slot choice for this drive number.. |
|
161 |
if(LocalDrives::iReverseMapping[localDrvNum]==iDriveNumber) |
|
162 |
{ |
|
163 |
// Caps - find out which one is connected |
|
164 |
TLocalDriveCapsBuf capsInfo; |
|
165 |
TInt r = LocalDrives::iLocalDrives[localDrvNum].Caps(capsInfo); |
|
166 |
if(r==KErrNotReady) |
|
167 |
{ |
|
168 |
continue; //go to next localdrive |
|
169 |
} |
|
170 |
//found a connected drive |
|
171 |
//Update mapping |
|
172 |
#ifdef _DEBUG |
|
173 |
RDebug::Print(_L("Multislot drive mapping update: DriveNum %d to LocDrv %d"),iDriveNumber,localDrvNum); |
|
174 |
#endif |
|
175 |
||
176 |
LocalDrives::iMapping[iDriveNumber] = localDrvNum; |
|
177 |
break; // Swap complete - don't look any further |
|
178 |
} |
|
179 |
} |
|
180 |
} |
|
181 |
UnLock(); |
|
182 |
} |
|
183 |
||
184 |
TInt TDrive::CheckMount() |
|
185 |
// |
|
186 |
// Check the drive and try to mount a media if not already mounted. |
|
187 |
// |
|
188 |
{ |
|
189 |
__PRINT2(_L("TDrive::CheckMount Drive%d, changed:%d"),DriveNumber(), iChanged); |
|
190 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
191 |
||
192 |
if (!iFSys) |
|
193 |
return KErrNotReady; |
|
194 |
||
195 |
if (iChanged) // If a media change has occurred |
|
196 |
{ |
|
197 |
iMountFailures = 0; |
|
198 |
iChanged=EFalse; // Reset the flag |
|
199 |
if (IsMounted()) // Dismount the mount if it is still marked as mounted |
|
200 |
{ |
|
201 |
DoDismount(); |
|
202 |
} |
|
203 |
//If we have a dual/multi removable media slot then we may need to |
|
204 |
//swop the mappings. |
|
205 |
MultiSlotDriveCheck(); |
|
206 |
} |
|
207 |
||
208 |
if (!IsMounted()) // Checks that iCurrentMount!=NULL |
|
209 |
{ |
|
210 |
__PRINT(_L("TDrive::CheckMount() Not Mounted")); |
|
211 |
const TInt KMaxMountFailures = 3; |
|
212 |
// if we've repeatedly failed to mount, give up until a media change |
|
213 |
if (iMountFailures >= KMaxMountFailures) |
|
214 |
{ |
|
215 |
__PRINT1(_L("TDrive::CheckMount() retries exceeded, last Err:%d"), iLastMountError); |
|
216 |
return iLastMountError; |
|
217 |
} |
|
218 |
||
219 |
if (!ReMount()) // Have we just remounted a mount we have previously encountered? |
|
220 |
{ |
|
221 |
MountFileSystem(EFalse); // If not, mount it for the first time now |
|
222 |
} |
|
223 |
else if(IsWriteProtected() && IsWriteableResource()) |
|
224 |
{ |
|
225 |
DoDismount(); |
|
226 |
return KErrAccessDenied; |
|
227 |
} |
|
228 |
} |
|
229 |
||
230 |
if (iReason==KErrNone && CurrentMount().LockStatus() > 0) |
|
231 |
{ |
|
248
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
232 |
//-- this means that the mount has drive access objects opened (RFormat or RRawDisk) |
0 | 233 |
__PRINT1(_L("TDrive::CheckMount() Mount is locked! LockStaus:%d"), CurrentMount().LockStatus()); |
234 |
return KErrInUse; |
|
235 |
} |
|
236 |
||
237 |
__PRINT1(_L("TDrive::CheckMount returned %d "),iReason); |
|
238 |
||
239 |
return(iReason); |
|
240 |
} |
|
241 |
||
242 |
//---------------------------------------------------------------------------- |
|
243 |
/** |
|
244 |
Try and re-mount any of the pending media |
|
245 |
||
246 |
@return ETrue if the mount matching media found and been attached back (set as iCurrentMount) |
|
247 |
*/ |
|
248 |
TBool TDrive::ReMount() |
|
249 |
{ |
|
250 |
const TInt mCount=Mount().Count(); |
|
251 |
__PRINT1(_L("TDrive::ReMount() MountCnt:%d"), mCount); |
|
252 |
||
253 |
const TInt u=(Mount().UniqueID()<<16); |
|
254 |
iReason=KErrNone; |
|
255 |
||
256 |
//-- try every instance of CMountCB that is associated with this object of TDrive. |
|
257 |
//-- mounts are stored in the container of mCount elements. |
|
258 |
//-- if some CMountCB recognises the media it belongs, it means that "remount succeded" |
|
259 |
for(TInt i=0; i<mCount; i++) |
|
260 |
{ |
|
261 |
CMountCB* pM=(CMountCB*)Mount().At(u|i); |
|
262 |
||
263 |
if (ReMount(*pM)) |
|
264 |
return ETrue; |
|
265 |
} |
|
266 |
||
267 |
return EFalse; |
|
268 |
} |
|
269 |
||
270 |
//---------------------------------------------------------------------------- |
|
271 |
/** |
|
272 |
Try and re-mount the specified media. |
|
273 |
||
274 |
@return ETrue if remounting succeeded - i.e. the CMountCB instance that matches the media is found in the |
|
275 |
mounts container (Mount()) and bound to the media. |
|
276 |
*/ |
|
277 |
TBool TDrive::ReMount(CMountCB& aMount) |
|
278 |
{ |
|
279 |
__PRINT1(_L("TDrive::ReMount(0x%x)"), &aMount); |
|
280 |
iReason=KErrNone; |
|
281 |
||
282 |
if (!aMount.IsDismounted() && !aMount.ProxyDriveDismounted()) |
|
283 |
{ |
|
284 |
aMount.SetDrive(this); |
|
257 | 285 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReMount, EF32TraceUidFileSys, DriveNumber()); |
0 | 286 |
|
287 |
//-- actually, this is asking CMountCB to see if it belongs to the current media. |
|
288 |
iReason = aMount.ReMount(); |
|
289 |
||
257 | 290 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReMountRet, EF32TraceUidFileSys, iReason); |
0 | 291 |
|
292 |
if (iReason == KErrNone) // ReMount succeeded |
|
293 |
{ |
|
294 |
aMount.Open(); |
|
295 |
iCurrentMount = &aMount; |
|
296 |
__PRINT1(_L("TDrive::ReMount for Mount:0x%x OK!"), &aMount); |
|
297 |
return ETrue; |
|
298 |
} |
|
299 |
||
300 |
__PRINT2(_L("TDrive::ReMount for Mount:0x%x failed iReason=%d"),&aMount,iReason); |
|
301 |
} |
|
302 |
else |
|
303 |
{ |
|
304 |
__PRINT1(_L("TDrive::ReMount() failed - Mount:0x%x is dismounted"), &aMount); |
|
305 |
} |
|
306 |
||
307 |
return EFalse; |
|
308 |
} |
|
309 |
||
310 |
||
311 |
||
312 |
//---------------------------------------------------------------------------- |
|
313 |
/** |
|
314 |
Mount the media on the drive. Optionally force a bad media to be mounted. |
|
315 |
||
316 |
@param apMount out: pointer to the produced CMountCB object; NULL if the CMountCB is not constructed |
|
317 |
@param aForceMount if ETrue, the filesystem will be forcedly mounted on the drive, disregarding what it contains. |
|
318 |
@param aFsNameHash file system name hash; see TDrive::MountFileSystem() |
|
319 |
*/ |
|
320 |
void TDrive::DoMountFileSystemL(CMountCB*& apMount, TBool aForceMount, TUint32 aFsNameHash) |
|
321 |
{ |
|
322 |
CFileSystem* pMountsFs = NULL; //-- reference to the filesystem that will be producing CMountCB |
|
323 |
||
324 |
apMount = NULL; |
|
325 |
||
257 | 326 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber()); |
0 | 327 |
|
328 |
//-- construct a new CmountCB object. |
|
329 |
//-- on return pMountsFs will be the pointer to the factory object of CFileSystem that produced this mount |
|
330 |
apMount = FSys().NewMountExL(this, &pMountsFs, aForceMount, aFsNameHash); |
|
331 |
||
257 | 332 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, KErrNone, apMount); |
0 | 333 |
__PRINT2(_L("TDrive::MountMediaL created mount:0x%x FileSys:0x%x"), apMount, pMountsFs); |
334 |
||
335 |
ASSERT(pMountsFs && apMount); |
|
336 |
||
337 |
apMount->SetMountNumber(iMountNumber++); |
|
338 |
apMount->InitL(*this, pMountsFs); //-- initialise Mount |
|
339 |
apMount->MountL(aForceMount); //-- mount the file system |
|
340 |
Mount().AddL(apMount,EFalse); //-- add mount object to the mounts container. |
|
341 |
||
342 |
iCurrentMount=apMount; |
|
343 |
} |
|
344 |
||
345 |
||
346 |
//---------------------------------------------------------------------------- |
|
347 |
/* |
|
348 |
Mount file system on the drive. |
|
349 |
@param aForceMount if EFalse, will try to mount the file system normally, the file system implementation will decide if it can work on this drive or not. |
|
350 |
if ETrue, will mount the file suystem by force, this is used mostly for formatting unrecognisable media. |
|
351 |
||
352 |
@param aFsNameHash optional parameter. Can specify the concrete file system name (hash). It can be used to force mounting some specific |
|
353 |
file system. Default value '0' means "not specified / not used" |
|
354 |
||
355 |
||
356 |
TDrive::iReason on return contains the operation result code. |
|
357 |
*/ |
|
358 |
void TDrive::MountFileSystem(TBool aForceMount, TUint32 aFsNameHash /*=0*/ ) |
|
359 |
{ |
|
360 |
__PRINT2(_L("TDrive::MountFileSystem aForceMount=%d, FSNameHash:0x%x"),aForceMount, aFsNameHash); |
|
361 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
362 |
||
363 |
iCurrentMount=NULL; |
|
364 |
if(!iFSys) |
|
365 |
{ |
|
366 |
iReason=KErrNotReady; |
|
367 |
return; |
|
368 |
} |
|
369 |
||
370 |
CMountCB* pM=NULL; |
|
371 |
TRAP(iReason, DoMountFileSystemL(pM, aForceMount, aFsNameHash)); |
|
372 |
if (iReason == KErrNone) |
|
373 |
{ |
|
374 |
iMountFailures = 0; |
|
375 |
ASSERT(iCurrentMount); |
|
376 |
} |
|
377 |
else |
|
378 |
{ |
|
379 |
iLastMountError = iReason; |
|
380 |
iMountFailures++; |
|
381 |
__PRINT2(_L("TDrive::MountFileSystem 0x%x failed iReason=%d"),pM,iReason); |
|
382 |
if(pM) |
|
383 |
pM->Close(); |
|
384 |
||
385 |
ASSERT(!iCurrentMount); |
|
386 |
} |
|
387 |
} |
|
388 |
||
389 |
||
390 |
//---------------------------------------------------------------------------- |
|
391 |
/** |
|
392 |
Generic mount control method. |
|
393 |
@param aLevel specifies the operation to perfrom on the mount |
|
394 |
@param aOption specific option for the given operation |
|
395 |
@param aParam pointer to generic parameter, its meaning depends on aLevel and aOption |
|
396 |
||
397 |
@return standard error code. |
|
398 |
*/ |
|
399 |
TInt TDrive::MountControl(TInt aLevel, TInt aOption, TAny* aParam) |
|
400 |
{ |
|
257 | 401 |
TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBMountControl, EF32TraceUidFileSys, DriveNumber(), aLevel, aOption, aParam); |
0 | 402 |
TInt r = CurrentMount().MountControl(aLevel, aOption, aParam); |
257 | 403 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBMountControlRet, EF32TraceUidFileSys, r); |
404 |
||
0 | 405 |
return r; |
406 |
} |
|
407 |
||
408 |
//---------------------------------------------------------------------------- |
|
409 |
/** |
|
410 |
Request aFreeSpaceRequired free bytes from the mount associated with this drive. |
|
411 |
The volume free space on for some filesystems can be changing (usually increasing) after it has been mounted. |
|
412 |
If the mount supports this functionality, it can block this call until certain number of free bytes encounted if its free |
|
413 |
space calculation activity hasn't finished yet. |
|
414 |
||
415 |
@param aFreeSpaceRequired required free space, bytes. |
|
416 |
||
417 |
@return KErrNone on success and if there is at least aFreeSpaceRequired bytes on the volume |
|
418 |
KErrDiskFull on success and if there is no aFreeSpaceRequired bytes on the volume |
|
419 |
system-wide error code otherwise |
|
420 |
*/ |
|
421 |
TInt TDrive::RequestFreeSpaceOnMount(TUint64 aFreeSpaceRequired) |
|
422 |
{ |
|
423 |
TInt nRes; |
|
424 |
||
425 |
nRes = CheckMount(); |
|
426 |
if(nRes != KErrNone) |
|
427 |
return nRes; |
|
428 |
||
429 |
//-- 1. Try mount-specific request first. If the mount is still performing free space calculations, |
|
430 |
//-- the caller will be suspended until aFreeSpaceRequired bytes is available or scanning process finishes |
|
431 |
{ |
|
432 |
TUint64 freeSpaceReq = aFreeSpaceRequired; |
|
257 | 433 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFreeSpace, EF32TraceUidFileSys, DriveNumber()); |
0 | 434 |
nRes = CurrentMount().RequestFreeSpace(freeSpaceReq); |
257 | 435 |
TRACERET3(UTF::EBorder, UTraceModuleFileSys::ECMountCBFreeSpaceRet, EF32TraceUidFileSys, nRes, I64LOW(freeSpaceReq), I64HIGH(freeSpaceReq)); |
0 | 436 |
if(nRes == KErrNone) |
437 |
{ |
|
438 |
return (freeSpaceReq >= aFreeSpaceRequired) ? KErrNone : KErrDiskFull; |
|
439 |
} |
|
440 |
} |
|
441 |
||
442 |
//-- given Mount doesn't support this functionality, use legacy method |
|
443 |
TVolumeInfo volInfo; |
|
444 |
nRes = Volume(volInfo); |
|
445 |
if(nRes !=KErrNone) |
|
446 |
return nRes; |
|
447 |
||
448 |
return ((TUint64)volInfo.iFree >= aFreeSpaceRequired) ? KErrNone : KErrDiskFull; |
|
449 |
} |
|
450 |
||
451 |
//---------------------------------------------------------------------------- |
|
452 |
/** |
|
453 |
Get size of the mounted volume. It can be less than physical volume size because FileSystem data may occupy some space. |
|
454 |
||
455 |
@param aSize on success mounted volume size in bytes will be returned there |
|
456 |
@return KErrNone on success, standard error code otherwise |
|
457 |
*/ |
|
458 |
TInt TDrive::MountedVolumeSize(TUint64& aSize) |
|
459 |
{ |
|
460 |
TInt nRes; |
|
461 |
||
462 |
nRes = CheckMount(); |
|
463 |
if(nRes != KErrNone) |
|
464 |
return nRes; |
|
257 | 465 |
|
0 | 466 |
//-- 1. Try mount-specific request first. It won't block this call as CMountCB::VolumeL() can do if some background activity is going on the mount |
257 | 467 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBVolumeSize, EF32TraceUidFileSys, DriveNumber()); |
0 | 468 |
nRes = CurrentMount().MountedVolumeSize(aSize); |
257 | 469 |
TRACERET3(UTF::EBorder, UTraceModuleFileSys::ECMountCBVolumeSize, EF32TraceUidFileSys, nRes, I64LOW(aSize), I64HIGH(aSize)); |
0 | 470 |
if(nRes == KErrNone) |
471 |
return nRes; |
|
472 |
||
473 |
//-- given Mount doesn't support this functionality, use legacy method |
|
474 |
TVolumeInfo volInfo; |
|
475 |
nRes = Volume(volInfo); |
|
476 |
if(nRes == KErrNone) |
|
477 |
{ |
|
478 |
aSize = volInfo.iSize; |
|
479 |
} |
|
480 |
||
481 |
return nRes; |
|
482 |
} |
|
483 |
||
484 |
//---------------------------------------------------------------------------- |
|
485 |
/** |
|
486 |
Get _current_ amount of free space on the volume. Some mounts implementations can be updating the amount of free space |
|
487 |
in background. |
|
488 |
||
489 |
@param aFreeDiskSpace on success will contain a current amount of free space |
|
490 |
@return KErrNone on success, standard error code otherwise |
|
491 |
||
492 |
*/ |
|
493 |
TInt TDrive::FreeDiskSpace(TInt64& aFreeDiskSpace) |
|
494 |
{ |
|
495 |
TInt nRes; |
|
496 |
||
497 |
nRes = CheckMount(); |
|
498 |
if(nRes != KErrNone) |
|
499 |
return nRes; |
|
500 |
||
501 |
//-- 1. Try mount-specific request first. It won't block this call as CMountCB::VolumeL() can do |
|
257 | 502 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBCurrentFreeSpace, EF32TraceUidFileSys, DriveNumber()); |
0 | 503 |
nRes = CurrentMount().GetCurrentFreeSpaceAvailable(aFreeDiskSpace); |
257 | 504 |
TRACERET3(UTF::EBorder, UTraceModuleFileSys::ECMountCBCurrentFreeSpaceRet, EF32TraceUidFileSys, nRes, I64LOW(aFreeDiskSpace), I64HIGH(aFreeDiskSpace)); |
0 | 505 |
if(nRes == KErrNone) |
506 |
return nRes; |
|
507 |
||
508 |
//-- given Mount doesn't support this functionality, use legacy method |
|
509 |
TVolumeInfo volInfo; |
|
510 |
nRes = Volume(volInfo); |
|
511 |
if(nRes == KErrNone) |
|
512 |
{ |
|
513 |
aFreeDiskSpace = volInfo.iFree; |
|
514 |
} |
|
515 |
||
516 |
return nRes; |
|
517 |
} |
|
518 |
||
519 |
//---------------------------------------------------------------------------- |
|
520 |
/** |
|
521 |
Finalise drive (the mount). |
|
522 |
||
523 |
@param aOperation describes finalisation operation ,see RFs::TFinaliseDrvMode |
|
524 |
@param aParam1 not used, for future expansion |
|
525 |
@param aParam2 not used, for future expansion |
|
526 |
||
527 |
@return Standard error code |
|
528 |
*/ |
|
529 |
TInt TDrive::FinaliseMount(TInt aOperation, TAny* aParam1/*=NULL*/, TAny* aParam2/*=NULL*/) |
|
530 |
{ |
|
531 |
TInt r=CheckMount(); |
|
532 |
if (r!=KErrNone) |
|
533 |
return(r); |
|
534 |
||
535 |
r = FlushCachedFileInfo(); |
|
536 |
if (r!=KErrNone) |
|
537 |
return(r); |
|
538 |
||
539 |
if(IsWriteProtected()) |
|
540 |
return(KErrAccessDenied); |
|
541 |
||
257 | 542 |
TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount2, EF32TraceUidFileSys, DriveNumber(), aOperation, aParam1, aParam2); |
0 | 543 |
TRAP(r,CurrentMount().FinaliseMountL(aOperation, aParam1, aParam2)); |
257 | 544 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount2Ret, EF32TraceUidFileSys, r); |
0 | 545 |
|
249
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
546 |
// Pass FinaliseDrive notification down to media driver |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
547 |
TInt driveNumber = DriveNumber(); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
548 |
if (LocalDrives::IsValidDriveMapping(driveNumber) && !LocalDrives::IsProxyDrive(driveNumber)) |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
549 |
{ |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
550 |
TBusLocalDrive& drv = LocalDrives::GetLocalDrive(driveNumber); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
551 |
|
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
552 |
TLocalDriveFinaliseInfoBuf finaliseBuf; |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
553 |
finaliseBuf().iMode = aOperation; |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
554 |
|
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
555 |
// notify local drive, ignore the error |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
556 |
drv.QueryDevice(RLocalDrive::EQueryFinaliseDrive, finaliseBuf); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
557 |
} |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
558 |
|
0 | 559 |
return r; |
560 |
} |
|
561 |
||
562 |
//---------------------------------------------------------------------------- |
|
563 |
/** old implementation */ |
|
564 |
TInt TDrive::FinaliseMount() |
|
565 |
{ |
|
566 |
TInt r=CheckMount(); |
|
567 |
if (r!=KErrNone) |
|
568 |
return(r); |
|
569 |
||
570 |
r = FlushCachedFileInfo(); |
|
571 |
if (r!=KErrNone) |
|
572 |
return(r); |
|
573 |
||
574 |
if(IsWriteProtected()) |
|
575 |
return(KErrAccessDenied); |
|
576 |
||
257 | 577 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount1, EF32TraceUidFileSys, DriveNumber()); |
0 | 578 |
TRAP(r,CurrentMount().FinaliseMountL()); |
257 | 579 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFinaliseMount1Ret, EF32TraceUidFileSys, r); |
0 | 580 |
|
581 |
return r; |
|
582 |
} |
|
583 |
||
584 |
||
585 |
||
586 |
CFileCB* TDrive::LocateFile(const TDesC& aName) |
|
587 |
// |
|
588 |
// Locate a file of the same name already open on the drive. |
|
589 |
// |
|
590 |
{ |
|
591 |
TDblQueIter<CFileCB> q(CurrentMount().iMountQ); |
|
592 |
CFileCB* pF; |
|
593 |
// early out for normal case, list is empty |
|
594 |
if(q==NULL) |
|
595 |
return NULL; |
|
596 |
||
597 |
// strip off trailing dots |
|
598 |
TInt length= aName.Length(); |
|
599 |
while((length !=0) && (aName[length-1]==KExtDelimiter)) |
|
600 |
{ |
|
601 |
length--; |
|
602 |
} |
|
603 |
||
604 |
TPtrC temp(aName.Ptr(),length); |
|
605 |
||
606 |
TFileName tempName; |
|
607 |
tempName.CopyF(temp); |
|
608 |
TUint32 nameHash=CalcNameHash(tempName); |
|
609 |
||
610 |
while ((pF=q++)!=NULL) |
|
611 |
{ |
|
612 |
if(nameHash==pF->NameHash()) |
|
613 |
{ |
|
614 |
if (pF->FileNameF().Match(tempName)==KErrNone) |
|
615 |
return(pF); |
|
616 |
} |
|
617 |
} |
|
618 |
return(NULL); |
|
619 |
} |
|
620 |
||
621 |
||
622 |
CFileCache* TDrive::LocateClosedFile(const TDesC& aName, TBool aResurrect) |
|
623 |
// |
|
624 |
// Locate a recently closed file of the same name on the drive. |
|
625 |
// |
|
626 |
{ |
|
627 |
// strip off trailing dots |
|
628 |
TInt length= aName.Length(); |
|
629 |
while((length !=0) && (aName[length-1]==KExtDelimiter)) |
|
630 |
{ |
|
631 |
length--; |
|
632 |
} |
|
633 |
||
634 |
TPtrC temp(aName.Ptr(),length); |
|
635 |
||
636 |
TFileName tempName; |
|
637 |
tempName.CopyF(temp); |
|
638 |
TUint32 nameHash=CalcNameHash(tempName); |
|
639 |
||
640 |
CFileCache* pF = NULL; |
|
641 |
CMountCB* currentMount = &CurrentMount(); |
|
642 |
||
643 |
||
644 |
TClosedFileUtils::Lock(); |
|
645 |
||
646 |
TInt count = TClosedFileUtils::Count(); |
|
647 |
while(count--) |
|
648 |
{ |
|
649 |
CFileCache* fileCache = TClosedFileUtils::At(count); |
|
650 |
if (&fileCache->Drive() == this && |
|
651 |
fileCache->NameHash()== nameHash && |
|
652 |
fileCache->FileNameF().Match(tempName)==KErrNone && |
|
653 |
&fileCache->Mount() == currentMount) |
|
654 |
{ |
|
655 |
__ASSERT_DEBUG(TClosedFileUtils::IsClosed(fileCache), Fault(EObjRemoveContainerNotFound)); |
|
656 |
__CACHE_PRINT2(_L("CLOSEDFILES: LocateClosedFile(%S, %d\n"), &fileCache->FileNameF(), aResurrect); |
|
657 |
if (aResurrect) |
|
658 |
{ |
|
659 |
TClosedFileUtils::ReOpen(fileCache, EFalse); |
|
660 |
} |
|
661 |
pF = fileCache; |
|
662 |
break; |
|
663 |
} |
|
664 |
||
665 |
} |
|
666 |
TClosedFileUtils::Unlock(); |
|
667 |
||
668 |
if (pF != NULL && !aResurrect) |
|
669 |
{ |
|
670 |
pF->Close(); |
|
671 |
pF = NULL; |
|
672 |
} |
|
673 |
||
674 |
return(pF); |
|
675 |
} |
|
676 |
||
677 |
||
678 |
static TBool IsSubDir(const TDesC& aFullName,const TDesC& aParent) |
|
679 |
// |
|
680 |
// Returns ETrue if aFullName is a subdirectory of aParent |
|
681 |
// Assumes aParent is a path name with the trailing backslash removed |
|
682 |
// |
|
683 |
{ |
|
684 |
||
685 |
__ASSERT_DEBUG(aParent.Length() && aParent[aParent.Length()-1]!=KPathDelimiter,Fault(EIsSubDirBadDes)); |
|
686 |
TPtrC entryFullName(NULL,0); |
|
687 |
TPtrC entryParent(NULL,0); |
|
688 |
TInt posFullName=0; |
|
689 |
TInt posParent=0; |
|
690 |
||
691 |
FOREVER |
|
692 |
{ |
|
693 |
NextInPath(aParent,entryParent,posParent); |
|
694 |
if (entryParent.Length()==0) |
|
695 |
break; |
|
696 |
NextInPath(aFullName,entryFullName,posFullName); |
|
697 |
if (entryParent!=entryFullName) |
|
698 |
return(EFalse); |
|
699 |
} |
|
700 |
||
701 |
if (aFullName.Length()<=posFullName) |
|
702 |
return(EFalse); |
|
703 |
if (aFullName[posFullName]!=KPathDelimiter) |
|
704 |
return(EFalse); |
|
705 |
return(ETrue); |
|
706 |
} |
|
707 |
||
708 |
CFileCB* TDrive::LocateFileByPath(const TDesC& aPath) |
|
709 |
// |
|
710 |
// Locate a file opened in a subdirectory of aPath |
|
711 |
// |
|
712 |
{ |
|
713 |
||
714 |
TDblQueIter<CFileCB> q(CurrentMount().iMountQ); |
|
715 |
CFileCB* pF; |
|
716 |
while ((pF=q++)!=NULL) |
|
717 |
{ |
|
718 |
if (IsSubDir(pF->FileName(),aPath)) |
|
719 |
return(pF); |
|
720 |
} |
|
721 |
return(NULL); |
|
722 |
} |
|
723 |
||
724 |
void TDrive::FlushCachedFileInfoL() |
|
725 |
// |
|
726 |
// Flush data stored in the file control blocks |
|
727 |
// |
|
728 |
{ |
|
729 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
730 |
TDblQueIter<CFileCB> q(CurrentMount().iMountQ); |
|
731 |
CFileCB* pF; |
|
732 |
while ((pF=q++)!=NULL) |
|
733 |
{ |
|
734 |
if (pF->iAtt&KEntryAttModified) |
|
735 |
pF->FlushAllL(); |
|
736 |
} |
|
737 |
} |
|
738 |
||
739 |
/** |
|
740 |
Flushes (asynchronously) all dirty data on this drive and optionally |
|
741 |
purges non-dirty data |
|
742 |
||
743 |
aPurgeCache - purges all file caches on this drive AFTER dirty data has ben flushed |
|
744 |
||
745 |
returns KErrNone if complete |
|
746 |
CFsRequest::EReqActionBusy if flushing is in progress |
|
747 |
otherwise one of the other system-wide error codes. |
|
748 |
*/ |
|
749 |
TInt TDrive::FlushCachedFileInfo(TBool aPurgeCache) |
|
750 |
{ |
|
751 |
if (iCurrentMount == NULL) |
|
752 |
return KErrNone; |
|
753 |
||
754 |
TBool driveThread = FsThreadManager::IsDriveThread(iDriveNumber,EFalse); |
|
755 |
||
756 |
Lock(); |
|
757 |
||
758 |
||
759 |
TInt ret = KErrNone; |
|
760 |
||
761 |
TDblQueIter<CFileCB> q(iCurrentMount->iMountQ); |
|
762 |
CFileCB* pF; |
|
763 |
while ((pF=q++)!=NULL) |
|
764 |
{ |
|
765 |
CFileCache* fileCache = pF->FileCache(); |
|
766 |
||
767 |
// Write dirty data if there is a file cache |
|
768 |
TInt flushDirtyRetCode = CFsRequest::EReqActionComplete; |
|
769 |
if (fileCache) |
|
770 |
{ |
|
771 |
flushDirtyRetCode = fileCache->FlushDirty(); |
|
772 |
if (flushDirtyRetCode == CFsRequest::EReqActionComplete) // nothing to flush |
|
773 |
{ |
|
774 |
if (aPurgeCache) |
|
775 |
fileCache->Purge(EFalse); |
|
776 |
} |
|
777 |
else if (flushDirtyRetCode == CFsRequest::EReqActionBusy) // flushing |
|
778 |
{ |
|
779 |
ret = flushDirtyRetCode; |
|
780 |
} |
|
781 |
else // error |
|
782 |
{ |
|
783 |
ret = flushDirtyRetCode; |
|
784 |
break; |
|
785 |
} |
|
786 |
} |
|
787 |
// if no file cache or no dirty data left, update the file entry & attributes |
|
788 |
if (driveThread && (pF->iAtt&KEntryAttModified) && flushDirtyRetCode == CFsRequest::EReqActionComplete ) |
|
789 |
{ |
|
790 |
TRAP(ret, pF->FlushAllL()); |
|
791 |
if (ret != KErrNone) |
|
792 |
break; |
|
793 |
} |
|
794 |
} |
|
795 |
||
796 |
UnLock(); |
|
797 |
||
798 |
||
799 |
return ret; |
|
800 |
} |
|
801 |
||
802 |
//---------------------------------------------------------------------------- |
|
803 |
/** |
|
804 |
Purge dirty cache data associated with all files on a given mount |
|
805 |
*/ |
|
806 |
void TDrive::PurgeDirty(CMountCB& aMount) |
|
807 |
{ |
|
808 |
TDblQueIter<CFileCB> q(aMount.iMountQ); |
|
809 |
CFileCB* pF; |
|
810 |
while ((pF=q++)!=NULL) |
|
811 |
{ |
|
812 |
CFileCache* fileCache = pF->FileCache(); |
|
813 |
if (fileCache) |
|
814 |
{ |
|
815 |
fileCache->Purge(ETrue); |
|
816 |
fileCache->MarkFileClean(); |
|
817 |
} |
|
818 |
} |
|
819 |
} |
|
820 |
||
821 |
//---------------------------------------------------------------------------- |
|
822 |
TInt TDrive::ValidateShare(CFileCB& aFile, TShare aReqShare) |
|
823 |
// |
|
824 |
// Check that the sharing rules are obeyed. |
|
825 |
// |
|
826 |
{ |
|
257 | 827 |
|
0 | 828 |
switch (aReqShare) |
829 |
{ |
|
830 |
case EFileShareExclusive: |
|
831 |
case EFileShareReadersOnly: |
|
832 |
case EFileShareAny: |
|
833 |
case EFileShareReadersOrWriters: |
|
834 |
break; |
|
835 |
default: |
|
257 | 836 |
return(KErrArgument); |
0 | 837 |
} |
838 |
switch (aFile.iShare) |
|
839 |
{ |
|
840 |
case EFileShareExclusive: |
|
257 | 841 |
return(KErrInUse); |
0 | 842 |
|
843 |
case EFileShareReadersOnly: |
|
844 |
case EFileShareAny: |
|
845 |
if (aReqShare != aFile.iShare && aReqShare != EFileShareReadersOrWriters) |
|
257 | 846 |
return(KErrInUse); |
0 | 847 |
break; |
848 |
||
849 |
case EFileShareReadersOrWriters: |
|
257 | 850 |
if (aReqShare==EFileShareExclusive) |
851 |
return(KErrInUse); |
|
0 | 852 |
// |
257 | 853 |
// If the file is currently open as EFileShareReadersOrWriters then |
0 | 854 |
// promote the share to the requested share mode. |
855 |
// |
|
257 | 856 |
// If the requested share is EFileShareReadersOnly, verfiy that no |
857 |
// other share has the file open for writing. |
|
858 |
// |
|
859 |
||
0 | 860 |
if (aReqShare == EFileShareReadersOnly) |
861 |
{ |
|
257 | 862 |
FileShares->Lock(); |
863 |
TInt count = FileShares->Count(); |
|
864 |
while(count--) |
|
0 | 865 |
{ |
257 | 866 |
CFileShare* share = (CFileShare*)(*FileShares)[count]; |
867 |
if (&share->File() == &aFile) |
|
0 | 868 |
{ |
257 | 869 |
if(share->iMode & EFileWrite) |
870 |
{ |
|
871 |
FileShares->Unlock(); |
|
872 |
return KErrInUse; |
|
873 |
} |
|
0 | 874 |
} |
875 |
} |
|
257 | 876 |
FileShares->Unlock(); |
0 | 877 |
} |
878 |
break; |
|
879 |
||
880 |
default: |
|
881 |
Fault(EDrvIllegalShareValue); |
|
882 |
break; |
|
883 |
} |
|
257 | 884 |
return(KErrNone); |
0 | 885 |
} |
257 | 886 |
|
0 | 887 |
void TDrive::DriveInfo(TDriveInfo& anInfo) |
888 |
// |
|
889 |
// Get the drive info. |
|
890 |
// |
|
891 |
{ |
|
892 |
anInfo.iType=EMediaNotPresent; |
|
893 |
anInfo.iMediaAtt=0; |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
894 |
anInfo.iBattery=EBatNotSupported; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
895 |
anInfo.iConnectionBusType=EConnectionBusInternal; |
0 | 896 |
|
897 |
if(iFSys) |
|
898 |
{ |
|
257 | 899 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemDriveInfo, EF32TraceUidFileSys, &FSys(), DriveNumber()); |
0 | 900 |
FSys().DriveInfo(anInfo,DriveNumber()); |
257 | 901 |
TRACE3(UTF::EBorder, UTraceModuleFileSys::ECFileSystemDriveInfoRet, EF32TraceUidFileSys, |
902 |
anInfo.iType, anInfo.iDriveAtt, anInfo.iMediaAtt); |
|
0 | 903 |
} |
904 |
||
905 |
anInfo.iDriveAtt=Att(); |
|
906 |
} |
|
907 |
||
908 |
TInt TDrive::Volume(TVolumeInfo& aVolume) |
|
909 |
// |
|
910 |
// Get the drive volume info. |
|
911 |
// |
|
912 |
{ |
|
913 |
TInt r=CheckMount(); |
|
914 |
if (r==KErrNone) |
|
915 |
{ |
|
916 |
DriveInfo(aVolume.iDrive); |
|
917 |
CMountCB& m=CurrentMount(); |
|
918 |
aVolume.iName=m.VolumeName(); |
|
919 |
aVolume.iUniqueID=m.iUniqueID; |
|
920 |
aVolume.iSize=m.iSize; |
|
921 |
||
257 | 922 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBVolumeL, EF32TraceUidFileSys, DriveNumber()); |
0 | 923 |
TRAP(r,m.VolumeL(aVolume)) |
257 | 924 |
TRACE7(UTF::EBorder, UTraceModuleFileSys::ECMountCBVolumeLRet, EF32TraceUidFileSys, |
925 |
r, aVolume.iUniqueID, I64LOW(aVolume.iSize), I64HIGH(aVolume.iSize), |
|
926 |
I64LOW(aVolume.iFree), I64HIGH(aVolume.iFree), aVolume.iFileCacheFlags); |
|
927 |
||
0 | 928 |
} |
929 |
return(r); |
|
930 |
} |
|
931 |
||
932 |
||
933 |
void TDrive::SetVolumeL(const TDesC& aName,HBufC*& aBuf) |
|
934 |
// |
|
935 |
// Set the volume name. |
|
936 |
// |
|
937 |
{ |
|
938 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
939 |
aBuf=aName.AllocL(); |
|
940 |
TPtr volumeName=aBuf->Des(); |
|
257 | 941 |
|
942 |
TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBSetVolumeL, EF32TraceUidFileSys, DriveNumber(), aName); |
|
0 | 943 |
CurrentMount().SetVolumeL(volumeName); |
257 | 944 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBSetVolumeLRet, EF32TraceUidFileSys, KErrNone); |
945 |
||
946 |
||
0 | 947 |
delete &CurrentMount().VolumeName(); |
948 |
CurrentMount().SetVolumeName(aBuf); |
|
949 |
} |
|
950 |
||
951 |
TInt TDrive::SetVolume(const TDesC& aName) |
|
952 |
// |
|
953 |
// Set the volume name. |
|
954 |
// |
|
955 |
{ |
|
956 |
TInt r=CheckMount(); |
|
957 |
HBufC* pV=NULL; |
|
958 |
if (r==KErrNone) |
|
959 |
{ |
|
960 |
if(IsWriteProtected()) |
|
961 |
return(KErrAccessDenied); |
|
962 |
TRAP(r,SetVolumeL(aName,pV)) |
|
963 |
if (r!=KErrNone) |
|
964 |
delete pV; |
|
965 |
} |
|
966 |
return(r); |
|
967 |
} |
|
968 |
||
969 |
TInt TDrive::MkDir(const TDesC& aName) |
|
970 |
// |
|
971 |
// Make a directory. |
|
972 |
// |
|
973 |
{ |
|
974 |
TInt r=CheckMount(); |
|
975 |
if (r!=KErrNone) |
|
976 |
return(r); |
|
977 |
if(IsWriteProtected()) |
|
978 |
return(KErrAccessDenied); |
|
979 |
TParse newDirName; |
|
980 |
newDirName.Set(aName,NULL,NULL); |
|
257 | 981 |
|
982 |
TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBMkDirL, EF32TraceUidFileSys, DriveNumber(), aName); |
|
0 | 983 |
TRAP(r,CurrentMount().MkDirL(newDirName.FullName())) |
257 | 984 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBMkDirLRet, EF32TraceUidFileSys, r); |
985 |
||
0 | 986 |
return(r); |
987 |
} |
|
257 | 988 |
|
0 | 989 |
TInt TDrive::RmDir(const TDesC& aName) |
990 |
// |
|
991 |
// Remove a directory. |
|
992 |
// |
|
993 |
{ |
|
994 |
TInt r=CheckMount(); |
|
995 |
if (r!=KErrNone) |
|
996 |
return(r); |
|
997 |
TEntry entry; |
|
998 |
r=Entry(aName,entry); |
|
999 |
if (r!=KErrNone) |
|
1000 |
return(r); |
|
1001 |
if (entry.IsDir()==EFalse) |
|
1002 |
return(KErrPathNotFound); |
|
1003 |
if ((entry.iAtt&KEntryAttReadOnly) || IsWriteProtected()) |
|
1004 |
return(KErrAccessDenied); |
|
257 | 1005 |
|
1006 |
TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBRmDirL, EF32TraceUidFileSys, DriveNumber(), aName); |
|
0 | 1007 |
TRAP(r,CurrentMount().RmDirL(aName)) |
257 | 1008 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRmDirLRet, EF32TraceUidFileSys, r); |
1009 |
||
0 | 1010 |
return(r); |
1011 |
} |
|
1012 |
||
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1013 |
/* |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1014 |
Delete files allowing wild cards. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1015 |
*/ |
0 | 1016 |
TInt TDrive::Delete(const TDesC& aName) |
1017 |
{ |
|
1018 |
TInt r=CheckMountAndEntryName(aName); |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1019 |
if(r!=KErrNone) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1020 |
return r; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1021 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1022 |
if(LocateFile(aName)) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1023 |
return KErrInUse; //-- the file is already opened by someone |
0 | 1024 |
|
1025 |
// remove from closed queue - NB this isn't strictly necessary if file is read-only or write-protected... |
|
1026 |
LocateClosedFile(aName, EFalse); |
|
1027 |
||
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1028 |
if (IsWriteProtected()) |
0 | 1029 |
return(KErrAccessDenied); |
257 | 1030 |
|
1031 |
//-- filesystems' CMountCB::DeleteL() implementations shall check the entry attributes themeselves. |
|
1032 |
TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteL, EF32TraceUidFileSys, DriveNumber(), aName); |
|
0 | 1033 |
TRAP(r,CurrentMount().DeleteL(aName)) |
257 | 1034 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBDeleteLRet, EF32TraceUidFileSys, r); |
1035 |
||
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1036 |
return r; |
0 | 1037 |
} |
1038 |
||
1039 |
TInt TDrive::CheckMountAndEntryNames(const TDesC& anOldName,const TDesC& aNewName) |
|
1040 |
// |
|
1041 |
// Check mount, that neither is open, and that both names are legal. |
|
1042 |
// |
|
1043 |
{ |
|
1044 |
||
1045 |
TInt r=CheckMountAndEntryName(anOldName); |
|
1046 |
if (r!=KErrNone) |
|
1047 |
return(r); |
|
1048 |
if (IsIllegalFullName(aNewName)) |
|
1049 |
return(KErrBadName); |
|
1050 |
return(KErrNone); |
|
1051 |
} |
|
1052 |
||
1053 |
TInt TDrive::CheckDirectories(const TDesC& anOldName,const TDesC& aNewName) |
|
1054 |
// |
|
1055 |
// Return KErrAlreadyExists if aNewName exists and |
|
1056 |
// KErrAccessDenied if anOldName is a directory being moved to a subdirectory of itself |
|
1057 |
// |
|
1058 |
{ |
|
1059 |
||
1060 |
TEntry entry; |
|
1061 |
TInt r=Entry(anOldName,entry); |
|
1062 |
if (r!=KErrNone) |
|
1063 |
return(r); |
|
1064 |
if (entry.IsDir()) |
|
1065 |
{ |
|
1066 |
//-- check the length of the destination directory name. It shall not exceed 253 characters. |
|
1067 |
//-- aNewName looks like "\\dir1" i.e. drive letter and ':' is removed from the name and there is no trailing '\\' in this case. |
|
1068 |
||
1069 |
const TInt maxDirNameLength = KMaxFileName - 3; |
|
1070 |
if(aNewName.Length() > maxDirNameLength) |
|
1071 |
return KErrBadName; |
|
1072 |
if(IsSubDir(aNewName,anOldName)) |
|
1073 |
return(KErrInUse); // rename into a subdir of itself |
|
1074 |
if (LocateFileByPath(anOldName)) |
|
1075 |
return(KErrInUse); // a file inside anOldName is open |
|
1076 |
} |
|
1077 |
else if (LocateFile(anOldName)) |
|
1078 |
return(KErrInUse); |
|
1079 |
||
1080 |
r=Entry(aNewName,entry); |
|
1081 |
if (r!=KErrNone && r!=KErrNotFound) |
|
1082 |
return(r); |
|
1083 |
return(KErrNone); |
|
1084 |
} |
|
1085 |
||
1086 |
TInt TDrive::Rename(const TDesC& anOldName,const TDesC& aNewName) |
|
1087 |
// |
|
1088 |
// Rename files or directories. No wild cards. |
|
1089 |
// |
|
1090 |
{ |
|
1091 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
1092 |
TInt r=CheckMountAndEntryNames(anOldName,aNewName); |
|
1093 |
if (r!=KErrNone) |
|
1094 |
return(r); |
|
1095 |
TPtrC oldEntryName(StripBackSlash(anOldName)); |
|
1096 |
TPtrC newEntryName(StripBackSlash(aNewName)); |
|
1097 |
r=CheckDirectories(oldEntryName,newEntryName); |
|
1098 |
if (r!=KErrNone) |
|
1099 |
return(r); |
|
1100 |
if(IsWriteProtected()) |
|
1101 |
return(KErrAccessDenied); |
|
1102 |
||
1103 |
// remove from closed queue |
|
1104 |
LocateClosedFile(anOldName, EFalse); |
|
1105 |
LocateClosedFile(aNewName, EFalse); |
|
257 | 1106 |
|
1107 |
TRACEMULT3(UTF::EBorder, UTraceModuleFileSys::ECMountCBRenameL, EF32TraceUidFileSys, DriveNumber(), oldEntryName,newEntryName); |
|
0 | 1108 |
TRAP(r,CurrentMount().RenameL(oldEntryName,newEntryName)) |
257 | 1109 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBRenameLRet, EF32TraceUidFileSys, r); |
1110 |
||
0 | 1111 |
return(r); |
1112 |
} |
|
1113 |
||
1114 |
TInt TDrive::Replace(const TDesC& anOldName,const TDesC& aNewName) |
|
1115 |
// |
|
1116 |
// Replace anOldName with aNewName atomically. No wild cards. No directories |
|
1117 |
// |
|
1118 |
{ |
|
1119 |
TInt r=CheckMountAndEntryNames(anOldName,aNewName); |
|
1120 |
if (r!=KErrNone) |
|
1121 |
return(r); |
|
1122 |
TEntry entry; |
|
1123 |
r=Entry(aNewName,entry); |
|
1124 |
if (r!=KErrNotFound) |
|
1125 |
{ |
|
1126 |
if (r!=KErrNone) |
|
1127 |
return(r); |
|
1128 |
if (entry.IsDir() || entry.IsReadOnly()) |
|
1129 |
return(KErrAccessDenied); |
|
1130 |
if (LocateFile(aNewName)) |
|
1131 |
return(KErrInUse); |
|
1132 |
} |
|
1133 |
r=Entry(anOldName,entry); |
|
1134 |
if (r!=KErrNone) |
|
1135 |
return(r); |
|
1136 |
if (entry.IsDir() || IsWriteProtected()) |
|
1137 |
return(KErrAccessDenied); |
|
1138 |
if (LocateFile(anOldName)) |
|
1139 |
return(KErrInUse); |
|
1140 |
||
1141 |
// remove from closed queue |
|
1142 |
LocateClosedFile(anOldName, EFalse); |
|
1143 |
LocateClosedFile(aNewName, EFalse); |
|
257 | 1144 |
|
1145 |
TRACEMULT3(UTF::EBorder, UTraceModuleFileSys::ECMountCBReplaceL, EF32TraceUidFileSys, DriveNumber(), anOldName, aNewName); |
|
0 | 1146 |
TRAP(r,CurrentMount().ReplaceL(anOldName,aNewName)) |
257 | 1147 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReplaceLRet, EF32TraceUidFileSys, r); |
1148 |
||
0 | 1149 |
return(r); |
1150 |
} |
|
1151 |
||
1152 |
TInt TDrive::Entry(const TDesC& aName,TEntry& anEntry) |
|
1153 |
// |
|
1154 |
// Get the entry details. |
|
1155 |
// |
|
1156 |
{ |
|
1157 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
1158 |
TInt r=CheckMountAndEntryName(aName); |
|
1159 |
if (r!=KErrNone) |
|
1160 |
return(r); |
|
1161 |
TPtrC entryName(StripBackSlash(aName)); |
|
1162 |
TRAP(r,DoEntryL(entryName,anEntry)); |
|
1163 |
||
1164 |
if (r==KErrHidden) |
|
1165 |
r=KErrNotFound; |
|
1166 |
else if (r==KErrPathHidden) |
|
1167 |
r=KErrPathNotFound; |
|
1168 |
||
1169 |
return(r); |
|
1170 |
} |
|
1171 |
||
1172 |
void TDrive::DoEntryL(const TDesC& aName, TEntry& anEntry) |
|
1173 |
// |
|
1174 |
// Get entry details |
|
1175 |
// |
|
1176 |
{ |
|
257 | 1177 |
TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBEntryL, EF32TraceUidFileSys, DriveNumber(), aName); |
0 | 1178 |
CurrentMount().EntryL(aName,anEntry); |
248
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1179 |
|
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1180 |
// If the file is already open then read the file attributes directly from the file |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1181 |
TFileName foldedName; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1182 |
TUint32 nameHash=0; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1183 |
foldedName.CopyF(aName); |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1184 |
nameHash=CalcNameHash(foldedName); |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1185 |
|
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1186 |
__CHECK_DRIVETHREAD(iDriveNumber); |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1187 |
TDblQueIter<CFileCB> q(CurrentMount().iMountQ); |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1188 |
CMountCB* currentMount = &CurrentMount(); |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1189 |
CFileCB* file; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1190 |
while ((file=q++)!=NULL) |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1191 |
{ |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1192 |
if ((&file->Drive()==this) && |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1193 |
&file->Mount() == currentMount && |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1194 |
nameHash == file->NameHash() && |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1195 |
file->FileNameF().Match(foldedName)==KErrNone) |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1196 |
{ |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1197 |
anEntry.iAtt = file->Att() & ~KEntryAttModified; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1198 |
anEntry.SetFileSize(file->CachedSize64()); |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1199 |
anEntry.iModified = file->Modified(); |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1200 |
break; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1201 |
} |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1202 |
} |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1203 |
|
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1204 |
|
257 | 1205 |
TRACE5(UTF::EBorder, UTraceModuleFileSys::ECMountCBEntryLRet, EF32TraceUidFileSys, |
1206 |
KErrNone, anEntry.iAtt, |
|
1207 |
I64LOW(anEntry.iModified.Int64()), I64HIGH(anEntry.iModified.Int64()), |
|
1208 |
anEntry.iSize); |
|
1209 |
||
0 | 1210 |
} |
1211 |
||
248
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1212 |
TInt TDrive::CheckAttributes(TUint& aSetAttMask,TUint& aClearAttMask) |
0 | 1213 |
// |
1214 |
// Validate the changes against the current entry attributes |
|
1215 |
// |
|
1216 |
{ |
|
248
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1217 |
ValidateAtts(aSetAttMask,aClearAttMask); |
0 | 1218 |
return(KErrNone); |
1219 |
} |
|
1220 |
||
1221 |
TInt TDrive::SetEntry(const TDesC& aName,const TTime& aTime,TUint aSetAttMask,TUint aClearAttMask) |
|
1222 |
// |
|
1223 |
// Set the entry details. |
|
1224 |
// |
|
1225 |
{ |
|
1226 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
1227 |
TInt r=CheckMountAndEntryName(aName); |
|
1228 |
if (r!=KErrNone) |
|
1229 |
return(r); |
|
1230 |
TPtrC entryName(StripBackSlash(aName)); |
|
1231 |
CFileCB* pF=LocateFile(entryName); |
|
1232 |
if (pF!=NULL) |
|
1233 |
return(KErrInUse); |
|
248
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1234 |
r=CheckAttributes(aSetAttMask,aClearAttMask); |
0 | 1235 |
if (r!=KErrNone) |
1236 |
return(r); |
|
1237 |
if (IsWriteProtected()) |
|
1238 |
return(KErrAccessDenied); |
|
1239 |
TTime nullTime(0); |
|
1240 |
if (aTime!=nullTime) |
|
1241 |
aSetAttMask|=KEntryAttModified; |
|
257 | 1242 |
|
1243 |
TRACEMULT6(UTF::EBorder, UTraceModuleFileSys::ECMountCBSetEntryL, EF32TraceUidFileSys, |
|
1244 |
DriveNumber(), aName, I64LOW(aTime.Int64()), I64HIGH(aTime.Int64()), aSetAttMask, aClearAttMask); |
|
256
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
249
diff
changeset
|
1245 |
TRAP(r,CurrentMount().SetEntryL(entryName,aTime,aSetAttMask,aClearAttMask)) |
257 | 1246 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBSetEntryLRet, EF32TraceUidFileSys, r); |
249
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1247 |
// If the file is already open then write the file attributes directly to the file |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1248 |
TFileName foldedName; |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1249 |
TUint32 nameHash=0; |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1250 |
foldedName.CopyF(aName); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1251 |
nameHash=CalcNameHash(foldedName); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1252 |
|
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1253 |
__CHECK_DRIVETHREAD(iDriveNumber); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1254 |
TDblQueIter<CFileCB> q(CurrentMount().iMountQ); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1255 |
CMountCB* currentMount = &CurrentMount(); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1256 |
CFileCB* file; |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1257 |
while ((file=q++)!=NULL) |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1258 |
{ |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1259 |
if ((&file->Drive()==this) && |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1260 |
&file->Mount() == currentMount && |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1261 |
nameHash == file->NameHash() && |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1262 |
file->FileNameF().Match(foldedName)==KErrNone) |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1263 |
{ |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1264 |
TUint att = file->Att(); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1265 |
att |= aSetAttMask; |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1266 |
att &= ~aClearAttMask; |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1267 |
file->SetAtt(att | KEntryAttModified); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1268 |
file->SetModified(aTime); |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1269 |
break; |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1270 |
} |
a179b74831c9
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
248
diff
changeset
|
1271 |
} |
0 | 1272 |
|
1273 |
return(r); |
|
1274 |
} |
|
1275 |
||
1276 |
TInt TDrive::FileTemp(CFsRequest* aRequest,TInt& aHandle,const TDesC& aPath,TDes& aName,TUint aMode) |
|
1277 |
// |
|
1278 |
// Create a temporary file and return the file name. |
|
1279 |
// |
|
1280 |
{ |
|
1281 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
1282 |
aName=aPath; |
|
1283 |
TInt len=aName.Length(); |
|
1284 |
TInt t=User::TickCount()&0xfffff; |
|
1285 |
aMode|=EFileWrite; |
|
1286 |
for (TInt retry=0;retry<KMaxTempNameAttempts;retry++) |
|
1287 |
{ |
|
1288 |
aName.SetLength(len); |
|
1289 |
aName.AppendFormat(_L("TMP%05x.$$$"),t); |
|
1290 |
TEntry e; |
|
1291 |
TInt r=Entry(aName,e); |
|
1292 |
if (r!=KErrNone) |
|
1293 |
{ |
|
1294 |
if (r!=KErrNotFound) |
|
1295 |
return(r); |
|
1296 |
return(FileOpen(aRequest,aHandle,aName,aMode,EFileCreate)); |
|
1297 |
} |
|
1298 |
t=((t|1)*13)&0xfffff; |
|
1299 |
} |
|
1300 |
return(KErrGeneral); |
|
1301 |
} |
|
1302 |
||
1303 |
LOCAL_C HBufC* CreateFileNameL(const TDesC& aName) |
|
1304 |
// |
|
1305 |
// Create a HBufC from aName |
|
1306 |
// Converts _L("\\F32.\\GROUP\\release.") to _L("\\F32\\GROUP\\release") |
|
1307 |
// |
|
1308 |
{ |
|
1309 |
||
1310 |
TParsePtrC name(aName); |
|
1311 |
TFileName fileName; |
|
1312 |
fileName.Append(KPathDelimiter); |
|
1313 |
||
1314 |
if (name.Path().Length()) |
|
1315 |
{ |
|
1316 |
TInt pos=0; |
|
1317 |
TPtrC entry(NULL,0); |
|
1318 |
FOREVER |
|
1319 |
{ |
|
1320 |
NextInPath(name.Path(),entry,pos); |
|
1321 |
if (entry.Length()==0) |
|
1322 |
break; |
|
1323 |
fileName.Append(entry); |
|
1324 |
fileName.Append(KPathDelimiter); |
|
1325 |
} |
|
1326 |
} |
|
1327 |
||
1328 |
fileName.Append(name.Name()); |
|
1329 |
if (name.Ext().Length()>1) |
|
1330 |
fileName.Append(name.Ext()); |
|
1331 |
return(fileName.AllocL()); |
|
1332 |
} |
|
1333 |
||
1334 |
void TDrive::FileOpenL(CFsRequest* aRequest,TInt& aHandle,const TDesC& aName,TUint aMode,TFileOpen anOpen,CFileCB*& aFileCB,CFileShare*& aFileShare) |
|
1335 |
// |
|
1336 |
// Open/Create/Replace a file. |
|
1337 |
// |
|
1338 |
{ |
|
1339 |
aFileCB=NULL; |
|
1340 |
aFileShare=NULL; |
|
1341 |
TInt r = CheckMount(); |
|
1342 |
if (r!=KErrNone) |
|
1343 |
User::Leave(r); |
|
1344 |
||
1345 |
if (IsIllegalFullName(aRequest->Src())) |
|
1346 |
User::Leave(KErrBadName); |
|
1347 |
||
1348 |
if (CurrentMount().Locked()) |
|
1349 |
User::Leave(KErrInUse); |
|
1350 |
||
1351 |
if ((aMode & EFileWrite) != 0) |
|
1352 |
{ |
|
1353 |
TDriveInfo driveInfo; |
|
1354 |
DriveInfo(driveInfo); |
|
1355 |
if (driveInfo.iType==EMediaRom || (driveInfo.iMediaAtt&KMediaAttWriteProtected)!=0) |
|
1356 |
User::Leave(KErrAccessDenied); |
|
1357 |
} |
|
1358 |
||
1359 |
TShare share=(TShare)(aMode&KFileShareMask); |
|
1360 |
if (share==EFileShareReadersOnly && (aMode&EFileWrite)!=0) |
|
1361 |
User::Leave(KErrArgument); |
|
1362 |
||
1363 |
if (aMode & EFileReadAsyncAll) |
|
1364 |
{ |
|
1365 |
// Async read all mode is not compatible with EFileShareExclusive or EFileShareReadersOnly, |
|
1366 |
// as these modes prevent a writer from accessing the file and completing the request. |
|
1367 |
if(share == EFileShareExclusive || share == EFileShareReadersOnly) |
|
1368 |
User::Leave(KErrArgument); |
|
1369 |
} |
|
1370 |
||
1371 |
// check for silly cache on / off combinations |
|
1372 |
const TUint KBadWriteMode = EFileWriteBuffered | EFileWriteDirectIO; |
|
1373 |
const TUint KBadReadMode = EFileReadBuffered | EFileReadDirectIO; |
|
1374 |
const TUint KBadReadAheadMode = EFileReadAheadOn | EFileReadAheadOff; |
|
1375 |
const TUint KBadReadAheadMode2 = EFileReadDirectIO | EFileReadAheadOn; |
|
1376 |
if (((aMode & KBadWriteMode) == KBadWriteMode) || |
|
1377 |
((aMode & KBadReadMode) == KBadReadMode) || |
|
1378 |
((aMode & KBadReadAheadMode) == KBadReadAheadMode) || |
|
1379 |
((aMode & KBadReadAheadMode2) == KBadReadAheadMode2)) |
|
1380 |
{ |
|
1381 |
User::Leave(KErrArgument); |
|
1382 |
} |
|
1383 |
||
1384 |
// Only allow delete on close for a newly created file. |
|
1385 |
if ((aMode & EDeleteOnClose) && (anOpen!=EFileCreate)) |
|
1386 |
User::Leave(KErrArgument); |
|
1387 |
||
257 | 1388 |
CFileCB* pF=LocateFile(aName); |
0 | 1389 |
CFileCache* pFileCache = NULL; |
257 | 1390 |
TBool openFile=EFalse; |
1391 |
if (pF!=NULL) |
|
0 | 1392 |
{ |
257 | 1393 |
if (pF->iShare==EFileShareReadersOnly && (aMode&EFileWrite)!=0) |
0 | 1394 |
User::Leave(KErrInUse); |
1395 |
if (anOpen==EFileCreate) |
|
1396 |
User::Leave(KErrAlreadyExists); |
|
257 | 1397 |
TInt r=ValidateShare(*pF,share); |
0 | 1398 |
if (r!=KErrNone) |
1399 |
User::Leave(r); |
|
257 | 1400 |
if ((r=pF->Open())!=KErrNone) |
0 | 1401 |
User::Leave(r); |
257 | 1402 |
aFileCB=pF; |
1403 |
pFileCache = pF->FileCache(); |
|
0 | 1404 |
} |
1405 |
else |
|
1406 |
{ |
|
257 | 1407 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFileL, EF32TraceUidFileSys, &FSys(), DriveNumber()); |
1408 |
||
0 | 1409 |
//-- construct CFileCB object, belonging to the corresponding mount |
257 | 1410 |
pF = aFileCB = CurrentMount().NewFileL(); |
1411 |
||
1412 |
TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFileLRet, EF32TraceUidFileSys, r, pF); |
|
0 | 1413 |
TDrive* createdDrive=!aRequest->SubstedDrive() ? this : aRequest->SubstedDrive(); |
1414 |
||
1415 |
HBufC* fileName = CreateFileNameL(aName); |
|
1416 |
||
257 | 1417 |
pF->InitL(this, createdDrive, fileName); |
1418 |
||
1419 |
||
1420 |
pF->iShare = share; |
|
0 | 1421 |
openFile=ETrue; |
257 | 1422 |
CurrentMount().iMountQ.AddLast(*pF); |
1423 |
Files->AddL(pF,ETrue); |
|
0 | 1424 |
} |
1425 |
||
257 | 1426 |
CFileShare* pS=aFileShare=new(ELeave) CFileShare(pF); |
0 | 1427 |
|
1428 |
// We need to call CFileCB::PromoteShare immediately after the CFileShare |
|
1429 |
// instance is created since the destructor calls CFileCB::DemoteShare() |
|
1430 |
// which checks the share count is non-zero |
|
257 | 1431 |
pS->iMode=aMode; |
1432 |
pF->PromoteShare(pS); |
|
1433 |
||
1434 |
pS->InitL(); |
|
0 | 1435 |
aFileCB=NULL; |
257 | 1436 |
FileShares->AddL(pS,ETrue); |
1437 |
aHandle=aRequest->Session()->Handles().AddL(pS,ETrue); |
|
0 | 1438 |
|
1439 |
||
1440 |
if (openFile) |
|
1441 |
{ |
|
257 | 1442 |
TRACEMULT5(UTF::EBorder, UTraceModuleFileSys::ECMountCBFileOpenL, EF32TraceUidFileSys, DriveNumber(), aName, aMode, (TUint) anOpen, (TUint) pF); |
1443 |
CurrentMount().FileOpenL(aName,aMode,anOpen,pF); |
|
1444 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBFileOpenLRet, EF32TraceUidFileSys, KErrNone); |
|
1445 |
||
0 | 1446 |
// Delete on close may now be safely flagged if required. |
1447 |
// The file did not exist on the media prior to the |
|
1448 |
// CMountCB::FileOpenL() call for the case of a create. |
|
1449 |
if ((aMode & EDeleteOnClose) && (anOpen==EFileCreate)) |
|
257 | 1450 |
pF->SetDeleteOnClose(); |
1451 |
||
1452 |
TBool localBufferSuppport = (CurrentMount().LocalBufferSupport(pF) == KErrNone)?(TBool)ETrue:(TBool)EFalse; |
|
1453 |
pF->SetLocalBufferSupport(localBufferSuppport); |
|
0 | 1454 |
if (localBufferSuppport) |
1455 |
{ |
|
257 | 1456 |
// if file exists on closed queue resurrect it or discard it, |
0 | 1457 |
// depending on the file open mode |
1458 |
pFileCache = LocateClosedFile(aName, anOpen == EFileOpen?(TBool)ETrue:(TBool)EFalse); |
|
1459 |
if (pFileCache) |
|
1460 |
{ |
|
257 | 1461 |
pFileCache = pFileCache->ReNewL(*pS); // NB may return NULL if caching not enabled |
0 | 1462 |
} |
1463 |
else |
|
1464 |
{ |
|
257 | 1465 |
pFileCache = CFileCache::NewL(*pS); // NB may return NULL if caching not enabled |
0 | 1466 |
} |
1467 |
if (pFileCache) |
|
257 | 1468 |
// set the cached size to be the same as the uncached size |
1469 |
pF->SetCachedSize64(pF->Size64()); |
|
0 | 1470 |
} |
1471 |
else |
|
1472 |
{ |
|
1473 |
__CACHE_PRINT(_L("TDrive::FileOpenL(), Local buffers not supported")); |
|
1474 |
} |
|
1475 |
} |
|
1476 |
||
257 | 1477 |
// initialize share mode flags |
0 | 1478 |
if (pFileCache != NULL) |
257 | 1479 |
pFileCache->Init(*pS); |
0 | 1480 |
} |
1481 |
||
1482 |
TInt TDrive::FileOpen(CFsRequest* aRequest,TInt& aHandle,const TDesC& aName,TUint aMode,TFileOpen anOpen) |
|
1483 |
// |
|
1484 |
// Open/Create/Replace a file. |
|
1485 |
// |
|
1486 |
{ |
|
1487 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
1488 |
CFileCB* pF=NULL; |
|
1489 |
CFileShare* pS=NULL; |
|
1490 |
aHandle=0; |
|
257 | 1491 |
TRAPD(r,FileOpenL(aRequest,aHandle,aName,aMode,anOpen,pF,pS)) |
0 | 1492 |
|
1493 |
// Allow files > 2GB-1 to be opened only if EFileBigFile is specified in iMode |
|
1494 |
if (r == KErrNone && pS && ((TUint64)pS->File().Size64() > KMaxLegacyFileSize) && (!(pS->IsFileModeBig()))) |
|
1495 |
r = KErrTooBig; |
|
1496 |
||
1497 |
if (r!=KErrNone) |
|
1498 |
{ |
|
1499 |
if (r==KErrHidden) |
|
1500 |
r=KErrNotFound; |
|
1501 |
else if (r==KErrPathHidden) |
|
1502 |
r=KErrPathNotFound; |
|
1503 |
||
1504 |
if(pF && !pS) |
|
1505 |
pF->Close(); |
|
1506 |
CheckSubClose(pS,aHandle,aRequest->Session()); |
|
1507 |
} |
|
1508 |
return(r); |
|
1509 |
} |
|
1510 |
||
1511 |
void TDrive::DirOpenL(CSessionFs* aSession,TInt& aHandle,const TDesC& aName,TUint anAtt,const TUidType& aUidType,CDirCB*& aDir) |
|
1512 |
// |
|
1513 |
// Open a directory listing. Leave on error. |
|
1514 |
// |
|
1515 |
{ |
|
257 | 1516 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewDirL, EF32TraceUidFileSys, &FSys(), DriveNumber()); |
1517 |
||
0 | 1518 |
CDirCB* pD = aDir = CurrentMount().NewDirL(); //-- construct CDirCB object, belonging to the corresponding mount |
1519 |
||
257 | 1520 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewDirLRet, EF32TraceUidFileSys, KErrNone, pD); |
0 | 1521 |
pD->InitL(this); |
1522 |
// modify resource counter after initialisation to ensure correct cleanup |
|
1523 |
AddResource(CurrentMount()); |
|
1524 |
pD->iAtt=anAtt; |
|
1525 |
pD->iUidType=aUidType; |
|
1526 |
Dirs->AddL(pD,ETrue); |
|
1527 |
aHandle=aSession->Handles().AddL(pD,ETrue); |
|
257 | 1528 |
|
1529 |
TRACEMULT3(UTF::EBorder, UTraceModuleFileSys::ECMountCBDirOpenL, EF32TraceUidFileSys, DriveNumber(), aName, (TUint) pD); |
|
0 | 1530 |
CurrentMount().DirOpenL(aName,pD); |
257 | 1531 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBDirOpenLRet, EF32TraceUidFileSys, KErrNone); |
0 | 1532 |
} |
1533 |
||
1534 |
TInt TDrive::DirOpen(CSessionFs* aSession,TInt& aHandle,const TDesC& aName,TUint anAtt,const TUidType& aUidType) |
|
1535 |
// |
|
1536 |
// Open a directory listing. |
|
1537 |
// |
|
1538 |
{ |
|
1539 |
TInt r=CheckMountAndEntryName(aName); |
|
1540 |
if (r!=KErrNone) |
|
1541 |
return(r); |
|
1542 |
if (CurrentMount().Locked()) |
|
1543 |
return(KErrInUse); |
|
1544 |
CDirCB* pD=NULL; |
|
1545 |
aHandle=0; |
|
1546 |
TRAP(r,DirOpenL(aSession,aHandle,aName,anAtt,aUidType,pD)); |
|
1547 |
||
1548 |
if (r==KErrHidden) |
|
1549 |
r=KErrNotFound; |
|
1550 |
else if (r==KErrPathHidden) |
|
1551 |
r=KErrPathNotFound; |
|
1552 |
||
1553 |
if (r!=KErrNone) |
|
1554 |
CheckSubClose(pD,aHandle,aSession); |
|
1555 |
return(r); |
|
1556 |
} |
|
1557 |
||
1558 |
||
1559 |
TInt TDrive::ReadFileSection(const TDesC& aName,TInt aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage) |
|
1560 |
// |
|
1561 |
// Starting from aPos, read aLength bytes of a file into a Trg, |
|
1562 |
// regardless of lock state |
|
1563 |
// |
|
1564 |
{ |
|
1565 |
return ReadFileSection64(aName, aPos, aTrg, aLength, aMessage); |
|
1566 |
} |
|
1567 |
||
1568 |
||
1569 |
TInt TDrive::ReadFileSection64(const TDesC& aName,TInt64 aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage) |
|
1570 |
// |
|
1571 |
// Starting from aPos, read aLength bytes of a file into a Trg, |
|
1572 |
// regardless of lock state |
|
1573 |
// |
|
1574 |
{ |
|
1575 |
||
1576 |
// flush dirty data if already open |
|
1577 |
CFileCB* file; |
|
1578 |
IsFileOpen(aName, file); |
|
1579 |
if (file && file->FileCache()) |
|
1580 |
{ |
|
1581 |
if (file->FileCache()->FlushDirty() == CFsRequest::EReqActionBusy) |
|
1582 |
return CFsRequest::EReqActionBusy; |
|
1583 |
} |
|
1584 |
||
1585 |
__PRINT(_L("TDrive::ReadSection")); |
|
1586 |
TInt r=CheckMountAndEntryName(aName); |
|
1587 |
if (r!=KErrNone) |
|
1588 |
return(r); |
|
1589 |
TPtrC entryName(StripBackSlash(aName)); |
|
257 | 1590 |
|
0 | 1591 |
TRACETHREADID(aMessage); |
257 | 1592 |
TRACEMULT7(UTF::EBorder, UTraceModuleFileSys::ECMountCBReadFileSectionL, EF32TraceUidFileSys, |
1593 |
DriveNumber(), aName, I64LOW(aPos), I64HIGH(aPos), (TUint) aTrg, aLength, I64LOW(threadId)); |
|
0 | 1594 |
TRAP(r,ReadSectionL(entryName,aPos,aTrg,aLength,aMessage)); |
257 | 1595 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBReadFileSectionLRet, EF32TraceUidFileSys, r); |
1596 |
||
0 | 1597 |
if (r==KErrHidden) |
1598 |
r=KErrNotFound; |
|
1599 |
else if (r==KErrPathHidden) |
|
1600 |
r=KErrPathNotFound; |
|
1601 |
||
1602 |
return(r); |
|
1603 |
} |
|
1604 |
||
1605 |
||
1606 |
void TDrive::ReadSectionL(const TDesC& aName,TInt64 aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage) |
|
1607 |
// |
|
1608 |
// Starting from aPos, read aLength bytes of a file into a Trg, |
|
1609 |
// regardless of lock state |
|
1610 |
// |
|
1611 |
{ |
|
1612 |
__PRINT(_L("TDrive::ReadSectionL")); |
|
1613 |
||
1614 |
FlushCachedFileInfoL(); |
|
1615 |
CurrentMount().ReadSection64L(aName,aPos,aTrg,aLength,aMessage); |
|
1616 |
} |
|
1617 |
||
1618 |
/** |
|
1619 |
Check the disk's integrity |
|
1620 |
*/ |
|
1621 |
TInt TDrive::CheckDisk() |
|
1622 |
{ |
|
1623 |
TInt r=CheckMount(); |
|
1624 |
if (r==KErrNone) |
|
1625 |
TRAP(r,FlushCachedFileInfoL()); |
|
1626 |
if (r==KErrNone) |
|
1627 |
{ |
|
257 | 1628 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBCheckDisk1, EF32TraceUidFileSys, DriveNumber()); |
0 | 1629 |
r=CurrentMount().CheckDisk(); |
257 | 1630 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBCheckDisk1Ret, EF32TraceUidFileSys, r); |
0 | 1631 |
} |
1632 |
return(r); |
|
1633 |
} |
|
1634 |
||
1635 |
/** |
|
1636 |
@prototype |
|
1637 |
*/ |
|
1638 |
TInt TDrive::CheckDisk(TInt aOperation, TAny* aParam1/*=NULL*/, TAny* aParam2/*=NULL*/) |
|
1639 |
{ |
|
1640 |
TInt r=CheckMount(); |
|
1641 |
if (r==KErrNone) |
|
1642 |
TRAP(r,FlushCachedFileInfoL()); |
|
1643 |
if (r==KErrNone) |
|
1644 |
{ |
|
257 | 1645 |
TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBCheckDisk2, EF32TraceUidFileSys, DriveNumber(), aOperation, aParam1, aParam2); |
0 | 1646 |
r=CurrentMount().CheckDisk(aOperation, aParam1, aParam2); |
257 | 1647 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBCheckDisk2Ret, EF32TraceUidFileSys, r); |
0 | 1648 |
} |
1649 |
||
1650 |
return(r); |
|
1651 |
} |
|
1652 |
||
1653 |
TInt TDrive::ScanDrive() |
|
1654 |
{ |
|
1655 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
1656 |
TInt r=CheckMount(); |
|
1657 |
if(r==KErrNone) |
|
1658 |
{ |
|
1659 |
if(IsWriteProtected()) |
|
1660 |
return(KErrAccessDenied); |
|
1661 |
TRAP(r,FlushCachedFileInfoL()); |
|
1662 |
} |
|
1663 |
if(r!=KErrNone) |
|
1664 |
return r; |
|
1665 |
||
1666 |
// Empty closed file queue |
|
1667 |
TClosedFileUtils::Remove(DriveNumber()); |
|
1668 |
||
257 | 1669 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBScanDrive1, EF32TraceUidFileSys, DriveNumber()); |
0 | 1670 |
r = CurrentMount().ScanDrive(); |
257 | 1671 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBScanDrive1Ret, EF32TraceUidFileSys, r); |
1672 |
||
0 | 1673 |
return r; |
1674 |
} |
|
1675 |
||
1676 |
||
1677 |
/** |
|
1678 |
@prototype |
|
1679 |
*/ |
|
1680 |
TInt TDrive::ScanDrive(TInt aOperation, TAny* aParam1/*=NULL*/, TAny* aParam2/*=NULL*/) |
|
1681 |
{ |
|
1682 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
1683 |
TInt r=CheckMount(); |
|
1684 |
if(r==KErrNone) |
|
1685 |
{ |
|
1686 |
if(IsWriteProtected()) |
|
1687 |
return(KErrAccessDenied); |
|
1688 |
TRAP(r,FlushCachedFileInfoL()); |
|
1689 |
} |
|
1690 |
if(r!=KErrNone) |
|
1691 |
return r; |
|
1692 |
||
1693 |
// Empty closed file queue |
|
1694 |
TClosedFileUtils::Remove(DriveNumber()); |
|
1695 |
||
257 | 1696 |
TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBScanDrive2, EF32TraceUidFileSys, DriveNumber(), aOperation, aParam1, aParam2); |
0 | 1697 |
r = CurrentMount().ScanDrive(aOperation, aParam1, aParam2); |
257 | 1698 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBScanDrive2Ret, EF32TraceUidFileSys, r); |
1699 |
||
0 | 1700 |
return r; |
1701 |
} |
|
1702 |
||
1703 |
||
1704 |
TInt TDrive::GetShortName(const TDesC& aName,TDes& aShortName) |
|
1705 |
// |
|
1706 |
// Get the short name associated with a long file name |
|
1707 |
// |
|
1708 |
{ |
|
1709 |
TInt r=CheckMountAndEntryName(aName); |
|
1710 |
if (r!=KErrNone) |
|
1711 |
return(r); |
|
1712 |
TPtrC entryName(StripBackSlash(aName)); |
|
257 | 1713 |
|
1714 |
TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetShortNameL, EF32TraceUidFileSys, DriveNumber(), entryName); |
|
0 | 1715 |
TRAP(r,CurrentMount().GetShortNameL(entryName,aShortName)); |
257 | 1716 |
TRACERETMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetShortNameLRet, EF32TraceUidFileSys, r, aShortName); |
1717 |
||
0 | 1718 |
return(r); |
1719 |
} |
|
1720 |
||
1721 |
TInt TDrive::GetLongName(const TDesC& aShortName,TDes& aLongName) |
|
1722 |
// |
|
1723 |
// Get the long name associated with a short file name |
|
1724 |
// |
|
1725 |
{ |
|
1726 |
TInt r=CheckMountAndEntryName(aShortName); |
|
1727 |
if (r!=KErrNone) |
|
1728 |
return(r); |
|
1729 |
TPtrC entryName(StripBackSlash(aShortName)); |
|
257 | 1730 |
|
1731 |
TRACEMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetLongNameL, EF32TraceUidFileSys, DriveNumber(), entryName); |
|
0 | 1732 |
TRAP(r,CurrentMount().GetLongNameL(entryName,aLongName)); |
257 | 1733 |
TRACERETMULT2(UTF::EBorder, UTraceModuleFileSys::ECMountCBGetLongNameLRet, EF32TraceUidFileSys, r, aLongName); |
1734 |
||
0 | 1735 |
return(r); |
1736 |
} |
|
1737 |
||
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1738 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1739 |
/** |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1740 |
Query whether the file is open or not. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1741 |
*/ |
0 | 1742 |
TInt TDrive::IsFileOpen(const TDesC& aFileName,CFileCB*& aFileCB) |
1743 |
{ |
|
1744 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
1745 |
||
1746 |
aFileCB = NULL; |
|
1747 |
||
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1748 |
TInt r=CheckMountAndEntryName(aFileName); |
0 | 1749 |
if (r!=KErrNone) |
1750 |
return(r); |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1751 |
|
0 | 1752 |
Files->Lock(); |
1753 |
TInt count=Files->Count(); |
|
1754 |
||
1755 |
// create a hash to speed up the search |
|
1756 |
||
1757 |
TFileName foldedName; |
|
1758 |
TUint32 nameHash=0; |
|
1759 |
if (count > 0) |
|
1760 |
{ |
|
1761 |
foldedName.CopyF(aFileName); |
|
1762 |
nameHash=CalcNameHash(foldedName); |
|
1763 |
} |
|
1764 |
||
1765 |
while(count--) |
|
1766 |
{ |
|
1767 |
CFileCB* file=(CFileCB*)(*Files)[count]; |
|
1768 |
||
1769 |
if ((&file->Drive()==this) && nameHash == file->NameHash() && file->FileNameF().Match(foldedName)!=KErrNotFound) |
|
1770 |
{ |
|
1771 |
aFileCB = file; |
|
1772 |
break; |
|
1773 |
} |
|
1774 |
} |
|
1775 |
Files->Unlock(); |
|
1776 |
return(KErrNone); |
|
1777 |
} |
|
1778 |
||
1779 |
TInt TDrive::IsFileInRom(const TDesC& aFileName,TUint8*& aFileStart) |
|
1780 |
// |
|
1781 |
// Return the start of the file if it is in rom |
|
1782 |
// |
|
1783 |
{ |
|
1784 |
TInt r=CheckMount(); |
|
1785 |
if (r==KErrNone) |
|
1786 |
CurrentMount().IsFileInRom(aFileName,aFileStart); |
|
1787 |
return(r); |
|
1788 |
} |
|
1789 |
||
1790 |
TBool TDrive::IsWriteProtected() |
|
1791 |
// |
|
1792 |
// return true if the media is write protected |
|
1793 |
// |
|
1794 |
{ |
|
1795 |
// __CHECK_DRIVETHREAD(iDriveNumber); |
|
1796 |
TDriveInfo drvInfo; |
|
1797 |
drvInfo.iMediaAtt=0; |
|
1798 |
if(Att() && iFSys) |
|
1799 |
FSys().DriveInfo(drvInfo,DriveNumber()); |
|
1800 |
return((drvInfo.iMediaAtt&KMediaAttWriteProtected)!=0); |
|
1801 |
} |
|
1802 |
||
1803 |
||
1804 |
||
1805 |
||
1806 |
/** |
|
1807 |
Checks whether any resource that could write to disk is open on |
|
1808 |
the current mount. |
|
1809 |
||
1810 |
@return True, if a resource that could write to disk is open on |
|
1811 |
the current mount, false otherwise. |
|
1812 |
*/ |
|
1813 |
EXPORT_C TBool TDrive::IsWriteableResource() const |
|
1814 |
{ |
|
1815 |
// __CHECK_DRIVETHREAD(iDriveNumber); |
|
1816 |
if(iCurrentMount==NULL) |
|
1817 |
return(EFalse); |
|
1818 |
if(iCurrentMount->LockStatus()>0) |
|
1819 |
{ |
|
1820 |
// check format subsessions |
|
1821 |
Formats->Lock(); |
|
1822 |
TInt count=Formats->Count(); |
|
1823 |
while(count--) |
|
1824 |
{ |
|
1825 |
CFormatCB* format=(CFormatCB*)(*Formats)[count]; |
|
1826 |
if(&format->Mount()==iCurrentMount) |
|
1827 |
{ |
|
1828 |
Formats->Unlock(); |
|
1829 |
return(ETrue); |
|
1830 |
} |
|
1831 |
} |
|
1832 |
Formats->Unlock(); |
|
1833 |
// check raw disk subsessions |
|
1834 |
RawDisks->Lock(); |
|
1835 |
count=RawDisks->Count(); |
|
1836 |
while(count--) |
|
1837 |
{ |
|
1838 |
CRawDiskCB* rawDisk=(CRawDiskCB*)(*RawDisks)[count]; |
|
1839 |
if(&rawDisk->Mount()==iCurrentMount && !rawDisk->IsWriteProtected()) |
|
1840 |
{ |
|
1841 |
Formats->Unlock(); |
|
1842 |
return(ETrue); |
|
1843 |
} |
|
1844 |
} |
|
1845 |
Formats->Unlock(); |
|
1846 |
} |
|
1847 |
else if(iCurrentMount->LockStatus()<0) |
|
1848 |
{ |
|
1849 |
// check file share subsessions |
|
1850 |
FileShares->Lock(); |
|
1851 |
TInt count=FileShares->Count(); |
|
1852 |
while(count--) |
|
1853 |
{ |
|
1854 |
CFileShare* fileShare=(CFileShare*)(*FileShares)[count]; |
|
1855 |
if (&fileShare->File().Mount()==iCurrentMount && ((fileShare->iMode&EFileWrite)!=0)) |
|
1856 |
{ |
|
1857 |
FileShares->Unlock(); |
|
1858 |
return(ETrue); |
|
1859 |
} |
|
1860 |
} |
|
1861 |
FileShares->Unlock(); |
|
1862 |
} |
|
1863 |
return(EFalse); |
|
1864 |
} |
|
1865 |
||
1866 |
||
1867 |
||
1868 |
||
1869 |
/** |
|
1870 |
Tests whether the current function can cause a write to disk. |
|
1871 |
||
1872 |
@return True, if the current function can cause a write to disk, |
|
1873 |
false otherwise. |
|
1874 |
*/ |
|
1875 |
EXPORT_C TBool TDrive::IsCurrentWriteFunction() const |
|
1876 |
{ |
|
1877 |
// __CHECK_DRIVETHREAD(iDriveNumber); |
|
1878 |
CDriveThread* pT=NULL; |
|
1879 |
TInt r=FsThreadManager::GetDriveThread(iDriveNumber, &pT); |
|
1880 |
__ASSERT_ALWAYS(r==KErrNone && pT,Fault(EDriveCurrentWriteFunction)); |
|
1881 |
return(pT->IsRequestWriteable()); |
|
1882 |
} |
|
1883 |
||
1884 |
||
1885 |
||
1886 |
||
1887 |
TInt TDrive::ForceRemountDrive(const TDesC8* aMountInfo,TInt aMountInfoMessageHandle,TUint aFlags) |
|
1888 |
// |
|
1889 |
// Force a remount of the drive |
|
1890 |
// |
|
1891 |
{ |
|
1892 |
__PRINT(_L("TDrive::ForceRemountDrive")); |
|
1893 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
1894 |
if(iFSys==NULL) |
|
1895 |
return(KErrNotReady); |
|
1896 |
TInt r; |
|
1897 |
CMountCB* pM=NULL; |
|
257 | 1898 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber()); |
0 | 1899 |
TRAP(r,pM=FSys().NewMountL()); |
257 | 1900 |
TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM); |
0 | 1901 |
if(r!=KErrNone) |
1902 |
return(r); |
|
1903 |
pM->SetDrive(this); |
|
257 | 1904 |
|
1905 |
TRACE4(UTF::EBorder, UTraceModuleFileSys::ECMountCBForceRemountDrive, EF32TraceUidFileSys, |
|
1906 |
DriveNumber(), aMountInfo, aMountInfoMessageHandle, aFlags); |
|
0 | 1907 |
r=pM->ForceRemountDrive(aMountInfo,aMountInfoMessageHandle,aFlags); |
257 | 1908 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBForceRemountDriveRet, EF32TraceUidFileSys, r); |
1909 |
||
0 | 1910 |
pM->Close(); |
1911 |
return(r); |
|
1912 |
} |
|
257 | 1913 |
|
0 | 1914 |
TBool TDrive::IsExtensionMounted(CProxyDriveFactory* aFactory) |
1915 |
// |
|
1916 |
// return ETrue if extension mounted on the drive |
|
1917 |
// |
|
1918 |
{ |
|
1919 |
for(TInt i=0;i<iExtInfo.iCount;++i) |
|
1920 |
{ |
|
1921 |
if(iExtInfo.iInfo[i].iFactory==aFactory) |
|
1922 |
return(ETrue); |
|
1923 |
} |
|
1924 |
return(EFalse); |
|
1925 |
} |
|
257 | 1926 |
|
0 | 1927 |
TInt TDrive::MountExtension(CProxyDriveFactory* aFactory,TBool aIsPrimary) |
1928 |
// |
|
1929 |
// Mount an extension |
|
1930 |
// |
|
1931 |
{ |
|
1932 |
__PRINT1(_L("TDrive::MountExtension aIsPrimary=%d"),aIsPrimary); |
|
1933 |
if(aIsPrimary) |
|
1934 |
{ |
|
1935 |
__CHECK_MAINTHREAD(); |
|
1936 |
// primary extension mounted before file system since it must be present |
|
1937 |
// for successful mount |
|
1938 |
__ASSERT_ALWAYS(!iFSys,Fault(EMountExtensionFSys)); |
|
1939 |
if(iExtInfo.iCount!=0) |
|
1940 |
return(KErrAccessDenied); |
|
1941 |
iExtInfo.iInfo[iExtInfo.iCount].iFactory=aFactory; |
|
1942 |
iExtInfo.iInfo[iExtInfo.iCount++].iIsPrimary=ETrue; |
|
1943 |
return(KErrNone); |
|
1944 |
} |
|
1945 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
1946 |
// must be a secondary extension |
|
1947 |
if(iFSys==NULL) |
|
1948 |
return(KErrNotReady); |
|
1949 |
TBool extSupported = iFSys->IsExtensionSupported(); |
|
257 | 1950 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECFileSystemIsExtensionSupported, EF32TraceUidFileSys, extSupported); |
0 | 1951 |
if(!extSupported) |
1952 |
return(KErrNotSupported); |
|
1953 |
if(IsExtensionMounted(aFactory)) |
|
1954 |
return(KErrAlreadyExists); |
|
1955 |
if(iCurrentMount && (CurrentMount().LockStatus()!=0 || Mount().Count()>1)) |
|
1956 |
return(KErrInUse); |
|
1957 |
if(iExtInfo.iCount>=KMaxExtensionCount) |
|
1958 |
return(KErrAccessDenied); |
|
1959 |
iExtInfo.iInfo[iExtInfo.iCount].iFactory=aFactory; |
|
1960 |
iExtInfo.iInfo[iExtInfo.iCount++].iIsPrimary=EFalse; |
|
1961 |
// now dismount and mount so that the extension incorporated |
|
1962 |
Dismount(); |
|
1963 |
TInt r=CheckMount(); |
|
1964 |
// if mount fails then remove the secondary extension |
|
1965 |
if(r!=KErrNone) |
|
1966 |
{ |
|
1967 |
--iExtInfo.iCount; |
|
1968 |
__ASSERT_DEBUG(iExtInfo.iCount>=0,Fault(EExtensionInfoCount0)); |
|
1969 |
} |
|
1970 |
return(r); |
|
1971 |
} |
|
1972 |
||
1973 |
TInt TDrive::DismountExtension(CProxyDriveFactory* aFactory, TBool /*aIsPrimary*/) |
|
1974 |
// |
|
1975 |
// Dismount an extension |
|
1976 |
// |
|
1977 |
{ |
|
1978 |
__PRINT(_L("TDrive::DismountExtension")); |
|
1979 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
1980 |
||
1981 |
// Empty closed file queue |
|
1982 |
TClosedFileUtils::Remove(DriveNumber()); |
|
1983 |
||
1984 |
if(iExtInfo.iCount==0) |
|
1985 |
return(KErrNotFound); |
|
1986 |
if(iCurrentMount && (CurrentMount().LockStatus()!=0 || Mount().Count()>1)) |
|
1987 |
return(KErrInUse); |
|
1988 |
for(TInt i=0;i<iExtInfo.iCount;++i) |
|
1989 |
{ |
|
1990 |
if(iExtInfo.iInfo[i].iFactory==aFactory) |
|
1991 |
{ |
|
1992 |
// cannot dismount a primary extension without dismounting the file system |
|
1993 |
if(i==0 && iExtInfo.iInfo[i].iIsPrimary) |
|
1994 |
return(KErrAccessDenied); |
|
1995 |
// slide any remaining extensions down |
|
1996 |
for(TInt j=i+1;j<iExtInfo.iCount;++j) |
|
1997 |
iExtInfo.iInfo[j-1].iFactory=iExtInfo.iInfo[j].iFactory; |
|
1998 |
iExtInfo.iCount--; |
|
1999 |
__ASSERT_DEBUG(iExtInfo.iCount>=0,Fault(EExtensionInfoCount1)); |
|
2000 |
Dismount(); |
|
2001 |
return(KErrNone); |
|
2002 |
} |
|
2003 |
} |
|
2004 |
return(KErrNotFound); |
|
2005 |
} |
|
2006 |
||
2007 |
TInt TDrive::ExtensionName(TDes& aExtensionName,TInt aPos) |
|
2008 |
// |
|
2009 |
// Return the extension name |
|
2010 |
// |
|
2011 |
{ |
|
2012 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
2013 |
||
2014 |
if(iFSys==NULL) |
|
2015 |
return(KErrNotReady); |
|
2016 |
||
2017 |
if(aPos<iExtInfo.iCount) |
|
2018 |
{ |
|
2019 |
aExtensionName=iExtInfo.iInfo[aPos].iFactory->Name(); |
|
2020 |
return(KErrNone); |
|
2021 |
} |
|
2022 |
return(KErrNotFound); |
|
2023 |
} |
|
2024 |
||
2025 |
#if defined(_LOCKABLE_MEDIA) |
|
2026 |
||
2027 |
TInt TDrive::LockDevice(TMediaPassword& aOld,TMediaPassword& aNew,TBool aStore) |
|
2028 |
// |
|
2029 |
// Lock media device |
|
2030 |
// |
|
2031 |
{ |
|
2032 |
__PRINT(_L("TDrive::LockDevice")); |
|
2033 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
2034 |
if(iFSys==NULL) |
|
2035 |
return(KErrNotReady); |
|
2036 |
TInt r; |
|
2037 |
CMountCB* pM=NULL; |
|
257 | 2038 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber()); |
0 | 2039 |
TRAP(r,pM=FSys().NewMountL()); |
257 | 2040 |
TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM); |
0 | 2041 |
if(r!=KErrNone) |
2042 |
return(r); |
|
2043 |
pM->SetDrive(this); |
|
2044 |
||
257 | 2045 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECMountCBLock, EF32TraceUidFileSys, DriveNumber(), aStore); |
0 | 2046 |
r=pM->Lock(aOld,aNew,aStore); |
257 | 2047 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBLockRet, EF32TraceUidFileSys, r); |
2048 |
||
0 | 2049 |
pM->Close(); |
2050 |
return(r); |
|
2051 |
} |
|
2052 |
||
2053 |
TInt TDrive::UnlockDevice(TMediaPassword& aPassword,TBool aStore) |
|
2054 |
// |
|
2055 |
// Unlock media device |
|
2056 |
// |
|
2057 |
{ |
|
2058 |
__PRINT(_L("TDrive::UnlockDevice")); |
|
2059 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
2060 |
if(iFSys==NULL) |
|
2061 |
return(KErrNotReady); |
|
2062 |
TInt r; |
|
2063 |
CMountCB* pM=NULL; |
|
257 | 2064 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber()); |
0 | 2065 |
TRAP(r,pM=FSys().NewMountL()); |
257 | 2066 |
TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM); |
0 | 2067 |
if(r!=KErrNone) |
2068 |
return(r); |
|
2069 |
||
2070 |
// reset mount failure count - which is likely to be non-zero if drive is locked |
|
2071 |
iMountFailures = 0; |
|
2072 |
||
2073 |
pM->SetDrive(this); |
|
2074 |
||
257 | 2075 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECMountCBUnlock, EF32TraceUidFileSys, DriveNumber(), aStore); |
0 | 2076 |
r=pM->Unlock(aPassword,aStore); |
257 | 2077 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBUnlockRet, EF32TraceUidFileSys, r); |
2078 |
||
0 | 2079 |
pM->Close(); |
2080 |
return(r); |
|
2081 |
} |
|
2082 |
||
2083 |
TInt TDrive::ClearDevicePassword(TMediaPassword& aPassword) |
|
2084 |
// |
|
2085 |
// Clear password of media device |
|
2086 |
// |
|
2087 |
{ |
|
2088 |
__PRINT(_L("TDrive::ClearDevicePassword")); |
|
2089 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
2090 |
if(iFSys==NULL) |
|
2091 |
return(KErrNotReady); |
|
2092 |
TInt r; |
|
2093 |
CMountCB* pM=NULL; |
|
257 | 2094 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber()); |
0 | 2095 |
TRAP(r,pM=FSys().NewMountL()); |
257 | 2096 |
TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM); |
0 | 2097 |
if(r!=KErrNone) |
2098 |
return(r); |
|
2099 |
pM->SetDrive(this); |
|
2100 |
||
2101 |
// ClearPassword() will only work if the card is already unlocked. |
|
2102 |
// If the stack powers down, the card will become locked, so now that TBusLocalDrive::Caps() |
|
2103 |
// no longer powers up ths stack, we need to unlock the card first - but ignore the error as |
|
2104 |
// the stack may unlock from the password store. |
|
2105 |
TDriveInfo info; |
|
2106 |
DriveInfo(info); |
|
2107 |
if (info.iMediaAtt & KMediaAttLocked) |
|
2108 |
UnlockDevice(aPassword, EFalse); |
|
2109 |
||
257 | 2110 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBClearPassword, EF32TraceUidFileSys, DriveNumber()); |
0 | 2111 |
r=pM->ClearPassword(aPassword); |
257 | 2112 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBClearPasswordRet, EF32TraceUidFileSys, r); |
2113 |
||
0 | 2114 |
pM->Close(); |
2115 |
return(r); |
|
2116 |
} |
|
2117 |
||
2118 |
TInt TDrive::EraseDevicePassword() |
|
2119 |
// |
|
2120 |
// Erase password from the media device |
|
2121 |
// |
|
2122 |
{ |
|
2123 |
__PRINT(_L("TDrive::EraseDevicePassword")); |
|
2124 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
2125 |
if(iFSys==NULL) |
|
2126 |
return(KErrNotReady); |
|
2127 |
TInt r; |
|
2128 |
CMountCB* pM=NULL; |
|
257 | 2129 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountL, EF32TraceUidFileSys, &FSys(), DriveNumber()); |
0 | 2130 |
TRAP(r,pM=FSys().NewMountL()); |
257 | 2131 |
TRACERET2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewMountLRet, EF32TraceUidFileSys, r, pM); |
0 | 2132 |
if(r!=KErrNone) |
2133 |
return(r); |
|
2134 |
pM->SetDrive(this); |
|
2135 |
||
257 | 2136 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBErasePassword, EF32TraceUidFileSys, DriveNumber()); |
0 | 2137 |
r=pM->ErasePassword(); |
257 | 2138 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBErasePasswordRet, EF32TraceUidFileSys, r); |
2139 |
||
0 | 2140 |
pM->Close(); |
2141 |
return(r); |
|
2142 |
} |
|
2143 |
||
2144 |
#else |
|
2145 |
||
2146 |
TInt TDrive::LockDevice(TMediaPassword& /*aOld*/,TMediaPassword& /*aNew*/,TBool /*aStore*/) |
|
2147 |
// |
|
2148 |
// Lock media device |
|
2149 |
// |
|
2150 |
{ |
|
2151 |
return(KErrNotSupported); |
|
2152 |
} |
|
2153 |
||
2154 |
TInt TDrive::UnlockDevice(TMediaPassword& /*aPassword*/,TBool /*aStore*/) |
|
2155 |
// |
|
2156 |
// Unlock media device |
|
2157 |
// |
|
2158 |
{ |
|
2159 |
return(KErrNotSupported); |
|
2160 |
} |
|
2161 |
||
2162 |
TInt TDrive::ClearDevicePassword(TMediaPassword& /*aPassword*/) |
|
2163 |
// |
|
2164 |
// Clear password of media device |
|
2165 |
// |
|
2166 |
{ |
|
2167 |
return(KErrNotSupported); |
|
2168 |
} |
|
2169 |
||
2170 |
TInt TDrive::EraseDevicePassword(TMediaPassword& /*aPassword*/) |
|
2171 |
// |
|
2172 |
// Clear password of media device |
|
2173 |
// |
|
2174 |
{ |
|
2175 |
return(KErrNotSupported); |
|
2176 |
} |
|
2177 |
||
2178 |
#endif |
|
2179 |
||
2180 |
||
2181 |
||
2182 |
||
2183 |
/** |
|
2184 |
Gets the current notification state, which indicates whether the client |
|
2185 |
is notified of any read or write failures. |
|
2186 |
||
2187 |
The notification status is a property of the current session with |
|
2188 |
the file server, the value of which is stored in CSessionFs::iNotifyUser. |
|
2189 |
If set to ETrue, the client will receive notifications from the file system. |
|
2190 |
||
2191 |
Called by CMountCB::GetNotifyUser(). |
|
2192 |
||
2193 |
@return True, if the client receives notifications from the file system, |
|
2194 |
false otherwise. |
|
2195 |
||
2196 |
@see CMountCB |
|
2197 |
*/ |
|
2198 |
EXPORT_C TBool TDrive::GetNotifyUser() |
|
2199 |
{ |
|
2200 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
2201 |
if(iDriveFlags & ENotifyOff) |
|
2202 |
return(EFalse); |
|
2203 |
else |
|
2204 |
{ |
|
2205 |
CDriveThread* pT=NULL; |
|
2206 |
||
2207 |
const TInt r=FsThreadManager::GetDriveThread(iDriveNumber,&pT); |
|
2208 |
||
2209 |
//-- if this drive is synchronous, i.e. all requests are processed in the main FS thread, |
|
2210 |
//-- pretend that user notifications are turned off to avoid panic in the assert below. |
|
2211 |
//-- for synch. drives pT will always be NULL and it's not possible to obtain CSessionFs by drive number. |
|
2212 |
if(r == KErrAccessDenied) |
|
2213 |
return EFalse; |
|
2214 |
||
2215 |
__ASSERT_ALWAYS(r==KErrNone && pT,Fault(EDriveGetNotifyUser)); |
|
2216 |
return(pT->IsSessionNotifyUser()); |
|
2217 |
} |
|
2218 |
} |
|
2219 |
||
2220 |
||
2221 |
||
2222 |
||
2223 |
/** |
|
268
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2224 |
Gracefully dismounts the current mount. This is method is called from outside, so do some finalisation work on mount. |
0 | 2225 |
After calling this function there is no current mount on the drive. |
268
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2226 |
|
0 | 2227 |
*/ |
2228 |
EXPORT_C void TDrive::Dismount() |
|
2229 |
{ |
|
2230 |
__PRINT1(_L("TDrive::Dismount() iCurrentMount:0x%x"),iCurrentMount); |
|
2231 |
||
2232 |
iMountFailures = 0; |
|
2233 |
if (!iCurrentMount) |
|
2234 |
return; |
|
2235 |
||
268
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2236 |
//-- try to do the best flushing file caches |
0 | 2237 |
TRAP_IGNORE(FlushCachedFileInfoL()); |
2238 |
||
2239 |
//-- try our best to finalise the mount (the mount can decide to do some job during finalisation, e.g. write some data) |
|
268
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2240 |
//-- finalise the mount in RO mode, we are dismounting the FS anyway |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2241 |
TRAP_IGNORE(iCurrentMount->FinaliseMountL(RFs::EFinal_RO)); |
0 | 2242 |
|
2243 |
DoDismount(); |
|
2244 |
} |
|
2245 |
||
2246 |
||
2247 |
||
2248 |
||
2249 |
/** |
|
268
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2250 |
Dismounts the current mount by force. |
0 | 2251 |
*/ |
2252 |
void TDrive::ForceDismount() |
|
2253 |
{ |
|
2254 |
__PRINT1(_L("TDrive::ForceDismount() iCurrentMount:0x%x"),iCurrentMount); |
|
2255 |
||
2256 |
iMountFailures = 0; |
|
2257 |
||
2258 |
if(!iCurrentMount) |
|
2259 |
return; |
|
2260 |
||
2261 |
TRAP_IGNORE(FlushCachedFileInfoL()); |
|
268
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2262 |
|
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2263 |
//-- try our best to finalise the mount (the mount can decide to do some job during finalisation, e.g. write some data) |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2264 |
//-- finalise the mount in RO mode, we are dismounting the FS anyway |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2265 |
TRAP_IGNORE(iCurrentMount->FinaliseMountL(RFs::EFinal_RO)); |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2266 |
|
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2267 |
//-- mark the mount as 'Dismounted'; this invalidates all object handles until the mount is successfully "remounted". |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2268 |
//-- if there are still some objects opened on this mount, CMountCB::Close() won't destroy it until all objects are closed. |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2269 |
iCurrentMount->SetDismounted(); |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
2270 |
|
0 | 2271 |
DoDismount(); |
2272 |
} |
|
2273 |
||
2274 |
/** |
|
2275 |
An internal method. Dismounts and closes a current mount. |
|
2276 |
This method must not involve writing data to the media, because it could have beeen physically changed before. |
|
2277 |
Called only from TDrive::CheckMount(). |
|
2278 |
*/ |
|
2279 |
void TDrive::DoDismount() |
|
2280 |
{ |
|
2281 |
__PRINT1(_L("TDrive::DoDismount() iCurrentMount:0x%x"),iCurrentMount); |
|
2282 |
||
2283 |
iMountFailures = 0; |
|
2284 |
||
2285 |
if (!iCurrentMount) |
|
2286 |
return; |
|
2287 |
||
257 | 2288 |
TRACE1(UTF::EBorder, UTraceModuleFileSys::ECMountCBDismounted, EF32TraceUidFileSys, DriveNumber()); |
0 | 2289 |
iCurrentMount->Dismounted(); |
257 | 2290 |
TRACE0(UTF::EBorder, UTraceModuleFileSys::ECMountCBDismountedRet, EF32TraceUidFileSys); |
2291 |
||
0 | 2292 |
iCurrentMount->Close(); |
2293 |
iCurrentMount=NULL; |
|
2294 |
} |
|
2295 |
||
2296 |
||
2297 |
/** |
|
2298 |
Return the number of active mounts associated with this drive. |
|
2299 |
(inactive mounts are those that have been forcibly dismounted) |
|
2300 |
*/ |
|
2301 |
TInt TDrive::ActiveMounts() const |
|
2302 |
{ |
|
2303 |
TInt activeMounts = 0; |
|
2304 |
||
2305 |
TInt idx = Mount().Count(); |
|
2306 |
while(idx--) |
|
2307 |
{ |
|
2308 |
if(((CMountCB*)Mount()[idx])->IsDismounted()) |
|
2309 |
{ |
|
2310 |
activeMounts++; |
|
2311 |
} |
|
2312 |
} |
|
2313 |
||
2314 |
__PRINT1(_L("TDrive::ActiveMounts = %d"), activeMounts); |
|
2315 |
return activeMounts; |
|
2316 |
} |
|
2317 |
||
2318 |
||
2319 |
||
2320 |
||
2321 |
/** |
|
2322 |
Reactivate any disactive mounts on the drive following a dismount. |
|
2323 |
(inactive mounts are those that have been foribly dismounted) |
|
2324 |
*/ |
|
2325 |
void TDrive::ReactivateMounts() |
|
2326 |
{ |
|
2327 |
__PRINT(_L("TDrive::ReactivateMounts")); |
|
2328 |
||
2329 |
TInt idx = Mount().Count(); |
|
2330 |
while(idx--) |
|
2331 |
{ |
|
2332 |
((CMountCB*)Mount()[idx])->SetDismounted(EFalse); |
|
2333 |
} |
|
2334 |
} |
|
2335 |
||
2336 |
||
2337 |
||
2338 |
||
2339 |
/** |
|
2340 |
Increments the drive dismount lock. This defers dismount |
|
2341 |
of a file system until all clients have notified that it |
|
2342 |
is safe to do so. |
|
2343 |
||
2344 |
@see RFs::NotifyDismount |
|
2345 |
*/ |
|
2346 |
void TDrive::DismountLock() |
|
2347 |
{ iDismountLock++; } |
|
2348 |
||
2349 |
||
2350 |
||
2351 |
||
2352 |
/** |
|
2353 |
Decrements the drive dismount lock. When the lock count |
|
2354 |
reaches zero, the file system may be unmounted |
|
2355 |
||
2356 |
@see RFs::AllowDismount |
|
2357 |
@return The new lock count |
|
2358 |
*/ |
|
2359 |
TInt TDrive::DismountUnlock() |
|
2360 |
{ |
|
2361 |
return(--iDismountLock); |
|
2362 |
} |
|
2363 |
||
2364 |
||
2365 |
||
2366 |
||
2367 |
/** |
|
2368 |
Return the state of the dismount lock. |
|
2369 |
*/ |
|
2370 |
TBool TDrive::DismountLocked() const |
|
2371 |
{ return(iDismountLock); } |
|
2372 |
||
2373 |
||
2374 |
||
2375 |
||
2376 |
/** |
|
2377 |
Pending flag - set while waiting for clients to accept the dismount |
|
2378 |
*/ |
|
2379 |
void TDrive::SetDismountDeferred(TBool aPending) |
|
2380 |
{ |
|
2381 |
if(aPending) |
|
2382 |
iDriveFlags |= EDismountDeferred; |
|
2383 |
else |
|
2384 |
iDriveFlags &= ~EDismountDeferred; |
|
2385 |
} |
|
2386 |
||
2387 |
||
257 | 2388 |
|
0 | 2389 |
TInt TDrive::ControlIO(const RMessagePtr2& aMessage,TInt aCommand,TAny* aParam1,TAny* aParam2) |
2390 |
// |
|
2391 |
// General purpose test interface - .FSY specific. |
|
2392 |
// |
|
2393 |
{ |
|
2394 |
TInt r=CheckMount(); |
|
2395 |
if(r==KErrNone || (r==KErrInUse && iReason==KErrNone)) |
|
2396 |
{ |
|
2397 |
TRACETHREADID(aMessage); |
|
257 | 2398 |
TRACE5(UTF::EBorder, UTraceModuleFileSys::ECMountCBControlIO, EF32TraceUidFileSys, |
2399 |
DriveNumber(), aCommand, aParam1, aParam2, I64LOW(threadId)); |
|
0 | 2400 |
r=CurrentMount().ControlIO(aMessage,aCommand,aParam1,aParam2); |
257 | 2401 |
TRACERET1(UTF::EBorder, UTraceModuleFileSys::ECMountCBControlIORet, EF32TraceUidFileSys, r); |
0 | 2402 |
} |
2403 |
return(r); |
|
2404 |
} |
|
2405 |
||
2406 |
||
2407 |
||
2408 |
||
2409 |
/** |
|
2410 |
Gets the drive attributes |
|
2411 |
||
2412 |
@return The drive attributes. |
|
2413 |
*/ |
|
2414 |
EXPORT_C TUint TDrive::Att() |
|
2415 |
{ |
|
2416 |
TUint a=iAtt; |
|
2417 |
return(a); |
|
2418 |
} |
|
2419 |
||
2420 |
void TDrive::SetAtt(TUint aValue) |
|
2421 |
// |
|
2422 |
// set drive attributes |
|
2423 |
// |
|
2424 |
{ |
|
2425 |
iAtt=aValue; |
|
2426 |
} |
|
2427 |
||
2428 |
EXPORT_C TBool TDrive::IsDriveThread() const |
|
2429 |
// |
|
2430 |
// Return ETrue if the current thread id is the same as that of the drive's drive thread |
|
2431 |
// |
|
2432 |
{ |
|
2433 |
return(FsThreadManager::IsDriveThread(iDriveNumber,ETrue)); |
|
2434 |
} |
|
2435 |
||
2436 |
EXPORT_C TBool TDrive::IsMainThread() const |
|
2437 |
// |
|
2438 |
// Reture ETrue if the current thread id is the same as that of the main file server thread |
|
2439 |
// |
|
2440 |
{ |
|
2441 |
return(FsThreadManager::IsMainThread()); |
|
2442 |
} |
|
2443 |
||
2444 |
EXPORT_C void TDrive::DriveFault(TBool aDriveError) const |
|
2445 |
// |
|
2446 |
// |
|
2447 |
// |
|
2448 |
{ |
|
2449 |
if(aDriveError) |
|
2450 |
::Fault(EFsDriveThreadError); |
|
2451 |
else |
|
2452 |
::Fault(EFsMainThreadError); |
|
2453 |
} |
|
2454 |
||
2455 |
TInt TDrive::ClampFile(const TDesC& aName, TAny* aHandle) |
|
2456 |
// |
|
2457 |
// Attempt to clamp file |
|
2458 |
// |
|
2459 |
{ |
|
2460 |
CMountCB* mount = (CMountCB*)&(CurrentMount()); |
|
2461 |
TInt driveNo = DriveNumber(); |
|
2462 |
return(mount->ClampFile(driveNo,aName,aHandle)); |
|
2463 |
} |
|
2464 |
||
2465 |
||
2466 |
TInt TDrive::UnclampFile(CMountCB* aMount, RFileClamp* aHandle) |
|
2467 |
// |
|
2468 |
// Attempt to unclamp file |
|
2469 |
// |
|
2470 |
{ |
|
2471 |
return(aMount->UnclampFile(aHandle)); |
|
2472 |
} |
|
2473 |
||
2474 |
||
2475 |
TInt TDrive::ClampsOnDrive() |
|
2476 |
// |
|
2477 |
// Returns the number of clamps on this drive |
|
2478 |
// |
|
2479 |
{ |
|
2480 |
Lock(); |
|
2481 |
TInt clamps = IsMounted()?((CMountCB*)&(CurrentMount()))->NoOfClamps():0; |
|
2482 |
UnLock(); |
|
2483 |
return (clamps); |
|
2484 |
} |
|
2485 |
||
2486 |
||
2487 |
||
2488 |
void TDrive::SetClampFlag(TBool aClamped) |
|
2489 |
// |
|
2490 |
// Indicate if any files are clamped |
|
2491 |
// |
|
2492 |
{ |
|
2493 |
if(aClamped) |
|
2494 |
iDriveFlags |= EClampPresent; |
|
2495 |
else |
|
2496 |
iDriveFlags &= ~EClampPresent; |
|
2497 |
} |
|
2498 |
||
2499 |
||
2500 |
TBool TDrive::ClampFlag() |
|
2501 |
// |
|
2502 |
// Report if any files are clamped |
|
2503 |
// |
|
2504 |
{ return(iDriveFlags & EClampPresent); } |
|
2505 |
||
2506 |
||
2507 |
||
2508 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
2509 |
TInt TDrive::ClearDeferredDismount() |
|
2510 |
// debug-only function for testing |
|
2511 |
{ |
|
2512 |
Lock(); |
|
2513 |
FsNotify::HandleDismount(EFsDismountRegisterClient, DriveNumber(), ETrue, KErrNone); |
|
2514 |
SetDismountDeferred(EFalse); |
|
2515 |
UnLock(); |
|
2516 |
return KErrNone; |
|
2517 |
} |
|
2518 |
#endif |
|
2519 |
||
2520 |
||
2521 |
TInt TDrive::DismountProxyDrive() |
|
2522 |
// |
|
2523 |
// Dismount a proxy drive |
|
2524 |
// |
|
2525 |
{ |
|
2526 |
__PRINT(_L("TDrive::DismountProxyDrive")); |
|
2527 |
__CHECK_DRIVETHREAD(iDriveNumber); |
|
2528 |
||
2529 |
if (!IsProxyDrive(iDriveNumber) || LocalDrives::DriveNumberToLocalDriveNumber(iDriveNumber) == KDriveInvalid) |
|
2530 |
return KErrArgument; |
|
2531 |
||
2532 |
if(iCurrentMount) |
|
2533 |
return(KErrInUse); |
|
2534 |
||
2535 |
||
2536 |
// Prevent ALL inactive mounts from EVER being remounted as they MAY (& probably do) point to |
|
2537 |
// this proxy-drive which we are about to delete.... |
|
2538 |
// NB We could try to find out which mounts actually use this particular proxy-drive, but that's |
|
2539 |
// a bit tricky to determine if there are extensions present as CMountCB::ProxyDrive() will only |
|
2540 |
// return the first proxy drive in the chain. |
|
2541 |
TInt mCount=Mount().Count(); |
|
2542 |
TInt u=(Mount().UniqueID()<<16); |
|
2543 |
for (TInt i=0;i<mCount;i++) |
|
2544 |
{ |
|
2545 |
CMountCB* pM=(CMountCB*)Mount().At(u|i); |
|
2546 |
pM->SetProxyDriveDismounted(); |
|
2547 |
} |
|
2548 |
||
2549 |
FsThreadManager::LockDrive(iDriveNumber); |
|
2550 |
// Proxy drives are responsible for managing the drive threads... |
|
2551 |
FsThreadManager::CloseDrive(iDriveNumber); |
|
2552 |
LocalDrives::ClearProxyDriveMapping(iDriveNumber); |
|
2553 |
FsThreadManager::UnlockDrive(iDriveNumber); |
|
2554 |
||
2555 |
return KErrNone; |
|
2556 |
} |
|
2557 |
||
2558 |
//---------------------------------------------------------------------------- |
|
2559 |
/** |
|
2560 |
Complete, remove and delete notification requests |
|
2561 |
@param aCompletionCode completion code for some notifications |
|
2562 |
*/ |
|
2563 |
void TDrive::DoCompleteDismountNotify(TInt aCompletionCode) |
|
2564 |
{ |
|
2565 |
FsNotify::HandleDismount(EFsDismountRegisterClient, iDriveNumber, ETrue, KErrNone); |
|
2566 |
FsNotify::HandleDismount(EFsDismountNotifyClients, iDriveNumber, ETrue, aCompletionCode); |
|
2567 |
FsNotify::HandleDismount(EFsDismountForceDismount, iDriveNumber, ETrue, aCompletionCode); |
|
2568 |
} |
|
2569 |
||
2570 |
//---------------------------------------------------------------------------- |
|
2571 |
/** |
|
2572 |
a helper method that allows forced dismounting current mount for volume formatting. |
|
2573 |
*/ |
|
2574 |
TInt TDrive::ForceUnmountFileSystemForFormatting() |
|
2575 |
{ |
|
2576 |
TInt nRes; |
|
2577 |
||
2578 |
//-- check if there are any clamps on this drive |
|
2579 |
nRes = ClampsOnDrive(); |
|
2580 |
if(nRes > 0) |
|
2581 |
return KErrInUse; |
|
2582 |
||
2583 |
//-- purge all dirty data in the files associated with this drive's mount |
|
2584 |
CDriveThread* pT=NULL; |
|
2585 |
nRes = FsThreadManager::GetDriveThread(DriveNumber(), &pT); |
|
2586 |
if(nRes == KErrNone && pT) |
|
2587 |
{ |
|
2588 |
pT->CompleteReadWriteRequests(); |
|
2589 |
} |
|
2590 |
||
2591 |
PurgeDirty(CurrentMount()); |
|
2592 |
||
2593 |
//-- |
|
2594 |
||
2595 |
ForceDismount(); |
|
2596 |
||
2597 |
DoCompleteDismountNotify(KErrDisMounted); //-- complete all dismount notifications |
|
2598 |
||
2599 |
return KErrNone; |
|
2600 |
} |
|
2601 |
||
2602 |
//----------------------------------------------------------------------------- |
|
2603 |
/** |
|
2604 |
Instantiate CFormatCB object for formatting the file ssytem on the given TDrive. |
|
2605 |
||
2606 |
@param aRequest file server request object |
|
2607 |
@param aFmtHandle out: format handle |
|
2608 |
@param aFmtMode format mode |
|
2609 |
@param apLDFormatInfo pointer to legacy parameters structure; NULL means "not used" |
|
2610 |
@param apVolFormatParam pointer to the newparameters structure; NULL means "not used" |
|
2611 |
||
2612 |
@return pointer to the instantiated CFormatCB object. |
|
2613 |
*/ |
|
2614 |
CFormatCB* TDrive::FormatOpenL(CFsRequest* aRequest, TInt& aFmtHandle, TFormatMode aFmtMode, const TLDFormatInfo* apLDFormatInfo, const TVolFormatParam* apVolFormatParam) |
|
2615 |
{ |
|
2616 |
ASSERT(!(apLDFormatInfo && apVolFormatParam)); //-- these parameters are mutually exclusive |
|
2617 |
||
257 | 2618 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFormatL, EF32TraceUidFileSys, &FSys(), DriveNumber()); |
2619 |
||
0 | 2620 |
CFormatCB* pFormat = CurrentMount().NewFormatL(); |
2621 |
||
257 | 2622 |
TRACE2(UTF::EBorder, UTraceModuleFileSys::ECFileSystemNewFormatLRet, EF32TraceUidFileSys, KErrNone, pFormat); |
0 | 2623 |
|
2624 |
Formats->AddL(pFormat, ETrue); |
|
2625 |
pFormat->InitL(this, aFmtMode); |
|
2626 |
||
2627 |
if(aFmtMode & ESpecialFormat) |
|
2628 |
{ |
|
2629 |
if(apLDFormatInfo) |
|
2630 |
{//-- the user has specified formatting parameters as TLDFormatInfo |
|
2631 |
pFormat->SetFormatParameters(apLDFormatInfo); |
|
2632 |
} |
|
2633 |
else if(apVolFormatParam && apVolFormatParam->SomeParamsSet()) |
|
2634 |
{//-- the user has specified formatting parameters as TVolFormatParam |
|
2635 |
TInt nRes = pFormat->SetFormatParameters(apVolFormatParam); |
|
2636 |
User::LeaveIfError(nRes); //-- the particular file system might not support this feature |
|
2637 |
} |
|
2638 |
else |
|
2639 |
{//-- this is a special case, ESpecialFormat is set, but no parameters provided at all; |
|
2640 |
//-- invalidate CFormatCB::iSpecialInfo to make filesystem not to use it |
|
2641 |
pFormat->SetFormatParameters((TLDFormatInfo*)NULL); |
|
2642 |
} |
|
2643 |
} |
|
2644 |
||
2645 |
||
2646 |
// modify resource counter after initialised to ensure correct cleanup |
|
2647 |
AddDiskAccess(CurrentMount()); |
|
2648 |
aFmtHandle = aRequest->Session()->Handles().AddL(pFormat, ETrue); |
|
2649 |
||
2650 |
return pFormat; |
|
2651 |
} |
|
2652 |
||
2653 |
||
2654 |
||
2655 |
||
2656 |
||
2657 |
EXPORT_C void UNUSED1() {} |
|
2658 |
EXPORT_C void UNUSED2() {} |
|
2659 |
EXPORT_C void UNUSED3() {} |
|
2660 |
||
2661 |
||
2662 |
||
2663 |
||
2664 |
||
2665 |
||
2666 |
||
2667 |
||
2668 |