/** Check if we can move the file to the new location */ TMTPResponseCode CMTPMoveObject::CanMoveObjectL(const TDesC& aOldName, const TDesC& aNewName) const { OstTraceFunctionEntry0( CMTPMOVEOBJECT_CANMOVEOBJECTL_ENTRY ); TMTPResponseCode result = EMTPRespCodeOK; TEntry fileEntry; LEAVEIFERROR(iFramework.Fs().Entry(aOldName, fileEntry), OstTraceExt1( TRACE_ERROR, DUP1_CMTPMOVEOBJECT_CANMOVEOBJECTL, "can't get entry details from %S", aOldName)); TInt drive(iFramework.StorageMgr().DriveNumber(iStorageId)); LEAVEIFERROR(drive, OstTrace1( TRACE_ERROR, DUP2_CMTPMOVEOBJECT_CANMOVEOBJECTL, "can't get driver number for storage %d", iStorageId)); TVolumeInfo volumeInfo; LEAVEIFERROR(iFramework.Fs().Volume(volumeInfo, drive), OstTrace1( TRACE_ERROR, DUP3_CMTPMOVEOBJECT_CANMOVEOBJECTL, "can't get volume info for drive %d", drive)); #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API if(volumeInfo.iFree < fileEntry.FileSize()) #else if(volumeInfo.iFree < fileEntry.iSize) #endif { result = EMTPRespCodeStoreFull; } else if (BaflUtils::FileExists(iFramework.Fs(), aNewName)) { result = EMTPRespCodeInvalidParentObject; } OstTraceFunctionExit0( CMTPMOVEOBJECT_CANMOVEOBJECTL_EXIT ); OstTrace1( TRACE_NORMAL, CMTPMOVEOBJECT_CANMOVEOBJECTL, "response code 0x%04X", result ); return result; }
void CStateDownload::ScanDirectory(RFs& aFs, const TDesC& aDir, const TDesC& aWild, CDesCArray* aFilesArray) { TParse parse; parse.Set(aWild, &aDir, NULL); TPtrC spec(parse.FullName()); TFindFile FindFile(aFs); CDir* dir; if (FindFile.FindWildByPath(parse.FullName(), NULL, dir) == KErrNone) { CleanupStack::PushL(dir); TInt count=dir->Count(); for(TInt i = 0; i < count; i++) { parse.Set((*dir)[i].iName, &spec, NULL); TEntry entry; if(aFs.Entry(parse.FullName(),entry) == KErrNone) { if(!entry.IsDir()) { //InsertIsqL raises a KErrAlreadyExists (-11) when inserting a duplicate TRAPD(err,aFilesArray->InsertIsqL(parse.FullName())); } } } CleanupStack::PopAndDestroy(dir); } }
/** Check if we can copy the file to the new location */ TMTPResponseCode CMTPImageDpCopyObject::CanCopyObjectL(const TDesC& aOldName, const TDesC& aNewName) const { OstTraceFunctionEntry0( CMTPIMAGEDPCOPYOBJECT_CANCOPYOBJECTL_ENTRY ); TMTPResponseCode result = EMTPRespCodeOK; TEntry fileEntry; LEAVEIFERROR(iFramework.Fs().Entry(aOldName, fileEntry), OstTraceExt2( TRACE_ERROR, DUP1_CMTPIMAGEDPCOPYOBJECT_CANCOPYOBJECTL, "Gets the entry details for %S failed! error code %d", aOldName, munged_err )); TDriveNumber drive(static_cast<TDriveNumber>(iFramework.StorageMgr().DriveNumber(iStorageId))); LEAVEIFERROR(drive, OstTraceExt2( TRACE_ERROR, DUP2_CMTPIMAGEDPCOPYOBJECT_CANCOPYOBJECTL, "Gets drive for storage %d failed! error code %d", iStorageId, munged_err )); TVolumeInfo volumeInfo; LEAVEIFERROR(iFramework.Fs().Volume(volumeInfo, drive), OstTraceExt2( TRACE_ERROR, DUP3_CMTPIMAGEDPCOPYOBJECT_CANCOPYOBJECTL, "Gets volume information for driver %d failed! error code %d", drive, munged_err )); if(volumeInfo.iFree < fileEntry.FileSize()) { result = EMTPRespCodeStoreFull; } else if (BaflUtils::FileExists(iFramework.Fs(), aNewName)) { result = EMTPRespCodeInvalidParentObject; } OstTrace1( TRACE_NORMAL, CMTPIMAGEDPCOPYOBJECT_CANCOPYOBJECTL, "CanCopyObjectL - Exit with response code 0x%04X", result ); OstTraceFunctionExit0( CMTPIMAGEDPCOPYOBJECT_CANCOPYOBJECTL_EXIT ); return result; }
// ----------------------------------------------------------------------------- // CGetPartialObject::VerifyParametersL // Verify if the parameter of the request (i.e. offset) is good. // ----------------------------------------------------------------------------- // TBool CGetPartialObject::VerifyParametersL() { PRINT( _L( "MM MTP => CGetPartialObject::VerifyParametersL" ) ); __ASSERT_DEBUG( iRequestChecker, Panic( EMmMTPDpRequestCheckNull ) ); TBool result = EFalse; iObjectHandle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 ); iOffset = Request().Uint32( TMTPTypeRequest::ERequestParameter2 ); iPartialDataLength = Request().Uint32( TMTPTypeRequest::ERequestParameter3 ); PRINT3( _L( "MM MTP <> CGetPartialObject::VerifyParametersL iObjectHandle = 0x%x, iOffset = 0x%x, iMaxLength = 0x%x " ), iObjectHandle, iOffset, iPartialDataLength ); //get object info, but do not have the ownship of the object CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo( iObjectHandle ); __ASSERT_DEBUG( objectInfo, Panic( EMmMTPDpObjectNull ) ); const TDesC& suid( objectInfo->DesC( CMTPObjectMetaData::ESuid ) ); PRINT1( _L( "MM MTP <> CGetPartialObject::VerifyParametersL suid = %S" ), &suid ); TEntry fileEntry; User::LeaveIfError( iFramework.Fs().Entry( suid, fileEntry ) ); if ( iOffset < fileEntry.FileSize() ) { result = ETrue; } PRINT1( _L( "MM MTP <= CGetPartialObject::VerifyParametersL result = %d" ), result ); return result; }
void QFileSystemMetaData::fillFromTEntry(const TEntry& entry) { entryFlags &= ~(QFileSystemMetaData::SymbianTEntryFlags); knownFlagsMask |= QFileSystemMetaData::SymbianTEntryFlags; //Symbian doesn't have unix type file permissions entryFlags |= QFileSystemMetaData::ReadPermissions; if(!entry.IsReadOnly()) { entryFlags |= QFileSystemMetaData::WritePermissions; } //set the type if(entry.IsDir()) entryFlags |= (QFileSystemMetaData::DirectoryType | QFileSystemMetaData::ExecutePermissions); else entryFlags |= QFileSystemMetaData::FileType; //set the attributes entryFlags |= QFileSystemMetaData::ExistsAttribute; if(entry.IsHidden()) entryFlags |= QFileSystemMetaData::HiddenAttribute; #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API size_ = entry.FileSize(); #else size_ = (TUint)(entry.iSize); #endif modificationTime_ = entry.iModified; }
// ---------------------------------------------------------------------------------------- // CTerminalControlServer::DeleteFileL // ---------------------------------------------------------------------------------------- void CTerminalControlServer::DeleteFileL( const TDesC8 &aFileName ) { RDEBUG("CTerminalControlServer::DeleteFileL"); RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL( fs ); HBufC *fileName = HBufC::NewLC( aFileName.Length()+1 ); TPtr fnptr( fileName->Des() ); fnptr.Copy(aFileName); TEntry entry; User::LeaveIfError( fs.Entry( fnptr, entry ) ); if( entry.IsDir() ) { if(fnptr.Right(1) != _L("\\")) { fnptr.Append(_L("\\")); } User::LeaveIfError(fs.RmDir( fnptr ) ); } else { User::LeaveIfError(fs.Delete( fnptr ) ); } CleanupStack::PopAndDestroy( fileName ); CleanupStack::PopAndDestroy( &fs ); }
/** Save the object properties before moving */ void CMTPMoveObject::GetPreviousPropertiesL(const TDesC& aFileName) { OstTraceFunctionEntry0( CMTPMOVEOBJECT_GETPREVIOUSPROPERTIESL_ENTRY ); LEAVEIFERROR(iFramework.Fs().Modified(aFileName, iPreviousModifiedTime), OstTraceExt1( TRACE_ERROR, CMTPMOVEOBJECT_GETPREVIOUSPROPERTIESL, "Can't get the last modification date and time for %S", aFileName)); if ( iIsFolder ) { TEntry fileEntry; User::LeaveIfError(iFramework.Fs().Entry( aFileName, fileEntry )); iIsHidden = fileEntry.IsHidden(); } OstTraceFunctionExit0( CMTPMOVEOBJECT_GETPREVIOUSPROPERTIESL_EXIT ); }
TInt CFileEngine::DeleteFile(const TDesC& aPath) { TInt returnErr=0; CDir* dir; TInt err=iFs.GetDir(aPath,KEntryAttNormal|KEntryAttDir|KEntryAttHidden,ESortByDate,dir); if(err==KErrNone) { TInt tempInt = dir->Count(); for(TInt i = 0;i < tempInt;i++) { TEntry iEntry = (*dir)[i]; if(iEntry.IsDir()) { TInt iLength=iEntry.iName.Length(); if(iLength>0) { TFileName filePath; filePath.Append(aPath); filePath.Append(iEntry.iName); filePath.Append(_L("\\")); DeleteFile(filePath); } } else { TFileName filePath; filePath.Append(aPath); filePath.Append(iEntry.iName); returnErr=BaflUtils::DeleteFile(iFs,filePath); } } } else { returnErr=err; } if(dir) { delete dir; dir=NULL; } returnErr=iFs.RmDir(aPath); return returnErr; }
// ----------------------------------------------------------------------------- // CMoveObject::CanMoveObjectL // Check if we can move the file to the new location // ----------------------------------------------------------------------------- // TMTPResponseCode CMoveObject::CanMoveObjectL( const TDesC& aOldName, const TDesC& aNewName ) const { PRINT2( _L( "MM MTP => CMoveObject::CanMoveObjectL aOldName = %S, aNewName = %S" ), &aOldName, &aNewName ); TMTPResponseCode result = EMTPRespCodeOK; TEntry fileEntry; User::LeaveIfError( iFramework.Fs().Entry( aOldName, fileEntry ) ); TInt drive = iFramework.StorageMgr().DriveNumber( iStorageId ); User::LeaveIfError( drive ); TVolumeInfo volumeInfo; User::LeaveIfError( iFramework.Fs().Volume( volumeInfo, drive ) ); if ( volumeInfo.iFree < fileEntry.FileSize() ) { result = EMTPRespCodeStoreFull; } else if ( BaflUtils::FileExists( iFramework.Fs(), aNewName ) ) { #ifdef MMMTPDP_REPLACE_EXIST_FILE // delete the old one and replace TInt delErr = iFramework.Fs().Delete( aNewName ); PRINT1( _L( "MM MTP <> CMoveObject::CanMoveObjectL delErr = %d" ), delErr ); // delete from the metadata DB TRAPD( err, iFramework.ObjectMgr().RemoveObjectL( aNewName ) ); PRINT1( _L( "MM MTP <> CMoveObject::CanMoveObjectL err = %d" ), err ); // delete from video/mpx DB CMTPObjectMetaData* objectInfo = CMTPObjectMetaData::NewLC(); // + objectInfo if ( iFramework.ObjectMgr().ObjectL( aNewName, *objectInfo ) ) { TRAP( err, iDpConfig.GetWrapperL().DeleteObjectL( aNewName, objectInfo->Uint( CMTPObjectMetaData::EFormatCode ) ) ); } CleanupStack::PopAndDestroy( objectInfo ); // - objectInfo if ( err ) { // do nothing } #else result = EMTPRespCodeInvalidParentObject; #endif } PRINT1( _L( "MM MTP <= CMoveObject::CanMoveObjectL result = 0x%x" ), result ); return result; }
LOCAL_C void Test3() // // Test RFs::Entry() // { test.Next(_L("Use RFs::EntryL() to check files")); TEntry entry; TInt r=TheFs.Entry(_L("UIDCHKNO.SHT"),entry); test_KErrNone(r); test(entry.iName==_L("UIDCHKNO.SHT")); test(entry.IsTypeValid()==EFalse); r=TheFs.Entry(_L("UIDCHKNO.LNG"),entry); test_KErrNone(r); test(entry.iName==_L("UIDCHKNO.LNG")); test(entry.IsTypeValid()==EFalse); r=TheFs.Entry(_L("UIDCHK.MSG"),entry); test_KErrNone(r); test(entry.iName==_L("UIDCHK.MSG")); test(entry.IsTypeValid()); test(entry.iType[0]==TUid::Uid('X') && entry.iType[1]==TUid::Uid('Y') && entry.iType[2]==TUid::Uid('Z')); r=TheFs.Entry(_L("UIDCHK.BLG"),entry); test_KErrNone(r); test(entry.iName==_L("UIDCHK.BLG")); test(entry.IsTypeValid()); test(entry.iType[0]==TUid::Uid('U') && entry.iType[1]==TUid::Uid('I') && entry.iType[2]==TUid::Uid('D')); r=TheFs.Entry(_L("UIDCHK.DAT"),entry); test_KErrNone(r); test(entry.iName==_L("UIDCHK.DAT")); test(entry.IsTypeValid()); test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T')); r=TheFs.Entry(_L("UIDWINS.PE"),entry); test_KErrNone(r); test(entry.iName==_L("UIDWINS.PE")); #if defined(__WINS__) TFileName sessionPath; TheFs.SessionPath(sessionPath); if (sessionPath[0]!='C') test(entry.IsTypeValid()==EFalse); else { test(entry.IsTypeValid()); test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3)); } #else test(entry.IsTypeValid()==EFalse); #endif }
// --------------------------------------------------------------------------- // CRfsFileMan::ResetAttributes // --------------------------------------------------------------------------- // void CRfsFileMan::ResetAttributes( const TDesC& aFullPath, const TEntry& aEntry ) { FUNC_LOG; if ( aEntry.IsReadOnly() ) { TInt err = iFs.SetEntry( aFullPath, aEntry.iModified, 0, KEntryAttReadOnly | KEntryAttHidden ); ERROR( err, "Failed to reset attributes" ); } }
// --------------------------------------------------------------------------- // Scan directory for files. // --------------------------------------------------------------------------- // void CAknsSrvActiveBackupDataClient::ScanDirectoryForSkinFilesL( const TDesC& aRootDir ) { AKNS_TRACE_DEBUG("CAknsSrvActiveBackupDataClient::ScanDirectoryForSkinFilesL" ); CDirScan *dirScan = CDirScan::NewLC( iFsSession ); dirScan->SetScanDataL( aRootDir, KEntryAttNormal | KEntryAttHidden | KEntryAttSystem | KEntryAttDir, ESortNone ); // Fetch all directories and files from root. CDir* entryList = NULL; TParse parse; for(;;) { TRAPD( err, dirScan->NextL( entryList ) ); // Stop in error case, or if no more data. if (!entryList || ( err != KErrNone) ) { break; } for (TInt i=0; i < entryList->Count(); i++) { TEntry entry = (*entryList)[i]; const TDesC& dir = dirScan->FullPath(); parse.Set( entry.iName, &dir, NULL ); if ( !entry.IsDir() ) { iFileArray.Append( parse ); } } delete entryList; } AKNS_TRACE_DEBUG1("CAknsSrvActiveBackupDataClient::ScanDirectoryForSkinFilesL noFiles=%d", iFileArray.Count() ); // Destroy the list. CleanupStack::PopAndDestroy( dirScan ); }
void FormatEntry(TDes& aBuffer, const TEntry& aEntry) { _LIT(KEntryDetails,"Entry details: "); _LIT(KReadOnly," Read-only"); _LIT(KHidden," Hidden"); _LIT(KSystem," System"); _LIT(KDirectory," Directory"); _LIT(KArchive," Archive"); _LIT(KNewLIne,"\n"); aBuffer.Append(KEntryDetails); if(aEntry.IsReadOnly()) aBuffer.Append(KReadOnly); if(aEntry.IsHidden()) aBuffer.Append(KHidden); if(aEntry.IsSystem()) aBuffer.Append(KSystem); if(aEntry.IsDir()) aBuffer.Append(KDirectory); if(aEntry.IsArchive()) aBuffer.Append(KArchive); aBuffer.Append(KNewLIne); }
void CImageReader::GetFileType(const TDesC& aFileName, TDes8& aFileType) { TEntry FileEntry; if(CCoeEnv::Static()->FsSession().Entry(aFileName,FileEntry) == KErrNone) { TBuf8<255> FileBuffer; if(!FileEntry.IsDir()) { TInt FileSize = FileEntry.iSize; if(FileSize > 255) { FileSize = 255; } if(CCoeEnv::Static()->FsSession().ReadFileSection(aFileName,0,FileBuffer,FileSize) == KErrNone) { RApaLsSession RSession; if(RSession.Connect() == KErrNone) { TDataRecognitionResult FileDataType; RSession.RecognizeData(aFileName,FileBuffer,*&FileDataType); // if(FileDataType.iConfidence > aResult.iConfidence) // { aFileType.Copy(FileDataType.iDataType.Des8()); // } RSession.Close(); } } } } }
/** Check the GetPartialObject reqeust @return EMTPRespCodeOK if the request is good, otherwise, one of the error response codes */ TMTPResponseCode CMTPGetPartialObject::CheckRequestL() { OstTraceFunctionEntry0( CMTPGETPARTIALOBJECT_CHECKREQUESTL_ENTRY ); TMTPResponseCode result = CMTPRequestProcessor::CheckRequestL(); if(result == EMTPRespCodeOK) { TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); iOffset = Request().Uint32(TMTPTypeRequest::ERequestParameter2); iLength = Request().Uint32(TMTPTypeRequest::ERequestParameter3); //does not take ownership iObjectInfo = iRequestChecker->GetObjectInfo(objectHandle); if (!iObjectInfo) { // The object handle has already been checked, so an invalid handle can // only occur if it was invalidated during a context switch between // the validation time and now. result = EMTPRespCodeInvalidObjectHandle; } else { TEntry fileEntry; LEAVEIFERROR(iFramework.Fs().Entry(iObjectInfo->DesC(CMTPObjectMetaData::ESuid), fileEntry), OstTraceExt1(TRACE_ERROR, CMTPGETPARTIALOBJECT_CHECKREQUESTL, "can't get entry details for %S!", iObjectInfo->DesC(CMTPObjectMetaData::ESuid))); if((iOffset >= fileEntry.FileSize())) { result = EMTPRespCodeInvalidParameter; } } } OstTraceFunctionExit0( CMTPGETPARTIALOBJECT_CHECKREQUESTL_EXIT ); return result; }
// --------------------------------------------------------------------------- // CRfsFileMan::Delete // --------------------------------------------------------------------------- // TInt CRfsFileMan::Delete( const TDesC& aFullPath, const TEntry& aEntry ) { FUNC_LOG; INFO_1( "Delete '%S'", &aFullPath ); TBool isDir( aEntry.IsDir() ); TInt err( isDir ? iFs.RmDir( aFullPath ) : iFs.Delete( aFullPath ) ); if ( err == KErrAccessDenied ) { ResetAttributes( aFullPath, aEntry ); err = isDir ? iFs.RmDir( aFullPath ) : iFs.Delete( aFullPath ); } ERROR_1( err, "Failed to delete '%S'", &aFullPath ); return err; }
// --------------------------------------------------------------------------- // CRfsFileMan::DeleteL // --------------------------------------------------------------------------- // void CRfsFileMan::DeleteL( const TDesC& aFullPath, const TEntry& aRootEntry ) { FUNC_LOG; if ( aRootEntry.IsDir() ) { INFO_1( "Checking contents of '%S'", &aFullPath ); HBufC* buffer = HBufC::NewLC( KMaxPath ); TPtr ptr = buffer->Des(); CDirStackEntry::PushDirEntryL( iDirStack, aFullPath, iFs ); // Setup root dir while ( iDirStack.Count() > 0 ) { CDirStackEntry& stackEntry = *( iDirStack[ iDirStack.Count() - 1 ] ); const TEntry* dirEntry = stackEntry.GetNextEntry( ptr ); if ( dirEntry ) { if ( dirEntry->IsDir() ) { CDirStackEntry::PushDirEntryL( iDirStack, ptr, iFs ); } else { Delete( ptr, *dirEntry ); } } else { // Dir has been processed. Now it is empty and can be deleted. stackEntry.FullPath( ptr ); TEntry entry; if( iFs.Entry( ptr, entry ) == KErrNone ) { Delete( ptr, entry ); } CDirStackEntry::PopAndDestroyDirEntry( iDirStack ); } } CleanupStack::PopAndDestroy( buffer ); } else { Delete( aFullPath, aRootEntry ); } }
void IntegrityDeleteFileL(const TDesC& aPath, CIntegrityTreeLeaf* aLeaf, RFs& aFs, RLoader& aLoader, CFileMan& aFileMan) { _LIT(KSysBin, "\\sys\\bin"); RBuf name; name.CreateL(aPath, KMaxFileName); CleanupClosePushL(name); name.Append(aLeaf->Name()); TEntry entry; TInt err = aFs.Entry(name, entry); if (err == KErrNone) { aFs.SetAtt(name, 0, KEntryAttReadOnly); if(entry.IsDir()) { // Make sure to append slash before calling RmDir - otherwise it deletes the parent directory if (name[name.Length()-1] != KPathDelimiter) { name.Append(KPathDelimiter); } User::LeaveIfError(aFileMan.RmDir(name)); } else { if ( aLeaf->Type() == EBackupFile ) // Implies a commit operation is in progress { if ( IsBinary(entry) ) { // Forming the file name so the renamed file can be under sys/bin // for special delete mechanism using RLoader::Delete RBuf tmpName; TParsePtrC fileName(name); tmpName.CreateL(name.Length() + KSysBin.iTypeLength); CleanupClosePushL(tmpName); tmpName.Append(fileName.Drive()); tmpName.Append(KSysBin); tmpName.Append(fileName.Path()); tmpName.Append(fileName.NameAndExt()); DEBUG_PRINTF3(_L("Integrity Services - Renaming %S to %S"), &name, &tmpName); aFileMan.Rename(name,tmpName,CFileMan::EOverWrite); User::LeaveIfError(aLoader.Delete(tmpName)); // Using RLoader delete for paged binaries DEBUG_PRINTF2(_L("Integrity Services - Deleted renamed file %S"), &tmpName); // prune the directory tree if possible RemoveDirectoryTreeL(aFs, tmpName); CleanupStack::PopAndDestroy(&tmpName); } else { User::LeaveIfError(aFileMan.Delete(name)); } } else { // Need to use RLoader Delete which can be used during deletion of Added files during Rollback User::LeaveIfError(aLoader.Delete(name)); } } // prune the directory tree if possible RemoveDirectoryTreeL(aFs, name); } else if(err != KErrNotFound && err != KErrPathNotFound) { DEBUG_PRINTF3(_L("Integrity Services - error %d removing %S"), err, &name); User::Leave(err); } else { DEBUG_PRINTF3(_L("Integrity Services - error %d removing %S"), err, &name); // Check for any renamed files to move it to sys/bin for special delete mechanism RBuf tmpName; TParsePtrC fileName(name); tmpName.CreateL(name.Length() + KSysBin.iTypeLength); CleanupClosePushL(tmpName); tmpName.Append(fileName.Drive()); tmpName.Append(KSysBin); tmpName.Append(fileName.Path()); tmpName.Append(fileName.NameAndExt()); DEBUG_PRINTF2(_L("Integrity Services - Removing %S renamed binary files if any"), &tmpName); aLoader.Delete(tmpName); // prune the directory tree if possible RemoveDirectoryTreeL(aFs, tmpName); CleanupStack::PopAndDestroy(&tmpName); } CleanupStack::PopAndDestroy(&name); }
LOCAL_C void DoTestsL() { test.Start(_L("@SYMTESTCaseID:PIM-T-NOMACH-0001 T_NOMACH")); CTestRegister* TempFiles = CTestRegister::NewLC(); #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ TempFiles->RegisterL(KDatabaseOpenName, EFileTypeCnt); #endif // __SYMBIAN_CNTMODEL_USE_SQLITE__ TempFiles->RegisterL(KDatabaseFileName, EFileTypeCnt); CntTest->CreateDatabaseL(); TInt err; #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ //see comments above function TestDbUpdateL test.Printf(KTestDbUpdate); TRAP(err,TestDbUpdateL()); test(err==KErrNone); #endif // __SYMBIAN_CNTMODEL_USE_SQLITE__ test.Printf(KTest11Digitmatching); TRAP(err,Test11DigitMatchingL()); test(err==KErrNone); test.Printf(KTest15Digitmatching); TRAP(err,Test15DigitMatchingL()); test(err==KErrNone); test.Printf(KTestEmbeddedZeroes); TRAP(err,TestEmbeddedZeroesL()); test(err==KErrNone); test.Printf(KTestNoPhoneMatchLibrary); TestNoPhoneMatchLibraryL(); test.Printf(KTestNewMatching); TestNewMatchingL(); test.Printf(KTestFaxSMSMatching); TestFaxSMSMatchingL(); test.Printf(KSpeedDialSimpleTest); TRAP(err,SpeedDialSimpleTest()); test(err==KErrNone); test.Printf(KTestRemovingSpeedDials); TRAP(err,TestRemovingSpeedDialsL()); test(err==KErrNone); CntTest->CloseDatabase(); CntTest->DeleteDatabaseL(); CleanupStack::PopAndDestroy(TempFiles); // stop efsrv.lib warning on 8.1a wins TEntry dummy; (void)dummy.IsTypeValid(); }
TInt CMdSNotifier::Compare( const TEntry& aFirst, const TEntry& aSecond ) { return aFirst.Id() - aSecond.Id(); }
void CTestUtilSessionSwi::ServiceL(const RMessage2& aMessage) { switch (aMessage.Function()) { case ECopy: { HBufC* source = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); HBufC* destination = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,1); TInt err = Server().FileMan().Copy(*source, *destination, CFileMan::ERecurse | CFileMan::EOverWrite); if (err == KErrNone) { // Turn off the read only attributes TTime time(0); // must specify 0, or a valid time, otherwise sets time to a random value and causes -6/-21 errors err = Server().FileMan().Attribs(*destination, 0, KEntryAttReadOnly, time, CFileMan::ERecurse); } CleanupStack::PopAndDestroy(destination); CleanupStack::PopAndDestroy(source); aMessage.Complete(err); break; } case EMove: { HBufC* source = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); HBufC* destination = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,1); TInt err = Server().FS().Rename(*source,*destination); if (err == KErrNone) { // Turn off the read only attributes TTime time(0); // must specify 0, or a valid time, otherwise sets time to a random value and causes -6/-21 errors err = Server().FileMan().Attribs(*destination, 0, KEntryAttReadOnly, time, CFileMan::ERecurse); } CleanupStack::PopAndDestroy(destination); CleanupStack::PopAndDestroy(source); aMessage.Complete(err); break; } case EDelete: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); TEntry entry; TInt err = Server().FS().Entry(*fileName, entry); if (err == KErrNone) { if (entry.IsDir()) { TPath pathName(*fileName); if (pathName[pathName.Length() - 1] != KPathDelimiter) { pathName.Append(KPathDelimiter); } err = Server().FileMan().RmDir(pathName); } else { err = Server().FS().Delete(*fileName); } } CleanupStack::PopAndDestroy(fileName); aMessage.Complete(err); break; } case ERmDir: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); TParsePtrC parsePtr(*fileName); if(parsePtr.IsRoot()) { User::Leave(KErrAccessDenied); } TInt err = Server().FileMan().RmDir(*fileName); CleanupStack::PopAndDestroy(fileName); aMessage.Complete(err); break; } case EMkDirAll: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); TInt err = Server().FS().MkDirAll(*fileName); CleanupStack::PopAndDestroy(fileName); aMessage.Complete(err); break; } case EFileExists: { delete iDetector; iDetector=CTestFileDetector::NewL(aMessage, Server().FS()); iDetector->DetectFile(); break; } case ELock: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); RFile lockFile; TInt err = lockFile.Open(Server().FS(), *fileName, EFileWrite); if (err == KErrNone) iLockedFileHandles.Append(lockFile); CleanupStack::PopAndDestroy(fileName); aMessage.Complete(err); break; } case EUnlock: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); TInt err = KErrNotFound; TFileName lockedFileName; for (TInt i = 0; i < iLockedFileHandles.Count() && err;i++) { TInt err2 = iLockedFileHandles[i].FullName(lockedFileName); User::LeaveIfError(err2); if (lockedFileName.MatchF(*fileName) != KErrNotFound) { iLockedFileHandles[i].Close(); iLockedFileHandles.Remove(i); err = KErrNone; } } CleanupStack::PopAndDestroy(fileName); aMessage.Complete(err); break; } case EFormat: { TInt drive = aMessage.Int0(); TBool formatFatOnly = aMessage.Int1(); TChar aDriveChar; User::LeaveIfError(Server().FS().DriveToChar(drive, aDriveChar)); TBuf<3> bfDrv; bfDrv.Append(aDriveChar); bfDrv.Append(KBP); RFormat format; TInt count; User::LeaveIfError(format.Open(Server().FS(), bfDrv, EHighDensity, count)); CleanupClosePushL(format); if (formatFatOnly) { User::LeaveIfError(format.Next(count)); } else { while (count > 0) { User::LeaveIfError(format.Next(count)); } } CleanupStack::PopAndDestroy(&format); aMessage.Complete(KErrNone); break; } case EMount: { TInt drive = aMessage.Int0(); User::LeaveIfError(Server().FS().Connect()); //Mount the drive synchronizely to make sure the drive is ready for the next operation User::LeaveIfError(Server().FS().MountFileSystem(KFAT, drive, ETrue)); aMessage.Complete(KErrNone); break; } case EUnMount: { TInt drive = aMessage.Int0(); TFileName fsName; User::LeaveIfError(Server().FS().FileSystemName(fsName, drive)); User::LeaveIfError(Server().FS().DismountFileSystem(fsName, drive)); aMessage.Complete(KErrNone); break; } case ESetReadOnly: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); TInt setReadOnly = aMessage.Int1(); TUint setmask; TUint clearmask; if (setReadOnly) { // Setting read only attribute setmask = KEntryAttReadOnly; clearmask = 0; } else { // Clearing read only attribute setmask = 0; clearmask = KEntryAttReadOnly; } // Turn off the read only attributes TTime time(0); TInt err = Server().FileMan().Attribs(*fileName, setmask, clearmask, time); CleanupStack::PopAndDestroy(fileName); aMessage.Complete(err); break; } case EGetFileHandle: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); RFile file; CleanupClosePushL(file); User::LeaveIfError(file.Open(Server().FS(), *fileName, EFileRead | EFileShareReadersOnly)); User::LeaveIfError(file.TransferToClient(aMessage, 1)); CleanupStack::PopAndDestroy(2, fileName); // file break; } case EWatchFile: { if (iFileWatcher) { if (iFileWatcher->IsActive()) { aMessage.Complete(KErrServerBusy); break; } else { delete iFileWatcher; iFileWatcher = NULL; } } // Create a new file watcher for this session iFileWatcher = CFileWatcher::NewL(Server().FS(), aMessage); break; } case EWatchFileCancel: { if (iFileWatcher) { iFileWatcher->Cancel(); aMessage.Complete(KErrNone); } else { // No file watch request to cancel! aMessage.Complete(KErrNotReady); } break; } case EGetNumFiles: { HBufC* dirPath = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); CDir* dirContents = NULL; User::LeaveIfError(Server().FS().GetDir(*dirPath, KEntryAttNormal, ESortNone, dirContents)); TPckg<TInt> numFiles(dirContents->Count()); delete dirContents; aMessage.WriteL(1, numFiles); aMessage.Complete(KErrNone); CleanupStack::PopAndDestroy(dirPath); break; } case ERegenerateCache: { #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK Swi::RSisRegistryWritableSession session; User::LeaveIfError(session.Connect()); CleanupClosePushL(session); session.RegenerateCacheL(); CleanupStack::PopAndDestroy(&session); aMessage.Complete(KErrNone); #else aMessage.Complete(KErrNotSupported); #endif break; } case EGetFileHash: { HBufC* fileNameA = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); CMessageDigest* digest = CalculateFileHashLC(*fileNameA); aMessage.WriteL(1, digest->Final()); aMessage.Complete(KErrNone); CleanupStack::PopAndDestroy(2, fileNameA); break; } default: { PanicClient(aMessage,EPanicIllegalFunction); break; } } }
/** Verify request */ TMTPResponseCode CMTPSetObjectPropValue::CheckRequestL() { TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL(); TUint32 handle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); CMTPObjectMetaData* meta = iRequestChecker->GetObjectInfo(handle); __ASSERT_DEBUG(meta, Panic(EMTPDpObjectNull)); if(!iSingleton.StorageMgr().IsReadWriteStorage(meta->Uint(CMTPObjectMetaData::EStorageId))) { responseCode = EMTPRespCodeAccessDenied; } if(responseCode == EMTPRespCodeOK) { TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2); if(propCode != EMTPObjectPropCodeAssociationType && propCode != EMTPObjectPropCodeAssociationDesc) { const TInt count = sizeof(KMTPDpSupportedProperties) / sizeof(TUint16); TInt i = 0; for(i = 0; i < count; i++) { if(KMTPDpSupportedProperties[i] == propCode && IsPropCodeReadonly(propCode)) // Object property code supported, but cann't be set. { responseCode = EMTPRespCodeAccessDenied; break; } else if(KMTPDpSupportedProperties[i] == propCode) // Object property code supported and can be set. { break; } } if(i == count) { responseCode = EMTPRespCodeInvalidObjectPropCode; } } else if(meta->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeAssociation) { responseCode = EMTPRespCodeInvalidObjectFormatCode; } } else { const TDesC& suid(meta->DesC(CMTPObjectMetaData::ESuid)); TEntry entry; LEAVEIFERROR( iFramework.Fs().Entry(suid, entry), OstTraceExt1( TRACE_ERROR, CMTPSETOBJECTPROPVALUE_CHECKREQUESTL, "Gets entry details for %S failed!", suid)); //According to spec, there are 4 statuses: No Protection; Read-only; Read-only data; Non-transferrable data //Currently, we only use FS's Read-only attribute to support No Protection and Read-only statuses. //so if the attribute is read-only, we will return EMTPRespCodeAccessDenied. if (entry.IsReadOnly()) { responseCode = EMTPRespCodeAccessDenied; } } return responseCode; }
static void TestL() { CHlpFileList* masterList = new(ELeave) CHlpFileList(5); CleanupStack::PushL(masterList); TInt i = EDriveY; FOREVER { // Make sure we go from Y -> C, then do Z last if (i < EDriveC) i = EDriveZ; if (DiskPresent(i)) { { TChar driveLetter = '?'; RFs::DriveToChar(i, driveLetter); TheTest.Printf(_L("\n\nDisk %c: is installed..."), static_cast<TUint>(driveLetter)); } // This generates a list for a specific directory on the specified drive. CHlpFileList* list = BuildListForDriveLC(TDriveUnit(i), TheFs); // We now compare this list with our 'master' list to check for duplicates, // better matches, etc. TInt masterCount = masterList->Count(); for(TInt j=masterCount-1; j>=0; j--) { CHlpFileEntry* entry = masterList->At(j); // This bit checks to see if an entry in the master list // collides with an entry in the list we have just generated... //TBool foundCollision = EFalse; TInt newListCount = list->Count(); for(TInt k=newListCount-1; k>=0; k--) { CHlpFileEntry* newEntry = list->At(k); __PRINT_FILE_NO(_L("Performing drive resolution on entry"), *newEntry, k); if (entry->Name().CompareF(newEntry->Name()) == 0) { // Names are the same, so compare priorities... if (newEntry->Type() == entry->Type()) { // A file with the same name AND extension is already present in the array, // but are the UID's the same? If they are NOT, then the file // should be treated as a different help file to that of the // existing array entry. TFileName file; TEntry existingTEntry; entry->GetFullNameAndPath(file); User::LeaveIfError(TheFs.Entry(file, existingTEntry)); TEntry newTEntry; newEntry->GetFullNameAndPath(file); User::LeaveIfError(TheFs.Entry(file, newTEntry)); if (existingTEntry.MostDerivedUid() == newTEntry.MostDerivedUid()) { // The uids and names of the files are the same. If the extensions are also the same // then we load the file on the drive tending to C:. However, if the extensions differ // we load the file with the extension tending to 01, i.e. UK English. if (entry->FileName().CompareF(newEntry->FileName()) == 0) { // Name, uid and extensions are the same, therefore load the file on the drive // nearest C:. We do this by setting the priority of the existing entry to // EDsicarded so that it will force the next 'if' statement to fire, and hence // the existing entry will be replaced by the new one. entry->SetType(CHlpFileEntry::EDiscarded); __PRINT_FILE(_L("Uid, name, extension match. Saving entry tending to C: which is"), *newEntry); } else { // Name and uid the same, extensions different therefore load the file with // extension nearest to 01. If the new entry is nearer 01, then we set the // existing entry to discarded and therefore it will be removed at the next // 'if' statement. if (entry->HelpFileLocale() > newEntry->HelpFileLocale()) { entry->SetType(CHlpFileEntry::EDiscarded); __PRINT_FILE(_L("Uid & name match, extensions differ.\n Saving entry tending to H01 which is"), *newEntry); } else { __PRINT_FILE(_L("Uid & name match, extensions differ.\n Discarding new entry because it tends to H99"), *newEntry); } } } else { // This entry should be treated as a separate entity from the current // existing entry because it has different uid's. Therefore, we just // move on to check against the next existing entry in the list __PRINT_FILE(_L("Duplicate name and extension, but different uids detected. New entry == "), *newEntry); continue; } } // Is the new entry a better match than the existing one? if (newEntry->Type() < entry->Type()) { // The new entry is of a better 'quality' than the existing // entry, so remove the old and add the new... __PRINT_FILE(_L("Removing stored (new better match found)"), *entry); //foundCollision = ETrue; masterList->Delete(j); delete entry; masterList->AppendL(newEntry); // Remove it from the new list as the master list now takes // ownership... list->Delete(k); break; } else { // This entry is of lower quality than an existing // entry in the master list, so we can safely discard it. delete newEntry; list->Delete(k); } continue; } } } // At this point, anything that is left int the new list should // be valid to add to the master list... TInt newListCount = list->Count(); for(TInt k=newListCount-1; k>=0; k--) { __PRINT_FILE_NO(_L("Saving entry"), *list->At(k), k); masterList->AppendL(list->At(k)); } // We only destroy the list, rather than list+contents because each element // in the new list is now guaranteed to be present in the master list. CleanupStack::PopAndDestroy(); // list } if (i-- == EDriveZ) break; } // Print out the master list TheTest.Printf(_L("\n\nThe help files that would be loaded are:-")); TheTest.Printf(_L("\n=========================================")); TInt masterCount = masterList->Count(); for(i=0; i<masterCount; i++) __PRINT_FILE_NO(_L("Entry"), *masterList->At(i), i); masterList->ResetAndDestroy(); CleanupStack::PopAndDestroy(); // masterList }
// ----------------------------------------------------------------------------- // CAknFileSelectionModel::UpdateItemListL // ----------------------------------------------------------------------------- // TInt CAknFileSelectionModel::UpdateItemListL() { iEntryArray->Reset(); iImageIndexArray.Reset(); CDir* entryArray = ReadDirectory( iCurrentPath.DriveAndPath() ); if ( !entryArray ) { return KErrNotFound; } CleanupStack::PushL( entryArray ); TInt itemCount( entryArray->Count() ); if ( itemCount > 0 ) { TInt filterCount( iFilterArray->Count() ); TInt filterIndex; TBool accepted; CDesC16Array* desC16FoldersArray = new ( ELeave ) CDesC16ArrayFlat( KEntryArrayGranularity ); CleanupStack::PushL( desC16FoldersArray ); CDesC16Array* desC16FilesArray = new ( ELeave ) CDesC16ArrayFlat( KEntryArrayGranularity ); CleanupStack::PushL( desC16FilesArray ); CArrayPakFlat<TEntry>* tmpFoldersArray = new( ELeave ) CArrayPakFlat<TEntry>( KEntryArrayGranularity ); CleanupStack::PushL( tmpFoldersArray ); CArrayPakFlat<TEntry>* tmpFilesArray = new( ELeave ) CArrayPakFlat<TEntry>( KEntryArrayGranularity ); CleanupStack::PushL( tmpFilesArray ); tmpFoldersArray->Reset(); desC16FoldersArray->Reset(); tmpFilesArray->Reset(); desC16FilesArray->Reset(); for ( TInt i( 0 ); i < itemCount; i++ ) // Generate filtered list { accepted = ETrue; // If there are no filters, accept the entry TEntry entry = ( *entryArray )[i]; filterIndex = 0; // Go thru the filters while the entry is accepted while( ( filterIndex < filterCount ) && ( accepted ) ) { accepted = iFilterArray->At( filterIndex )->Accept( iCurrentPath.DriveAndPath(), entry ); filterIndex++; } if ( accepted ) // Directory entry has passed all filters { // Add filename to filtered list if ( entry.IsDir() ) { desC16FoldersArray->AppendL( GetLocalizedName( entry.iName ) ); tmpFoldersArray->AppendL( entry, sizeof( TEntry ) ); } else { desC16FilesArray->AppendL( GetLocalizedName( entry.iName ) ); tmpFilesArray->AppendL( entry, sizeof( TEntry ) ); } } } TInt entryCount = 0; TInt index; TKeyArrayPak key( _FOFF( TEntry, iName ), ECmpCollated ); // Add folder entries desC16FoldersArray->Sort( ECmpCollated ); entryCount = desC16FoldersArray->MdcaCount(); for( TInt j( 0 ); j < entryCount; j++ ) { for( TInt k( 0 ); k < entryCount; k++ ) { if( ( *desC16FoldersArray )[j] == GetLocalizedName( ( *tmpFoldersArray )[k].iName ) && iEntryArray->Find( ( *tmpFoldersArray )[k], key, index ) != 0 ) { TEntry tmpEntry = ( *tmpFoldersArray )[k]; iEntryArray->AppendL( tmpEntry, sizeof( TEntry ) ); // Entry is a directory TFileTypeIcon folderIcon( EFolderIcon ); if( !AknCFDUtility::IsRemoteDrive( iCurrentPath.Drive() ) ) { if ( ContainsSubfolders( tmpEntry.iName ) ) { folderIcon = ESubFolderIcon; } else if ( !ContainsFiles( tmpEntry.iName ) ) { folderIcon = EFolderEmptyIcon; } } iImageIndexArray.Append( folderIcon ); break; } } } // Add file entries desC16FilesArray->Sort( ECmpCollated ); entryCount = desC16FilesArray->MdcaCount(); for( TInt j( 0 ); j < entryCount; j++ ) { for( TInt k( 0 ); k < entryCount; k++ ) { if( ( *desC16FilesArray )[j] == GetLocalizedName( ( *tmpFilesArray )[k].iName ) && iEntryArray->Find( ( *tmpFilesArray )[k], key, index ) != 0 ) { TEntry tmpFile = ( *tmpFilesArray )[k]; iEntryArray->AppendL( tmpFile, sizeof( TEntry ) ); // Entry is a file AppendIconForFileL( tmpFile.iName ); break; } } } CleanupStack::PopAndDestroy( tmpFilesArray ); CleanupStack::PopAndDestroy( tmpFoldersArray ); CleanupStack::Pop( desC16FilesArray ); desC16FilesArray->Reset(); delete desC16FilesArray; CleanupStack::Pop( desC16FoldersArray ); desC16FoldersArray->Reset(); delete desC16FoldersArray; } CleanupStack::PopAndDestroy( entryArray ); if ( AknCFDUtility::DirectoriesOnly( iDialogType ) ) { // Set the current folder name as first item. // Current folder is for example "E:\Images\Holiday\" // Remove trailing backslash, we get "E:\Images\Holiday" // Parse the path with TParse and ask for NameAndExt(). // TParse interpretes "Holiday" as file name and returns it. HBufC * bufFolder = HBufC::NewLC(KMaxPath); * bufFolder = iCurrentPath.DriveAndPath() ; TPtr folder = bufFolder->Des(); AknCFDUtility::RemoveTrailingBackslash( folder ); // ignore error TParsePtr parsedFolder(folder); folder = parsedFolder.NameAndExt(); iFolderEntry.iName = folder; iEntryArray->InsertL( 0, iFolderEntry, sizeof( TEntry ) ); iImageIndexArray.Insert( EThisFolderIcon, 0 ); CleanupStack::PopAndDestroy(); //bufFolder } return iEntryArray->Count(); }
/** Apply the references to the specified object @return EFalse */ TBool CMTPSetObjectPropValue::DoHandleResponsePhaseL() { TMTPResponseCode responseCode = EMTPRespCodeInvalidObjectPropFormat; TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2); switch(propCode) { case EMTPObjectPropCodeDateModified: { TTime modifiedTime; if( iDpSingletons.MTPUtility().MTPTimeStr2TTime(iMTPTypeString->StringChars(), modifiedTime) ) { iRfs.SetModified( iObjMeta->DesC(CMTPObjectMetaData::ESuid), modifiedTime ); responseCode = EMTPRespCodeOK; } else { responseCode = EMTPRespCodeInvalidObjectPropValue; } } break; case EMTPObjectPropCodeHidden: { if ( EMTPHidden == iMTPTypeUint16.Value()) { TEntry entry; User::LeaveIfError(iFramework.Fs().Entry(iObjMeta->DesC(CMTPObjectMetaData::ESuid), entry)); if ( !entry.IsHidden()) { entry.iAtt &= ~KEntryAttHidden; entry.iAtt |= KEntryAttHidden; User::LeaveIfError(iFramework.Fs().SetAtt(iObjMeta->DesC(CMTPObjectMetaData::ESuid), entry.iAtt, ~entry.iAtt)); } responseCode = EMTPRespCodeOK; } else if ( EMTPVisible == iMTPTypeUint16.Value()) { TEntry entry; User::LeaveIfError(iFramework.Fs().Entry(iObjMeta->DesC(CMTPObjectMetaData::ESuid), entry)); if ( entry.IsHidden()) { entry.iAtt &= ~KEntryAttHidden; User::LeaveIfError(iFramework.Fs().SetAtt(iObjMeta->DesC(CMTPObjectMetaData::ESuid), entry.iAtt, ~entry.iAtt)); } responseCode = EMTPRespCodeOK; } else { responseCode = EMTPRespCodeInvalidObjectPropValue; } } break; case EMTPObjectPropCodeObjectFileName: { TRAPD(err, iDpSingletons.MTPUtility().RenameObjectL(iObjMeta->Uint(CMTPObjectMetaData::EHandle),iMTPTypeString->StringChars())) ; if( KErrNone == err ) { responseCode = EMTPRespCodeOK; } else if(KErrNotFound == err) { responseCode = EMTPRespCodeInvalidObjectHandle; } else if( KErrAlreadyExists == err) { responseCode = EMTPRespCodeInvalidObjectPropValue; } else { responseCode = EMTPRespCodeAccessDenied; } } break; case EMTPObjectPropCodeName: { //Might need to consider to save this name into meta-data base. //Notify all the Data Providers if the Owner of the object is DeviceDP const TDesC& name = iMTPTypeString->StringChars(); if(name != iFileEntry.iName) { iObjMeta->SetDesCL( CMTPObjectMetaData::EName, name); iFramework.ObjectMgr().ModifyObjectL(*iObjMeta); } responseCode = EMTPRespCodeOK; } break; case EMTPObjectPropCodeNonConsumable: { iObjMeta->SetUint( CMTPObjectMetaData::ENonConsumable, iMTPTypeUint8.Value()); iFramework.ObjectMgr().ModifyObjectL(*iObjMeta); responseCode = EMTPRespCodeOK; } break; case EMTPObjectPropCodeAssociationType: { if (EModeMTP != iFramework.Mode()) { responseCode = EMTPRespCodeOK; } else if( iMTPTypeUint16.Value() != EMTPAssociationTypeGenericFolder ) { responseCode = EMTPRespCodeInvalidObjectPropValue; } else { responseCode = EMTPRespCodeOK; } } break; case EMTPObjectPropCodeAssociationDesc: { if(TUint32(iMTPTypeUint32.Value()) == 0 ) { responseCode = EMTPRespCodeOK; } else responseCode = EMTPRespCodeInvalidObjectPropValue; } break; default: OstTrace1( TRACE_ERROR, CMTPSETOBJECTPROPVALUE_DOHANDLERESPONSEPHASEL, "Invalid property code %d", propCode); User::Leave( KErrNotSupported ); break; } SendResponseL(responseCode); return EFalse; }
// ----------------------------------------------------------------------------- // CSendObject::DoHandleResponsePhaseObjectL // SendObject // ----------------------------------------------------------------------------- // TBool CSendObject::DoHandleResponsePhaseObjectL() { PRINT( _L( "MM MTP => CSendObject::DoHandleResponsePhaseObjectL" ) ); TBool result = ETrue; TEntry fileEntry; User::LeaveIfError( iFs.Entry( iFullPath, fileEntry ) ); if ( fileEntry.FileSize() != iObjectSize ) { iFs.Delete( iFullPath ); iObjectMgr.UnreserveObjectHandleL( *iReceivedObjectInfo ); TMTPResponseCode responseCode = EMTPRespCodeObjectTooLarge; if ( fileEntry.FileSize() < iObjectSize ) { responseCode = EMTPRespCodeIncompleteTransfer; } SendResponseL( responseCode ); Rollback(); result = EFalse; } // SendObject is cancelled or connection is dropped. if ( result && iCancelled ) { iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest, iConnection ); SendResponseL( EMTPRespCodeTransactionCancelled ); Rollback(); } else if ( result && !iCancelled ) { if ( iObjectSize > 0 ) // media file { TRAPD( err, AddMediaToStoreL() ); PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL err = %d" ), err ); if ( ( iPreviousOperation == EMTPOpCodeSendObjectPropList ) && ( err == KErrNone ) ) { // Only leave when getting proplist element from data received by fw. // It should not happen after ReceiveDataL in which construction of proplist already succeed. SetObjectPropListL(); } // Commits into MTP data object enumeration store the object handle and // storage space previously reserved for the specified object. iFramework.ObjectMgr().CommitReservedObjectHandleL( *iReceivedObjectInfo ); iRollbackList.Append( &CSendObject::RemoveObjectFromDbL ); } // Commit object to MTP data store iFramework.RouteRequestUnregisterL( iExpectedSendObjectRequest, iConnection ); SendResponseL( EMTPRespCodeOK ); } iCancelled = EFalse; PRINT1( _L( "MM MTP <= CSendObject::DoHandleResponsePhaseObjectL result = %d" ), result ); return result; }
LOCAL_C void Test4() // // Test uid's can be read when the file is open // // EFileShareExclusive,EFileShareReadersOnly,EFileShareAny, // EFileStream=0,EFileStreamText=0x100, // EFileRead=0,EFileWrite=0x200 // { test.Next(_L("Uids can be read if the file is open")); RFile f; TEntry entry; TInt r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareExclusive|EFileRead); test_KErrNone(r); r=TheFs.Entry(_L("UIDCHK.DAT"),entry); test_KErrNone(r); test(entry.iName==_L("UIDCHK.DAT")); test(entry.IsTypeValid()); test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T')); f.Close(); r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareExclusive|EFileWrite); test_KErrNone(r); r=TheFs.Entry(_L("UIDCHK.DAT"),entry); test_KErrNone(r); test(entry.iName==_L("UIDCHK.DAT")); test(entry.IsTypeValid()); test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T')); r=f.SetSize(256); test_KErrNone(r); TBuf8<16> des; r=TheFs.ReadFileSection(_L("UIDCHK.DAT"),0,des,16); test_KErrNone(r); f.Close(); r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareReadersOnly|EFileRead); test_KErrNone(r); r=TheFs.Entry(_L("UIDCHK.DAT"),entry); test_KErrNone(r); test(entry.iName==_L("UIDCHK.DAT")); test(entry.IsTypeValid()); test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T')); f.Close(); // EFileShareReadersOnly|EFileWrite is illegal r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileRead); test_KErrNone(r); r=TheFs.Entry(_L("UIDCHK.DAT"),entry); test_KErrNone(r); test(entry.iName==_L("UIDCHK.DAT")); test(entry.IsTypeValid()); test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T')); f.Close(); r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileWrite); test_KErrNone(r); RFile secondFile; r=secondFile.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileWrite); test_KErrNone(r); RFile thirdFile; r=thirdFile.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileRead); test_KErrNone(r); r=TheFs.Entry(_L("UIDCHK.DAT"),entry); test_KErrNone(r); test(entry.iName==_L("UIDCHK.DAT")); test(entry.IsTypeValid()); test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T')); f.Close(); secondFile.Close(); thirdFile.Close(); r=f.Open(TheFs,_L("UIDWINS.PE"),EFileShareAny|EFileWrite); test_KErrNone(r); r=TheFs.Entry(_L("UIDWINS.PE"),entry); test_KErrNone(r); test(entry.iName==_L("UIDWINS.PE")); #if defined(__WINS__) TFileName sessionPath; TheFs.SessionPath(sessionPath); if (sessionPath[0]!='C') test(entry.IsTypeValid()==EFalse); else { test(entry.IsTypeValid()); test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3)); } #else test(entry.IsTypeValid()==EFalse); #endif f.Close(); }