19 |
19 |
20 |
20 |
21 #include <stdlib.h> |
21 #include <stdlib.h> |
22 #include <string> |
22 #include <string> |
23 |
23 |
24 #ifndef __LINUX__ |
24 #ifdef __LINUX__ |
|
25 |
|
26 #include <dirent.h> |
|
27 #ifndef MKDIR |
|
28 #define MKDIR(a) mkdir(a,0777) |
|
29 #endif |
|
30 #else |
|
31 #ifdef _STLP_INTERNAL_WINDOWS_H |
|
32 #define __INTERLOCKED_DECLARED |
|
33 #endif |
25 #include <windows.h> |
34 #include <windows.h> |
26 #include <direct.h> |
35 #include <direct.h> |
27 #else |
36 #ifndef MKDIR |
28 #include <dirent.h> |
37 #define MKDIR mkdir |
|
38 #endif |
29 #endif |
39 #endif |
30 |
40 #include <sys/stat.h> |
31 #ifdef __TOOLS2__ |
41 #include <sys/types.h> |
32 #include <sys/stat.h> |
42 using namespace std; |
33 #include <sys/types.h> |
43 |
34 using namespace std; |
|
35 #endif |
|
36 |
44 |
37 #include <f32file.h> |
45 #include <f32file.h> |
38 #include "h_utl.h" |
46 #include "h_utl.h" |
39 #include "r_obey.h" |
47 #include "r_obey.h" |
40 #include "r_romnode.h" |
48 #include "r_romnode.h" |
41 #include "r_rofs.h" |
49 #include "r_rofs.h" |
42 #include "r_driveimage.h" |
50 #include "r_driveimage.h" |
43 |
51 |
44 extern TBool gFastCompress; |
|
45 |
52 |
46 // File format supported by Rofsbuild |
53 // File format supported by Rofsbuild |
47 DriveFileFormatSupported CDriveImage::iFormatType[] = |
54 DriveFileFormatSupported CDriveImage::iFormatType[] = |
48 { |
55 { |
49 {"FAT16",EFAT16}, |
56 {"FAT16",EFAT16}, |
56 File format conversion from char* to coresponding enum value. |
63 File format conversion from char* to coresponding enum value. |
57 |
64 |
58 @param aUserFileFormat - pointer to user entered file format. |
65 @param aUserFileFormat - pointer to user entered file format. |
59 @param aDriveFileFormat - Reference to actual variable. |
66 @param aDriveFileFormat - Reference to actual variable. |
60 */ |
67 */ |
61 TBool CDriveImage::FormatTranslation(TText* aUserFileFormat,enum TFileSystem& aDriveFileFormat) |
68 TBool CDriveImage::FormatTranslation(const char* aUserFileFormat,enum TFileSystem& aDriveFileFormat) |
62 { |
69 { |
63 struct DriveFileFormatSupported* strPointer = iFormatType; |
70 struct DriveFileFormatSupported* strPointer = iFormatType; |
64 for( ; (strPointer->iDriveFileFormat) != '\0' ; ++strPointer ) |
71 for( ; (strPointer->iDriveFileFormat) != '\0' ; ++strPointer ) |
65 { |
72 { |
66 if(!strcmp((char*)aUserFileFormat,strPointer->iDriveFileFormat)) |
73 if(!strcmp(aUserFileFormat,strPointer->iDriveFileFormat)) |
67 { |
74 { |
68 aDriveFileFormat = strPointer->iFileSystem; |
75 aDriveFileFormat = strPointer->iFileSystem; |
69 return ETrue; |
76 return ETrue; |
70 } |
77 } |
71 } |
78 } |
77 Constructor: CDriveImage class |
84 Constructor: CDriveImage class |
78 |
85 |
79 @param aObey - pointer to Drive obey file. |
86 @param aObey - pointer to Drive obey file. |
80 */ |
87 */ |
81 CDriveImage::CDriveImage(CObeyFile *aObey) |
88 CDriveImage::CDriveImage(CObeyFile *aObey) |
82 : iObey( aObey ),iParentInnerList(0),iListReference(0),iTempDirName(NULL), iData(0) |
89 : iObey( aObey ),iParentDirEntry(0),iListReference(0),iTempDirName(NULL), iData(0) |
83 { |
90 { |
84 } |
91 } |
85 |
92 |
86 |
93 |
87 /** |
94 /** |
124 |
131 |
125 // Create the temp folder. |
132 // Create the temp folder. |
126 // Check for folder exist, if exist it loops until dir created or loop exit. |
133 // Check for folder exist, if exist it loops until dir created or loop exit. |
127 while(dirCheck) |
134 while(dirCheck) |
128 { |
135 { |
129 sprintf(iTempDirName,"%s%05d","temp",dirCheck); |
136 sprintf(iTempDirName,"%s%05d","temp",dirCheck); |
130 #ifdef __LINUX__ |
137 retStatus = MKDIR(iTempDirName); |
131 retStatus = mkdir((char*)iTempDirName,0777); |
|
132 #else |
|
133 retStatus = mkdir((char*)iTempDirName); |
|
134 #endif |
|
135 if(!retStatus) |
138 if(!retStatus) |
136 break; |
139 break; |
137 |
140 |
138 ++dirCheck; |
141 ++dirCheck; |
139 } |
142 } |
174 |
177 |
175 @param alogfile - Logfile name required for file system module. |
178 @param alogfile - Logfile name required for file system module. |
176 @return Status(r) - returns the status of file system module. |
179 @return Status(r) - returns the status of file system module. |
177 'KErrGeneral' - Unable to done the above operations properly. |
180 'KErrGeneral' - Unable to done the above operations properly. |
178 */ |
181 */ |
179 TInt CDriveImage::CreateImage(TText* alogfile) |
182 TInt CDriveImage::CreateImage(const char* alogfile) |
180 { |
183 { |
181 |
184 |
182 TInt retStatus = 0; |
185 TInt retStatus = 0; |
183 retStatus = CreateList(); |
186 retStatus = CreateList(); |
184 |
187 |
186 return KErrGeneral; |
189 return KErrGeneral; |
187 |
190 |
188 if(retStatus != KErrNone) |
191 if(retStatus != KErrNone) |
189 { |
192 { |
190 Print(EError,"Insufficent Memory/Not able to generate the Structure\n"); |
193 Print(EError,"Insufficent Memory/Not able to generate the Structure\n"); |
191 if(DeleteTempFolder((char*)iTempDirName) != KErrNone ) |
194 if(DeleteTempFolder(iTempDirName) != KErrNone ) |
192 { |
195 { |
193 Print(EWarning,"Not able to delete the temp folder : %s",iTempDirName); |
196 Print(EWarning,"Not able to delete the temp folder : %s",iTempDirName); |
194 } |
197 } |
195 return KErrGeneral; |
198 return KErrGeneral; |
196 } |
199 } |
214 (char*)iObey->iDriveFileName, |
217 (char*)iObey->iDriveFileName, |
215 (char*)alogfile, |
218 (char*)alogfile, |
216 iObey->iConfigurableFatAttributes); ; |
219 iObey->iConfigurableFatAttributes); ; |
217 |
220 |
218 //delete the temp folder. |
221 //delete the temp folder. |
219 if(DeleteTempFolder((char*)iTempDirName) != KErrNone ) |
222 if(DeleteTempFolder(iTempDirName) != KErrNone ) |
220 { |
223 { |
221 cout << "Warning: Not able to delete the temp folder : " << iTempDirName << "\n" ; |
224 cout << "Warning: Not able to delete the temp folder : " << iTempDirName << "\n" ; |
222 } |
225 } |
223 |
226 |
224 return retStatus; |
227 return retStatus; |
232 @param aTempDirName - Temporory folder name to be deleted. |
235 @param aTempDirName - Temporory folder name to be deleted. |
233 @return Status(r) - returns the status. |
236 @return Status(r) - returns the status. |
234 'KErrGeneral' - Unable to done the above operations properly. |
237 'KErrGeneral' - Unable to done the above operations properly. |
235 'KErrNone' - successfully deleted the folder. |
238 'KErrNone' - successfully deleted the folder. |
236 */ |
239 */ |
237 TInt CDriveImage::DeleteTempFolder(char* aTempDirName) |
240 TInt CDriveImage::DeleteTempFolder(const char* aTempDirName) |
238 { |
241 { |
239 |
242 |
240 TInt fileDeleted = 1; |
243 TInt fileDeleted = 1; |
241 std::string dirPath(aTempDirName); |
244 string dirPath(aTempDirName); |
242 std::string fileName(aTempDirName); |
245 string fileName(aTempDirName); |
243 |
246 |
244 #ifdef __LINUX__ |
247 #ifdef __LINUX__ |
245 |
248 |
246 // Open directory |
249 // Open directory |
247 DIR *dirHandler = opendir(aTempDirName); |
250 DIR *dirHandler = opendir(aTempDirName); |
252 |
255 |
253 dirPath.append("/"); |
256 dirPath.append("/"); |
254 fileName.append("/"); |
257 fileName.append("/"); |
255 |
258 |
256 // Go through each entry |
259 // Go through each entry |
257 while(dirEntry = readdir(dirHandler)) |
260 while((dirEntry = readdir(dirHandler))) |
258 { |
261 { |
259 if(dirEntry->d_type != DT_DIR) |
262 if(dirEntry->d_type != DT_DIR) |
260 { |
263 { |
261 fileName.append((char*)dirEntry->d_name); |
264 fileName.append((char*)dirEntry->d_name); |
262 remove(fileName.c_str()); |
265 remove(fileName.c_str()); |
361 @return r - returns 'KErrNoMemory' if memory is not allocated or 'KErrNone' |
364 @return r - returns 'KErrNoMemory' if memory is not allocated or 'KErrNone' |
362 */ |
365 */ |
363 TInt CDriveImage::CreateDirOrFileEntry(TRomNode* atempnode,enum KNodeType aType) |
366 TInt CDriveImage::CreateDirOrFileEntry(TRomNode* atempnode,enum KNodeType aType) |
364 { |
367 { |
365 |
368 |
366 CDirectory* iDirectory = new CDirectory((char*)atempnode->iName); |
369 CDirectory* parentDirectory = NULL ; |
|
370 if(KNodeTypeChild == aType) |
|
371 parentDirectory = iParentDirEntry; |
|
372 else if(KNodeTypeSibling == aType) |
|
373 parentDirectory = (CDirectory*)(iNodeAddStore[iListReference-1]); |
|
374 |
|
375 CDirectory* iDirectory = new CDirectory(atempnode->iName,parentDirectory); |
367 if(!iDirectory) |
376 if(!iDirectory) |
368 return KErrNoMemory; |
377 return KErrNoMemory; |
369 |
378 |
370 char attrib = 0 ; |
379 char attrib = 0 ; |
371 if(atempnode->iAtt & KEntryAttReadOnly) |
380 if(atempnode->iAtt & KEntryAttReadOnly) |
401 switch(aType) |
410 switch(aType) |
402 { |
411 { |
403 case KNodeTypeRoot: |
412 case KNodeTypeRoot: |
404 iDirectory->SetEntryAttribute(EAttrVolumeId); |
413 iDirectory->SetEntryAttribute(EAttrVolumeId); |
405 iNodeList.push_back(iDirectory); |
414 iNodeList.push_back(iDirectory); |
406 iParentInnerList = iDirectory->GetEntryList(); |
415 iParentDirEntry = iDirectory; |
407 break; |
416 break; |
408 |
417 |
409 case KNodeTypeChild: |
418 case KNodeTypeChild: |
410 iNodeAddStore.push_back((void*)iParentInnerList); |
419 iNodeAddStore.push_back((void*)iParentDirEntry); |
411 ++iListReference; |
420 ++iListReference; |
412 iParentInnerList->push_back(iDirectory); |
421 parentDirectory->InsertIntoEntryList(iDirectory); |
413 iParentInnerList = iDirectory->GetEntryList(); |
422 iParentDirEntry = iDirectory ; |
414 break; |
423 break; |
415 |
424 |
416 case KNodeTypeSibling: |
425 case KNodeTypeSibling: |
417 iParentInnerList =(std::list<CDirectory*> *)(iNodeAddStore[iListReference-1]); |
426 parentDirectory->InsertIntoEntryList(iDirectory); |
418 iParentInnerList->push_back(iDirectory); |
427 iParentDirEntry = iDirectory ; |
419 iParentInnerList = iDirectory->GetEntryList(); |
|
420 break; |
428 break; |
421 |
429 |
422 default: |
430 default: |
423 break; |
431 break; |
424 } |
432 } |
433 Hidden file node is not placed in temp folder. |
441 Hidden file node is not placed in temp folder. |
434 |
442 |
435 @return r - returns 'KErrNoMemory/KErrGeneral' if fails to update the options or memory |
443 @return r - returns 'KErrNoMemory/KErrGeneral' if fails to update the options or memory |
436 not allocated or else 'KErrNone' for Succesfully operation. |
444 not allocated or else 'KErrNone' for Succesfully operation. |
437 */ |
445 */ |
438 TInt CDriveImage::ConstructOptions() |
446 TInt CDriveImage::ConstructOptions() { |
439 { |
|
440 |
447 |
441 TInt32 len = 0; |
448 TInt32 len = 0; |
442 TRomNode* node = TRomNode::FirstNode(); |
449 TRomNode* node = TRomNode::FirstNode(); |
443 CBytePair bpe(gFastCompress); |
450 CBytePair bpe; |
444 |
451 |
445 while(node) |
452 while(node) |
446 { |
453 { |
447 // Don't do anything for hidden files. |
454 // Don't do anything for hidden files. |
448 if(node->IsFile() && (!node->iHidden)) |
455 if(node->IsFile() && (!node->iHidden)) |
449 { |
456 { |
450 |
457 |
451 TInt32 size=HFile::GetLength((TText*)node->iEntry->iFileName); |
458 TInt32 size=HFile::GetLength(node->iEntry->iFileName); |
452 if(size <= 0) |
459 if(size <= 0) |
453 { |
460 { |
454 Print(EWarning,"File %s does not exist or is 0 bytes in length.\n",node->iEntry->iFileName); |
461 Print(EWarning,"File %s does not exist or is 0 bytes in length.\n",node->iEntry->iFileName); |
455 } |
462 } |
456 node->iSize = size; |
463 node->iSize = size; |
457 if(node->iEntry->iExecutable && (size > 0)) |
464 if(node->iEntry->iExecutable && (size > 0)) |
458 { |
465 { |
459 |
466 |
460 if((node->iFileUpdate) || (node->iOverride)) |
467 if((node->iFileUpdate) || (node->iOverride)) |
461 { |
468 { |
462 iData = new char[(size * 2)]; |
469 size_t allocSize = size << 1 ; |
|
470 iData = new char[allocSize]; |
463 if(!iData) |
471 if(!iData) |
464 return KErrNoMemory; |
472 return KErrNoMemory; |
465 |
473 |
466 HMem::Set(iData, 0xff, (size * 2)); |
474 HMem::Set(iData, 0xff, allocSize); |
467 TUint8* aData = (TUint8*)iData; |
475 TUint8* aData = (TUint8*)iData; |
468 len = node->PlaceFile(aData,0,(size * 2),&bpe); |
476 len = node->PlaceFile(aData,0,allocSize,&bpe); |
469 if(len < KErrNone) |
477 if(len < KErrNone) |
470 { |
478 { |
471 delete[] iData; |
479 delete[] iData; |
472 iData = 0; |
480 iData = 0; |
473 return KErrGeneral; |
481 return KErrGeneral; |
504 TInt CDriveImage::PlaceFileTemporary(const TInt afileSize,TRomNode* acurrentNode) |
512 TInt CDriveImage::PlaceFileTemporary(const TInt afileSize,TRomNode* acurrentNode) |
505 { |
513 { |
506 |
514 |
507 TInt randomValue = 0; |
515 TInt randomValue = 0; |
508 char randomString[KMaxGenBuffer] = "\0"; |
516 char randomString[KMaxGenBuffer] = "\0"; |
509 unsigned char* fileSourcePath = acurrentNode->iEntry->iName; |
517 char* fileSourcePath = acurrentNode->iEntry->iName; |
510 std::string newFileName; |
518 string newFileName; |
511 |
519 |
512 do |
520 do |
513 { |
521 { |
514 newFileName.append(iTempDirName); |
522 newFileName.append(iTempDirName); |
515 newFileName.append("/"); |
523 newFileName.append("/"); |
516 |
524 |
517 if(!randomValue) |
525 if(!randomValue) |
518 { |
526 { |
519 newFileName.append((char*)fileSourcePath); |
527 newFileName.append(fileSourcePath); |
520 } |
528 } |
521 else |
529 else |
522 { |
530 { |
523 newFileName.append(randomString); |
531 newFileName.append(randomString); |
524 newFileName.append((char*)fileSourcePath); |
532 newFileName.append(fileSourcePath); |
525 } |
533 } |
526 |
534 |
527 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
535 |
528 ifstream test(newFileName.c_str()); |
536 ifstream test(newFileName.c_str()); |
529 #else //!__MSVCDOTNET__ |
|
530 ifstream test(newFileName.c_str(), ios::nocreate); |
|
531 #endif //__MSVCDOTNET__ |
|
532 |
|
533 if (!test) |
537 if (!test) |
534 { |
538 { |
535 test.close(); |
539 test.close(); |
536 ofstream driveFile((char *)newFileName.c_str(),ios::binary); |
540 ofstream driveFile(newFileName.c_str(),ios_base::binary); |
537 if (!driveFile) |
541 if (!driveFile) |
538 { |
542 { |
539 Print(EError,"Cannot open file %s for output\n",newFileName.c_str()); |
543 Print(EError,"Cannot open file %s for output\n",newFileName.c_str()); |
540 return KErrGeneral; |
544 return KErrGeneral; |
541 } |
545 } |
543 driveFile.write(iData,afileSize); |
547 driveFile.write(iData,afileSize); |
544 driveFile.close(); |
548 driveFile.close(); |
545 |
549 |
546 // Update the new source path. |
550 // Update the new source path. |
547 delete[] acurrentNode->iEntry->iFileName; |
551 delete[] acurrentNode->iEntry->iFileName; |
548 acurrentNode->iEntry->iFileName = new char[ strlen(newFileName.c_str()) + 1 ]; |
552 acurrentNode->iEntry->iFileName = new char[ newFileName.length() + 1 ]; |
549 if(!acurrentNode->iEntry->iFileName) |
553 if(!acurrentNode->iEntry->iFileName) |
550 return KErrNoMemory; |
554 return KErrNoMemory; |
551 |
555 |
552 strcpy(acurrentNode->iEntry->iFileName,newFileName.c_str()); |
556 memcpy(acurrentNode->iEntry->iFileName,newFileName.c_str(),newFileName.length()); |
|
557 acurrentNode->iEntry->iFileName[newFileName.length()] = 0; |
553 break; |
558 break; |
554 } |
559 } |
555 |
560 |
556 test.close(); |
561 test.close(); |
557 newFileName.erase(); |
562 newFileName.erase(); |