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 ;
|
|
92 |
if(romNode->IsDirectory()) {
|
|
93 |
curFS = new(std::nothrow) TFSNode(parentFS,romNode->iName,attrib | ATTR_DIRECTORY);
|
|
94 |
if(!curFS){
|
|
95 |
err = true ;
|
|
96 |
break ;
|
|
97 |
}
|
|
98 |
if(!root) root = curFS ;
|
|
99 |
time_t now = time(NULL);
|
|
100 |
curFS->Init(now,now,now,0);
|
|
101 |
TRomNode* child = romNode->Currentchild();
|
|
102 |
if(child){
|
|
103 |
TRomNode* sibling = romNode->Currentsibling();
|
|
104 |
if(sibling)
|
|
105 |
nodesStack.push(make_pair(sibling,parentFS));
|
|
106 |
romNode = child ;
|
|
107 |
parentFS = curFS ;
|
|
108 |
continue ;
|
|
109 |
}
|
|
110 |
}
|
|
111 |
else { // file
|
|
112 |
curFS = new(std::nothrow) TFSNode(parentFS,romNode->iEntry->iName,attrib,romNode->iEntry->iFileName);
|
|
113 |
if(!curFS){
|
|
114 |
err = true ;
|
|
115 |
break ;
|
|
116 |
}
|
|
117 |
|
|
118 |
if(!root) root = curFS ;
|
|
119 |
struct stat statbuf ;
|
|
120 |
stat(romNode->iEntry->iFileName, &statbuf);
|
|
121 |
curFS->Init(statbuf.st_ctime,statbuf.st_atime,statbuf.st_mtime,statbuf.st_size);
|
|
122 |
|
|
123 |
}
|
|
124 |
|
|
125 |
TRomNode* sibling = romNode->Currentsibling();
|
|
126 |
if(sibling) {
|
|
127 |
romNode = sibling ;
|
|
128 |
}
|
|
129 |
else {
|
|
130 |
if(nodesStack.empty()) {
|
|
131 |
break ;
|
|
132 |
}
|
|
133 |
else {
|
|
134 |
romNode = nodesStack.top().first;
|
|
135 |
parentFS = nodesStack.top().second ;
|
|
136 |
nodesStack.pop() ;
|
|
137 |
|
|
138 |
}
|
|
139 |
}
|
|
140 |
}
|
|
141 |
if(err) {
|
|
142 |
if(root) delete root ;
|
|
143 |
return NULL ;
|
|
144 |
}
|
|
145 |
return root ;
|
|
146 |
}
|
|
147 |
|
|
148 |
/**
|
|
149 |
Creates the Image/Call to file system module.
|
|
150 |
|
|
151 |
Updates the required operations to generate the data drive images.
|
|
152 |
Deletes the temp folder if created.
|
|
153 |
Calls the file system modules with required parameters.
|
|
154 |
|
|
155 |
@param alogfile - Logfile name required for file system module.
|
|
156 |
@return Status(r) - returns the status of file system module.
|
|
157 |
'KErrGeneral' - Unable to done the above operations properly.
|
|
158 |
*/
|
|
159 |
TInt CDriveImage::CreateImage(const char* alogfile) {
|
|
160 |
|
|
161 |
TSupportedFatType fst = EFatUnknown ;
|
|
162 |
if(stricmp(iObey->iDriveFileFormat,"FAT16") == 0)
|
|
163 |
fst = EFat16 ;
|
|
164 |
else if(stricmp(iObey->iDriveFileFormat,"FAT32") == 0)
|
|
165 |
fst = EFat32 ;
|
|
166 |
if(EFatUnknown == fst){
|
|
167 |
Print(EError,"Unsupported FAT type : %s",iObey->iDriveFileFormat);
|
|
168 |
return KErrGeneral ;
|
|
169 |
}
|
|
170 |
|
|
171 |
TFatImgGenerator generator(fst,iObey->iConfigurableFatAttributes);
|
|
172 |
|
|
173 |
if(!generator.IsValid()){
|
|
174 |
return KErrGeneral;
|
|
175 |
}
|
|
176 |
TFSNode* root = PrepareFileSystem(iObey->iRootDirectory);
|
|
177 |
if(!root)
|
|
178 |
return KErrGeneral;
|
|
179 |
|
|
180 |
|
|
181 |
TInt retVal = generator.Execute(root,iObey->iDriveFileName) ? KErrNone : KErrGeneral;
|
|
182 |
|
|
183 |
delete root ;
|
|
184 |
|
|
185 |
return retVal;
|
|
186 |
}
|