Update contrib.
1 // Copyright (c) 2007-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 "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Definitions for the classes that represent Windows media objects, e.g. a file, physical drive or partition.
22 #ifndef WIN_MEDIA_DEVICE_H
23 #define WIN_MEDIA_DEVICE_H
27 #define WIN32_LEAN_AND_MEAN
28 #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
30 #pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
32 #pragma warning( default : 4201 ) // nonstandard extension used : nameless struct/union
35 //-----------------------------------------------------------------------------
37 const TUint32 KDefaultSectorSz = 512; //-- default sector size
38 const TUint32 KMinMediaSizeInSectors = 128; //-- minimal number of sectors on the media allowed
41 //-----------------------------------------------------------------------------
44 this structure describes "drive" geometry
45 the "drive" consists of a number of sectors.
50 TDriveGeometry() {iBytesPerSector=0; iSizeInSectors=0;}
52 TInt64 TotalSizeInBytes() const {return iBytesPerSector*(TInt64)iSizeInSectors;}
56 TUint32 iBytesPerSector; ///< bytes per sectors (usually 512)
57 TUint32 iSizeInSectors; ///< size of the bedia in sectors
61 //-----------------------------------------------------------------------------
64 Windows media device creation parameters
66 class TMediaDeviceParams
70 TMediaDeviceParams() {ipDevName = NULL; iReadOnly = EFalse;}
73 TDriveGeometry iDrvGeometry; ///< drive geometry
74 const char* ipDevName; ///< windows device name
75 TBool iReadOnly; ///< if ETrue, the device shall be opened as RO
79 //-----------------------------------------------------------------------------
82 Abstract class representing interface to the Windows device (file or volume).
84 class CWinMediaDeviceBase
87 CWinMediaDeviceBase();
88 virtual ~CWinMediaDeviceBase();
90 virtual TInt Connect(const TMediaDeviceParams& aParams)=0;
91 virtual void Disconnect();
94 virtual TInt Read(TInt64 aPos,TInt aLength, TDes8& aDataDes)=0;
95 virtual TInt Write(TInt64 aPos,TInt aLength, const TDesC8& aDataDes)=0;
96 virtual TInt Erase(TInt64 aPos, TUint32 aLength, TUint8 aFill);
98 void GetDriveGeometry(TDriveGeometry& aDG) const {aDG = iDrvGeometry;}
102 CWinMediaDeviceBase(const CWinMediaDeviceBase&);
103 CWinMediaDeviceBase& operator=(const CWinMediaDeviceBase&);
105 inline HANDLE Handle() const {return iDevHandle;}
106 inline TBool HandleValid() const;
107 inline TBool HandleValid(HANDLE aHandle) const;
109 TUint32 BytesPerSector() const {return iDrvGeometry.iBytesPerSector;}
111 TInt MapWinError(DWORD aWinError) const;
113 enum {KScratchBufSz = 128*1024}; ///< scratch buffer size
117 HANDLE iDevHandle; ///< Windows device handle
118 TDriveGeometry iDrvGeometry; ///< drive geometry.
119 TUint8* ipScratchBuf; ///< scratch buffer for IO operations
122 //-----------------------------------------------------------------------------
124 TBool CWinMediaDeviceBase::HandleValid() const
126 return HandleValid(iDevHandle);
129 TBool CWinMediaDeviceBase::HandleValid(HANDLE aHandle) const
131 return aHandle && (aHandle != INVALID_HANDLE_VALUE);
135 //-----------------------------------------------------------------------------
138 This class represents a windows "volume" device, like a physical or logical drive or partition.
139 it can also handle files, but not very effectiively.
141 class CWinVolumeDevice: public CWinMediaDeviceBase
147 virtual TInt Connect(const TMediaDeviceParams& aParams);
148 virtual TInt Read(TInt64 aPos,TInt aLength, TDes8& aDataDes);
149 virtual TInt Write(TInt64 aPos,TInt aLength, const TDesC8& aDataDes);
152 MEDIA_TYPE iMediaType; ///< windows media type.
157 //-----------------------------------------------------------------------------
160 This class represents a windows "file" device, i.e. image file on some drive
162 class CWinImgFileDevice: public CWinMediaDeviceBase
166 ~CWinImgFileDevice();
168 virtual TInt Connect(const TMediaDeviceParams& aParams);
169 virtual void Disconnect();
171 virtual TInt Read(TInt64 aPos,TInt aLength, TDes8& aDataDes);
172 virtual TInt Write(TInt64 aPos,TInt aLength, const TDesC8& aDataDes);
177 HANDLE ihFileMapping; ///< handle for the image file mapping
178 TUint8* ipImageFile; ///< pointer to the beginning of the image file mapped into memory
190 #endif //WIN_MEDIA_DEVICE_H