imgtools/romtools/rofsbuild/r_obey.cpp
changeset 607 378360dbbdba
parent 590 360bd6b35136
parent 606 30b30f9da0b7
child 609 f76e0f94b7ab
equal deleted inserted replaced
591:22486c9c7b15 607:378360dbbdba
    35 
    35 
    36 #include "h_utl.h"
    36 #include "h_utl.h"
    37 #include "r_obey.h"
    37 #include "r_obey.h"
    38 #include "r_coreimage.h"
    38 #include "r_coreimage.h"
    39 #include "patchdataprocessor.h"
    39 #include "patchdataprocessor.h"
    40 #include "filesysteminterface.h" 
    40 #include "fatimagegenerator.h" 
    41 #include "r_driveimage.h"
    41 #include "r_driveimage.h"
    42 
    42 
    43 extern TInt gCodePagingOverride;
    43 extern TInt gCodePagingOverride;
    44 extern TInt gDataPagingOverride;
    44 extern TInt gDataPagingOverride;
    45 extern ECompression gCompress;
    45 extern ECompression gCompress;
    52 static char* const NullString = "" ;
    52 static char* const NullString = "" ;
    53 const ObeyFileKeyword ObeyFileReader::iKeywords[] =
    53 const ObeyFileKeyword ObeyFileReader::iKeywords[] =
    54 {
    54 {
    55 	{_K("file"),		2,-2, EKeywordFile, "File to be copied into ROFS"},
    55 	{_K("file"),		2,-2, EKeywordFile, "File to be copied into ROFS"},
    56 	{_K("data"),		2,-2, EKeywordData, "same as file"},
    56 	{_K("data"),		2,-2, EKeywordData, "same as file"},
       
    57 	{_K("dir"),         2,1, EKeywordDir, "Directory to be created into FAT image"},
    57 
    58 
    58 	{_K("rofsname"),	1, 1, EKeywordRofsName, "output file for ROFS image"},
    59 	{_K("rofsname"),	1, 1, EKeywordRofsName, "output file for ROFS image"},
    59 	{_K("romsize"),		1, 1, EKeywordRomSize, "size of ROM image"}, 
    60 	{_K("romsize"),		1, 1, EKeywordRomSize, "size of ROM image"}, 
    60 	{_P("hide"),	    2, -1, EKeywordHide, "Exclude named file from ROM directory structure"},
    61 	{_P("hide"),	    2, -1, EKeywordHide, "Exclude named file from ROM directory structure"},
    61 	{_P("alias"),	    2, -2, EKeywordAlias, "Create alias for existing file in ROM directory structure"},
    62 	{_P("alias"),	    2, -2, EKeywordAlias, "Create alias for existing file in ROM directory structure"},
   410 
   411 
   411 
   412 
   412 const FileAttributeKeyword ObeyFileReader::iAttributeKeywords[] =
   413 const FileAttributeKeyword ObeyFileReader::iAttributeKeywords[] =
   413 {
   414 {
   414 	{"attrib",3			,0,1,EAttributeAtt, "File attributes in ROM file system"},
   415 	{"attrib",3			,0,1,EAttributeAtt, "File attributes in ROM file system"},
   415 	{"exattrib",3		,0,1,EAttributeAttExtra, "File extra attributes in ROM file system"},
   416 	{"exattrib",3		,0,1,EAttributeAttExtra, "File extra attributes in ROM file system"}, 
   416 	//	{_K("compress")		,1,1,EAttributeCompress, "Compress file"},
       
   417 	{"stack",3			,1,1,EAttributeStack, "?"},
   417 	{"stack",3			,1,1,EAttributeStack, "?"},
   418 	{"fixed",3			,1,0,EAttributeFixed, "Relocate to a fixed address space"},
   418 	{"fixed",3			,1,0,EAttributeFixed, "Relocate to a fixed address space"},
   419 	{"priority",3		,1,1,EAttributePriority, "Override process priority"},
   419 	{"priority",3		,1,1,EAttributePriority, "Override process priority"},
   420 	{_K("uid1")			,1,1,EAttributeUid1, "Override first UID"},
   420 	{_K("uid1")			,1,1,EAttributeUid1, "Override first UID"},
   421 	{_K("uid2")			,1,1,EAttributeUid2, "Override second UID"},
   421 	{_K("uid2")			,1,1,EAttributeUid2, "Override second UID"},
   495 iCheckSum(0),
   495 iCheckSum(0),
   496 iNumberOfFiles(0),
   496 iNumberOfFiles(0),
   497 iTime(0),
   497 iTime(0),
   498 iRootDirectory(0),
   498 iRootDirectory(0),
   499 iNumberOfDataFiles(0),
   499 iNumberOfDataFiles(0),
   500 iDriveFileName(0),
   500 iDriveFileName(0), 
   501 iDataSize(0),
   501 iDriveFileFormat(0), 
   502 iDriveFileFormat(0),
       
   503 iConfigurableFatAttributes(new ConfigurableFatAttributes),
       
   504 iReader(aReader), 
   502 iReader(aReader), 
   505 iMissingFiles(0), 
   503 iMissingFiles(0), 
   506 iLastExecutable(0),
   504 iLastExecutable(0),
   507 iFirstFile(0), 	
   505 iFirstFile(0), 	
   508 iCurrentFile(0),
   506 iCurrentFile(0),
   537 	if(iRomFileName){ 
   535 	if(iRomFileName){ 
   538 		delete [] iRomFileName;
   536 		delete [] iRomFileName;
   539 		iRomFileName = 0 ;
   537 		iRomFileName = 0 ;
   540 	}
   538 	}
   541 	if (iRootDirectory)
   539 	if (iRootDirectory)
   542 		iRootDirectory->Destroy();
   540 		iRootDirectory->Destroy(); 
   543 	if(iConfigurableFatAttributes)
       
   544 		delete iConfigurableFatAttributes;
       
   545 	if(iPatchData)
   541 	if(iPatchData)
   546 		delete iPatchData;
   542 		delete iPatchData;
   547 }
   543 }
   548 
   544 
   549 //
   545 //
   737 				break;
   733 				break;
   738 			}
   734 			}
   739 
   735 
   740 		case EKeywordHide:						
   736 		case EKeywordHide:						
   741 		case EKeywordFile:
   737 		case EKeywordFile:
       
   738 		case EKeywordDir:
   742 		case EKeywordData:
   739 		case EKeywordData:
   743 		case EKeywordFileCompress:
   740 		case EKeywordFileCompress:
   744 		case EKeywordFileUncompress:
   741 		case EKeywordFileUncompress:
   745 			if (!ProcessDriveFile(keyword))
   742 			if (!ProcessDriveFile(keyword))
   746 				return KErrGeneral;
   743 				return KErrGeneral;
   787 			if(*bigString == '\0')
   784 			if(*bigString == '\0')
   788 			{
   785 			{
   789 				Print(EWarning,"Not a valid Image Size. Default size is considered\n");		
   786 				Print(EWarning,"Not a valid Image Size. Default size is considered\n");		
   790 				break;
   787 				break;
   791 			}
   788 			}
   792 #ifdef __LINUX__
   789  
   793 			errno = 0;
   790 			Val(iConfigurableFatAttributes.iImageSize,bigString); 
   794 			iDataSize = strtoll(bigString,NULL,10);
       
   795 			if((iDataSize == LONG_MAX) || (iDataSize == LONG_MIN) ||(errno == ERANGE))
       
   796 			{
       
   797 				Print(EWarning,"Invalid Range. Default size is considered\n");		
       
   798 			}
       
   799 #else
       
   800 			iDataSize = _atoi64(bigString);
       
   801 #endif
       
   802 		}
   791 		}
   803 		break;
   792 		break;
   804 	case EKeywordDataImageVolume:
   793 	case EKeywordDataImageVolume:
   805 		{				
   794 		{				
   806 			// Get the volume label provided by using "volume" keyword.
   795 			// Get the volume label provided by using "volume" keyword.
   821 
   810 
   822 				// Remove the new line character from the end
   811 				// Remove the new line character from the end
   823 				position = volumeLabel.find_first_of("\r\n");
   812 				position = volumeLabel.find_first_of("\r\n");
   824 				if (position != string::npos)
   813 				if (position != string::npos)
   825 					volumeLabel = volumeLabel.substr(0,position);
   814 					volumeLabel = volumeLabel.substr(0,position);
   826 
   815 				size_t length = volumeLabel.length() ;
   827 				iConfigurableFatAttributes->iDriveVolumeLabel = volumeLabel.data() ;
   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;
   828 			}
   822 			}
   829 			else {
   823 			else {
   830 				Print(EWarning,"Value for Volume Label is not provided. Default value is considered.\n");
   824 				Print(EWarning,"Value for Volume Label is not provided. Default value is considered.\n");
   831 			}
   825 			}
   832 			break;
   826 			break;
   837 			TInt sectorSize = atoi(bigString);
   831 			TInt sectorSize = atoi(bigString);
   838 			if(sectorSize <= 0)	{
   832 			if(sectorSize <= 0)	{
   839 				Print(EWarning,"Invalid Sector Size value. Default value is considered.\n");
   833 				Print(EWarning,"Invalid Sector Size value. Default value is considered.\n");
   840 			}
   834 			}
   841 			else {
   835 			else {
   842 				iConfigurableFatAttributes->iDriveSectorSize = atoi(bigString);
   836 				iConfigurableFatAttributes.iDriveSectorSize = atoi(bigString);
   843 			}
   837 			}
   844 		}			
   838 		}			
   845 		break;
   839 		break;
   846 	case EKeywordDataImageNoOfFats:
   840 	case EKeywordDataImageNoOfFats:
   847 		{
   841 		{
   848 			const char* bigString = iReader.Word(1);
   842 			const char* bigString = iReader.Word(1);
   849 			TInt noOfFats = atoi(bigString);
   843 			TInt noOfFats = atoi(bigString);
   850 			if (noOfFats <=0)
   844 			if (noOfFats <=0)
   851 				Print(EWarning,"Invalid No of FATs specified. Default value is considered.\n");
   845 				Print(EWarning,"Invalid No of FATs specified. Default value is considered.\n");
   852 			else
   846 			else
   853 				iConfigurableFatAttributes->iDriveNoOfFATs = atoi(bigString);			
   847 				iConfigurableFatAttributes.iDriveNoOfFATs = atoi(bigString);			
   854 		}			
   848 		}			
   855 		break;			
   849 		break;			
   856 	default:
   850 	default:
   857 		// unexpected keyword iReader.Word(0), keep going.
   851 		// unexpected keyword iReader.Word(0), keep going.
   858 		break;
   852 		break;
   877 		Print(EError,"The name of the image file has not been supplied.\n");
   871 		Print(EError,"The name of the image file has not been supplied.\n");
   878 		Print(EError,"Use the keyword \"dataimagename\".\n");
   872 		Print(EError,"Use the keyword \"dataimagename\".\n");
   879 		retVal = EFalse;
   873 		retVal = EFalse;
   880 	}
   874 	}
   881 	// Check for '-'ve entered value.
   875 	// Check for '-'ve entered value.
   882 	if(iDataSize <= 0){
   876 	if(iConfigurableFatAttributes.iImageSize <= 0){
   883 		Print(EWarning,"Image Size should be positive. Default size is Considered.\n");
   877 		Print(EWarning,"Image Size should be positive. Default size is Considered.\n");
   884 	}
   878 	}
   885 
   879 
   886 	// File system format.
   880 	// File system format.
   887 	if(iDriveFileFormat==0) {
   881 	if(iDriveFileFormat==0) {
   889 		Print(EError,"Use the keyword \"dataimagefilesystem\".\n");
   883 		Print(EError,"Use the keyword \"dataimagefilesystem\".\n");
   890 		retVal = EFalse;
   884 		retVal = EFalse;
   891 	}
   885 	}
   892 
   886 
   893 	// Checking the validity of file system format.
   887 	// Checking the validity of file system format.
   894 	if(iDriveFileFormat){
   888 	if(iDriveFileFormat){		 
   895 		strupr((char *)iDriveFileFormat);
   889 		if(stricmp(iDriveFileFormat,"FAT16") && stricmp(iDriveFileFormat,"FAT32")) {
   896 		enum TFileSystem check = (TFileSystem)0;
       
   897 		if(!(CDriveImage::FormatTranslation(iDriveFileFormat,check))) {
       
   898 			Print(EError,"The name of the file system not supported : %s\n",iDriveFileFormat);
   890 			Print(EError,"The name of the file system not supported : %s\n",iDriveFileFormat);
   899 			retVal = EFalse;
   891 			retVal = EFalse;
   900 		}
   892 		}
   901 	}
   893 	}
   902 	if(retVal)
   894 	if(retVal)
   929 	TInt currentLine = iReader.CurrentLine();
   921 	TInt currentLine = iReader.CurrentLine();
   930 
   922 
   931 	switch (aKeyword)
   923 	switch (aKeyword)
   932 	{
   924 	{
   933 	case EKeywordData:
   925 	case EKeywordData:
       
   926 	case EKeywordDir:
   934 	case EKeywordHide:
   927 	case EKeywordHide:
   935 		isPeFile = EFalse;
   928 		isPeFile = EFalse;
   936 		break;
   929 		break;
   937 
   930 
   938 	case EKeywordFile:
   931 	case EKeywordFile:
   948 
   941 
   949 	default:
   942 	default:
   950 		return EFalse;
   943 		return EFalse;
   951 	}
   944 	}
   952 
   945 
   953 	if (aKeyword!=EKeywordHide) {
   946 	if (aKeyword!=EKeywordHide && aKeyword!=EKeywordDir) {
   954 		// check the PC file exists
   947 		// check the PC file exists
   955 		char* nname = NormaliseFileName(iReader.Word(1));		  
   948 		char* nname = NormaliseFileName(iReader.Word(1));		  
   956 		ifstream test(nname);
   949 		ifstream test(nname);
   957 		if(!test.is_open()){
   950 		if(!test.is_open()){
   958 			Print(EError,"Cannot open file %s for input.\n",iReader.Word(1));
   951 			Print(EError,"Cannot open file %s for input.\n",iReader.Word(1));
   963 		 
   956 		 
   964 	}
   957 	}
   965 	else
   958 	else
   966 		epocPathStart=1;   
   959 		epocPathStart=1;   
   967 
   960 
   968 	iNumberOfFiles++;
   961 	if(aKeyword != EKeywordDir)
       
   962 		iNumberOfFiles++;
   969 
   963 
   970 	TBool endOfName=EFalse;
   964 	TBool endOfName=EFalse;
   971 	const char *epocStartPtr= IsValidFilePath(iReader.Word(epocPathStart));
   965 	const char *epocStartPtr;
       
   966 	if(aKeyword != EKeywordDir)
       
   967 		epocStartPtr = IsValidFilePath(iReader.Word(epocPathStart));
       
   968 	else
       
   969 		epocStartPtr = IsValidDirPath(iReader.Word(epocPathStart));
   972 	char *epocEndPtr = const_cast<char*>(epocStartPtr);
   970 	char *epocEndPtr = const_cast<char*>(epocStartPtr);
   973 
   971 
   974 	if (epocStartPtr == NULL) {
   972 	if (epocStartPtr == NULL) {
   975 		Print(EError, "Invalid destination path on line %d\n",currentLine);
   973 		Print(EError, "Invalid destination path on line %d\n",currentLine);
   976 		return EFalse;
   974 		return EFalse;
   980 	TRomNode* subDir=0;
   978 	TRomNode* subDir=0;
   981 	TRomBuilderEntry *file=0;      
   979 	TRomBuilderEntry *file=0;      
   982 
   980 
   983 	while (!endOfName) {
   981 	while (!endOfName) {
   984 		endOfName = GetNextBitOfFileName(epocEndPtr);      
   982 		endOfName = GetNextBitOfFileName(epocEndPtr);      
   985 		if (endOfName) { // file		
   983 		if (endOfName && (aKeyword!=EKeywordDir)) { // file
   986 			TRomNode* alreadyExists=dir->FindInDirectory(epocStartPtr);
   984 			TRomNode* alreadyExists=dir->FindInDirectory(epocStartPtr);
   987 			if ((aKeyword != EKeywordHide) && alreadyExists) { // duplicate file		
   985 			if ((aKeyword != EKeywordHide) && alreadyExists) { // duplicate file		
   988 				if (gKeepGoing) {
   986 				if (gKeepGoing) {
   989 					Print(EWarning, "Duplicate file for %s on line %d, will be ignored\n",iReader.Word(1),iReader.CurrentLine());
   987 					Print(EWarning, "Duplicate file for %s on line %d, will be ignored\n",iReader.Word(1),iReader.CurrentLine());
   990 					iNumberOfFiles--;
   988 					iNumberOfFiles--;
  1032 
  1030 
  1033 			dir->AddFile(node);	// to drive directory structure.
  1031 			dir->AddFile(node);	// to drive directory structure.
  1034 		}		 
  1032 		}		 
  1035 		else {
  1033 		else {
  1036 			// directory
  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 
  1037 			subDir = dir->FindInDirectory(epocStartPtr);      
  1039 			subDir = dir->FindInDirectory(epocStartPtr);      
  1038 			if (!subDir){ // sub directory does not exist			
  1040 			if (!subDir){ // sub directory does not exist			
  1039 				if(aKeyword==EKeywordHide) {
  1041 				if(aKeyword==EKeywordHide) {
  1040 					Print(EWarning, "Hiding non-existent file %s on line %d\n",
  1042 					Print(EWarning, "Hiding non-existent file %s on line %d\n",
  1041 						iReader.Word(1),iReader.CurrentLine());
  1043 						iReader.Word(1),iReader.CurrentLine());
  1681 	while(*p) {			
  1683 	while(*p) {			
  1682 		if (*p == '/' || *p == '\\') {
  1684 		if (*p == '/' || *p == '\\') {
  1683 			if (len == 0)
  1685 			if (len == 0)
  1684 				return NULL;
  1686 				return NULL;
  1685 			len=0;
  1687 			len=0;
       
  1688 			p++;
       
  1689 			continue;
       
  1690 
  1686 		}
  1691 		}
  1687 		len++;
  1692 		len++;
  1688 		p++;
  1693 		p++;
  1689 	}
  1694 	}
  1690 	return (len ? aPath : NULL);
  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;
  1691 }
  1714 }
  1692 
  1715 
  1693 //
  1716 //
  1694 // Move the end pointer past the next directory separator, replacing it with 0
  1717 // Move the end pointer past the next directory separator, replacing it with 0
  1695 //
  1718 //