author | hgs |
Fri, 23 Apr 2010 22:08:41 +0100 | |
changeset 121 | 661475905584 |
parent 36 | 538db54a451d |
child 244 | a77889bee936 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// |
|
15 |
||
16 |
#include "elocal.h" |
|
17 |
#include <emulator.h> |
|
18 |
#include <TCHAR.h> |
|
19 |
||
20 |
const TInt KMajorVersionNumber=1; |
|
21 |
const TInt KMinorVersionNumber=0; |
|
22 |
||
23 |
const TUint KInvalidSetFilePointer = 0xffffffff; // INVALID_SET_FILE_POINTER |
|
24 |
||
25 |
#pragma data_seg(".data2") |
|
26 |
#ifdef __VC32__ |
|
27 |
#pragma bss_seg(".data2") |
|
28 |
#endif |
|
29 |
static TInt ReadSpeed; |
|
30 |
static TInt WriteSpeed; |
|
31 |
#pragma data_seg() |
|
32 |
#ifdef __VC32__ |
|
33 |
#pragma bss_seg() |
|
34 |
#endif |
|
35 |
||
36 |
static void Panic(TPanic aPanic) |
|
37 |
{ |
|
38 |
User::Panic(_L("LocalFSys"),aPanic); |
|
39 |
} |
|
40 |
||
41 |
||
42 |
// |
|
43 |
// Map aDrive to a path given by environment variables |
|
44 |
// |
|
45 |
TBool MapDrive(TDes& aFileName, TInt aDrive) |
|
46 |
{ |
|
47 |
||
48 |
TDriveName root(TDriveUnit(aDrive).Name()); |
|
49 |
TFileName path; |
|
50 |
TBuf<3> rootWithSlash(root); |
|
51 |
rootWithSlash.Append('\\'); |
|
52 |
||
53 |
if (MapEmulatedFileName(path, rootWithSlash) == KErrNone) |
|
54 |
{ |
|
55 |
aFileName=path.Left(3); // drive letter, colon and backslash |
|
56 |
return(ETrue); |
|
57 |
} |
|
58 |
aFileName=root; // no trailing backslash |
|
59 |
return(EFalse); |
|
60 |
} |
|
61 |
||
62 |
TInt MapFileName(TDes& aFileName, TInt aDrive, const TDesC& aName) |
|
63 |
{ |
|
64 |
TFileName n(TDriveUnit(aDrive).Name()); |
|
65 |
n.Append(aName); |
|
66 |
return MapEmulatedFileName(aFileName,n); |
|
67 |
} |
|
68 |
||
69 |
void MapFileNameL(TDes& aFileName, TInt aDrive, const TDesC& aName) |
|
70 |
{ |
|
71 |
User::LeaveIfError(MapFileName(aFileName,aDrive,aName)); |
|
72 |
} |
|
73 |
||
74 |
||
75 |
/** |
|
76 |
Check whether a descriptor has enough space for null-terminating and append a zero terminator if it does. |
|
77 |
Supposed to be used for Win32 file operations, taking C-like strings as parameters. |
|
78 |
The main purpose is to avoid panics caused by descriptors overflow. |
|
79 |
||
80 |
@param aDes descriptor to be null-terminated; a file(directory) name presumably. |
|
81 |
@return cast to LPCTSTR value of the descriptor, supposed to be the unicode string |
|
82 |
@leave KErrBadName if there is no room for trailing zero |
|
83 |
*/ |
|
84 |
LPCTSTR StrPtrZL(TDes16& aDes) |
|
85 |
{ |
|
86 |
if(aDes.MaxLength() - aDes.Length() < 1) |
|
87 |
User::Leave(KErrBadName); //-- no room for terminating zero |
|
88 |
||
89 |
return (LPCTSTR)aDes.PtrZ(); |
|
90 |
} |
|
91 |
||
92 |
||
93 |
||
94 |
// |
|
95 |
// Converts a TTime structure to a Windows/NT filetime. Assumes that aTime is a |
|
96 |
// UTC (system) time |
|
97 |
// |
|
98 |
static void timeToFileTimeL(const TTime& aTime,FILETIME* f) |
|
99 |
{ |
|
100 |
||
101 |
TDateTime dateTime=aTime.DateTime(); |
|
102 |
SYSTEMTIME t; |
|
103 |
#pragma warning( disable : 4244 ) // conversion from 'const int' to 'unsigned short', possible loss of data |
|
104 |
t.wYear=dateTime.Year(); |
|
105 |
t.wMonth=dateTime.Month()+1; |
|
106 |
t.wDay=dateTime.Day()+1; |
|
107 |
t.wDayOfWeek=(aTime.DayNoInWeek()+1)%7; |
|
108 |
t.wHour=dateTime.Hour(); |
|
109 |
t.wMinute=dateTime.Minute(); |
|
110 |
t.wSecond=dateTime.Second(); |
|
111 |
t.wMilliseconds=dateTime.MicroSecond()/1000; |
|
112 |
#pragma warning( default : 4244 ) // conversion from 'const int' to 'unsigned short', possible loss of data |
|
113 |
__ASSERT_ALWAYS(SystemTimeToFileTime(&t,f)==TRUE,User::Leave(KErrArgument)); |
|
114 |
} |
|
115 |
||
116 |
// |
|
117 |
// Convert Windows/NT file time to TTime |
|
118 |
// Assumes the NT file time is UTC |
|
119 |
// |
|
120 |
static void fileTimeToTime(FILETIME* f,TTime& aTime) |
|
121 |
{ |
|
122 |
SYSTEMTIME t; |
|
123 |
__ASSERT_ALWAYS(FileTimeToSystemTime(f,&t)==TRUE,Panic(EFileTimeToSystemTime)); |
|
124 |
aTime=TDateTime(t.wYear,TMonth(t.wMonth-1),t.wDay-1,t.wHour,t.wMinute,t.wSecond,t.wMilliseconds*1000); |
|
125 |
} |
|
126 |
||
127 |
// |
|
128 |
// Return the size and free space on a drive. |
|
129 |
// |
|
130 |
static TInt GetMediaSize(TInt aDriveNumber,TInt64& aSize,TInt64& aFree) |
|
131 |
{ |
|
132 |
||
133 |
TBuf<4> driveName; |
|
134 |
MapDrive(driveName,aDriveNumber); |
|
135 |
DWORD sectorsPerCluster; |
|
136 |
DWORD bytesPerSector; |
|
137 |
DWORD freeClusters; |
|
138 |
DWORD sizeClusters; |
|
139 |
// this function should be upgraded to GetDiskFreeSpaceEx |
|
140 |
BOOL b=Emulator::GetDiskFreeSpace((LPCTSTR)driveName.PtrZ(),§orsPerCluster,&bytesPerSector,&freeClusters,&sizeClusters); |
|
141 |
if (!b) |
|
142 |
return Emulator::LastError(); |
|
143 |
||
144 |
TInt64 bytesPerCluster=(TInt)(sectorsPerCluster*bytesPerSector); |
|
145 |
aSize=TInt64((TInt)sizeClusters)*bytesPerCluster; |
|
146 |
aFree=TInt64((TInt)freeClusters)*bytesPerCluster; |
|
147 |
return(KErrNone); |
|
148 |
} |
|
149 |
||
150 |
// |
|
151 |
// Return the volume name and uniqueID. |
|
152 |
// |
|
153 |
static TInt GetVolumeId(TInt aDriveNumber,TUint& aUniqueID) |
|
154 |
{ |
|
155 |
||
156 |
TBuf<4> driveName; |
|
157 |
MapDrive(driveName,aDriveNumber); |
|
158 |
DWORD uniqueID,componentLength,flags; |
|
159 |
BOOL b=Emulator::GetVolumeInformation((LPCTSTR)driveName.PtrZ(),NULL,0,&uniqueID,&componentLength,&flags,NULL,0); |
|
160 |
if (!b) |
|
161 |
return Emulator::LastError(); |
|
162 |
||
163 |
aUniqueID=uniqueID; |
|
164 |
return(KErrNone); |
|
165 |
} |
|
166 |
||
167 |
//######################################################################################################################### |
|
168 |
//## CLocalMountCB class implementation |
|
169 |
//######################################################################################################################### |
|
170 |
||
171 |
||
172 |
CLocalMountCB::CLocalMountCB() |
|
173 |
{ |
|
174 |
} |
|
175 |
||
176 |
CLocalMountCB::~CLocalMountCB() |
|
177 |
{ |
|
178 |
} |
|
179 |
||
180 |
||
181 |
// |
|
182 |
// Returns ETrue if the drive == EDriveZ |
|
183 |
// |
|
184 |
TBool CLocalMountCB::IsRomDrive() const |
|
185 |
{ |
|
186 |
// WINS emulated rom drive is Z: |
|
187 |
return(Drive().DriveNumber()==EDriveZ); |
|
188 |
} |
|
189 |
||
190 |
//------------------------------------------------------------------------------------------------------------------- |
|
191 |
||
192 |
/** |
|
193 |
Mount a volume. |
|
194 |
||
195 |
@param aForceMount Flag to indicate whether mount should be forced to succeed if an error occurs |
|
196 |
@leave KErrNoMemory,KErrNotReady,KErrCorrupt,KErrUnknown. |
|
197 |
*/ |
|
198 |
void CLocalMountCB::MountL(TBool /*aForceMount*/) |
|
199 |
{ |
|
200 |
TInt64 s,f; |
|
201 |
const TInt driveNum=Drive().DriveNumber(); |
|
202 |
User::LeaveIfError(GetMediaSize(driveNum,s,f)); |
|
203 |
||
204 |
iSize=s; |
|
205 |
if (driveNum==EDriveZ) |
|
206 |
iSize=4*1048576; |
|
207 |
||
208 |
User::LeaveIfError(GetVolumeId(driveNum,iUniqueID)); |
|
209 |
SetVolumeName(HBufC::NewL(0)); // all Win32 volumes are unnamed |
|
210 |
||
211 |
//-- assign default value, 4G-1 |
|
212 |
iMaxFileSizeSupported = ((TUint64)4 << 30)-1; |
|
213 |
||
214 |
{ |
|
215 |
//-- find out the maximal supported file size. For this we need to query the name of the windows filesystem that is |
|
216 |
//-- used for the emulated drive |
|
217 |
TBuf<20> bufWinDrive; |
|
218 |
MapDrive(bufWinDrive, Drive().DriveNumber()); |
|
219 |
ASSERT(bufWinDrive.Length() >= 3); |
|
220 |
||
221 |
TCHAR rootName[10]; |
|
222 |
TCHAR volName[30]; |
|
223 |
TCHAR volFSFileName[30]; |
|
224 |
DWORD volSerNum; |
|
225 |
DWORD volMaxCompLen; |
|
226 |
DWORD volFsFlags; |
|
227 |
||
228 |
memset(rootName, 0, sizeof(rootName)); |
|
229 |
wcsncpy(rootName, bufWinDrive.Ptr(), 3); //- something like "k:\\" |
|
230 |
||
231 |
BOOL b = GetVolumeInformation(rootName, volName, sizeof(volName)/sizeof(TCHAR), &volSerNum, &volMaxCompLen, &volFsFlags, volFSFileName, sizeof(volFSFileName)/sizeof(TCHAR)); |
|
232 |
if(b) |
|
233 |
{ |
|
234 |
if(_wcsicmp(volFSFileName, _TEXT("NTFS")) == 0) |
|
235 |
{//-- this is NTFS |
|
236 |
iMaxFileSizeSupported = 0xFFFFFFF0000; //-- max. file size for NTFS |
|
237 |
} |
|
238 |
else |
|
239 |
{//-- theoretically other than FAT & NTFS filesystem are possible.. Figure yourself. |
|
240 |
} } |
|
241 |
} |
|
242 |
||
243 |
||
244 |
} |
|
245 |
||
246 |
//------------------------------------------------------------------------------------------------------------------- |
|
247 |
/** |
|
248 |
Try remount this volume. Checks if the volume parameters remained the same as on original MountL() call, and |
|
249 |
if they are, re-initialises the mount. |
|
250 |
@return KErrNone if the remount was OK |
|
251 |
system-wide error code otherwise |
|
252 |
*/ |
|
253 |
TInt CLocalMountCB::ReMount() |
|
254 |
{ |
|
255 |
||
256 |
TInt d=Drive().DriveNumber(); |
|
257 |
TUint uniqueID; |
|
258 |
TInt r=GetVolumeId(d,uniqueID); |
|
259 |
if (r==KErrNone && uniqueID!=iUniqueID) |
|
260 |
r=KErrGeneral; |
|
261 |
return(r); |
|
262 |
} |
|
263 |
||
264 |
//------------------------------------------------------------------------------------------------------------------- |
|
265 |
void CLocalMountCB::Dismounted() |
|
266 |
{ |
|
267 |
} |
|
268 |
||
269 |
//------------------------------------------------------------------------------------------------------------------- |
|
270 |
// |
|
271 |
// Return the volume info. |
|
272 |
// |
|
273 |
void CLocalMountCB::VolumeL(TVolumeInfo& aVolume) const |
|
274 |
{ |
|
275 |
||
276 |
TInt64 s,f; |
|
277 |
TInt driveNum=Drive().DriveNumber(); |
|
278 |
User::LeaveIfError(GetMediaSize(driveNum,s,f)); |
|
279 |
if (driveNum==EDriveZ) |
|
280 |
aVolume.iFree=0; |
|
281 |
else |
|
282 |
aVolume.iFree=f; |
|
283 |
} |
|
284 |
||
285 |
//------------------------------------------------------------------------------------------------------------------- |
|
286 |
// |
|
287 |
// Set the volume label. Not supported on Win32 volumes |
|
288 |
// |
|
289 |
void CLocalMountCB::SetVolumeL(TDes&) |
|
290 |
{ |
|
291 |
||
292 |
User::Leave(IsRomDrive() ? KErrAccessDenied : KErrNotSupported); |
|
293 |
} |
|
294 |
||
295 |
//------------------------------------------------------------------------------------------------------------------- |
|
296 |
// |
|
297 |
// Return the address of the file if it is in rom |
|
298 |
// |
|
299 |
void CLocalMountCB::IsFileInRom(const TDesC& aName,TUint8*& aFileStart) |
|
300 |
{ |
|
301 |
||
302 |
aFileStart=NULL; |
|
303 |
if (!IsRomDrive()) |
|
304 |
return; |
|
305 |
||
306 |
TFileName n; |
|
307 |
if (MapFileName(n,Drive().DriveNumber(),aName)!=KErrNone) |
|
308 |
return; |
|
309 |
||
310 |
DWORD access=GENERIC_READ; |
|
311 |
DWORD share=FILE_SHARE_WRITE|FILE_SHARE_READ; |
|
312 |
DWORD create=OPEN_EXISTING; |
|
313 |
HANDLE h=Emulator::CreateFile((LPCTSTR)n.PtrZ(),access,share,NULL,create,FILE_FLAG_RANDOM_ACCESS,NULL); |
|
314 |
if (h==INVALID_HANDLE_VALUE) |
|
315 |
return; |
|
316 |
||
317 |
CLocalFileCB::RomAddress(aName, h, aFileStart); |
|
318 |
CloseHandle(h); |
|
319 |
} |
|
320 |
||
321 |
//------------------------------------------------------------------------------------------------------------------- |
|
322 |
/** |
|
323 |
Make a directory. |
|
324 |
@param aName full path to the directory to create. Name validity is checked by file server. |
|
325 |
*/ |
|
326 |
void CLocalMountCB::MkDirL(const TDesC& aName) |
|
327 |
{ |
|
328 |
||
329 |
if (IsRomDrive()) |
|
330 |
User::Leave(KErrAccessDenied); |
|
331 |
TFileName n; |
|
332 |
MapFileNameL(n,Drive().DriveNumber(),aName); |
|
333 |
BOOL b=Emulator::CreateDirectory(StrPtrZL(n),NULL); |
|
334 |
||
335 |
if (b) |
|
336 |
return; |
|
337 |
TInt r=Emulator::LastError(); |
|
338 |
if (r!=KErrAlreadyExists) |
|
339 |
User::Leave(r); |
|
340 |
TEntry e; |
|
341 |
EntryL(aName,e); |
|
342 |
||
343 |
if (e.IsDir()) |
|
344 |
User::Leave(KErrAlreadyExists); |
|
345 |
else |
|
346 |
User::Leave(KErrAccessDenied); |
|
347 |
} |
|
348 |
||
349 |
//------------------------------------------------------------------------------------------------------------------- |
|
350 |
/** |
|
351 |
Remove a directory. |
|
352 |
@param aName directory name |
|
353 |
*/ |
|
354 |
void CLocalMountCB::RmDirL(const TDesC& aName) |
|
355 |
{ |
|
356 |
||
357 |
if (IsRomDrive()) |
|
358 |
User::Leave(KErrAccessDenied); |
|
359 |
||
360 |
TFileName n; |
|
361 |
MapFileNameL(n,Drive().DriveNumber(),aName); |
|
362 |
BOOL b=Emulator::RemoveDirectory(StrPtrZL(n)); |
|
363 |
||
364 |
if (!b) |
|
365 |
User::Leave(Emulator::LastError()); |
|
366 |
} |
|
367 |
||
368 |
//------------------------------------------------------------------------------------------------------------------- |
|
369 |
// |
|
370 |
// Delete a file. |
|
371 |
// |
|
372 |
void CLocalMountCB::DeleteL(const TDesC& aName) |
|
373 |
{ |
|
374 |
||
375 |
if (IsRomDrive()) |
|
376 |
User::Leave(KErrAccessDenied); |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
377 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
378 |
//-- check entry attributes |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
379 |
TEntry entry; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
380 |
EntryL(aName, entry); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
381 |
if (entry.IsDir() || entry.IsReadOnly()) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
382 |
User::Leave(KErrAccessDenied); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
383 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
384 |
TFileName n; |
0 | 385 |
MapFileNameL(n,Drive().DriveNumber(),aName); |
386 |
BOOL b=Emulator::DeleteFile(StrPtrZL(n)); |
|
387 |
||
388 |
if (!b) |
|
389 |
User::Leave(Emulator::LastError()); |
|
390 |
} |
|
391 |
||
392 |
//------------------------------------------------------------------------------------------------------------------- |
|
393 |
// |
|
394 |
// Rename a file or directory. |
|
395 |
// |
|
396 |
void CLocalMountCB::RenameL(const TDesC& aOldName,const TDesC& aNewName) |
|
397 |
{ |
|
398 |
||
399 |
if (IsRomDrive()) |
|
400 |
User::Leave(KErrAccessDenied); |
|
401 |
TEntry entry; |
|
402 |
TRAPD(r,EntryL(aNewName,entry)); |
|
403 |
if (r!=KErrNone && r!=KErrNotFound) |
|
404 |
User::Leave(r); |
|
405 |
TFileName old; |
|
406 |
MapFileNameL(old,Drive().DriveNumber(),aOldName); |
|
407 |
TFileName n; |
|
408 |
MapFileNameL(n,Drive().DriveNumber(),aNewName); |
|
409 |
BOOL b=Emulator::MoveFile(StrPtrZL(old),StrPtrZL(n)); |
|
410 |
||
411 |
if (!b) |
|
412 |
User::Leave(Emulator::LastError()); |
|
413 |
} |
|
414 |
||
415 |
//------------------------------------------------------------------------------------------------------------------- |
|
416 |
void CLocalMountCB::ReplaceL(const TDesC& aOldName,const TDesC& aNewName) |
|
417 |
// |
|
418 |
// Delete aNewName if it exists and rename anOldName. |
|
419 |
// |
|
420 |
{ |
|
421 |
||
422 |
if (IsRomDrive()) |
|
423 |
User::Leave(KErrAccessDenied); |
|
424 |
TEntry entry; |
|
425 |
if(FileNamesIdentical(aOldName,aNewName)) |
|
426 |
{ |
|
427 |
return; |
|
428 |
} |
|
429 |
TRAPD(r,DeleteL(aNewName)); |
|
430 |
if (r!=KErrNotFound && r!=KErrNone) |
|
431 |
User::Leave(r); |
|
432 |
TFileName old; |
|
433 |
MapFileNameL(old,Drive().DriveNumber(),aOldName); |
|
434 |
TFileName n; |
|
435 |
MapFileNameL(n,Drive().DriveNumber(),aNewName); |
|
436 |
BOOL b=Emulator::MoveFile(StrPtrZL(old),StrPtrZL(n)); |
|
437 |
if (!b) |
|
438 |
User::Leave(Emulator::LastError()); |
|
439 |
} |
|
440 |
||
441 |
//------------------------------------------------------------------------------------------------------------------- |
|
442 |
// |
|
443 |
// Set and get file pointer for windows files |
|
444 |
// |
|
445 |
static DWORD SetFilePointerL(HANDLE hFile,LONG lDistanceToMove,DWORD dwMoveMethod) |
|
446 |
||
447 |
{ |
|
448 |
DWORD dwRet; |
|
449 |
||
450 |
dwRet=SetFilePointer(hFile,lDistanceToMove,0,dwMoveMethod); |
|
451 |
if (dwRet==KInvalidSetFilePointer) // INVALID_HANDLE_VALUE |
|
452 |
User::Leave(Emulator::LastError()); |
|
453 |
||
454 |
return (dwRet); |
|
455 |
} |
|
456 |
||
457 |
//------------------------------------------------------------------------------------------------------------------- |
|
458 |
// |
|
459 |
// Set and get file pointer for windows files |
|
460 |
// |
|
461 |
static DWORD SetFilePointer64L(HANDLE hFile, LARGE_INTEGER * lpDistanceToMove, DWORD dwMoveMethod) |
|
462 |
{ |
|
463 |
||
464 |
DWORD dwRet; |
|
465 |
||
466 |
dwRet=SetFilePointer(hFile, lpDistanceToMove->LowPart, &(lpDistanceToMove->HighPart), dwMoveMethod); |
|
467 |
||
468 |
TInt r = Emulator::LastError(); |
|
469 |
if ((KInvalidSetFilePointer==dwRet) && (r != NO_ERROR)) |
|
470 |
User::Leave(r); |
|
471 |
||
472 |
return (dwRet); |
|
473 |
} |
|
474 |
||
475 |
//------------------------------------------------------------------------------------------------------------------- |
|
476 |
/** |
|
477 |
Read file section without opening this file on a file server side. |
|
478 |
||
479 |
@param aName file name; all trailing dots from the name will be removed |
|
480 |
@param aFilePos start read position within a file |
|
481 |
@param aLength how many bytes to read; on return will be how many bytes actually read |
|
482 |
@param aDes local buffer desctriptor |
|
483 |
@param aMessage from file server, used to write data to the buffer in different address space. |
|
484 |
||
485 |
@leave on media read error |
|
486 |
*/ |
|
487 |
void CLocalMountCB::ReadSectionL(const TDesC& aName,TInt aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage) |
|
488 |
{ |
|
489 |
||
490 |
TFileName n; |
|
491 |
MapFileNameL(n,Drive().DriveNumber(),aName); |
|
492 |
||
493 |
WIN32_FIND_DATA d; |
|
494 |
HANDLE hFile=Emulator::FindFirstFile(StrPtrZL(n),&d); |
|
495 |
if (hFile==INVALID_HANDLE_VALUE) |
|
496 |
User::Leave(Emulator::LastError()); |
|
497 |
FOREVER |
|
498 |
{ |
|
499 |
TPtrC fileName((TText*)(&d.cFileName[0])); |
|
500 |
if (fileName!=_L(".") && fileName!=_L("..")) |
|
501 |
break; |
|
502 |
if (!Emulator::FindNextFile(hFile,&d)) |
|
503 |
{ |
|
504 |
TInt r = Emulator::LastError(); |
|
505 |
User::Leave(r == KErrEof ? KErrNotFound : r); |
|
506 |
} |
|
507 |
} |
|
508 |
||
509 |
FindClose(hFile); |
|
510 |
||
511 |
hFile=Emulator::CreateFile(StrPtrZL(n),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); |
|
512 |
if (hFile==INVALID_HANDLE_VALUE) |
|
513 |
return; |
|
514 |
||
515 |
DWORD dwSizeLow, dwSizeHigh; |
|
516 |
dwSizeLow=GetFileSize(hFile,&dwSizeHigh); |
|
517 |
TInt r = Emulator::LastError(); |
|
518 |
if((NO_ERROR != r) && (INVALID_FILE_SIZE == dwSizeLow)) |
|
519 |
User::Leave(r); |
|
520 |
||
521 |
// ReadSectionL can support only upto 2G as aPos is TInt! |
|
522 |
const TInt64 fileSize = MAKE_TINT64(dwSizeHigh, dwSizeHigh); |
|
523 |
if(fileSize > KMaxTInt) |
|
524 |
{ |
|
525 |
if (!CloseHandle(hFile)) |
|
526 |
User::Leave(Emulator::LastError()); |
|
527 |
||
528 |
User::Leave(KErrTooBig); |
|
529 |
} |
|
530 |
||
531 |
// Check that reading from aPos for aLength lies within the file |
|
532 |
// if aPos is within the file, and aLength is too long, read up to EOF |
|
533 |
// If aPos is beyond the file, return a zero length descriptor |
|
534 |
||
535 |
if ((TInt)dwSizeLow>=(aPos+aLength)) // Can read entire length requested from aPos |
|
536 |
SetFilePointerL(hFile,aPos,FILE_BEGIN); |
|
537 |
||
538 |
else if ((TInt)dwSizeLow>aPos) // Can read from aPos but not entire length requested |
|
539 |
{ |
|
540 |
SetFilePointerL(hFile,aPos,FILE_BEGIN); |
|
541 |
aLength=dwSizeLow-aPos; |
|
542 |
} |
|
543 |
else // Cannot read from aPos because it lies outside file |
|
544 |
{ // Close file and leave with KErrEof |
|
545 |
if (!CloseHandle(hFile)) |
|
546 |
User::Leave(Emulator::LastError()); |
|
547 |
||
548 |
User::Leave(KErrEof); |
|
549 |
} |
|
550 |
||
551 |
TBuf8<0x1000> buf; |
|
552 |
TInt pos=0; |
|
553 |
||
554 |
if (aMessage.Handle() == KLocalMessageHandle) |
|
555 |
((TPtr8* )aTrg)->SetLength(0); |
|
556 |
||
557 |
while (aLength) |
|
558 |
{ |
|
559 |
TInt readTotal=Min(aLength,buf.MaxLength()); |
|
560 |
DWORD ret; |
|
561 |
BOOL b=ReadFile(hFile,(TAny*)buf.Ptr(),readTotal,&ret,NULL); |
|
562 |
if (!b || ((TInt)ret!=readTotal)) |
|
563 |
User::Leave(Emulator::LastError()); |
|
564 |
buf.SetLength(ret); |
|
565 |
||
566 |
if(aMessage.Handle() == KLocalMessageHandle) |
|
567 |
((TPtr8* )aTrg)->Append(buf); |
|
568 |
else |
|
569 |
aMessage.WriteL(0,buf,pos); |
|
570 |
||
571 |
pos+=ret; |
|
572 |
if (((TInt)ret)<readTotal) |
|
573 |
break; |
|
574 |
aLength-=readTotal; |
|
575 |
} |
|
576 |
||
577 |
if (!CloseHandle(hFile)) |
|
578 |
User::Leave(Emulator::LastError()); |
|
579 |
} |
|
580 |
||
581 |
||
582 |
//------------------------------------------------------------------------------------------------------------------- |
|
583 |
// |
|
584 |
// Read the entry uid if present |
|
585 |
// |
|
586 |
void CLocalMountCB::ReadUidL(const TDesC& aName,TEntry& anEntry) const |
|
587 |
{ |
|
588 |
||
589 |
// First check to see if the first sixteen bytes form a valid UID |
|
590 |
TBuf<KMaxFileName + 1> fileName=aName; |
|
591 |
HANDLE hFile=Emulator::CreateFile(StrPtrZL(fileName),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); |
|
592 |
if (hFile==INVALID_HANDLE_VALUE) |
|
593 |
return; |
|
594 |
DWORD ret; |
|
595 |
TBuf8<sizeof(TCheckedUid)> checkedUidBuf; |
|
596 |
checkedUidBuf.SetLength(sizeof(TCheckedUid)); |
|
597 |
ReadFile(hFile,&checkedUidBuf[0],sizeof(TCheckedUid),&ret,NULL); |
|
598 |
if (ret!=sizeof(TCheckedUid)) |
|
599 |
goto close; |
|
600 |
{ |
|
601 |
TCheckedUid checkedUid(checkedUidBuf); |
|
602 |
if(checkedUid.UidType()!=TUidType(TUid::Null(),TUid::Null(),TUid::Null())) |
|
603 |
{ |
|
604 |
anEntry.iType=checkedUid.UidType(); |
|
605 |
goto close; |
|
606 |
} |
|
607 |
} |
|
608 |
||
609 |
//Look at PE file for UID section |
|
610 |
{ |
|
611 |
const TInt KPeHeaderAddrAddr=0x3c; |
|
612 |
const TInt KPeHeaderAddrSize=0x01; |
|
613 |
const TInt KNumberOfSectionsOffset=0x06; |
|
614 |
const TInt KNumberOfSectionsSize=0x02; |
|
615 |
const TInt KSectionTableOffset=0xf8; |
|
616 |
const TInt KSectionHeaderSize=0x28; |
|
617 |
const TInt KSectionNameLength=0x08; |
|
618 |
const TInt KPtrToRawDataOffset=0x14; |
|
619 |
const TInt KPtrToRawDataSize=0x04; |
|
620 |
const TText8 peText[4]={'P','E',0,0}; |
|
621 |
const TText8 uidText[8]={'.','S','Y','M','B','I','A','N'}; |
|
622 |
||
623 |
//Read address of start of PE header |
|
624 |
if (SetFilePointer(hFile,KPeHeaderAddrAddr,0,FILE_BEGIN)==KInvalidSetFilePointer) |
|
625 |
goto close; |
|
626 |
TInt peAddr=0; |
|
627 |
ReadFile(hFile,&peAddr,KPeHeaderAddrSize,&ret,NULL); |
|
628 |
if (ret!=KPeHeaderAddrSize) |
|
629 |
goto close; |
|
630 |
||
631 |
//Check it really is the start of PE header |
|
632 |
if (SetFilePointer(hFile,peAddr,0,FILE_BEGIN)==KInvalidSetFilePointer) |
|
633 |
goto close; |
|
634 |
TText8 text[4]; |
|
635 |
ReadFile(hFile,text,4,&ret,NULL); |
|
636 |
if (*(TInt32*)text!=*(TInt32*)peText) |
|
637 |
goto close; |
|
638 |
||
639 |
//Read number of sections |
|
640 |
if (SetFilePointer(hFile,peAddr+KNumberOfSectionsOffset,0,FILE_BEGIN)==KInvalidSetFilePointer) |
|
641 |
goto close; |
|
642 |
TInt sections=0; |
|
643 |
ReadFile(hFile,§ions,KNumberOfSectionsSize,&ret,NULL); |
|
644 |
if (ret!=KNumberOfSectionsSize) |
|
645 |
goto close; |
|
646 |
||
647 |
//Go through section headers looking for UID section |
|
648 |
if (SetFilePointer(hFile,peAddr+KSectionTableOffset,0,FILE_BEGIN)==KInvalidSetFilePointer) |
|
649 |
goto close; |
|
650 |
TInt i=0; |
|
651 |
for(;i<sections;i++) |
|
652 |
{ |
|
653 |
TText8 name[KSectionNameLength]; |
|
654 |
ReadFile(hFile,name,KSectionNameLength,&ret,NULL); |
|
655 |
if (ret!=KSectionNameLength) |
|
656 |
goto close; |
|
657 |
if (*(TInt64*)name==*(TInt64*)uidText) |
|
658 |
break; |
|
659 |
if (SetFilePointer(hFile,KSectionHeaderSize-KSectionNameLength,0,FILE_CURRENT)==KInvalidSetFilePointer) |
|
660 |
goto close; |
|
661 |
} |
|
662 |
if (i==sections) |
|
663 |
goto close; |
|
664 |
||
665 |
//Read RVA/Offset |
|
666 |
if (SetFilePointer(hFile,KPtrToRawDataOffset-KSectionNameLength,0,FILE_CURRENT)==KInvalidSetFilePointer) |
|
667 |
goto close; |
|
668 |
TInt uidOffset; |
|
669 |
ReadFile(hFile,&uidOffset,KPtrToRawDataSize,&ret,NULL); |
|
670 |
if (ret!=KPtrToRawDataSize) |
|
671 |
goto close; |
|
672 |
||
673 |
//Read UIDs! |
|
674 |
if (SetFilePointer(hFile,uidOffset,0,FILE_BEGIN)==KInvalidSetFilePointer) |
|
675 |
User::Leave(KErrGeneral); |
|
676 |
||
677 |
TEmulatorImageHeader header; |
|
678 |
ReadFile(hFile,&header,sizeof(header),&ret,NULL); |
|
679 |
if (ret==sizeof(header)) |
|
680 |
anEntry.iType=*(TUidType*)&header; |
|
681 |
} |
|
682 |
//Close file |
|
683 |
close: |
|
684 |
if (!CloseHandle(hFile)) |
|
685 |
User::Leave(Emulator::LastError()); |
|
686 |
} |
|
687 |
||
688 |
//------------------------------------------------------------------------------------------------------------------- |
|
689 |
/** |
|
690 |
Try to find a directory entry by the given name and path. |
|
691 |
This method _must_ leave if the entry is not found. See the caller. |
|
692 |
||
693 |
@param aName path to the directory object. all trailing dots from the name will be removed. |
|
694 |
@param anEntry on return will contain the entry data |
|
695 |
||
696 |
@leave KErrPathNotFound if there is no path to the aName |
|
697 |
KErrNotFound if the entry corresponding to the aName is not found |
|
698 |
system-wide erorr code of media read failure. |
|
699 |
*/ |
|
700 |
void CLocalMountCB::EntryL(const TDesC& aName,TEntry& anEntry) const |
|
701 |
{ |
|
702 |
||
703 |
TFileName n; |
|
704 |
MapFileNameL(n,Drive().DriveNumber(),aName); |
|
705 |
WIN32_FIND_DATA d; |
|
706 |
HANDLE h=Emulator::FindFirstFile(StrPtrZL(n),&d); |
|
707 |
if (h==INVALID_HANDLE_VALUE) |
|
708 |
User::Leave(Emulator::LastError()); |
|
709 |
FOREVER |
|
710 |
{ |
|
711 |
TPtrC fileName((TText*)(&d.cFileName[0])); |
|
712 |
if (fileName!=_L(".") && fileName!=_L("..")) |
|
713 |
break; |
|
714 |
if (!Emulator::FindNextFile(h,&d)) |
|
715 |
{ |
|
716 |
TInt r = Emulator::LastError(); |
|
717 |
User::Leave(r == KErrEof ? KErrNotFound : r); |
|
718 |
} |
|
719 |
} |
|
720 |
FindClose(h); |
|
721 |
anEntry.iName.Des()=(TText*)(&d.cFileName[0]); |
|
722 |
anEntry.iAtt=d.dwFileAttributes&KEntryAttMaskSupported; |
|
723 |
if (IsRomDrive()) |
|
724 |
anEntry.iAtt|=KEntryAttReadOnly; |
|
725 |
||
726 |
anEntry.SetFileSize(MAKE_TINT64(d.nFileSizeHigh,d.nFileSizeLow)); |
|
727 |
||
728 |
fileTimeToTime(&d.ftLastWriteTime,anEntry.iModified); |
|
729 |
ReadUidL(n,anEntry); |
|
730 |
} |
|
731 |
||
732 |
//------------------------------------------------------------------------------------------------------------------- |
|
733 |
/** |
|
734 |
Set directory entry details. |
|
735 |
@param aName entry name; all trailing dots from the name will be removed |
|
736 |
@param aTime entry modification time (and last access as well) |
|
737 |
@param aSetAttMask entry attributes OR mask |
|
738 |
@param aClearAttMask entry attributes AND mask |
|
739 |
||
740 |
*/ |
|
741 |
void CLocalMountCB::SetEntryL(const TDesC& aName,const TTime& aTime,TUint aSetAttMask,TUint aClearAttMask) |
|
742 |
{ |
|
743 |
||
744 |
if (IsRomDrive()) |
|
745 |
User::Leave(KErrAccessDenied); |
|
746 |
TFileName n; |
|
747 |
MapFileNameL(n,Drive().DriveNumber(),aName); |
|
748 |
TUint setAttMask=aSetAttMask&KEntryAttMaskSupported; |
|
749 |
DWORD att=Emulator::GetFileAttributes(StrPtrZL(n)); |
|
750 |
if (att==0xffffffffu) |
|
751 |
User::Leave(Emulator::LastError()); |
|
752 |
||
753 |
if (setAttMask|aClearAttMask) |
|
754 |
{ |
|
755 |
att|=setAttMask; |
|
756 |
att&=(~aClearAttMask); |
|
757 |
if (!Emulator::SetFileAttributes((LPCTSTR)n.Ptr(),att)) |
|
758 |
User::Leave(Emulator::LastError()); |
|
759 |
} |
|
760 |
||
761 |
if (aSetAttMask&KEntryAttModified) |
|
762 |
{ |
|
763 |
FILETIME f; |
|
764 |
timeToFileTimeL(aTime,&f); |
|
765 |
||
766 |
if (att&KEntryAttReadOnly) |
|
767 |
{ |
|
768 |
DWORD writeableAtt=att&(~KEntryAttReadOnly); |
|
769 |
if (!Emulator::SetFileAttributes((LPCTSTR)n.Ptr(),writeableAtt)) |
|
770 |
User::Leave(Emulator::LastError()); |
|
771 |
} |
|
772 |
||
773 |
HANDLE h; |
|
774 |
if (att&KEntryAttDir) |
|
775 |
{ |
|
776 |
h=Emulator::CreateFile((LPCTSTR)n.Ptr(),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_DIRECTORY|FILE_FLAG_BACKUP_SEMANTICS, NULL); |
|
777 |
if (h==INVALID_HANDLE_VALUE) |
|
778 |
User::Leave(Emulator::LastError()); |
|
779 |
} |
|
780 |
else |
|
781 |
{ |
|
782 |
h=Emulator::CreateFile((LPCTSTR)n.Ptr(),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL); |
|
783 |
if (h==INVALID_HANDLE_VALUE) |
|
784 |
User::Leave(Emulator::LastError()); |
|
785 |
} |
|
786 |
||
787 |
if (!SetFileTime(h,NULL,&f,&f)) |
|
788 |
{ |
|
789 |
TInt error = Emulator::LastError(); |
|
790 |
CloseHandle(h); |
|
791 |
User::Leave(error); |
|
792 |
} |
|
793 |
||
794 |
if (!CloseHandle(h)) |
|
795 |
User::Leave(Emulator::LastError()); |
|
796 |
||
797 |
if ((att&KEntryAttReadOnly) && !Emulator::SetFileAttributes((LPCTSTR)n.Ptr(),att)) |
|
798 |
User::Leave(Emulator::LastError()); |
|
799 |
} |
|
800 |
} |
|
801 |
||
802 |
//------------------------------------------------------------------------------------------------------------------- |
|
803 |
/** |
|
804 |
Open/Create/Replace a file on the current mount. |
|
805 |
||
806 |
@param aName file name; all trailing dots from the name will be removed |
|
807 |
@param aMode File open mode, See TFileMode |
|
808 |
@param anOpen specifies action: open, create or replace the file |
|
809 |
@param aFile pointer to the CFileCB object to populate |
|
810 |
||
811 |
*/ |
|
812 |
void CLocalMountCB::FileOpenL(const TDesC& aName,TUint aMode,TFileOpen anOpen,CFileCB* aFile) |
|
813 |
{ |
|
814 |
||
815 |
if (IsRomDrive() && (anOpen!=EFileOpen || (aMode&EFileWrite))) |
|
816 |
User::Leave(KErrAccessDenied); |
|
817 |
TFileName n; |
|
818 |
MapFileNameL(n,Drive().DriveNumber(),aName); |
|
819 |
||
820 |
DWORD access=GENERIC_READ|GENERIC_WRITE; |
|
821 |
DWORD share=FILE_SHARE_WRITE|FILE_SHARE_READ; |
|
822 |
DWORD create=0; |
|
823 |
switch (anOpen) |
|
824 |
{ |
|
825 |
case EFileOpen: create=OPEN_EXISTING; break; |
|
826 |
case EFileCreate: create=CREATE_NEW; break; |
|
827 |
case EFileReplace: create=CREATE_ALWAYS; break; |
|
828 |
} |
|
829 |
||
830 |
HANDLE h=Emulator::CreateFile(StrPtrZL(n),access,share,NULL,create,FILE_FLAG_RANDOM_ACCESS,NULL); |
|
831 |
||
832 |
if((h==INVALID_HANDLE_VALUE) && !(aMode&EFileWrite)) |
|
833 |
{ |
|
834 |
// If windows will not allow write access and it was not requested then open for read only |
|
835 |
access=GENERIC_READ; |
|
836 |
h=Emulator::CreateFile(StrPtrZL(n),access,share,NULL,create,FILE_FLAG_RANDOM_ACCESS,NULL); |
|
837 |
} |
|
838 |
||
839 |
if (h==INVALID_HANDLE_VALUE) |
|
840 |
User::Leave(Emulator::LastError()); |
|
841 |
CLocalFileCB& file=(*((CLocalFileCB*)aFile)); |
|
842 |
file.SetHandle(h); |
|
843 |
||
844 |
BY_HANDLE_FILE_INFORMATION info; |
|
845 |
if (!GetFileInformationByHandle(h,&info)) |
|
846 |
User::Leave(Emulator::LastError()); |
|
847 |
||
848 |
const TUint64 fileSize = MAKE_TUINT64(info.nFileSizeHigh, info.nFileSizeLow); |
|
849 |
||
850 |
// Check on file size |
|
851 |
if(MaxFileSizeSupported() < fileSize) |
|
852 |
User::Leave(KErrTooBig); |
|
853 |
||
854 |
file.SetMaxSupportedSize(MaxFileSizeSupported()); |
|
855 |
file.SetSize64(fileSize, EFalse); |
|
856 |
file.SetAtt(info.dwFileAttributes&KEntryAttMaskSupported); |
|
857 |
||
858 |
// if (IsRomDrive()) |
|
859 |
// file.iAtt|=KEntryAttReadOnly; |
|
860 |
TTime tempTime=file.Modified(); |
|
861 |
fileTimeToTime(&info.ftLastWriteTime,tempTime); |
|
862 |
file.SetModified(tempTime); |
|
863 |
} |
|
864 |
||
865 |
void AppendAsteriskL(TDes& aDes) |
|
866 |
{ |
|
867 |
if (aDes.Length()==aDes.MaxLength()) |
|
868 |
User::Leave(KErrBadName); |
|
869 |
aDes.Append('*'); |
|
870 |
} |
|
871 |
||
872 |
//------------------------------------------------------------------------------------------------------------------- |
|
873 |
/** |
|
874 |
Open a directory on the current mount. |
|
875 |
||
876 |
@param aName path to the object in the directory we want to open; all trailing dots from the name will be removed |
|
877 |
@param aDir dir. CB to be filled in. |
|
878 |
||
879 |
If there is no such a path, this method must leave with KErrPathNotFound |
|
880 |
||
881 |
@leave KErrPathNotFound if thereis no such path |
|
882 |
@leave error code on media read fault |
|
883 |
*/ |
|
884 |
void CLocalMountCB::DirOpenL(const TDesC& aName,CDirCB* aDir) |
|
885 |
{ |
|
886 |
||
887 |
TFileName n; |
|
888 |
TParse parse; |
|
889 |
MapFileNameL(n,Drive().DriveNumber(),aName); |
|
890 |
parse.Set(n,NULL,NULL); |
|
891 |
n=parse.DriveAndPath(); |
|
892 |
AppendAsteriskL(n); |
|
893 |
WIN32_FIND_DATA info; |
|
894 |
HANDLE h=Emulator::FindFirstFile(StrPtrZL(n),&info); |
|
895 |
if (h==INVALID_HANDLE_VALUE) |
|
896 |
{ |
|
897 |
TInt error=Emulator::LastError(); |
|
898 |
TParse parser; |
|
899 |
TInt r=parser.Set(n,NULL,NULL); |
|
900 |
if (r!=KErrNone) |
|
901 |
User::Leave(r); |
|
902 |
if (!parser.IsRoot() || Drive().DriveNumber()!=0 || error!=KErrNotFound) |
|
903 |
User::Leave(error); |
|
904 |
h=NULL; |
|
905 |
} |
|
906 |
CLocalDirCB& dir=(*((CLocalDirCB*)aDir)); |
|
907 |
dir.SetHandle(h); |
|
908 |
dir.SetPending(ETrue); |
|
909 |
dir.iEntry.iName.Des()=(TText*)(&info.cFileName[0]); |
|
910 |
dir.iEntry.iAtt=info.dwFileAttributes&KEntryAttMaskSupported; |
|
911 |
||
912 |
const TInt64 fileSize = MAKE_TINT64(info.nFileSizeHigh,info.nFileSizeLow); |
|
913 |
dir.iEntry.SetFileSize(fileSize); |
|
914 |
||
915 |
n=parse.FullName(); |
|
916 |
if (parse.NameAndExt().Length()==0) |
|
917 |
AppendAsteriskL(n); |
|
918 |
dir.SetFullName(n); |
|
919 |
fileTimeToTime(&info.ftLastWriteTime,dir.iEntry.iModified); |
|
920 |
} |
|
921 |
||
922 |
//------------------------------------------------------------------------------------------------------------------- |
|
923 |
// |
|
924 |
// Read directly from disk |
|
925 |
// |
|
926 |
void CLocalMountCB::RawReadL(TInt64 /*aPos*/,TInt /*aLength*/,const TAny* /*aDes*/,TInt /*anOffset*/,const RMessagePtr2& /*aMessage*/) const |
|
927 |
{ |
|
928 |
User::Leave(KErrNotSupported); |
|
929 |
} |
|
930 |
||
931 |
//------------------------------------------------------------------------------------------------------------------- |
|
932 |
// |
|
933 |
// Write directly to disk |
|
934 |
// |
|
935 |
void CLocalMountCB::RawWriteL(TInt64 /*aPos*/,TInt /*aLength*/,const TAny* /*aDes*/ ,TInt /*anOffset*/,const RMessagePtr2& /*aMessage*/) |
|
936 |
{ |
|
937 |
User::Leave(KErrNotSupported); |
|
938 |
} |
|
939 |
||
940 |
//------------------------------------------------------------------------------------------------------------------- |
|
941 |
// |
|
942 |
// Get the short name associated with aLongName |
|
943 |
// |
|
944 |
void CLocalMountCB::GetShortNameL(const TDesC& aLongName,TDes& aShortName) |
|
945 |
{ |
|
946 |
||
947 |
if (IsRomDrive()) |
|
948 |
User::Leave(KErrNotSupported); |
|
949 |
||
950 |
TFileName n; |
|
951 |
MapFileNameL(n,Drive().DriveNumber(),aLongName); |
|
952 |
WIN32_FIND_DATA d; |
|
953 |
HANDLE h=Emulator::FindFirstFile(StrPtrZL(n),&d); |
|
954 |
if (h==INVALID_HANDLE_VALUE) |
|
955 |
User::Leave(Emulator::LastError()); |
|
956 |
FindClose(h); |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
957 |
if (d.cAlternateFileName[0]) // we have a dos name too |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
958 |
aShortName=(TText*)(&d.cAlternateFileName[0]); |
0 | 959 |
else |
960 |
aShortName=(TText*)(&d.cFileName[0]); |
|
961 |
} |
|
962 |
||
963 |
//------------------------------------------------------------------------------------------------------------------- |
|
964 |
// |
|
965 |
// Get the short name associated with aLongName |
|
966 |
// |
|
967 |
void CLocalMountCB::GetLongNameL(const TDesC& aShortName,TDes& aLongName) |
|
968 |
{ |
|
969 |
||
970 |
if (IsRomDrive()) |
|
971 |
User::Leave(KErrNotSupported); |
|
972 |
||
973 |
TFileName n; |
|
974 |
MapFileNameL(n,Drive().DriveNumber(),aShortName); |
|
975 |
WIN32_FIND_DATA d; |
|
976 |
HANDLE h=Emulator::FindFirstFile(StrPtrZL(n),&d); |
|
977 |
if (h==INVALID_HANDLE_VALUE) |
|
978 |
User::Leave(Emulator::LastError()); |
|
979 |
FindClose(h); |
|
980 |
aLongName=(TText*)(&d.cFileName[0]); |
|
981 |
} |
|
982 |
||
983 |
//------------------------------------------------------------------------------------------------------------------- |
|
984 |
/** |
|
985 |
Reports whether the specified interface is supported - if it is, |
|
986 |
the supplied interface object is modified to it |
|
987 |
||
988 |
@param aInterfaceId The interface of interest |
|
989 |
@param aInterface The interface object |
|
990 |
@return KErrNone if the interface is supported, otherwise KErrNotFound |
|
991 |
||
992 |
@see CMountCB::GetInterface() |
|
993 |
*/ |
|
994 |
TInt CLocalMountCB::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput) |
|
995 |
{ |
|
996 |
switch(aInterfaceId) |
|
997 |
{ |
|
998 |
case EFileExtendedInterface: |
|
999 |
((CMountCB::MFileExtendedInterface*&) aInterface) = this; |
|
1000 |
return KErrNone; |
|
1001 |
||
1002 |
case ELocalBufferSupport: |
|
1003 |
// CLocalMountCB doesn't ever use any extensions? |
|
1004 |
// - seems to not have any iProxyDrive or LocalDrive() or similar, |
|
1005 |
// so we'll just return KErrNone here. |
|
1006 |
return KErrNone; |
|
1007 |
||
1008 |
default: |
|
1009 |
return CMountCB::GetInterface(aInterfaceId,aInterface,aInput); |
|
1010 |
} |
|
1011 |
} |
|
1012 |
||
1013 |
//------------------------------------------------------------------------------------------------------------------- |
|
1014 |
TInt CLocalMountCB::LocalBufferSupport() |
|
1015 |
{ |
|
1016 |
TAny* dummyInterface = NULL; |
|
1017 |
TAny* dummyInput = NULL; |
|
1018 |
return GetInterface(ELocalBufferSupport,dummyInterface,dummyInput); |
|
1019 |
} |
|
1020 |
||
1021 |
//------------------------------------------------------------------------------------------------------------------- |
|
1022 |
/** |
|
1023 |
Read file section without opening this file on a file server side. |
|
1024 |
||
1025 |
@param aName file name; all trailing dots from the name will be removed |
|
1026 |
@param aFilePos start read position within a file |
|
1027 |
@param aLength how many bytes to read; on return will be how many bytes actually read |
|
1028 |
@param aDes local buffer desctriptor |
|
1029 |
@param aMessage from file server, used to write data to the buffer in different address space. |
|
1030 |
||
1031 |
@leave on media read error |
|
1032 |
*/ |
|
1033 |
void CLocalMountCB::ReadSection64L(const TDesC& aName, TInt64 aPos, TAny* aTrg, TInt aLength, const RMessagePtr2& aMessage) |
|
1034 |
{ |
|
1035 |
TFileName n; |
|
1036 |
MapFileNameL(n,Drive().DriveNumber(),aName); |
|
1037 |
||
1038 |
WIN32_FIND_DATA d; |
|
1039 |
HANDLE hFile=Emulator::FindFirstFile(StrPtrZL(n),&d); |
|
1040 |
if (hFile==INVALID_HANDLE_VALUE) |
|
1041 |
User::Leave(Emulator::LastError()); |
|
1042 |
||
1043 |
FOREVER |
|
1044 |
{ |
|
1045 |
TPtrC fileName((TText*)(&d.cFileName[0])); |
|
1046 |
if (fileName!=_L(".") && fileName!=_L("..")) |
|
1047 |
break; |
|
1048 |
if (!Emulator::FindNextFile(hFile,&d)) |
|
1049 |
{ |
|
1050 |
TInt r = Emulator::LastError(); |
|
1051 |
User::Leave(r == KErrEof ? KErrNotFound : r); |
|
1052 |
} |
|
1053 |
} |
|
1054 |
||
1055 |
FindClose(hFile); |
|
1056 |
||
1057 |
hFile=Emulator::CreateFile(StrPtrZL(n),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); |
|
1058 |
if (hFile==INVALID_HANDLE_VALUE) |
|
1059 |
return; |
|
1060 |
||
1061 |
DWORD dwSizeLow, dwSizeHigh; |
|
1062 |
dwSizeLow=GetFileSize(hFile,&dwSizeHigh); |
|
1063 |
TInt r = Emulator::LastError(); |
|
1064 |
if((NO_ERROR != r) && (INVALID_FILE_SIZE == dwSizeLow)) |
|
1065 |
User::Leave(r); |
|
1066 |
||
1067 |
// Check on file size |
|
1068 |
const TInt64 fileSize = MAKE_TINT64(dwSizeHigh, dwSizeLow); |
|
1069 |
if(MaxFileSizeSupported() < (TUint64)fileSize) |
|
1070 |
{ |
|
1071 |
if (!CloseHandle(hFile)) |
|
1072 |
User::Leave(Emulator::LastError()); |
|
1073 |
||
1074 |
User::Leave(KErrTooBig); |
|
1075 |
} |
|
1076 |
||
1077 |
// Check that reading from aPos for aLength lies within the file |
|
1078 |
// if aPos is within the file, and aLength is too long, read up to EOF |
|
1079 |
// If aPos is beyond the file, return a zero length descriptor |
|
1080 |
||
1081 |
if (fileSize>=aPos+aLength) // Can read entire length requested from aPos |
|
1082 |
SetFilePointer64L(hFile,(LARGE_INTEGER *)&aPos,FILE_BEGIN); |
|
1083 |
||
1084 |
else if (fileSize>aPos) // Can read from aPos but not entire length requested |
|
1085 |
{ |
|
1086 |
SetFilePointer64L(hFile,(LARGE_INTEGER *)&aPos,FILE_BEGIN); |
|
1087 |
aLength=(TInt)(fileSize-aPos); |
|
1088 |
} |
|
1089 |
else // Cannot read from aPos because it lies outside file |
|
1090 |
{ // Close file and leave with KErrEof |
|
1091 |
if (!CloseHandle(hFile)) |
|
1092 |
User::Leave(Emulator::LastError()); |
|
1093 |
||
1094 |
User::Leave(KErrEof); |
|
1095 |
} |
|
1096 |
||
1097 |
TBuf8<0x1000> buf; |
|
1098 |
TInt pos=0; |
|
1099 |
||
1100 |
if (aMessage.Handle() == KLocalMessageHandle) |
|
1101 |
((TPtr8* )aTrg)->SetLength(0); |
|
1102 |
||
1103 |
while (aLength) |
|
1104 |
{ |
|
1105 |
TInt readTotal=Min(aLength,buf.MaxLength()); |
|
1106 |
DWORD ret; |
|
1107 |
BOOL b=ReadFile(hFile,(TAny*)buf.Ptr(),readTotal,&ret,NULL); |
|
1108 |
if (!b || ((TInt)ret!=readTotal)) |
|
1109 |
User::Leave(Emulator::LastError()); |
|
1110 |
buf.SetLength(ret); |
|
1111 |
||
1112 |
if(aMessage.Handle() == KLocalMessageHandle) |
|
1113 |
((TPtr8* )aTrg)->Append(buf); |
|
1114 |
else |
|
1115 |
aMessage.WriteL(0,buf,pos); |
|
1116 |
||
1117 |
pos+=ret; |
|
1118 |
if (((TInt)ret)<readTotal) |
|
1119 |
break; |
|
1120 |
aLength-=readTotal; |
|
1121 |
} |
|
1122 |
||
1123 |
if (!CloseHandle(hFile)) |
|
1124 |
User::Leave(Emulator::LastError()); |
|
1125 |
} |
|
1126 |
||
1127 |
//------------------------------------------------------------------------------------------------------------------- |
|
1128 |
||
1129 |
/** |
|
1130 |
CLocalMountCB control method. |
|
1131 |
@param aLevel specifies the operation to perfrom on the mount |
|
1132 |
@param aOption specific option for the given operation |
|
1133 |
@param aParam pointer to generic parameter, its meaning depends on aLevel and aOption |
|
1134 |
||
1135 |
@return standard error code. |
|
1136 |
*/ |
|
1137 |
||
1138 |
TInt CLocalMountCB::MountControl(TInt aLevel, TInt aOption, TAny* aParam) |
|
1139 |
{ |
|
1140 |
//-- File System - specific queries |
|
1141 |
if(aLevel == EMountFsParamQuery && aOption == ESQ_GetMaxSupportedFileSize) |
|
1142 |
{//-- this is a query to provide the max. supported file size; aParam is a pointer to TUint64 to return the value |
|
1143 |
*(TUint64*)aParam = MaxFileSizeSupported(); |
|
1144 |
return KErrNone; |
|
1145 |
} |
|
1146 |
||
1147 |
return KErrNotSupported; |
|
1148 |
} |
|
1149 |
||
1150 |
//######################################################################################################################### |
|
1151 |
//## CLocalFileCB class implementation |
|
1152 |
//######################################################################################################################### |
|
1153 |
||
1154 |
||
1155 |
CLocalFileCB::CLocalFileCB() |
|
1156 |
{ |
|
1157 |
} |
|
1158 |
||
1159 |
CLocalFileCB::~CLocalFileCB() |
|
1160 |
{ |
|
1161 |
||
1162 |
if (iAtt&KEntryAttModified) |
|
1163 |
{ |
|
1164 |
TRAPD(ret,FlushDataL()); |
|
1165 |
// if (ret!=KErrNone) // Can fail if floppy disk is removed |
|
1166 |
// Panic(EFileClose); // Ignore error |
|
1167 |
} |
|
1168 |
if (iWinHandle!=NULL && !CloseHandle(iWinHandle)) |
|
1169 |
Panic(EFileClose); |
|
1170 |
} |
|
1171 |
||
1172 |
//------------------------------------------------------------------------------------------------------------------- |
|
1173 |
// |
|
1174 |
// Returns ETrue if the drive number == EDriveZ |
|
1175 |
// |
|
1176 |
TBool CLocalFileCB::IsRomDrive() const |
|
1177 |
{ |
|
1178 |
||
1179 |
// WINS emulated rom drive is Z: |
|
1180 |
return(((CLocalFileCB*)this)->Mount().Drive().DriveNumber()==EDriveZ); |
|
1181 |
} |
|
1182 |
||
1183 |
//------------------------------------------------------------------------------------------------------------------- |
|
1184 |
// |
|
1185 |
// Check that the file pointer iCurrentPos is positioned correctly |
|
1186 |
// in relation to the Win32 file pointer |
|
1187 |
// |
|
1188 |
void CLocalFileCB::CheckPosL(TInt64 aPos) |
|
1189 |
{ |
|
1190 |
// Get the current Win32 file pointer position |
|
1191 |
LARGE_INTEGER pos; |
|
1192 |
pos.QuadPart = 0; |
|
1193 |
DWORD position=SetFilePointer(iWinHandle,pos.LowPart,&pos.HighPart,FILE_CURRENT); |
|
1194 |
TInt r = Emulator::LastError(); |
|
1195 |
if ((KInvalidSetFilePointer == position) && (r != NO_ERROR)) |
|
1196 |
User::Leave(r); |
|
1197 |
// Set iCurrentPos and Win32 file pointers to aPos if they are different to each |
|
1198 |
// other or different to aPos |
|
1199 |
if ((pos.QuadPart!=iCurrentPos) || (iCurrentPos!=aPos)) |
|
1200 |
{ |
|
1201 |
iCurrentPos=(-1); |
|
1202 |
pos.QuadPart = aPos; |
|
1203 |
position = SetFilePointer(iWinHandle,pos.LowPart,&pos.HighPart,FILE_BEGIN); |
|
1204 |
r = Emulator::LastError(); |
|
1205 |
if ((KInvalidSetFilePointer == position) && (r != NO_ERROR)) |
|
1206 |
User::Leave(r); |
|
1207 |
iCurrentPos=aPos; |
|
1208 |
} |
|
1209 |
} |
|
1210 |
||
1211 |
//------------------------------------------------------------------------------------------------------------------- |
|
1212 |
void CLocalFileCB::ReadL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage) |
|
1213 |
{ |
|
1214 |
ReadL((TInt64)aPos, aLength, (TDes8*)aDes, aMessage, 0); |
|
1215 |
} |
|
1216 |
||
1217 |
//------------------------------------------------------------------------------------------------------------------- |
|
1218 |
void CLocalFileCB::WriteL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage) |
|
1219 |
{ |
|
1220 |
WriteL((TInt64)aPos, aLength, (TDesC8*)aDes, aMessage, 0); |
|
1221 |
} |
|
1222 |
||
1223 |
struct SRomMap |
|
1224 |
{ |
|
1225 |
HBufC* iName; |
|
1226 |
TUint8* iAddr; |
|
1227 |
}; |
|
1228 |
//------------------------------------------------------------------------------------------------------------------- |
|
1229 |
||
1230 |
TInt CLocalFileCB::RomAddress(const TDesC& aName, HANDLE aFile, TUint8*& aAddr) |
|
1231 |
{ |
|
1232 |
static CArrayFixSeg<SRomMap>* gRomMap = new CArrayFixSeg<SRomMap>(64); |
|
1233 |
for (TInt ii=0; ii<gRomMap->Count(); ii++) |
|
1234 |
{ |
|
1235 |
if (*gRomMap->At(ii).iName == aName) |
|
1236 |
{ |
|
1237 |
aAddr = gRomMap->At(ii).iAddr; |
|
1238 |
return KErrNone; |
|
1239 |
} |
|
1240 |
} |
|
1241 |
||
1242 |
HANDLE fileMapping=CreateFileMappingA(aFile,NULL,PAGE_READONLY,0,0,NULL); |
|
1243 |
if (fileMapping==0) |
|
1244 |
return Emulator::LastError(); |
|
1245 |
aAddr=(TUint8*)MapViewOfFile(fileMapping,FILE_MAP_READ,0,0,0); |
|
1246 |
SRomMap entry; |
|
1247 |
entry.iAddr = aAddr; |
|
1248 |
entry.iName = aName.Alloc(); |
|
1249 |
if (entry.iName) |
|
1250 |
{ |
|
1251 |
TRAPD(ignore, gRomMap->AppendL(entry)); |
|
1252 |
} |
|
1253 |
return KErrNone; |
|
1254 |
} |
|
1255 |
||
1256 |
//------------------------------------------------------------------------------------------------------------------- |
|
1257 |
// |
|
1258 |
// If ROM file, do a memory map and return the address |
|
1259 |
// |
|
1260 |
TInt CLocalFileCB::Address(TInt& aPos) const |
|
1261 |
{ |
|
1262 |
||
1263 |
TBool isRomFile=IsRomDrive(); |
|
1264 |
if (!isRomFile) |
|
1265 |
return(KErrNotSupported); |
|
1266 |
||
1267 |
if (aPos>Size64()) |
|
1268 |
return(KErrEof); |
|
1269 |
if (iFilePtr==NULL) |
|
1270 |
{ |
|
1271 |
CLocalFileCB* This=(CLocalFileCB*)this; |
|
1272 |
TInt err = RomAddress(*iFileName, iWinHandle, This->iFilePtr); |
|
1273 |
if (err) |
|
1274 |
return err; |
|
1275 |
} |
|
1276 |
aPos=(TInt)((TUint8*)iFilePtr+aPos); |
|
1277 |
return(KErrNone); |
|
1278 |
} |
|
1279 |
||
1280 |
//------------------------------------------------------------------------------------------------------------------- |
|
1281 |
// |
|
1282 |
// Set the file size. |
|
1283 |
// |
|
1284 |
void CLocalFileCB::SetSizeL(TInt aSize) |
|
1285 |
{ |
|
1286 |
SetSizeL(aSize); |
|
1287 |
} |
|
1288 |
||
1289 |
//------------------------------------------------------------------------------------------------------------------- |
|
1290 |
// |
|
1291 |
// Set the entry's attributes and modified time. |
|
1292 |
// |
|
1293 |
void CLocalFileCB::SetEntryL(const TTime& aTime,TUint aSetAttMask,TUint aClearAttMask) |
|
1294 |
{ |
|
1295 |
||
1296 |
if (IsRomDrive()) |
|
1297 |
User::Leave(KErrAccessDenied); |
|
1298 |
TUint setAttMask=aSetAttMask&KEntryAttMaskSupported; |
|
1299 |
if (setAttMask|aClearAttMask) |
|
1300 |
{ |
|
1301 |
iAtt|=setAttMask; |
|
1302 |
iAtt&=(~aClearAttMask); |
|
1303 |
iAtt|=KEntryAttModified; |
|
1304 |
} |
|
1305 |
if (aSetAttMask&KEntryAttModified) |
|
1306 |
iModified=aTime; |
|
1307 |
iAtt|=KEntryAttModified; |
|
1308 |
} |
|
1309 |
||
1310 |
//------------------------------------------------------------------------------------------------------------------- |
|
1311 |
// |
|
1312 |
// Commit any buffered date to the media. |
|
1313 |
// |
|
1314 |
void CLocalFileCB::FlushAllL() |
|
1315 |
{ |
|
1316 |
FlushDataL(); |
|
1317 |
} |
|
1318 |
||
1319 |
//------------------------------------------------------------------------------------------------------------------- |
|
1320 |
// |
|
1321 |
// Commit any buffered date to the media. |
|
1322 |
// |
|
1323 |
void CLocalFileCB::FlushDataL() |
|
1324 |
{ |
|
1325 |
||
1326 |
if (IsRomDrive()) |
|
1327 |
return; |
|
1328 |
||
1329 |
TFileName n; |
|
1330 |
TInt driveNumber=Mount().Drive().DriveNumber(); |
|
1331 |
MapFileNameL(n,driveNumber,FileName()); |
|
1332 |
||
1333 |
if(!Emulator::SetFileAttributes(StrPtrZL(n),iAtt&KEntryAttMaskSupported)) |
|
1334 |
User::Leave(Emulator::LastError()); // Panic(EFileCloseSetAttributes); |
|
1335 |
FILETIME f; |
|
1336 |
timeToFileTimeL(iModified,&f); |
|
1337 |
if (!SetFileTime(iWinHandle,&f,&f,&f)) |
|
1338 |
User::Leave(Emulator::LastError()); |
|
1339 |
||
1340 |
iAtt&=(~KEntryAttModified); |
|
1341 |
} |
|
1342 |
||
1343 |
//------------------------------------------------------------------------------------------------------------------- |
|
1344 |
// |
|
1345 |
// Rename the file while open |
|
1346 |
// |
|
1347 |
void CLocalFileCB::RenameL(const TDesC& aNewName) |
|
1348 |
{ |
|
1349 |
||
1350 |
TInt driveNumber=Mount().Drive().DriveNumber(); |
|
1351 |
||
1352 |
TFileName n1; |
|
1353 |
MapFileNameL(n1,driveNumber,FileName()); |
|
1354 |
TFileName n2; |
|
1355 |
MapFileNameL(n2,driveNumber,aNewName); |
|
1356 |
||
1357 |
CloseHandle(iWinHandle); |
|
1358 |
TInt ret=KErrNone; |
|
1359 |
if (!Emulator::MoveFile(StrPtrZL(n1),StrPtrZL(n2))) |
|
1360 |
{ |
|
1361 |
ret=Emulator::LastError(); |
|
1362 |
n2=n1; |
|
1363 |
} |
|
1364 |
DWORD access=GENERIC_READ|GENERIC_WRITE; |
|
1365 |
DWORD share=FILE_SHARE_WRITE|FILE_SHARE_READ; |
|
1366 |
DWORD create=OPEN_EXISTING; |
|
1367 |
iWinHandle=Emulator::CreateFile(StrPtrZL(n2),access,share,NULL,create,FILE_FLAG_RANDOM_ACCESS,NULL); |
|
1368 |
if (iWinHandle==INVALID_HANDLE_VALUE) |
|
1369 |
User::Leave(Emulator::LastError()); |
|
1370 |
||
1371 |
LARGE_INTEGER pos; |
|
1372 |
pos.QuadPart = iCurrentPos; |
|
1373 |
DWORD position = SetFilePointer(iWinHandle,pos.LowPart,&pos.HighPart,FILE_BEGIN); |
|
1374 |
TInt r = Emulator::LastError(); |
|
1375 |
if ((KInvalidSetFilePointer == position) && (r != NO_ERROR)) |
|
1376 |
User::Leave(r); |
|
1377 |
||
1378 |
User::LeaveIfError(ret); |
|
1379 |
AllocBufferL(iFileName,aNewName); |
|
1380 |
} |
|
1381 |
||
1382 |
//------------------------------------------------------------------------------------------------------------------- |
|
1383 |
TInt CLocalFileCB::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput) |
|
1384 |
{ |
|
1385 |
switch(aInterfaceId) |
|
1386 |
{ |
|
1387 |
case EExtendedFileInterface: |
|
1388 |
((CFileCB::MExtendedFileInterface*&) aInterface) = this; |
|
1389 |
return KErrNone; |
|
1390 |
||
1391 |
default: |
|
1392 |
return CFileCB::GetInterface(aInterfaceId,aInterface,aInput); |
|
1393 |
} |
|
1394 |
} |
|
1395 |
||
1396 |
//------------------------------------------------------------------------------------------------------------------- |
|
1397 |
/** |
|
1398 |
Read data from the file. |
|
1399 |
||
1400 |
@param aFilePos start read position within a file |
|
1401 |
@param aLength how many bytes to read; on return will be how many bytes actually read |
|
1402 |
@param aDes local buffer desctriptor |
|
1403 |
@param aMessage from file server, used to write data to the buffer in different address space. |
|
1404 |
@param aDesOffset offset within data descriptor where the data will be copied |
|
1405 |
||
1406 |
@leave on media read error |
|
1407 |
||
1408 |
*/ |
|
1409 |
void CLocalFileCB::ReadL(TInt64 aPos,TInt& aLength,TDes8* aDes,const RMessagePtr2& aMessage, TInt aOffset) |
|
1410 |
{ |
|
1411 |
||
1412 |
const TUint64 KMaxFilePosition = LocalMount().MaxFileSizeSupported()-1; |
|
1413 |
||
1414 |
||
1415 |
if(KMaxFilePosition < (TUint64)aPos) |
|
1416 |
User::Leave(KErrNotSupported); |
|
1417 |
||
1418 |
CheckPosL(aPos); |
|
1419 |
TInt pos=0; |
|
1420 |
TInt len=aLength; |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1421 |
TBuf8<65536> buf; |
0 | 1422 |
|
1423 |
if (aMessage.Handle() == KLocalMessageHandle) |
|
1424 |
((TPtr8* )aDes)->SetLength(0); |
|
1425 |
||
1426 |
while (len) |
|
1427 |
{ |
|
1428 |
TInt s=Min(len,buf.MaxLength()); |
|
1429 |
DWORD res; |
|
1430 |
BOOL b=ReadFile(iWinHandle,(TAny*)buf.Ptr(),s,&res,NULL); |
|
1431 |
if(!b) |
|
1432 |
User::Leave(Emulator::LastError()); |
|
1433 |
||
1434 |
buf.SetLength(res); |
|
1435 |
||
1436 |
if (aMessage.Handle() == KLocalMessageHandle) |
|
1437 |
((TPtr8* )aDes)->Append(buf); |
|
1438 |
else |
|
1439 |
aMessage.WriteL(0,buf,pos + aOffset); |
|
1440 |
||
1441 |
pos+=res; |
|
1442 |
if (((TInt)res)<s) |
|
1443 |
break; |
|
1444 |
len-=s; |
|
1445 |
} |
|
1446 |
TInt delay = (ReadSpeed * aLength) >> 10; |
|
1447 |
if (delay) |
|
1448 |
User::AfterHighRes(delay); |
|
1449 |
aLength=pos; |
|
1450 |
iCurrentPos=aPos+pos; |
|
1451 |
} |
|
1452 |
||
1453 |
//------------------------------------------------------------------------------------------------------------------- |
|
1454 |
/** |
|
1455 |
Write data to the file. |
|
1456 |
||
1457 |
@param aFilePos start write position within a file |
|
1458 |
@param aLength how many bytes to write; on return contain amount of data actually written |
|
1459 |
@param aDes local buffer desctriptor |
|
1460 |
@param aMessage from file server, used to write data to the media from different address space. |
|
1461 |
@param aDesOffset offset within data descriptor |
|
1462 |
||
1463 |
@leave on media read error |
|
1464 |
||
1465 |
*/ |
|
1466 |
void CLocalFileCB::WriteL(TInt64 aPos,TInt& aLength,const TDesC8* aDes,const RMessagePtr2& aMessage, TInt aOffset) |
|
1467 |
{ |
|
1468 |
if (IsRomDrive()) |
|
1469 |
User::Leave(KErrAccessDenied); |
|
1470 |
||
1471 |
||
1472 |
const TUint64 KMaxFileSize = LocalMount().MaxFileSizeSupported(); |
|
1473 |
const TUint64 KMaxFilePosition = KMaxFileSize - 1; |
|
1474 |
||
1475 |
if( KMaxFilePosition < (TUint64)aPos || KMaxFileSize < (TUint64)(aPos + aLength) ) |
|
1476 |
User::Leave(KErrNotSupported); |
|
1477 |
||
1478 |
CheckPosL(aPos); |
|
1479 |
TInt pos=0; |
|
1480 |
TInt len=aLength; |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1481 |
TBuf8<65536> buf; |
0 | 1482 |
|
1483 |
while (len) |
|
1484 |
{ |
|
1485 |
TInt s=Min(len,buf.MaxLength()); |
|
1486 |
||
1487 |
if (aMessage.Handle() == KLocalMessageHandle) |
|
1488 |
buf.Copy( ((TPtr8* )aDes)->MidTPtr(pos, s) ); |
|
1489 |
else |
|
1490 |
aMessage.ReadL(0,buf,pos + aOffset); |
|
1491 |
||
1492 |
DWORD res; |
|
1493 |
BOOL b=WriteFile(iWinHandle,buf.Ptr(),s,&res,NULL); |
|
1494 |
||
1495 |
if (!b) |
|
1496 |
User::Leave(Emulator::LastError()); |
|
1497 |
||
1498 |
if (((TInt)res)<s) |
|
1499 |
User::Leave(KErrCorrupt); |
|
1500 |
||
1501 |
len-=s; |
|
1502 |
pos+=s; |
|
1503 |
} |
|
1504 |
TInt delay = (WriteSpeed * aLength) >> 10; |
|
1505 |
if (delay) |
|
1506 |
User::AfterHighRes(delay); |
|
1507 |
aLength=pos; |
|
1508 |
iCurrentPos=aPos+pos; |
|
1509 |
} |
|
1510 |
||
1511 |
//------------------------------------------------------------------------------------------------------------------- |
|
1512 |
/** |
|
1513 |
Set file size. |
|
1514 |
@param aSize new file size. |
|
1515 |
*/ |
|
1516 |
void CLocalFileCB::SetSizeL(TInt64 aSize) |
|
1517 |
{ |
|
1518 |
const TUint64 KMaxFileSize = LocalMount().MaxFileSizeSupported(); |
|
1519 |
||
1520 |
if(KMaxFileSize < (TUint64)aSize) |
|
1521 |
User::Leave(KErrNotSupported); |
|
1522 |
||
1523 |
CheckPosL(aSize); |
|
1524 |
if(!SetEndOfFile(iWinHandle)) |
|
1525 |
{ |
|
1526 |
iCurrentPos= -1; |
|
1527 |
User::Leave(Emulator::LastError()); |
|
1528 |
} |
|
1529 |
||
1530 |
SetSize64(aSize, EFalse); |
|
1531 |
} |
|
1532 |
||
1533 |
//######################################################################################################################### |
|
1534 |
//## CLocalDirCB class implementation |
|
1535 |
//######################################################################################################################### |
|
1536 |
||
1537 |
CLocalDirCB::CLocalDirCB() |
|
1538 |
:iEntry() |
|
1539 |
{ |
|
1540 |
} |
|
1541 |
||
1542 |
CLocalDirCB::~CLocalDirCB() |
|
1543 |
{ |
|
1544 |
||
1545 |
if (iWinHandle!=NULL && !FindClose(iWinHandle)) |
|
1546 |
Panic(EDirClose); |
|
1547 |
} |
|
1548 |
||
1549 |
//------------------------------------------------------------------------------------------------------------------- |
|
1550 |
TBool CLocalDirCB::MatchUid() |
|
1551 |
{ |
|
1552 |
||
1553 |
if (iUidType[0]!=TUid::Null() || iUidType[1]!=TUid::Null() || iUidType[2]!=TUid::Null()) |
|
1554 |
return(ETrue); |
|
1555 |
||
1556 |
return(EFalse); |
|
1557 |
} |
|
1558 |
||
1559 |
//------------------------------------------------------------------------------------------------------------------- |
|
1560 |
/** @return ETrue if the aUidTrg matches aUidSuitor */ |
|
1561 |
static TBool CompareUid(const TUidType& aUidTrg, const TUidType& aUidSuitor) |
|
1562 |
{ |
|
1563 |
||
1564 |
if (aUidTrg[0]!=TUid::Null() && aUidTrg[0]!=aUidSuitor[0]) |
|
1565 |
return(EFalse); |
|
1566 |
if (aUidTrg[1]!=TUid::Null() && aUidTrg[1]!=aUidSuitor[1]) |
|
1567 |
return(EFalse); |
|
1568 |
if (aUidTrg[2]!=TUid::Null() && aUidTrg[2]!=aUidSuitor[2]) |
|
1569 |
return(EFalse); |
|
1570 |
return(ETrue); |
|
1571 |
} |
|
1572 |
||
1573 |
//------------------------------------------------------------------------------------------------------------------- |
|
1574 |
/** |
|
1575 |
Read current entry from the directory and move to the next one. |
|
1576 |
This function must leave KErrEof when the end of directory is reached |
|
1577 |
||
1578 |
@param anEntry extracted directory entry |
|
1579 |
@leave KErrEof when there are no more entries in the directory |
|
1580 |
system-wide error code on media read fault. |
|
1581 |
||
1582 |
*/ |
|
1583 |
void CLocalDirCB::ReadL(TEntry& anEntry) |
|
1584 |
{ |
|
1585 |
||
1586 |
if (iWinHandle==NULL) |
|
1587 |
User::Leave(KErrEof); |
|
1588 |
||
1589 |
FOREVER |
|
1590 |
{ |
|
1591 |
if (!iPending) |
|
1592 |
{ |
|
1593 |
WIN32_FIND_DATA info; |
|
1594 |
if (!Emulator::FindNextFile(iWinHandle,&info)) |
|
1595 |
User::Leave(Emulator::LastError()); |
|
1596 |
||
1597 |
iEntry.iName.Des()=(TText*)(&info.cFileName[0]); |
|
1598 |
iEntry.iAtt=info.dwFileAttributes&KEntryAttMaskSupported; |
|
1599 |
iEntry.SetFileSize(MAKE_TINT64(info.nFileSizeHigh,info.nFileSizeLow)); |
|
1600 |
fileTimeToTime(&info.ftLastWriteTime,iEntry.iModified); |
|
1601 |
} |
|
1602 |
iPending=EFalse; |
|
1603 |
anEntry=iEntry; |
|
1604 |
if (anEntry.iName==_L(".") || anEntry.iName==_L("..")) |
|
1605 |
continue; |
|
1606 |
if ((iFullName.NameAndExt()==_L("*.*") || iFullName.NameAndExt()==_L("*") || anEntry.iName.MatchF(iFullName.NameAndExt())!=KErrNotFound) && Mount().MatchEntryAtt(anEntry.iAtt&KEntryAttMaskSupported,iAtt)) |
|
1607 |
{ |
|
1608 |
if (MatchUid()) |
|
1609 |
{ |
|
1610 |
TParse fileName; |
|
1611 |
TBuf<KMaxFileName> driveAndPath=iFullName.DriveAndPath(); |
|
1612 |
fileName.Set(anEntry.iName,&driveAndPath,NULL); |
|
1613 |
(*(CLocalMountCB*)&Mount()).ReadUidL(fileName.FullName(),anEntry); |
|
1614 |
if (CompareUid(iUidType,anEntry.iType)) |
|
1615 |
break; |
|
1616 |
} |
|
1617 |
else |
|
1618 |
break; |
|
1619 |
} |
|
1620 |
} |
|
1621 |
if ((iAtt&KEntryAttAllowUid)==0 || anEntry.iAtt&KEntryAttDir || MatchUid()) |
|
1622 |
return; |
|
1623 |
TParse fileName; |
|
1624 |
TBuf<KMaxFileName> driveAndPath=iFullName.DriveAndPath(); |
|
1625 |
fileName.Set(anEntry.iName,&driveAndPath,NULL); |
|
1626 |
(*(CLocalMountCB*)&Mount()).ReadUidL(fileName.FullName(),anEntry); |
|
1627 |
} |
|
1628 |
||
1629 |
//######################################################################################################################### |
|
1630 |
//## CLocalFormatCB class implementation |
|
1631 |
//######################################################################################################################### |
|
1632 |
||
1633 |
CLocalFormatCB::CLocalFormatCB() |
|
1634 |
{ |
|
1635 |
} |
|
1636 |
||
1637 |
CLocalFormatCB::~CLocalFormatCB() |
|
1638 |
{ |
|
1639 |
} |
|
1640 |
||
1641 |
void CLocalFormatCB::DoFormatStepL() |
|
1642 |
{ |
|
1643 |
iCurrentStep=0; |
|
1644 |
User::Leave(KErrNotSupported); |
|
1645 |
} |
|
1646 |
||
1647 |
||
1648 |
//######################################################################################################################### |
|
1649 |
//## CLocal File System class implementation |
|
1650 |
//######################################################################################################################### |
|
1651 |
||
1652 |
extern "C" |
|
1653 |
{ |
|
1654 |
// |
|
1655 |
// Create a new file system |
|
1656 |
// |
|
1657 |
EXPORT_C CFileSystem* CreateFileSystem() |
|
1658 |
{ |
|
1659 |
return(new CLocal); |
|
1660 |
} |
|
1661 |
} |
|
1662 |
||
1663 |
CLocal::CLocal() |
|
1664 |
{ |
|
1665 |
} |
|
1666 |
||
1667 |
TInt CLocal::Install() |
|
1668 |
{ |
|
1669 |
||
1670 |
SetErrorMode(SEM_FAILCRITICALERRORS); |
|
1671 |
EmulatorDiskSpeed(ReadSpeed, WriteSpeed); |
|
1672 |
iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KF32BuildVersionNumber); |
|
1673 |
_LIT(KWin32Name,"Win32"); |
|
1674 |
return(SetName(&KWin32Name)); |
|
1675 |
} |
|
1676 |
||
1677 |
CMountCB* CLocal::NewMountL() const |
|
1678 |
// |
|
1679 |
// Create a new mount control block. |
|
1680 |
// |
|
1681 |
{ |
|
1682 |
||
1683 |
return(new(ELeave) CLocalMountCB); |
|
1684 |
} |
|
1685 |
||
1686 |
CFileCB* CLocal::NewFileL() const |
|
1687 |
// |
|
1688 |
// Create a new file. |
|
1689 |
// |
|
1690 |
{ |
|
1691 |
||
1692 |
return(new(ELeave) CLocalFileCB); |
|
1693 |
} |
|
1694 |
||
1695 |
CDirCB* CLocal::NewDirL() const |
|
1696 |
// |
|
1697 |
// Create a new directory lister. |
|
1698 |
// |
|
1699 |
{ |
|
1700 |
return(new(ELeave) CLocalDirCB); |
|
1701 |
} |
|
1702 |
||
1703 |
CFormatCB* CLocal::NewFormatL() const |
|
1704 |
// |
|
1705 |
// Create a new media formatter. |
|
1706 |
// |
|
1707 |
{ |
|
1708 |
return(new(ELeave) CLocalFormatCB); |
|
1709 |
} |
|
1710 |
||
1711 |
TInt CLocal::DefaultPath(TDes& aPath) const |
|
1712 |
// |
|
1713 |
// Return the initial default path. |
|
1714 |
// |
|
1715 |
{ |
|
1716 |
aPath=_L("?:\\"); |
|
1717 |
aPath[0] = (TUint8) RFs::GetSystemDriveChar(); |
|
1718 |
return(KErrNone); |
|
1719 |
} |
|
1720 |
||
1721 |
void CLocal::DriveInfo(TDriveInfo& anInfo,TInt aDriveNumber) const |
|
1722 |
// |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1723 |
// Return the drive info. |
0 | 1724 |
// |
1725 |
{ |
|
1726 |
||
1727 |
anInfo.iMediaAtt=0; |
|
1728 |
||
1729 |
// Get Fake drive info. |
|
1730 |
if (aDriveNumber==EDriveZ) |
|
1731 |
{ |
|
1732 |
anInfo.iType=EMediaRom; |
|
1733 |
anInfo.iMediaAtt=KMediaAttWriteProtected; |
|
1734 |
anInfo.iDriveAtt=KDriveAttRom|KDriveAttInternal; |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1735 |
anInfo.iConnectionBusType=EConnectionBusInternal; |
0 | 1736 |
return; |
1737 |
} |
|
1738 |
if (aDriveNumber==EDriveC) |
|
1739 |
{ |
|
1740 |
anInfo.iType=EMediaHardDisk; |
|
1741 |
anInfo.iMediaAtt=KMediaAttVariableSize; |
|
1742 |
anInfo.iDriveAtt=KDriveAttLocal|KDriveAttInternal; |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1743 |
anInfo.iConnectionBusType=EConnectionBusInternal; |
0 | 1744 |
return; |
1745 |
} |
|
1746 |
TFileName envValue; |
|
1747 |
if (MapDrive(envValue,aDriveNumber)) |
|
1748 |
{ |
|
1749 |
anInfo.iType=EMediaHardDisk; |
|
1750 |
anInfo.iDriveAtt=KDriveAttLocal|KDriveAttInternal; |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1751 |
anInfo.iConnectionBusType=EConnectionBusInternal; |
0 | 1752 |
return; |
1753 |
} |
|
1754 |
anInfo.iType=EMediaNotPresent; |
|
1755 |
anInfo.iDriveAtt=0; |
|
1756 |
} |
|
1757 |
||
1758 |
||
1759 |
||
1760 |
||
1761 |
||
1762 |
||
1763 |
||
1764 |
||
1765 |
||
1766 |
||
1767 |
||
1768 |
||
1769 |
||
1770 |
||
1771 |