/src/libewf/libewf/libewf_segment_table.c
Line | Count | Source |
1 | | /* |
2 | | * Segment table functions |
3 | | * |
4 | | * Copyright (C) 2006-2026, Joachim Metz <joachim.metz@gmail.com> |
5 | | * |
6 | | * Refer to AUTHORS for acknowledgements. |
7 | | * |
8 | | * This program is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include <common.h> |
23 | | #include <memory.h> |
24 | | #include <narrow_string.h> |
25 | | #include <system_string.h> |
26 | | #include <types.h> |
27 | | #include <wide_string.h> |
28 | | |
29 | | #include "libewf_definitions.h" |
30 | | #include "libewf_libbfio.h" |
31 | | #include "libewf_libcdata.h" |
32 | | #include "libewf_libcerror.h" |
33 | | #include "libewf_libclocale.h" |
34 | | #include "libewf_libfdata.h" |
35 | | #include "libewf_libuna.h" |
36 | | #include "libewf_segment_file.h" |
37 | | #include "libewf_segment_table.h" |
38 | | |
39 | | /* Creates a segment table |
40 | | * Make sure the value segment_table is referencing, is set to NULL |
41 | | * Returns 1 if successful or -1 on error |
42 | | */ |
43 | | int libewf_segment_table_initialize( |
44 | | libewf_segment_table_t **segment_table, |
45 | | libewf_io_handle_t *io_handle, |
46 | | size64_t maximum_segment_size, |
47 | | libcerror_error_t **error ) |
48 | 7.47k | { |
49 | 7.47k | static char *function = "libewf_segment_table_initialize"; |
50 | | |
51 | 7.47k | if( segment_table == NULL ) |
52 | 0 | { |
53 | 0 | libcerror_error_set( |
54 | 0 | error, |
55 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
56 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
57 | 0 | "%s: invalid segment table.", |
58 | 0 | function ); |
59 | |
|
60 | 0 | return( -1 ); |
61 | 0 | } |
62 | 7.47k | if( *segment_table != NULL ) |
63 | 0 | { |
64 | 0 | libcerror_error_set( |
65 | 0 | error, |
66 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
67 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
68 | 0 | "%s: invalid segment table value already set.", |
69 | 0 | function ); |
70 | |
|
71 | 0 | return( -1 ); |
72 | 0 | } |
73 | 7.47k | if( io_handle == NULL ) |
74 | 0 | { |
75 | 0 | libcerror_error_set( |
76 | 0 | error, |
77 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
78 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
79 | 0 | "%s: invalid IO handle.", |
80 | 0 | function ); |
81 | |
|
82 | 0 | return( -1 ); |
83 | 0 | } |
84 | 7.47k | *segment_table = memory_allocate_structure( |
85 | 7.47k | libewf_segment_table_t ); |
86 | | |
87 | 7.47k | if( *segment_table == NULL ) |
88 | 0 | { |
89 | 0 | libcerror_error_set( |
90 | 0 | error, |
91 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
92 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
93 | 0 | "%s: unable to create segment table.", |
94 | 0 | function ); |
95 | |
|
96 | 0 | goto on_error; |
97 | 0 | } |
98 | 7.47k | if( memory_set( |
99 | 7.47k | *segment_table, |
100 | 7.47k | 0, |
101 | 7.47k | sizeof( libewf_segment_table_t ) ) == NULL ) |
102 | 0 | { |
103 | 0 | libcerror_error_set( |
104 | 0 | error, |
105 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
106 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
107 | 0 | "%s: unable to clear segment table.", |
108 | 0 | function ); |
109 | |
|
110 | 0 | memory_free( |
111 | 0 | *segment_table ); |
112 | |
|
113 | 0 | *segment_table = NULL; |
114 | |
|
115 | 0 | return( -1 ); |
116 | 0 | } |
117 | 7.47k | if( libfdata_list_initialize( |
118 | 7.47k | &( ( *segment_table )->segment_files_list ), |
119 | 7.47k | (intptr_t *) io_handle, |
120 | 7.47k | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_io_handle_free, |
121 | 7.47k | (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libewf_io_handle_clone, |
122 | 7.47k | (int (*)(intptr_t *, intptr_t *, libfdata_list_element_t *, libfdata_cache_t *, int, off64_t, size64_t, uint32_t, uint8_t, libcerror_error_t **)) &libewf_segment_file_read_element_data, |
123 | 7.47k | NULL, |
124 | 7.47k | LIBFDATA_DATA_HANDLE_FLAG_NON_MANAGED, |
125 | 7.47k | error ) != 1 ) |
126 | 0 | { |
127 | 0 | libcerror_error_set( |
128 | 0 | error, |
129 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
130 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
131 | 0 | "%s: unable to create segment files list.", |
132 | 0 | function ); |
133 | |
|
134 | 0 | goto on_error; |
135 | 0 | } |
136 | 7.47k | if( libfcache_cache_initialize( |
137 | 7.47k | &( ( *segment_table )->segment_files_cache ), |
138 | 7.47k | LIBEWF_MAXIMUM_CACHE_ENTRIES_SEGMENT_FILES, |
139 | 7.47k | error ) != 1 ) |
140 | 0 | { |
141 | 0 | libcerror_error_set( |
142 | 0 | error, |
143 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
144 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
145 | 0 | "%s: unable to create segment files cache.", |
146 | 0 | function ); |
147 | |
|
148 | 0 | goto on_error; |
149 | 0 | } |
150 | 7.47k | ( *segment_table )->maximum_segment_size = maximum_segment_size; |
151 | | |
152 | 7.47k | return( 1 ); |
153 | | |
154 | 0 | on_error: |
155 | 0 | if( *segment_table != NULL ) |
156 | 0 | { |
157 | 0 | if( ( *segment_table )->segment_files_list != NULL ) |
158 | 0 | { |
159 | 0 | libfdata_list_free( |
160 | 0 | &( ( *segment_table )->segment_files_list ), |
161 | 0 | NULL ); |
162 | 0 | } |
163 | 0 | memory_free( |
164 | 0 | *segment_table ); |
165 | |
|
166 | 0 | *segment_table = NULL; |
167 | 0 | } |
168 | 0 | return( -1 ); |
169 | 7.47k | } |
170 | | |
171 | | /* Frees a segment table |
172 | | * Returns 1 if successful or -1 on error |
173 | | */ |
174 | | int libewf_segment_table_free( |
175 | | libewf_segment_table_t **segment_table, |
176 | | libcerror_error_t **error ) |
177 | 7.47k | { |
178 | 7.47k | static char *function = "libewf_segment_table_free"; |
179 | 7.47k | int result = 1; |
180 | | |
181 | 7.47k | if( segment_table == NULL ) |
182 | 0 | { |
183 | 0 | libcerror_error_set( |
184 | 0 | error, |
185 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
186 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
187 | 0 | "%s: invalid segment table.", |
188 | 0 | function ); |
189 | |
|
190 | 0 | return( -1 ); |
191 | 0 | } |
192 | 7.47k | if( *segment_table != NULL ) |
193 | 7.47k | { |
194 | 7.47k | if( libewf_segment_table_clear( |
195 | 7.47k | *segment_table, |
196 | 7.47k | error ) != 1 ) |
197 | 0 | { |
198 | 0 | libcerror_error_set( |
199 | 0 | error, |
200 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
201 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
202 | 0 | "%s: unable to clear segment table.", |
203 | 0 | function ); |
204 | |
|
205 | 0 | result = -1; |
206 | 0 | } |
207 | 7.47k | if( libfcache_cache_free( |
208 | 7.47k | &( ( *segment_table )->segment_files_cache ), |
209 | 7.47k | error ) != 1 ) |
210 | 0 | { |
211 | 0 | libcerror_error_set( |
212 | 0 | error, |
213 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
214 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
215 | 0 | "%s: unable to free segment files cache.", |
216 | 0 | function ); |
217 | |
|
218 | 0 | result = -1; |
219 | 0 | } |
220 | 7.47k | if( libfdata_list_free( |
221 | 7.47k | &( ( *segment_table )->segment_files_list ), |
222 | 7.47k | error ) != 1 ) |
223 | 0 | { |
224 | 0 | libcerror_error_set( |
225 | 0 | error, |
226 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
227 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
228 | 0 | "%s: unable to free segment files list.", |
229 | 0 | function ); |
230 | |
|
231 | 0 | result = -1; |
232 | 0 | } |
233 | 7.47k | memory_free( |
234 | 7.47k | *segment_table ); |
235 | | |
236 | 7.47k | *segment_table = NULL; |
237 | 7.47k | } |
238 | 7.47k | return( result ); |
239 | 7.47k | } |
240 | | |
241 | | /* Clears the segment table |
242 | | * Returns 1 if successful or -1 on error |
243 | | */ |
244 | | int libewf_segment_table_clear( |
245 | | libewf_segment_table_t *segment_table, |
246 | | libcerror_error_t **error ) |
247 | 10.3k | { |
248 | 10.3k | static char *function = "libewf_segment_table_clear"; |
249 | | |
250 | 10.3k | if( segment_table == NULL ) |
251 | 0 | { |
252 | 0 | libcerror_error_set( |
253 | 0 | error, |
254 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
255 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
256 | 0 | "%s: invalid segment table.", |
257 | 0 | function ); |
258 | |
|
259 | 0 | return( -1 ); |
260 | 0 | } |
261 | 10.3k | if( segment_table->basename != NULL ) |
262 | 1.38k | { |
263 | 1.38k | memory_free( |
264 | 1.38k | segment_table->basename ); |
265 | | |
266 | 1.38k | segment_table->basename = NULL; |
267 | 1.38k | } |
268 | 10.3k | if( libfdata_list_empty( |
269 | 10.3k | segment_table->segment_files_list, |
270 | 10.3k | error ) != 1 ) |
271 | 0 | { |
272 | 0 | libcerror_error_set( |
273 | 0 | error, |
274 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
275 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
276 | 0 | "%s: unable to empty segment files list.", |
277 | 0 | function ); |
278 | |
|
279 | 0 | return( -1 ); |
280 | 0 | } |
281 | 10.3k | if( libfcache_cache_empty( |
282 | 10.3k | segment_table->segment_files_cache, |
283 | 10.3k | error ) != 1 ) |
284 | 0 | { |
285 | 0 | libcerror_error_set( |
286 | 0 | error, |
287 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
288 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
289 | 0 | "%s: unable to empty segment files cache.", |
290 | 0 | function ); |
291 | |
|
292 | 0 | return( -1 ); |
293 | 0 | } |
294 | 10.3k | segment_table->maximum_segment_size = 0; |
295 | 10.3k | segment_table->number_of_segments = 0; |
296 | 10.3k | segment_table->current_segment_file = NULL; |
297 | 10.3k | segment_table->flags = 0; |
298 | | |
299 | 10.3k | return( 1 ); |
300 | 10.3k | } |
301 | | |
302 | | /* Clones the segment table |
303 | | * Returns 1 if successful or -1 on error |
304 | | */ |
305 | | int libewf_segment_table_clone( |
306 | | libewf_segment_table_t **destination_segment_table, |
307 | | libewf_segment_table_t *source_segment_table, |
308 | | libcerror_error_t **error ) |
309 | 0 | { |
310 | 0 | static char *function = "libewf_segment_table_clone"; |
311 | |
|
312 | 0 | if( destination_segment_table == NULL ) |
313 | 0 | { |
314 | 0 | libcerror_error_set( |
315 | 0 | error, |
316 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
317 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
318 | 0 | "%s: invalid destination segment table.", |
319 | 0 | function ); |
320 | |
|
321 | 0 | return( -1 ); |
322 | 0 | } |
323 | 0 | if( *destination_segment_table != NULL ) |
324 | 0 | { |
325 | 0 | libcerror_error_set( |
326 | 0 | error, |
327 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
328 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
329 | 0 | "%s: invalid destination segment table value already set.", |
330 | 0 | function ); |
331 | |
|
332 | 0 | return( -1 ); |
333 | 0 | } |
334 | 0 | if( source_segment_table == NULL ) |
335 | 0 | { |
336 | 0 | *destination_segment_table = NULL; |
337 | |
|
338 | 0 | return( 1 ); |
339 | 0 | } |
340 | 0 | *destination_segment_table = memory_allocate_structure( |
341 | 0 | libewf_segment_table_t ); |
342 | |
|
343 | 0 | if( *destination_segment_table == NULL ) |
344 | 0 | { |
345 | 0 | libcerror_error_set( |
346 | 0 | error, |
347 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
348 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
349 | 0 | "%s: unable to create destination segment table.", |
350 | 0 | function ); |
351 | |
|
352 | 0 | goto on_error; |
353 | 0 | } |
354 | 0 | if( memory_set( |
355 | 0 | *destination_segment_table, |
356 | 0 | 0, |
357 | 0 | sizeof( libewf_segment_table_t ) ) == NULL ) |
358 | 0 | { |
359 | 0 | libcerror_error_set( |
360 | 0 | error, |
361 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
362 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
363 | 0 | "%s: unable to clear source to destination segment table.", |
364 | 0 | function ); |
365 | |
|
366 | 0 | memory_free( |
367 | 0 | *destination_segment_table ); |
368 | |
|
369 | 0 | *destination_segment_table = NULL; |
370 | |
|
371 | 0 | return( -1 ); |
372 | 0 | } |
373 | 0 | if( source_segment_table->basename != NULL ) |
374 | 0 | { |
375 | 0 | ( *destination_segment_table )->basename = system_string_allocate( |
376 | 0 | source_segment_table->basename_size ); |
377 | |
|
378 | 0 | if( *destination_segment_table == NULL ) |
379 | 0 | { |
380 | 0 | libcerror_error_set( |
381 | 0 | error, |
382 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
383 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
384 | 0 | "%s: unable to create destination segment table.", |
385 | 0 | function ); |
386 | |
|
387 | 0 | goto on_error; |
388 | 0 | } |
389 | 0 | if( memory_copy( |
390 | 0 | ( *destination_segment_table )->basename, |
391 | 0 | source_segment_table->basename, |
392 | 0 | sizeof( system_character_t ) * source_segment_table->basename_size ) == NULL ) |
393 | 0 | { |
394 | 0 | libcerror_error_set( |
395 | 0 | error, |
396 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
397 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
398 | 0 | "%s: unable to copy source to destination basename.", |
399 | 0 | function ); |
400 | |
|
401 | 0 | goto on_error; |
402 | 0 | } |
403 | 0 | ( *destination_segment_table )->basename_size = source_segment_table->basename_size; |
404 | 0 | } |
405 | 0 | if( libfdata_list_clone( |
406 | 0 | &( ( *destination_segment_table )->segment_files_list ), |
407 | 0 | source_segment_table->segment_files_list, |
408 | 0 | error ) != 1 ) |
409 | 0 | { |
410 | 0 | libcerror_error_set( |
411 | 0 | error, |
412 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
413 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
414 | 0 | "%s: unable to create destination segment files list.", |
415 | 0 | function ); |
416 | |
|
417 | 0 | goto on_error; |
418 | 0 | } |
419 | 0 | if( libfcache_cache_clone( |
420 | 0 | &( ( *destination_segment_table )->segment_files_cache ), |
421 | 0 | source_segment_table->segment_files_cache, |
422 | 0 | error ) != 1 ) |
423 | 0 | { |
424 | 0 | libcerror_error_set( |
425 | 0 | error, |
426 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
427 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
428 | 0 | "%s: unable to create destination segment files cache.", |
429 | 0 | function ); |
430 | |
|
431 | 0 | goto on_error; |
432 | 0 | } |
433 | 0 | ( *destination_segment_table )->maximum_segment_size = source_segment_table->maximum_segment_size; |
434 | |
|
435 | 0 | return( 1 ); |
436 | | |
437 | 0 | on_error: |
438 | 0 | if( *destination_segment_table != NULL ) |
439 | 0 | { |
440 | 0 | if( ( *destination_segment_table )->segment_files_list != NULL ) |
441 | 0 | { |
442 | 0 | libfdata_list_free( |
443 | 0 | &( ( *destination_segment_table )->segment_files_list ), |
444 | 0 | NULL ); |
445 | 0 | } |
446 | 0 | if( ( *destination_segment_table )->basename != NULL ) |
447 | 0 | { |
448 | 0 | memory_free( |
449 | 0 | ( *destination_segment_table )->basename ); |
450 | 0 | } |
451 | 0 | memory_free( |
452 | 0 | *destination_segment_table ); |
453 | |
|
454 | 0 | *destination_segment_table = NULL; |
455 | 0 | } |
456 | 0 | return( -1 ); |
457 | 0 | } |
458 | | |
459 | | /* Retrieves the size of the basename |
460 | | * Returns 1 if successful, 0 if not set or -1 on error |
461 | | */ |
462 | | int libewf_segment_table_get_basename_size( |
463 | | libewf_segment_table_t *segment_table, |
464 | | size_t *basename_size, |
465 | | libcerror_error_t **error ) |
466 | 0 | { |
467 | 0 | static char *function = "libewf_segment_table_get_basename_size"; |
468 | |
|
469 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
470 | | int result = 0; |
471 | | #endif |
472 | |
|
473 | 0 | if( segment_table == NULL ) |
474 | 0 | { |
475 | 0 | libcerror_error_set( |
476 | 0 | error, |
477 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
478 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
479 | 0 | "%s: invalid segment table.", |
480 | 0 | function ); |
481 | |
|
482 | 0 | return( -1 ); |
483 | 0 | } |
484 | 0 | if( basename_size == NULL ) |
485 | 0 | { |
486 | 0 | libcerror_error_set( |
487 | 0 | error, |
488 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
489 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
490 | 0 | "%s: invalid basename size.", |
491 | 0 | function ); |
492 | |
|
493 | 0 | return( -1 ); |
494 | 0 | } |
495 | 0 | if( segment_table->basename == NULL ) |
496 | 0 | { |
497 | 0 | return( 0 ); |
498 | 0 | } |
499 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
500 | | if( libclocale_codepage == 0 ) |
501 | | { |
502 | | #if SIZEOF_WCHAR_T == 4 |
503 | | result = libuna_utf8_string_size_from_utf32( |
504 | | (libuna_utf32_character_t *) segment_table->basename, |
505 | | segment_table->basename_size, |
506 | | basename_size, |
507 | | error ); |
508 | | #elif SIZEOF_WCHAR_T == 2 |
509 | | result = libuna_utf8_string_size_from_utf16( |
510 | | (libuna_utf16_character_t *) segment_table->basename, |
511 | | segment_table->basename_size, |
512 | | basename_size, |
513 | | error ); |
514 | | #else |
515 | | #error Unsupported size of wchar_t |
516 | | #endif /* SIZEOF_WCHAR_T */ |
517 | | } |
518 | | else |
519 | | { |
520 | | #if SIZEOF_WCHAR_T == 4 |
521 | | result = libuna_byte_stream_size_from_utf32( |
522 | | (libuna_utf32_character_t *) segment_table->basename, |
523 | | segment_table->basename_size, |
524 | | libclocale_codepage, |
525 | | basename_size, |
526 | | error ); |
527 | | #elif SIZEOF_WCHAR_T == 2 |
528 | | result = libuna_byte_stream_size_from_utf16( |
529 | | (libuna_utf16_character_t *) segment_table->basename, |
530 | | segment_table->basename_size, |
531 | | libclocale_codepage, |
532 | | basename_size, |
533 | | error ); |
534 | | #else |
535 | | #error Unsupported size of wchar_t |
536 | | #endif /* SIZEOF_WCHAR_T */ |
537 | | } |
538 | | if( result != 1 ) |
539 | | { |
540 | | libcerror_error_set( |
541 | | error, |
542 | | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
543 | | LIBCERROR_CONVERSION_ERROR_GENERIC, |
544 | | "%s: unable to determine basename size.", |
545 | | function ); |
546 | | |
547 | | return( -1 ); |
548 | | } |
549 | | #else |
550 | 0 | *basename_size = segment_table->basename_size; |
551 | 0 | #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ |
552 | |
|
553 | 0 | return( 1 ); |
554 | 0 | } |
555 | | |
556 | | /* Retrieves the basename |
557 | | * Returns 1 if successful, 0 if not set or -1 on error |
558 | | */ |
559 | | int libewf_segment_table_get_basename( |
560 | | libewf_segment_table_t *segment_table, |
561 | | char *basename, |
562 | | size_t basename_size, |
563 | | libcerror_error_t **error ) |
564 | 0 | { |
565 | 0 | static char *function = "libewf_segment_table_get_basename"; |
566 | 0 | size_t narrow_basename_size = 0; |
567 | |
|
568 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
569 | | int result = 0; |
570 | | #endif |
571 | |
|
572 | 0 | if( segment_table == NULL ) |
573 | 0 | { |
574 | 0 | libcerror_error_set( |
575 | 0 | error, |
576 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
577 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
578 | 0 | "%s: invalid segment table.", |
579 | 0 | function ); |
580 | |
|
581 | 0 | return( -1 ); |
582 | 0 | } |
583 | 0 | if( basename == NULL ) |
584 | 0 | { |
585 | 0 | libcerror_error_set( |
586 | 0 | error, |
587 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
588 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
589 | 0 | "%s: invalid basename.", |
590 | 0 | function ); |
591 | |
|
592 | 0 | return( -1 ); |
593 | 0 | } |
594 | 0 | if( segment_table->basename == NULL ) |
595 | 0 | { |
596 | 0 | return( 0 ); |
597 | 0 | } |
598 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
599 | | if( libclocale_codepage == 0 ) |
600 | | { |
601 | | #if SIZEOF_WCHAR_T == 4 |
602 | | result = libuna_utf8_string_size_from_utf32( |
603 | | (libuna_utf32_character_t *) segment_table->basename, |
604 | | segment_table->basename_size, |
605 | | &narrow_basename_size, |
606 | | error ); |
607 | | #elif SIZEOF_WCHAR_T == 2 |
608 | | result = libuna_utf8_string_size_from_utf16( |
609 | | (libuna_utf16_character_t *) segment_table->basename, |
610 | | segment_table->basename_size, |
611 | | &narrow_basename_size, |
612 | | error ); |
613 | | #else |
614 | | #error Unsupported size of wchar_t |
615 | | #endif /* SIZEOF_WCHAR_T */ |
616 | | } |
617 | | else |
618 | | { |
619 | | #if SIZEOF_WCHAR_T == 4 |
620 | | result = libuna_byte_stream_size_from_utf32( |
621 | | (libuna_utf32_character_t *) segment_table->basename, |
622 | | segment_table->basename_size, |
623 | | libclocale_codepage, |
624 | | &narrow_basename_size, |
625 | | error ); |
626 | | #elif SIZEOF_WCHAR_T == 2 |
627 | | result = libuna_byte_stream_size_from_utf16( |
628 | | (libuna_utf16_character_t *) segment_table->basename, |
629 | | segment_table->basename_size, |
630 | | libclocale_codepage, |
631 | | &narrow_basename_size, |
632 | | error ); |
633 | | #else |
634 | | #error Unsupported size of wchar_t |
635 | | #endif /* SIZEOF_WCHAR_T */ |
636 | | } |
637 | | if( result != 1 ) |
638 | | { |
639 | | libcerror_error_set( |
640 | | error, |
641 | | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
642 | | LIBCERROR_CONVERSION_ERROR_GENERIC, |
643 | | "%s: unable to determine narrow basename size.", |
644 | | function ); |
645 | | |
646 | | return( -1 ); |
647 | | } |
648 | | #else |
649 | 0 | narrow_basename_size = segment_table->basename_size; |
650 | 0 | #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ |
651 | |
|
652 | 0 | if( basename_size < narrow_basename_size ) |
653 | 0 | { |
654 | 0 | libcerror_error_set( |
655 | 0 | error, |
656 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
657 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
658 | 0 | "%s: basename too small.", |
659 | 0 | function ); |
660 | |
|
661 | 0 | return( -1 ); |
662 | 0 | } |
663 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
664 | | if( libclocale_codepage == 0 ) |
665 | | { |
666 | | #if SIZEOF_WCHAR_T == 4 |
667 | | result = libuna_utf8_string_copy_from_utf32( |
668 | | (libuna_utf8_character_t *) basename, |
669 | | basename_size, |
670 | | (libuna_utf32_character_t *) segment_table->basename, |
671 | | segment_table->basename_size, |
672 | | error ); |
673 | | #elif SIZEOF_WCHAR_T == 2 |
674 | | result = libuna_utf8_string_copy_from_utf16( |
675 | | (libuna_utf8_character_t *) basename, |
676 | | basename_size, |
677 | | (libuna_utf16_character_t *) segment_table->basename, |
678 | | segment_table->basename_size, |
679 | | error ); |
680 | | #else |
681 | | #error Unsupported size of wchar_t |
682 | | #endif /* SIZEOF_WCHAR_T */ |
683 | | } |
684 | | else |
685 | | { |
686 | | #if SIZEOF_WCHAR_T == 4 |
687 | | result = libuna_byte_stream_copy_from_utf32( |
688 | | (uint8_t *) basename, |
689 | | basename_size, |
690 | | libclocale_codepage, |
691 | | (libuna_utf32_character_t *) segment_table->basename, |
692 | | segment_table->basename_size, |
693 | | error ); |
694 | | #elif SIZEOF_WCHAR_T == 2 |
695 | | result = libuna_byte_stream_copy_from_utf16( |
696 | | (uint8_t *) basename, |
697 | | basename_size, |
698 | | libclocale_codepage, |
699 | | (libuna_utf16_character_t *) segment_table->basename, |
700 | | segment_table->basename_size, |
701 | | error ); |
702 | | #else |
703 | | #error Unsupported size of wchar_t |
704 | | #endif /* SIZEOF_WCHAR_T */ |
705 | | } |
706 | | if( result != 1 ) |
707 | | { |
708 | | libcerror_error_set( |
709 | | error, |
710 | | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
711 | | LIBCERROR_CONVERSION_ERROR_GENERIC, |
712 | | "%s: unable to set basename.", |
713 | | function ); |
714 | | |
715 | | return( -1 ); |
716 | | } |
717 | | #else |
718 | 0 | if( system_string_copy( |
719 | 0 | basename, |
720 | 0 | segment_table->basename, |
721 | 0 | segment_table->basename_size ) == NULL ) |
722 | 0 | { |
723 | 0 | libcerror_error_set( |
724 | 0 | error, |
725 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
726 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
727 | 0 | "%s: unable to set basename.", |
728 | 0 | function ); |
729 | |
|
730 | 0 | return( -1 ); |
731 | 0 | } |
732 | 0 | basename[ segment_table->basename_size - 1 ] = 0; |
733 | |
|
734 | 0 | #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ |
735 | |
|
736 | 0 | return( 1 ); |
737 | 0 | } |
738 | | |
739 | | /* Sets the basename |
740 | | * Returns 1 if successful or -1 on error |
741 | | */ |
742 | | int libewf_segment_table_set_basename( |
743 | | libewf_segment_table_t *segment_table, |
744 | | const char *basename, |
745 | | size_t basename_length, |
746 | | libcerror_error_t **error ) |
747 | 1.38k | { |
748 | 1.38k | static char *function = "libewf_segment_table_set_basename"; |
749 | | |
750 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
751 | | int result = 0; |
752 | | #endif |
753 | | |
754 | 1.38k | if( segment_table == NULL ) |
755 | 0 | { |
756 | 0 | libcerror_error_set( |
757 | 0 | error, |
758 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
759 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
760 | 0 | "%s: invalid segment table.", |
761 | 0 | function ); |
762 | |
|
763 | 0 | return( -1 ); |
764 | 0 | } |
765 | 1.38k | if( basename == NULL ) |
766 | 0 | { |
767 | 0 | libcerror_error_set( |
768 | 0 | error, |
769 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
770 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
771 | 0 | "%s: invalid basename.", |
772 | 0 | function ); |
773 | |
|
774 | 0 | return( -1 ); |
775 | 0 | } |
776 | 1.38k | if( segment_table->basename != NULL ) |
777 | 0 | { |
778 | 0 | memory_free( |
779 | 0 | segment_table->basename ); |
780 | |
|
781 | 0 | segment_table->basename = NULL; |
782 | 0 | segment_table->basename_size = 0; |
783 | 0 | } |
784 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
785 | | if( libclocale_codepage == 0 ) |
786 | | { |
787 | | #if SIZEOF_WCHAR_T == 4 |
788 | | result = libuna_utf32_string_size_from_utf8( |
789 | | (libuna_utf8_character_t *) basename, |
790 | | basename_length, |
791 | | &( segment_table->basename_size ), |
792 | | error ); |
793 | | #elif SIZEOF_WCHAR_T == 2 |
794 | | result = libuna_utf16_string_size_from_utf8( |
795 | | (libuna_utf8_character_t *) basename, |
796 | | basename_length, |
797 | | &( segment_table->basename_size ), |
798 | | error ); |
799 | | #else |
800 | | #error Unsupported size of wchar_t |
801 | | #endif /* SIZEOF_WCHAR_T */ |
802 | | } |
803 | | else |
804 | | { |
805 | | #if SIZEOF_WCHAR_T == 4 |
806 | | result = libuna_utf32_string_size_from_byte_stream( |
807 | | (uint8_t *) basename, |
808 | | basename_length, |
809 | | libclocale_codepage, |
810 | | &( segment_table->basename_size ), |
811 | | error ); |
812 | | #elif SIZEOF_WCHAR_T == 2 |
813 | | result = libuna_utf16_string_size_from_byte_stream( |
814 | | (uint8_t *) basename, |
815 | | basename_length, |
816 | | libclocale_codepage, |
817 | | &( segment_table->basename_size ), |
818 | | error ); |
819 | | #else |
820 | | #error Unsupported size of wchar_t |
821 | | #endif /* SIZEOF_WCHAR_T */ |
822 | | } |
823 | | if( result != 1 ) |
824 | | { |
825 | | libcerror_error_set( |
826 | | error, |
827 | | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
828 | | LIBCERROR_CONVERSION_ERROR_GENERIC, |
829 | | "%s: unable to determine basename size.", |
830 | | function ); |
831 | | |
832 | | return( -1 ); |
833 | | } |
834 | | #else |
835 | 1.38k | segment_table->basename_size = basename_length + 1; |
836 | 1.38k | #endif |
837 | 1.38k | segment_table->basename = system_string_allocate( |
838 | 1.38k | segment_table->basename_size ); |
839 | | |
840 | 1.38k | if( segment_table->basename == NULL ) |
841 | 0 | { |
842 | 0 | libcerror_error_set( |
843 | 0 | error, |
844 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
845 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
846 | 0 | "%s: unable to create basename.", |
847 | 0 | function ); |
848 | |
|
849 | 0 | segment_table->basename_size = 0; |
850 | |
|
851 | 0 | return( -1 ); |
852 | 0 | } |
853 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
854 | | if( libclocale_codepage == 0 ) |
855 | | { |
856 | | #if SIZEOF_WCHAR_T == 4 |
857 | | result = libuna_utf32_string_copy_from_utf8( |
858 | | (libuna_utf32_character_t *) segment_table->basename, |
859 | | segment_table->basename_size, |
860 | | (libuna_utf8_character_t *) basename, |
861 | | basename_length, |
862 | | error ); |
863 | | #elif SIZEOF_WCHAR_T == 2 |
864 | | result = libuna_utf16_string_copy_from_utf8( |
865 | | (libuna_utf16_character_t *) segment_table->basename, |
866 | | segment_table->basename_size, |
867 | | (libuna_utf8_character_t *) basename, |
868 | | basename_length, |
869 | | error ); |
870 | | #else |
871 | | #error Unsupported size of wchar_t |
872 | | #endif /* SIZEOF_WCHAR_T */ |
873 | | } |
874 | | else |
875 | | { |
876 | | #if SIZEOF_WCHAR_T == 4 |
877 | | result = libuna_utf32_string_copy_from_byte_stream( |
878 | | (libuna_utf32_character_t *) segment_table->basename, |
879 | | segment_table->basename_size, |
880 | | (uint8_t *) basename, |
881 | | basename_length, |
882 | | libclocale_codepage, |
883 | | error ); |
884 | | #elif SIZEOF_WCHAR_T == 2 |
885 | | result = libuna_utf16_string_copy_from_byte_stream( |
886 | | (libuna_utf16_character_t *) segment_table->basename, |
887 | | segment_table->basename_size, |
888 | | (uint8_t *) basename, |
889 | | basename_length, |
890 | | libclocale_codepage, |
891 | | error ); |
892 | | #else |
893 | | #error Unsupported size of wchar_t |
894 | | #endif /* SIZEOF_WCHAR_T */ |
895 | | } |
896 | | if( result != 1 ) |
897 | | { |
898 | | libcerror_error_set( |
899 | | error, |
900 | | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
901 | | LIBCERROR_CONVERSION_ERROR_GENERIC, |
902 | | "%s: unable to set basename.", |
903 | | function ); |
904 | | |
905 | | memory_free( |
906 | | segment_table->basename ); |
907 | | |
908 | | segment_table->basename = NULL; |
909 | | segment_table->basename_size = 0; |
910 | | |
911 | | return( -1 ); |
912 | | } |
913 | | #else |
914 | 1.38k | if( system_string_copy( |
915 | 1.38k | segment_table->basename, |
916 | 1.38k | basename, |
917 | 1.38k | basename_length ) == NULL ) |
918 | 0 | { |
919 | 0 | libcerror_error_set( |
920 | 0 | error, |
921 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
922 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
923 | 0 | "%s: unable to set basename.", |
924 | 0 | function ); |
925 | |
|
926 | 0 | memory_free( |
927 | 0 | segment_table->basename ); |
928 | |
|
929 | 0 | segment_table->basename = NULL; |
930 | 0 | segment_table->basename_size = 0; |
931 | |
|
932 | 0 | return( -1 ); |
933 | 0 | } |
934 | 1.38k | segment_table->basename[ basename_length ] = 0; |
935 | | |
936 | 1.38k | #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ |
937 | | |
938 | 1.38k | return( 1 ); |
939 | 1.38k | } |
940 | | |
941 | | #if defined( HAVE_WIDE_CHARACTER_TYPE ) |
942 | | |
943 | | /* Retrieves the size of the basename |
944 | | * Returns 1 if successful, 0 if not set or -1 on error |
945 | | */ |
946 | | int libewf_segment_table_get_basename_size_wide( |
947 | | libewf_segment_table_t *segment_table, |
948 | | size_t *basename_size, |
949 | | libcerror_error_t **error ) |
950 | | { |
951 | | static char *function = "libewf_segment_table_get_basename_size_wide"; |
952 | | |
953 | | #if !defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
954 | | int result = 0; |
955 | | #endif |
956 | | |
957 | | if( segment_table == NULL ) |
958 | | { |
959 | | libcerror_error_set( |
960 | | error, |
961 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
962 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
963 | | "%s: invalid segment table.", |
964 | | function ); |
965 | | |
966 | | return( -1 ); |
967 | | } |
968 | | if( basename_size == NULL ) |
969 | | { |
970 | | libcerror_error_set( |
971 | | error, |
972 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
973 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
974 | | "%s: invalid basename size.", |
975 | | function ); |
976 | | |
977 | | return( -1 ); |
978 | | } |
979 | | if( segment_table->basename == NULL ) |
980 | | { |
981 | | return( 0 ); |
982 | | } |
983 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
984 | | *basename_size = segment_table->basename_size; |
985 | | #else |
986 | | if( libclocale_codepage == 0 ) |
987 | | { |
988 | | #if SIZEOF_WCHAR_T == 4 |
989 | | result = libuna_utf32_string_size_from_utf8( |
990 | | (libuna_utf8_character_t *) segment_table->basename, |
991 | | segment_table->basename_size, |
992 | | basename_size, |
993 | | error ); |
994 | | #elif SIZEOF_WCHAR_T == 2 |
995 | | result = libuna_utf16_string_size_from_utf8( |
996 | | (libuna_utf8_character_t *) segment_table->basename, |
997 | | segment_table->basename_size, |
998 | | basename_size, |
999 | | error ); |
1000 | | #else |
1001 | | #error Unsupported size of wchar_t |
1002 | | #endif /* SIZEOF_WCHAR_T */ |
1003 | | } |
1004 | | else |
1005 | | { |
1006 | | #if SIZEOF_WCHAR_T == 4 |
1007 | | result = libuna_utf32_string_size_from_byte_stream( |
1008 | | (uint8_t *) segment_table->basename, |
1009 | | segment_table->basename_size, |
1010 | | libclocale_codepage, |
1011 | | basename_size, |
1012 | | error ); |
1013 | | #elif SIZEOF_WCHAR_T == 2 |
1014 | | result = libuna_utf16_string_size_from_byte_stream( |
1015 | | (uint8_t *) segment_table->basename, |
1016 | | segment_table->basename_size, |
1017 | | libclocale_codepage, |
1018 | | basename_size, |
1019 | | error ); |
1020 | | #else |
1021 | | #error Unsupported size of wchar_t |
1022 | | #endif /* SIZEOF_WCHAR_T */ |
1023 | | } |
1024 | | if( result != 1 ) |
1025 | | { |
1026 | | libcerror_error_set( |
1027 | | error, |
1028 | | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1029 | | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1030 | | "%s: unable to determine basename size.", |
1031 | | function ); |
1032 | | |
1033 | | return( -1 ); |
1034 | | } |
1035 | | #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ |
1036 | | return( 1 ); |
1037 | | } |
1038 | | |
1039 | | /* Retrieves the basename |
1040 | | * Returns 1 if successful, 0 if not set or -1 on error |
1041 | | */ |
1042 | | int libewf_segment_table_get_basename_wide( |
1043 | | libewf_segment_table_t *segment_table, |
1044 | | wchar_t *basename, |
1045 | | size_t basename_size, |
1046 | | libcerror_error_t **error ) |
1047 | | { |
1048 | | static char *function = "libewf_segment_table_get_basename_wide"; |
1049 | | size_t wide_basename_size = 0; |
1050 | | |
1051 | | #if !defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
1052 | | int result = 0; |
1053 | | #endif |
1054 | | |
1055 | | if( segment_table == NULL ) |
1056 | | { |
1057 | | libcerror_error_set( |
1058 | | error, |
1059 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1060 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1061 | | "%s: invalid segment table.", |
1062 | | function ); |
1063 | | |
1064 | | return( -1 ); |
1065 | | } |
1066 | | if( basename == NULL ) |
1067 | | { |
1068 | | libcerror_error_set( |
1069 | | error, |
1070 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1071 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1072 | | "%s: invalid basename.", |
1073 | | function ); |
1074 | | |
1075 | | return( -1 ); |
1076 | | } |
1077 | | if( segment_table->basename == NULL ) |
1078 | | { |
1079 | | return( 0 ); |
1080 | | } |
1081 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
1082 | | wide_basename_size = segment_table->basename_size; |
1083 | | #else |
1084 | | if( libclocale_codepage == 0 ) |
1085 | | { |
1086 | | #if SIZEOF_WCHAR_T == 4 |
1087 | | result = libuna_utf32_string_size_from_utf8( |
1088 | | (libuna_utf8_character_t *) segment_table->basename, |
1089 | | segment_table->basename_size, |
1090 | | &wide_basename_size, |
1091 | | error ); |
1092 | | #elif SIZEOF_WCHAR_T == 2 |
1093 | | result = libuna_utf16_string_size_from_utf8( |
1094 | | (libuna_utf8_character_t *) segment_table->basename, |
1095 | | segment_table->basename_size, |
1096 | | &wide_basename_size, |
1097 | | error ); |
1098 | | #else |
1099 | | #error Unsupported size of wchar_t |
1100 | | #endif /* SIZEOF_WCHAR_T */ |
1101 | | } |
1102 | | else |
1103 | | { |
1104 | | #if SIZEOF_WCHAR_T == 4 |
1105 | | result = libuna_utf32_string_size_from_byte_stream( |
1106 | | (uint8_t *) segment_table->basename, |
1107 | | segment_table->basename_size, |
1108 | | libclocale_codepage, |
1109 | | &wide_basename_size, |
1110 | | error ); |
1111 | | #elif SIZEOF_WCHAR_T == 2 |
1112 | | result = libuna_utf16_string_size_from_byte_stream( |
1113 | | (uint8_t *) segment_table->basename, |
1114 | | segment_table->basename_size, |
1115 | | libclocale_codepage, |
1116 | | &wide_basename_size, |
1117 | | error ); |
1118 | | #else |
1119 | | #error Unsupported size of wchar_t |
1120 | | #endif /* SIZEOF_WCHAR_T */ |
1121 | | } |
1122 | | if( result != 1 ) |
1123 | | { |
1124 | | libcerror_error_set( |
1125 | | error, |
1126 | | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1127 | | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1128 | | "%s: unable to determine basename size.", |
1129 | | function ); |
1130 | | |
1131 | | return( -1 ); |
1132 | | } |
1133 | | #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ |
1134 | | if( basename_size < wide_basename_size ) |
1135 | | { |
1136 | | libcerror_error_set( |
1137 | | error, |
1138 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1139 | | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
1140 | | "%s: basename too small.", |
1141 | | function ); |
1142 | | |
1143 | | return( -1 ); |
1144 | | } |
1145 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
1146 | | if( system_string_copy( |
1147 | | basename, |
1148 | | segment_table->basename, |
1149 | | segment_table->basename_size ) == NULL ) |
1150 | | { |
1151 | | libcerror_error_set( |
1152 | | error, |
1153 | | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1154 | | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
1155 | | "%s: unable to set basename.", |
1156 | | function ); |
1157 | | |
1158 | | return( -1 ); |
1159 | | } |
1160 | | basename[ segment_table->basename_size - 1 ] = 0; |
1161 | | #else |
1162 | | if( libclocale_codepage == 0 ) |
1163 | | { |
1164 | | #if SIZEOF_WCHAR_T == 4 |
1165 | | result = libuna_utf32_string_copy_from_utf8( |
1166 | | (libuna_utf32_character_t *) basename, |
1167 | | basename_size, |
1168 | | (libuna_utf8_character_t *) segment_table->basename, |
1169 | | segment_table->basename_size, |
1170 | | error ); |
1171 | | #elif SIZEOF_WCHAR_T == 2 |
1172 | | result = libuna_utf16_string_copy_from_utf8( |
1173 | | (libuna_utf16_character_t *) basename, |
1174 | | basename_size, |
1175 | | (libuna_utf8_character_t *) segment_table->basename, |
1176 | | segment_table->basename_size, |
1177 | | error ); |
1178 | | #else |
1179 | | #error Unsupported size of wchar_t |
1180 | | #endif /* SIZEOF_WCHAR_T */ |
1181 | | } |
1182 | | else |
1183 | | { |
1184 | | #if SIZEOF_WCHAR_T == 4 |
1185 | | result = libuna_utf32_string_copy_from_byte_stream( |
1186 | | (libuna_utf32_character_t *) basename, |
1187 | | basename_size, |
1188 | | (uint8_t *) segment_table->basename, |
1189 | | segment_table->basename_size, |
1190 | | libclocale_codepage, |
1191 | | error ); |
1192 | | #elif SIZEOF_WCHAR_T == 2 |
1193 | | result = libuna_utf16_string_copy_from_byte_stream( |
1194 | | (libuna_utf16_character_t *) basename, |
1195 | | basename_size, |
1196 | | (uint8_t *) segment_table->basename, |
1197 | | segment_table->basename_size, |
1198 | | libclocale_codepage, |
1199 | | error ); |
1200 | | #else |
1201 | | #error Unsupported size of wchar_t |
1202 | | #endif /* SIZEOF_WCHAR_T */ |
1203 | | } |
1204 | | if( result != 1 ) |
1205 | | { |
1206 | | libcerror_error_set( |
1207 | | error, |
1208 | | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1209 | | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1210 | | "%s: unable to set basename.", |
1211 | | function ); |
1212 | | |
1213 | | return( -1 ); |
1214 | | } |
1215 | | #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ |
1216 | | return( 1 ); |
1217 | | } |
1218 | | |
1219 | | /* Sets the basename |
1220 | | * Returns 1 if successful or -1 on error |
1221 | | */ |
1222 | | int libewf_segment_table_set_basename_wide( |
1223 | | libewf_segment_table_t *segment_table, |
1224 | | const wchar_t *basename, |
1225 | | size_t basename_length, |
1226 | | libcerror_error_t **error ) |
1227 | | { |
1228 | | static char *function = "libewf_segment_table_set_basename_wide"; |
1229 | | |
1230 | | #if !defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
1231 | | int result = 0; |
1232 | | #endif |
1233 | | |
1234 | | if( segment_table == NULL ) |
1235 | | { |
1236 | | libcerror_error_set( |
1237 | | error, |
1238 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1239 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1240 | | "%s: invalid segment table.", |
1241 | | function ); |
1242 | | |
1243 | | return( -1 ); |
1244 | | } |
1245 | | if( basename == NULL ) |
1246 | | { |
1247 | | libcerror_error_set( |
1248 | | error, |
1249 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1250 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1251 | | "%s: invalid basename.", |
1252 | | function ); |
1253 | | |
1254 | | return( -1 ); |
1255 | | } |
1256 | | if( segment_table->basename != NULL ) |
1257 | | { |
1258 | | memory_free( |
1259 | | segment_table->basename ); |
1260 | | |
1261 | | segment_table->basename = NULL; |
1262 | | segment_table->basename_size = 0; |
1263 | | } |
1264 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
1265 | | segment_table->basename_size = basename_length + 1; |
1266 | | #else |
1267 | | if( libclocale_codepage == 0 ) |
1268 | | { |
1269 | | #if SIZEOF_WCHAR_T == 4 |
1270 | | result = libuna_utf8_string_size_from_utf32( |
1271 | | (libuna_utf32_character_t *) basename, |
1272 | | basename_length, |
1273 | | &( segment_table->basename_size ), |
1274 | | error ); |
1275 | | #elif SIZEOF_WCHAR_T == 2 |
1276 | | result = libuna_utf8_string_size_from_utf16( |
1277 | | (libuna_utf16_character_t *) basename, |
1278 | | basename_length, |
1279 | | &( segment_table->basename_size ), |
1280 | | error ); |
1281 | | #else |
1282 | | #error Unsupported size of wchar_t |
1283 | | #endif /* SIZEOF_WCHAR_T */ |
1284 | | } |
1285 | | else |
1286 | | { |
1287 | | #if SIZEOF_WCHAR_T == 4 |
1288 | | result = libuna_byte_stream_size_from_utf32( |
1289 | | (libuna_utf32_character_t *) basename, |
1290 | | basename_length, |
1291 | | libclocale_codepage, |
1292 | | &( segment_table->basename_size ), |
1293 | | error ); |
1294 | | #elif SIZEOF_WCHAR_T == 2 |
1295 | | result = libuna_byte_stream_size_from_utf16( |
1296 | | (libuna_utf16_character_t *) basename, |
1297 | | basename_length, |
1298 | | libclocale_codepage, |
1299 | | &( segment_table->basename_size ), |
1300 | | error ); |
1301 | | #else |
1302 | | #error Unsupported size of wchar_t |
1303 | | #endif /* SIZEOF_WCHAR_T */ |
1304 | | } |
1305 | | if( result != 1 ) |
1306 | | { |
1307 | | libcerror_error_set( |
1308 | | error, |
1309 | | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1310 | | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1311 | | "%s: unable to determine basename size.", |
1312 | | function ); |
1313 | | |
1314 | | return( -1 ); |
1315 | | } |
1316 | | #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ |
1317 | | segment_table->basename = system_string_allocate( |
1318 | | segment_table->basename_size ); |
1319 | | |
1320 | | if( segment_table->basename == NULL ) |
1321 | | { |
1322 | | libcerror_error_set( |
1323 | | error, |
1324 | | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1325 | | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
1326 | | "%s: unable to create basename.", |
1327 | | function ); |
1328 | | |
1329 | | return( -1 ); |
1330 | | } |
1331 | | #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) |
1332 | | if( system_string_copy( |
1333 | | segment_table->basename, |
1334 | | basename, |
1335 | | basename_length ) == NULL ) |
1336 | | { |
1337 | | libcerror_error_set( |
1338 | | error, |
1339 | | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1340 | | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
1341 | | "%s: unable to set basename.", |
1342 | | function ); |
1343 | | |
1344 | | memory_free( |
1345 | | segment_table->basename ); |
1346 | | |
1347 | | segment_table->basename = NULL; |
1348 | | segment_table->basename_size = 0; |
1349 | | |
1350 | | return( -1 ); |
1351 | | } |
1352 | | segment_table->basename[ basename_length ] = 0; |
1353 | | #else |
1354 | | if( libclocale_codepage == 0 ) |
1355 | | { |
1356 | | #if SIZEOF_WCHAR_T == 4 |
1357 | | result = libuna_utf8_string_copy_from_utf32( |
1358 | | (libuna_utf8_character_t *) segment_table->basename, |
1359 | | segment_table->basename_size, |
1360 | | (libuna_utf32_character_t *) basename, |
1361 | | basename_length, |
1362 | | error ); |
1363 | | #elif SIZEOF_WCHAR_T == 2 |
1364 | | result = libuna_utf8_string_copy_from_utf16( |
1365 | | (libuna_utf8_character_t *) segment_table->basename, |
1366 | | segment_table->basename_size, |
1367 | | (libuna_utf16_character_t *) basename, |
1368 | | basename_length, |
1369 | | error ); |
1370 | | #else |
1371 | | #error Unsupported size of wchar_t |
1372 | | #endif /* SIZEOF_WCHAR_T */ |
1373 | | } |
1374 | | else |
1375 | | { |
1376 | | #if SIZEOF_WCHAR_T == 4 |
1377 | | result = libuna_byte_stream_copy_from_utf32( |
1378 | | (uint8_t *) segment_table->basename, |
1379 | | segment_table->basename_size, |
1380 | | libclocale_codepage, |
1381 | | (libuna_utf32_character_t *) basename, |
1382 | | basename_length, |
1383 | | error ); |
1384 | | #elif SIZEOF_WCHAR_T == 2 |
1385 | | result = libuna_byte_stream_copy_from_utf16( |
1386 | | (uint8_t *) segment_table->basename, |
1387 | | segment_table->basename_size, |
1388 | | libclocale_codepage, |
1389 | | (libuna_utf16_character_t *) basename, |
1390 | | basename_length, |
1391 | | error ); |
1392 | | #else |
1393 | | #error Unsupported size of wchar_t |
1394 | | #endif /* SIZEOF_WCHAR_T */ |
1395 | | } |
1396 | | if( result != 1 ) |
1397 | | { |
1398 | | libcerror_error_set( |
1399 | | error, |
1400 | | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1401 | | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1402 | | "%s: unable to set basename.", |
1403 | | function ); |
1404 | | |
1405 | | memory_free( |
1406 | | segment_table->basename ); |
1407 | | |
1408 | | segment_table->basename = NULL; |
1409 | | segment_table->basename_size = 0; |
1410 | | |
1411 | | return( -1 ); |
1412 | | } |
1413 | | #endif /* defined( HAVE_WIDE_SYSTEM_CHARACTER ) */ |
1414 | | |
1415 | | return( 1 ); |
1416 | | } |
1417 | | |
1418 | | #endif /* defined( HAVE_WIDE_CHARACTER_TYPE ) */ |
1419 | | |
1420 | | /* Sets the maximum segment size |
1421 | | * Returns 1 if successful or -1 on error |
1422 | | */ |
1423 | | int libewf_segment_table_set_maximum_segment_size( |
1424 | | libewf_segment_table_t *segment_table, |
1425 | | size64_t maximum_segment_size, |
1426 | | libcerror_error_t **error ) |
1427 | 0 | { |
1428 | 0 | static char *function = "libewf_segment_table_set_maximum_segment_size"; |
1429 | |
|
1430 | 0 | if( segment_table == NULL ) |
1431 | 0 | { |
1432 | 0 | libcerror_error_set( |
1433 | 0 | error, |
1434 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1435 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1436 | 0 | "%s: invalid segment table.", |
1437 | 0 | function ); |
1438 | |
|
1439 | 0 | return( -1 ); |
1440 | 0 | } |
1441 | 0 | segment_table->maximum_segment_size = maximum_segment_size; |
1442 | |
|
1443 | 0 | return( 1 ); |
1444 | 0 | } |
1445 | | |
1446 | | /* Retrieves the number of segments |
1447 | | * Returns 1 if successful or -1 on error |
1448 | | */ |
1449 | | int libewf_segment_table_get_number_of_segments( |
1450 | | libewf_segment_table_t *segment_table, |
1451 | | uint32_t *number_of_segments, |
1452 | | libcerror_error_t **error ) |
1453 | 5.58k | { |
1454 | 5.58k | static char *function = "libewf_segment_table_get_number_of_segments"; |
1455 | | |
1456 | 5.58k | if( segment_table == NULL ) |
1457 | 0 | { |
1458 | 0 | libcerror_error_set( |
1459 | 0 | error, |
1460 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1461 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1462 | 0 | "%s: invalid segment table.", |
1463 | 0 | function ); |
1464 | |
|
1465 | 0 | return( -1 ); |
1466 | 0 | } |
1467 | 5.58k | if( number_of_segments == NULL ) |
1468 | 0 | { |
1469 | 0 | libcerror_error_set( |
1470 | 0 | error, |
1471 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1472 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1473 | 0 | "%s: invalid number of segments.", |
1474 | 0 | function ); |
1475 | |
|
1476 | 0 | return( -1 ); |
1477 | 0 | } |
1478 | 5.58k | *number_of_segments = segment_table->number_of_segments; |
1479 | | |
1480 | 5.58k | return( 1 ); |
1481 | 5.58k | } |
1482 | | |
1483 | | /* Retrieves a specific segment from the segment table |
1484 | | * Returns 1 if successful or -1 on error |
1485 | | */ |
1486 | | int libewf_segment_table_get_segment_by_index( |
1487 | | libewf_segment_table_t *segment_table, |
1488 | | uint32_t segment_number, |
1489 | | int *file_io_pool_entry, |
1490 | | size64_t *segment_file_size, |
1491 | | libcerror_error_t **error ) |
1492 | 4.86k | { |
1493 | 4.86k | static char *function = "libewf_segment_table_get_segment_by_index"; |
1494 | 4.86k | off64_t element_offset = 0; |
1495 | 4.86k | uint32_t element_flags = 0; |
1496 | | |
1497 | 4.86k | if( segment_table == NULL ) |
1498 | 0 | { |
1499 | 0 | libcerror_error_set( |
1500 | 0 | error, |
1501 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1502 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1503 | 0 | "%s: invalid segment table.", |
1504 | 0 | function ); |
1505 | |
|
1506 | 0 | return( -1 ); |
1507 | 0 | } |
1508 | 4.86k | #if SIZEOF_INT <= 4 |
1509 | 4.86k | if( segment_number > (uint32_t) INT_MAX ) |
1510 | 0 | { |
1511 | 0 | libcerror_error_set( |
1512 | 0 | error, |
1513 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1514 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1515 | 0 | "%s: invalid segment number value out of bounds.", |
1516 | 0 | function ); |
1517 | |
|
1518 | 0 | return( -1 ); |
1519 | 0 | } |
1520 | 4.86k | #endif |
1521 | 4.86k | if( libfdata_list_get_element_by_index( |
1522 | 4.86k | segment_table->segment_files_list, |
1523 | 4.86k | (int) segment_number, |
1524 | 4.86k | file_io_pool_entry, |
1525 | 4.86k | &element_offset, |
1526 | 4.86k | segment_file_size, |
1527 | 4.86k | &element_flags, |
1528 | 4.86k | error ) != 1 ) |
1529 | 0 | { |
1530 | 0 | libcerror_error_set( |
1531 | 0 | error, |
1532 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1533 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1534 | 0 | "%s: unable to retrieve element: %" PRIu32 " from segment files list.", |
1535 | 0 | function, |
1536 | 0 | segment_number ); |
1537 | |
|
1538 | 0 | return( -1 ); |
1539 | 0 | } |
1540 | 4.86k | return( 1 ); |
1541 | 4.86k | } |
1542 | | |
1543 | | /* Retrieves a segment at a specific offset from the segment table |
1544 | | * Returns 1 if successful, 0 if not or -1 on error |
1545 | | */ |
1546 | | int libewf_segment_table_get_segment_at_offset( |
1547 | | libewf_segment_table_t *segment_table, |
1548 | | off64_t offset, |
1549 | | int *file_io_pool_entry, |
1550 | | size64_t *segment_file_size, |
1551 | | libcerror_error_t **error ) |
1552 | 0 | { |
1553 | 0 | static char *function = "libewf_segment_table_get_segment_at_offset"; |
1554 | 0 | off64_t element_offset = 0; |
1555 | 0 | off64_t segment_file_data_offset = 0; |
1556 | 0 | uint32_t element_flags = 0; |
1557 | 0 | int result = 0; |
1558 | 0 | int segment_number = 0; |
1559 | |
|
1560 | 0 | if( segment_table == NULL ) |
1561 | 0 | { |
1562 | 0 | libcerror_error_set( |
1563 | 0 | error, |
1564 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1565 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1566 | 0 | "%s: invalid segment table.", |
1567 | 0 | function ); |
1568 | |
|
1569 | 0 | return( -1 ); |
1570 | 0 | } |
1571 | 0 | result = libfdata_list_get_element_at_offset( |
1572 | 0 | segment_table->segment_files_list, |
1573 | 0 | offset, |
1574 | 0 | &segment_number, |
1575 | 0 | &segment_file_data_offset, |
1576 | 0 | file_io_pool_entry, |
1577 | 0 | &element_offset, |
1578 | 0 | segment_file_size, |
1579 | 0 | &element_flags, |
1580 | 0 | error ); |
1581 | |
|
1582 | 0 | if( result == -1 ) |
1583 | 0 | { |
1584 | 0 | libcerror_error_set( |
1585 | 0 | error, |
1586 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1587 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1588 | 0 | "%s: unable to retrieve element at offset: %" PRIi64 " (0x%08" PRIx64 ") from segment files list.", |
1589 | 0 | function, |
1590 | 0 | offset, |
1591 | 0 | offset ); |
1592 | |
|
1593 | 0 | return( -1 ); |
1594 | 0 | } |
1595 | 0 | return( result ); |
1596 | 0 | } |
1597 | | |
1598 | | /* Retrieves the segment storage media size for a specific segment in the segment table |
1599 | | * Returns 1 if successful, 0 if not set or -1 on error |
1600 | | */ |
1601 | | int libewf_segment_table_get_segment_storage_media_size_by_index( |
1602 | | libewf_segment_table_t *segment_table, |
1603 | | uint32_t segment_number, |
1604 | | size64_t *storage_media_size, |
1605 | | libcerror_error_t **error ) |
1606 | 0 | { |
1607 | 0 | static char *function = "libewf_segment_table_get_segment_storage_media_size_by_index"; |
1608 | 0 | int result = 0; |
1609 | |
|
1610 | 0 | if( segment_table == NULL ) |
1611 | 0 | { |
1612 | 0 | libcerror_error_set( |
1613 | 0 | error, |
1614 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1615 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1616 | 0 | "%s: invalid segment table.", |
1617 | 0 | function ); |
1618 | |
|
1619 | 0 | return( -1 ); |
1620 | 0 | } |
1621 | 0 | #if SIZEOF_INT <= 4 |
1622 | 0 | if( segment_number > (uint32_t) INT_MAX ) |
1623 | 0 | { |
1624 | 0 | libcerror_error_set( |
1625 | 0 | error, |
1626 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1627 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1628 | 0 | "%s: invalid segment number value out of bounds.", |
1629 | 0 | function ); |
1630 | |
|
1631 | 0 | return( -1 ); |
1632 | 0 | } |
1633 | 0 | #endif |
1634 | 0 | result = libfdata_list_get_mapped_size_by_index( |
1635 | 0 | segment_table->segment_files_list, |
1636 | 0 | (int) segment_number, |
1637 | 0 | storage_media_size, |
1638 | 0 | error ); |
1639 | |
|
1640 | 0 | if( result == -1 ) |
1641 | 0 | { |
1642 | 0 | libcerror_error_set( |
1643 | 0 | error, |
1644 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1645 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1646 | 0 | "%s: unable to get mapped size of element: %" PRIu32 " in segment files list.", |
1647 | 0 | function, |
1648 | 0 | segment_number ); |
1649 | |
|
1650 | 0 | return( -1 ); |
1651 | 0 | } |
1652 | 0 | return( result ); |
1653 | 0 | } |
1654 | | |
1655 | | /* Sets the segment storage media size for a specific segment in the segment table |
1656 | | * Returns 1 if successful or -1 on error |
1657 | | */ |
1658 | | int libewf_segment_table_set_segment_storage_media_size_by_index( |
1659 | | libewf_segment_table_t *segment_table, |
1660 | | uint32_t segment_number, |
1661 | | size64_t storage_media_size, |
1662 | | libcerror_error_t **error ) |
1663 | 1.52k | { |
1664 | 1.52k | static char *function = "libewf_segment_table_set_segment_storage_media_size_by_index"; |
1665 | | |
1666 | 1.52k | if( segment_table == NULL ) |
1667 | 0 | { |
1668 | 0 | libcerror_error_set( |
1669 | 0 | error, |
1670 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1671 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1672 | 0 | "%s: invalid segment table.", |
1673 | 0 | function ); |
1674 | |
|
1675 | 0 | return( -1 ); |
1676 | 0 | } |
1677 | 1.52k | #if SIZEOF_INT <= 4 |
1678 | 1.52k | if( segment_number > (uint32_t) INT_MAX ) |
1679 | 0 | { |
1680 | 0 | libcerror_error_set( |
1681 | 0 | error, |
1682 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1683 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1684 | 0 | "%s: invalid segment number value out of bounds.", |
1685 | 0 | function ); |
1686 | |
|
1687 | 0 | return( -1 ); |
1688 | 0 | } |
1689 | 1.52k | #endif |
1690 | 1.52k | if( libfdata_list_set_mapped_size_by_index( |
1691 | 1.52k | segment_table->segment_files_list, |
1692 | 1.52k | (int) segment_number, |
1693 | 1.52k | storage_media_size, |
1694 | 1.52k | error ) != 1 ) |
1695 | 0 | { |
1696 | 0 | libcerror_error_set( |
1697 | 0 | error, |
1698 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1699 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1700 | 0 | "%s: unable to set mapped size of element: %" PRIu32 " in segment files list.", |
1701 | 0 | function, |
1702 | 0 | segment_number ); |
1703 | |
|
1704 | 0 | return( -1 ); |
1705 | 0 | } |
1706 | 1.52k | return( 1 ); |
1707 | 1.52k | } |
1708 | | |
1709 | | /* Retrieves a specific segment file from the segment table |
1710 | | * Returns 1 if successful or -1 on error |
1711 | | */ |
1712 | | int libewf_segment_table_get_segment_file_by_index( |
1713 | | libewf_segment_table_t *segment_table, |
1714 | | uint32_t segment_number, |
1715 | | libbfio_pool_t *file_io_pool, |
1716 | | libewf_segment_file_t **segment_file, |
1717 | | libcerror_error_t **error ) |
1718 | 10.8k | { |
1719 | 10.8k | static char *function = "libewf_segment_table_get_segment_file_by_index"; |
1720 | | |
1721 | 10.8k | if( segment_table == NULL ) |
1722 | 0 | { |
1723 | 0 | libcerror_error_set( |
1724 | 0 | error, |
1725 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1726 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1727 | 0 | "%s: invalid segment table.", |
1728 | 0 | function ); |
1729 | |
|
1730 | 0 | return( -1 ); |
1731 | 0 | } |
1732 | 10.8k | #if SIZEOF_INT <= 4 |
1733 | 10.8k | if( segment_number > (uint32_t) INT_MAX ) |
1734 | 0 | { |
1735 | 0 | libcerror_error_set( |
1736 | 0 | error, |
1737 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1738 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1739 | 0 | "%s: invalid segment number value out of bounds.", |
1740 | 0 | function ); |
1741 | |
|
1742 | 0 | return( -1 ); |
1743 | 0 | } |
1744 | 10.8k | #endif |
1745 | 10.8k | if( segment_file == NULL ) |
1746 | 0 | { |
1747 | 0 | libcerror_error_set( |
1748 | 0 | error, |
1749 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1750 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1751 | 0 | "%s: invalid segment file.", |
1752 | 0 | function ); |
1753 | |
|
1754 | 0 | return( -1 ); |
1755 | 0 | } |
1756 | 10.8k | if( libfdata_list_get_element_value_by_index( |
1757 | 10.8k | segment_table->segment_files_list, |
1758 | 10.8k | (intptr_t *) file_io_pool, |
1759 | 10.8k | (libfdata_cache_t *) segment_table->segment_files_cache, |
1760 | 10.8k | (int) segment_number, |
1761 | 10.8k | (intptr_t **) &( segment_table->current_segment_file ), |
1762 | 10.8k | 0, |
1763 | 10.8k | error ) != 1 ) |
1764 | 284 | { |
1765 | 284 | libcerror_error_set( |
1766 | 284 | error, |
1767 | 284 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1768 | 284 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1769 | 284 | "%s: unable to retrieve element value: %" PRIu32 " from segment files list.", |
1770 | 284 | function, |
1771 | 284 | segment_number ); |
1772 | | |
1773 | 284 | return( -1 ); |
1774 | 284 | } |
1775 | 10.6k | if( segment_table->current_segment_file == NULL ) |
1776 | 0 | { |
1777 | 0 | libcerror_error_set( |
1778 | 0 | error, |
1779 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1780 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1781 | 0 | "%s: missing segment file.", |
1782 | 0 | function ); |
1783 | |
|
1784 | 0 | return( -1 ); |
1785 | 0 | } |
1786 | 10.6k | if( ( (int64_t) segment_number + 1 ) != (int64_t) segment_table->current_segment_file->segment_number ) |
1787 | 0 | { |
1788 | 0 | libcerror_error_set( |
1789 | 0 | error, |
1790 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1791 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1792 | 0 | "%s: invalid segment number value out of bounds.", |
1793 | 0 | function ); |
1794 | |
|
1795 | 0 | return( -1 ); |
1796 | 0 | } |
1797 | 10.6k | if( libfdata_list_get_element_mapped_range( |
1798 | 10.6k | segment_table->segment_files_list, |
1799 | 10.6k | segment_number, |
1800 | 10.6k | &( segment_table->current_segment_file->range_start_offset ), |
1801 | 10.6k | (size64_t *) &( segment_table->current_segment_file->range_end_offset ), |
1802 | 10.6k | error ) != 1 ) |
1803 | 0 | { |
1804 | 0 | libcerror_error_set( |
1805 | 0 | error, |
1806 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1807 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1808 | 0 | "%s: unable to retrieve segment files list element: %" PRIu32 " mapped range.", |
1809 | 0 | function, |
1810 | 0 | segment_number ); |
1811 | |
|
1812 | 0 | return( -1 ); |
1813 | 0 | } |
1814 | 10.6k | segment_table->current_segment_file->range_end_offset += segment_table->current_segment_file->range_start_offset; |
1815 | | |
1816 | 10.6k | *segment_file = segment_table->current_segment_file; |
1817 | | |
1818 | 10.6k | return( 1 ); |
1819 | 10.6k | } |
1820 | | |
1821 | | /* Retrieves a segment file at a specific offset from the segment table |
1822 | | * Returns 1 if successful, 0 if not or -1 on error |
1823 | | */ |
1824 | | int libewf_segment_table_get_segment_file_at_offset( |
1825 | | libewf_segment_table_t *segment_table, |
1826 | | off64_t offset, |
1827 | | libbfio_pool_t *file_io_pool, |
1828 | | uint32_t *segment_number, |
1829 | | off64_t *segment_file_data_offset, |
1830 | | libewf_segment_file_t **segment_file, |
1831 | | libcerror_error_t **error ) |
1832 | 498 | { |
1833 | 498 | static char *function = "libewf_segment_table_get_segment_file_at_offset"; |
1834 | 498 | off64_t safe_segment_file_data_offset = 0; |
1835 | 498 | int result = 0; |
1836 | 498 | int segment_files_list_index = 0; |
1837 | | |
1838 | 498 | if( segment_table == NULL ) |
1839 | 0 | { |
1840 | 0 | libcerror_error_set( |
1841 | 0 | error, |
1842 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1843 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1844 | 0 | "%s: invalid segment table.", |
1845 | 0 | function ); |
1846 | |
|
1847 | 0 | return( -1 ); |
1848 | 0 | } |
1849 | 498 | if( segment_number == NULL ) |
1850 | 0 | { |
1851 | 0 | libcerror_error_set( |
1852 | 0 | error, |
1853 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1854 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1855 | 0 | "%s: invalid segment number.", |
1856 | 0 | function ); |
1857 | |
|
1858 | 0 | return( -1 ); |
1859 | 0 | } |
1860 | 498 | if( segment_file_data_offset == NULL ) |
1861 | 0 | { |
1862 | 0 | libcerror_error_set( |
1863 | 0 | error, |
1864 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1865 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1866 | 0 | "%s: invalid segment file data offset.", |
1867 | 0 | function ); |
1868 | |
|
1869 | 0 | return( -1 ); |
1870 | 0 | } |
1871 | 498 | if( segment_file == NULL ) |
1872 | 0 | { |
1873 | 0 | libcerror_error_set( |
1874 | 0 | error, |
1875 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1876 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1877 | 0 | "%s: invalid segment file.", |
1878 | 0 | function ); |
1879 | |
|
1880 | 0 | return( -1 ); |
1881 | 0 | } |
1882 | 498 | if( ( segment_table->current_segment_file != NULL ) |
1883 | 498 | && ( segment_table->current_segment_file->range_end_offset > 0 ) ) |
1884 | 498 | { |
1885 | 498 | if( ( offset >= segment_table->current_segment_file->range_start_offset ) |
1886 | 498 | && ( offset < segment_table->current_segment_file->range_end_offset ) ) |
1887 | 498 | { |
1888 | 498 | safe_segment_file_data_offset = offset - segment_table->current_segment_file->range_start_offset; |
1889 | | |
1890 | 498 | result = 1; |
1891 | 498 | } |
1892 | 498 | } |
1893 | 498 | if( result == 0 ) |
1894 | 0 | { |
1895 | 0 | result = libfdata_list_get_element_value_at_offset( |
1896 | 0 | segment_table->segment_files_list, |
1897 | 0 | (intptr_t *) file_io_pool, |
1898 | 0 | (libfdata_cache_t *) segment_table->segment_files_cache, |
1899 | 0 | offset, |
1900 | 0 | &segment_files_list_index, |
1901 | 0 | &safe_segment_file_data_offset, |
1902 | 0 | (intptr_t **) &( segment_table->current_segment_file ), |
1903 | 0 | 0, |
1904 | 0 | error ); |
1905 | |
|
1906 | 0 | if( result == -1 ) |
1907 | 0 | { |
1908 | 0 | libcerror_error_set( |
1909 | 0 | error, |
1910 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1911 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1912 | 0 | "%s: unable to retrieve segment file for offset: %" PRIi64 " (0x%08" PRIx64 ").", |
1913 | 0 | function, |
1914 | 0 | offset, |
1915 | 0 | offset ); |
1916 | |
|
1917 | 0 | return( -1 ); |
1918 | 0 | } |
1919 | 0 | else if( result != 0 ) |
1920 | 0 | { |
1921 | 0 | if( segment_table->current_segment_file == NULL ) |
1922 | 0 | { |
1923 | 0 | libcerror_error_set( |
1924 | 0 | error, |
1925 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1926 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1927 | 0 | "%s: missing segment file.", |
1928 | 0 | function ); |
1929 | |
|
1930 | 0 | return( -1 ); |
1931 | 0 | } |
1932 | 0 | if( ( (int64_t) segment_files_list_index + 1 ) != (int64_t) segment_table->current_segment_file->segment_number ) |
1933 | 0 | { |
1934 | 0 | libcerror_error_set( |
1935 | 0 | error, |
1936 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1937 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1938 | 0 | "%s: invalid segment number value out of bounds.", |
1939 | 0 | function ); |
1940 | |
|
1941 | 0 | return( -1 ); |
1942 | 0 | } |
1943 | 0 | if( libfdata_list_get_element_mapped_range( |
1944 | 0 | segment_table->segment_files_list, |
1945 | 0 | segment_files_list_index, |
1946 | 0 | &( segment_table->current_segment_file->range_start_offset ), |
1947 | 0 | (size64_t *) &( segment_table->current_segment_file->range_end_offset ), |
1948 | 0 | error ) != 1 ) |
1949 | 0 | { |
1950 | 0 | libcerror_error_set( |
1951 | 0 | error, |
1952 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1953 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1954 | 0 | "%s: unable to retrieve segment files list element: %d mapped range.", |
1955 | 0 | function, |
1956 | 0 | segment_files_list_index ); |
1957 | |
|
1958 | 0 | return( -1 ); |
1959 | 0 | } |
1960 | 0 | segment_table->current_segment_file->range_end_offset += segment_table->current_segment_file->range_start_offset; |
1961 | 0 | } |
1962 | 0 | } |
1963 | 498 | if( result != 0 ) |
1964 | 498 | { |
1965 | 498 | *segment_number = segment_table->current_segment_file->segment_number - 1; |
1966 | 498 | *segment_file_data_offset = safe_segment_file_data_offset; |
1967 | 498 | *segment_file = segment_table->current_segment_file; |
1968 | 498 | } |
1969 | 498 | return( result ); |
1970 | 498 | } |
1971 | | |
1972 | | /* Appends a segment to the segment table based on the segment file |
1973 | | * Returns 1 if successful or -1 on error |
1974 | | */ |
1975 | | int libewf_segment_table_append_segment_by_segment_file( |
1976 | | libewf_segment_table_t *segment_table, |
1977 | | libewf_segment_file_t *segment_file, |
1978 | | int file_io_pool_entry, |
1979 | | size64_t segment_file_size, |
1980 | | libcerror_error_t **error ) |
1981 | 6.70k | { |
1982 | 6.70k | static char *function = "libewf_segment_table_append_segment_by_segment_file"; |
1983 | | |
1984 | 6.70k | if( segment_table == NULL ) |
1985 | 0 | { |
1986 | 0 | libcerror_error_set( |
1987 | 0 | error, |
1988 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1989 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1990 | 0 | "%s: invalid segment table.", |
1991 | 0 | function ); |
1992 | |
|
1993 | 0 | return( -1 ); |
1994 | 0 | } |
1995 | 6.70k | if( segment_file == NULL ) |
1996 | 0 | { |
1997 | 0 | libcerror_error_set( |
1998 | 0 | error, |
1999 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2000 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2001 | 0 | "%s: invalid segment file.", |
2002 | 0 | function ); |
2003 | |
|
2004 | 0 | return( -1 ); |
2005 | 0 | } |
2006 | 6.70k | #if SIZEOF_INT <= 4 |
2007 | 6.70k | if( segment_file->segment_number > (uint32_t) INT_MAX ) |
2008 | 93 | { |
2009 | 93 | libcerror_error_set( |
2010 | 93 | error, |
2011 | 93 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2012 | 93 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
2013 | 93 | "%s: invalid segment file - segment number value out of bounds.", |
2014 | 93 | function ); |
2015 | | |
2016 | 93 | return( -1 ); |
2017 | 93 | } |
2018 | 6.61k | #endif |
2019 | 6.61k | if( segment_file->segment_number > segment_table->number_of_segments ) |
2020 | 6.61k | { |
2021 | 6.61k | if( libfdata_list_resize( |
2022 | 6.61k | segment_table->segment_files_list, |
2023 | 6.61k | (int) segment_file->segment_number, |
2024 | 6.61k | error ) != 1 ) |
2025 | 118 | { |
2026 | 118 | libcerror_error_set( |
2027 | 118 | error, |
2028 | 118 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2029 | 118 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
2030 | 118 | "%s: unable to resize segment files list.", |
2031 | 118 | function ); |
2032 | | |
2033 | 118 | return( -1 ); |
2034 | 118 | } |
2035 | 6.49k | segment_table->number_of_segments = segment_file->segment_number; |
2036 | 6.49k | } |
2037 | 6.49k | if( libfdata_list_set_element_by_index( |
2038 | 6.49k | segment_table->segment_files_list, |
2039 | 6.49k | (int) ( segment_file->segment_number - 1 ), |
2040 | 6.49k | file_io_pool_entry, |
2041 | 6.49k | 0, |
2042 | 6.49k | segment_file_size, |
2043 | 6.49k | 0, |
2044 | 6.49k | error ) != 1 ) |
2045 | 0 | { |
2046 | 0 | libcerror_error_set( |
2047 | 0 | error, |
2048 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2049 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2050 | 0 | "%s: unable to set element: %" PRIu32 " in segment files list.", |
2051 | 0 | function, |
2052 | 0 | segment_file->segment_number ); |
2053 | |
|
2054 | 0 | return( -1 ); |
2055 | 0 | } |
2056 | 6.49k | return( 1 ); |
2057 | 6.49k | } |
2058 | | |