606
|
1 |
/*
|
|
2 |
* Copyright (c) 1995-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 |
* @internalComponent * @released
|
|
16 |
* Rofsbuild Obey file class and its reader class.
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
|
|
20 |
#include <strstream>
|
|
21 |
#include <iomanip>
|
|
22 |
|
|
23 |
#include <string.h>
|
|
24 |
#include <stdlib.h>
|
|
25 |
#include <stdio.h>
|
|
26 |
#include <time.h>
|
|
27 |
#include <assert.h>
|
|
28 |
#include <errno.h>
|
|
29 |
|
|
30 |
#include <e32std.h>
|
|
31 |
#include <e32std_private.h>
|
|
32 |
#include <e32rom.h>
|
|
33 |
#include <u32std.h>
|
|
34 |
#include <f32file.h>
|
|
35 |
|
|
36 |
#include "h_utl.h"
|
|
37 |
#include "r_obey.h"
|
|
38 |
#include "r_coreimage.h"
|
|
39 |
#include "patchdataprocessor.h"
|
|
40 |
#include "fatimagegenerator.h"
|
|
41 |
#include "r_driveimage.h"
|
|
42 |
|
|
43 |
extern TInt gCodePagingOverride;
|
|
44 |
extern TInt gDataPagingOverride;
|
|
45 |
extern ECompression gCompress;
|
|
46 |
extern TBool gEnableStdPathWarning; // Default to not warn if destination path provided for a file is not in standard path.
|
|
47 |
extern TBool gKeepGoing;
|
|
48 |
|
|
49 |
|
|
50 |
#define _P(word) word, sizeof(word)-1 // match prefix, optionally followed by [HWVD]
|
|
51 |
#define _K(word) word, 0 // match whole word
|
|
52 |
static char* const NullString = "" ;
|
|
53 |
const ObeyFileKeyword ObeyFileReader::iKeywords[] =
|
|
54 |
{
|
|
55 |
{_K("file"), 2,-2, EKeywordFile, "File to be copied into ROFS"},
|
|
56 |
{_K("data"), 2,-2, EKeywordData, "same as file"},
|
|
57 |
{_K("dir"), 2,1, EKeywordDir, "Directory to be created into FAT image"},
|
|
58 |
|
|
59 |
{_K("rofsname"), 1, 1, EKeywordRofsName, "output file for ROFS image"},
|
|
60 |
{_K("romsize"), 1, 1, EKeywordRomSize, "size of ROM image"},
|
|
61 |
{_P("hide"), 2, -1, EKeywordHide, "Exclude named file from ROM directory structure"},
|
|
62 |
{_P("alias"), 2, -2, EKeywordAlias, "Create alias for existing file in ROM directory structure"},
|
|
63 |
{_P("rename"), 2, -2, EKeywordRename, "Change the name of a file in the ROM directory structure"},
|
|
64 |
{_K("rofssize"), 1, 1, EKeywordRofsSize, "maximum size of ROFS image"},
|
|
65 |
{_K("romchecksum"), 1, 1, EKeywordRofsChecksum, "desired 32-bit checksum value for the whole image"},
|
|
66 |
{_K("version"), 1, 1, EKeywordVersion, "ROFS image version number"},
|
|
67 |
{_K("time"), 1,-1, EKeywordTime, "ROFS image timestamp"},
|
|
68 |
{_K("extensionrofs"),1+2, 1, EKeywordExtensionRofs, "Start of definition of optional Extension ROFS"},
|
|
69 |
{_K("extensionrofsname"),1, 1, EKeywordCoreRofsName, "ROFS image on which extension ROFS is based"},
|
|
70 |
{_K("rem"), 0, 0, EKeywordNone, "comment"},
|
|
71 |
{_K("stop"), 0, 0, EKeywordNone, "Terminates OBEY file prematurely"},
|
|
72 |
{_K("romchecksum"), 1, 1, EKeywordRomChecksum, "desired 32-bit checksum value for the whole ROFS image"},
|
|
73 |
{_K("coreimage"), 1, 1, EKeywordCoreImage, "Core image to be used for extension directory structure"},
|
|
74 |
{_K("autosize"), 1, 1, EKeywordRofsAutoSize, "Automatically adjust maximum image size to actual used"},
|
|
75 |
{_K("pagingoverride"), 1, 1, EKeywordPagingOverride, "Overide the demand paging attributes for every file in ROM, NOPAGING|DEFAULTUNPAGED|DEFAULTPAGED"},
|
|
76 |
{_K("codepagingoverride"), 1, 1, EKeywordCodePagingOverride, "Overide the code paging attributes for every file in ROM, NOPAGING|DEFAULTUNPAGED|DEFAULTPAGED"},
|
|
77 |
{_K("datapagingoverride"), 1, 1, EKeywordDataPagingOverride, "Overide the data paging attributes for every file in ROM, NOPAGING|DEFAULTUNPAGED|DEFAULTPAGED"},
|
|
78 |
{_K("dataimagename"),1, 1,EKeywordDataImageName, "Data Drive image file name"},
|
|
79 |
{_K("dataimagefilesystem"),1, 1,EKeywordDataImageFileSystem, "Drive image file system format"},
|
|
80 |
{_K("dataimagesize"),1, 1,EKeywordDataImageSize, "Maximum size of Data Drive image"},
|
|
81 |
{_K("volume"),1, -1,EKeywordDataImageVolume, "Volume Label of Data Drive image"},
|
|
82 |
{_K("sectorsize"),1, 1,EKeywordDataImageSectorSize, "Sector size(in bytes) of Data Drive image"},
|
|
83 |
{_K("fattable"),1, 1,EKeywordDataImageNoOfFats, "Number of FATs in the Data Drive image"},
|
|
84 |
// things we don't normally report in the help information
|
|
85 |
{_K("trace"), 1, 1, EKeywordTrace, "(ROMBUILD activity trace flags)"},
|
|
86 |
{_K("filecompress"),2, -2,EKeywordFileCompress,"Non-XIP Executable to be loaded into the ROM compressed" },
|
|
87 |
{_K("fileuncompress"),2, -2,EKeywordFileUncompress,"Non-XIP Executable to be loaded into the ROM uncompressed" },
|
|
88 |
{_K("patchdata"),2, 5,EKeywordPatchDllData, "Patch exported data"},
|
|
89 |
{_K("imagename"), 1, 1, EKeywordSmrImageName, "output file for SMR image"},
|
617
|
90 |
{_K("hcrdata"), 1, 1, EKeywordSmrFileData, "file data for HCR SMR image"},
|
|
91 |
{_K("smrdata"), 1, 1, EKeywordSmrFileData, "file data for general SMR image"},
|
606
|
92 |
{_K("formatversion"), 1, 1, EKeywordSmrFormatVersion, "format version for HCR SMR image"},
|
|
93 |
{_K("payloadflags"), 1, 1, EKeywordSmrFlags, "payload flags for the HCR SMR image"},
|
|
94 |
{_K("payloaduid"), 1, 1, EKeywordSmrUID, "payload UID for the HCR SMR image"},
|
|
95 |
{0,0,0,0,EKeywordNone,""}
|
|
96 |
};
|
|
97 |
|
|
98 |
void ObeyFileReader::KeywordHelp() { // static
|
|
99 |
|
|
100 |
cout << "Obey file keywords:\n";
|
|
101 |
|
|
102 |
const ObeyFileKeyword* k=0;
|
|
103 |
for (k=iKeywords; k->iKeyword!=0; k++)
|
|
104 |
{
|
|
105 |
if (k->iHelpText == 0)
|
|
106 |
continue;
|
|
107 |
if (k->iHelpText[0]=='(' && !H.iVerbose)
|
|
108 |
continue; // don't normally report things in (parentheses)
|
|
109 |
|
|
110 |
char buf[32];
|
|
111 |
sprintf(buf, "%-20s", k->iKeyword);
|
|
112 |
if (k->iKeywordLength)
|
|
113 |
memcpy(buf+k->iKeywordLength,"[HWVD]",6);
|
|
114 |
if (H.iVerbose)
|
|
115 |
sprintf(buf+20,"%2d",k->iNumArgs);
|
|
116 |
cout << " " << buf << " " << k->iHelpText << endl;
|
|
117 |
}
|
|
118 |
cout << endl;
|
|
119 |
|
|
120 |
cout << "File attributes:\n";
|
|
121 |
|
|
122 |
const FileAttributeKeyword* f=0;
|
|
123 |
for (f=iAttributeKeywords; f->iKeyword!=0; f++)
|
|
124 |
{
|
|
125 |
if (f->iHelpText == 0)
|
|
126 |
continue;
|
|
127 |
if (f->iHelpText[0]=='(' && !H.iVerbose)
|
|
128 |
continue; // don't normally report things in (parentheses)
|
|
129 |
|
|
130 |
char buf[32];
|
|
131 |
sprintf(buf, "%-20s", f->iKeyword);
|
|
132 |
if (H.iVerbose)
|
|
133 |
sprintf(buf+20,"%2d",k->iNumArgs);
|
|
134 |
cout << " " << buf << " " << f->iHelpText << endl;
|
|
135 |
}
|
|
136 |
cout << endl;
|
|
137 |
}
|
|
138 |
|
|
139 |
ObeyFileReader::ObeyFileReader(const char* aFileName):iCurrentLine(0),
|
|
140 |
iFileName(aFileName),iNumWords(0),iLine(0),iMarkLine(0),iCurrentObeyStatement(0) {
|
|
141 |
for(TUint i = 0 ; i < KNumWords ; i++)
|
|
142 |
iWord[i] = NullString;
|
|
143 |
*iSuffix = 0 ;
|
|
144 |
}
|
|
145 |
|
|
146 |
ObeyFileReader::~ObeyFileReader() {
|
|
147 |
if(iCurrentObeyStatement) {
|
|
148 |
delete []iCurrentObeyStatement;
|
|
149 |
iCurrentObeyStatement = 0 ;
|
|
150 |
}
|
|
151 |
if(iLine) {
|
|
152 |
delete []iLine;
|
|
153 |
iLine = 0 ;
|
|
154 |
}
|
|
155 |
}
|
|
156 |
|
|
157 |
//
|
|
158 |
// Open the file & return a status
|
|
159 |
//
|
|
160 |
TBool ObeyFileReader::Open() {
|
|
161 |
ifstream ifs(iFileName.c_str(),ios_base::in + ios_base::binary);
|
|
162 |
if (!ifs.is_open()) {
|
|
163 |
Print(EError,"Cannot open obey file %s\n",iFileName.c_str());
|
|
164 |
return EFalse;
|
|
165 |
}
|
|
166 |
iLines.clear();
|
|
167 |
if(iLine){
|
|
168 |
delete []iLine;
|
|
169 |
iLine = 0 ;
|
|
170 |
}
|
|
171 |
ifs.seekg(0,ios_base::end);
|
|
172 |
size_t length = ifs.tellg();
|
|
173 |
char* buffer = new char[length + 2];
|
|
174 |
if (0 == buffer) {
|
|
175 |
Print(EError,"Insufficent Memory to Continue.");
|
|
176 |
ifs.close();
|
|
177 |
return EFalse;
|
|
178 |
}
|
|
179 |
ifs.seekg(0,ios_base::beg);
|
|
180 |
ifs.read(buffer,length);
|
|
181 |
size_t readcout = ifs.gcount() ;
|
|
182 |
if(readcout != length){
|
|
183 |
Print(EError,"Cannot Read All of File.");
|
|
184 |
delete []buffer ;
|
|
185 |
ifs.close();
|
|
186 |
return EFalse;
|
|
187 |
}
|
|
188 |
buffer[length] = '\n';
|
|
189 |
buffer[length + 1] = 0 ;
|
|
190 |
ifs.close();
|
|
191 |
char* lineStart = buffer ;
|
|
192 |
char* end = buffer + length ;
|
|
193 |
string line ;
|
|
194 |
size_t maxLengthOfLine = 0 ;
|
|
195 |
while(lineStart < end){
|
|
196 |
while(*lineStart == ' ' || *lineStart == '\t') //trimleft
|
|
197 |
lineStart ++ ;
|
|
198 |
char* lineEnd = lineStart ;
|
|
199 |
while(*lineEnd != '\r' && *lineEnd != '\n')
|
|
200 |
lineEnd ++ ;
|
|
201 |
if(strnicmp(lineStart,"REM",3) == 0){
|
|
202 |
line = "" ; // REMOVE "REM ... "
|
|
203 |
}
|
|
204 |
else {
|
|
205 |
TInt lastIndex = lineEnd - lineStart - 1;
|
|
206 |
while(lastIndex >= 0 && // trimright
|
|
207 |
(lineStart[lastIndex] == ' ' || lineStart[lastIndex] == '\t'))
|
|
208 |
lastIndex -- ;
|
|
209 |
if(lastIndex >= 0)
|
|
210 |
line.assign(lineStart,lastIndex + 1);
|
|
211 |
else
|
|
212 |
line = "";
|
|
213 |
}
|
|
214 |
if(line.length() > maxLengthOfLine)
|
|
215 |
maxLengthOfLine = line.length();
|
|
216 |
iLines.push_back(line);
|
|
217 |
if(*lineEnd == '\r') {
|
|
218 |
if(lineEnd[1] == '\n')
|
|
219 |
lineStart = lineEnd + 2 ;
|
|
220 |
else
|
|
221 |
lineStart = lineEnd + 1 ;
|
|
222 |
}
|
|
223 |
else // '\n'
|
|
224 |
lineStart = lineEnd + 1 ;
|
|
225 |
}
|
|
226 |
delete []buffer ;
|
|
227 |
iLine = new char[maxLengthOfLine + 1];
|
|
228 |
iCurrentObeyStatement = new char[maxLengthOfLine + 1];
|
|
229 |
*iCurrentObeyStatement = 0 ;
|
|
230 |
*iLine = 0 ;
|
|
231 |
iCurrentLine = 0 ;
|
|
232 |
iMarkLine = 0 ;
|
|
233 |
return ETrue;
|
|
234 |
}
|
|
235 |
|
|
236 |
void ObeyFileReader::Mark() {
|
|
237 |
iMarkLine = iCurrentLine - 1;
|
|
238 |
}
|
|
239 |
|
|
240 |
void ObeyFileReader::MarkNext() {
|
|
241 |
iMarkLine = iCurrentLine;
|
|
242 |
}
|
|
243 |
|
|
244 |
void ObeyFileReader::Rewind() {
|
|
245 |
iCurrentLine = iMarkLine;
|
|
246 |
}
|
|
247 |
|
|
248 |
char* ObeyFileReader::DupWord(TInt aIndex) const {
|
|
249 |
char* retVal = 0 ;
|
|
250 |
if(aIndex >= 0 && aIndex < (TInt)KNumWords){
|
|
251 |
size_t len = strlen(iWord[aIndex]) + 1;
|
|
252 |
retVal = new char[len];
|
|
253 |
if(retVal)
|
|
254 |
memcpy(retVal,iWord[aIndex],len);
|
|
255 |
}
|
|
256 |
return retVal ;
|
|
257 |
}
|
|
258 |
|
|
259 |
TInt ObeyFileReader::ReadAndParseLine() {
|
|
260 |
if (iCurrentLine >= (TInt)iLines.size())
|
|
261 |
return KErrEof;
|
|
262 |
iCurrentLine++;
|
|
263 |
iNumWords = Parse();
|
|
264 |
return KErrNone;
|
|
265 |
}
|
|
266 |
|
|
267 |
TInt ObeyFileReader::NextLine(TInt aPass, enum EKeyword& aKeyword) {
|
|
268 |
|
|
269 |
NextLine:
|
|
270 |
TInt err = ReadAndParseLine();
|
|
271 |
if (err == KErrEof)
|
|
272 |
return KErrEof;
|
|
273 |
if(iNumWords == 0)
|
|
274 |
goto NextLine;
|
|
275 |
if (stricmp(iWord[0], "stop")==0)
|
|
276 |
return KErrEof;
|
|
277 |
|
|
278 |
const ObeyFileKeyword* k=0;
|
|
279 |
for (k=iKeywords; k->iKeyword!=0; k++) {
|
|
280 |
if (k->iKeywordLength == 0) {
|
|
281 |
// Exact case-insensitive match on keyword
|
|
282 |
if (stricmp(iWord[0], k->iKeyword) != 0)
|
|
283 |
continue;
|
|
284 |
*iSuffix = 0;
|
|
285 |
}
|
|
286 |
else {
|
|
287 |
// Prefix match
|
|
288 |
if (strnicmp(iWord[0], k->iKeyword, k->iKeywordLength) != 0)
|
|
289 |
continue;
|
|
290 |
// Suffix must be empty, or a variant number in []
|
|
291 |
strncpy(iSuffix,iWord[0] + k->iKeywordLength,80);
|
|
292 |
if (*iSuffix != '\0' && *iSuffix != '[')
|
|
293 |
continue;
|
|
294 |
}
|
|
295 |
// found a match
|
|
296 |
if ((k->iPass & aPass) == 0)
|
|
297 |
goto NextLine;
|
|
298 |
if (k->iNumArgs>=0 && (1+k->iNumArgs != iNumWords)) {
|
|
299 |
Print(EError, "Incorrect number of arguments for keyword %s on line %d.\n",
|
|
300 |
iWord[0], iCurrentLine);
|
|
301 |
goto NextLine;
|
|
302 |
}
|
|
303 |
if (k->iNumArgs<0 && (1-k->iNumArgs > iNumWords)) {
|
|
304 |
Print(EError, "Too few arguments for keyword %s on line %d.\n",
|
|
305 |
iWord[0], iCurrentLine);
|
|
306 |
goto NextLine;
|
|
307 |
}
|
|
308 |
|
|
309 |
aKeyword = k->iKeywordEnum;
|
|
310 |
return KErrNone;
|
|
311 |
}
|
|
312 |
if (aPass == 1)
|
|
313 |
Print(EWarning, "Unknown keyword '%s'. Line %d ignored\n", iWord[0], iCurrentLine);
|
|
314 |
goto NextLine;
|
|
315 |
}
|
|
316 |
|
|
317 |
//
|
|
318 |
// splits a line into words, and returns the number of words found
|
|
319 |
//
|
|
320 |
TInt ObeyFileReader::Parse() {
|
|
321 |
|
|
322 |
for (TUint i = 0; i < KNumWords; i++)
|
|
323 |
iWord[i] = NullString;
|
|
324 |
|
|
325 |
enum TState {EInWord, EInQuotedWord, EInGap};
|
|
326 |
TState state = EInGap;
|
|
327 |
const string& line = iLines[iCurrentLine - 1];
|
|
328 |
size_t len = line.length();
|
|
329 |
memcpy(iLine,line.c_str(),len);
|
|
330 |
memcpy(iCurrentObeyStatement,iLine,len);
|
|
331 |
iLine[len] = 0 ;
|
|
332 |
iCurrentObeyStatement[len] = 0 ;
|
|
333 |
TUint i = 0;
|
|
334 |
char* linestr = iLine;
|
|
335 |
while (i < KNumWords && *linestr != 0) {
|
|
336 |
switch (state)
|
|
337 |
{
|
|
338 |
case EInGap:
|
|
339 |
if (*linestr =='\"') {
|
|
340 |
if (linestr[1] != 0 && linestr[1]!='\"')
|
|
341 |
iWord[i++] = linestr + 1;
|
|
342 |
state = EInQuotedWord;
|
|
343 |
}
|
|
344 |
else if (!IsGap(*linestr)) {
|
|
345 |
iWord[i++] = linestr;
|
|
346 |
state=EInWord;
|
|
347 |
}
|
|
348 |
else
|
|
349 |
*linestr=0;
|
|
350 |
break;
|
|
351 |
case EInWord:
|
|
352 |
if (*linestr == '\"') {
|
|
353 |
*linestr = 0;
|
|
354 |
if (linestr[1] != 0 && linestr[1] != '\"')
|
|
355 |
iWord[i++] = linestr+1;
|
|
356 |
state=EInQuotedWord;
|
|
357 |
}
|
|
358 |
else if (IsGap(*linestr)) {
|
|
359 |
*linestr=0;
|
|
360 |
state=EInGap;
|
|
361 |
}
|
|
362 |
break;
|
|
363 |
case EInQuotedWord:
|
|
364 |
if (*linestr == '\"'){
|
|
365 |
*linestr = 0;
|
|
366 |
state = EInGap;
|
|
367 |
}
|
|
368 |
break;
|
|
369 |
}
|
|
370 |
linestr++;
|
|
371 |
}
|
|
372 |
return i;
|
|
373 |
}
|
|
374 |
|
|
375 |
//
|
|
376 |
// Process the timestamp
|
|
377 |
//
|
|
378 |
void ObeyFileReader::ProcessTime(TInt64& aTime) {
|
|
379 |
char timebuf[256];
|
|
380 |
if (iNumWords>2)
|
|
381 |
sprintf(timebuf, "%s_%s", iWord[1], iWord[2]);
|
|
382 |
else
|
|
383 |
strncpy(timebuf, iWord[1],256);
|
|
384 |
|
|
385 |
TInt r = StringToTime(aTime, timebuf);
|
|
386 |
if (r==KErrGeneral) {
|
|
387 |
Print(EError, "incorrect format for time keyword on line %d\n", iCurrentLine);
|
|
388 |
exit(0x670);
|
|
389 |
}
|
|
390 |
if (r==KErrArgument){
|
|
391 |
Print(EError, "Time out of range on line %d\n", iCurrentLine);
|
|
392 |
exit(0x670);
|
|
393 |
}
|
|
394 |
}
|
|
395 |
|
|
396 |
TInt64 ObeyFileReader::iTimeNow = 0;
|
|
397 |
void ObeyFileReader::TimeNow(TInt64& aTime) {
|
|
398 |
if (iTimeNow==0) {
|
|
399 |
TInt sysTime = time(0); // seconds since midnight Jan 1st, 1970
|
|
400 |
sysTime -= (30*365*24*60*60+7*24*60*60); // seconds since midnight Jan 1st, 2000
|
|
401 |
TInt64 daysTo2000AD=730497;
|
|
402 |
TInt64 t=daysTo2000AD*24*3600+sysTime; // seconds since 0000
|
|
403 |
t = t+3600; // BST (?)
|
|
404 |
iTimeNow=t*1000000; // milliseconds
|
|
405 |
}
|
|
406 |
aTime=iTimeNow;
|
|
407 |
}
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
// File attributes.
|
|
412 |
|
|
413 |
|
|
414 |
const FileAttributeKeyword ObeyFileReader::iAttributeKeywords[] =
|
|
415 |
{
|
|
416 |
{"attrib",3 ,0,1,EAttributeAtt, "File attributes in ROM file system"},
|
|
417 |
{"exattrib",3 ,0,1,EAttributeAttExtra, "File extra attributes in ROM file system"},
|
|
418 |
{"stack",3 ,1,1,EAttributeStack, "?"},
|
|
419 |
{"fixed",3 ,1,0,EAttributeFixed, "Relocate to a fixed address space"},
|
|
420 |
{"priority",3 ,1,1,EAttributePriority, "Override process priority"},
|
|
421 |
{_K("uid1") ,1,1,EAttributeUid1, "Override first UID"},
|
|
422 |
{_K("uid2") ,1,1,EAttributeUid2, "Override second UID"},
|
|
423 |
{_K("uid3") ,1,1,EAttributeUid3, "Override third UID"},
|
|
424 |
{_K("heapmin") ,1,1,EAttributeHeapMin, "Override initial heap size"},
|
|
425 |
{_K("heapmax") ,1,1,EAttributeHeapMax, "Override maximum heap size"},
|
|
426 |
{_K("capability") ,1,1,EAttributeCapability, "Override capabilities"},
|
|
427 |
{_K("unpaged") ,1,0,EAttributeUnpaged, "Don't page code or data for this file"},
|
|
428 |
{_K("paged") ,1,0,EAttributePaged, "Page code and data for this file"},
|
|
429 |
{_K("unpagedcode") ,1,0,EAttributeUnpagedCode, "Don't page code for this file"},
|
|
430 |
{_K("pagedcode") ,1,0,EAttributePagedCode, "Page code for this file"},
|
|
431 |
{_K("unpageddata") ,1,0,EAttributeUnpagedData, "Don't page data for this file"},
|
|
432 |
{_K("pageddata") ,1,0,EAttributePagedData, "Page data for this file"},
|
|
433 |
{0,0,0,0,EAttributeAtt,0}
|
|
434 |
};
|
|
435 |
|
|
436 |
TInt ObeyFileReader::NextAttribute(TInt& aIndex, TInt aHasFile, enum EFileAttribute& aKeyword, char*& aArg)
|
|
437 |
{
|
|
438 |
NextAttribute:
|
|
439 |
if (aIndex >= iNumWords)
|
|
440 |
return KErrEof;
|
|
441 |
char* word=iWord[aIndex++];
|
|
442 |
const FileAttributeKeyword* k;
|
|
443 |
for (k=iAttributeKeywords; k->iKeyword!=0; k++)
|
|
444 |
{
|
|
445 |
if (k->iKeywordLength == 0)
|
|
446 |
{
|
|
447 |
// Exact match on keyword
|
|
448 |
if (stricmp(word, k->iKeyword) != 0)
|
|
449 |
continue;
|
|
450 |
}
|
|
451 |
else
|
|
452 |
{
|
|
453 |
// Prefix match
|
|
454 |
if (strnicmp(word, k->iKeyword, k->iKeywordLength) != 0)
|
|
455 |
continue;
|
|
456 |
}
|
|
457 |
// found a match
|
|
458 |
if (k->iNumArgs>0)
|
|
459 |
{
|
|
460 |
TInt argIndex = aIndex;
|
|
461 |
aIndex += k->iNumArgs; // interface only really supports 1 argument
|
|
462 |
if (aIndex>iNumWords)
|
|
463 |
{
|
|
464 |
Print(EError, "Missing argument for attribute %s on line %d\n", word, iCurrentLine);
|
|
465 |
return KErrArgument;
|
|
466 |
}
|
|
467 |
aArg=iWord[argIndex];
|
|
468 |
}
|
|
469 |
if (k->iIsFileAttribute && !aHasFile)
|
|
470 |
{
|
|
471 |
Print(EError, "File attribute %s applied to non-file on line %d\n", word, iCurrentLine);
|
|
472 |
return KErrNotSupported;
|
|
473 |
}
|
|
474 |
aKeyword=k->iAttributeEnum;
|
|
475 |
return KErrNone;
|
|
476 |
}
|
|
477 |
Print(EWarning, "Unknown attribute '%s' skipped on line %d\n", word, iCurrentLine);
|
|
478 |
goto NextAttribute;
|
|
479 |
}
|
|
480 |
|
|
481 |
|
|
482 |
|
|
483 |
/**
|
|
484 |
Constructor:
|
|
485 |
1.Obey file instance.
|
|
486 |
2.used by both rofs and datadrive image.
|
|
487 |
|
|
488 |
@param aReader - obey file reader object.
|
|
489 |
*/
|
|
490 |
CObeyFile::CObeyFile(ObeyFileReader& aReader):
|
|
491 |
iRomFileName(NULL),
|
|
492 |
iExtensionRofsName(0),
|
|
493 |
iKernelRofsName(0),
|
|
494 |
iRomSize(0),
|
|
495 |
iVersion(0,0,0),
|
|
496 |
iCheckSum(0),
|
|
497 |
iNumberOfFiles(0),
|
|
498 |
iTime(0),
|
|
499 |
iRootDirectory(0),
|
|
500 |
iNumberOfDataFiles(0),
|
|
501 |
iDriveFileName(0),
|
|
502 |
iDriveFileFormat(0),
|
|
503 |
iReader(aReader),
|
|
504 |
iMissingFiles(0),
|
|
505 |
iLastExecutable(0),
|
|
506 |
iFirstFile(0),
|
|
507 |
iCurrentFile(0),
|
|
508 |
iAutoSize(EFalse),
|
|
509 |
iAutoPageSize(4096),
|
|
510 |
iPagingOverrideParsed(0),
|
|
511 |
iCodePagingOverrideParsed(0),
|
|
512 |
iDataPagingOverrideParsed(0),
|
|
513 |
iPatchData(new CPatchDataProcessor)
|
|
514 |
{
|
|
515 |
iNextFilePtrPtr = &iFirstFile ;
|
|
516 |
}
|
|
517 |
|
|
518 |
/**
|
|
519 |
Obey file Destructor.
|
|
520 |
1.Release the tree memory.
|
|
521 |
2.Release all allocated memory if any.
|
|
522 |
*/
|
|
523 |
CObeyFile::~CObeyFile() {
|
|
524 |
if(iDriveFileName){
|
|
525 |
delete[] iDriveFileName;
|
|
526 |
iDriveFileName = 0 ;
|
|
527 |
}
|
|
528 |
if(iDriveFileFormat) {
|
|
529 |
delete[] iDriveFileFormat;
|
|
530 |
iDriveFileFormat = 0 ;
|
|
531 |
}
|
|
532 |
iRootDirectory->deleteTheFirstNode();
|
|
533 |
iRootDirectory->InitializeCount();
|
|
534 |
|
|
535 |
Release();
|
|
536 |
if(iRomFileName){
|
|
537 |
delete [] iRomFileName;
|
|
538 |
iRomFileName = 0 ;
|
|
539 |
}
|
|
540 |
if (iRootDirectory)
|
|
541 |
iRootDirectory->Destroy();
|
|
542 |
if(iPatchData)
|
|
543 |
delete iPatchData;
|
|
544 |
}
|
|
545 |
|
|
546 |
//
|
|
547 |
// Free resources not needed after building a ROM
|
|
548 |
//
|
|
549 |
void CObeyFile::Release() {
|
|
550 |
iFirstFile = 0;
|
|
551 |
iNextFilePtrPtr = &iFirstFile;
|
|
552 |
}
|
|
553 |
|
|
554 |
TRomBuilderEntry *CObeyFile::FirstFile() {
|
|
555 |
iCurrentFile = iFirstFile;
|
|
556 |
return iCurrentFile;
|
|
557 |
}
|
|
558 |
|
|
559 |
TRomBuilderEntry *CObeyFile::NextFile() {
|
|
560 |
iCurrentFile = iCurrentFile ? iCurrentFile->iNext : 0;
|
|
561 |
return iCurrentFile;
|
|
562 |
}
|
|
563 |
|
|
564 |
char* CObeyFile::ProcessCoreImage() const {
|
|
565 |
// check for coreimage keyword and return filename
|
|
566 |
enum EKeyword keyword;
|
|
567 |
char* coreImageFileName = 0;
|
|
568 |
iReader.Rewind();
|
|
569 |
while (iReader.NextLine(1,keyword) != KErrEof) {
|
|
570 |
if (keyword == EKeywordCoreImage) {
|
|
571 |
coreImageFileName = iReader.DupWord(1);
|
|
572 |
iReader.MarkNext();
|
|
573 |
break;
|
|
574 |
}
|
|
575 |
}
|
|
576 |
return coreImageFileName;
|
|
577 |
}
|
|
578 |
|
|
579 |
void CObeyFile::SkipToExtension() {
|
|
580 |
iReader.Rewind();
|
|
581 |
enum EKeyword keyword;
|
|
582 |
while (iReader.NextLine(1,keyword) != KErrEof) {
|
|
583 |
if (keyword == EKeywordExtensionRofs) {
|
|
584 |
iReader.Mark(); // ready for processing extension
|
|
585 |
break;
|
|
586 |
}
|
|
587 |
}
|
|
588 |
}
|
|
589 |
|
|
590 |
TInt CObeyFile::ProcessRofs() {
|
|
591 |
|
|
592 |
//
|
|
593 |
// First pass through the obey file to set up key variables
|
|
594 |
//
|
|
595 |
|
|
596 |
iReader.Rewind();
|
|
597 |
|
|
598 |
TInt count=0;
|
|
599 |
enum EKeyword keyword;
|
|
600 |
while (iReader.NextLine(1,keyword) != KErrEof) {
|
|
601 |
if (keyword == EKeywordExtensionRofs){
|
|
602 |
if (count==0)
|
|
603 |
return KErrNotFound; // no core ROFS, just extension ROFSs.
|
|
604 |
break;
|
|
605 |
}
|
|
606 |
|
|
607 |
count++;
|
|
608 |
if (! ProcessKeyword(keyword))
|
|
609 |
return KErrGeneral;
|
|
610 |
}
|
|
611 |
|
|
612 |
if (!GotKeyVariables())
|
|
613 |
return KErrGeneral;
|
|
614 |
|
|
615 |
//
|
|
616 |
// second pass to process the file specifications in the obey file building
|
|
617 |
// up the TRomNode directory structure and the TRomBuilderEntry list
|
|
618 |
//
|
|
619 |
iReader.Rewind();
|
|
620 |
|
|
621 |
iRootDirectory = new TRomNode("");
|
|
622 |
iLastExecutable = iRootDirectory;
|
|
623 |
|
|
624 |
TInt align=0;
|
|
625 |
while (iReader.NextLine(2,keyword)!=KErrEof) {
|
|
626 |
if (keyword == EKeywordExtensionRofs)
|
|
627 |
break;
|
|
628 |
|
|
629 |
if (keyword == EKeywordHide)
|
|
630 |
keyword = EKeywordHideV2;
|
|
631 |
|
|
632 |
switch (keyword)
|
|
633 |
{
|
|
634 |
case EKeywordHide:
|
|
635 |
case EKeywordAlias:
|
|
636 |
case EKeywordRename:
|
|
637 |
if (!ProcessRenaming(keyword))
|
|
638 |
return KErrGeneral;
|
|
639 |
break;
|
|
640 |
case EKeywordPatchDllData:
|
|
641 |
{
|
|
642 |
// Collect patchdata statements to process at the end
|
|
643 |
StringVector patchDataTokens;
|
|
644 |
SplitPatchDataStatement(patchDataTokens);
|
|
645 |
iPatchData->AddPatchDataStatement(patchDataTokens);
|
|
646 |
break;
|
|
647 |
}
|
|
648 |
default:
|
|
649 |
if (!ProcessFile(align, keyword))
|
|
650 |
return KErrGeneral;
|
|
651 |
align=0;
|
|
652 |
break;
|
|
653 |
}
|
|
654 |
}
|
|
655 |
|
|
656 |
if(!ParsePatchDllData())
|
|
657 |
return KErrGeneral;
|
|
658 |
iReader.Mark(); // ready for processing the extension rom(s)
|
|
659 |
|
|
660 |
if (iMissingFiles!=0) {
|
|
661 |
return KErrGeneral;
|
|
662 |
}
|
|
663 |
if ( 0 == iNumberOfFiles ){
|
|
664 |
Print(EError, "No files specified.\n");
|
|
665 |
return KErrGeneral;
|
|
666 |
}
|
|
667 |
|
|
668 |
return KErrNone;
|
|
669 |
}
|
|
670 |
|
|
671 |
TBool CObeyFile::Process() {
|
|
672 |
TBool result = ETrue;
|
|
673 |
iReader.Rewind();
|
|
674 |
enum EKeyword keyword;
|
|
675 |
while(iReader.NextLine(1, keyword) != KErrEof){
|
|
676 |
string key = iReader.Word(0);
|
|
677 |
string value = iReader.Word(1);
|
|
678 |
if(iKeyValues.find(key) != iKeyValues.end()){
|
|
679 |
iKeyValues[key].push_back(value);
|
|
680 |
}
|
|
681 |
else {
|
|
682 |
StringVector values;
|
|
683 |
values.push_back(value);
|
|
684 |
iKeyValues[key]=values;
|
|
685 |
}
|
|
686 |
|
|
687 |
|
|
688 |
}
|
|
689 |
return result;
|
|
690 |
}
|
|
691 |
StringVector CObeyFile::getValues(const string& aKey) {
|
|
692 |
StringVector values;
|
|
693 |
if(iKeyValues.find(aKey) != iKeyValues.end()){
|
|
694 |
values = iKeyValues[aKey];
|
|
695 |
}
|
|
696 |
return values;
|
|
697 |
}
|
|
698 |
|
|
699 |
/**
|
|
700 |
Process drive obey file and construct the tree.
|
|
701 |
|
|
702 |
@return - Return the status,
|
|
703 |
'KErrnone' for Success,
|
|
704 |
'KErrGeneral' for failure (required keywords not there in obey file or failed
|
|
705 |
to construct the tree).
|
|
706 |
*/
|
|
707 |
TInt CObeyFile::ProcessDataDrive() {
|
|
708 |
iReader.Rewind();
|
|
709 |
enum EKeyword keyword;
|
|
710 |
|
|
711 |
// First pass through the obey file to set up key variables
|
|
712 |
while (iReader.NextLine(1,keyword) != KErrEof) {
|
|
713 |
if (!ProcessDriveKeyword(keyword))
|
|
714 |
return KErrGeneral;
|
|
715 |
}
|
|
716 |
|
|
717 |
if (!GotKeyDriveVariables())
|
|
718 |
return KErrGeneral;
|
|
719 |
|
|
720 |
// Second pass to process the file specifications in the obey file.
|
|
721 |
// Build the TRomNode directory structure and the TRomBuilderEntry list
|
|
722 |
iReader.Rewind();
|
|
723 |
iRootDirectory = new TRomNode("//");
|
|
724 |
iLastExecutable = iRootDirectory;
|
|
725 |
|
|
726 |
while(iReader.NextLine(2,keyword)!=KErrEof) {
|
|
727 |
switch (keyword)
|
|
728 |
{
|
|
729 |
case EKeywordPatchDllData:
|
|
730 |
{ // Collect patchdata statements to process at the end
|
|
731 |
StringVector patchDataTokens;
|
|
732 |
SplitPatchDataStatement(patchDataTokens);
|
|
733 |
iPatchData->AddPatchDataStatement(patchDataTokens);
|
|
734 |
break;
|
|
735 |
}
|
|
736 |
|
|
737 |
case EKeywordHide:
|
|
738 |
case EKeywordFile:
|
|
739 |
case EKeywordDir:
|
|
740 |
case EKeywordData:
|
|
741 |
case EKeywordFileCompress:
|
|
742 |
case EKeywordFileUncompress:
|
|
743 |
if (!ProcessDriveFile(keyword))
|
|
744 |
return KErrGeneral;
|
|
745 |
break;
|
|
746 |
|
|
747 |
default:
|
|
748 |
break;
|
|
749 |
}
|
|
750 |
}
|
|
751 |
|
|
752 |
if(!ParsePatchDllData())
|
|
753 |
return KErrGeneral;
|
|
754 |
if (iMissingFiles) {
|
|
755 |
Print(EError, "Source Files Missing.\n");
|
|
756 |
return KErrGeneral;
|
|
757 |
}
|
|
758 |
if (!iNumberOfFiles)
|
617
|
759 |
Print(EAlways,"No files specified.\n");
|
606
|
760 |
|
|
761 |
return KErrNone;
|
|
762 |
}
|
|
763 |
|
|
764 |
|
|
765 |
/**
|
|
766 |
Process and stores the keyword information.
|
|
767 |
|
|
768 |
@param aKeyword - keyword to update its value to variables.
|
|
769 |
@return - Return the status i.e Success,
|
|
770 |
*/
|
|
771 |
TBool CObeyFile::ProcessDriveKeyword(enum EKeyword aKeyword) {
|
|
772 |
|
|
773 |
TBool success = ETrue;
|
|
774 |
switch (aKeyword)
|
|
775 |
{
|
|
776 |
case EKeywordDataImageName:
|
|
777 |
iDriveFileName = iReader.DupWord(1);
|
|
778 |
break;
|
|
779 |
case EKeywordDataImageFileSystem:
|
|
780 |
iDriveFileFormat = iReader.DupWord(1);
|
|
781 |
break;
|
|
782 |
case EKeywordDataImageSize:
|
|
783 |
{
|
|
784 |
const char* bigString = iReader.Word(1);
|
|
785 |
if(*bigString == '\0')
|
|
786 |
{
|
|
787 |
Print(EWarning,"Not a valid Image Size. Default size is considered\n");
|
|
788 |
break;
|
|
789 |
}
|
|
790 |
|
|
791 |
Val(iConfigurableFatAttributes.iImageSize,bigString);
|
|
792 |
}
|
|
793 |
break;
|
|
794 |
case EKeywordDataImageVolume:
|
|
795 |
{
|
|
796 |
// Get the volume label provided by using "volume" keyword.
|
|
797 |
// e.g. vlolume = NO NAME
|
|
798 |
string volumeLabel = iReader.GetCurrentObeyStatement();
|
|
799 |
string volumeLabelKeyword = "volume";
|
|
800 |
|
|
801 |
TUint position = volumeLabel.find(volumeLabelKeyword.c_str(),0,volumeLabelKeyword.size());
|
|
802 |
position += volumeLabelKeyword.size();
|
|
803 |
if (volumeLabel.find('=',position) != string::npos) {
|
|
804 |
position=volumeLabel.find('=',position);
|
|
805 |
++position;
|
|
806 |
}
|
|
807 |
|
|
808 |
position = volumeLabel.find_first_not_of(' ',position);
|
|
809 |
if (position != string::npos) {
|
|
810 |
volumeLabel = volumeLabel.substr(position);
|
|
811 |
|
|
812 |
// Remove the new line character from the end
|
|
813 |
position = volumeLabel.find_first_of("\r\n");
|
|
814 |
if (position != string::npos)
|
|
815 |
volumeLabel = volumeLabel.substr(0,position);
|
|
816 |
size_t length = volumeLabel.length() ;
|
|
817 |
if(length > 11)
|
|
818 |
length = 11 ;
|
|
819 |
memcpy(iConfigurableFatAttributes.iDriveVolumeLabel,volumeLabel.c_str(),length) ;
|
|
820 |
while(length != 11)
|
|
821 |
iConfigurableFatAttributes.iDriveVolumeLabel[length++] = ' ';
|
|
822 |
iConfigurableFatAttributes.iDriveVolumeLabel[length] = 0;
|
|
823 |
}
|
|
824 |
else {
|
|
825 |
Print(EWarning,"Value for Volume Label is not provided. Default value is considered.\n");
|
|
826 |
}
|
|
827 |
break;
|
|
828 |
}
|
|
829 |
case EKeywordDataImageSectorSize:
|
|
830 |
{
|
|
831 |
const char* bigString = iReader.Word(1);
|
|
832 |
TInt sectorSize = atoi(bigString);
|
|
833 |
if(sectorSize <= 0) {
|
|
834 |
Print(EWarning,"Invalid Sector Size value. Default value is considered.\n");
|
|
835 |
}
|
|
836 |
else {
|
|
837 |
iConfigurableFatAttributes.iDriveSectorSize = atoi(bigString);
|
|
838 |
}
|
|
839 |
}
|
|
840 |
break;
|
|
841 |
case EKeywordDataImageNoOfFats:
|
|
842 |
{
|
|
843 |
const char* bigString = iReader.Word(1);
|
|
844 |
TInt noOfFats = atoi(bigString);
|
|
845 |
if (noOfFats <=0)
|
|
846 |
Print(EWarning,"Invalid No of FATs specified. Default value is considered.\n");
|
|
847 |
else
|
|
848 |
iConfigurableFatAttributes.iDriveNoOfFATs = atoi(bigString);
|
|
849 |
}
|
|
850 |
break;
|
|
851 |
default:
|
|
852 |
// unexpected keyword iReader.Word(0), keep going.
|
|
853 |
break;
|
|
854 |
}
|
|
855 |
return success;
|
|
856 |
}
|
|
857 |
|
|
858 |
|
|
859 |
/**
|
|
860 |
Checks whether obeyfile has supplied enough variables to continue.
|
|
861 |
|
|
862 |
@return - Return the status
|
|
863 |
ETrue - Supplied valid values,
|
|
864 |
EFalse- Not valied values.
|
|
865 |
*/
|
|
866 |
TBool CObeyFile::GotKeyDriveVariables() {
|
|
867 |
|
|
868 |
TBool retVal=ETrue;
|
|
869 |
|
|
870 |
// Mandatory keywords
|
|
871 |
if (iDriveFileName==0) {
|
|
872 |
Print(EError,"The name of the image file has not been supplied.\n");
|
|
873 |
Print(EError,"Use the keyword \"dataimagename\".\n");
|
|
874 |
retVal = EFalse;
|
|
875 |
}
|
|
876 |
// Check for '-'ve entered value.
|
|
877 |
if(iConfigurableFatAttributes.iImageSize <= 0){
|
|
878 |
Print(EWarning,"Image Size should be positive. Default size is Considered.\n");
|
|
879 |
}
|
|
880 |
|
|
881 |
// File system format.
|
|
882 |
if(iDriveFileFormat==0) {
|
|
883 |
Print(EError,"The name of the file system not been supplied.\n");
|
|
884 |
Print(EError,"Use the keyword \"dataimagefilesystem\".\n");
|
|
885 |
retVal = EFalse;
|
|
886 |
}
|
|
887 |
|
|
888 |
// Checking the validity of file system format.
|
|
889 |
if(iDriveFileFormat){
|
|
890 |
if(stricmp(iDriveFileFormat,"FAT16") && stricmp(iDriveFileFormat,"FAT32")) {
|
|
891 |
Print(EError,"The name of the file system not supported : %s\n",iDriveFileFormat);
|
|
892 |
retVal = EFalse;
|
|
893 |
}
|
|
894 |
}
|
|
895 |
if(retVal)
|
|
896 |
Print(ELog,"\nCreating Data Drive image : %s\n", iDriveFileName);
|
|
897 |
|
|
898 |
return retVal;
|
|
899 |
}
|
|
900 |
|
|
901 |
/**
|
|
902 |
Process a parsed line to set up one or more new TRomBuilder entry objects.
|
|
903 |
|
|
904 |
@param - obey file keyword.
|
|
905 |
// iWord[0] = the keyword (file,)
|
|
906 |
// iWord[1] = the PC pathname
|
|
907 |
// iWord[2] = the EPOC pathname
|
|
908 |
// iWord[3] = start of the file attributes
|
|
909 |
|
|
910 |
@return - Return the status
|
|
911 |
ETrue - Successful generation of tree.
|
|
912 |
EFalse- Fail to generate the tree.
|
|
913 |
*/
|
|
914 |
TBool CObeyFile::ProcessDriveFile(enum EKeyword aKeyword) {
|
|
915 |
|
|
916 |
TBool isPeFile = ETrue;
|
|
917 |
TBool aFileCompressOption, aFileUncompressOption;
|
|
918 |
|
|
919 |
TInt epocPathStart=2;
|
|
920 |
aFileCompressOption = aFileUncompressOption = EFalse;
|
|
921 |
// do some validation of the keyword
|
|
922 |
TInt currentLine = iReader.CurrentLine();
|
|
923 |
|
|
924 |
switch (aKeyword)
|
|
925 |
{
|
|
926 |
case EKeywordData:
|
|
927 |
case EKeywordDir:
|
|
928 |
case EKeywordHide:
|
|
929 |
isPeFile = EFalse;
|
|
930 |
break;
|
|
931 |
|
|
932 |
case EKeywordFile:
|
|
933 |
break;
|
|
934 |
|
|
935 |
case EKeywordFileCompress:
|
|
936 |
aFileCompressOption = ETrue;
|
|
937 |
break;
|
|
938 |
|
|
939 |
case EKeywordFileUncompress:
|
|
940 |
aFileUncompressOption = ETrue;
|
|
941 |
break;
|
|
942 |
|
|
943 |
default:
|
|
944 |
return EFalse;
|
|
945 |
}
|
|
946 |
|
|
947 |
if (aKeyword!=EKeywordHide && aKeyword!=EKeywordDir) {
|
|
948 |
// check the PC file exists
|
|
949 |
char* nname = NormaliseFileName(iReader.Word(1));
|
|
950 |
ifstream test(nname);
|
|
951 |
if(!test.is_open()){
|
|
952 |
Print(EError,"Cannot open file %s for input.\n",iReader.Word(1));
|
|
953 |
iMissingFiles++;
|
|
954 |
}
|
|
955 |
test.close();
|
|
956 |
delete []nname ;
|
|
957 |
|
|
958 |
}
|
|
959 |
else
|
|
960 |
epocPathStart=1;
|
|
961 |
|
|
962 |
if(aKeyword != EKeywordDir)
|
|
963 |
iNumberOfFiles++;
|
|
964 |
|
|
965 |
TBool endOfName=EFalse;
|
|
966 |
const char *epocStartPtr;
|
|
967 |
if(aKeyword != EKeywordDir)
|
|
968 |
epocStartPtr = IsValidFilePath(iReader.Word(epocPathStart));
|
|
969 |
else
|
|
970 |
epocStartPtr = IsValidDirPath(iReader.Word(epocPathStart));
|
|
971 |
char *epocEndPtr = const_cast<char*>(epocStartPtr);
|
|
972 |
|
|
973 |
if (epocStartPtr == NULL) {
|
|
974 |
Print(EError, "Invalid destination path on line %d\n",currentLine);
|
|
975 |
return EFalse;
|
|
976 |
}
|
|
977 |
|
|
978 |
TRomNode* dir=iRootDirectory;
|
|
979 |
TRomNode* subDir=0;
|
|
980 |
TRomBuilderEntry *file=0;
|
|
981 |
|
|
982 |
while (!endOfName) {
|
|
983 |
endOfName = GetNextBitOfFileName(epocEndPtr);
|
|
984 |
if (endOfName && (aKeyword!=EKeywordDir)) { // file
|
|
985 |
TRomNode* alreadyExists=dir->FindInDirectory(epocStartPtr);
|
|
986 |
if ((aKeyword != EKeywordHide) && alreadyExists) { // duplicate file
|
|
987 |
if (gKeepGoing) {
|
|
988 |
Print(EWarning, "Duplicate file for %s on line %d, will be ignored\n",iReader.Word(1),iReader.CurrentLine());
|
|
989 |
iNumberOfFiles--;
|
|
990 |
return ETrue;
|
|
991 |
}
|
|
992 |
else {
|
|
993 |
Print(EError, "Duplicate file for %s on line %d\n",iReader.Word(1),iReader.CurrentLine());
|
|
994 |
return EFalse;
|
|
995 |
}
|
|
996 |
}
|
|
997 |
else if((aKeyword == EKeywordHide) && (alreadyExists)) {
|
|
998 |
alreadyExists->iEntry->iHidden = ETrue;
|
|
999 |
alreadyExists->iHidden = ETrue;
|
|
1000 |
return ETrue;
|
|
1001 |
}
|
|
1002 |
else if((aKeyword == EKeywordHide) && (!alreadyExists)) {
|
|
1003 |
Print(EWarning, "Hiding non-existent file %s on line %d\n",iReader.Word(1),iReader.CurrentLine());
|
|
1004 |
return ETrue;
|
|
1005 |
}
|
|
1006 |
|
|
1007 |
file = new TRomBuilderEntry(iReader.Word(1), epocStartPtr);
|
|
1008 |
file->iExecutable=isPeFile;
|
|
1009 |
if( aFileCompressOption ) {
|
|
1010 |
file->iCompressEnabled = ECompressionCompress;
|
|
1011 |
}
|
|
1012 |
else if(aFileUncompressOption ) {
|
|
1013 |
file->iCompressEnabled = ECompressionUncompress;
|
|
1014 |
}
|
|
1015 |
|
|
1016 |
TRomNode* node=new TRomNode(epocStartPtr, file);
|
|
1017 |
if (node==0)
|
|
1018 |
return EFalse;
|
|
1019 |
|
|
1020 |
TInt r=ParseFileAttributes(node, file, aKeyword);
|
|
1021 |
if (r!=KErrNone)
|
|
1022 |
return EFalse;
|
|
1023 |
|
|
1024 |
if(gCompress != ECompressionUnknown) {
|
|
1025 |
node->iFileUpdate = ETrue;
|
|
1026 |
}
|
|
1027 |
|
|
1028 |
if((node->iOverride) || (aFileCompressOption) || (aFileUncompressOption)) {
|
|
1029 |
node->iFileUpdate = ETrue;
|
|
1030 |
}
|
|
1031 |
|
|
1032 |
dir->AddFile(node); // to drive directory structure.
|
|
1033 |
}
|
|
1034 |
else {
|
|
1035 |
// directory
|
|
1036 |
//for directory creation, given /sys/bin/, it's possible to reach 0 at the end, just ignore that...
|
|
1037 |
if(!*epocStartPtr)
|
|
1038 |
break;
|
|
1039 |
|
|
1040 |
subDir = dir->FindInDirectory(epocStartPtr);
|
|
1041 |
if (!subDir){ // sub directory does not exist
|
|
1042 |
if(aKeyword==EKeywordHide) {
|
|
1043 |
Print(EWarning, "Hiding non-existent file %s on line %d\n",
|
|
1044 |
iReader.Word(1),iReader.CurrentLine());
|
|
1045 |
return ETrue;
|
|
1046 |
}
|
|
1047 |
subDir = dir->NewSubDir(epocStartPtr);
|
|
1048 |
if (!subDir)
|
|
1049 |
return EFalse;
|
|
1050 |
}
|
|
1051 |
dir=subDir;
|
|
1052 |
epocStartPtr = epocEndPtr;
|
|
1053 |
} // end of else.
|
|
1054 |
}
|
|
1055 |
return ETrue;
|
|
1056 |
}
|
|
1057 |
|
|
1058 |
|
|
1059 |
TInt CObeyFile::SetStackSize(TRomNode *aNode, const char* aStr) {
|
|
1060 |
if (EFalse == IsValidNumber(aStr))
|
|
1061 |
return Print(EError, "Number required as argument for keyword 'stack'.\n");
|
|
1062 |
TInt size ;
|
|
1063 |
TInt err = Val(size,aStr);
|
|
1064 |
if(KErrNone == err){
|
|
1065 |
aNode->SetStackSize(size );
|
|
1066 |
}
|
|
1067 |
return err;
|
|
1068 |
}
|
|
1069 |
|
|
1070 |
TInt CObeyFile::SetHeapSizeMin(TRomNode *aNode, const char* aStr) {
|
|
1071 |
if (EFalse == IsValidNumber(aStr))
|
|
1072 |
return Print(EError, "Number required as argument for keyword 'heapmin'.\n");
|
|
1073 |
TInt size ;
|
|
1074 |
TInt err = Val(size,aStr);
|
|
1075 |
if(KErrNone == err){
|
|
1076 |
aNode->SetHeapSizeMin(size );
|
|
1077 |
}
|
|
1078 |
return err;
|
|
1079 |
}
|
|
1080 |
|
|
1081 |
TInt CObeyFile::SetHeapSizeMax(TRomNode *aNode, const char* aStr) {
|
|
1082 |
if (EFalse == IsValidNumber(aStr))
|
|
1083 |
return Print(EError, "Number required as argument for keyword 'heapmax'.\n");
|
|
1084 |
TInt size ;
|
|
1085 |
TInt err = Val(size,aStr);
|
|
1086 |
if(KErrNone == err){
|
|
1087 |
aNode->SetHeapSizeMax(size );
|
|
1088 |
}
|
|
1089 |
return err;
|
|
1090 |
|
|
1091 |
}
|
|
1092 |
|
|
1093 |
TInt CObeyFile::SetCapability(TRomNode *aNode, const char* aStr) {
|
|
1094 |
if ( IsValidNumber(aStr)){
|
|
1095 |
Print(EDiagnostic,"Old style numeric CAPABILTY specification ignored.\n");
|
|
1096 |
return KErrNone;
|
|
1097 |
}
|
|
1098 |
SCapabilitySet cap;
|
|
1099 |
TInt r = ParseCapabilitiesArg(cap, (char*)aStr);
|
|
1100 |
if( KErrNone == r ) {
|
|
1101 |
aNode->SetCapability( cap );
|
|
1102 |
}
|
|
1103 |
return r;
|
|
1104 |
}
|
|
1105 |
|
|
1106 |
TInt CObeyFile::SetPriority(TRomNode *aNode, const char* aStr) {
|
|
1107 |
TProcessPriority priority;
|
|
1108 |
|
|
1109 |
if ( IsValidNumber(aStr)) {
|
|
1110 |
TUint32 temp = 0;
|
|
1111 |
Val(temp,aStr) ;
|
|
1112 |
priority = (TProcessPriority)temp ;
|
|
1113 |
}
|
|
1114 |
else {
|
|
1115 |
if (stricmp(aStr, "low")==0)
|
|
1116 |
priority=EPriorityLow;
|
|
1117 |
else if (strnicmp(aStr, "background", 4)==0)
|
|
1118 |
priority=EPriorityBackground;
|
|
1119 |
else if (strnicmp(aStr, "foreground", 4)==0)
|
|
1120 |
priority=EPriorityForeground;
|
|
1121 |
else if (stricmp(aStr, "high")==0)
|
|
1122 |
priority=EPriorityHigh;
|
|
1123 |
else if (strnicmp(aStr, "windowserver",3)==0)
|
|
1124 |
priority=EPriorityWindowServer;
|
|
1125 |
else if (strnicmp(aStr, "fileserver",4)==0)
|
|
1126 |
priority=EPriorityFileServer;
|
|
1127 |
else if (strnicmp(aStr, "realtimeserver",4)==0)
|
|
1128 |
priority=EPriorityRealTimeServer;
|
|
1129 |
else if (strnicmp(aStr, "supervisor",3)==0)
|
|
1130 |
priority=EPrioritySupervisor;
|
|
1131 |
else
|
|
1132 |
return Print(EError, "Unrecognised priority keyword.\n");
|
|
1133 |
}
|
|
1134 |
if (priority<EPriorityLow || priority>EPrioritySupervisor)
|
|
1135 |
return Print(EError, "Priority out of range.\n");
|
|
1136 |
|
|
1137 |
aNode->SetPriority( priority );
|
|
1138 |
return KErrNone;
|
|
1139 |
}
|
|
1140 |
|
|
1141 |
TInt CObeyFile::SetUid1(TRomNode *aNode, const char* aStr){
|
|
1142 |
if (EFalse == IsValidNumber(aStr))
|
|
1143 |
return Print(EError, "Number required as argument for keyword 'uid1'.\n");
|
|
1144 |
TInt size ;
|
|
1145 |
TInt err = Val(size,aStr);
|
|
1146 |
if(KErrNone == err){
|
|
1147 |
aNode->SetUid1(size );
|
|
1148 |
}
|
|
1149 |
return err;
|
|
1150 |
}
|
|
1151 |
TInt CObeyFile::SetUid2(TRomNode *aNode, const char* aStr) {
|
|
1152 |
if (EFalse == IsValidNumber(aStr))
|
|
1153 |
return Print(EError, "Number required as argument for keyword 'uid2'.\n");
|
|
1154 |
TInt size ;
|
|
1155 |
TInt err = Val(size,aStr);
|
|
1156 |
if(KErrNone == err){
|
|
1157 |
aNode->SetUid2(size );
|
|
1158 |
}
|
|
1159 |
return err;
|
|
1160 |
}
|
|
1161 |
TInt CObeyFile::SetUid3(TRomNode *aNode, const char* aStr) {
|
|
1162 |
if (EFalse == IsValidNumber(aStr))
|
|
1163 |
return Print(EError, "Number required as argument for keyword 'uid3'.\n");
|
|
1164 |
TInt size ;
|
|
1165 |
TInt err = Val(size,aStr);
|
|
1166 |
if(KErrNone == err){
|
|
1167 |
aNode->SetUid3(size );
|
|
1168 |
}
|
|
1169 |
return err;
|
|
1170 |
}
|
|
1171 |
|
|
1172 |
//
|
|
1173 |
// Process any inline keywords
|
|
1174 |
//
|
|
1175 |
TInt CObeyFile::ParseFileAttributes(TRomNode *aNode, TRomBuilderEntry* aFile, enum EKeyword aKeyword) {
|
|
1176 |
TInt currentLine = iReader.CurrentLine();
|
|
1177 |
enum EFileAttribute attribute;
|
|
1178 |
TInt r=KErrNone;
|
|
1179 |
TInt index=3;
|
|
1180 |
char* arg=0;
|
|
1181 |
|
|
1182 |
while(r==KErrNone) {
|
|
1183 |
r=iReader.NextAttribute(index,(aFile!=0),attribute,arg);
|
|
1184 |
if (r!=KErrNone)
|
|
1185 |
break;
|
|
1186 |
switch(attribute)
|
|
1187 |
{
|
|
1188 |
case EAttributeAtt:
|
|
1189 |
r=aNode->SetAtt(arg);
|
|
1190 |
break;
|
|
1191 |
case EAttributeAttExtra:
|
|
1192 |
r=aNode->SetAttExtra(arg, aFile, aKeyword);
|
|
1193 |
break;
|
|
1194 |
case EAttributeStack:
|
|
1195 |
r=SetStackSize(aNode, arg);
|
|
1196 |
break;
|
|
1197 |
case EAttributeFixed:
|
|
1198 |
aNode->SetFixed();
|
|
1199 |
r = KErrNone;
|
|
1200 |
break;
|
|
1201 |
case EAttributeUid1:
|
|
1202 |
r=SetUid1(aNode, arg);
|
|
1203 |
break;
|
|
1204 |
case EAttributeUid2:
|
|
1205 |
r=SetUid2(aNode, arg);
|
|
1206 |
break;
|
|
1207 |
case EAttributeUid3:
|
|
1208 |
r=SetUid3(aNode, arg);
|
|
1209 |
break;
|
|
1210 |
case EAttributeHeapMin:
|
|
1211 |
r=SetHeapSizeMin(aNode, arg);
|
|
1212 |
break;
|
|
1213 |
case EAttributeHeapMax:
|
|
1214 |
r=SetHeapSizeMax(aNode, arg);
|
|
1215 |
break;
|
|
1216 |
case EAttributePriority:
|
|
1217 |
r=SetPriority(aNode, arg);
|
|
1218 |
break;
|
|
1219 |
case EAttributeCapability:
|
|
1220 |
r=SetCapability(aNode, arg);
|
|
1221 |
break;
|
|
1222 |
case EAttributeUnpaged:
|
|
1223 |
aNode->iOverride |= KOverrideCodeUnpaged|KOverrideDataUnpaged;
|
|
1224 |
aNode->iOverride &= ~(KOverrideCodePaged|KOverrideDataPaged);
|
|
1225 |
break;
|
|
1226 |
case EAttributePaged:
|
|
1227 |
aNode->iOverride |= KOverrideCodePaged;
|
|
1228 |
aNode->iOverride &= ~(KOverrideCodeUnpaged);
|
|
1229 |
break;
|
|
1230 |
case EAttributeUnpagedCode:
|
|
1231 |
aNode->iOverride |= KOverrideCodeUnpaged;
|
|
1232 |
aNode->iOverride &= ~KOverrideCodePaged;
|
|
1233 |
break;
|
|
1234 |
case EAttributePagedCode:
|
|
1235 |
aNode->iOverride |= KOverrideCodePaged;
|
|
1236 |
aNode->iOverride &= ~KOverrideCodeUnpaged;
|
|
1237 |
break;
|
|
1238 |
case EAttributeUnpagedData:
|
|
1239 |
aNode->iOverride |= KOverrideDataUnpaged;
|
|
1240 |
aNode->iOverride &= ~KOverrideDataPaged;
|
|
1241 |
break;
|
|
1242 |
case EAttributePagedData:
|
|
1243 |
aNode->iOverride |= KOverrideDataPaged;
|
|
1244 |
aNode->iOverride &= ~KOverrideDataUnpaged;
|
|
1245 |
break;
|
|
1246 |
default:
|
|
1247 |
return Print(EError, "Unrecognised keyword in file attributes on line %d.\n",currentLine);
|
|
1248 |
}
|
|
1249 |
}
|
|
1250 |
|
|
1251 |
if (r==KErrEof)
|
|
1252 |
return KErrNone;
|
|
1253 |
return r;
|
|
1254 |
}
|
|
1255 |
|
|
1256 |
//
|
|
1257 |
// Process a parsed line to set up one or more new TRomBuilder entry objects.
|
|
1258 |
// iWord[0] = the keyword (file, primary or secondary)
|
|
1259 |
// iWord[1] = the PC pathname
|
|
1260 |
// iWord[2] = the EPOC pathname
|
|
1261 |
// iWord[3] = start of the file attributes
|
|
1262 |
//
|
|
1263 |
TBool CObeyFile::ProcessFile(TInt /*aAlign*/, enum EKeyword aKeyword){
|
|
1264 |
|
|
1265 |
TBool isPeFile = ETrue;
|
|
1266 |
TBool aFileCompressOption, aFileUncompressOption;
|
|
1267 |
TInt epocPathStart=2;
|
|
1268 |
aFileCompressOption = aFileUncompressOption = EFalse;
|
|
1269 |
TBool warnFlag = EFalse;
|
|
1270 |
static const char aStdPath[] = "SYS\\BIN\\";
|
|
1271 |
static const int sysBinLength = sizeof(aStdPath)-1;
|
|
1272 |
|
|
1273 |
// do some validation of the keyword
|
|
1274 |
TInt currentLine = iReader.CurrentLine();
|
|
1275 |
switch (aKeyword)
|
|
1276 |
{
|
|
1277 |
case EKeywordData:
|
|
1278 |
case EKeywordHideV2:
|
|
1279 |
iNumberOfDataFiles++;
|
|
1280 |
isPeFile = EFalse;
|
|
1281 |
break;
|
|
1282 |
|
|
1283 |
case EKeywordFile:
|
|
1284 |
warnFlag = gEnableStdPathWarning;
|
|
1285 |
break;
|
|
1286 |
case EKeywordFileCompress:
|
|
1287 |
aFileCompressOption = ETrue;
|
|
1288 |
warnFlag = gEnableStdPathWarning;
|
|
1289 |
break;
|
|
1290 |
case EKeywordFileUncompress:
|
|
1291 |
aFileUncompressOption = ETrue;
|
|
1292 |
warnFlag = gEnableStdPathWarning;
|
|
1293 |
break;
|
|
1294 |
|
|
1295 |
default:
|
|
1296 |
Print(EError,"Unexpected keyword '%s' on line %d.\n",iReader.Word(0),currentLine);
|
|
1297 |
return EFalse;
|
|
1298 |
}
|
|
1299 |
|
|
1300 |
if (aKeyword!=EKeywordHideV2) {
|
|
1301 |
|
|
1302 |
// check the PC file exists
|
|
1303 |
char* nname = NormaliseFileName(iReader.Word(1));
|
|
1304 |
ifstream test(nname);
|
|
1305 |
if (!test) {
|
|
1306 |
Print(EError,"Cannot open file %s for input.\n",iReader.Word(1));
|
|
1307 |
iMissingFiles++;
|
|
1308 |
}
|
|
1309 |
test.close();
|
|
1310 |
delete []nname;
|
|
1311 |
}
|
|
1312 |
else
|
|
1313 |
epocPathStart=1;
|
|
1314 |
|
|
1315 |
iNumberOfFiles++;
|
|
1316 |
|
|
1317 |
|
|
1318 |
TBool endOfName=EFalse;
|
|
1319 |
const char *epocStartPtr=IsValidFilePath(iReader.Word(epocPathStart));
|
|
1320 |
char *epocEndPtr=const_cast<char*>(epocStartPtr);
|
|
1321 |
if (epocStartPtr==NULL) {
|
|
1322 |
Print(EError, "Invalid destination path on line %d\n",currentLine);
|
|
1323 |
return EFalse;
|
|
1324 |
}
|
|
1325 |
if(warnFlag){ // Check for the std destination path(for executables) as per platsec.
|
|
1326 |
if(strnicmp(aStdPath,epocStartPtr,sysBinLength) != 0) {
|
|
1327 |
Print(EWarning,"Invalid destination path on line %d. \"%s\" \n",currentLine,epocStartPtr);
|
|
1328 |
}
|
|
1329 |
}
|
|
1330 |
|
|
1331 |
TRomNode* dir=iRootDirectory;
|
|
1332 |
TRomNode* subDir=0;
|
|
1333 |
TRomBuilderEntry *file=0;
|
|
1334 |
while (!endOfName) {
|
|
1335 |
endOfName = GetNextBitOfFileName(epocEndPtr);
|
|
1336 |
if (endOfName) {// file
|
|
1337 |
TRomNode* alreadyExists=dir->FindInDirectory(epocStartPtr);
|
|
1338 |
/*
|
|
1339 |
* The EKeywordHideV2 keyword is used to indicate that:
|
|
1340 |
* 1. if the file exists in the same image and then hidden, mark it hidden
|
|
1341 |
* 2. if the file exists in another image, but in this (ROFS) image, it is
|
|
1342 |
* required to hide that file, create a 0 length file entry setting the 'hide'
|
|
1343 |
* flag so that at runtime, file gets hidden in the composite filesystem.
|
|
1344 |
*/
|
|
1345 |
if ((aKeyword != EKeywordHideV2) && alreadyExists){ // duplicate file
|
|
1346 |
if(gKeepGoing){
|
|
1347 |
Print(EWarning, "Duplicate file for %s on line %d, will be ignored\n",iReader.Word(1),iReader.CurrentLine());
|
|
1348 |
switch (aKeyword)
|
|
1349 |
{
|
|
1350 |
case EKeywordData:
|
|
1351 |
case EKeywordHideV2:
|
|
1352 |
iNumberOfDataFiles--;
|
|
1353 |
default:
|
|
1354 |
break;
|
|
1355 |
}
|
|
1356 |
iNumberOfFiles--;
|
|
1357 |
return ETrue;
|
|
1358 |
}
|
|
1359 |
else {
|
|
1360 |
Print(EError, "Duplicate file for %s on line %d\n",iReader.Word(1),iReader.CurrentLine());
|
|
1361 |
return EFalse;
|
|
1362 |
}
|
|
1363 |
}
|
|
1364 |
|
|
1365 |
TBool aHidden = aKeyword==EKeywordHideV2;
|
|
1366 |
/* The file is only marked hidden and hence the source file name isn't known
|
|
1367 |
* here as hide statement says :
|
|
1368 |
* hide <filename as in ROM>
|
|
1369 |
* Therefore, create TRomBuilderEntry with iFileName as 0 for hidden file when
|
|
1370 |
* the file doesn't exist in the same ROM image. Otherwise, the src file name
|
|
1371 |
* is known because of alreadyExists (which comes from the 'file'/'data' statement).
|
|
1372 |
*/
|
|
1373 |
if(aHidden)
|
|
1374 |
file = new TRomBuilderEntry(0, epocStartPtr);
|
|
1375 |
else
|
|
1376 |
file = new TRomBuilderEntry(iReader.Word(1), epocStartPtr);
|
|
1377 |
file->iExecutable=isPeFile;
|
|
1378 |
file->iHidden= aHidden;
|
|
1379 |
if( aFileCompressOption ){
|
|
1380 |
file->iCompressEnabled = ECompressionCompress;
|
|
1381 |
}
|
|
1382 |
else if(aFileUncompressOption ) {
|
|
1383 |
file->iCompressEnabled = ECompressionUncompress;
|
|
1384 |
}
|
|
1385 |
TRomNode* node=new TRomNode(epocStartPtr, file);
|
|
1386 |
if (node==0)
|
|
1387 |
return EFalse;
|
|
1388 |
TInt r=ParseFileAttributes(node, file, aKeyword);
|
|
1389 |
if (r!=KErrNone)
|
|
1390 |
return EFalse;
|
|
1391 |
|
|
1392 |
dir->AddFile(node); // to ROFS directory structure
|
|
1393 |
AddFile(file); // to our list of files
|
|
1394 |
}
|
|
1395 |
else { // directory
|
|
1396 |
subDir = dir->FindInDirectory(epocStartPtr);
|
|
1397 |
if (!subDir) { // sub directory does not exist
|
|
1398 |
subDir = dir->NewSubDir(epocStartPtr);
|
|
1399 |
if (!subDir)
|
|
1400 |
return EFalse;
|
|
1401 |
}
|
|
1402 |
dir=subDir;
|
|
1403 |
epocStartPtr = epocEndPtr;
|
|
1404 |
}
|
|
1405 |
}
|
|
1406 |
return ETrue;
|
|
1407 |
}
|
|
1408 |
|
|
1409 |
|
|
1410 |
TBool CObeyFile::ProcessRenaming(enum EKeyword aKeyword) {
|
|
1411 |
|
|
1412 |
// find existing file
|
|
1413 |
TBool endOfName=EFalse;
|
|
1414 |
const char *epocStartPtr=IsValidFilePath(iReader.Word(1));
|
|
1415 |
|
|
1416 |
// Store the current name and new name to maintain renamed file map
|
|
1417 |
string currentName=iReader.Word(1);
|
|
1418 |
string newName=iReader.Word(2);
|
|
1419 |
|
|
1420 |
char *epocEndPtr= const_cast<char*>(epocStartPtr);
|
|
1421 |
if (epocStartPtr == NULL) {
|
|
1422 |
Print(EError, "Invalid source path on line %d\n",iReader.CurrentLine());
|
|
1423 |
return EFalse;
|
|
1424 |
}
|
|
1425 |
|
|
1426 |
char saved_srcname[257];
|
|
1427 |
strncpy(saved_srcname, iReader.Word(1),257);
|
|
1428 |
|
|
1429 |
TRomNode* dir=iRootDirectory;
|
|
1430 |
TRomNode* existingFile=0;
|
|
1431 |
while (!endOfName){
|
|
1432 |
endOfName = GetNextBitOfFileName(epocEndPtr);
|
|
1433 |
if (endOfName) { // file
|
|
1434 |
existingFile=dir->FindInDirectory(epocStartPtr);
|
|
1435 |
if (existingFile) {
|
|
1436 |
TInt fileCount=0;
|
|
1437 |
TInt dirCount=0;
|
|
1438 |
existingFile->CountDirectory(fileCount, dirCount);
|
|
1439 |
if (dirCount != 0 || fileCount != 0) {
|
|
1440 |
Print(EError, "Keyword %s not applicable to directories - line %d\n",
|
|
1441 |
iReader.Word(0),iReader.CurrentLine());
|
|
1442 |
return EFalse;
|
|
1443 |
}
|
|
1444 |
}
|
|
1445 |
}
|
|
1446 |
else { // directory
|
|
1447 |
TRomNode* subDir = dir->FindInDirectory(epocStartPtr);
|
|
1448 |
if (!subDir) // sub directory does not exist
|
|
1449 |
break;
|
|
1450 |
dir=subDir;
|
|
1451 |
epocStartPtr = epocEndPtr;
|
|
1452 |
}
|
|
1453 |
}
|
|
1454 |
if (aKeyword == EKeywordHide) {
|
|
1455 |
/*
|
|
1456 |
* The EKeywordHide keyword is used to indicate that if the file exists in
|
|
1457 |
* the primary ROFS image and then hidden in extension ROFS, mark it hidden.
|
|
1458 |
*/
|
|
1459 |
if (!existingFile) {
|
|
1460 |
Print(EWarning, "Hiding non-existent file %s on line %d\n",
|
|
1461 |
saved_srcname, iReader.CurrentLine());
|
|
1462 |
// Just a warning, as we've achieved the right overall effect.
|
|
1463 |
}
|
|
1464 |
else if (existingFile->iFileStartOffset==(TUint)KFileHidden){
|
|
1465 |
Print(EWarning, "Hiding already hidden file %s on line %d\n",
|
|
1466 |
saved_srcname, iReader.CurrentLine());
|
|
1467 |
// We will igrore this request, otherwise it will "undelete" it.
|
|
1468 |
}
|
|
1469 |
else {
|
|
1470 |
//hidden files will not be placed to the image
|
|
1471 |
existingFile->iHidden = ETrue;
|
|
1472 |
}
|
|
1473 |
return ETrue;
|
|
1474 |
}
|
|
1475 |
|
|
1476 |
if (!existingFile) {
|
|
1477 |
Print(EError, "Can't %s non-existent source file %s on line %d\n",
|
|
1478 |
iReader.Word(0), saved_srcname, iReader.CurrentLine());
|
|
1479 |
return EFalse;
|
|
1480 |
}
|
|
1481 |
|
|
1482 |
epocStartPtr = IsValidFilePath(iReader.Word(2));
|
|
1483 |
epocEndPtr = const_cast<char*>(epocStartPtr);
|
|
1484 |
endOfName = EFalse;
|
|
1485 |
if (epocStartPtr == NULL) {
|
|
1486 |
Print(EError, "Invalid destination path on line %d\n",iReader.CurrentLine());
|
|
1487 |
return EFalse;
|
|
1488 |
}
|
|
1489 |
|
|
1490 |
TRomNode* newdir=iRootDirectory;
|
|
1491 |
while (!endOfName) {
|
|
1492 |
endOfName = GetNextBitOfFileName(epocEndPtr);
|
|
1493 |
if (endOfName) {// file
|
|
1494 |
TRomNode* alreadyExists=newdir->FindInDirectory(epocStartPtr);
|
|
1495 |
if (alreadyExists && !(alreadyExists->iHidden)) {// duplicate file
|
|
1496 |
if(gKeepGoing){
|
|
1497 |
Print(EWarning, "Duplicate file for %s on line %d, renaming will be skipped\n",saved_srcname,iReader.CurrentLine());
|
|
1498 |
return ETrue;
|
|
1499 |
}
|
|
1500 |
else {
|
|
1501 |
Print(EError, "Duplicate file for %s on line %d\n",saved_srcname,iReader.CurrentLine());
|
|
1502 |
return EFalse;
|
|
1503 |
}
|
|
1504 |
}
|
|
1505 |
}
|
|
1506 |
else { // directory
|
|
1507 |
TRomNode* subDir = newdir->FindInDirectory(epocStartPtr);
|
|
1508 |
if (!subDir) {// sub directory does not exist
|
|
1509 |
subDir = newdir->NewSubDir(epocStartPtr);
|
|
1510 |
if (!subDir)
|
|
1511 |
return EFalse;
|
|
1512 |
}
|
|
1513 |
newdir=subDir;
|
|
1514 |
epocStartPtr = epocEndPtr;
|
|
1515 |
}
|
|
1516 |
}
|
|
1517 |
|
|
1518 |
if (aKeyword == EKeywordRename) {
|
|
1519 |
// rename => remove existingFile and insert into tree at new place
|
|
1520 |
// has no effect on the iNextExecutable or iNextNodeForSameFile links
|
|
1521 |
TInt r=ParseFileAttributes(existingFile, existingFile->iEntry, aKeyword);
|
|
1522 |
if (r!=KErrNone)
|
|
1523 |
return EFalse;
|
|
1524 |
existingFile->Rename(dir, newdir, epocStartPtr);
|
|
1525 |
// Store the current and new name of file in the renamed file map.
|
|
1526 |
iPatchData->AddToRenamedFileMap(currentName, newName);
|
|
1527 |
return ETrue;
|
|
1528 |
}
|
|
1529 |
|
|
1530 |
// alias => create new TRomNode entry and insert into tree
|
|
1531 |
TRomNode* node = new TRomNode(epocStartPtr, 0);
|
|
1532 |
if (node == 0) {
|
|
1533 |
Print(EError, "Out of memory\n");
|
|
1534 |
return EFalse;
|
|
1535 |
}
|
|
1536 |
node->Alias(existingFile);
|
|
1537 |
TInt r=ParseFileAttributes(node, 0, aKeyword);
|
|
1538 |
if (r!=KErrNone)
|
|
1539 |
return EFalse;
|
|
1540 |
newdir->AddFile(node); // to ROFS directory structure, though possibly hidden
|
|
1541 |
return ETrue;
|
|
1542 |
}
|
|
1543 |
|
|
1544 |
TInt ParsePagingPolicy(const char* policy){
|
|
1545 |
if(stricmp(policy,"NOPAGING") == 0)
|
|
1546 |
return EKernelConfigPagingPolicyNoPaging;
|
|
1547 |
else if (stricmp(policy,"ALWAYSPAGE") == 0)
|
|
1548 |
return EKernelConfigPagingPolicyAlwaysPage;
|
|
1549 |
else if(stricmp(policy,"DEFAULTUNPAGED") == 0)
|
|
1550 |
return EKernelConfigPagingPolicyDefaultUnpaged;
|
|
1551 |
else if(stricmp(policy,"DEFAULTPAGED") == 0)
|
|
1552 |
return EKernelConfigPagingPolicyDefaultPaged;
|
|
1553 |
return KErrArgument;
|
|
1554 |
}
|
|
1555 |
|
|
1556 |
TBool CObeyFile::ProcessKeyword(enum EKeyword aKeyword) {
|
|
1557 |
|
|
1558 |
TBool success = ETrue;
|
|
1559 |
switch (aKeyword)
|
|
1560 |
{
|
|
1561 |
case EKeywordRofsName:
|
|
1562 |
iRomFileName = iReader.DupWord(1);
|
|
1563 |
break;
|
|
1564 |
case EKeywordRofsSize:
|
|
1565 |
Val(iRomSize,iReader.Word(1));
|
|
1566 |
break;
|
|
1567 |
case EKeywordVersion:
|
|
1568 |
{
|
|
1569 |
istringstream val(iReader.Word(1));
|
|
1570 |
val >> iVersion;
|
|
1571 |
}
|
|
1572 |
break;
|
|
1573 |
case EKeywordRofsChecksum:
|
|
1574 |
Val(iCheckSum,iReader.Word(1));
|
|
1575 |
break;
|
|
1576 |
case EKeywordTime:
|
|
1577 |
iReader.ProcessTime(iTime);
|
|
1578 |
break;
|
|
1579 |
case EKeywordPagingOverride:
|
|
1580 |
{
|
|
1581 |
if(iPagingOverrideParsed)
|
|
1582 |
Print(EWarning, "PagingOverride redefined - previous PagingOverride values lost\n");
|
|
1583 |
if(iCodePagingOverrideParsed)
|
|
1584 |
Print(EWarning, "PagingOverride defined - previous CodePagingOverride values lost\n");
|
|
1585 |
iPagingOverrideParsed = true;
|
|
1586 |
TInt policy = ParsePagingPolicy(iReader.Word(1));
|
|
1587 |
if(policy < 0) {
|
|
1588 |
Print(EError,"Unrecognized option for PAGINGOVERRIDE keyword\n");
|
|
1589 |
success = false;
|
|
1590 |
}
|
|
1591 |
else {
|
|
1592 |
gCodePagingOverride = policy;
|
|
1593 |
if((policy == EKernelConfigPagingPolicyNoPaging) || (policy == EKernelConfigPagingPolicyDefaultUnpaged))
|
|
1594 |
gDataPagingOverride = policy;
|
|
1595 |
}
|
|
1596 |
}
|
|
1597 |
break;
|
|
1598 |
case EKeywordCodePagingOverride:
|
|
1599 |
{
|
|
1600 |
if(iCodePagingOverrideParsed)
|
|
1601 |
Print(EWarning, "CodePagingOverride redefined - previous CodePagingOverride values lost\n");
|
|
1602 |
if(iPagingOverrideParsed)
|
|
1603 |
Print(EWarning, "CodePagingOverride defined - previous PagingOverride values lost\n");
|
|
1604 |
iCodePagingOverrideParsed = true;
|
|
1605 |
TInt policy = ParsePagingPolicy(iReader.Word(1));
|
|
1606 |
if(policy<0)
|
|
1607 |
{
|
|
1608 |
Print(EError,"Unrecognized option for CODEPAGINGOVERRIDE keyword\n");
|
|
1609 |
success = false;
|
|
1610 |
}
|
|
1611 |
else
|
|
1612 |
gCodePagingOverride = policy;
|
|
1613 |
}
|
|
1614 |
break;
|
|
1615 |
case EKeywordDataPagingOverride:
|
|
1616 |
{
|
|
1617 |
if(iDataPagingOverrideParsed)
|
|
1618 |
Print(EWarning, "DataPagingOverride redefined - previous DataPagingOverride values lost\n");
|
|
1619 |
/* if(iPagingOverrideParsed){
|
|
1620 |
Print(EError, "DataPagingOverride defined - previous PagingOverride values lost\n");
|
|
1621 |
success = false;
|
|
1622 |
break;
|
|
1623 |
}
|
|
1624 |
*/
|
|
1625 |
iDataPagingOverrideParsed = true;
|
|
1626 |
TInt policy = ParsePagingPolicy(iReader.Word(1));
|
|
1627 |
if(policy < 0) {
|
|
1628 |
Print(EError,"Unrecognized option for DATAPAGINGOVERRIDE keyword\n");
|
|
1629 |
success = false;
|
|
1630 |
}
|
|
1631 |
else
|
|
1632 |
gDataPagingOverride = policy;
|
|
1633 |
}
|
|
1634 |
break;
|
|
1635 |
case EKeywordRofsAutoSize:
|
|
1636 |
iAutoSize = ETrue;
|
|
1637 |
Val(iAutoPageSize,iReader.Word(1));
|
|
1638 |
break;
|
|
1639 |
default:
|
|
1640 |
// unexpected keyword iReader.Word(0)
|
|
1641 |
break;
|
|
1642 |
}
|
|
1643 |
|
|
1644 |
return success;
|
|
1645 |
}
|
|
1646 |
//
|
|
1647 |
// Checks that the obeyfile has supplied enough variables to continue
|
|
1648 |
//
|
|
1649 |
TBool CObeyFile::GotKeyVariables() {
|
|
1650 |
|
|
1651 |
TBool retVal=ETrue;
|
|
1652 |
// Mandatory keywords
|
|
1653 |
if (iRomFileName == 0) {
|
|
1654 |
Print(EAlways,"The name of the image file has not been supplied.\n");
|
|
1655 |
Print(EAlways,"Use the keyword \"rofsname\".\n");
|
|
1656 |
retVal = EFalse;
|
|
1657 |
}
|
|
1658 |
if (iRomSize == 0) {
|
|
1659 |
Print(EAlways,"The size of the image has not been supplied.\n");
|
|
1660 |
Print(EAlways,"Use the keyword \"rofssize\".\n");
|
|
1661 |
retVal = EFalse;
|
|
1662 |
}
|
|
1663 |
// Apply defaults as necessary
|
|
1664 |
if (iTime == 0) {
|
|
1665 |
Print(ELog, "No timestamp specified. Using current time...\n");
|
|
1666 |
ObeyFileReader::TimeNow(iTime);
|
|
1667 |
}
|
|
1668 |
Print(ELog, "\nCreating Rofs image %s\n", iRomFileName);
|
|
1669 |
return retVal;
|
|
1670 |
}
|
|
1671 |
|
|
1672 |
//
|
|
1673 |
// Check the path is valid
|
|
1674 |
//
|
|
1675 |
const char* CObeyFile::IsValidFilePath(const char* aPath) {
|
|
1676 |
// skip leading "\"
|
|
1677 |
if (*aPath == '/' || *aPath == '\\')
|
|
1678 |
aPath++;
|
|
1679 |
if (*aPath == 0)
|
|
1680 |
return NULL; // file ends in a backslash
|
|
1681 |
|
|
1682 |
const char *p = aPath;
|
|
1683 |
TInt len=0;
|
|
1684 |
while(*p) {
|
|
1685 |
if (*p == '/' || *p == '\\') {
|
|
1686 |
if (len == 0)
|
|
1687 |
return NULL;
|
|
1688 |
len=0;
|
|
1689 |
p++;
|
|
1690 |
continue;
|
|
1691 |
|
|
1692 |
}
|
|
1693 |
len++;
|
|
1694 |
p++;
|
|
1695 |
}
|
|
1696 |
return (len ? aPath : NULL);
|
|
1697 |
}
|
|
1698 |
|
|
1699 |
const char* CObeyFile::IsValidDirPath(const char* aPath)
|
|
1700 |
{
|
|
1701 |
const char* walker = aPath;
|
|
1702 |
|
|
1703 |
//validate path...
|
|
1704 |
while(*walker)
|
|
1705 |
{
|
|
1706 |
if(((*walker=='/') || (*walker=='\\')) && ((*(walker+1)=='/') || (*(walker+1)=='\\')))
|
|
1707 |
return (const char*)0;
|
|
1708 |
walker++;
|
|
1709 |
}
|
|
1710 |
|
|
1711 |
if((*aPath=='/') || (*aPath=='\\'))
|
|
1712 |
aPath++;
|
|
1713 |
|
|
1714 |
return aPath;
|
|
1715 |
}
|
|
1716 |
|
|
1717 |
//
|
|
1718 |
// Move the end pointer past the next directory separator, replacing it with 0
|
|
1719 |
//
|
|
1720 |
TBool CObeyFile::GetNextBitOfFileName(char*& epocEndPtr) {
|
|
1721 |
while (*epocEndPtr != '/' && *epocEndPtr != '\\'){ // until reach the directory separator
|
|
1722 |
if (*epocEndPtr == 0) // if reach end of string, return TRUE, it's the filename
|
|
1723 |
return ETrue;
|
|
1724 |
epocEndPtr++;
|
|
1725 |
}
|
|
1726 |
*epocEndPtr = 0; // overwrite the directory separator with a 0
|
|
1727 |
epocEndPtr++; // point past the 0 ready for the next one
|
|
1728 |
return EFalse;
|
|
1729 |
}
|
|
1730 |
|
|
1731 |
void CObeyFile::AddFile(TRomBuilderEntry* aFile) {
|
|
1732 |
*iNextFilePtrPtr = aFile;
|
|
1733 |
iNextFilePtrPtr = &(aFile->iNext);
|
|
1734 |
}
|
|
1735 |
|
|
1736 |
//
|
|
1737 |
// First pass through the obey file to set up key variables
|
|
1738 |
//
|
|
1739 |
TInt CObeyFile::ProcessExtensionRofs(MRofsImage* aKernelRom) {
|
|
1740 |
|
|
1741 |
iReader.Rewind();
|
|
1742 |
enum EKeyword keyword;
|
|
1743 |
|
|
1744 |
// Deal with the "extensionrofs" keyword, which should be first
|
|
1745 |
// however, you may've found "time" before it.
|
|
1746 |
while(iReader.NextLine(1,keyword) != KErrEof) {
|
|
1747 |
if(EKeywordExtensionRofs == keyword)
|
|
1748 |
break ;
|
|
1749 |
}
|
|
1750 |
if(EKeywordExtensionRofs != keyword) return KErrEof;
|
|
1751 |
iRomFileName = iReader.DupWord(1);
|
|
1752 |
Print(ELog, "\n========================================================\n");
|
|
1753 |
Print(ELog, "Extension ROFS %s starting at line %d\n\n", iRomFileName, iReader.CurrentLine());
|
|
1754 |
|
|
1755 |
iReader.MarkNext(); // so that we rewind to the line after the extensionrom keyword
|
|
1756 |
|
|
1757 |
while (iReader.NextLine(1,keyword) != KErrEof) {
|
|
1758 |
if (keyword == EKeywordExtensionRofs)
|
|
1759 |
break;
|
|
1760 |
ProcessExtensionKeyword(keyword);
|
|
1761 |
}
|
|
1762 |
|
|
1763 |
if (!GotExtensionVariables(aKernelRom))
|
|
1764 |
return KErrGeneral;
|
|
1765 |
|
|
1766 |
// second pass to process the file specifications in the obey file building
|
|
1767 |
// up the TRomNode directory structure and the TRomBuilderEntry list
|
|
1768 |
//
|
|
1769 |
iReader.Rewind();
|
|
1770 |
|
|
1771 |
//
|
|
1772 |
if (aKernelRom == 0)
|
|
1773 |
return Print(EError, "Option to extend a kernel ROFS image not yet implemented\n");
|
|
1774 |
|
|
1775 |
iRootDirectory = new TRomNode("");
|
|
1776 |
|
|
1777 |
iLastExecutable = 0;
|
|
1778 |
|
|
1779 |
(aKernelRom->RootDirectory())->deleteTheFirstNode();
|
|
1780 |
|
|
1781 |
|
|
1782 |
iRootDirectory = aKernelRom->CopyDirectory(iLastExecutable);
|
|
1783 |
aKernelRom->SetRootDirectory(iRootDirectory);
|
|
1784 |
|
|
1785 |
|
|
1786 |
TInt align=0;
|
|
1787 |
while (iReader.NextLine(2,keyword)!=KErrEof) {
|
|
1788 |
if (keyword == EKeywordExtensionRofs)
|
|
1789 |
break;
|
|
1790 |
|
|
1791 |
switch (keyword)
|
|
1792 |
{
|
|
1793 |
case EKeywordHide:
|
|
1794 |
case EKeywordAlias:
|
|
1795 |
case EKeywordRename:
|
|
1796 |
if (!ProcessRenaming(keyword))
|
|
1797 |
return KErrGeneral;
|
|
1798 |
break;
|
|
1799 |
|
|
1800 |
case EKeywordPatchDllData:
|
|
1801 |
{
|
|
1802 |
// Collect patchdata statements to process at the end
|
|
1803 |
StringVector patchDataTokens;
|
|
1804 |
SplitPatchDataStatement(patchDataTokens);
|
|
1805 |
iPatchData->AddPatchDataStatement(patchDataTokens);
|
|
1806 |
break;
|
|
1807 |
}
|
|
1808 |
default:
|
|
1809 |
if (!ProcessFile(align, keyword))
|
|
1810 |
return KErrGeneral;
|
|
1811 |
align=0;
|
|
1812 |
break;
|
|
1813 |
}
|
|
1814 |
}
|
|
1815 |
|
|
1816 |
if(!ParsePatchDllData() )
|
|
1817 |
return KErrGeneral;
|
|
1818 |
|
|
1819 |
iReader.MarkNext(); // ready for processing the next extension rom(s)
|
|
1820 |
|
|
1821 |
if (iMissingFiles!=0)
|
|
1822 |
return KErrGeneral;
|
|
1823 |
if (iNumberOfFiles == 0) {
|
|
1824 |
Print(EError, "No files specified.\n");
|
|
1825 |
return KErrGeneral;
|
|
1826 |
}
|
|
1827 |
return KErrNone;
|
|
1828 |
}
|
|
1829 |
void CObeyFile::ProcessExtensionKeyword(enum EKeyword aKeyword) {
|
|
1830 |
|
|
1831 |
switch (aKeyword)
|
|
1832 |
{
|
|
1833 |
case EKeywordCoreRofsName:
|
|
1834 |
iKernelRofsName = iReader.DupWord(1);
|
|
1835 |
return;
|
|
1836 |
case EKeywordRofsSize:
|
|
1837 |
Val(iRomSize,iReader.Word(1));
|
|
1838 |
return;
|
|
1839 |
case EKeywordVersion:
|
|
1840 |
{
|
|
1841 |
istringstream val(iReader.Word(1));
|
|
1842 |
val >> iVersion;
|
|
1843 |
}
|
|
1844 |
return;
|
|
1845 |
case EKeywordRomChecksum:
|
|
1846 |
Val(iCheckSum,iReader.Word(1)); //--
|
|
1847 |
return;
|
|
1848 |
case EKeywordTime:
|
|
1849 |
iReader.ProcessTime(iTime);
|
|
1850 |
return;
|
|
1851 |
case EKeywordRofsAutoSize:
|
|
1852 |
iAutoSize = ETrue;
|
|
1853 |
Val(iAutoPageSize , iReader.Word(1));
|
|
1854 |
return;
|
|
1855 |
default:
|
|
1856 |
Print(EError,"Keyword '%s' not valid in extension ROFS - line %d\n", iReader.Word(0), iReader.CurrentLine());
|
|
1857 |
break;
|
|
1858 |
}
|
|
1859 |
return;
|
|
1860 |
}
|
|
1861 |
//
|
|
1862 |
// Checks that the obeyfile has supplied enough variables to continue
|
|
1863 |
//
|
|
1864 |
TBool CObeyFile::GotExtensionVariables(MRofsImage* aRom) {
|
|
1865 |
|
|
1866 |
TBool retVal=ETrue;
|
|
1867 |
const char* kernelRofsName = iKernelRofsName;
|
|
1868 |
|
|
1869 |
// Mandatory keywords
|
|
1870 |
|
|
1871 |
if (iRomSize == 0){
|
|
1872 |
Print(EAlways,"The size of the extension ROFS has not been supplied.\n");
|
|
1873 |
Print(EAlways,"Use the keyword \"rofssize\".\n");
|
|
1874 |
retVal = EFalse;
|
|
1875 |
}
|
|
1876 |
|
|
1877 |
// keywords we need if we don't already have a ROFS image to work from
|
|
1878 |
if (aRom == 0) {
|
|
1879 |
if (iKernelRofsName == 0) {
|
|
1880 |
Print(EAlways,"The name of the core ROFS has not been supplied.\n");
|
|
1881 |
Print(EAlways,"Use the keyword \"rofsname\".\n");
|
|
1882 |
retVal = EFalse;
|
|
1883 |
}
|
|
1884 |
}
|
|
1885 |
else {
|
|
1886 |
if (iKernelRofsName != 0){
|
|
1887 |
Print(EWarning,"Keyword \"rofsname\" ignored.\n");
|
|
1888 |
}
|
|
1889 |
kernelRofsName = aRom->RomFileName();
|
|
1890 |
}
|
|
1891 |
|
|
1892 |
// validation
|
|
1893 |
// Apply defaults as necessary
|
|
1894 |
if (iTime == 0) {
|
|
1895 |
Print(ELog, "No timestamp specified. Using current time...\n");
|
|
1896 |
ObeyFileReader::TimeNow(iTime);
|
|
1897 |
}
|
|
1898 |
|
|
1899 |
// fix up "*" in rofsname
|
|
1900 |
char newname[256];
|
|
1901 |
char* p=newname;
|
|
1902 |
char* q=iRomFileName;
|
|
1903 |
char c;
|
|
1904 |
|
|
1905 |
while ((c=*q++)!='\0'){
|
|
1906 |
if (c!='*') {
|
|
1907 |
*p++=c;
|
|
1908 |
continue;
|
|
1909 |
}
|
|
1910 |
const char *r = kernelRofsName;
|
|
1911 |
while ((c=*r++)!='\0')
|
|
1912 |
*p++=c;
|
|
1913 |
}
|
|
1914 |
*p++ = '\0';
|
|
1915 |
delete []iRomFileName;
|
|
1916 |
size_t len = p - newname ;
|
|
1917 |
iRomFileName = new char[len];
|
|
1918 |
memcpy(iRomFileName,newname,len);
|
|
1919 |
Print(ELog, "\nCreating ROFS image %s\n", iRomFileName);
|
|
1920 |
return retVal;
|
|
1921 |
}
|
|
1922 |
|
|
1923 |
// Fuction to split patchdata statement
|
|
1924 |
void CObeyFile::SplitPatchDataStatement(StringVector& aPatchDataTokens) {
|
|
1925 |
// Get the value of symbol size, address/ordinal and new value
|
|
1926 |
// to be patched from the patchdata statement.
|
|
1927 |
// Syntax of patchdata statements is as follows:
|
|
1928 |
// 1) patchdata dll_name ordinal OrdinalNumber size_in_bytes new_value
|
|
1929 |
// 2) patchdata dll_name addr Address size_in_bytes new_value
|
|
1930 |
for(TInt count=1; count<=5; count++) {
|
|
1931 |
aPatchDataTokens.push_back(iReader.Word(count));
|
|
1932 |
}
|
|
1933 |
|
|
1934 |
// Store the the value of current line which will be used
|
|
1935 |
// when displaying error messages.
|
|
1936 |
ostringstream outStrStream;
|
|
1937 |
outStrStream<<iReader.CurrentLine();
|
|
1938 |
aPatchDataTokens.push_back(outStrStream.str());
|
|
1939 |
}
|
|
1940 |
|
|
1941 |
TBool CObeyFile::ParsePatchDllData() {
|
|
1942 |
// Get the list of patchdata statements
|
|
1943 |
VectorOfStringVector patchDataStatements=iPatchData->GetPatchDataStatements();
|
|
1944 |
// Get the list of renamed file map
|
|
1945 |
MapOfString RenamedFileMap=iPatchData->GetRenamedFileMap();
|
|
1946 |
|
|
1947 |
for(TUint count=0; count < patchDataStatements.size(); count++) {
|
|
1948 |
|
|
1949 |
StringVector strVector = patchDataStatements.at(count);
|
|
1950 |
string filename=strVector.at(0);
|
|
1951 |
string lineNoStr = strVector.at(5);
|
|
1952 |
TUint lineNo = 0 ;
|
|
1953 |
Val(lineNo,lineNoStr.c_str());
|
|
1954 |
TRomNode* existingFile = NULL;
|
|
1955 |
|
|
1956 |
do {
|
|
1957 |
TRomNode* dir=iRootDirectory;
|
|
1958 |
TBool endOfName=EFalse;
|
|
1959 |
|
|
1960 |
if (!IsValidFilePath(filename.c_str())) {
|
|
1961 |
Print(EError, "Invalid source path on line %d\n",lineNo);
|
|
1962 |
return EFalse;
|
|
1963 |
}
|
|
1964 |
char* epocStartPtr =NormaliseFileName(filename.c_str());
|
|
1965 |
char* savedPtr = epocStartPtr;
|
|
1966 |
if(*epocStartPtr == '/' ||*epocStartPtr == '\\')
|
|
1967 |
epocStartPtr++ ;
|
|
1968 |
char* epocEndPtr = epocStartPtr;
|
|
1969 |
|
|
1970 |
while (!endOfName) {
|
|
1971 |
endOfName = GetNextBitOfFileName(epocEndPtr);
|
|
1972 |
if (endOfName) {// file
|
|
1973 |
existingFile=dir->FindInDirectory(epocStartPtr);
|
|
1974 |
if (existingFile) {
|
|
1975 |
TInt fileCount=0;
|
|
1976 |
TInt dirCount=0;
|
|
1977 |
existingFile->CountDirectory(fileCount, dirCount);
|
|
1978 |
if (dirCount != 0 || fileCount != 0) {
|
|
1979 |
Print(EError, "Keyword %s not applicable to directories - line %d\n","patchdata",lineNo);
|
|
1980 |
return EFalse;
|
|
1981 |
}
|
|
1982 |
}
|
|
1983 |
}
|
|
1984 |
else {// directory
|
|
1985 |
TRomNode* subDir = dir->FindInDirectory(epocStartPtr);
|
|
1986 |
if (!subDir) // sub directory does not exist
|
|
1987 |
break;
|
|
1988 |
dir=subDir;
|
|
1989 |
epocStartPtr = epocEndPtr;
|
|
1990 |
}
|
|
1991 |
}
|
|
1992 |
delete []savedPtr;
|
|
1993 |
|
|
1994 |
if(!existingFile) {
|
|
1995 |
// If the E32Image file to be patched is not included then check if the
|
|
1996 |
// file was renamed.
|
|
1997 |
MapOfStringIterator RenamedFileMapIterator;
|
|
1998 |
if ((RenamedFileMapIterator=RenamedFileMap.find(filename)) != RenamedFileMap.end())
|
|
1999 |
filename = (*RenamedFileMapIterator).second;
|
|
2000 |
else {
|
|
2001 |
Print(EError, "File %s not found - line %d\n", filename.c_str(), lineNo);
|
|
2002 |
return EFalse;
|
|
2003 |
}
|
|
2004 |
}
|
|
2005 |
}while(!existingFile);
|
|
2006 |
|
|
2007 |
TUint32 aSize, aOrdinal, aNewValue, aOffset;
|
|
2008 |
TLinAddr aDataAddr;
|
|
2009 |
|
|
2010 |
aOrdinal = (TUint32)-1;
|
|
2011 |
aDataAddr = (TUint32)-1;
|
|
2012 |
aOffset = 0;
|
|
2013 |
|
|
2014 |
string symbolSize=strVector.at(3);
|
|
2015 |
Val(aSize,symbolSize.c_str());
|
|
2016 |
string aValue=strVector.at(4);
|
|
2017 |
Val(aNewValue,aValue.c_str());
|
|
2018 |
|
|
2019 |
DllDataEntry *dataEntry = new DllDataEntry(aSize, aNewValue);
|
|
2020 |
|
|
2021 |
// Set the address of the data or the ordinal number specified in OBY statement.
|
|
2022 |
string keyword=strVector.at(1);
|
|
2023 |
string keywordValue=strVector.at(2);
|
|
2024 |
|
|
2025 |
/* Check for +OFFSET at the end of the ordinal number or address */
|
|
2026 |
TUint plus = keywordValue.find("+",0);
|
|
2027 |
if (plus != string::npos) {
|
|
2028 |
/* Get the offset that we found after the + sign */
|
|
2029 |
string offset = keywordValue.substr(plus+1);
|
|
2030 |
Val(aOffset,offset.c_str());
|
|
2031 |
|
|
2032 |
keywordValue.resize(plus);
|
|
2033 |
}
|
|
2034 |
if(stricmp (keyword.c_str(), "addr") == 0)
|
|
2035 |
Val(aDataAddr,keywordValue.c_str());
|
|
2036 |
|
|
2037 |
else
|
|
2038 |
Val(aOrdinal,keywordValue.c_str());
|
|
2039 |
|
|
2040 |
dataEntry->iDataAddress = aDataAddr;
|
|
2041 |
dataEntry->iOrdinal = aOrdinal;
|
|
2042 |
dataEntry->iOffset = aOffset;
|
|
2043 |
|
|
2044 |
existingFile->SetDllData();
|
|
2045 |
|
|
2046 |
DllDataEntry *aDllDataEntry= existingFile->iEntry->GetFirstDllDataEntry();
|
|
2047 |
if (aDllDataEntry == NULL) {
|
|
2048 |
// Set the first node of the patchdata linked list
|
|
2049 |
aDllDataEntry=dataEntry;
|
|
2050 |
existingFile->iEntry->SetFirstDllDataEntry(aDllDataEntry);
|
|
2051 |
}
|
|
2052 |
else {
|
|
2053 |
// Goto the last node
|
|
2054 |
while((aDllDataEntry->NextDllDataEntry()) != NULL) {
|
|
2055 |
aDllDataEntry = aDllDataEntry->NextDllDataEntry();
|
|
2056 |
}
|
|
2057 |
// Add the new node at the end of linked list
|
|
2058 |
aDllDataEntry->AddDllDataEntry(dataEntry);
|
|
2059 |
}
|
|
2060 |
}
|
|
2061 |
return ETrue;
|
|
2062 |
}
|