os/boardsupport/emulator/emulatorbsp/win_drive/win_media_device.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/boardsupport/emulator/emulatorbsp/win_drive/win_media_device.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,203 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Definitions for the classes that represent Windows media objects, e.g. a file, physical drive or partition.
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 +*/
    1.24 +
    1.25 +#ifndef WIN_MEDIA_DEVICE_H
    1.26 +#define WIN_MEDIA_DEVICE_H
    1.27 +
    1.28 +#include "common.h"
    1.29 +
    1.30 +#define WIN32_LEAN_AND_MEAN
    1.31 +#pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
    1.32 +#include <windows.h>
    1.33 +#pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
    1.34 +#include <winioctl.h> 
    1.35 +#pragma warning( default : 4201 ) // nonstandard extension used : nameless struct/union
    1.36 +
    1.37 +
    1.38 +//-----------------------------------------------------------------------------
    1.39 +
    1.40 +const TUint32 KDefaultSectorSz = 512;       //-- default sector size
    1.41 +const TUint32 KMinMediaSizeInSectors = 128; //-- minimal number of sectors on the media allowed
    1.42 +
    1.43 +
    1.44 +//-----------------------------------------------------------------------------
    1.45 +
    1.46 +/** 
    1.47 +    this structure describes "drive" geometry
    1.48 +    the "drive" consists of a number of sectors.
    1.49 +*/
    1.50 +class TDriveGeometry
    1.51 +{
    1.52 + public:
    1.53 +    TDriveGeometry() {iBytesPerSector=0; iSizeInSectors=0;}
    1.54 +    
    1.55 +    TInt64 TotalSizeInBytes() const {return iBytesPerSector*(TInt64)iSizeInSectors;}
    1.56 +
    1.57 + public:
    1.58 +
    1.59 +    TUint32 iBytesPerSector;  ///< bytes per sectors (usually 512)
    1.60 +    TUint32 iSizeInSectors;   ///< size of the bedia in sectors
    1.61 +};
    1.62 +
    1.63 +
    1.64 +//-----------------------------------------------------------------------------
    1.65 +
    1.66 +/**
    1.67 +    Windows media device creation parameters
    1.68 +*/
    1.69 +class TMediaDeviceParams
    1.70 +{
    1.71 + public:       
    1.72 + 
    1.73 +    TMediaDeviceParams() {ipDevName = NULL; iReadOnly = EFalse;}
    1.74 +
    1.75 + public:
    1.76 +    TDriveGeometry iDrvGeometry;    ///< drive geometry
    1.77 +    const char*    ipDevName;       ///< windows device name
    1.78 +    TBool          iReadOnly;       ///< if ETrue, the device shall be opened as RO
    1.79 +
    1.80 +};
    1.81 +
    1.82 +//-----------------------------------------------------------------------------
    1.83 +
    1.84 +/**
    1.85 +    Abstract class representing interface to the Windows device (file or volume).
    1.86 +*/
    1.87 +class CWinMediaDeviceBase
    1.88 +{
    1.89 + public:  
    1.90 +             CWinMediaDeviceBase();
    1.91 +    virtual ~CWinMediaDeviceBase();
    1.92 +
    1.93 +    virtual TInt Connect(const TMediaDeviceParams& aParams)=0;
    1.94 +    virtual void Disconnect(); 
    1.95 +
    1.96 +
    1.97 +    virtual TInt Read(TInt64 aPos,TInt aLength, TDes8& aDataDes)=0;
    1.98 +    virtual TInt Write(TInt64 aPos,TInt aLength, const TDesC8& aDataDes)=0;
    1.99 +    virtual TInt Erase(TInt64 aPos, TUint32 aLength, TUint8 aFill);
   1.100 +
   1.101 +    void  GetDriveGeometry(TDriveGeometry& aDG) const {aDG = iDrvGeometry;}
   1.102 +
   1.103 + protected:
   1.104 +    
   1.105 +    CWinMediaDeviceBase(const CWinMediaDeviceBase&);
   1.106 +    CWinMediaDeviceBase& operator=(const CWinMediaDeviceBase&);
   1.107 +    
   1.108 +    inline HANDLE Handle() const {return iDevHandle;}
   1.109 +    inline TBool HandleValid() const;
   1.110 +    inline TBool HandleValid(HANDLE aHandle) const;
   1.111 +    
   1.112 +    TUint32 BytesPerSector() const {return iDrvGeometry.iBytesPerSector;}
   1.113 +
   1.114 +    TInt MapWinError(DWORD aWinError) const; 
   1.115 +
   1.116 +    enum {KScratchBufSz = 128*1024}; ///< scratch buffer size
   1.117 +
   1.118 + protected:
   1.119 +    
   1.120 +    HANDLE              iDevHandle;     ///< Windows device handle
   1.121 +    TDriveGeometry      iDrvGeometry;   ///< drive geometry.
   1.122 +    TUint8*             ipScratchBuf;   ///< scratch buffer for IO operations
   1.123 +};
   1.124 +
   1.125 +//-----------------------------------------------------------------------------
   1.126 +
   1.127 +TBool CWinMediaDeviceBase::HandleValid() const 
   1.128 +{
   1.129 +    return HandleValid(iDevHandle);
   1.130 +}
   1.131 +
   1.132 +TBool CWinMediaDeviceBase::HandleValid(HANDLE aHandle) const 
   1.133 +{
   1.134 +    return aHandle && (aHandle != INVALID_HANDLE_VALUE);
   1.135 +}
   1.136 +
   1.137 +
   1.138 +//-----------------------------------------------------------------------------
   1.139 +
   1.140 +/**
   1.141 +    This class represents a windows "volume" device, like a physical or logical drive or partition.
   1.142 +    it can also handle files, but not very effectiively.
   1.143 +*/
   1.144 +class CWinVolumeDevice: public CWinMediaDeviceBase
   1.145 +{
   1.146 + public:  
   1.147 +    CWinVolumeDevice();
   1.148 +   ~CWinVolumeDevice();
   1.149 +
   1.150 +    virtual TInt Connect(const TMediaDeviceParams& aParams);
   1.151 +    virtual TInt Read(TInt64 aPos,TInt aLength, TDes8& aDataDes);
   1.152 +    virtual TInt Write(TInt64 aPos,TInt aLength, const TDesC8& aDataDes);
   1.153 + private:   
   1.154 +    
   1.155 +    MEDIA_TYPE iMediaType;  ///< windows media type.
   1.156 +};
   1.157 +
   1.158 +
   1.159 +
   1.160 +//-----------------------------------------------------------------------------
   1.161 +
   1.162 +/**
   1.163 +    This class represents a windows "file" device, i.e. image file on some drive
   1.164 +*/
   1.165 +class CWinImgFileDevice: public CWinMediaDeviceBase
   1.166 +{
   1.167 + public:  
   1.168 +    CWinImgFileDevice();
   1.169 +   ~CWinImgFileDevice();
   1.170 +
   1.171 +    virtual TInt Connect(const TMediaDeviceParams& aParams);
   1.172 +    virtual void Disconnect(); 
   1.173 +
   1.174 +    virtual TInt Read(TInt64 aPos,TInt aLength, TDes8& aDataDes);
   1.175 +    virtual TInt Write(TInt64 aPos,TInt aLength, const TDesC8& aDataDes);
   1.176 +
   1.177 + private:
   1.178 +   
   1.179 + private:   
   1.180 +    HANDLE  ihFileMapping; ///< handle for the image file mapping
   1.181 +    TUint8* ipImageFile;   ///< pointer to the beginning of the image file mapped into memory
   1.182 +};
   1.183 +
   1.184 +
   1.185 +
   1.186 +
   1.187 +
   1.188 +
   1.189 +
   1.190 +
   1.191 +
   1.192 +
   1.193 +#endif //WIN_MEDIA_DEVICE_H
   1.194 +
   1.195 +
   1.196 +
   1.197 +
   1.198 +
   1.199 +
   1.200 +
   1.201 +
   1.202 +
   1.203 +
   1.204 +
   1.205 +
   1.206 +