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