imgtools/romtools/rofsbuild/fsnode.cpp
author y4jin
Thu, 18 Nov 2010 13:43:06 +0800
changeset 704 0f8b90f18a21
parent 675 02e65118a746
permissions -rw-r--r--
Fix the illegal word scanned by sfchecksource tools
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
605
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
     1
/*
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
     3
* All rights reserved.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
     4
* This component and the accompanying materials are made available
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
     6
* which accompanies this distribution, and is available
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
     8
*
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
     9
* Initial Contributors:
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    11
*
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    12
* Contributors:
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    13
*
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    14
* Description: 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    15
*
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    16
*/
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    17
#include "fsnode.h"
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    18
#include "fatdefines.h"
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    19
#include "utf16string.h"
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    20
#include <stdio.h> 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    21
#include <iostream>
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    22
#include <iomanip>
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    23
#include <stdio.h> 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    24
#include <stdlib.h> 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    25
 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    26
#include <ctype.h> 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    27
 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    28
using namespace std;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    29
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    30
const TUint KBytesPerEntry = 13 ;
617
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    31
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    32
static inline bool is_a_long_file_name_char(unsigned char ch){
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    33
	return ( ch >= ' ' && ch != '"' && ch != '*' && ch != ':' && ch != '<' \
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    34
		&& ch != '>' && ch != '?' && ch != '|' && ch != 127) ; 
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    35
	
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    36
}
605
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    37
//
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    38
TFSNode::TFSNode(TFSNode* aParent, const char* aFileName, TUint8 aAttrs, const char* aPCSideName)  :
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    39
iParent(aParent),iFirstChild(0),iSibling(0),iAttrs(aAttrs), iPCSideName(0), iWideName(0){
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    40
	
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    41
  // According to the FAT specification, short name should be inited with empty string (' ' string)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    42
	memset(iShortName,0x20,11);  
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    43
	iShortName[11] = 0 ; 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    44
	if(aFileName) {
617
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    45
		const unsigned char* ptr = reinterpret_cast<const unsigned char*>(aFileName);
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    46
		bool allSpaces = true ;
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    47
		while(*ptr){
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    48
			if( !is_a_long_file_name_char(*ptr))
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    49
				throw "Illegal filename or dir name! \n";		
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    50
			if(*ptr != ' ')
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    51
				allSpaces = false ;		
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    52
			ptr++ ;
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    53
		}
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    54
		if(allSpaces)
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    55
			throw "Illegal filename or dir name(all spaces)!\n";
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    56
		iFileName = strdup(aFileName); 
605
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    57
		GenerateBasicName() ;	
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    58
	} 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    59
	if(aPCSideName) {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    60
		iPCSideName = strdup(aPCSideName);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    61
	}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    62
	iFATEntry = 0;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    63
	iCrtTimeTenth  = 0;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    64
	iCrtTime.iImageTime = 0 ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    65
	iCrtDate.iImageDate = 0 ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    66
	iLstAccDate.iImageDate = 0  ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    67
	iWrtTime.iImageTime = 0 ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    68
	iWrtDate.iImageDate = 0  ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    69
	iFileSize = 0;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    70
	if(!iParent) return ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    71
	
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    72
	if(!iParent->iFirstChild)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    73
	    iParent->iFirstChild = this ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    74
    else {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    75
        TFSNode* sibling = iParent->iFirstChild;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    76
        while(sibling->iSibling)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    77
            sibling = sibling->iSibling ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    78
        sibling->iSibling = this ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    79
    } 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    80
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    81
}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    82
TFSNode::~TFSNode(){
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    83
	if(iFirstChild)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    84
		delete iFirstChild ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    85
	if(iSibling)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    86
		delete iSibling ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    87
	if(iFileName)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    88
		free(iFileName) ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    89
	if(iWideName)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    90
		delete iWideName;
617
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    91
	if(iPCSideName)
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    92
		free(iPCSideName);
605
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    93
}
617
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
    94
 
605
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    95
/** GenerateBasicName : Generate the short name according to long name 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    96
	* 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    97
	* algorithm :
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    98
	* 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
    99
	* 1.	The UNICODE name passed to the file system is converted to upper case.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   100
	* 2.	The upper cased UNICODE name is converted to OEM.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   101
	*     if (the uppercased UNICODE glyph does not exist as an OEM glyph in the OEM code page)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   102
	*				or	(the OEM glyph is invalid in an 8.3 name)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   103
	*			{
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   104
	*				Replace the glyph to an OEM '_' (underscore) character.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   105
	*				Set a "lossy conversion" flag.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   106
	*			}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   107
	* 3.	Strip all leading and embedded spaces from the long name.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   108
	* 4.	Strip all leading periods from the long name.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   109
	* 5.	While		(not at end of the long name)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   110
	*					and	(char is not a period)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   111
	*					and	(total chars copied < 8)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   112
	*			{
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   113
	*				Copy characters into primary portion of the basis name
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   114
	*			}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   115
	*	6.	Insert a dot at the end of the primary components of the basis-name 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   116
	*     if the basis name has an extension after the last period in the name.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   117
	*
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   118
	* 7.	Scan for the last embedded period in the long name.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   119
	*     If	(the last embedded period was found)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   120
	*     {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   121
	*     	While		(not at end of the long name) and	(total chars copied < 3)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   122
	*     	{
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   123
	*     		Copy characters into extension portion of the basis name
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   124
	*     	}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   125
	*     }
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   126
  *
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   127
  */
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   128
void TFSNode::GenerateBasicName() { 
617
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
   129
	const char* filename =  iFileName ;	 
605
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   130
	TUint length = strlen(filename);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   131
	if(0 == length)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   132
	    return ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   133
	if(0 == strcmp(filename,".")){
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   134
        iShortName[0] = '.' ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   135
        return ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   136
	}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   137
	if(0 == strcmp(filename,"..")){
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   138
        iShortName[0] = '.' ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   139
        iShortName[1] = '.' ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   140
        return ;
617
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
   141
	} 
605
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   142
	iWideName = new UTF16String(filename,length); // The unicode string
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   143
	char base[10];
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   144
	const char* ext = filename + length;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   145
	
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   146
	//Strip all leading periods and spaces from the long name.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   147
	while(*filename == '.' || *filename == ' ' || *filename == '\t') {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   148
		filename ++ ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   149
		length -- ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   150
	}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   151
	//find the extension
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   152
	while(ext > filename && *ext != '.')
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   153
		ext -- ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   154
	if(ext == filename){
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   155
		ext = "" ; 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   156
	}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   157
	else {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   158
		length = ext - filename;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   159
		ext ++ ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   160
	} 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   161
	bool lossyConv = false ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   162
	TUint bl = 0;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   163
	for(TUint i = 0 ; i < length ; i++) {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   164
		if(filename[i] >= 'a' && filename[i] <= 'z')
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   165
			base[bl++] = filename[i] + 'A' - 'a';
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   166
		else if(filename[i] >= 'A' && filename[i] <= 'Z')
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   167
			base[bl++] = filename[i];
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   168
		else if(filename[i] == '$' || filename[i] == '%' ||
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   169
			filename[i] == '-' || filename[i] == '_' || filename[i] == '@' ||
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   170
			filename[i] == '~' || filename[i] == '`' || filename[i] == '!' ||
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   171
			filename[i] == '(' || filename[i] == ')' || filename[i] == '{' ||
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   172
			filename[i] == '}' || filename[i] == '^' || filename[i] == '#' ||
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   173
			filename[i] == '&' ||filename[i] == '\'')
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   174
			base[bl++] = filename[i];
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   175
		else if(filename[i] != ' ' && filename[i] != '.'){
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   176
			base[bl++] = '_';
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   177
			lossyConv = true ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   178
		}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   179
		if(bl > 8){
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   180
			bl -- ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   181
			lossyConv = true ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   182
			break ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   183
		}		
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   184
	}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   185
	if(lossyConv){
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   186
		if(bl > 6) bl = 6 ;		
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   187
		iShortName[bl] = '~';
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   188
		iShortName[bl+1] = '1';		
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   189
	}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   190
	memcpy(iShortName,base,bl);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   191
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   192
	//Copy the extension part.	
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   193
	TUint ei = 8;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   194
	for(TUint e = 0; ei < 11 && ext[e] != 0 ; e++){
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   195
		if(ext[e] >= 'a' && ext[e] <= 'z')
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   196
			iShortName[ei++] = ext[e] + 'A' - 'a';
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   197
		else if(ext[e] >= 'A' && ext[e] <= 'Z')
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   198
			iShortName[ei++] = ext[e] ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   199
		else if(ext[e] == '$' || ext[e] == '%' || ext[e] == '-' || ext[e] == '_' || 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   200
			ext[e] == '@' || ext[e] == '~' || ext[e] == '`' || ext[e] == '!' || 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   201
			ext[e] == '(' || ext[e] == ')' || ext[e] == '{' || ext[e] == '}' || 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   202
			ext[e] == '^' || ext[e] == '#' || ext[e] == '&' ||ext[e] == '\'')
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   203
			iShortName[ei++] = ext[e] ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   204
	}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   205
 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   206
	if(iParent) 
617
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
   207
		iParent->MakeUniqueShortName(iShortName,bl); 
605
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   208
}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   209
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   210
#ifdef _DEBUG
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   211
void TFSNode::PrintTree(int nTab) {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   212
	for( int i = 0 ; i < nTab ; i++ )
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   213
		cout << " " ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   214
	cout << (iFileName ? iFileName : "") << " [" << hex << setw(2) << setfill('0') << (unsigned short)iAttrs << "] \n" ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   215
	if(iFirstChild)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   216
		iFirstChild->PrintTree(nTab + 2);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   217
	if(iSibling)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   218
		iSibling->PrintTree(nTab);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   219
}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   220
#endif
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   221
bool TFSNode::IsDirectory() const {
617
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
   222
	return (0 != (iAttrs & ATTR_DIRECTORY) || ATTR_VOLUME_ID == iAttrs) ;
605
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   223
}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   224
int TFSNode::GetWideNameLength() const {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   225
	if(!iWideName)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   226
		return 0 ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   227
	return iWideName->length() ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   228
}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   229
TUint TFSNode::GetSize() const {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   230
	
617
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
   231
	if( !IsDirectory())
605
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   232
		return iFileSize ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   233
	TUint retVal = sizeof(TShortDirEntry) ; // the tailed entry 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   234
	if(iParent)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   235
		retVal += sizeof(TShortDirEntry) * 2 ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   236
	TFSNode* child = iFirstChild ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   237
	while(child) {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   238
		TUint longNameEntries =  (child->GetWideNameLength() + KBytesPerEntry) / KBytesPerEntry  ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   239
		retVal += longNameEntries * sizeof(TLongDirEntry) ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   240
		retVal += sizeof(TShortDirEntry);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   241
		child = child->iSibling ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   242
	}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   243
	return retVal ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   244
}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   245
 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   246
void TFSNode::Init(time_t aCreateTime, time_t aAccessTime, time_t aWriteTime, TUint aSize ) {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   247
	
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   248
	struct tm* temp = localtime(&aCreateTime);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   249
	iCrtDate.iCurrentDate.Day = temp->tm_mday;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   250
	iCrtDate.iCurrentDate.Month = temp->tm_mon+1; //As per FAT spec
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   251
	iCrtDate.iCurrentDate.Year = temp->tm_year - 80;//As per FAT spec
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   252
	iCrtTime.iCurrentTime.Hour = temp->tm_hour;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   253
	iCrtTime.iCurrentTime.Minute = temp->tm_min;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   254
	iCrtTime.iCurrentTime.Seconds = temp->tm_sec / 2;//As per FAT spec
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   255
	iCrtTimeTenth = 0;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   256
	
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   257
	temp = localtime(&aAccessTime);	
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   258
	iLstAccDate.iCurrentDate.Day = temp->tm_mday;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   259
	iLstAccDate.iCurrentDate.Month = temp->tm_mon+1; //As per FAT spec
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   260
	iLstAccDate.iCurrentDate.Year = temp->tm_year - 80;//As per FAT spec
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   261
	
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   262
	temp = localtime(&aWriteTime);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   263
	iWrtDate.iCurrentDate.Day = temp->tm_mday;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   264
	iWrtDate.iCurrentDate.Month = temp->tm_mon+1; //As per FAT spec
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   265
	iWrtDate.iCurrentDate.Year = temp->tm_year - 80;//As per FAT spec
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   266
	iWrtTime.iCurrentTime.Hour = temp->tm_hour;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   267
	iWrtTime.iCurrentTime.Minute = temp->tm_min;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   268
	iWrtTime.iCurrentTime.Seconds = temp->tm_sec / 2;//As per FAT spec 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   269
	
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   270
	iFileSize = aSize ; 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   271
}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   272
/** WriteDirEntries : Write FAT information for this node to a cluster buffer
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   273
	* aStartIndex : [in],the beginning index of the outputed cluster  
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   274
  * aClusterData : [in,out] the cluster buffer
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   275
  * 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   276
  * notice, aClusterData is only required if node is a directory node.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   277
  * for a file node, no data will be written out.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   278
  * in this case, only corresponding cluster index information is updated.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   279
  */ 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   280
void TFSNode::WriteDirEntries(TUint aStartIndex,TUint8* aClusterData){
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   281
	if(iFATEntry){
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   282
		*((TUint16*)iFATEntry->DIR_FstClusHI) = (aStartIndex >> 16) ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   283
		*((TUint16*)iFATEntry->DIR_FstClusLO) = (aStartIndex & 0xFFFF) ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   284
	}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   285
	 
617
3a747a240983 ROM Tools 12.2.0.4
Zheng Shen <zheng.shen@nokia.com>
parents: 605
diff changeset
   286
	if(IsDirectory()) { // Directory , write dir entries ; 
605
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   287
		TShortDirEntry* entry = reinterpret_cast<TShortDirEntry*>(aClusterData);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   288
		if(iParent != NULL) {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   289
			//Make 
675
02e65118a746 Fix the illegal word scanned by sfchecksource tools
y4jin
parents: 647
diff changeset
   290
			GetShortEntry(entry); 			
605
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   291
			memcpy(entry->DIR_Name,".            ",sizeof(entry->DIR_Name));
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   292
			entry ++ ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   293
			iParent->GetShortEntry(entry);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   294
			memcpy(entry->DIR_Name,"..           ",sizeof(entry->DIR_Name));
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   295
			entry ++ ; 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   296
		}		 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   297
		TFSNode* child = iFirstChild ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   298
		while(child){			
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   299
			int items = child->GetLongEntries(reinterpret_cast<TLongDirEntry*>(entry));
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   300
			entry += items ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   301
			child->GetShortEntry(entry);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   302
			child->iFATEntry = entry ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   303
			entry ++ ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   304
			child = child->iSibling ; 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   305
			
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   306
		}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   307
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   308
	}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   309
}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   310
/** GetShortEntry : Make a short directory entry (FAT16/32 conception)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   311
  * aEntry : the entry buffer   
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   312
  */ 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   313
void TFSNode::GetShortEntry(TShortDirEntry* aEntry) {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   314
  if(!aEntry) return ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   315
	if(iFATEntry){
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   316
		if(iFATEntry != aEntry)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   317
			memcpy(aEntry,iFATEntry,sizeof(TShortDirEntry));
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   318
		return ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   319
	}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   320
	memcpy(aEntry->DIR_Name,iShortName,sizeof(aEntry->DIR_Name)); 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   321
	aEntry->DIR_Attr = iAttrs;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   322
	aEntry->DIR_NTRes = 0 ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   323
	aEntry->DIR_CrtTimeTenth = 0 ;        
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   324
	memcpy(aEntry->DIR_CrtTime,&iCrtTime,sizeof(aEntry->DIR_CrtTime)); 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   325
	memcpy(aEntry->DIR_CrtDate,&iCrtDate,sizeof(aEntry->DIR_CrtDate));
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   326
	memcpy(aEntry->DIR_LstAccDate,&iLstAccDate,sizeof(aEntry->DIR_LstAccDate));
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   327
	memset(aEntry->DIR_FstClusHI,0,sizeof(aEntry->DIR_FstClusHI));
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   328
	memcpy(aEntry->DIR_WrtTime,&iWrtTime,sizeof(aEntry->DIR_WrtTime)); 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   329
	memcpy(aEntry->DIR_WrtDate,&iWrtDate,sizeof(aEntry->DIR_WrtDate)); 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   330
	memset(aEntry->DIR_FstClusLO,0,sizeof(aEntry->DIR_FstClusLO)); 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   331
	memcpy(aEntry->DIR_FileSize,&iFileSize,sizeof(aEntry->DIR_FileSize));  
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   332
}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   333
TUint8 FATChkSum(const char* pFcbName) {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   334
    short fcbNameLen ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   335
    TUint8 sum = 0 ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   336
    for(fcbNameLen = 11 ; fcbNameLen != 0 ; fcbNameLen --) {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   337
        sum = ((sum & 1) ? 0x80 : 0 ) + (sum >> 1 ) + *pFcbName++ ; 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   338
    }
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   339
    return sum ;        
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   340
}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   341
/** GetLongEntries : Make a series of long directory entries (FAT16/32 conception)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   342
  * aEntries : the start addr of the long directory entries buffer
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   343
  *
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   344
  * return value : actual entris count.   
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   345
  */ 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   346
int TFSNode::GetLongEntries(TLongDirEntry* aEntries) {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   347
  
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   348
  if(!aEntries) return 0;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   349
	int packs = (GetWideNameLength() + KBytesPerEntry) / KBytesPerEntry  ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   350
	
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   351
	TUint buflen = packs * KBytesPerEntry;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   352
	TUint16* buffer = new(std::nothrow) TUint16[buflen];
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   353
	if(!buffer)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   354
	return 0 ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   355
	memset(buffer,0xff,(buflen << 1));    
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   356
	if(iWideName) {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   357
	    memcpy(buffer,iWideName->c_str(),iWideName->bytes()); 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   358
	    buffer[iWideName->length()] = 0;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   359
	}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   360
	TUint8 chkSum = FATChkSum(iShortName);;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   361
    
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   362
	TUint16* ptr = buffer ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   363
	TLongDirEntry* entry = aEntries +(packs - 1);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   364
  for(int i = 1 ; i <= packs ; i++, entry--) {		
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   365
		entry->LDIR_Ord = i ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   366
		entry->LDIR_Chksum = chkSum ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   367
		entry->LDIR_Attr = (TUint8)ATTR_LONG_NAME;    
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   368
		*((TUint16*)(entry->LDIR_FstClusLO)) = 0;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   369
		entry->LDIR_Type = 0;         
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   370
		memcpy(entry->LDIR_Name1,ptr,10); 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   371
		memcpy(entry->LDIR_Name2,&ptr[5],12); 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   372
		memcpy(entry->LDIR_Name3,&ptr[11],4);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   373
		ptr += 13; 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   374
  }
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   375
	aEntries->LDIR_Ord |= 0x40 ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   376
    
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   377
	delete []buffer ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   378
	return packs ; 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   379
}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   380
/** Make a unique name for a new child which has not been added.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   381
  * to avoid same short names under a directory
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   382
  * rShortName : [in,out] , The new short name to be checked and changed.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   383
  * baseNameLength: [in], the length of the base part of the short name 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   384
  * not including the "~n"
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   385
  * for example, 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   386
  *  "ABC.LOG" => baseNameLength == 3 ("ABC")
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   387
  *  "AB~1.TXT" => baseNameLength == 2 ("AB")
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   388
  *
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   389
  *
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   390
  *The Numeric-Tail Generation Algorithm
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   391
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   392
  * If (a "lossy conversion" was not flagged)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   393
  * 		and	(the long name fits within the 8.3 naming conventions)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   394
  * 		and	(the basis-name does not collide with any existing short name)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   395
  * {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   396
  * 	The short name is only the basis-name without the numeric tail.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   397
  * }
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   398
  * else {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   399
  * 	Insert a numeric-tail "~n" to the end of the primary name such that the value of 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   400
  *		the "~n" is chosen so that the name thus formed does not collide with 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   401
  *		any existing short name and that the primary name does not exceed eight
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   402
  *		characters in length.
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   403
  * }
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   404
  * The "~n" string can range from "~1" to "~999999". 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   405
  *
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   406
  */
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   407
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   408
void TFSNode::MakeUniqueShortName(char rShortName[12],TUint baseNameLength) const { 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   409
	bool dup ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   410
	char nstring[10];
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   411
	int n = 0 ;	
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   412
	do {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   413
		TFSNode* child = iFirstChild ; 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   414
		dup = false ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   415
		while(child){		 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   416
			if(0 == memcmp(rShortName,child->iShortName,11)) {
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   417
				dup = true ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   418
				break ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   419
			}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   420
			child = child->iSibling ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   421
		}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   422
		if(dup){ //duplex , increase the index , make a new name 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   423
			int nlen = sprintf(nstring,"~%u",++n);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   424
			while((baseNameLength + nlen > 8) && baseNameLength > 1)
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   425
				baseNameLength -- ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   426
			memcpy(&rShortName[baseNameLength],nstring,nlen);
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   427
			
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   428
		}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   429
	}while(dup) ;
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   430
		 
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   431
}
122d2b873fd1 Minor changes: rofsbuild
jjkang
parents:
diff changeset
   432