userlibandfileserver/fileserver/sfat32/sl_file.cpp
author hgs
Wed, 23 Jun 2010 12:52:28 +0100
changeset 176 af6ec97d9189
parent 148 31ea0f8e3c99
child 231 75252ea6123b
permissions -rw-r--r--
201023_13
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
     1
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
     2
// All rights reserved.
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
     3
// This component and the accompanying materials are made available
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
     4
// under the terms of the License "Eclipse Public License v1.0"
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
     5
// which accompanies this distribution, and is available
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
     7
//
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
     8
// Initial Contributors:
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    10
//
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    11
// Contributors:
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    12
//
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    13
// Description:
148
31ea0f8e3c99 201021_18
hgs
parents: 90
diff changeset
    14
// f32\sfat32\sl_file.cpp
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    15
// 
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    16
//
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    17
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    18
#include "sl_std.h"
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    19
#include "sl_cache.h"
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    20
#include <e32math.h>
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    21
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    22
const TInt KSeekIndexSize=128; // Cache 128 clusters
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    23
const TInt KSeekIndexSizeLog2=7;
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    24
const TInt KFirstClusterNum=2;
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    25
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    26
CFatFileCB::CFatFileCB()
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    27
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    28
    __PRINT1(_L("CFatFileCB created 0x%x"),this);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    29
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    30
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    31
CFatFileCB::~CFatFileCB()
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    32
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    33
    __PRINT1(_L("~CFatFileCB deleted 0x%x"),this);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    34
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    35
    //-- a nasty trick to find out if the CFatFileCB is in consistent state on the moment of destruction.
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    36
    //-- Because of OOM conditions CFatFileCB might not be fully constructed and to be deleted, while FlushAll()
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    37
    //-- implies valid iMount.
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    38
    const CMountCB* pMount  = &Mount();
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    39
    if(pMount)
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    40
        {//-- do some finalisation work if CMountCB is valid
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
    41
        if(FileAttModified())
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
    42
            {
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
    43
            IndicateFileTimeModified(ETrue); //-- this will force writing file modification time to the media on Flush
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    44
            TRAP_IGNORE(FlushAllL());
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    45
            }
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
    46
        }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    47
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    48
    delete[] iSeekIndex;
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    49
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    50
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    51
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    52
void CFatFileCB::CreateSeekIndex()
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    53
//
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    54
// Create a seek index
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    55
//
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    56
    {
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    57
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    58
    iSeekIndex = new TUint32[KSeekIndexSize];
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    59
    if (iSeekIndex == NULL)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    60
        return;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    61
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    62
    Mem::FillZ(iSeekIndex, sizeof(TUint32) * KSeekIndexSize);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    63
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    64
    iSeekIndexSize=CalcSeekIndexSize(FCB_FileSize());
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    65
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    66
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
    67
TInt CFatFileCB::SeekToPosition(TUint aNewRelCluster, TUint aClusterOffset)
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    68
//
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    69
// Use the seek index to set iCurrentPos.iCluster as close as possible to aNewRelCluster
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    70
// Return aNewRelCluster-aCurrentPos.iCluster
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    71
//
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    72
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    73
    TInt clusterOffset=aClusterOffset;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    74
    TInt seekPos=(aNewRelCluster>>iSeekIndexSize)-1;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    75
    __ASSERT_DEBUG(seekPos<KSeekIndexSize,Fault(EFatFileSeekIndexTooSmall));
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    76
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    77
    while(seekPos>=0 && iSeekIndex[seekPos]==0 && clusterOffset!=0)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    78
        {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    79
        seekPos--;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    80
        clusterOffset--;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    81
        }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    82
    if (clusterOffset==0) // Counted back to the current cluster
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    83
        return(aClusterOffset);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    84
    if (seekPos<0)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    85
        {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    86
        iCurrentPos.iCluster=FCB_StartCluster();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    87
        return(aNewRelCluster);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    88
        }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    89
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    90
    iCurrentPos.iCluster=iSeekIndex[seekPos];
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    91
    return(aNewRelCluster-((seekPos+1)<<iSeekIndexSize));
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    92
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    93
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
    94
void CFatFileCB::SetSeekIndexValueL(TUint aRelCluster, TUint aStoredCluster)
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    95
//
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    96
// Sets a value in the seekindex
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    97
//
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
    98
    {
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
    99
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   100
    TInt seekPos=(aRelCluster>>iSeekIndexSize)-1;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   101
    __ASSERT_DEBUG(seekPos<KSeekIndexSize,Fault(EFatFileSeekIndexTooSmall));
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   102
    __ASSERT_DEBUG(seekPos>=0,Fault(EFatFileSeekIndexTooSmall2));
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   103
    iSeekIndex[seekPos] = aStoredCluster;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   104
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   105
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   106
TBool CFatFileCB::IsSeekBackwards(TUint aPos)
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   107
//
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   108
// Return true if aPos<currentPos
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   109
//
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   110
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   111
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   112
    TUint cluster=iCurrentPos.iCluster<<ClusterSizeLog2();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   113
    TInt offset=ClusterRelativePos(iCurrentPos.iPos);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   114
    TUint currentPos=cluster+offset;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   115
    return(aPos<currentPos);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   116
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   117
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   118
void CFatFileCB::CheckPosL(TUint aPos)
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   119
//
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   120
// Check that the file is positioned correctly.
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   121
// If aPos<currentPos attempt to guess the new position.
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   122
//
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   123
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   124
    __PRINT1(_L("CFatFileCB::CheckPosL(%d)"), aPos);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   125
    if (aPos==iCurrentPos.iPos)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   126
        return;
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   127
    __ASSERT_DEBUG(aPos <= FCB_FileSize(), Fault(EFatFilePosBeyondEnd));
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   128
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   129
    if (FileSizeModified() && IsSeekBackwards(aPos))
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   130
        FlushDataL(); 
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   131
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   132
    TUint newRelCluster=aPos>>ClusterSizeLog2();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   133
    if ( aPos && (aPos==(newRelCluster<<ClusterSizeLog2())) )
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   134
        newRelCluster--;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   135
    TUint oldRelCluster=iCurrentPos.iPos>>ClusterSizeLog2();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   136
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   137
    if ( iCurrentPos.iPos && (iCurrentPos.iPos==(oldRelCluster<<ClusterSizeLog2())) )
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   138
        oldRelCluster--;    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   139
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   140
    TInt clusterOffset=newRelCluster-oldRelCluster;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   141
    TUint32 oldCluster=iCurrentPos.iCluster;
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   142
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   143
    iCurrentPos.iPos=aPos;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   144
    if (clusterOffset==0)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   145
        return;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   146
    TInt seekOffset=clusterOffset;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   147
    if (iSeekIndex!=NULL)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   148
        { // Can alter iCurrentPos.iCluster
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   149
        seekOffset=SeekToPosition(newRelCluster,seekOffset);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   150
        if (seekOffset==0)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   151
            return;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   152
        }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   153
    if (clusterOffset==-1 && seekOffset!=1)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   154
        { // Check previous cluster
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   155
        TUint32 cluster=oldCluster-1;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   156
        if (FAT().GetNextClusterL(cluster) && cluster==oldCluster)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   157
            {
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   158
            iCurrentPos.iCluster=oldCluster-1;
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   159
            return;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   160
            }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   161
        }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   162
    if (seekOffset<0)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   163
        {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   164
        seekOffset=newRelCluster;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   165
        iCurrentPos.iCluster=FCB_StartCluster();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   166
        }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   167
    while (seekOffset--)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   168
        {
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   169
        if (!FAT().GetNextClusterL(iCurrentPos.iCluster))
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   170
            {
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   171
            __PRINT(_L("CFatFileCB::CheckPosL() corrupt#1"));
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   172
            User::Leave(KErrCorrupt);
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   173
            }
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   174
        TInt cluster=newRelCluster-seekOffset;
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   175
        if (iSeekIndex!=NULL && cluster && (cluster>>iSeekIndexSize)<<iSeekIndexSize==cluster)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   176
            SetSeekIndexValueL(cluster,iCurrentPos.iCluster);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   177
        }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   178
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   179
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   180
//-----------------------------------------------------------------------------
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   181
/** 
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   182
    Initialize FileCB from file's entry data.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   183
    
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   184
    @param  aFatDirEntry        this file DOS dir entry.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   185
    @param  aFileDosEntryPos    this file DOS entry dir. iterator in the parent directory.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   186
*/
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   187
void CFatFileCB::SetupL(const TFatDirEntry& aFatDirEntry, const TEntryPos& aFileDosEntryPos)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   188
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   189
    __PRINT1(_L("CFatFileCB::SetupL[0x%x]"), this);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   190
    
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   191
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   192
    //-- set up a file control block
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   193
    iCurrentPos.iCluster= FatMount().StartCluster(aFatDirEntry);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   194
    iCurrentPos.iPos=0;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   195
    
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   196
    SetAtt(aFatDirEntry.Attributes());
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   197
    SetModified(aFatDirEntry.Time(FatMount().TimeOffset()));
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   198
    
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   199
    FCB_SetStartCluster(iCurrentPos.iCluster);
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   200
    FCB_SetFileSize(aFatDirEntry.Size()); 
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   201
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   202
    iFileDosEntryPos = aFileDosEntryPos;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   203
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   204
    SetMaxSupportedSize(KMaxSupportedFatFileSize);
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   205
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   206
    //-- create seek index
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   207
    ASSERT(!iSeekIndex);
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   208
    CreateSeekIndex();
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   209
    if(!iSeekIndex)
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   210
        User::Leave(KErrNoMemory);
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   211
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   212
    
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   213
    IndicateFileAttModified(EFalse);
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   214
    IndicateFileSizeModified(EFalse);
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   215
    IndicateFileTimeModified(EFalse);
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   216
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   217
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   218
//-----------------------------------------------------------------------------
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   219
/**
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   220
    Read data from the file.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   221
    
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   222
    @param  aFilePos    start read position within a file
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   223
    @param  aLength     how many bytes to read; on return will be how many bytes actually read
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   224
    @param  aDes        local buffer desctriptor
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   225
    @param  aMessage    from file server, used to write data to the buffer in different address space.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   226
    @param  aDesOffset  offset within data descriptor where the data will be copied
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   227
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   228
    @leave on media read error
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   229
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   230
*/
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   231
void CFatFileCB::ReadL(TInt64 aPos,TInt& aLength, TDes8* aDes, const RMessagePtr2& aMessage, TInt aOffset)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   232
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   233
    __PRINT3(_L("CFatFileCB::ReadL[0x%x] pos=%LU len=%d"), this, aPos, aLength);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   234
    
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   235
    if((TUint64)aPos > KMaxSupportedFatFileSize-1)
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   236
        User::Leave(KErrNotSupported);  //-- max. position in the file is 0xFFFFFFFE
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   237
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   238
    FatMount().CheckStateConsistentL();
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   239
    
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   240
    CheckPosL(I64LOW(aPos));
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   241
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   242
    const TUint startPos = iCurrentPos.iPos;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   243
    const TUint curSize  = FCB_FileSize();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   244
    const TUint length   = (TUint)aLength;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   245
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   246
    if((startPos + length > curSize) || (startPos > startPos + length) )
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   247
        aLength=curSize-startPos;
148
31ea0f8e3c99 201021_18
hgs
parents: 90
diff changeset
   248
		
31ea0f8e3c99 201021_18
hgs
parents: 90
diff changeset
   249
	TUint flag = DirectIOMode(aMessage) ? RLocalDrive::ELocDrvDirectIO : 0;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   250
	
148
31ea0f8e3c99 201021_18
hgs
parents: 90
diff changeset
   251
    FatMount().ReadFromClusterListL(iCurrentPos,aLength,aDes,aMessage,aOffset, flag);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   252
	aLength=iCurrentPos.iPos-startPos;
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   253
	}
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   254
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   255
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   256
void CFatFileCB::ReadL(TInt aFilePos,TInt& aLength,const TAny* aTrg,const RMessagePtr2& aMessage)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   257
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   258
    ReadL(TInt64(aFilePos),aLength,(TDes8*) aTrg,aMessage, 0);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   259
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   260
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   261
//-----------------------------------------------------------------------------
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   262
/**
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   263
    Write data to the file.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   264
    
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   265
    @param  aFilePos    start write position within a file
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   266
    @param  aLength     how many bytes to write; on return contain amount of data actually written
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   267
    @param  aDes        local buffer desctriptor
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   268
    @param  aMessage    from file server, used to write data to the media from different address space.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   269
    @param  aDesOffset  offset within data descriptor 
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   270
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   271
    @leave on media read error
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   272
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   273
*/
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   274
void CFatFileCB::WriteL(TInt64 aPos,TInt& aLength,const TDesC8* aSrc,const RMessagePtr2& aMessage, TInt aOffset)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   275
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   276
    __PRINT3(_L("CFatFileCB::WriteL[0x%x] pos=%LU len=%d"), this, aPos, aLength);
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   277
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   278
    // FAT supports 32 bits only for file size
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   279
    TUint64 endPos = aPos + aLength;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   280
    if(endPos > KMaxSupportedFatFileSize)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   281
        User::Leave(KErrNotSupported);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   282
    
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   283
    FatMount().CheckStateConsistentL();
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   284
    FatMount().CheckWritableL();
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   285
    const TUint pos = I64LOW(aPos);
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   286
    CheckPosL(pos);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   287
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   288
    const TUint startCluster = FCB_StartCluster();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   289
    const TUint length       = (TUint)aLength;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   290
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   291
    endPos = iCurrentPos.iPos + length; 
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   292
    if ((endPos           > FCB_FileSize()) ||
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   293
        (iCurrentPos.iPos > endPos)         ) // Overflow condition 
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   294
        DoSetSizeL(iCurrentPos.iPos+length,EFalse);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   295
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   296
    TUint startPos=iCurrentPos.iPos;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   297
    TUint badcluster=0;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   298
    TUint goodcluster=0;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   299
   	
148
31ea0f8e3c99 201021_18
hgs
parents: 90
diff changeset
   300
	TUint flag = DirectIOMode(aMessage) ? RLocalDrive::ELocDrvDirectIO : 0;
31ea0f8e3c99 201021_18
hgs
parents: 90
diff changeset
   301
	
31ea0f8e3c99 201021_18
hgs
parents: 90
diff changeset
   302
	TRAPD(ret, FatMount().WriteToClusterListL(iCurrentPos,aLength,aSrc,aMessage,aOffset,badcluster, goodcluster, flag));
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   303
   	
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   304
    if (ret == KErrCorrupt || ret == KErrDied)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   305
        {
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   306
        if(startCluster == 0)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   307
            { //Empty File, revert all the clusters allocated.
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   308
            const TUint32 cluster = FCB_StartCluster();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   309
            FCB_SetStartCluster(0);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   310
            FCB_SetFileSize(0);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   311
            IndicateFileSizeModified(ETrue);
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   312
            
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   313
            FlushAllL();
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   314
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   315
            iCurrentPos.iCluster = 0;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   316
            iCurrentPos.iPos = 0;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   317
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   318
            FAT().FreeClusterListL(cluster);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   319
            FAT().FlushL();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   320
            }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   321
        else
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   322
            { //Calculate the clusters required based on file size, revert extra clusters if allocated.
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   323
            const TUint curSize = FCB_FileSize();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   324
            TUint ClustersNeeded = curSize >> ClusterSizeLog2();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   325
            if(curSize > (ClustersNeeded << ClusterSizeLog2()))
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   326
                {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   327
                ClustersNeeded++;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   328
                }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   329
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   330
            TUint32 cluster = FCB_StartCluster();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   331
            while(--ClustersNeeded)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   332
                {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   333
                FAT().GetNextClusterL(cluster);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   334
                }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   335
                
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   336
            iCurrentPos.iCluster = cluster;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   337
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   338
            if (FAT().GetNextClusterL(cluster))
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   339
                {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   340
                FAT().FreeClusterListL(cluster);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   341
                }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   342
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   343
            FAT().WriteFatEntryEofL(iCurrentPos.iCluster);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   344
            FAT().FlushL();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   345
            }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   346
        }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   347
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   348
    User::LeaveIfError(ret);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   349
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   350
    if(badcluster != 0)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   351
        {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   352
        if(FCB_StartCluster() == badcluster)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   353
            {
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   354
            FCB_SetStartCluster(goodcluster);
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   355
            FlushStartClusterL();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   356
            }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   357
        else
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   358
            {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   359
            TUint32 aCluster = FCB_StartCluster();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   360
            do
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   361
                {
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   362
                if((TUint)badcluster == FAT().ReadL(aCluster))
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   363
                    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   364
                    FAT().WriteL(aCluster, goodcluster);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   365
                    FAT().FlushL();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   366
                    break;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   367
                    }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   368
                }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   369
            while(FAT().GetNextClusterL(aCluster));
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   370
            }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   371
        }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   372
    aLength=iCurrentPos.iPos-startPos;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   373
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   374
    if(!IsSequentialMode() && FatMount().IsRuggedFSys() && pos+(TUint)aLength > FCB_FileSize())
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   375
        {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   376
        WriteFileSizeL(pos+aLength);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   377
        }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   378
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   379
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   380
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   381
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   382
void CFatFileCB::WriteL(TInt aFilePos,TInt& aLength,const TAny* aSrc,const RMessagePtr2& aMessage)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   383
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   384
    WriteL(TInt64(aFilePos),aLength,(TDesC8*) aSrc,aMessage, 0);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   385
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   386
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   387
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   388
//-----------------------------------------------------------------------------
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   389
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   390
void CFatFileCB::ResizeIndex(TInt aNewMult,TUint aNewSize)
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   391
//
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   392
// Resize the seek index to accomodate a larger or smaller filesize
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   393
// Assumes KSeekIndexSize is a power of 2.
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   394
//
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   395
    {
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   396
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   397
    TInt maxNewIndex=aNewSize>>(ClusterSizeLog2()+aNewMult);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   398
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   399
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   400
    TInt    index=0;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   401
    TInt    indexEnd=KSeekIndexSize;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   402
    TInt    newValEnd=maxNewIndex;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   403
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   404
    if (iSeekIndexSize<aNewMult)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   405
        {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   406
        TInt newVal=index;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   407
        TInt step=1<<(aNewMult-iSeekIndexSize);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   408
        index+=step-1;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   409
        while(index<indexEnd && newVal<newValEnd)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   410
            {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   411
            iSeekIndex[newVal] =  iSeekIndex[index];
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   412
            newVal++;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   413
            index+=step;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   414
            }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   415
        while(newVal<indexEnd)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   416
            iSeekIndex[newVal++] =  0;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   417
        }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   418
    else
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   419
        {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   420
        TInt diffSize = iSeekIndexSize-aNewMult;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   421
        TInt oldVal=(KSeekIndexSize>>diffSize) - 1;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   422
        TInt newVal=indexEnd-1;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   423
        TInt skip=(1<<diffSize)-1;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   424
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   425
        if ((iSeekIndexSize - aNewMult) > KSeekIndexSizeLog2)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   426
            {
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   427
            ClearIndex(0); //-- Invalidate every entry.
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   428
            }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   429
        else
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   430
            {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   431
            while(newVal>=index)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   432
                {
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   433
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   434
                iSeekIndex[newVal--] =  iSeekIndex[oldVal--];
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   435
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   436
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   437
                for(TInt i=skip;i>0;i--)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   438
                    {   
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   439
                    iSeekIndex[newVal--] = 0;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   440
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   441
                    }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   442
                }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   443
            }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   444
        }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   445
    iSeekIndexSize=aNewMult;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   446
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   447
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   448
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   449
/**
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   450
    Zero freed clusters in the index
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   451
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   452
    @param  aNewSize new size of the file that the index corresponds to.
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   453
            if = 0  all existing index will be zero filled
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   454
*/ 
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   455
void CFatFileCB::ClearIndex(TUint aNewSize)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   456
    {
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   457
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   458
    if (!iSeekIndex)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   459
        return;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   460
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   461
    if(aNewSize==0)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   462
        {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   463
        //-- zero fill all the array
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   464
        Mem::FillZ(iSeekIndex, KSeekIndexSize*sizeof(TUint32));
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   465
        return;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   466
        }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   467
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   468
    // Files that fill up a cluster exactly do not have a trailing empty
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   469
    // cluster. So the entry for that position must also be invalidated
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   470
    aNewSize--;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   471
    TInt firstInvalidIndex=aNewSize>>(iSeekIndexSize+ClusterSizeLog2());
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   472
        
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   473
    TInt indexLen=KSeekIndexSize-firstInvalidIndex;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   474
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   475
    Mem::FillZ(iSeekIndex+firstInvalidIndex, indexLen * sizeof(TUint32));
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   476
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   477
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   478
TInt CFatFileCB::CalcSeekIndexSize(TUint aSize)
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   479
//
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   480
// Find the nearest power of 2 > aSize
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   481
//
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   482
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   483
    TInt count = 0;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   484
    const TUint indexSize=KSeekIndexSize<<ClusterSizeLog2();//KSeekIndexSize=128
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   485
    if (aSize<=indexSize)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   486
      return(count);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   487
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   488
    while((aSize>>=1)>0)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   489
        {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   490
        count++;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   491
        }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   492
    return (count - (KSeekIndexSizeLog2 + ClusterSizeLog2()) + 1);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   493
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   494
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   495
//-----------------------------------------------------------------------------
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   496
/**
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   497
    Set file size.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   498
    @param aSize new file size.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   499
*/
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   500
void CFatFileCB::SetSizeL(TInt64 aSize)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   501
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   502
    __PRINT2(_L("CFatFileCB::SetSizeL[0x%x] sz=%LU"), this, aSize);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   503
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   504
    //-- max. file size for FAT is 4GB-1
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   505
    if (I64HIGH(aSize))
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   506
        User::Leave(KErrNotSupported);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   507
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   508
    DoSetSizeL(I64LOW(aSize), FatMount().IsRuggedFSys());
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   509
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   510
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   511
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   512
void CFatFileCB::SetSizeL(TInt aSize)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   513
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   514
    SetSizeL(TInt64(aSize));
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   515
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   516
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   517
//-----------------------------------------------------------------------------
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   518
/**
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   519
    Shrink file to zero size.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   520
*/
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   521
void CFatFileCB::DoShrinkFileToZeroSizeL()
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   522
    {
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   523
        ASSERT(FCB_FileSize());
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   524
        ASSERT(FileSizeModified());
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   525
        
148
31ea0f8e3c99 201021_18
hgs
parents: 90
diff changeset
   526
        ClearIndex(0); // Clear seek index array
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   527
        
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   528
        //-- update file dir. entry
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   529
        const TUint32 cluster = FCB_StartCluster();
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   530
        FCB_SetStartCluster(0);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   531
        FCB_SetFileSize(0);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   532
            FlushAllL();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   533
        
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   534
        //-- free cluster list. 
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   535
            CheckPosL(0);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   536
            FAT().FreeClusterListL(cluster);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   537
            FAT().FlushL();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   538
            }
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   539
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   540
//-----------------------------------------------------------------------------
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   541
/*
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   542
    Shrink file to smaller size, but > 0
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   543
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   544
    @param aNewSize new file size
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   545
    @param aForceCachesFlush if ETrue, all file/FAT caches will be flushed 
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   546
*/
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   547
void CFatFileCB::DoShrinkFileL(TUint32 aNewSize, TBool aForceCachesFlush)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   548
    {
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   549
    ASSERT(FileSizeModified());
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   550
    ASSERT(FCB_FileSize() > aNewSize && aNewSize);
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   551
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   552
    if(aForceCachesFlush)       
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   553
        WriteFileSizeL(aNewSize); //-- write file size directly to its dir. entry
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   554
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   555
    CheckPosL(aNewSize);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   556
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   557
    TUint32 cluster=iCurrentPos.iCluster;
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   558
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   559
    if (FAT().GetNextClusterL(cluster))
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   560
        {//-- truncate the cluster chain
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   561
        FAT().WriteFatEntryEofL(iCurrentPos.iCluster);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   562
        FAT().FreeClusterListL(cluster);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   563
        }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   564
        
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   565
    ClearIndex(aNewSize);
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   566
    FAT().FlushL();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   567
    }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   568
    
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   569
//-----------------------------------------------------------------------------
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   570
/**
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   571
    Expand a file.
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   572
    
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   573
    @param aNewSize new file size.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   574
    @param aForceCachesFlush if ETrue, all file/FAT caches will be flushed
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   575
*/
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   576
void CFatFileCB::DoExpandFileL(TUint32 aNewSize, TBool aForceCachesFlush)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   577
    {
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   578
    ASSERT(FCB_FileSize() < aNewSize);
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   579
    ASSERT(FileSizeModified());
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   580
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   581
    const TUint32 KClusterSzLog2  = ClusterSizeLog2();
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   582
    const TUint32 newSizeClusters = (TUint32)(((TUint64)aNewSize + Pow2(KClusterSzLog2) - 1) >> KClusterSzLog2);
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   583
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   584
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   585
    //-- expanding a file
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   586
    if (FCB_StartCluster() == 0)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   587
        {//-- the initial file size is 0 (no cluster chain)
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   588
         
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   589
        ClearIndex(0); //-- clear seek index array
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   590
        //-- FAT().FreeClusterHint() will give us a hint of the last free cluster
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   591
        const TUint32 tempStartCluster=FAT().AllocateClusterListL(newSizeClusters, FAT().FreeClusterHint()); 
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   592
        FAT().FlushL();
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   593
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   594
        iCurrentPos.iCluster=tempStartCluster;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   595
        FCB_SetStartCluster(tempStartCluster);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   596
        FCB_SetFileSize(aNewSize);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   597
        FlushAllL();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   598
        }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   599
    else
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   600
        {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   601
        const TUint curSize = FCB_FileSize(); 
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   602
        const TUint32 oldSizeClusters = ((curSize + Pow2(KClusterSzLog2) - 1) >> KClusterSzLog2);
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   603
        ASSERT(newSizeClusters >= oldSizeClusters);
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   604
        const TUint newClusters = newSizeClusters-oldSizeClusters;  //-- Number of clusters we need to append to the existing cluster chain
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   605
        if (newClusters)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   606
            {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   607
            TEntryPos currentPos=iCurrentPos;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   608
            CheckPosL(FCB_FileSize());
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   609
            FAT().ExtendClusterListL(newClusters,iCurrentPos.iCluster);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   610
            iCurrentPos=currentPos;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   611
            }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   612
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   613
        FAT().FlushL();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   614
        
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   615
        if(!IsSequentialMode() && aForceCachesFlush)    // Write file size directly to its dir. entry if a cache flush
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   616
            WriteFileSizeL(aNewSize);               // is needed and rugged FAT is not ignored by client
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   617
        }
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   618
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   619
    }
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   620
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   621
//-----------------------------------------------------------------------------
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   622
/**
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   623
    Set file size. This can involve extending/truncating file's cluster chain.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   624
    @param  aSize               new file size
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   625
    @param  aForceCachesFlush   if ETrue, all changes in metadata will go to the media immediately. 
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   626
                                it is used in Rugged FAT mode.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   627
*/
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   628
void CFatFileCB::DoSetSizeL(TUint aSize, TBool aForceCachesFlush)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   629
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   630
    __PRINT4(_L("CFatFileCB::DoSetSizeL[0x%x] sz:%d, oldSz:%d, flush:%d"), this, aSize, FCB_FileSize(), aForceCachesFlush);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   631
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   632
    FatMount().CheckStateConsistentL();
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   633
    FatMount().CheckWritableL();
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   634
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   635
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   636
    // Can not change the file size if it is clamped
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   637
    if(Mount().IsFileClamped(MAKE_TINT64(0,FCB_StartCluster())) > 0)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   638
        User::Leave(KErrInUse);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   639
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   640
    if(aSize == FCB_FileSize())
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   641
        return;
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   642
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   643
    IndicateFileSizeModified(ETrue);
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   644
	IndicateFileAttModified(ETrue);		// ensure file size is flushed
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   645
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   646
	TInt newIndexMult=CalcSeekIndexSize(aSize);
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   647
	if (iSeekIndex!=NULL && newIndexMult!=iSeekIndexSize)
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   648
		ResizeIndex(newIndexMult,aSize);
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   649
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   650
	//-------------------------------------------
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   651
    //-- shrinking file to 0 size
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   652
    if(aSize == 0)
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   653
        {
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   654
        DoShrinkFileToZeroSizeL();
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   655
        return;
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   656
        }
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   657
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   658
    //-------------------------------------------
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   659
    //-- shrinking file to non-zero size
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   660
    if (aSize < FCB_FileSize())
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   661
        {
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   662
        DoShrinkFileL(aSize, aForceCachesFlush);
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   663
        return;
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   664
        }
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   665
    
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   666
    //-------------------------------------------
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   667
    //-- expanding a file
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   668
    DoExpandFileL(aSize, aForceCachesFlush);
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   669
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   670
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   671
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   672
//-----------------------------------------------------------------------------
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   673
/**
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   674
    Set file entry details, like file attributes and modified time
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   675
    This method doesn't write data to the media immediately, instead, all modified data are cached and can be flushed later 
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   676
    in FlushAllL()
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   677
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   678
    @param  aTime           file modification time (and last access as well)
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   679
    @param  aSetAttMask     file attributes OR mask
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   680
    @param  aClearAttMask   file attributes AND mask
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   681
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   682
*/
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   683
void CFatFileCB::SetEntryL(const TTime& aTime,TUint aSetAttMask,TUint aClearAttMask)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   684
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   685
    __PRINT1(_L("CFatFileCB::SetEntryL[0x%x]"), this);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   686
    
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   687
    FatMount().CheckStateConsistentL();
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   688
    FatMount().CheckWritableL();
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   689
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   690
    //-- change file attributes
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   691
    const TUint setAttMask = (aSetAttMask & KEntryAttMaskSupported); //-- supported attributes to set
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   692
	TUint oldAtt = Att();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   693
	TUint newAtt = oldAtt;
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   694
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   695
	if (setAttMask|aClearAttMask)
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   696
		{
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   697
        newAtt |= setAttMask;
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   698
        newAtt &= ~aClearAttMask;
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   699
		if (newAtt != oldAtt)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   700
			{
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   701
	        SetAtt(newAtt);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   702
		    IndicateFileAttModified(ETrue); //-- indicate that file attributes have changed
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   703
			}
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   704
		}
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   705
    
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   706
    //-- set file entry modification time if required
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   707
	if (aSetAttMask&KEntryAttModified)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   708
		{
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   709
        SetModified(aTime);        //-- set file modified time
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   710
        IndicateFileAttModified(ETrue); //-- indicate that file attributes have changed
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   711
        IndicateFileTimeModified(ETrue); //-- this will force writing file mod. time to the media on Flush
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   712
        }
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   713
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   714
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   715
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   716
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   717
//-----------------------------------------------------------------------------
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   718
/** 
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   719
    The same as FlushAllL(). This method is called from RFile::Flush()
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   720
*/
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   721
void CFatFileCB::FlushDataL()
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   722
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   723
    __PRINT1(_L("CFatFileCB::FlushDataL[0x%x]"), this);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   724
    FlushAllL();
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   725
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   726
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   727
//-----------------------------------------------------------------------------
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   728
/** 
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   729
    Flush the fide directory entry data: files size, attributes, time etc. 
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   730
*/
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   731
void CFatFileCB::FlushAllL()
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   732
    {
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   733
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   734
    //-- define this symbol in order to enable legacy behaviour, i.e. compulsory updating file dir. entry on flush.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   735
    //-- otherwise the FlushAllL() will update the file dir. entry only if it differs from what is on the media, i.e.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   736
    //-- file size, start cluster, attributes and modification timestamp
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   737
    #define ALWAYS_UPDATE_ENTRY_ON_FLUSH
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   738
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   739
    __PRINT1(_L("CFatFileCB::FlushAllL[0x%x]"), this);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   740
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   741
    if (Mount().IsCurrentMount()==EFalse)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   742
        User::Leave(KErrDisMounted);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   743
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   744
    FatMount().CheckStateConsistentL();
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   745
    FatMount().CheckWritableL();
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   746
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   747
    if(!FileSizeModified() && !FileAttModified() && !FileTimeModified())
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   748
        return; //-- nothing has changed in the file entry at all
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   749
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   750
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   751
    //-- read file dir. entry
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   752
    TFatDirEntry entry;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   753
    FatMount().ReadDirEntryL(iFileDosEntryPos,entry);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   754
    __ASSERT_ALWAYS(entry.IsEndOfDirectory()==EFalse,User::Leave(KErrCorrupt));
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   755
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   756
    //-- the problem with KEntryAttModified here is that the file server uses this flag to 
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   757
    //-- deal with dirty file data. This means that this flag can be set even if there were no changes
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   758
    //-- in file time and attributes. Just check if any of the entry field has changed at all
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   759
    
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   760
    TBool bUpdateDirEntry = ETrue;
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   761
    const TTimeIntervalSeconds  timeOffset = FatMount().TimeOffset();
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   762
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   763
#ifndef ALWAYS_UPDATE_ENTRY_ON_FLUSH
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   764
    
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   765
    TBool bTimeModified = FileTimeModified();  //-- check if file modifiication time has been changed explicitly
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   766
    if(bTimeModified)
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   767
        {//-- additional check; for FAT entry modification time has 2 sec. granularity.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   768
        bTimeModified = !entry.IsTimeTheSame(iModified, timeOffset);
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   769
        }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   770
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   771
    if(!bTimeModified)
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   772
      if(//-- TS is the same as on the media, check other entry fields
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   773
        (entry.Attributes() == (Att() & KEntryAttMaskSupported)) && //-- file attributes have not changed
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   774
        (entry.Size() == FCB_FileSize()) &&                         //-- file size hasn't changed
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   775
        (entry.StartCluster() == FCB_StartCluster())                //-- file start cluster hasn't changed 
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   776
        )               
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   777
        {
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   778
        bUpdateDirEntry = EFalse; //-- no need to update file dir. entry
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   779
        }
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   780
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   781
#endif //#ifndef ALWAYS_UPDATE_ENTRY_TS_ON_FLUSH
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   782
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   783
    if(bUpdateDirEntry)
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   784
        {//-- write entry to the media
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   785
        __PRINT(_L("  CFatFileCB::FlushAllL #1"));
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   786
        entry.SetAttributes(Att() & KEntryAttMaskSupported);
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   787
        entry.SetSize(FCB_FileSize());
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   788
        entry.SetTime(iModified, timeOffset);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   789
        
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   790
        entry.SetStartCluster(FCB_StartCluster());
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   791
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   792
	    const TBool setNotify = FatMount().GetNotifyUser();
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   793
		if(setNotify)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   794
			{
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   795
			FatMount().SetNotifyOff();	// do not launch a notifier
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   796
			}
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   797
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   798
			TRAPD(ret, FatMount().WriteDirEntryL(iFileDosEntryPos,entry));
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   799
		
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   800
		if(setNotify)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   801
			{
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   802
			FatMount().SetNotifyOn();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   803
			}
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   804
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   805
		User::LeaveIfError(ret);
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   806
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   807
		IndicateFileSizeModified(EFalse);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   808
		IndicateFileTimeModified(EFalse);
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   809
	    }
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   810
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   811
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   812
    //-- KEntryAttModified must be reset anyway
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   813
    IndicateFileAttModified(EFalse); 
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   814
	}
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   815
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   816
//-----------------------------------------------------------------------------
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   817
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   818
/**
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   819
    Rename already opened file.
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   820
    @param  aNewName new file name; all trailing dots from the name will be removed
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   821
*/
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   822
void CFatFileCB::RenameL(const TDesC& aNewName)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   823
    {
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   824
    __PRINT2(_L("CFatFileCB::RenameL[0x%x], name:%S"),this, &aNewName);
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   825
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   826
    FatMount().CheckStateConsistentL();
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   827
    FatMount().CheckWritableL();
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   828
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   829
    const TPtrC fileName = RemoveTrailingDots(aNewName); //-- remove trailing dots from the name
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   830
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   831
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   832
    FatMount().DoRenameOrReplaceL(*iFileName, fileName, CFatMountCB::EModeRename, iFileDosEntryPos);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   833
    
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   834
    AllocBufferL(iFileName, fileName);
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   835
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   836
    if(!FatMount().IsRuggedFSys())
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   837
        FAT().FlushL();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   838
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   839
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   840
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   841
//***********************************************************
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   842
//* BlockMap interface
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   843
//***********************************************************
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   844
    
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   845
TInt CFatFileCB::BlockMap(SBlockMapInfo& aInfo, TInt64& aStartPos, TInt64 aEndPos)
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   846
//
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   847
// Retrieves the block map of a given section of the file, in the FAT file system.
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   848
//  
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   849
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   850
    __PRINT2(_L("CFatFileCB::BlockMap aStartPos=%ld aEndPos=%ld"), aStartPos, aEndPos);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   851
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   852
    if ( I64HIGH(aStartPos) || I64HIGH(aEndPos) )
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   853
        return KErrNotSupported;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   854
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   855
    TUint startPos = I64LOW(aStartPos);
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   856
    TUint endPos = I64LOW(aEndPos);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   857
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   858
    // aEndPos will always be >=0 at this point
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   859
    const TUint length = endPos - startPos;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   860
    
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   861
    // Store the position of cluster zero in aInfo
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   862
    CFatMountCB& fatMount = FatMount();
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   863
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   864
    TInt drvNo=-1;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   865
    TBusLocalDrive* locDrv;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   866
    if((fatMount.LocalDrive()->GetLocalDrive(locDrv)==KErrNone) && ((drvNo=GetLocalDriveNumber(locDrv))>=0) && (drvNo<KMaxLocalDrives))
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   867
        aInfo.iLocalDriveNumber=drvNo;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   868
    else
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   869
        return KErrNotSupported;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   870
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   871
    // Fetch the address of cluster 0
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   872
    aInfo.iStartBlockAddress = fatMount.FAT().DataPositionInBytes(KFirstClusterNum);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   873
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   874
    TRAPD(r, CheckPosL(startPos));
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   875
    if (r != KErrNone)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   876
        return r;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   877
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   878
    aInfo.iBlockStartOffset = fatMount.ClusterRelativePos(iCurrentPos.iPos);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   879
    aInfo.iBlockGranularity = 1 << FatMount().ClusterSizeLog2();
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   880
    const TUint myStartPos = iCurrentPos.iPos;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   881
    if ( myStartPos + length > FCB_FileSize())
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   882
        return KErrArgument;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   883
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   884
    TRAP(r, FatMount().BlockMapReadFromClusterListL(iCurrentPos, length, aInfo));
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   885
    if (r != KErrNone)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   886
        return r;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   887
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   888
    aStartPos = iCurrentPos.iPos;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   889
    if ((I64LOW(aStartPos) == FCB_FileSize()) || ( I64LOW(aStartPos) == (myStartPos + length)))
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   890
        return KErrCompletion;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   891
    else
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   892
        return KErrNone;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   893
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   894
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   895
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   896
TInt CFatFileCB::GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   897
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   898
    switch(aInterfaceId)
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   899
        {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   900
        case EExtendedFileInterface:
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   901
            ((CFileCB::MExtendedFileInterface*&) aInterface) = this;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   902
            return KErrNone;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   903
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   904
        case EBlockMapInterface:
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   905
            aInterface = (CFileCB::MBlockMapInterface*) this;
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   906
            return KErrNone;
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   907
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   908
        case EGetLocalDrive:
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   909
            return FatMount().LocalDrive()->GetLocalDrive((TBusLocalDrive*&) aInterface);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   910
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   911
        default:
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   912
            return CFileCB::GetInterface(aInterfaceId,aInterface,aInput);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   913
        }
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   914
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   915
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   916
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   917
/**
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   918
    Overwrites file's start cluster (iStartCluster) in its directory entry.
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   919
*/
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   920
void CFatFileCB::FlushStartClusterL()
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   921
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   922
    __PRINT1(_L("CFatFileCB::FlushStartClusterL[0x%x]"), this);
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   923
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   924
    CFatMountCB& mount = FatMount();
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   925
    TFatDirEntry dirEntry;
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   926
    
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   927
    mount.ReadDirEntryL(iFileDosEntryPos, dirEntry); //-- read this file's dir. entry
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   928
    dirEntry.SetStartCluster(FCB_StartCluster());    //-- set new start cluster
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   929
    mount.WriteDirEntryL(iFileDosEntryPos, dirEntry);//-- write the entry back
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   930
    }
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   931
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   932
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   933
/**
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   934
    This is a RuggedFAT - specific method. Writes file size to the corresponding field of its file directory entry.
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   935
*/
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   936
void CFatFileCB::WriteFileSizeL(TUint aSize)
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   937
    {
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   938
    __PRINT2(_L("CFatFileCB::WriteFileSizeL[0x%x], sz:%d"), this, aSize);
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   939
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   940
    CFatMountCB& mount = FatMount();
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   941
    TFatDirEntry dirEntry;
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   942
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   943
    mount.ReadDirEntryL(iFileDosEntryPos, dirEntry); //-- read this file's dir. entry
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   944
    dirEntry.SetSize(aSize);                         //-- set new size
176
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   945
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   946
	// As we're updating the directory entry anyway, we might as well update the attributes & time 
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   947
	// if these have been modified to save having to update them later...
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   948
	if (FileAttModified())
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   949
		{
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   950
		dirEntry.SetAttributes(Att() & KEntryAttMaskSupported);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   951
        IndicateFileAttModified(EFalse); 
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   952
		IndicateFileTimeModified(ETrue);	//-- this mirrors the behaviour of CFatFileCB::~CFatFileCB()
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   953
		}
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   954
	if (FileTimeModified())
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   955
		{
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   956
		dirEntry.SetTime(iModified, FatMount().TimeOffset());
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   957
        IndicateFileTimeModified(EFalse);
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   958
		}
af6ec97d9189 201023_13
hgs
parents: 148
diff changeset
   959
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   960
    mount.WriteDirEntryL(iFileDosEntryPos, dirEntry);//-- write the entry back
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   961
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   962
    IndicateFileSizeModified(EFalse);
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   963
    }
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   964
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   965
15
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   966
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   967
4122176ea935 Revision: 200948 + Removing redundant base integration tests and fixing build errors
John Imhofe <john.imhofe@nokia.com>
parents:
diff changeset
   968
90
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   969
947f0dc9f7a8 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 15
diff changeset
   970