sl@0
|
1 |
// Copyright (c) 1996-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\sfat\sl_disk.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "sl_disk.h"
|
sl@0
|
19 |
#include "sl_cache.h"
|
sl@0
|
20 |
#include "sl_dir_cache.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
/**
|
sl@0
|
23 |
@file
|
sl@0
|
24 |
*/
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
//################################################################################################################################
|
sl@0
|
28 |
//# CRawDisk implementation
|
sl@0
|
29 |
//################################################################################################################################
|
sl@0
|
30 |
|
sl@0
|
31 |
|
sl@0
|
32 |
/**
|
sl@0
|
33 |
Factory function. Constructs objects of the classes derived from CRawDisk.
|
sl@0
|
34 |
|
sl@0
|
35 |
@param aOwner reference to the onwning FAT Mount class
|
sl@0
|
36 |
@param aLocDrvCaps local drive capabilities from the media driver
|
sl@0
|
37 |
@return pointer to the constructed object. May be NULL on error.
|
sl@0
|
38 |
*/
|
sl@0
|
39 |
CRawDisk* CRawDisk::NewL(CFatMountCB& aOwner, const TLocalDriveCaps& aLocDrvCaps)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
__PRINT1(_L("CRawDisk::NewL() drv:%d"), aOwner.DriveNumber());
|
sl@0
|
42 |
|
sl@0
|
43 |
if(aLocDrvCaps.iMediaAtt & KMediaAttVariableSize)
|
sl@0
|
44 |
{//-- this is the RAM drive "attribute"
|
sl@0
|
45 |
ASSERT((aLocDrvCaps.iDriveAtt & (KDriveAttInternal|KDriveAttLocal)) && aLocDrvCaps.iType == EMediaRam);
|
sl@0
|
46 |
if(!aLocDrvCaps.iBaseAddress)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
ASSERT(0);
|
sl@0
|
49 |
return NULL;
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
return CRamDisk::NewL(aOwner);
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
//-- create CAtaDisk by default
|
sl@0
|
56 |
return CAtaDisk::NewL(aOwner);
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
|
sl@0
|
60 |
CRawDisk::CRawDisk(CFatMountCB& aOwner)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
iFatMount = &aOwner;
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
/**
|
sl@0
|
66 |
Default implementation. Initialises and re-initialises the object.
|
sl@0
|
67 |
*/
|
sl@0
|
68 |
void CRawDisk::InitializeL()
|
sl@0
|
69 |
{
|
sl@0
|
70 |
ASSERT(iFatMount);
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
|
sl@0
|
74 |
TInt CRawDisk::GetLastErrorInfo(TDes8& /*aErrorInfo*/) const
|
sl@0
|
75 |
{
|
sl@0
|
76 |
return KErrNotSupported;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
//################################################################################################################################
|
sl@0
|
80 |
//## CAtaDisk class implementation
|
sl@0
|
81 |
//################################################################################################################################
|
sl@0
|
82 |
|
sl@0
|
83 |
CAtaDisk::CAtaDisk(CFatMountCB& aFatMount)
|
sl@0
|
84 |
:CRawDisk(aFatMount), iDrive(aFatMount.DriveInterface())
|
sl@0
|
85 |
{
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
CAtaDisk::~CAtaDisk()
|
sl@0
|
89 |
{
|
sl@0
|
90 |
delete ipDirCache;
|
sl@0
|
91 |
delete iUidCache;
|
sl@0
|
92 |
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
|
sl@0
|
96 |
//-------------------------------------------------------------------------------------
|
sl@0
|
97 |
|
sl@0
|
98 |
/**
|
sl@0
|
99 |
CAtaDisk factory method.
|
sl@0
|
100 |
|
sl@0
|
101 |
@param aFatMount reference to the owner.
|
sl@0
|
102 |
@return pointer to the constructed object.
|
sl@0
|
103 |
*/
|
sl@0
|
104 |
CAtaDisk* CAtaDisk::NewL(CFatMountCB& aFatMount)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
__PRINT1(_L("CAtaDisk::NewL() drv:%d"), aFatMount.DriveNumber());
|
sl@0
|
107 |
|
sl@0
|
108 |
CAtaDisk* pSelf = new (ELeave) CAtaDisk(aFatMount);
|
sl@0
|
109 |
|
sl@0
|
110 |
CleanupStack::PushL(pSelf);
|
sl@0
|
111 |
|
sl@0
|
112 |
pSelf->ConstructL();
|
sl@0
|
113 |
pSelf->InitializeL();
|
sl@0
|
114 |
|
sl@0
|
115 |
CleanupStack::Pop();
|
sl@0
|
116 |
|
sl@0
|
117 |
return pSelf;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
//-------------------------------------------------------------------------------------
|
sl@0
|
121 |
|
sl@0
|
122 |
/** 2nd stage constructor */
|
sl@0
|
123 |
void CAtaDisk::ConstructL()
|
sl@0
|
124 |
{
|
sl@0
|
125 |
//=========================== create data WT cache that is primarily used for caching exacutable modules' UIDs
|
sl@0
|
126 |
const TUint32 KUidCachePageSzLog2 = 9; //-- 512 bytes in page
|
sl@0
|
127 |
const TUint32 KUidCachePages = 64; //-- 64 pages; total cache size is 32K
|
sl@0
|
128 |
|
sl@0
|
129 |
iUidCache = CMediaWTCache::NewL(iDrive, KUidCachePages, KUidCachePageSzLog2);
|
sl@0
|
130 |
|
sl@0
|
131 |
|
sl@0
|
132 |
//=========================== create directory cache
|
sl@0
|
133 |
|
sl@0
|
134 |
//-- Get dir. cache parameters from config. They may be set in estart.txt for a specified drive.
|
sl@0
|
135 |
const TUint32 KDirCacheSize = iFatMount->FatConfig().DirCacheSize(); //- Total directory cache size, bytes.
|
sl@0
|
136 |
const TUint32 KMaxDirCachePageSzLog2 = iFatMount->FatConfig().DirCacheMaxPageSizeLog2(); //- Log2 of the Max. dir. cache page.
|
sl@0
|
137 |
|
sl@0
|
138 |
__PRINT2(_L("CAtaDisk::ConstructL() Dir Cache config:%d,%d"),KDirCacheSize,KMaxDirCachePageSzLog2);
|
sl@0
|
139 |
|
sl@0
|
140 |
ASSERT(KDirCacheSize >= K1KiloByte && KDirCacheSize <= K1MegaByte);
|
sl@0
|
141 |
ASSERT((KMaxDirCachePageSzLog2 >= KDefSectorSzLog2) && (Pow2(KMaxDirCachePageSzLog2) <= KDirCacheSize));
|
sl@0
|
142 |
|
sl@0
|
143 |
//-- calculate the size and number of pages for the dir. cache.
|
sl@0
|
144 |
//-- if the mount's cluster size is less than max. page size from config, the page size will be cluster size.
|
sl@0
|
145 |
//-- otherwise it will be the value from config. I.e the minimal page size is cluster size; the maximal page size is taken from config.
|
sl@0
|
146 |
//-- The number of pages depends on total cache size and page size.
|
sl@0
|
147 |
const TUint clustSizeLog2 = iFatMount->ClusterSizeLog2(); //-- current FAT cluster size Log2
|
sl@0
|
148 |
const TUint32 pageSzLog2 = (clustSizeLog2 <= KMaxDirCachePageSzLog2) ? clustSizeLog2 : KMaxDirCachePageSzLog2;
|
sl@0
|
149 |
const TUint32 numPages = KDirCacheSize / (Pow2(pageSzLog2));
|
sl@0
|
150 |
|
sl@0
|
151 |
ASSERT(!ipDirCache);
|
sl@0
|
152 |
|
sl@0
|
153 |
#ifdef USE_DP_DIR_CACHE
|
sl@0
|
154 |
|
sl@0
|
155 |
//=========================== create Demand Paging type of the directory cache
|
sl@0
|
156 |
|
sl@0
|
157 |
// initialize cache memory manager as all file systems have mounted by now
|
sl@0
|
158 |
if(CCacheMemoryManagerFactory::CacheMemoryManager())
|
sl@0
|
159 |
{
|
sl@0
|
160 |
// Note: the configuration data of min and max cache size are aligned with the memory size it
|
sl@0
|
161 |
// occupies in kernel as we are using demand paging subsystem for dynamic cache size support.
|
sl@0
|
162 |
// Therefore, they are refered as 'Mem Size' in following calculation.
|
sl@0
|
163 |
// However, 'Data Size' refers to the logical size of a page, i.e. the actual data size each page
|
sl@0
|
164 |
// contains.
|
sl@0
|
165 |
// The constraints we have to consider when setting up the dynamic cache:
|
sl@0
|
166 |
// 1. each page's data size is aligned with cluster size, unless cluster size is bigger than
|
sl@0
|
167 |
// the default maximum page size allowed (typically 32 KB).
|
sl@0
|
168 |
// 2. if page's data size is smaller than segment size (typically 4 KB), i.e. the unit size of
|
sl@0
|
169 |
// demand paging subsystem's page management, we will still use up the whole segment for
|
sl@0
|
170 |
// that page.
|
sl@0
|
171 |
// 3. the default min and max cache's memory size is pre-defined in fat_config.cpp file.
|
sl@0
|
172 |
// (see KDef_DynamicDirCacheMin & KDef_DynamicDirCacheMax).
|
sl@0
|
173 |
|
sl@0
|
174 |
// calculate page data size (logical view of page size)
|
sl@0
|
175 |
const TUint32 DefMaxCachePageLog2 = iFatMount->FatConfig().DynamicDirCacheMaxPageSizeLog2();
|
sl@0
|
176 |
const TUint32 PageDataSizeLog2 = clustSizeLog2 < DefMaxCachePageLog2 ? clustSizeLog2 : DefMaxCachePageLog2;
|
sl@0
|
177 |
|
sl@0
|
178 |
// calculate page number, based on memory size we have reserved
|
sl@0
|
179 |
const TUint32 SegmentSizeLog2 = CCacheMemoryManagerFactory::CacheMemoryManager()->SegmentSizeInBytesLog2();
|
sl@0
|
180 |
const TUint32 PageMemSizeLog2 = PageDataSizeLog2 < SegmentSizeLog2 ? SegmentSizeLog2 : PageDataSizeLog2;
|
sl@0
|
181 |
TUint32 CacheSizeMinInPages = iFatMount->FatConfig().DynamicDirCacheSizeMin() >> PageMemSizeLog2;
|
sl@0
|
182 |
TUint32 CacheSizeMaxInPages = iFatMount->FatConfig().DynamicDirCacheSizeMax() >> PageMemSizeLog2;
|
sl@0
|
183 |
|
sl@0
|
184 |
// cache memory client is connected via name
|
sl@0
|
185 |
TBuf<0x20> clientName = _L("CACHE_MEM_CLIENT:");
|
sl@0
|
186 |
clientName.Append('A'+iFatMount->DriveNumber());
|
sl@0
|
187 |
|
sl@0
|
188 |
TRAPD(err, ipDirCache = CDynamicDirCache::NewL(iDrive, CacheSizeMinInPages, CacheSizeMaxInPages, PageDataSizeLog2, clientName));
|
sl@0
|
189 |
if (err == KErrNone)
|
sl@0
|
190 |
return;
|
sl@0
|
191 |
|
sl@0
|
192 |
//-- fall back to constructing old type of cache
|
sl@0
|
193 |
|
sl@0
|
194 |
}
|
sl@0
|
195 |
#endif // USE_DP_DIR_CACHE
|
sl@0
|
196 |
|
sl@0
|
197 |
//=========================== create legacy type of the directory cache
|
sl@0
|
198 |
ASSERT(!ipDirCache);
|
sl@0
|
199 |
|
sl@0
|
200 |
ipDirCache = CMediaWTCache::NewL(iDrive, numPages, pageSzLog2);
|
sl@0
|
201 |
__PRINT3(_L("CDirCache::NewL(drive: %C, NumPages=%d, PageSize=%u)"), 'A'+iFatMount->DriveNumber(), numPages, 1<<pageSzLog2);
|
sl@0
|
202 |
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
//-------------------------------------------------------------------------------------
|
sl@0
|
206 |
|
sl@0
|
207 |
/**
|
sl@0
|
208 |
Initialises and re-initialises the object.
|
sl@0
|
209 |
*/
|
sl@0
|
210 |
void CAtaDisk::InitializeL()
|
sl@0
|
211 |
{
|
sl@0
|
212 |
CRawDisk::InitializeL();
|
sl@0
|
213 |
|
sl@0
|
214 |
//-- there is a little issue here. after formatting FAT mounts's cluster size can change.
|
sl@0
|
215 |
//-- dir. cache page size depends on the cluster size. This method doesn't change the dir. cache page size.
|
sl@0
|
216 |
//-- At present it is done in CFatMountCB::InitializeL() that deletes this object and then reconstructs it again.
|
sl@0
|
217 |
|
sl@0
|
218 |
//-- invalidate directory cache here
|
sl@0
|
219 |
ipDirCache->InvalidateCache();
|
sl@0
|
220 |
|
sl@0
|
221 |
TInt64 cacheBasePos;
|
sl@0
|
222 |
|
sl@0
|
223 |
if(iFatMount->FatType() == EFat32)
|
sl@0
|
224 |
{
|
sl@0
|
225 |
//-- this is FAT32, all directories including Root are files and aligned to the cluster heap boundary
|
sl@0
|
226 |
//-- set dir. cache base position to the cluster heap boundary
|
sl@0
|
227 |
const TUint32 offsetMask = (1 << iFatMount->ClusterSizeLog2() )-1;
|
sl@0
|
228 |
cacheBasePos = (iFatMount->ClusterBasePosition() & offsetMask);
|
sl@0
|
229 |
}
|
sl@0
|
230 |
else
|
sl@0
|
231 |
{
|
sl@0
|
232 |
//-- this is FAT12/16. Root directory is a separate volume object and has no alignment.
|
sl@0
|
233 |
//-- set cache base position to its beginning.
|
sl@0
|
234 |
cacheBasePos = iFatMount->StartOfRootDirInBytes();
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
ipDirCache->SetCacheBasePos(cacheBasePos);
|
sl@0
|
238 |
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
//-------------------------------------------------------------------------------------
|
sl@0
|
242 |
|
sl@0
|
243 |
/**
|
sl@0
|
244 |
Read data from the media through LRU data cache cache.
|
sl@0
|
245 |
|
sl@0
|
246 |
@param aPos absolute media position
|
sl@0
|
247 |
@param aLength how many bytes to read
|
sl@0
|
248 |
@param aDes data descriptor
|
sl@0
|
249 |
|
sl@0
|
250 |
@leave on error
|
sl@0
|
251 |
*/
|
sl@0
|
252 |
void CAtaDisk::ReadCachedL(TInt64 aPos,TInt aLength,TDes8& aDes) const
|
sl@0
|
253 |
{
|
sl@0
|
254 |
__PRINT3(_L("CAtaDisk::ReadL() pos:%u:%u, len:%u"), I64HIGH(aPos), I64LOW(aPos), aLength);
|
sl@0
|
255 |
iUidCache->ReadL(aPos, aLength, aDes);
|
sl@0
|
256 |
}
|
sl@0
|
257 |
|
sl@0
|
258 |
//-------------------------------------------------------------------------------------
|
sl@0
|
259 |
|
sl@0
|
260 |
/**
|
sl@0
|
261 |
Write data to the media through LRU data cache
|
sl@0
|
262 |
|
sl@0
|
263 |
@param aPos absolute media position
|
sl@0
|
264 |
@param aDes data descriptor
|
sl@0
|
265 |
|
sl@0
|
266 |
@leave on error
|
sl@0
|
267 |
*/
|
sl@0
|
268 |
void CAtaDisk::WriteCachedL(TInt64 aPos, const TDesC8& aDes)
|
sl@0
|
269 |
{
|
sl@0
|
270 |
__PRINT3(_L("CAtaDisk::WriteL() pos:%u:%u, len:%u"), I64HIGH(aPos), I64LOW(aPos), aDes.Size());
|
sl@0
|
271 |
iUidCache->WriteL(aPos, aDes);
|
sl@0
|
272 |
}
|
sl@0
|
273 |
|
sl@0
|
274 |
|
sl@0
|
275 |
//-------------------------------------------------------------------------------------
|
sl@0
|
276 |
|
sl@0
|
277 |
/**
|
sl@0
|
278 |
Read data from the media directly without any caches.
|
sl@0
|
279 |
Mostly used by file IO
|
sl@0
|
280 |
|
sl@0
|
281 |
@param aPos absolute media position
|
sl@0
|
282 |
@param aLength how many bytes to read
|
sl@0
|
283 |
@param aTrg Pointer to the data descriptor, i.e. (const TAny*)(&TDes8)
|
sl@0
|
284 |
@param aMessage Refrence to server message from request
|
sl@0
|
285 |
@param anOffset Offset into read data to write
|
sl@0
|
286 |
|
sl@0
|
287 |
@leave on error
|
sl@0
|
288 |
*/
|
sl@0
|
289 |
void CAtaDisk::ReadL(TInt64 aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2 &aMessage,TInt anOffset) const
|
sl@0
|
290 |
{
|
sl@0
|
291 |
|
sl@0
|
292 |
__PRINT4(_L("CAtaDisk::ReadL() pos:%u:%u, len:%u, offset:%u"), I64HIGH(aPos), I64LOW(aPos), aLength, anOffset);
|
sl@0
|
293 |
User::LeaveIfError(iDrive.ReadNonCritical(aPos,aLength,aTrg,aMessage,anOffset));
|
sl@0
|
294 |
}
|
sl@0
|
295 |
|
sl@0
|
296 |
//-------------------------------------------------------------------------------------
|
sl@0
|
297 |
|
sl@0
|
298 |
/**
|
sl@0
|
299 |
Write data to the media directly without any cached.
|
sl@0
|
300 |
Mostly used by file IO
|
sl@0
|
301 |
|
sl@0
|
302 |
This method shall invalidate some data caches to keep them in synch with the media.
|
sl@0
|
303 |
|
sl@0
|
304 |
@param aPos Media position in bytes
|
sl@0
|
305 |
@param aLength Length in bytes of write
|
sl@0
|
306 |
@param aTrg Pointer to the data descriptor, i.e. (const TAny*)(&TDes8)
|
sl@0
|
307 |
@param aMessage Refrence to server message from request, contains data
|
sl@0
|
308 |
@param anOffset Offset into write data to use in write
|
sl@0
|
309 |
|
sl@0
|
310 |
@leave on error
|
sl@0
|
311 |
*/
|
sl@0
|
312 |
void CAtaDisk::WriteL(TInt64 aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2 &aMessage,TInt anOffset)
|
sl@0
|
313 |
{
|
sl@0
|
314 |
__PRINT4(_L("CAtaDisk::WriteL() pos:%u:%u, len:%u, offset:%u"), I64HIGH(aPos), I64LOW(aPos), aLength, anOffset);
|
sl@0
|
315 |
|
sl@0
|
316 |
//-- write data to the media directly
|
sl@0
|
317 |
User::LeaveIfError(iDrive.WriteNonCritical(aPos,aLength,aSrc,aMessage,anOffset));
|
sl@0
|
318 |
|
sl@0
|
319 |
//-- we need to invalidate UID cache page that corresponds to aPos (if any). This is UID caching specific. UID is stored in the first few bytes of
|
sl@0
|
320 |
//-- the executable module and therefore belongs to one cache page only.
|
sl@0
|
321 |
//-- If someone writes to the beginning of the exe module file, corresponding UID cache page will be invalidated and re-read from the media later
|
sl@0
|
322 |
iUidCache->InvalidateCachePage(aPos);
|
sl@0
|
323 |
|
sl@0
|
324 |
//-- invalidate affected(if any) part of the FAT cache in the case if someone used to write data to FAT area, which usually do not happen
|
sl@0
|
325 |
iFatMount->FAT().InvalidateCacheL(aPos,aLength);
|
sl@0
|
326 |
|
sl@0
|
327 |
}
|
sl@0
|
328 |
|
sl@0
|
329 |
//-------------------------------------------------------------------------------------
|
sl@0
|
330 |
|
sl@0
|
331 |
/** Get information for last disk error */
|
sl@0
|
332 |
TInt CAtaDisk::GetLastErrorInfo(TDes8& aErrorInfo) const
|
sl@0
|
333 |
{
|
sl@0
|
334 |
return iDrive.GetLastErrorInfo(aErrorInfo);
|
sl@0
|
335 |
}
|
sl@0
|
336 |
|
sl@0
|
337 |
|
sl@0
|
338 |
//-------------------------------------------------------------------------------------
|
sl@0
|
339 |
/** Invalidate whole UID cache */
|
sl@0
|
340 |
void CAtaDisk::InvalidateUidCache()
|
sl@0
|
341 |
{
|
sl@0
|
342 |
ASSERT(iUidCache);
|
sl@0
|
343 |
iUidCache->InvalidateCache();
|
sl@0
|
344 |
}
|
sl@0
|
345 |
|
sl@0
|
346 |
/**
|
sl@0
|
347 |
Invalidate the UID cache page that has aPos cached.
|
sl@0
|
348 |
This method doesn't pay attention to the length of the block being invalidated because
|
sl@0
|
349 |
UID lives in the very beginning of the exe module and always fits into a single page
|
sl@0
|
350 |
*/
|
sl@0
|
351 |
void CAtaDisk::InvalidateUidCachePage(TUint64 aPos)
|
sl@0
|
352 |
{
|
sl@0
|
353 |
ASSERT(iUidCache);
|
sl@0
|
354 |
iUidCache->InvalidateCachePage(aPos);
|
sl@0
|
355 |
}
|
sl@0
|
356 |
|
sl@0
|
357 |
|
sl@0
|
358 |
//################################################################################################################################
|
sl@0
|
359 |
//## CRamDisk class implementation
|
sl@0
|
360 |
//################################################################################################################################
|
sl@0
|
361 |
|
sl@0
|
362 |
|
sl@0
|
363 |
/**
|
sl@0
|
364 |
CRamDisk factory method.
|
sl@0
|
365 |
|
sl@0
|
366 |
@param aFatMount reference to the owner.
|
sl@0
|
367 |
@return pointer to the constructed object.
|
sl@0
|
368 |
*/
|
sl@0
|
369 |
CRamDisk* CRamDisk::NewL(CFatMountCB& aFatMount)
|
sl@0
|
370 |
{
|
sl@0
|
371 |
__PRINT1(_L("CRamDisk::NewL() drv:%d"), aFatMount.DriveNumber());
|
sl@0
|
372 |
CRamDisk* pSelf = new(ELeave)CRamDisk(aFatMount);
|
sl@0
|
373 |
|
sl@0
|
374 |
CleanupStack::PushL(pSelf);
|
sl@0
|
375 |
|
sl@0
|
376 |
pSelf->InitializeL();
|
sl@0
|
377 |
|
sl@0
|
378 |
CleanupStack::Pop();
|
sl@0
|
379 |
|
sl@0
|
380 |
return pSelf;
|
sl@0
|
381 |
}
|
sl@0
|
382 |
|
sl@0
|
383 |
CRamDisk::CRamDisk(CFatMountCB& aFatMount)
|
sl@0
|
384 |
:CRawDisk(aFatMount)
|
sl@0
|
385 |
{
|
sl@0
|
386 |
}
|
sl@0
|
387 |
|
sl@0
|
388 |
//-------------------------------------------------------------------------------------
|
sl@0
|
389 |
|
sl@0
|
390 |
/**
|
sl@0
|
391 |
Initialises and re-initialises the object.
|
sl@0
|
392 |
*/
|
sl@0
|
393 |
void CRamDisk::InitializeL()
|
sl@0
|
394 |
{
|
sl@0
|
395 |
CRawDisk::InitializeL();
|
sl@0
|
396 |
|
sl@0
|
397 |
//-- set the RAM disk base
|
sl@0
|
398 |
TLocalDriveCapsV2 caps;
|
sl@0
|
399 |
TPckg<TLocalDriveCapsV2> capsPckg(caps);
|
sl@0
|
400 |
User::LeaveIfError(iFatMount->LocalDrive()->Caps(capsPckg));
|
sl@0
|
401 |
|
sl@0
|
402 |
ASSERT(caps.iMediaAtt & KMediaAttVariableSize);
|
sl@0
|
403 |
|
sl@0
|
404 |
//-- set RAM disk base
|
sl@0
|
405 |
iRamDiskBase = caps.iBaseAddress;
|
sl@0
|
406 |
ASSERT(iRamDiskBase);
|
sl@0
|
407 |
}
|
sl@0
|
408 |
|
sl@0
|
409 |
|
sl@0
|
410 |
|
sl@0
|
411 |
/** @return the start address of the Ram Drive in low memory */
|
sl@0
|
412 |
TUint8* CRamDisk::RamDiskBase() const
|
sl@0
|
413 |
{
|
sl@0
|
414 |
return iRamDiskBase;
|
sl@0
|
415 |
}
|
sl@0
|
416 |
|
sl@0
|
417 |
//-------------------------------------------------------------------------------------
|
sl@0
|
418 |
//
|
sl@0
|
419 |
// Read aLength of data from the disk
|
sl@0
|
420 |
//
|
sl@0
|
421 |
void CRamDisk::ReadCachedL(TInt64 aPos,TInt aLength,TDes8& aDes) const
|
sl@0
|
422 |
{
|
sl@0
|
423 |
|
sl@0
|
424 |
__PRINT3(_L("CRamDisk::ReadL Base 0x%x Pos 0x%x, Len %d"),RamDiskBase(),I64LOW(aPos),aLength);
|
sl@0
|
425 |
__ASSERT_ALWAYS((aPos+aLength<=I64INT(iFatMount->Size())) && (aLength>=0),User::Leave(KErrCorrupt));
|
sl@0
|
426 |
Mem::Copy((TUint8*)aDes.Ptr(),RamDiskBase()+I64LOW(aPos),aLength);
|
sl@0
|
427 |
aDes.SetLength(aLength);
|
sl@0
|
428 |
}
|
sl@0
|
429 |
|
sl@0
|
430 |
//-------------------------------------------------------------------------------------
|
sl@0
|
431 |
//
|
sl@0
|
432 |
// Write aLength of data to the disk
|
sl@0
|
433 |
//
|
sl@0
|
434 |
void CRamDisk::WriteCachedL(TInt64 aPos,const TDesC8& aDes)
|
sl@0
|
435 |
{
|
sl@0
|
436 |
|
sl@0
|
437 |
__PRINT3(_L("CRamDisk::WriteL Base 0x%x Pos 0x%x, Len %d"),RamDiskBase(),aPos,aDes.Length());
|
sl@0
|
438 |
__ASSERT_ALWAYS(aPos+aDes.Length()<=I64INT(iFatMount->Size()),User::Leave(KErrCorrupt));
|
sl@0
|
439 |
Mem::Copy(RamDiskBase()+I64LOW(aPos),(TUint8*)aDes.Ptr(),aDes.Length());
|
sl@0
|
440 |
}
|
sl@0
|
441 |
|
sl@0
|
442 |
|
sl@0
|
443 |
//-------------------------------------------------------------------------------------
|
sl@0
|
444 |
//
|
sl@0
|
445 |
// Read from ramDrive into thread relative descriptor
|
sl@0
|
446 |
//
|
sl@0
|
447 |
void CRamDisk::ReadL(TInt64 aPos,TInt aLength,const TAny* /*aTrg*/,const RMessagePtr2 &aMessage,TInt anOffset) const
|
sl@0
|
448 |
{
|
sl@0
|
449 |
__PRINT2(_L("CRamDisk::ReadL TAny* Pos 0x%x, Len %d"),aPos,aLength);
|
sl@0
|
450 |
__ASSERT_ALWAYS((aPos+aLength<=I64INT(iFatMount->Size())) && (aLength>=0),User::Leave(KErrCorrupt));
|
sl@0
|
451 |
TUint8* pos=RamDiskBase()+I64LOW(aPos);
|
sl@0
|
452 |
TPtrC8 buf(pos,aLength);
|
sl@0
|
453 |
aMessage.WriteL(0,buf,anOffset);
|
sl@0
|
454 |
}
|
sl@0
|
455 |
|
sl@0
|
456 |
//-------------------------------------------------------------------------------------
|
sl@0
|
457 |
//
|
sl@0
|
458 |
// Write from thread relative descriptor into ramDrive
|
sl@0
|
459 |
//
|
sl@0
|
460 |
void CRamDisk::WriteL(TInt64 aPos,TInt aLength,const TAny* /*aSrc*/,const RMessagePtr2 &aMessage,TInt anOffset)
|
sl@0
|
461 |
{
|
sl@0
|
462 |
__PRINT2(_L("CRamDisk::WriteL TAny* Pos 0x%x, Len %d"),aPos,aLength);
|
sl@0
|
463 |
__ASSERT_ALWAYS(aPos+aLength<=I64INT(iFatMount->Size()),User::Leave(KErrCorrupt));
|
sl@0
|
464 |
TUint8* pos=RamDiskBase()+I64LOW(aPos);
|
sl@0
|
465 |
TPtr8 buf(pos,aLength);
|
sl@0
|
466 |
aMessage.ReadL(0,buf,anOffset);
|
sl@0
|
467 |
}
|
sl@0
|
468 |
|
sl@0
|
469 |
|
sl@0
|
470 |
|
sl@0
|
471 |
|
sl@0
|
472 |
|
sl@0
|
473 |
|
sl@0
|
474 |
|
sl@0
|
475 |
|
sl@0
|
476 |
|
sl@0
|
477 |
|
sl@0
|
478 |
|
sl@0
|
479 |
|
sl@0
|
480 |
|
sl@0
|
481 |
|
sl@0
|
482 |
|
sl@0
|
483 |
|
sl@0
|
484 |
|
sl@0
|
485 |
|
sl@0
|
486 |
|
sl@0
|
487 |
|
sl@0
|
488 |
|
sl@0
|
489 |
|
sl@0
|
490 |
|
sl@0
|
491 |
|
sl@0
|
492 |
|
sl@0
|
493 |
|
sl@0
|
494 |
|