sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32\sfsrv\cl_fraw.cpp sl@0: // sl@0: // sl@0: sl@0: #include "cl_std.h" sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Opens a direct access channel to the disk. sl@0: sl@0: Other resources are disabled from accessing the disk until Close() is called. sl@0: sl@0: Note that if any resources are currently open on the disk, an error sl@0: is returned. sl@0: sl@0: @param aFs The file server session. sl@0: @param aDrive The drive containing the disk to be accessed. Specify a drive sl@0: in the range EDriveA to EDriveZ for drives A to Z. sl@0: sl@0: @return KErrNone, if successful; sl@0: KErrInUse is returned if any resources are currently open on the disk; sl@0: otherwise one of the other system-wide error codes. sl@0: sl@0: @capability TCB sl@0: sl@0: */ sl@0: EXPORT_C TInt RRawDisk::Open(RFs& aFs,TInt aDrive) sl@0: { sl@0: if (!RFs::IsValidDrive(aDrive)) sl@0: return(KErrArgument); sl@0: iDrive=aDrive; sl@0: return(CreateSubSession(aFs,EFsRawDiskOpen,TIpcArgs(aDrive))); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Closes the direct access channel to the disk, and allows other resources sl@0: to access the disk. sl@0: */ sl@0: EXPORT_C void RRawDisk::Close() sl@0: { sl@0: CloseSubSession(EFsRawSubClose); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Reads directly from the disk. sl@0: sl@0: The function reads a number of bytes into the specified descriptor from sl@0: the disk, beginning at the specified position. sl@0: sl@0: @param aPos The position on the disk at which to begin reading. sl@0: @param aDes The descriptor into which data is to be read. sl@0: On return aDes contains the data read. sl@0: sl@0: @panic User In debug builds, the media driver panics if aPos is larger than sl@0: the size of the physical media or if the end address, given by sl@0: aPos + the maximum length of the descriptor, is greater than sl@0: the size of the physical media. sl@0: sl@0: @return KErrNone, if successful, otherwise one of the other system-wide error sl@0: codes. sl@0: sl@0: @capability TCB sl@0: sl@0: */ sl@0: EXPORT_C TInt RRawDisk::Read(TInt64 aPos,TDes8& aDes) sl@0: { sl@0: TInt maxLength = aDes.MaxLength(); sl@0: if (maxLength==0) sl@0: return(KErrNone); sl@0: TPtrC8 tBuf((TUint8*)&aPos,sizeof(TInt64)); sl@0: return(SendReceive(EFsRawDiskRead,TIpcArgs(&aDes,maxLength,&tBuf))); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Writes directly to the disk. sl@0: sl@0: The function writes the contents of the specified descriptor to the sl@0: disk at position aPos. sl@0: sl@0: @param aPos The position at which to begin writing. sl@0: @param aDes The descriptor containing the data to be written to the disk. sl@0: sl@0: @panic User In debug builds, the media driver panics if aPos is larger than sl@0: the size of the physical media or if the end address, given by sl@0: aPos + the maximum length of the descriptor, is greater than sl@0: the size of the physical media. sl@0: sl@0: @return KErrNone, if successful, otherwise one of the other system-wide error sl@0: codes. sl@0: sl@0: @capability TCB sl@0: sl@0: */ sl@0: EXPORT_C TInt RRawDisk::Write(TInt64 aPos,TDesC8& aDes) sl@0: { sl@0: TInt length = aDes.Length(); sl@0: if (length==0) sl@0: return(KErrNone); sl@0: TPtrC8 tBuf((TUint8*)&aPos,sizeof(TInt64)); sl@0: return(SendReceive(EFsRawDiskWrite,TIpcArgs(&aDes,length,&tBuf))); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: // sl@0: // Old read / write methods left in to be BC sl@0: // sl@0: class _RRawDisk : public RRawDisk sl@0: { sl@0: public: sl@0: IMPORT_C TInt Read(TInt aPos,TDes8& aDes); sl@0: IMPORT_C TInt Write(TInt aPos,TDesC8& aDes); sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Reads directly from the disk. sl@0: sl@0: The function reads a number of bytes into the specified descriptor from sl@0: the disk beginning at the specified position. sl@0: sl@0: @param aPos The position on the disk at which to begin reading. sl@0: @param aDes The descriptor into which data is to be read. On return, contains the sl@0: data read. The number of bytes read is the smaller of: sl@0: a) the total number of bytes on the disk minus aPos; sl@0: b) the maximum length of the descriptor. sl@0: sl@0: @return KErrNone, if successful, otherwise one of the other system-wide error sl@0: codes. sl@0: sl@0: @capability TCB sl@0: @deprecated sl@0: */ sl@0: EXPORT_C TInt _RRawDisk::Read(TInt aPos,TDes8& aDes) sl@0: { sl@0: TInt maxLength = aDes.MaxLength(); sl@0: if (maxLength==0) sl@0: return(KErrNone); sl@0: TInt64 pos = MAKE_TINT64(0,aPos); sl@0: TPtrC8 tBuf((TUint8*)&pos,sizeof(TInt64)); sl@0: return(SendReceive(EFsRawDiskRead,TIpcArgs(&aDes,maxLength,&tBuf))); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: Writes directly to the disk. sl@0: sl@0: The function writes the contents of the specified descriptor to the sl@0: disk at position aPos. sl@0: sl@0: @param aPos The position at which to begin writing. sl@0: @param aDes The descriptor containing the data to be written to the disk. sl@0: sl@0: @return KErrNone, if successful, otherwise one of the other system-wide error sl@0: codes. sl@0: sl@0: @capability TCB sl@0: @deprecated sl@0: */ sl@0: EXPORT_C TInt _RRawDisk::Write(TInt aPos,TDesC8& aDes) sl@0: { sl@0: TInt length = aDes.Length(); sl@0: if (length==0) sl@0: return(KErrNone); sl@0: TInt64 pos = MAKE_TINT64(0,aPos); sl@0: TPtrC8 tBuf((TUint8*)&pos,sizeof(TInt64)); sl@0: return(SendReceive(EFsRawDiskWrite,TIpcArgs(&aDes,length,&tBuf))); sl@0: }