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