|
1 /* |
|
2 * Copyright (c) 2003-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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __R_COREIMAGE_H__ |
|
20 #define __R_COREIMAGE_H__ |
|
21 |
|
22 class TRomNode; |
|
23 class E32Rofs; |
|
24 |
|
25 /** |
|
26 @internalComponent |
|
27 |
|
28 MRofsImage is the interface used to access information held within an image. |
|
29 This interface used to remove the dependency between processing of |
|
30 extensions and kernel commands in the obey file |
|
31 */ |
|
32 class MRofsImage |
|
33 { |
|
34 public: |
|
35 /** Gets the root directory node from the image |
|
36 |
|
37 @return TRomNode* the first node in the directory tree |
|
38 */ |
|
39 virtual TRomNode* RootDirectory() = 0; |
|
40 |
|
41 /** Copies the specified directory tree. |
|
42 |
|
43 @param aSourceDirectory The directory that is to be copied |
|
44 @return The copied directory tree. |
|
45 */ |
|
46 virtual TRomNode* CopyDirectory(TRomNode*& aSourceDirectory)=0; |
|
47 /** Sets the root directory to be the specified node. |
|
48 |
|
49 @param aDir The node that is to be set as the root directory |
|
50 */ |
|
51 virtual void SetRootDirectory(TRomNode* aDir) = 0; |
|
52 /** Gets the filename of the core image |
|
53 |
|
54 @returns The filename of the core image file |
|
55 */ |
|
56 virtual TText* RomFileName() = 0; |
|
57 /** Gets the size of the image file |
|
58 |
|
59 @returns size of file |
|
60 */ |
|
61 virtual TInt Size() = 0; |
|
62 }; |
|
63 |
|
64 const int K_ID_SIZE=4; /** Size of the image header identifier */ |
|
65 |
|
66 /** |
|
67 @internalComponent |
|
68 |
|
69 Provides the access the actual core image file. All file operations to the |
|
70 core image file are through this class. |
|
71 */ |
|
72 class RCoreImageReader |
|
73 { |
|
74 public: |
|
75 /** Image Type read from header of image file */ |
|
76 enum TImageType |
|
77 { |
|
78 /** Format of file has not been recognised */ |
|
79 E_UNKNOWN, |
|
80 /** File is a core RofsImage file */ |
|
81 E_ROFS, |
|
82 /** File is an extension RofsImage file */ |
|
83 E_ROFX |
|
84 }; |
|
85 |
|
86 RCoreImageReader(char *aFilename); |
|
87 ~RCoreImageReader(); |
|
88 TBool Open(); |
|
89 TImageType ReadImageType(); |
|
90 TInt ReadCoreHeader(TRofsHeader& aHeader); |
|
91 TInt ReadExtensionHeader(TExtensionRofsHeader& aHeader); |
|
92 |
|
93 TInt ReadDirEntry(TRofsDir& aDir); |
|
94 TInt ReadDirEntry(TRofsDir& aDir, long aFilePos); |
|
95 |
|
96 long FilePosition(); |
|
97 void SetFilePosition(long aFilePos); |
|
98 |
|
99 TInt ReadRofEntry(TRofsEntry& aEntry); |
|
100 TInt ReadRofEntry(TRofsEntry& aEntry, long aFilePos); |
|
101 TInt ReadRofEntryName(TUint16* aName, int aLength); |
|
102 TBool IsValidPosition(long filePos); |
|
103 TText* Filename(); |
|
104 private: |
|
105 TInt ReadIdentifier(); |
|
106 TInt ImageError(int aBytesRead, int aExpected, char* aInfo); |
|
107 |
|
108 /** Image type of the file being read */ |
|
109 TImageType iImageType; |
|
110 /** File handle of core image being read */ |
|
111 FILE* iCoreImage; |
|
112 /** Filename of core image file */ |
|
113 char* iFilename; |
|
114 /** Image type identifier read from image header */ |
|
115 TUint8 iIdentifier[K_ID_SIZE]; |
|
116 }; |
|
117 |
|
118 /** |
|
119 |
|
120 @internalComponent |
|
121 |
|
122 Processes the core image file to create a directory tree. |
|
123 It is used when the coreimage option has been specified either |
|
124 on the command line or in the obey file. It implements the MRofsImage |
|
125 so it can be used by the extension image processing. |
|
126 */ |
|
127 class CCoreImage : public MRofsImage |
|
128 { |
|
129 public: |
|
130 CCoreImage(RCoreImageReader* aReader); |
|
131 virtual TInt ProcessImage(); |
|
132 void Display(ostream* aOut); |
|
133 virtual ~CCoreImage(); |
|
134 |
|
135 // Implementation of MRofsImage |
|
136 TRomNode* RootDirectory(); |
|
137 TRomNode* CopyDirectory(TRomNode*& aSourceDirectory); |
|
138 void SetRootDirectory(TRomNode* aDir); |
|
139 TText* RomFileName(); |
|
140 TInt Size(); |
|
141 |
|
142 protected: |
|
143 void SaveDirInfo(TRofsHeader& header); |
|
144 void SaveDirInfo(TExtensionRofsHeader& header); |
|
145 TInt ProcessDirectory(long aAdjustment); |
|
146 TInt CreateRootDir(); |
|
147 long DirTreeOffset(); |
|
148 |
|
149 /** used to read the core image file*/ |
|
150 RCoreImageReader *iReader; |
|
151 private: |
|
152 /** The node for the root directory */ |
|
153 TRomNode *iRootDirectory; |
|
154 /** The first node in list of file entries */ |
|
155 TRomBuilderEntry *iFileEntries; |
|
156 /** Offset to the directory tree in the core image */ |
|
157 long iDirTreeOffset; |
|
158 /** Size of the directory tree in the core image */ |
|
159 long iDirTreeSize; |
|
160 /** Offset to the file entries of the directory in the core image */ |
|
161 long iDirFileEntriesOffset; |
|
162 /** Size of the file entries block of the directory */ |
|
163 long iDirFileEntriesSize; |
|
164 /** Filename of the rom image file */ |
|
165 TText* iRomFileName; |
|
166 /** Size of image */ |
|
167 TInt iImageSize; |
|
168 }; |
|
169 |
|
170 /** |
|
171 @internalComponent |
|
172 |
|
173 Used for handling a single directory entry in the core image. This class allows |
|
174 the directory tree to be created recursively. |
|
175 */ |
|
176 class TDirectoryEntry |
|
177 { |
|
178 public: |
|
179 TDirectoryEntry(long filePos, RCoreImageReader* aReader, TRomNode* aCurrentDir); |
|
180 ~TDirectoryEntry(); |
|
181 TInt Process(long adjustment); |
|
182 private: |
|
183 TInt CreateFileEntry(TText* aName, TRofsEntry& aRofsEntry); |
|
184 TInt AddSubDirs(long endDirPos); |
|
185 TInt AddFiles(long startPos, int size); |
|
186 TText* GetName(TUint16 aFirstChar, TInt aLength); |
|
187 |
|
188 /** Handle to core image file */ |
|
189 RCoreImageReader* iReader; |
|
190 /** Node for the current directory */ |
|
191 TRomNode* iCurrentDir; |
|
192 /** Current position in the file */ |
|
193 long iFilePos; |
|
194 /** |
|
195 The references in the extension directory tree are relative the core |
|
196 image and not the actual offset in the file. This variable holds the |
|
197 difference between the entries in the directory tree and the actual file |
|
198 position. This allows the same methods to be used for both core and |
|
199 extension images. |
|
200 */ |
|
201 long iAdjustment; |
|
202 }; |
|
203 |
|
204 #endif |