baseport/src/cedar/generic/base/syborg/svphostfs/fs/svphostfil.cpp
changeset 2 d55eb581a87c
parent 1 2fb8b9db1c86
child 3 c2946f91d81f
equal deleted inserted replaced
1:2fb8b9db1c86 2:d55eb581a87c
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <f32file.h>
       
    19 #include <f32fsys.h>
       
    20 #include <f32ver.h>
       
    21 #include <e32uid.h>
       
    22 
       
    23 #include "svphostfsy.h"
       
    24 
       
    25 
       
    26 
       
    27 //////////////////////////////////////////////////////////////////////////
       
    28 //	CSVPHostFileCB							//
       
    29 //////////////////////////////////////////////////////////////////////////	
       
    30 
       
    31 CSVPHostFileCB::CSVPHostFileCB()
       
    32 //
       
    33 // Constructor
       
    34 //
       
    35 	{
       
    36 	DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::CSVPHostFileCB()"));
       
    37 
       
    38 	__DECLARE_NAME(_S("CSVPHostFileCB"));
       
    39 	}
       
    40 
       
    41 CSVPHostFileCB::~CSVPHostFileCB()
       
    42 //
       
    43 // Destructor
       
    44 //
       
    45 	{
       
    46 	DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::~CSVPHostFileCB()"));
       
    47 	if ((TInt)iHandle == KErrBadHandle) return;
       
    48 	
       
    49 	SVP_HOST_FS_DEVICE().FileClose(Drive().DriveNumber(), iHandle);
       
    50 	}
       
    51 
       
    52 TBool CSVPHostFileCB::IsRomDrive() const
       
    53 //
       
    54 // Returns ETrue if the drive number == EDriveZ
       
    55 //
       
    56 	{
       
    57 	DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::IsRomDrive()"));
       
    58 	return(EFalse);
       
    59 	}
       
    60 
       
    61 
       
    62 void CSVPHostFileCB::CheckPos(TInt /*aPos*/)
       
    63 	{
       
    64 	DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::CheckPos()"));
       
    65 	}
       
    66 
       
    67 void CSVPHostFileCB::ReadL(TInt aPos,TInt& aLength ,const TAny* aDes , const RMessagePtr2& aMessage)
       
    68 	{
       
    69 	DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::ReadL(%d,%d)"), aPos, aLength);
       
    70 
       
    71 	TInt n = 0;
       
    72 	TInt pos=aPos;
       
    73 	TInt len=aLength;
       
    74 	TBuf8<0x400> buf;
       
    75 
       
    76 	if (aMessage.Handle() == KLocalMessageHandle)
       
    77 		((TPtr8* )aDes)->SetLength(0);
       
    78 
       
    79 	TUint driveNumber = Drive().DriveNumber() ; 
       
    80 	while (len)
       
    81 		{
       
    82 		TInt s=Min(len,buf.MaxLength());
       
    83 		TSVPHostFsFileReadInfo info(driveNumber, iHandle,s,pos+n,(char*)buf.Ptr());
       
    84 
       
    85 		DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::ReadL pos %d s %d p 0x%08x"), pos+n, s, buf.Ptr());
       
    86 
       
    87 		User::LeaveIfError(SVP_HOST_FS_DEVICE().FileRead(info));
       
    88 
       
    89 		DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::ReadL read %d bytes"), info.iLength);
       
    90 
       
    91 		buf.SetLength(info.iLength);
       
    92 
       
    93 		DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::ReadL set buf length"));
       
    94 
       
    95 		if (aMessage.Handle() == KLocalMessageHandle)
       
    96 		        ((TPtr8* )aDes)->Append(buf);
       
    97 		else
       
    98 		        aMessage.WriteL(0,buf,n);
       
    99 		
       
   100 		n+=info.iLength;
       
   101 
       
   102 		if (((TInt)info.iLength)<s)
       
   103 		        break;
       
   104 		len-=info.iLength;
       
   105 		}
       
   106 	aLength=n;
       
   107 	iCurrentPos=n+aPos;
       
   108 	DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::ReadL aLength %d iCurrentPos %d"), aLength, iCurrentPos);
       
   109 	}
       
   110 
       
   111 
       
   112 
       
   113 void CSVPHostFileCB::WriteL(TInt aPos, TInt& aLength, const TAny* aDes, const RMessagePtr2& aMessage)
       
   114 	{
       
   115 	DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::WriteL(%d,%d)"), aPos, aLength);
       
   116 
       
   117 	TInt n=0;
       
   118 	TInt pos=aPos;
       
   119 	TInt len=aLength;
       
   120 	TBuf8<0x400> buf;
       
   121 	TUint driveNumber = Drive().DriveNumber() ; 
       
   122 	while (len)
       
   123 		{
       
   124 		TInt s=Min(len,buf.MaxLength());
       
   125 
       
   126 		if (aMessage.Handle() == KLocalMessageHandle)
       
   127 			buf.Copy( ((TPtr8* )aDes)->MidTPtr(n, s) );
       
   128 		else
       
   129 			aMessage.ReadL(0,buf,n);
       
   130 
       
   131 		TSVPHostFsFileWriteInfo info(driveNumber, iHandle,s,pos+n,(char*)buf.Ptr());
       
   132 
       
   133 		DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::WriteL pos %d s %d p 0x%08x"), pos+n, s, buf.Ptr());
       
   134 
       
   135 		User::LeaveIfError(SVP_HOST_FS_DEVICE().FileWrite(info));
       
   136 
       
   137 		DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::WriteL wrote %d bytes"), info.iLength);
       
   138 
       
   139 		if (((TInt)info.iLength)<s) 
       
   140 		  {
       
   141 		    DP(_L("** (SVPHOSTFIL) !!! CSVPHostFileCB::WriteL failed to write s %d bytes"), s);
       
   142 			User::Leave(KErrCorrupt);
       
   143 		  }
       
   144 
       
   145 		len-=info.iLength;
       
   146 		n+=info.iLength;
       
   147 		}
       
   148 	aLength=n;
       
   149 	iCurrentPos=n+aPos;
       
   150 	}
       
   151 
       
   152 TInt CSVPHostFileCB::Address(TInt& /*aPos*/) const
       
   153 //
       
   154 //	If ROM file, do a memory map and return the address
       
   155 //	Dummy implementation
       
   156 //
       
   157 	{
       
   158 	DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::Address()"));
       
   159 	return(KErrNone);
       
   160 	}
       
   161 
       
   162 void CSVPHostFileCB::SetSizeL(TInt aSize)
       
   163 //
       
   164 //	Set the file size
       
   165 //
       
   166 	{
       
   167 	DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::SetSizeL()"));
       
   168 	
       
   169 	TSVPHostFsFileSetSizeInfo info(Drive().DriveNumber(), iHandle,aSize);
       
   170 
       
   171 	User::LeaveIfError(SVP_HOST_FS_DEVICE().FileSetSize(info));
       
   172 
       
   173 	}
       
   174 
       
   175 
       
   176 void CSVPHostFileCB::SetEntryL(const TTime& aTime,TUint aSetAttMask,TUint aClearAttMask)
       
   177 // TODO: Not tested
       
   178 	{
       
   179 	DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::SetEntryL()"));
       
   180 	//User::Leave(KErrNotSupported);
       
   181 	}
       
   182 
       
   183 void CSVPHostFileCB::FlushAllL()
       
   184 //
       
   185 // Commit any buffered date to the media.
       
   186 //
       
   187 	{
       
   188 	DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::FlushAll()"));
       
   189 
       
   190 	User::LeaveIfError(SVP_HOST_FS_DEVICE().FlushAll(Drive().DriveNumber()));
       
   191 	}
       
   192 
       
   193 
       
   194 void CSVPHostFileCB::FlushDataL()
       
   195 //
       
   196 //	Commit any buffered date to the media
       
   197 //	Dummy implementation of a pure virtual function
       
   198 //
       
   199 	{
       
   200 	DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::FlushDataL()"));
       
   201 	  
       
   202 	User::LeaveIfError(SVP_HOST_FS_DEVICE().FlushData(Drive().DriveNumber()));
       
   203 	}
       
   204 
       
   205 void CSVPHostFileCB::RenameL(const TDesC& /*aNewName*/)
       
   206 //
       
   207 //	Rename the file while open
       
   208 //	Dummy implementation of a pure virtual function
       
   209 //
       
   210 	{
       
   211 	DP(_L("** (SVPHOSTFIL) CSVPHostFileCB::RenameL()"));
       
   212 
       
   213 	}