1 /*             ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
2  *
3  *                 Copyright (c) 2014-2015 Datalight, Inc.
4  *                     All Rights Reserved Worldwide.
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; use version 2 of the License.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
12  *  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License along
16  *  with this program; if not, write to the Free Software Foundation, Inc.,
17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 /*  Businesses and individuals that for commercial or other reasons cannot
21  *  comply with the terms of the GPLv2 license may obtain a commercial license
22  *  before incorporating Reliance Edge into proprietary software for
23  *  distribution in any form.  Visit http://www.datalight.com/reliance-edge for
24  *  more information.
25  */
26 #ifndef REDTOOLS_H
27 #define REDTOOLS_H
28 
29 
30 #ifdef _WIN32
31     #include <Windows.h>
32     #define HOST_PATH_MAX    MAX_PATH
33 #else
34     #include <linux/limits.h>
35     #define HOST_PATH_MAX    PATH_MAX
36 #endif
37 
38 
39 #if REDCONF_IMAGE_BUILDER == 1
40 
41     #define MACRO_NAME_MAX_LEN    32
42 
43     typedef struct
44     {
45         uint8_t bVolNumber;
46         const char * pszInputDir;
47         const char * pszOutputFile;
48         #if REDCONF_API_POSIX == 1
49             const char * pszVolName;
50         #else
51             const char * pszMapFile;
52             const char * pszDefineFile;
53             bool fNowarn;
54         #endif
55     } IMGBLDPARAM;
56 
57 
58     void ImgbldParseParams( int argc,
59                             char * argv[],
60                             IMGBLDPARAM * pParam );
61     int ImgbldStart( IMGBLDPARAM * pParam );
62 
63 
64     typedef struct
65     {
66         #if REDCONF_API_POSIX == 1
67             char asOutFilePath[ HOST_PATH_MAX ];
68         #else
69             uint32_t ulOutFileIndex;
70         #endif
71         char asInFilePath[ HOST_PATH_MAX ];
72     } FILEMAPPING;
73 
74 
75     extern void * gpCopyBuffer;
76     extern uint32_t gulCopyBufferSize;
77 
78 
79 /*  Implemented in ibposix.c
80  */
81     #if REDCONF_API_POSIX == 1
82         REDSTATUS IbPosixCopyDir( const char * pszVolName,
83                                   const char * pszInDir );
84         int IbPosixCreateDir( const char * pszVolName,
85                               const char * pszFullPath,
86                               const char * pszBasePath );
87         int IbConvertPath( const char * pszVolName,
88                            const char * pszFullPath,
89                            const char * pszBasePath,
90                            char * szOutPath );
91     #endif
92 
93 
94 /*  Implemented in ibfse.c
95  */
96     #if REDCONF_API_FSE == 1
97         typedef struct sFILELISTENTRY FILELISTENTRY;
98         struct sFILELISTENTRY
99         {
100             FILEMAPPING fileMapping;
101             FILELISTENTRY * pNext;
102         };
103 
104 
105         void FreeFileList( FILELISTENTRY ** ppsFileList );
106 
107         int IbFseGetFileList( const char * pszPath,
108                               const char * pszIndirPath,
109                               FILELISTENTRY ** ppFileListHead );
110         int IbFseOutputDefines( FILELISTENTRY * pFileList,
111                                 const IMGBLDPARAM * pOptions );
112         int IbFseCopyFiles( int volNum,
113                             const FILELISTENTRY * pFileList );
114     #endif /* if REDCONF_API_FSE == 1 */
115 
116 
117 /*  Implemented in os-specific space (ibwin.c and iblinux.c)
118  */
119     #if REDCONF_API_POSIX == 1
120         int IbPosixCopyDirRecursive( const char * pszVolName,
121                                      const char * pszInDir );
122     #endif
123     #if REDCONF_API_FSE == 1
124         int IbFseBuildFileList( const char * pszDirPath,
125                                 FILELISTENTRY ** ppFileListHead );
126     #endif
127     #if REDCONF_API_FSE == 1
128         int IbSetRelativePath( char * pszPath,
129                                const char * pszParentPath );
130     #endif
131     bool IsRegularFile( const char * pszPath );
132 
133 
134 /*  Implemented in ibcommon.c
135  */
136     int IbCopyFile( int volNum,
137                     const FILEMAPPING * pFileMapping );
138     int IbCheckFileExists( const char * pszPath,
139                            bool * pfExists );
140 
141 
142 /*  Implemented separately in ibfse.c and ibposix.c
143  */
144     int IbApiInit( void );
145     int IbApiUninit( void );
146     int IbWriteFile( int volNum,
147                      const FILEMAPPING * pFileMapping,
148                      uint64_t ullOffset,
149                      void * pData,
150                      uint32_t ulDataLen );
151 
152 #endif /* IMAGE_BUILDER */
153 
154 /*  For image copier tool
155  */
156 
157 #ifdef _WIN32
158     #define HOST_PSEP       '\\'
159     #if !__STDC__
160         #define snprintf    _snprintf
161         #define stat        _stat
162         #define S_IFDIR     _S_IFDIR
163         #define rmdir       _rmdir
164     #endif
165 #else
166     #define HOST_PSEP       '/'
167 #endif
168 
169 typedef struct
170 {
171     uint8_t bVolNumber;
172     const char * pszOutputDir;
173     const char * pszBDevSpec;
174     #if REDCONF_API_POSIX == 1
175         const char * pszVolName;
176     #endif
177     bool fNoWarn;
178 } IMGCOPYPARAM;
179 
180 typedef struct
181 {
182     #if REDCONF_API_POSIX == 1
183         const char * pszVolume;  /* Volume path prefix. */
184         uint32_t ulVolPrefixLen; /* strlen(COPIER::pszVolume) */
185     #else
186         uint8_t bVolNum;         /* Volume number. */
187     #endif
188     const char * pszOutputDir;   /* Output directory path. */
189     bool fNoWarn;                /* If true, no warning to overwrite. */
190     uint8_t * pbCopyBuffer;      /* Buffer for copying file data. */
191 } COPIER;
192 
193 
194 void ImgcopyParseParams( int argc,
195                          char * argv[],
196                          IMGCOPYPARAM * pParam );
197 int ImgcopyStart( IMGCOPYPARAM * pParam );
198 
199 /*  Implemented separately in imgcopywin.c and imgcopylinux.c.  These functions
200  *  print an error message and abort on failure.
201  */
202 void ImgcopyMkdir( const char * pszDir );
203 void ImgcopyRecursiveRmdir( const char * pszDir );
204 
205 
206 #endif /* REDTOOLS_H */
207