|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Cluster class used to allocate cluster numbers for directory entries |
|
16 * and while writing file contents. And it is responsible to create the |
|
17 * MAP of content starting cluster to ending cluster which can be used |
|
18 * to generate FAT table. Since the cluster number is unique all over the |
|
19 * filesystem component, this class is designed as singleton class. |
|
20 * @internalComponent |
|
21 * @released |
|
22 * |
|
23 */ |
|
24 |
|
25 |
|
26 #include "cluster.h" |
|
27 |
|
28 |
|
29 //Initialize the Static CCluster instance pointer |
|
30 CCluster* CCluster::iClusterInstance = NULL; |
|
31 |
|
32 /** |
|
33 Static function which is used to instantiate and return the address of CCluster class. |
|
34 |
|
35 @internalComponent |
|
36 @released |
|
37 |
|
38 @param aClusterSize - single cluster size in Bytes |
|
39 @param aTotalNumberOfClusters - Maximum number of clusters |
|
40 @return - returns the instance of CCluster class |
|
41 */ |
|
42 |
|
43 CCluster* CCluster::Instance(unsigned int aClusterSize,unsigned int aTotalNumberOfClusters) |
|
44 { |
|
45 if (iClusterInstance == NULL) // is it the first call? |
|
46 { |
|
47 // create sole instance |
|
48 iClusterInstance = new CCluster(aClusterSize, aTotalNumberOfClusters); |
|
49 } |
|
50 return iClusterInstance; // address of sole instance |
|
51 } |
|
52 |
|
53 /** |
|
54 Destructor: Clears the clusters per entry map |
|
55 |
|
56 @internalComponent |
|
57 @released |
|
58 */ |
|
59 CCluster::~CCluster () |
|
60 { |
|
61 iClustersPerEntry.clear(); |
|
62 iClusterInstance = NULL; |
|
63 } |
|
64 |
|
65 |
|
66 /** |
|
67 Constructor Receives inputs from dirregion Class and initializes the class variables |
|
68 |
|
69 @internalComponent |
|
70 @released |
|
71 |
|
72 @param aClusterSize - Size of every Cluster |
|
73 @param aTotalNumberOfClusters - maximum number of clusters allowed for current FAT image |
|
74 */ |
|
75 CCluster::CCluster(unsigned int aClusterSize, unsigned int aTotalNumberOfClusters) |
|
76 :iClusterSize(aClusterSize),iTotalNumberOfClusters(aTotalNumberOfClusters) |
|
77 { |
|
78 iRootClusterNumber = KRootClusterNumber; |
|
79 iCurrentClusterNumber = iRootClusterNumber; |
|
80 } |
|
81 |
|
82 /** |
|
83 Function to return the current cluster number |
|
84 |
|
85 @internalComponent |
|
86 @released |
|
87 |
|
88 @return - returns the current cluster number |
|
89 */ |
|
90 unsigned int CCluster::GetCurrentClusterNumber() const |
|
91 { |
|
92 return iCurrentClusterNumber; |
|
93 } |
|
94 |
|
95 /** |
|
96 Function to decrement the current cluster number |
|
97 |
|
98 @internalComponent |
|
99 @released |
|
100 */ |
|
101 void CCluster::DecrementCurrentClusterNumber() |
|
102 { |
|
103 --iCurrentClusterNumber; |
|
104 } |
|
105 |
|
106 /** |
|
107 Function to get the High word of Current cluster number |
|
108 |
|
109 @internalComponent |
|
110 @released |
|
111 |
|
112 @return - returns the 16 bit HIGH word |
|
113 */ |
|
114 unsigned short int CCluster::GetHighWordClusterNumber() const |
|
115 { |
|
116 return (unsigned short)(iCurrentClusterNumber >> KBitShift16); |
|
117 } |
|
118 |
|
119 /** |
|
120 Function to get the Low word of Current cluster number |
|
121 |
|
122 @internalComponent |
|
123 @released |
|
124 |
|
125 @return - returns the 16 bit LOW word |
|
126 */ |
|
127 unsigned short int CCluster::GetLowWordClusterNumber() const |
|
128 { |
|
129 return (unsigned short)(iCurrentClusterNumber & KHighWordMask); |
|
130 } |
|
131 |
|
132 |
|
133 /** |
|
134 Function responsible to |
|
135 1. Increment the current Cluster Number |
|
136 2. Throw the error "image size too big" if the allocated clusters count exceeds total |
|
137 number of available clusters. |
|
138 |
|
139 @internalComponent |
|
140 @released |
|
141 */ |
|
142 void CCluster::UpdateNextAvailableClusterNumber() |
|
143 { |
|
144 if(iCurrentClusterNumber >= iTotalNumberOfClusters) |
|
145 { |
|
146 throw ErrorHandler(IMAGESIZETOOBIG,"Occupied number of clusters count exceeded than available clusters",__FILE__,__LINE__); |
|
147 } |
|
148 ++iCurrentClusterNumber; |
|
149 } |
|
150 |
|
151 /** |
|
152 Function to Return the cluster size |
|
153 |
|
154 @internalComponent |
|
155 @released |
|
156 |
|
157 @return the cluster size |
|
158 */ |
|
159 unsigned int CCluster::GetClusterSize() const |
|
160 { |
|
161 return iClusterSize; |
|
162 } |
|
163 |
|
164 /** |
|
165 Function Creates mapping between starting cluster number (where data starts) and |
|
166 the sub sequent cluster numbers (where the data extends). |
|
167 |
|
168 @internalComponent |
|
169 @released |
|
170 |
|
171 @param aStartingClusterNumber - Cluster number where the data starts |
|
172 @param aPairClusterNumber - Cluster number where the data extends |
|
173 */ |
|
174 void CCluster::CreateMap(unsigned int aStartingClusterNumber,unsigned int aPairClusterNumber) |
|
175 { |
|
176 iClustersPerEntry.insert(std::make_pair(aStartingClusterNumber,aPairClusterNumber)); |
|
177 } |
|
178 |
|
179 /** |
|
180 Function to get Clusters per Entry MAP container. |
|
181 |
|
182 @internalComponent |
|
183 @released |
|
184 |
|
185 @return - returns the CLusters per entry container |
|
186 */ |
|
187 |
|
188 TClustersPerEntryMap* CCluster::GetClustersPerEntryMap() |
|
189 { |
|
190 return &iClustersPerEntry; |
|
191 } |