606
|
1 |
/*
|
|
2 |
* Copyright (c) 2006-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 |
* Driveimage class implementation.
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
|
|
20 |
|
|
21 |
#include <stdlib.h>
|
|
22 |
#include <string>
|
|
23 |
#include "fsnode.h"
|
|
24 |
#include "fatimagegenerator.h"
|
|
25 |
#include <boost/filesystem.hpp>
|
|
26 |
#include <stack>
|
|
27 |
#include <utility>
|
|
28 |
#include <new>
|
|
29 |
using namespace boost ;
|
|
30 |
#ifdef __LINUX__
|
|
31 |
|
|
32 |
#include <dirent.h>
|
|
33 |
#ifndef MKDIR
|
|
34 |
#define MKDIR(a) mkdir(a,0777)
|
|
35 |
#endif
|
|
36 |
#else
|
|
37 |
#ifdef _STLP_INTERNAL_WINDOWS_H
|
|
38 |
#define __INTERLOCKED_DECLARED
|
|
39 |
#endif
|
|
40 |
#include <windows.h>
|
|
41 |
#include <direct.h>
|
|
42 |
#ifndef MKDIR
|
|
43 |
#define MKDIR mkdir
|
|
44 |
#endif
|
|
45 |
#endif
|
|
46 |
#include <sys/stat.h>
|
|
47 |
#include <sys/types.h>
|
|
48 |
using namespace std;
|
|
49 |
|
|
50 |
|
|
51 |
#include <f32file.h>
|
|
52 |
#include "h_utl.h"
|
|
53 |
#include "r_obey.h"
|
|
54 |
#include "r_romnode.h"
|
|
55 |
#include "r_rofs.h"
|
|
56 |
#include "r_driveimage.h"
|
|
57 |
|
|
58 |
/**
|
|
59 |
Constructor: CDriveImage class
|
|
60 |
|
|
61 |
@param aObey - pointer to Drive obey file.
|
|
62 |
*/
|
|
63 |
CDriveImage::CDriveImage(CObeyFile *aObey)
|
|
64 |
: iObey( aObey )
|
|
65 |
{
|
|
66 |
}
|
|
67 |
|
|
68 |
|
|
69 |
CDriveImage::~CDriveImage()
|
|
70 |
{
|
|
71 |
|
|
72 |
}
|
|
73 |
/**
|
|
74 |
*
|
|
75 |
*/
|
|
76 |
TFSNode* CDriveImage::PrepareFileSystem(TRomNode* aRomNode){
|
|
77 |
TUint8 attrib ;
|
|
78 |
TFSNode* root = 0;
|
|
79 |
TRomNode* romNode = aRomNode;
|
|
80 |
stack<pair<TRomNode*,TFSNode*> > nodesStack ;
|
|
81 |
TFSNode* parentFS = 0 ;
|
|
82 |
TFSNode* curFS = 0;
|
|
83 |
bool err = false ;
|
|
84 |
while(1) {
|
|
85 |
attrib = 0 ;
|
|
86 |
if(romNode->iAtt & KEntryAttReadOnly)
|
|
87 |
attrib |= ATTR_READ_ONLY ;
|
|
88 |
if(romNode->iAtt & KEntryAttHidden)
|
|
89 |
attrib |= ATTR_HIDDEN ;
|
|
90 |
if(romNode->iAtt & KEntryAttSystem)
|
|
91 |
attrib |= ATTR_SYSTEM ;
|
617
|
92 |
if(romNode->IsDirectory()) {
|
|
93 |
try {
|
|
94 |
curFS = new TFSNode(parentFS,romNode->iName,attrib | ATTR_DIRECTORY);
|
|
95 |
}
|
|
96 |
catch(const char* errInfo){
|
|
97 |
Print(EError,errInfo);
|
|
98 |
err = true ;
|
|
99 |
break ;
|
|
100 |
}
|
|
101 |
catch(...) {
|
|
102 |
err = true ;
|
|
103 |
break ;
|
606
|
104 |
}
|
|
105 |
if(!root) root = curFS ;
|
|
106 |
time_t now = time(NULL);
|
|
107 |
curFS->Init(now,now,now,0);
|
|
108 |
TRomNode* child = romNode->Currentchild();
|
|
109 |
if(child){
|
|
110 |
TRomNode* sibling = romNode->Currentsibling();
|
|
111 |
if(sibling)
|
|
112 |
nodesStack.push(make_pair(sibling,parentFS));
|
|
113 |
romNode = child ;
|
|
114 |
parentFS = curFS ;
|
|
115 |
continue ;
|
|
116 |
}
|
|
117 |
}
|
617
|
118 |
else { // file
|
|
119 |
try {
|
|
120 |
curFS = new TFSNode(parentFS,romNode->iEntry->iName,attrib,romNode->iEntry->iFileName);
|
|
121 |
}
|
|
122 |
catch(const char* errInfo){
|
|
123 |
Print(EError,errInfo);
|
|
124 |
err = true ;
|
|
125 |
break ;
|
|
126 |
}
|
|
127 |
catch(...) {
|
606
|
128 |
err = true ;
|
|
129 |
break ;
|
617
|
130 |
}
|
606
|
131 |
|
617
|
132 |
if(!root) root = curFS ;
|
|
133 |
struct stat statbuf ;
|
|
134 |
stat(romNode->iEntry->iFileName, &statbuf);
|
|
135 |
curFS->Init(statbuf.st_ctime,statbuf.st_atime,statbuf.st_mtime,statbuf.st_size);
|
606
|
136 |
|
|
137 |
}
|
|
138 |
|
|
139 |
TRomNode* sibling = romNode->Currentsibling();
|
|
140 |
if(sibling) {
|
|
141 |
romNode = sibling ;
|
|
142 |
}
|
|
143 |
else {
|
|
144 |
if(nodesStack.empty()) {
|
|
145 |
break ;
|
|
146 |
}
|
|
147 |
else {
|
|
148 |
romNode = nodesStack.top().first;
|
|
149 |
parentFS = nodesStack.top().second ;
|
|
150 |
nodesStack.pop() ;
|
|
151 |
|
|
152 |
}
|
|
153 |
}
|
|
154 |
}
|
|
155 |
if(err) {
|
|
156 |
if(root) delete root ;
|
|
157 |
return NULL ;
|
|
158 |
}
|
|
159 |
return root ;
|
|
160 |
}
|
|
161 |
|
|
162 |
/**
|
|
163 |
Creates the Image/Call to file system module.
|
|
164 |
|
|
165 |
Updates the required operations to generate the data drive images.
|
|
166 |
Deletes the temp folder if created.
|
|
167 |
Calls the file system modules with required parameters.
|
|
168 |
|
|
169 |
@param alogfile - Logfile name required for file system module.
|
|
170 |
@return Status(r) - returns the status of file system module.
|
|
171 |
'KErrGeneral' - Unable to done the above operations properly.
|
|
172 |
*/
|
|
173 |
TInt CDriveImage::CreateImage(const char* alogfile) {
|
|
174 |
|
|
175 |
TSupportedFatType fst = EFatUnknown ;
|
|
176 |
if(stricmp(iObey->iDriveFileFormat,"FAT16") == 0)
|
|
177 |
fst = EFat16 ;
|
|
178 |
else if(stricmp(iObey->iDriveFileFormat,"FAT32") == 0)
|
|
179 |
fst = EFat32 ;
|
|
180 |
if(EFatUnknown == fst){
|
|
181 |
Print(EError,"Unsupported FAT type : %s",iObey->iDriveFileFormat);
|
|
182 |
return KErrGeneral ;
|
|
183 |
}
|
|
184 |
|
|
185 |
TFatImgGenerator generator(fst,iObey->iConfigurableFatAttributes);
|
|
186 |
|
|
187 |
if(!generator.IsValid()){
|
|
188 |
return KErrGeneral;
|
|
189 |
}
|
|
190 |
TFSNode* root = PrepareFileSystem(iObey->iRootDirectory);
|
|
191 |
if(!root)
|
|
192 |
return KErrGeneral;
|
|
193 |
|
|
194 |
|
|
195 |
TInt retVal = generator.Execute(root,iObey->iDriveFileName) ? KErrNone : KErrGeneral;
|
|
196 |
|
|
197 |
delete root ;
|
|
198 |
|
|
199 |
return retVal;
|
|
200 |
}
|