0
|
1 |
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// f32\sfsrv\cl_drive.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "cl_std.h"
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
EXPORT_C TDriveUnit::TDriveUnit(TInt aDrive)
|
|
24 |
/**
|
|
25 |
Constructor taking a drive number.
|
|
26 |
|
|
27 |
@param aDrive The drive number.
|
|
28 |
|
|
29 |
@panic FSCLIENT 0 if aDrive is greater than or equal to KMaxDrives or less than 0.
|
|
30 |
|
|
31 |
@see KMaxDrives
|
|
32 |
*/
|
|
33 |
{
|
|
34 |
__ASSERT_ALWAYS((aDrive>=0 && aDrive<KMaxDrives),Panic(EDriveUnitBadDrive));
|
|
35 |
iDrive=aDrive;
|
|
36 |
}
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
EXPORT_C TDriveUnit::TDriveUnit(const TDesC& aDriveText)
|
|
42 |
/**
|
|
43 |
Constructor taking a drive letter.
|
|
44 |
|
|
45 |
@param aDriveText A descriptor containing text whose first character is
|
|
46 |
the drive letter. Can be upper or lower case. Trailing text
|
|
47 |
is ignored.
|
|
48 |
|
|
49 |
@panic FSCLIENT 1 if the drive letter is invalid, i.e. does not correspond
|
|
50 |
to a drive number.
|
|
51 |
|
|
52 |
@see RFs::CharToDrive
|
|
53 |
*/
|
|
54 |
{
|
|
55 |
__ASSERT_ALWAYS(RFs::CharToDrive(aDriveText[0],iDrive)==0,Panic(EDriveUnitBadDriveText));
|
|
56 |
}
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
EXPORT_C TDriveUnit& TDriveUnit::operator=(TInt aDrive)
|
|
62 |
/**
|
|
63 |
Assigns the drive number to the drive unit
|
|
64 |
|
|
65 |
@param aDrive The new drive number.
|
|
66 |
|
|
67 |
@return A reference to this drive unit.
|
|
68 |
|
|
69 |
@panic FSCLIENT 0 if aDrive is greater than or equal to KMaxDrives.
|
|
70 |
|
|
71 |
@see KMaxDrives
|
|
72 |
*/
|
|
73 |
{
|
|
74 |
__ASSERT_ALWAYS(aDrive<KMaxDrives,Panic(EDriveUnitBadDrive));
|
|
75 |
iDrive=aDrive;
|
|
76 |
return *this;
|
|
77 |
}
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
EXPORT_C TDriveUnit& TDriveUnit::operator=(const TDesC& aDriveText)
|
|
83 |
/**
|
|
84 |
Assigns a drive letter to the drive unit.
|
|
85 |
|
|
86 |
The letter must be between A and Z or a panic is raised. Any trailing
|
|
87 |
text within the descriptor is ignored.
|
|
88 |
|
|
89 |
@param aDriveText Descriptor containing text whose first character is
|
|
90 |
the drive letter. It can be upper or lower case.
|
|
91 |
|
|
92 |
@return A reference to this drive unit.
|
|
93 |
|
|
94 |
@panic FSCLIENT 1 if the drive letter is invalid, i.e. does not correspond
|
|
95 |
to a drive number.
|
|
96 |
|
|
97 |
@see RFs::CharToDrive
|
|
98 |
*/
|
|
99 |
{
|
|
100 |
__ASSERT_ALWAYS(RFs::CharToDrive(aDriveText[0],iDrive)==0,Panic(EDriveUnitBadDriveText));
|
|
101 |
return *this;
|
|
102 |
}
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
EXPORT_C TDriveName TDriveUnit::Name() const
|
|
108 |
/**
|
|
109 |
Gets the drive unit as text.
|
|
110 |
|
|
111 |
The drive letter is returned with a trailing colon.
|
|
112 |
|
|
113 |
@return The drive letter and a trailing colon.
|
|
114 |
|
|
115 |
@panic FSCLIENT 0 if RFs::DriveToChar() returned an error.
|
|
116 |
*/
|
|
117 |
{
|
|
118 |
TChar driveLetter;
|
|
119 |
TInt r = RFs::DriveToChar(iDrive,driveLetter);
|
|
120 |
__ASSERT_ALWAYS(r == KErrNone, Panic(EDriveUnitBadDrive));
|
|
121 |
TDriveName driveName;
|
|
122 |
driveName.SetLength(2);
|
|
123 |
driveName[0]=(TText)driveLetter;
|
|
124 |
driveName[1]=KDriveDelimiter;
|
|
125 |
return driveName;
|
|
126 |
}
|
|
127 |
|
271
|
128 |
|
|
129 |
|
|
130 |
//-------------------------------------------------------------------------------------------------------------------
|
|
131 |
|
|
132 |
/**
|
|
133 |
internal class of the CFsMountHelper, provides the real implementation, It is not supposed to
|
|
134 |
be instantiated by anyone except CFsMountHelper.
|
|
135 |
*/
|
|
136 |
class TFsMntHelperImpl
|
|
137 |
{
|
|
138 |
friend class CFsMountHelper;
|
|
139 |
|
|
140 |
private:
|
|
141 |
|
|
142 |
TFsMntHelperImpl(RFs& aFs, TInt aDrvNum);
|
|
143 |
|
|
144 |
//------ 1:1 interface to the host CFsMountHelper class
|
|
145 |
void Init();
|
|
146 |
TInt GetMountProperties();
|
|
147 |
TInt MountFileSystem() const;
|
|
148 |
void DismountFileSystem(TRequestStatus& aStat, CFsMountHelper::TFsDismountMode aDismountMode) const;
|
|
149 |
//------
|
|
150 |
|
|
151 |
private:
|
|
152 |
TBool DataValid() const {return iFsName.Length() >0;}
|
|
153 |
TBool operator==(const TFsMntHelperImpl& aRhs) const;
|
|
154 |
|
|
155 |
enum {KPrimExtIdx =0}; //-- index of the primary extension name in the iExtNames array
|
|
156 |
|
|
157 |
const TDesC& FSysName() const {return iFsName;}
|
|
158 |
const TDesC& PrimaryExtName() const {return iExtNames[KPrimExtIdx];}
|
|
159 |
|
|
160 |
/** bits in a error bitmap that indicate some, potentially multiple, API failure reasons */
|
|
161 |
enum TErrorBits
|
|
162 |
{
|
|
163 |
Err_GetFsName = 0x0001, ///< Error when trying to obtain FS name (possible reason: there is no FS at all on this drive)
|
|
164 |
Err_MountFs = 0x0002, ///< Error when mounting the FS. (possible reason: the FS layout on the media is corrupt or not recognised)
|
|
165 |
Err_MountFsPrimExt = 0x0004, ///< Error when mounting the FS with the primary extension
|
|
166 |
Err_MountSecExt = 0x0008, ///< Error when mounting the secondary extension
|
|
167 |
};
|
|
168 |
|
|
169 |
|
|
170 |
void AddErrorBit(TUint32 aFlag) const {ASSERT(aFlag); iErrorBitmap |= aFlag;}
|
|
171 |
|
|
172 |
/** panic codes */
|
|
173 |
enum TPanicCode
|
|
174 |
{
|
|
175 |
ENotInitialised, ///< the instance of the implementation is not created
|
|
176 |
EDrvNumberInvalid,///< invalid drive number provided
|
|
177 |
ENotImplemented ///< the functionality is not implemented
|
|
178 |
};
|
|
179 |
|
|
180 |
void Panic(TPanicCode aPanicCode) const;
|
|
181 |
|
|
182 |
private:
|
|
183 |
RFs& iFs; ///< reference to the file server session
|
|
184 |
TInt iDrvNum; ///< drive number
|
|
185 |
TFSName iFsName; ///< file system name.
|
|
186 |
TFSName iExtNames[KMaxExtensionCount]; ///< [0] is a primary ext. name + up to several secondary ones
|
|
187 |
TBool iDrvSynch; ///< true if the drive is synchronous
|
|
188 |
mutable TUint32 iErrorBitmap; ///< 32 bits indicating API call failures. '1' bit corresponds to some particular reason. See TErrorBits.
|
|
189 |
};
|
|
190 |
|
|
191 |
|
|
192 |
//-------------------------------------------------------------------------------------------------------------------
|
|
193 |
|
|
194 |
void TFsMntHelperImpl::DismountFileSystem(TRequestStatus& aStat, CFsMountHelper::TFsDismountMode aDismountMode) const
|
|
195 |
{
|
|
196 |
if(!this)
|
|
197 |
Panic(ENotInitialised);
|
|
198 |
|
|
199 |
TInt nRes;
|
|
200 |
|
|
201 |
#ifdef _DEBUG
|
|
202 |
//-- consistency check (debug mode only). Check that we are dismounting file system with the same parameters
|
|
203 |
//-- since last GetMountProperties() call
|
|
204 |
TFsMntHelperImpl currSnapshot(iFs, iDrvNum);
|
|
205 |
currSnapshot.GetMountProperties();
|
|
206 |
ASSERT(currSnapshot == *this);
|
|
207 |
|
|
208 |
#endif //_DEBUG
|
|
209 |
|
|
210 |
|
|
211 |
nRes = KErrArgument;
|
|
212 |
TRequestStatus* pStat = &aStat;
|
|
213 |
|
|
214 |
switch(aDismountMode)
|
|
215 |
{
|
|
216 |
case CFsMountHelper::ENormal:
|
|
217 |
//-- normal graceful dismounting. Will fail with KErrInUse if there are any opened objects, like files, directories etc.
|
|
218 |
//-- aStat is completed with the API return code.
|
|
219 |
nRes = iFs.DismountFileSystem(iFsName, iDrvNum);
|
|
220 |
User::RequestComplete(pStat, nRes);
|
|
221 |
break;
|
|
222 |
|
|
223 |
case CFsMountHelper::EForceImmediate:
|
|
224 |
//-- immediate forced dismount. Don't pay attention to any opened objects. All handles will become invalid.
|
|
225 |
//-- The user should wait for aStat completion. Though it is very likely that it is completed immediately.
|
|
226 |
iFs.NotifyDismount(iDrvNum, aStat, EFsDismountForceDismount);
|
|
227 |
break;
|
|
228 |
|
|
229 |
|
|
230 |
case CFsMountHelper::ENotifyClients:
|
|
231 |
//-- attempt to dismount FS with notifying any interested clients.
|
|
232 |
iFs.NotifyDismount(iDrvNum, aStat, EFsDismountNotifyClients);
|
|
233 |
break;
|
|
234 |
|
|
235 |
default:
|
|
236 |
ASSERT(0);
|
|
237 |
User::RequestComplete(pStat, KErrArgument);
|
|
238 |
break;
|
|
239 |
};
|
|
240 |
|
|
241 |
}
|
|
242 |
|
|
243 |
|
|
244 |
//-------------------------------------------------------------------
|
|
245 |
TInt TFsMntHelperImpl::GetMountProperties()
|
|
246 |
{
|
|
247 |
if(!this)
|
|
248 |
Panic(ENotInitialised);
|
|
249 |
Init();
|
|
250 |
|
|
251 |
TInt nRes;
|
|
252 |
|
|
253 |
//-- 1. get file system name
|
|
254 |
nRes = iFs.FileSystemName(iFsName, iDrvNum);
|
|
255 |
if(nRes != KErrNone)
|
|
256 |
{
|
|
257 |
AddErrorBit(Err_GetFsName); //-- indicate an error
|
|
258 |
return nRes;
|
|
259 |
}
|
|
260 |
|
|
261 |
//-- 2. find out if the drive sync/async
|
|
262 |
TPckgBuf<TBool> drvSyncBuf;
|
|
263 |
nRes = iFs.QueryVolumeInfoExt(iDrvNum, EIsDriveSync, drvSyncBuf);
|
|
264 |
if(nRes != KErrNone)
|
|
265 |
{//-- pretend that the drive is asynch. in the case of file system being corrupted. this is 99.9% true
|
|
266 |
iDrvSynch = EFalse;
|
|
267 |
}
|
|
268 |
else
|
|
269 |
{
|
|
270 |
iDrvSynch = drvSyncBuf();
|
|
271 |
}
|
|
272 |
|
|
273 |
//-- 3. find out extension names if there are any. Extension #0 is a primary one and up to several secondary ones
|
|
274 |
for(TInt i=0; i<KMaxExtensionCount; ++i)
|
|
275 |
{
|
|
276 |
nRes = iFs.ExtensionName(iExtNames[i], iDrvNum, i);
|
|
277 |
if(nRes != KErrNone)
|
|
278 |
{
|
|
279 |
iExtNames[i].Zero();
|
|
280 |
}
|
|
281 |
}
|
|
282 |
|
|
283 |
|
|
284 |
return KErrNone;
|
|
285 |
|
|
286 |
}
|
|
287 |
|
|
288 |
//-------------------------------------------------------------------
|
|
289 |
TInt TFsMntHelperImpl::MountFileSystem() const
|
|
290 |
{
|
|
291 |
if(!this)
|
|
292 |
Panic(ENotInitialised);
|
|
293 |
|
|
294 |
ASSERT(DataValid());
|
|
295 |
|
|
296 |
TInt nRes;
|
|
297 |
const TBool bPrimaryExtExists = (PrimaryExtName().Length() >0);
|
|
298 |
|
|
299 |
//-- all possible extensions that have existed before dismounting should be present in the file server context.
|
|
300 |
//-- anyway, it's impossible to load them here, because their file names are unknown
|
|
301 |
|
|
302 |
if(bPrimaryExtExists)
|
|
303 |
{//-- there was a primary extension, use special mounting API
|
|
304 |
nRes = iFs.MountFileSystem(FSysName(), PrimaryExtName(), iDrvNum, iDrvSynch);
|
|
305 |
}
|
|
306 |
else
|
|
307 |
{
|
|
308 |
nRes = iFs.MountFileSystem(FSysName(), iDrvNum, iDrvSynch);
|
|
309 |
}
|
|
310 |
|
|
311 |
//-- actually, if nRes != KErrNone, it doesn't _necessarily_ mean that _mounting_ of the file system failed.
|
|
312 |
//-- for example, the FS can be bound to the drive OK, but the media can be corrupted. This can happen when the FS
|
|
313 |
//-- had been dismounted from such a corrupted media.
|
|
314 |
//-- opposite, KErrNotReady is very likely to mean that the removable media is not present.
|
|
315 |
|
|
316 |
const TInt nFsMountRes = nRes;
|
|
317 |
if(nFsMountRes != KErrNone)
|
|
318 |
{
|
|
319 |
AddErrorBit(bPrimaryExtExists ? Err_MountFsPrimExt : Err_MountFs);
|
|
320 |
}
|
|
321 |
|
|
322 |
//-- mount secondary extensions if there were any
|
|
323 |
TInt nExtMountRes = KErrNone;
|
|
324 |
for(TInt i=1; i<KMaxExtensionCount; ++i)
|
|
325 |
{
|
|
326 |
if(iExtNames[i].Length() >0)
|
|
327 |
{
|
|
328 |
nRes = iFs.MountExtension(iExtNames[i], iDrvNum);
|
|
329 |
if(nRes != KErrNone)
|
|
330 |
{//-- indicate that an error happened while installing some secondary extension
|
|
331 |
AddErrorBit(Err_MountSecExt);
|
|
332 |
nExtMountRes = nRes;
|
|
333 |
}
|
|
334 |
}
|
|
335 |
}
|
|
336 |
|
|
337 |
//-- return FS mounting error code if it wasn't OK, otherwise - extension mounting code.
|
|
338 |
//-- for more info see error bitmap
|
|
339 |
return (nFsMountRes != KErrNone) ? nFsMountRes : nExtMountRes;
|
|
340 |
}
|
|
341 |
|
|
342 |
//-------------------------------------------------------------------
|
|
343 |
void TFsMntHelperImpl::Init()
|
|
344 |
{
|
|
345 |
if(!this)
|
|
346 |
Panic(ENotInitialised);
|
|
347 |
|
|
348 |
iDrvSynch = EFalse;
|
|
349 |
iFsName.Zero();
|
|
350 |
iErrorBitmap = 0;
|
|
351 |
|
|
352 |
for(TInt i=0; i<KMaxExtensionCount; ++i)
|
|
353 |
{
|
|
354 |
iExtNames[i].Zero();
|
|
355 |
}
|
|
356 |
|
|
357 |
}
|
|
358 |
|
|
359 |
//-------------------------------------------------------------------
|
|
360 |
/**
|
|
361 |
Panics.
|
|
362 |
@param aPanicCode a panic code
|
|
363 |
*/
|
|
364 |
void TFsMntHelperImpl::Panic(TPanicCode aPanicCode) const
|
|
365 |
{
|
|
366 |
_LIT(KPanicCat,"CFsMountHelper");
|
|
367 |
User::Panic(KPanicCat, aPanicCode);
|
|
368 |
}
|
|
369 |
|
|
370 |
TFsMntHelperImpl::TFsMntHelperImpl(RFs& aFs, TInt aDrvNum)
|
|
371 |
:iFs(aFs), iDrvNum(aDrvNum)
|
|
372 |
{
|
|
373 |
if(aDrvNum < EDriveA || aDrvNum >EDriveZ)
|
|
374 |
Panic(EDrvNumberInvalid);
|
|
375 |
|
|
376 |
Init();
|
|
377 |
}
|
|
378 |
|
|
379 |
/**
|
|
380 |
Debug only method. Compares 2 instances of the implementation
|
|
381 |
*/
|
|
382 |
TBool TFsMntHelperImpl::operator==(const TFsMntHelperImpl& aRhs) const
|
|
383 |
{
|
|
384 |
ASSERT(this != &aRhs);
|
|
385 |
|
|
386 |
#ifdef _DEBUG
|
|
387 |
|
|
388 |
|
|
389 |
if(iFsName.CompareF(aRhs.iFsName) !=0)
|
|
390 |
return EFalse;
|
|
391 |
|
|
392 |
for(TInt i=0; i<KMaxExtensionCount; ++i)
|
|
393 |
{
|
|
394 |
if(iExtNames[i].CompareF(aRhs.iExtNames[i]) !=0)
|
|
395 |
return EFalse;
|
|
396 |
}
|
|
397 |
|
|
398 |
if(!iDrvSynch != !aRhs.iDrvSynch)
|
|
399 |
return EFalse;
|
|
400 |
|
|
401 |
return ETrue;
|
|
402 |
|
|
403 |
#else //_DEBUG
|
|
404 |
(void)aRhs;
|
|
405 |
Panic(ENotImplemented);
|
|
406 |
return EFalse;
|
|
407 |
|
|
408 |
#endif// _DEBUG
|
|
409 |
}
|
|
410 |
|
|
411 |
|
279
|
412 |
//-------------------------------------------------------------------
|
|
413 |
/**
|
|
414 |
Closes the object, deletes the implementation
|
|
415 |
*/
|
|
416 |
void CFsMountHelper::Close()
|
|
417 |
{
|
|
418 |
delete ipImpl;
|
|
419 |
ipImpl = NULL;
|
|
420 |
}
|
271
|
421 |
|
|
422 |
//-------------------------------------------------------------------
|
|
423 |
/**
|
|
424 |
Factory function. Produces an object of this class
|
|
425 |
|
|
426 |
@param aFs file server session
|
|
427 |
@param aDrvNum drive number
|
|
428 |
|
|
429 |
@return pointer to the constructed object or NULL on error.
|
|
430 |
*/
|
|
431 |
EXPORT_C CFsMountHelper* CFsMountHelper::New(RFs& aFs, TInt aDrvNum)
|
|
432 |
{
|
|
433 |
|
|
434 |
CFsMountHelper* pSelf = new CFsMountHelper;
|
|
435 |
|
|
436 |
if(pSelf)
|
|
437 |
{
|
|
438 |
pSelf->ipImpl = new TFsMntHelperImpl(aFs, aDrvNum);
|
|
439 |
|
|
440 |
if(!pSelf->ipImpl)
|
|
441 |
{
|
|
442 |
delete pSelf;
|
|
443 |
pSelf = NULL;
|
|
444 |
}
|
|
445 |
}
|
|
446 |
|
|
447 |
return pSelf;
|
|
448 |
}
|
|
449 |
|
|
450 |
|
|
451 |
|
|
452 |
//-------------------------------------------------------------------
|
|
453 |
/**
|
|
454 |
Acqires drive/mount/file system properties that will be used for mounting the file system back.
|
|
455 |
@return Standard Error code.
|
|
456 |
*/
|
|
457 |
EXPORT_C TInt CFsMountHelper::GetMountProperties()
|
|
458 |
{
|
|
459 |
return ipImpl->GetMountProperties();
|
|
460 |
}
|
|
461 |
|
|
462 |
//-------------------------------------------------------------------
|
|
463 |
/**
|
|
464 |
Mount the file system onto the drive using properties previously acquired by GetMountProperties() call.
|
|
465 |
Note that the drive shouldn't have the file system mounted, this API call will fail in this case.
|
|
466 |
|
|
467 |
@return KErrNone if mounting file system + possible extensions was ok
|
|
468 |
the result of file system mounting if the file system mounting failed (e.g. because of the damaged media)
|
|
469 |
the result of mounting secondary extension if file system mounted OK, but secondary extension mounting resulted in some error.
|
|
470 |
*/
|
|
471 |
EXPORT_C TInt CFsMountHelper::MountFileSystem() const
|
|
472 |
{
|
|
473 |
return ipImpl->MountFileSystem();
|
|
474 |
}
|
|
475 |
|
|
476 |
//-------------------------------------------------------------------
|
|
477 |
|
|
478 |
/**
|
|
479 |
An asynchronous API to dismount the file system on the specified drive.
|
|
480 |
Precondition: The drive / file system parameters at the time of this API call must be the same as acquired by the last call of GetMountProperties().
|
|
481 |
This is checked in debug mode to prevent possible inconsistencied when mounting the file system back later.
|
|
482 |
This means that the GetMountProperties() should be called at least once before any attempt to dismount the file system.
|
|
483 |
|
|
484 |
@param aStat request status. On completion will contain the dismounting result code.
|
|
485 |
@param aDismountMode describes the dismounting method. See TFsDismountMode.
|
|
486 |
|
|
487 |
|
|
488 |
*/
|
|
489 |
EXPORT_C void CFsMountHelper::DismountFileSystem(TRequestStatus& aStat, TFsDismountMode aDismountMode/*=ENormal*/) const
|
|
490 |
{
|
|
491 |
ipImpl->DismountFileSystem(aStat, aDismountMode);
|
|
492 |
}
|
|
493 |
|
|
494 |
|
|
495 |
//-------------------------------------------------------------------
|
|
496 |
/**
|
|
497 |
A simplified synchronous version of the DismountFileSystem() API.
|
|
498 |
Works absolutely the same as RFs::DismountFileSystem()
|
|
499 |
|
|
500 |
@return RFs::DismountFileSystem() result code
|
|
501 |
*/
|
|
502 |
EXPORT_C TInt CFsMountHelper::DismountFileSystem() const
|
|
503 |
{
|
|
504 |
TRequestStatus stat;
|
|
505 |
DismountFileSystem(stat, ENormal);
|
|
506 |
User::WaitForRequest(stat);
|
|
507 |
|
|
508 |
return stat.Int();
|
|
509 |
}
|
|
510 |
|
|
511 |
|
|
512 |
|
279
|
513 |
EXPORT_C CFsMountHelper::~CFsMountHelper()
|
|
514 |
{
|
|
515 |
Close();
|
|
516 |
}
|
271
|
517 |
|
|
518 |
|
|
519 |
|