os/kernelhwsrv/kerneltest/f32test/ext/t_testext.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// f32test\ext\t_testext.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32math.h>
sl@0
    19
#include "t_testext.h"
sl@0
    20
sl@0
    21
CTestProxyDrive::CTestProxyDrive(CProxyDrive* aProxyDrive, CMountCB* aMount)
sl@0
    22
    : CBaseExtProxyDrive(aProxyDrive,aMount), iMount(aMount)
sl@0
    23
    {
sl@0
    24
    __PRINT(_L("CTestProxyDrive::CTestProxyDrive"));
sl@0
    25
    }
sl@0
    26
sl@0
    27
CTestProxyDrive::~CTestProxyDrive()
sl@0
    28
    {
sl@0
    29
    __PRINT(_L("CTestProxyDrive::~CTestProxyDrive"));
sl@0
    30
    delete[] iMap;
sl@0
    31
    }
sl@0
    32
sl@0
    33
void CTestProxyDrive::InitL()
sl@0
    34
    {
sl@0
    35
    __PRINT(_L("CTestProxyDrive::Init"));
sl@0
    36
sl@0
    37
    DoInitL();
sl@0
    38
sl@0
    39
    // Allocate bad sector bit map
sl@0
    40
    TInt size = (iTotalSectors+7) >> 3; // round up by byte
sl@0
    41
    iMap = new(ELeave) TUint8[size];
sl@0
    42
    Mem::FillZ(iMap, size);
sl@0
    43
sl@0
    44
    iMountInitialised = ETrue;
sl@0
    45
    }
sl@0
    46
sl@0
    47
TInt CTestProxyDrive::ControlIO(const RMessagePtr2& aMessage,TInt aCommand,TAny* aParam1,TAny* aParam2)
sl@0
    48
    {
sl@0
    49
    __PRINT(_L("CTestProxyDrive::ControlIO"));
sl@0
    50
sl@0
    51
    TInt r = KErrNone;
sl@0
    52
sl@0
    53
    if (!iMountInitialised)
sl@0
    54
        return KErrNotReady;
sl@0
    55
sl@0
    56
    switch(aCommand+EExtCustom)
sl@0
    57
        {
sl@0
    58
        case ESetEvent:
sl@0
    59
            r = SetEvent((TInt)aParam1, (TInt)aParam2);
sl@0
    60
            break;
sl@0
    61
        
sl@0
    62
        case EMark:
sl@0
    63
            //-- mark given sector as bad
sl@0
    64
            __PRINT1(_L("CTestProxyDrive: marking sector:%d as bad"), (TInt)aParam1);
sl@0
    65
            r = Mark((TInt)aParam1);
sl@0
    66
            break;
sl@0
    67
        
sl@0
    68
        case EUnmark:
sl@0
    69
            //-- mark given sector as good
sl@0
    70
            __PRINT1(_L("CTestProxyDrive: Unmarking sector:%d"), (TInt)aParam1);
sl@0
    71
            r = Unmark((TInt)aParam1);
sl@0
    72
            break;
sl@0
    73
        
sl@0
    74
        case EUnmarkAll:
sl@0
    75
            r = UnmarkAll();
sl@0
    76
            break;
sl@0
    77
        
sl@0
    78
        case EIsMarked:
sl@0
    79
            if (IsMarked((TInt)aParam1))
sl@0
    80
                r = aMessage.Write(3, TPckgBuf<TBool>(ETrue));
sl@0
    81
            else
sl@0
    82
                r = aMessage.Write(3, TPckgBuf<TBool>(EFalse));
sl@0
    83
            break;
sl@0
    84
        case EDiskSize:
sl@0
    85
            r = aMessage.Write(2, TPckgBuf<TInt64>(iMount->Size()));
sl@0
    86
            break;
sl@0
    87
        default:
sl@0
    88
            r = DoControlIO(aMessage,aCommand,aParam1,aParam2);
sl@0
    89
            __PRINT2(_L("Get unknown command %d error %d"), aCommand, r);
sl@0
    90
        }
sl@0
    91
    return r;
sl@0
    92
    }
sl@0
    93
sl@0
    94
TInt CTestProxyDrive::GetLastErrorInfo(TDes8 &aErrorInfo)
sl@0
    95
    {
sl@0
    96
    __PRINT(_L("CTestProxyDrive::GetLastErrorInfo"));
sl@0
    97
    TPckgBuf<TErrorInfo> errInfoBuf;
sl@0
    98
    errInfoBuf().iReasonCode = iLastErrorReason;
sl@0
    99
    errInfoBuf().iErrorPos = iSuccessBytes;
sl@0
   100
    aErrorInfo = errInfoBuf;
sl@0
   101
sl@0
   102
    return KErrNone;
sl@0
   103
    }
sl@0
   104
sl@0
   105
TInt CTestProxyDrive::SetEvent(TInt aType, TInt aValue)
sl@0
   106
    {
sl@0
   107
    __PRINT(_L("CTestProxyDrive::SetEvent"));
sl@0
   108
sl@0
   109
    switch (aType)
sl@0
   110
        {
sl@0
   111
        case ENone:
sl@0
   112
            break;
sl@0
   113
        case ENext:
sl@0
   114
            iEventType = aType;
sl@0
   115
            break;
sl@0
   116
        case ERandom:
sl@0
   117
            Mark((TInt)(Math::Random() / (TReal64)KMaxTUint) * iTotalSectors);
sl@0
   118
            break;
sl@0
   119
        case EDeterministic:
sl@0
   120
            iEventType = aType;
sl@0
   121
            if (aValue <= 0)
sl@0
   122
                return KErrArgument;
sl@0
   123
            iCount = aValue;
sl@0
   124
            break;
sl@0
   125
        default:
sl@0
   126
            return KErrArgument;
sl@0
   127
        }
sl@0
   128
    return KErrNone;
sl@0
   129
    }
sl@0
   130
sl@0
   131
sl@0
   132
/**
sl@0
   133
    mark aSector as a bad sector by adding it to the bad sectors map
sl@0
   134
    @param  aSector sector number to mark as bad
sl@0
   135
*/
sl@0
   136
TInt CTestProxyDrive::Mark(TInt aSector)
sl@0
   137
    {
sl@0
   138
    __PRINT1(_L("CTestProxyDrive::Mark %d"), aSector);
sl@0
   139
sl@0
   140
    if (aSector >= iTotalSectors)
sl@0
   141
        return KErrNone;
sl@0
   142
    if (aSector < 0)
sl@0
   143
        return KErrArgument;
sl@0
   144
    iMap[aSector>>3] = (TUint8)(iMap[aSector>>3] | (1<<(aSector & 7)));
sl@0
   145
    return KErrNone;
sl@0
   146
    }
sl@0
   147
sl@0
   148
TInt CTestProxyDrive::Unmark(TInt aSector)
sl@0
   149
//
sl@0
   150
// Remove bad cluster aValue from list.
sl@0
   151
//
sl@0
   152
    {
sl@0
   153
    __PRINT1(_L("CTestProxyDrive::Unmark %d"), aSector);
sl@0
   154
sl@0
   155
    if (aSector>=iTotalSectors || aSector<0)
sl@0
   156
        return KErrArgument;
sl@0
   157
    iMap[aSector>>3] = (TUint8)(iMap[aSector>>3] & ~(1<<(aSector & 7)));
sl@0
   158
    return KErrNone;
sl@0
   159
    }
sl@0
   160
sl@0
   161
TInt CTestProxyDrive::UnmarkAll()
sl@0
   162
//
sl@0
   163
// Clear all bad cluster marks.
sl@0
   164
//
sl@0
   165
    {
sl@0
   166
    __PRINT(_L("CTestProxyDrive::UnmarkAll"));
sl@0
   167
sl@0
   168
    Mem::FillZ(iMap, (iTotalSectors+7)>>3);
sl@0
   169
    return KErrNone;
sl@0
   170
    }
sl@0
   171
sl@0
   172
TBool CTestProxyDrive::IsMarked(TInt aSector) const
sl@0
   173
//
sl@0
   174
// Check if cluster number is in bad cluster list.
sl@0
   175
//
sl@0
   176
    {
sl@0
   177
    
sl@0
   178
sl@0
   179
    if (aSector>=iTotalSectors || aSector<0)
sl@0
   180
        return EFalse;
sl@0
   181
    
sl@0
   182
    const TBool bMarked = iMap[aSector>>3] & (1<<(aSector & 7));
sl@0
   183
    if(bMarked)
sl@0
   184
        {
sl@0
   185
        __PRINT1(_L("CTestProxyDrive::IsMarked %d"), aSector);
sl@0
   186
        }
sl@0
   187
sl@0
   188
    return bMarked ;
sl@0
   189
    }
sl@0
   190
sl@0
   191
TBool CTestProxyDrive::CheckEvent(TInt64 aPos, TInt aLength)
sl@0
   192
    {
sl@0
   193
    //__PRINT(_L("CTestProxyDrive::CheckEvent"));
sl@0
   194
sl@0
   195
    if (!iMountInitialised)
sl@0
   196
        return EFalse;
sl@0
   197
sl@0
   198
    return DoCheckEvent(aPos, aLength);
sl@0
   199
    }