equal
deleted
inserted
replaced
30 //For file size larger than it, we will split one setSize() to several smaller one, each with the following size. |
30 //For file size larger than it, we will split one setSize() to several smaller one, each with the following size. |
31 const TInt64 KMTPFileSetSizeChunk(1<<30); //1G |
31 const TInt64 KMTPFileSetSizeChunk(1<<30); //1G |
32 |
32 |
33 const TUint KUSBHeaderLen = 12; |
33 const TUint KUSBHeaderLen = 12; |
34 |
34 |
|
35 //MTP should reserve some disk space to prevent ood monitor popup |
|
36 //'Out of memory' note.When syncing music through ovi suite, |
|
37 //sometimes device screen get freeze with this note |
|
38 //If you need to adjust this value,please also update the definition |
|
39 //in file 'cmtpgetstorageinfo.cpp' |
|
40 const TInt KFreeSpaceThreshHoldValue(11*1024*1024);//11M |
35 |
41 |
36 |
42 |
37 CMTPTypeFile::CFileWriter* CMTPTypeFile::CFileWriter::NewL(RFile& aFile, RBuf8& aWriteBuf) |
43 CMTPTypeFile::CFileWriter* CMTPTypeFile::CFileWriter::NewL(RFile& aFile, RBuf8& aWriteBuf) |
38 { |
44 { |
39 CFileWriter *self = new(ELeave)CFileWriter(aFile, aWriteBuf); |
45 CFileWriter *self = new(ELeave)CFileWriter(aFile, aWriteBuf); |
85 WaitForWriteComplete(); //make sure all async request complete |
91 WaitForWriteComplete(); //make sure all async request complete |
86 if(iWriteResult != KErrNone) |
92 if(iWriteResult != KErrNone) |
87 { |
93 { |
88 iFile.SetSize(0); |
94 iFile.SetSize(0); |
89 } |
95 } |
|
96 |
90 } |
97 } |
91 |
98 |
92 |
99 |
93 void CMTPTypeFile::CFileWriter::DoCancel() |
100 void CMTPTypeFile::CFileWriter::DoCancel() |
94 { |
101 { |
176 @param aSize The new size of the file (in bytes). |
183 @param aSize The new size of the file (in bytes). |
177 @leave One of the system wide error codes, if a processing failure occurs. |
184 @leave One of the system wide error codes, if a processing failure occurs. |
178 */ |
185 */ |
179 EXPORT_C void CMTPTypeFile::SetSizeL(TUint64 aSize) |
186 EXPORT_C void CMTPTypeFile::SetSizeL(TUint64 aSize) |
180 { |
187 { |
|
188 //Firstly, check the disk free space, at anytime, we must make sure |
|
189 //the free space can not be lower than the threshold value after this |
|
190 //file syncing |
|
191 TInt driveNo; |
|
192 TDriveInfo driveInfo; |
|
193 iFile.Drive(driveNo,driveInfo); |
|
194 RFs fs; |
|
195 TVolumeInfo volumeInfo; |
|
196 fs.Connect(); |
|
197 fs.Volume(volumeInfo,driveNo); |
|
198 fs.Close(); |
|
199 |
|
200 if(volumeInfo.iFree <= KFreeSpaceThreshHoldValue + aSize) |
|
201 { |
|
202 User::Leave(KErrDiskFull); |
|
203 } |
|
204 |
181 iTargetFileSize = (TInt64)aSize; //keep a record for the target file size |
205 iTargetFileSize = (TInt64)aSize; //keep a record for the target file size |
182 |
206 |
183 iRemainingDataSize = (TInt64)aSize;//Current implemenation does not support file size with 2 x64 |
207 iRemainingDataSize = (TInt64)aSize;//Current implemenation does not support file size with 2 x64 |
184 |
208 |
185 if(iRemainingDataSize> KMTPFileChunkSizeForLargeFile) //512K |
209 if(iRemainingDataSize> KMTPFileChunkSizeForLargeFile) //512K |
203 User::LeaveIfError(iFile.SetSize(aSize)); |
227 User::LeaveIfError(iFile.SetSize(aSize)); |
204 iCurrentFileSetSize = aSize; |
228 iCurrentFileSetSize = aSize; |
205 } |
229 } |
206 iFileWriter1 = CFileWriter::NewL(iFile, iBuffer1); |
230 iFileWriter1 = CFileWriter::NewL(iFile, iBuffer1); |
207 iFileWriter2 = CFileWriter::NewL(iFile, iBuffer2); |
231 iFileWriter2 = CFileWriter::NewL(iFile, iBuffer2); |
|
232 |
208 } |
233 } |
209 |
234 |
210 /** |
235 /** |
211 Provides a reference to the native file object encapsulate by the MTP file |
236 Provides a reference to the native file object encapsulate by the MTP file |
212 object data type. |
237 object data type. |
524 void CMTPTypeFile::ConstructL(RFs& aFs, const TDesC& aName, TFileMode aMode) |
549 void CMTPTypeFile::ConstructL(RFs& aFs, const TDesC& aName, TFileMode aMode) |
525 { |
550 { |
526 if (aMode & EFileWrite) |
551 if (aMode & EFileWrite) |
527 { |
552 { |
528 iFileOpenForRead = EFalse; |
553 iFileOpenForRead = EFalse; |
529 User::LeaveIfError(iFile.Replace(aFs, aName, aMode|EFileWriteDirectIO)); |
554 TInt err = iFile.Create(aFs, aName, aMode|EFileWriteDirectIO); |
|
555 if (err != KErrNone) |
|
556 { |
|
557 User::LeaveIfError(iFile.Replace(aFs, aName, aMode|EFileWriteDirectIO)); |
|
558 } |
530 } |
559 } |
531 else |
560 else |
532 { |
561 { |
533 iFileOpenForRead = ETrue; |
562 iFileOpenForRead = ETrue; |
534 User::LeaveIfError(iFile.Open(aFs, aName, aMode|EFileReadDirectIO|EFileShareReadersOnly)); |
563 User::LeaveIfError(iFile.Open(aFs, aName, aMode|EFileReadDirectIO|EFileShareReadersOnly)); |
557 void CMTPTypeFile::ConstructL(RFs& aFs, const TDesC& aName, TFileMode aMode, TInt64 aRequiredSize, TInt64 aOffSet) |
586 void CMTPTypeFile::ConstructL(RFs& aFs, const TDesC& aName, TFileMode aMode, TInt64 aRequiredSize, TInt64 aOffSet) |
558 { |
587 { |
559 if (aMode & EFileWrite) |
588 if (aMode & EFileWrite) |
560 { |
589 { |
561 iFileOpenForRead = EFalse; |
590 iFileOpenForRead = EFalse; |
562 User::LeaveIfError(iFile.Replace(aFs, aName, aMode|EFileWriteDirectIO)); |
591 TInt err = iFile.Create(aFs, aName, aMode|EFileWriteDirectIO); |
|
592 if (err != KErrNone) |
|
593 { |
|
594 User::LeaveIfError(iFile.Replace(aFs, aName, aMode|EFileWriteDirectIO)); |
|
595 } |
563 } |
596 } |
564 else |
597 else |
565 { |
598 { |
566 iFileOpenForRead = ETrue; |
599 iFileOpenForRead = ETrue; |
567 iOffSet = aOffSet; |
600 iOffSet = aOffSet; |
571 #else |
604 #else |
572 TInt size = 0; |
605 TInt size = 0; |
573 #endif |
606 #endif |
574 User::LeaveIfError(iFile.Size(size)); |
607 User::LeaveIfError(iFile.Size(size)); |
575 |
608 |
576 if(aRequiredSize < size) |
609 |
|
610 if(aOffSet + aRequiredSize <= size) |
577 { |
611 { |
578 iTargetFileSize = aRequiredSize; |
612 iTargetFileSize = aRequiredSize; |
579 } |
613 } |
580 else |
614 else |
581 { |
615 { |
582 iTargetFileSize = size; |
616 iTargetFileSize = size - aOffSet; |
583 } |
617 } |
584 iRemainingDataSize = iTargetFileSize; |
618 iRemainingDataSize = iTargetFileSize; |
585 |
619 |
586 //For File reading, NO "SetSizeL()" will be called, therefore, create the buffer here. |
620 //For File reading, NO "SetSizeL()" will be called, therefore, create the buffer here. |
587 if (iRemainingDataSize > KMTPFileChunkSizeForLargeFile) //512K |
621 if (iRemainingDataSize > KMTPFileChunkSizeForLargeFile) //512K |