/src/libpff/libfdata/libfdata_list.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * The list functions |
3 | | * |
4 | | * Copyright (C) 2010-2024, 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 <types.h> |
25 | | |
26 | | #include "libfdata_definitions.h" |
27 | | #include "libfdata_libcdata.h" |
28 | | #include "libfdata_libcerror.h" |
29 | | #include "libfdata_libcnotify.h" |
30 | | #include "libfdata_libfcache.h" |
31 | | #include "libfdata_list.h" |
32 | | #include "libfdata_list_element.h" |
33 | | #include "libfdata_mapped_range.h" |
34 | | #include "libfdata_range.h" |
35 | | #include "libfdata_types.h" |
36 | | #include "libfdata_unused.h" |
37 | | |
38 | | /* Creates a list |
39 | | * Make sure the value list is referencing, is set to NULL |
40 | | * |
41 | | * If the flag LIBFDATA_DATA_HANDLE_FLAG_MANAGED is set the list |
42 | | * takes over management of the data handle and the data handle is freed when |
43 | | * no longer needed |
44 | | * |
45 | | * Returns 1 if successful or -1 on error |
46 | | */ |
47 | | int libfdata_list_initialize( |
48 | | libfdata_list_t **list, |
49 | | intptr_t *data_handle, |
50 | | int (*free_data_handle)( |
51 | | intptr_t **data_handle, |
52 | | libcerror_error_t **error ), |
53 | | int (*clone_data_handle)( |
54 | | intptr_t **destination_data_handle, |
55 | | intptr_t *source_data_handle, |
56 | | libcerror_error_t **error ), |
57 | | int (*read_element_data)( |
58 | | intptr_t *data_handle, |
59 | | intptr_t *file_io_handle, |
60 | | libfdata_list_element_t *list_element, |
61 | | libfdata_cache_t *cache, |
62 | | int element_data_file_index, |
63 | | off64_t element_data_offset, |
64 | | size64_t element_data_size, |
65 | | uint32_t element_data_flags, |
66 | | uint8_t read_flags, |
67 | | libcerror_error_t **error ), |
68 | | int (*write_element_data)( |
69 | | intptr_t *data_handle, |
70 | | intptr_t *file_io_handle, |
71 | | libfdata_list_element_t *list_element, |
72 | | libfdata_cache_t *cache, |
73 | | int element_data_file_index, |
74 | | off64_t element_data_offset, |
75 | | size64_t element_data_size, |
76 | | uint32_t element_data_flags, |
77 | | uint8_t write_flags, |
78 | | libcerror_error_t **error ), |
79 | | uint8_t flags, |
80 | | libcerror_error_t **error ) |
81 | 48.8k | { |
82 | 48.8k | libfdata_internal_list_t *internal_list = NULL; |
83 | 48.8k | static char *function = "libfdata_list_initialize"; |
84 | | |
85 | 48.8k | if( list == NULL ) |
86 | 0 | { |
87 | 0 | libcerror_error_set( |
88 | 0 | error, |
89 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
90 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
91 | 0 | "%s: invalid list.", |
92 | 0 | function ); |
93 | |
|
94 | 0 | return( -1 ); |
95 | 0 | } |
96 | 48.8k | if( *list != NULL ) |
97 | 0 | { |
98 | 0 | libcerror_error_set( |
99 | 0 | error, |
100 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
101 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
102 | 0 | "%s: invalid list value already set.", |
103 | 0 | function ); |
104 | |
|
105 | 0 | return( -1 ); |
106 | 0 | } |
107 | 48.8k | if( ( flags & 0xfe ) != 0 ) |
108 | 0 | { |
109 | 0 | libcerror_error_set( |
110 | 0 | error, |
111 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
112 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
113 | 0 | "%s: unsupported flags: 0x%02" PRIx8 ".", |
114 | 0 | function ); |
115 | |
|
116 | 0 | return( -1 ); |
117 | 0 | } |
118 | 48.8k | internal_list = memory_allocate_structure( |
119 | 48.8k | libfdata_internal_list_t ); |
120 | | |
121 | 48.8k | if( internal_list == NULL ) |
122 | 0 | { |
123 | 0 | libcerror_error_set( |
124 | 0 | error, |
125 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
126 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
127 | 0 | "%s: unable to create list.", |
128 | 0 | function ); |
129 | |
|
130 | 0 | goto on_error; |
131 | 0 | } |
132 | 48.8k | if( memory_set( |
133 | 48.8k | internal_list, |
134 | 48.8k | 0, |
135 | 48.8k | sizeof( libfdata_internal_list_t ) ) == NULL ) |
136 | 0 | { |
137 | 0 | libcerror_error_set( |
138 | 0 | error, |
139 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
140 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
141 | 0 | "%s: unable to clear list.", |
142 | 0 | function ); |
143 | |
|
144 | 0 | memory_free( |
145 | 0 | internal_list ); |
146 | |
|
147 | 0 | return( -1 ); |
148 | 0 | } |
149 | 48.8k | if( libcdata_array_initialize( |
150 | 48.8k | &( internal_list->elements_array ), |
151 | 48.8k | 0, |
152 | 48.8k | error ) != 1 ) |
153 | 0 | { |
154 | 0 | libcerror_error_set( |
155 | 0 | error, |
156 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
157 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
158 | 0 | "%s: unable to create elements array.", |
159 | 0 | function ); |
160 | |
|
161 | 0 | goto on_error; |
162 | 0 | } |
163 | 48.8k | if( libcdata_array_initialize( |
164 | 48.8k | &( internal_list->mapped_ranges_array ), |
165 | 48.8k | 0, |
166 | 48.8k | error ) != 1 ) |
167 | 0 | { |
168 | 0 | libcerror_error_set( |
169 | 0 | error, |
170 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
171 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
172 | 0 | "%s: unable to create mapped ranges array.", |
173 | 0 | function ); |
174 | |
|
175 | 0 | goto on_error; |
176 | 0 | } |
177 | 48.8k | internal_list->flags |= flags; |
178 | 48.8k | internal_list->data_handle = data_handle; |
179 | 48.8k | internal_list->free_data_handle = free_data_handle; |
180 | 48.8k | internal_list->clone_data_handle = clone_data_handle; |
181 | 48.8k | internal_list->read_element_data = read_element_data; |
182 | 48.8k | internal_list->write_element_data = write_element_data; |
183 | | |
184 | 48.8k | *list = (libfdata_list_t *) internal_list; |
185 | | |
186 | 48.8k | return( 1 ); |
187 | | |
188 | 0 | on_error: |
189 | 0 | if( internal_list != NULL ) |
190 | 0 | { |
191 | 0 | if( internal_list->elements_array != NULL ) |
192 | 0 | { |
193 | 0 | libcdata_array_free( |
194 | 0 | &( internal_list->elements_array ), |
195 | 0 | NULL, |
196 | 0 | NULL ); |
197 | 0 | } |
198 | 0 | memory_free( |
199 | 0 | internal_list ); |
200 | 0 | } |
201 | 0 | return( -1 ); |
202 | 48.8k | } |
203 | | |
204 | | /* Frees a list |
205 | | * Returns 1 if successful or -1 on error |
206 | | */ |
207 | | int libfdata_list_free( |
208 | | libfdata_list_t **list, |
209 | | libcerror_error_t **error ) |
210 | 48.8k | { |
211 | 48.8k | libfdata_internal_list_t *internal_list = NULL; |
212 | 48.8k | static char *function = "libfdata_list_free"; |
213 | 48.8k | int result = 1; |
214 | | |
215 | 48.8k | if( list == NULL ) |
216 | 0 | { |
217 | 0 | libcerror_error_set( |
218 | 0 | error, |
219 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
220 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
221 | 0 | "%s: invalid list.", |
222 | 0 | function ); |
223 | |
|
224 | 0 | return( -1 ); |
225 | 0 | } |
226 | 48.8k | if( *list != NULL ) |
227 | 48.8k | { |
228 | 48.8k | internal_list = (libfdata_internal_list_t *) *list; |
229 | 48.8k | *list = NULL; |
230 | | |
231 | 48.8k | if( libcdata_array_free( |
232 | 48.8k | &( internal_list->elements_array ), |
233 | 48.8k | (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_list_element_free, |
234 | 48.8k | error ) != 1 ) |
235 | 0 | { |
236 | 0 | libcerror_error_set( |
237 | 0 | error, |
238 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
239 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
240 | 0 | "%s: unable to free the elements array.", |
241 | 0 | function ); |
242 | |
|
243 | 0 | result = -1; |
244 | 0 | } |
245 | 48.8k | if( libcdata_array_free( |
246 | 48.8k | &( internal_list->mapped_ranges_array ), |
247 | 48.8k | (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_mapped_range_free, |
248 | 48.8k | error ) != 1 ) |
249 | 0 | { |
250 | 0 | libcerror_error_set( |
251 | 0 | error, |
252 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
253 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
254 | 0 | "%s: unable to free the mapped ranges array.", |
255 | 0 | function ); |
256 | |
|
257 | 0 | result = -1; |
258 | 0 | } |
259 | 48.8k | if( ( internal_list->flags & LIBFDATA_DATA_HANDLE_FLAG_MANAGED ) != 0 ) |
260 | 11.7k | { |
261 | 11.7k | if( internal_list->data_handle != NULL ) |
262 | 11.7k | { |
263 | 11.7k | if( internal_list->free_data_handle == NULL ) |
264 | 0 | { |
265 | 0 | libcerror_error_set( |
266 | 0 | error, |
267 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
268 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
269 | 0 | "%s: invalid list - missing free data handle function.", |
270 | 0 | function ); |
271 | |
|
272 | 0 | result = -1; |
273 | 0 | } |
274 | 11.7k | else if( internal_list->free_data_handle( |
275 | 11.7k | &( internal_list->data_handle ), |
276 | 11.7k | error ) != 1 ) |
277 | 0 | { |
278 | 0 | libcerror_error_set( |
279 | 0 | error, |
280 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
281 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
282 | 0 | "%s: unable to free data handle.", |
283 | 0 | function ); |
284 | |
|
285 | 0 | result = -1; |
286 | 0 | } |
287 | 11.7k | } |
288 | 11.7k | } |
289 | 48.8k | memory_free( |
290 | 48.8k | internal_list ); |
291 | 48.8k | } |
292 | 48.8k | return( result ); |
293 | 48.8k | } |
294 | | |
295 | | /* Clones (duplicates) the list |
296 | | * Returns 1 if successful or -1 on error |
297 | | */ |
298 | | int libfdata_list_clone( |
299 | | libfdata_list_t **destination_list, |
300 | | libfdata_list_t *source_list, |
301 | | libcerror_error_t **error ) |
302 | 0 | { |
303 | 0 | libfdata_internal_list_t *internal_destination_list = NULL; |
304 | 0 | libfdata_internal_list_t *internal_source_list = NULL; |
305 | 0 | static char *function = "libfdata_list_clone"; |
306 | |
|
307 | 0 | if( destination_list == NULL ) |
308 | 0 | { |
309 | 0 | libcerror_error_set( |
310 | 0 | error, |
311 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
312 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
313 | 0 | "%s: invalid destination list.", |
314 | 0 | function ); |
315 | |
|
316 | 0 | return( -1 ); |
317 | 0 | } |
318 | 0 | if( *destination_list != NULL ) |
319 | 0 | { |
320 | 0 | libcerror_error_set( |
321 | 0 | error, |
322 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
323 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
324 | 0 | "%s: invalid destination list value already set.", |
325 | 0 | function ); |
326 | |
|
327 | 0 | return( -1 ); |
328 | 0 | } |
329 | 0 | if( source_list == NULL ) |
330 | 0 | { |
331 | 0 | *destination_list = NULL; |
332 | |
|
333 | 0 | return( 1 ); |
334 | 0 | } |
335 | 0 | internal_source_list = (libfdata_internal_list_t *) source_list; |
336 | |
|
337 | 0 | internal_destination_list = memory_allocate_structure( |
338 | 0 | libfdata_internal_list_t ); |
339 | |
|
340 | 0 | if( internal_destination_list == NULL ) |
341 | 0 | { |
342 | 0 | libcerror_error_set( |
343 | 0 | error, |
344 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
345 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
346 | 0 | "%s: unable to create destination list.", |
347 | 0 | function ); |
348 | |
|
349 | 0 | goto on_error; |
350 | 0 | } |
351 | 0 | if( memory_set( |
352 | 0 | internal_destination_list, |
353 | 0 | 0, |
354 | 0 | sizeof( libfdata_internal_list_t ) ) == NULL ) |
355 | 0 | { |
356 | 0 | libcerror_error_set( |
357 | 0 | error, |
358 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
359 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
360 | 0 | "%s: unable to clear destination list.", |
361 | 0 | function ); |
362 | |
|
363 | 0 | memory_free( |
364 | 0 | internal_destination_list ); |
365 | |
|
366 | 0 | return( -1 ); |
367 | 0 | } |
368 | 0 | if( internal_source_list->data_handle != NULL ) |
369 | 0 | { |
370 | 0 | if( internal_source_list->free_data_handle == NULL ) |
371 | 0 | { |
372 | 0 | libcerror_error_set( |
373 | 0 | error, |
374 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
375 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
376 | 0 | "%s: invalid source list - missing free data handle function.", |
377 | 0 | function ); |
378 | |
|
379 | 0 | goto on_error; |
380 | 0 | } |
381 | 0 | if( internal_source_list->clone_data_handle == NULL ) |
382 | 0 | { |
383 | 0 | libcerror_error_set( |
384 | 0 | error, |
385 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
386 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
387 | 0 | "%s: invalid source list - missing clone data handle function.", |
388 | 0 | function ); |
389 | |
|
390 | 0 | goto on_error; |
391 | 0 | } |
392 | 0 | if( internal_source_list->clone_data_handle( |
393 | 0 | &( internal_destination_list->data_handle ), |
394 | 0 | internal_source_list->data_handle, |
395 | 0 | error ) != 1 ) |
396 | 0 | { |
397 | 0 | libcerror_error_set( |
398 | 0 | error, |
399 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
400 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
401 | 0 | "%s: unable to clone data handle.", |
402 | 0 | function ); |
403 | |
|
404 | 0 | goto on_error; |
405 | 0 | } |
406 | 0 | } |
407 | | /* TODO set destination list in destination elements */ |
408 | 0 | if( libcdata_array_clone( |
409 | 0 | &( internal_destination_list->elements_array ), |
410 | 0 | internal_source_list->elements_array, |
411 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_list_element_free, |
412 | 0 | (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libfdata_list_element_clone, |
413 | 0 | error ) != 1 ) |
414 | 0 | { |
415 | 0 | libcerror_error_set( |
416 | 0 | error, |
417 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
418 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
419 | 0 | "%s: unable to create destination elements array.", |
420 | 0 | function ); |
421 | |
|
422 | 0 | goto on_error; |
423 | 0 | } |
424 | 0 | if( libcdata_array_clone( |
425 | 0 | &( internal_destination_list->mapped_ranges_array ), |
426 | 0 | internal_source_list->mapped_ranges_array, |
427 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_mapped_range_free, |
428 | 0 | (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libfdata_mapped_range_clone, |
429 | 0 | error ) != 1 ) |
430 | 0 | { |
431 | 0 | libcerror_error_set( |
432 | 0 | error, |
433 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
434 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
435 | 0 | "%s: unable to create destination mapped ranges array.", |
436 | 0 | function ); |
437 | |
|
438 | 0 | goto on_error; |
439 | 0 | } |
440 | 0 | internal_destination_list->flags = internal_source_list->flags | LIBFDATA_DATA_HANDLE_FLAG_MANAGED; |
441 | 0 | internal_destination_list->free_data_handle = internal_source_list->free_data_handle; |
442 | 0 | internal_destination_list->clone_data_handle = internal_source_list->clone_data_handle; |
443 | 0 | internal_destination_list->read_element_data = internal_source_list->read_element_data; |
444 | 0 | internal_destination_list->write_element_data = internal_source_list->write_element_data; |
445 | |
|
446 | 0 | *destination_list = (libfdata_list_t *) internal_destination_list; |
447 | |
|
448 | 0 | return( 1 ); |
449 | | |
450 | 0 | on_error: |
451 | 0 | if( internal_destination_list != NULL ) |
452 | 0 | { |
453 | 0 | if( internal_destination_list->elements_array != NULL ) |
454 | 0 | { |
455 | 0 | libcdata_array_free( |
456 | 0 | &( internal_destination_list->elements_array ), |
457 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_list_element_free, |
458 | 0 | NULL ); |
459 | 0 | } |
460 | 0 | if( ( internal_destination_list->data_handle != NULL ) |
461 | 0 | && ( internal_source_list->free_data_handle != NULL ) ) |
462 | 0 | { |
463 | 0 | internal_source_list->free_data_handle( |
464 | 0 | &( internal_destination_list->data_handle ), |
465 | 0 | NULL ); |
466 | 0 | } |
467 | 0 | memory_free( |
468 | 0 | internal_destination_list ); |
469 | 0 | } |
470 | 0 | return( -1 ); |
471 | 0 | } |
472 | | |
473 | | /* Sets the calculate mapped ranges flag |
474 | | * Returns 1 if successful or -1 on error |
475 | | */ |
476 | | int libfdata_list_set_calculate_mapped_ranges_flag( |
477 | | libfdata_list_t *list, |
478 | | libcerror_error_t **error ) |
479 | 1.28M | { |
480 | 1.28M | libfdata_internal_list_t *internal_list = NULL; |
481 | 1.28M | static char *function = "libfdata_list_set_calculate_mapped_ranges_flag"; |
482 | | |
483 | 1.28M | if( list == NULL ) |
484 | 0 | { |
485 | 0 | libcerror_error_set( |
486 | 0 | error, |
487 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
488 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
489 | 0 | "%s: invalid list.", |
490 | 0 | function ); |
491 | |
|
492 | 0 | return( -1 ); |
493 | 0 | } |
494 | 1.28M | internal_list = (libfdata_internal_list_t *) list; |
495 | | |
496 | 1.28M | internal_list->flags |= LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES; |
497 | | |
498 | 1.28M | return( 1 ); |
499 | 1.28M | } |
500 | | |
501 | | /* List elements functions |
502 | | */ |
503 | | |
504 | | /* Empties the list |
505 | | * Returns 1 if successful or -1 on error |
506 | | */ |
507 | | int libfdata_list_empty( |
508 | | libfdata_list_t *list, |
509 | | libcerror_error_t **error ) |
510 | 11.7k | { |
511 | 11.7k | libfdata_internal_list_t *internal_list = NULL; |
512 | 11.7k | static char *function = "libfdata_list_empty"; |
513 | | |
514 | 11.7k | if( list == NULL ) |
515 | 0 | { |
516 | 0 | libcerror_error_set( |
517 | 0 | error, |
518 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
519 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
520 | 0 | "%s: invalid list.", |
521 | 0 | function ); |
522 | |
|
523 | 0 | return( -1 ); |
524 | 0 | } |
525 | 11.7k | internal_list = (libfdata_internal_list_t *) list; |
526 | | |
527 | 11.7k | if( libcdata_array_empty( |
528 | 11.7k | internal_list->elements_array, |
529 | 11.7k | (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_list_element_free, |
530 | 11.7k | error ) != 1 ) |
531 | 0 | { |
532 | 0 | libcerror_error_set( |
533 | 0 | error, |
534 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
535 | 0 | LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED, |
536 | 0 | "%s: unable to empty elements array.", |
537 | 0 | function ); |
538 | |
|
539 | 0 | return( -1 ); |
540 | 0 | } |
541 | 11.7k | if( libcdata_array_empty( |
542 | 11.7k | internal_list->mapped_ranges_array, |
543 | 11.7k | (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_mapped_range_free, |
544 | 11.7k | error ) != 1 ) |
545 | 0 | { |
546 | 0 | libcerror_error_set( |
547 | 0 | error, |
548 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
549 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
550 | 0 | "%s: unable to empty mapped ranges array.", |
551 | 0 | function ); |
552 | |
|
553 | 0 | return( -1 ); |
554 | 0 | } |
555 | 11.7k | internal_list->size = 0; |
556 | | |
557 | 11.7k | return( 1 ); |
558 | 11.7k | } |
559 | | |
560 | | /* Resizes the list |
561 | | * Returns 1 if successful or -1 on error |
562 | | */ |
563 | | int libfdata_list_resize( |
564 | | libfdata_list_t *list, |
565 | | int number_of_elements, |
566 | | libcerror_error_t **error ) |
567 | 7.45k | { |
568 | 7.45k | libfdata_internal_list_t *internal_list = NULL; |
569 | 7.45k | static char *function = "libfdata_list_resize"; |
570 | | |
571 | 7.45k | if( list == NULL ) |
572 | 0 | { |
573 | 0 | libcerror_error_set( |
574 | 0 | error, |
575 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
576 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
577 | 0 | "%s: invalid list.", |
578 | 0 | function ); |
579 | |
|
580 | 0 | return( -1 ); |
581 | 0 | } |
582 | 7.45k | internal_list = (libfdata_internal_list_t *) list; |
583 | | |
584 | 7.45k | if( libcdata_array_resize( |
585 | 7.45k | internal_list->elements_array, |
586 | 7.45k | number_of_elements, |
587 | 7.45k | (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_list_element_free, |
588 | 7.45k | error ) != 1 ) |
589 | 40 | { |
590 | 40 | libcerror_error_set( |
591 | 40 | error, |
592 | 40 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
593 | 40 | LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED, |
594 | 40 | "%s: unable to resize elements array.", |
595 | 40 | function ); |
596 | | |
597 | 40 | return( -1 ); |
598 | 40 | } |
599 | 7.41k | if( libcdata_array_resize( |
600 | 7.41k | internal_list->mapped_ranges_array, |
601 | 7.41k | number_of_elements, |
602 | 7.41k | (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_mapped_range_free, |
603 | 7.41k | error ) != 1 ) |
604 | 0 | { |
605 | 0 | libcerror_error_set( |
606 | 0 | error, |
607 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
608 | 0 | LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED, |
609 | 0 | "%s: unable to resize mapped ranges array.", |
610 | 0 | function ); |
611 | |
|
612 | 0 | return( -1 ); |
613 | 0 | } |
614 | 7.41k | internal_list->flags |= LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES; |
615 | | |
616 | 7.41k | return( 1 ); |
617 | 7.41k | } |
618 | | |
619 | | /* Reverses the order of the elements |
620 | | * Returns 1 if successful or -1 on error |
621 | | */ |
622 | | int libfdata_list_reverse( |
623 | | libfdata_list_t *list, |
624 | | libcerror_error_t **error ) |
625 | 177 | { |
626 | 177 | libfdata_internal_list_t *internal_list = NULL; |
627 | 177 | libfdata_list_element_t *list_element = NULL; |
628 | 177 | static char *function = "libfdata_list_reverse"; |
629 | 177 | int element_index = 0; |
630 | 177 | int number_of_elements = 0; |
631 | | |
632 | 177 | if( list == NULL ) |
633 | 0 | { |
634 | 0 | libcerror_error_set( |
635 | 0 | error, |
636 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
637 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
638 | 0 | "%s: invalid list.", |
639 | 0 | function ); |
640 | |
|
641 | 0 | return( -1 ); |
642 | 0 | } |
643 | 177 | internal_list = (libfdata_internal_list_t *) list; |
644 | | |
645 | 177 | if( libcdata_array_reverse( |
646 | 177 | internal_list->elements_array, |
647 | 177 | error ) != 1 ) |
648 | 0 | { |
649 | 0 | libcerror_error_set( |
650 | 0 | error, |
651 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
652 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
653 | 0 | "%s: unable to reverse elements array.", |
654 | 0 | function ); |
655 | |
|
656 | 0 | return( -1 ); |
657 | 0 | } |
658 | 177 | if( libcdata_array_get_number_of_entries( |
659 | 177 | internal_list->elements_array, |
660 | 177 | &number_of_elements, |
661 | 177 | error ) != 1 ) |
662 | 0 | { |
663 | 0 | libcerror_error_set( |
664 | 0 | error, |
665 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
666 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
667 | 0 | "%s: unable to retrieve number of elements from elements array.", |
668 | 0 | function ); |
669 | |
|
670 | 0 | return( -1 ); |
671 | 0 | } |
672 | 177 | for( element_index = 0; |
673 | 177 | element_index < number_of_elements; |
674 | 177 | element_index++ ) |
675 | 0 | { |
676 | 0 | if( libcdata_array_get_entry_by_index( |
677 | 0 | internal_list->elements_array, |
678 | 0 | element_index, |
679 | 0 | (intptr_t **) &list_element, |
680 | 0 | error ) != 1 ) |
681 | 0 | { |
682 | 0 | libcerror_error_set( |
683 | 0 | error, |
684 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
685 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
686 | 0 | "%s: unable to retrieve entry: %d from elements array.", |
687 | 0 | function, |
688 | 0 | element_index ); |
689 | |
|
690 | 0 | return( -1 ); |
691 | 0 | } |
692 | 0 | if( libfdata_list_element_set_element_index( |
693 | 0 | list_element, |
694 | 0 | element_index, |
695 | 0 | error ) != 1 ) |
696 | 0 | { |
697 | 0 | libcerror_error_set( |
698 | 0 | error, |
699 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
700 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
701 | 0 | "%s: unable to set list element: %d index.", |
702 | 0 | function, |
703 | 0 | element_index ); |
704 | |
|
705 | 0 | return( -1 ); |
706 | 0 | } |
707 | 0 | } |
708 | 177 | internal_list->flags |= LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES; |
709 | | |
710 | 177 | return( 1 ); |
711 | 177 | } |
712 | | |
713 | | /* Retrieves the number of elements of the list |
714 | | * Returns 1 if successful or -1 on error |
715 | | */ |
716 | | int libfdata_list_get_number_of_elements( |
717 | | libfdata_list_t *list, |
718 | | int *number_of_elements, |
719 | | libcerror_error_t **error ) |
720 | 16.5k | { |
721 | 16.5k | libfdata_internal_list_t *internal_list = NULL; |
722 | 16.5k | static char *function = "libfdata_list_get_number_of_elements"; |
723 | | |
724 | 16.5k | if( list == NULL ) |
725 | 0 | { |
726 | 0 | libcerror_error_set( |
727 | 0 | error, |
728 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
729 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
730 | 0 | "%s: invalid list.", |
731 | 0 | function ); |
732 | |
|
733 | 0 | return( -1 ); |
734 | 0 | } |
735 | 16.5k | internal_list = (libfdata_internal_list_t *) list; |
736 | | |
737 | 16.5k | if( libcdata_array_get_number_of_entries( |
738 | 16.5k | internal_list->elements_array, |
739 | 16.5k | number_of_elements, |
740 | 16.5k | error ) != 1 ) |
741 | 0 | { |
742 | 0 | libcerror_error_set( |
743 | 0 | error, |
744 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
745 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
746 | 0 | "%s: unable to retrieve number of elements from elements array.", |
747 | 0 | function ); |
748 | |
|
749 | 0 | return( -1 ); |
750 | 0 | } |
751 | 16.5k | return( 1 ); |
752 | 16.5k | } |
753 | | |
754 | | /* Retrieves a specific list element |
755 | | * Returns 1 if successful or -1 on error |
756 | | */ |
757 | | int libfdata_list_get_list_element_by_index( |
758 | | libfdata_list_t *list, |
759 | | int element_index, |
760 | | libfdata_list_element_t **element, |
761 | | libcerror_error_t **error ) |
762 | 571 | { |
763 | 571 | libfdata_internal_list_t *internal_list = NULL; |
764 | 571 | static char *function = "libfdata_list_get_list_element_by_index"; |
765 | | |
766 | 571 | if( list == NULL ) |
767 | 0 | { |
768 | 0 | libcerror_error_set( |
769 | 0 | error, |
770 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
771 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
772 | 0 | "%s: invalid list.", |
773 | 0 | function ); |
774 | |
|
775 | 0 | return( -1 ); |
776 | 0 | } |
777 | 571 | internal_list = (libfdata_internal_list_t *) list; |
778 | | |
779 | 571 | if( libcdata_array_get_entry_by_index( |
780 | 571 | internal_list->elements_array, |
781 | 571 | element_index, |
782 | 571 | (intptr_t **) element, |
783 | 571 | error ) != 1 ) |
784 | 12 | { |
785 | 12 | libcerror_error_set( |
786 | 12 | error, |
787 | 12 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
788 | 12 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
789 | 12 | "%s: unable to retrieve entry: %d from elements array.", |
790 | 12 | function, |
791 | 12 | element_index ); |
792 | | |
793 | 12 | return( -1 ); |
794 | 12 | } |
795 | 559 | internal_list->current_element_index = element_index; |
796 | | |
797 | 559 | return( 1 ); |
798 | 571 | } |
799 | | |
800 | | /* Retrieves the data range of a specific element |
801 | | * Returns 1 if successful or -1 on error |
802 | | */ |
803 | | int libfdata_list_get_element_by_index( |
804 | | libfdata_list_t *list, |
805 | | int element_index, |
806 | | int *element_file_index, |
807 | | off64_t *element_offset, |
808 | | size64_t *element_size, |
809 | | uint32_t *element_flags, |
810 | | libcerror_error_t **error ) |
811 | 3.35k | { |
812 | 3.35k | libfdata_internal_list_t *internal_list = NULL; |
813 | 3.35k | libfdata_list_element_t *list_element = NULL; |
814 | 3.35k | static char *function = "libfdata_list_get_element_by_index"; |
815 | | |
816 | 3.35k | if( list == NULL ) |
817 | 0 | { |
818 | 0 | libcerror_error_set( |
819 | 0 | error, |
820 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
821 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
822 | 0 | "%s: invalid list.", |
823 | 0 | function ); |
824 | |
|
825 | 0 | return( -1 ); |
826 | 0 | } |
827 | 3.35k | internal_list = (libfdata_internal_list_t *) list; |
828 | | |
829 | 3.35k | if( libcdata_array_get_entry_by_index( |
830 | 3.35k | internal_list->elements_array, |
831 | 3.35k | element_index, |
832 | 3.35k | (intptr_t **) &list_element, |
833 | 3.35k | error ) != 1 ) |
834 | 0 | { |
835 | 0 | libcerror_error_set( |
836 | 0 | error, |
837 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
838 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
839 | 0 | "%s: unable to retrieve entry: %d from elements array.", |
840 | 0 | function, |
841 | 0 | element_index ); |
842 | |
|
843 | 0 | return( -1 ); |
844 | 0 | } |
845 | 3.35k | if( libfdata_list_element_get_data_range( |
846 | 3.35k | list_element, |
847 | 3.35k | element_file_index, |
848 | 3.35k | element_offset, |
849 | 3.35k | element_size, |
850 | 3.35k | element_flags, |
851 | 3.35k | error ) != 1 ) |
852 | 0 | { |
853 | 0 | libcerror_error_set( |
854 | 0 | error, |
855 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
856 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
857 | 0 | "%s: unable to retrieve data range from list element: %d.", |
858 | 0 | function, |
859 | 0 | element_index ); |
860 | |
|
861 | 0 | return( -1 ); |
862 | 0 | } |
863 | 3.35k | internal_list->current_element_index = element_index; |
864 | | |
865 | 3.35k | return( 1 ); |
866 | 3.35k | } |
867 | | |
868 | | /* Sets the data range of a specific element |
869 | | * Returns 1 if successful or -1 on error |
870 | | */ |
871 | | int libfdata_list_set_element_by_index( |
872 | | libfdata_list_t *list, |
873 | | int element_index, |
874 | | int element_file_index, |
875 | | off64_t element_offset, |
876 | | size64_t element_size, |
877 | | uint32_t element_flags, |
878 | | libcerror_error_t **error ) |
879 | 7.86k | { |
880 | 7.86k | libfdata_internal_list_t *internal_list = NULL; |
881 | 7.86k | libfdata_list_element_t *list_element = NULL; |
882 | 7.86k | libfdata_mapped_range_t *mapped_range = NULL; |
883 | 7.86k | static char *function = "libfdata_list_set_element_by_index"; |
884 | 7.86k | off64_t previous_element_offset = 0; |
885 | 7.86k | size64_t mapped_size = 0; |
886 | 7.86k | size64_t previous_element_size = 0; |
887 | 7.86k | uint32_t previous_element_flags = 0; |
888 | 7.86k | int previous_element_file_index = 0; |
889 | 7.86k | int result = 0; |
890 | | |
891 | | #if defined( HAVE_DEBUG_OUTPUT ) |
892 | | off64_t mapped_range_offset = 0; |
893 | | size64_t mapped_range_size = 0; |
894 | | #endif |
895 | | |
896 | 7.86k | if( list == NULL ) |
897 | 0 | { |
898 | 0 | libcerror_error_set( |
899 | 0 | error, |
900 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
901 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
902 | 0 | "%s: invalid list.", |
903 | 0 | function ); |
904 | |
|
905 | 0 | return( -1 ); |
906 | 0 | } |
907 | 7.86k | internal_list = (libfdata_internal_list_t *) list; |
908 | | |
909 | 7.86k | if( libcdata_array_get_entry_by_index( |
910 | 7.86k | internal_list->elements_array, |
911 | 7.86k | element_index, |
912 | 7.86k | (intptr_t **) &list_element, |
913 | 7.86k | error ) != 1 ) |
914 | 0 | { |
915 | 0 | libcerror_error_set( |
916 | 0 | error, |
917 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
918 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
919 | 0 | "%s: unable to retrieve entry: %d from elements array.", |
920 | 0 | function, |
921 | 0 | element_index ); |
922 | |
|
923 | 0 | return( -1 ); |
924 | 0 | } |
925 | 7.86k | if( list_element == NULL ) |
926 | 7.22k | { |
927 | 7.22k | if( libfdata_list_element_initialize( |
928 | 7.22k | &list_element, |
929 | 7.22k | list, |
930 | 7.22k | element_index, |
931 | 7.22k | error ) != 1 ) |
932 | 0 | { |
933 | 0 | libcerror_error_set( |
934 | 0 | error, |
935 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
936 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
937 | 0 | "%s: unable to create list element.", |
938 | 0 | function ); |
939 | |
|
940 | 0 | return( -1 ); |
941 | 0 | } |
942 | 7.22k | if( libcdata_array_set_entry_by_index( |
943 | 7.22k | internal_list->elements_array, |
944 | 7.22k | element_index, |
945 | 7.22k | (intptr_t *) list_element, |
946 | 7.22k | error ) != 1 ) |
947 | 0 | { |
948 | 0 | libcerror_error_set( |
949 | 0 | error, |
950 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
951 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
952 | 0 | "%s: unable to set entry: %d in elements array.", |
953 | 0 | function, |
954 | 0 | element_index ); |
955 | |
|
956 | 0 | libfdata_list_element_free( |
957 | 0 | &list_element, |
958 | 0 | NULL ); |
959 | |
|
960 | 0 | return( -1 ); |
961 | 0 | } |
962 | 7.22k | } |
963 | 633 | else |
964 | 633 | { |
965 | 633 | result = libfdata_list_element_get_mapped_size( |
966 | 633 | list_element, |
967 | 633 | &mapped_size, |
968 | 633 | error ); |
969 | | |
970 | 633 | if( result == -1 ) |
971 | 0 | { |
972 | 0 | libcerror_error_set( |
973 | 0 | error, |
974 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
975 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
976 | 0 | "%s: unable to retrieve mapped size of list element: %d.", |
977 | 0 | function, |
978 | 0 | element_index ); |
979 | |
|
980 | 0 | return( -1 ); |
981 | 0 | } |
982 | 633 | else if( result == 0 ) |
983 | 0 | { |
984 | 0 | if( libfdata_list_element_get_data_range( |
985 | 0 | list_element, |
986 | 0 | &previous_element_file_index, |
987 | 0 | &previous_element_offset, |
988 | 0 | &previous_element_size, |
989 | 0 | &previous_element_flags, |
990 | 0 | error ) != 1 ) |
991 | 0 | { |
992 | 0 | libcerror_error_set( |
993 | 0 | error, |
994 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
995 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
996 | 0 | "%s: unable to retrieve data range of list element: %d.", |
997 | 0 | function, |
998 | 0 | element_index ); |
999 | |
|
1000 | 0 | return( -1 ); |
1001 | 0 | } |
1002 | 0 | } |
1003 | 633 | } |
1004 | 7.86k | if( libfdata_list_element_set_data_range( |
1005 | 7.86k | list_element, |
1006 | 7.86k | element_file_index, |
1007 | 7.86k | element_offset, |
1008 | 7.86k | element_size, |
1009 | 7.86k | element_flags, |
1010 | 7.86k | error ) != 1 ) |
1011 | 0 | { |
1012 | 0 | libcerror_error_set( |
1013 | 0 | error, |
1014 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1015 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1016 | 0 | "%s: unable to set data range of list element: %d.", |
1017 | 0 | function, |
1018 | 0 | element_index ); |
1019 | |
|
1020 | 0 | return( -1 ); |
1021 | 0 | } |
1022 | | /* Make sure the list has a mapped range entry for every element |
1023 | | */ |
1024 | 7.86k | if( libcdata_array_get_entry_by_index( |
1025 | 7.86k | internal_list->mapped_ranges_array, |
1026 | 7.86k | element_index, |
1027 | 7.86k | (intptr_t **) &mapped_range, |
1028 | 7.86k | error ) != 1 ) |
1029 | 0 | { |
1030 | 0 | libcerror_error_set( |
1031 | 0 | error, |
1032 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1033 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1034 | 0 | "%s: unable to retrieve entry: %d from mapped ranges array.", |
1035 | 0 | function, |
1036 | 0 | element_index ); |
1037 | |
|
1038 | 0 | return( -1 ); |
1039 | 0 | } |
1040 | 7.86k | if( mapped_range == NULL ) |
1041 | 7.22k | { |
1042 | 7.22k | if( libfdata_mapped_range_initialize( |
1043 | 7.22k | &mapped_range, |
1044 | 7.22k | error ) != 1 ) |
1045 | 0 | { |
1046 | 0 | libcerror_error_set( |
1047 | 0 | error, |
1048 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1049 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1050 | 0 | "%s: unable to create mapped range.", |
1051 | 0 | function ); |
1052 | |
|
1053 | 0 | return( -1 ); |
1054 | 0 | } |
1055 | 7.22k | if( libcdata_array_set_entry_by_index( |
1056 | 7.22k | internal_list->mapped_ranges_array, |
1057 | 7.22k | element_index, |
1058 | 7.22k | (intptr_t *) mapped_range, |
1059 | 7.22k | error ) != 1 ) |
1060 | 0 | { |
1061 | 0 | libcerror_error_set( |
1062 | 0 | error, |
1063 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1064 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1065 | 0 | "%s: unable to set entry: %d in mapped ranges array.", |
1066 | 0 | function, |
1067 | 0 | element_index ); |
1068 | |
|
1069 | 0 | libfdata_mapped_range_free( |
1070 | 0 | &mapped_range, |
1071 | 0 | NULL ); |
1072 | |
|
1073 | 0 | return( -1 ); |
1074 | 0 | } |
1075 | 7.22k | internal_list->size += element_size; |
1076 | 7.22k | internal_list->flags |= LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES; |
1077 | 7.22k | } |
1078 | | /* If the size of the element is mapped or if the element size did not change |
1079 | | * there is no need to recalculate the mapped range |
1080 | | */ |
1081 | 633 | else if( ( mapped_size == 0 ) |
1082 | 633 | && ( previous_element_size != element_size ) ) |
1083 | 0 | { |
1084 | 0 | internal_list->size -= previous_element_size; |
1085 | 0 | internal_list->size += element_size; |
1086 | 0 | internal_list->flags |= LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES; |
1087 | 0 | } |
1088 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1089 | | if( libcnotify_verbose != 0 ) |
1090 | | { |
1091 | | libcnotify_printf( |
1092 | | "%s: element: %03d\tfile index: %03d offset: %" PRIi64 " - %" PRIi64 " (0x%08" PRIx64 " - 0x%08" PRIx64 ") (size: %" PRIu64 ")\n", |
1093 | | function, |
1094 | | element_index, |
1095 | | element_file_index, |
1096 | | element_offset, |
1097 | | element_offset + element_size, |
1098 | | element_offset, |
1099 | | element_offset + element_size, |
1100 | | element_size ); |
1101 | | |
1102 | | if( ( internal_list->flags & LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES ) == 0 ) |
1103 | | { |
1104 | | if( libfdata_mapped_range_get( |
1105 | | mapped_range, |
1106 | | &mapped_range_offset, |
1107 | | &mapped_range_size, |
1108 | | error ) != 1 ) |
1109 | | { |
1110 | | libcerror_error_set( |
1111 | | error, |
1112 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1113 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1114 | | "%s: unable to retrieve values from mapped range: %d.", |
1115 | | function, |
1116 | | element_index ); |
1117 | | |
1118 | | return( -1 ); |
1119 | | } |
1120 | | libcnotify_printf( |
1121 | | "%s: element: %03d\tmapped range: %" PRIi64 " - %" PRIi64 " (0x%08" PRIx64 " - 0x%08" PRIx64 ") (size: %" PRIu64 ")\n", |
1122 | | function, |
1123 | | element_index, |
1124 | | mapped_range_offset, |
1125 | | mapped_range_offset + mapped_range_size, |
1126 | | mapped_range_offset, |
1127 | | mapped_range_offset + mapped_range_size, |
1128 | | mapped_range_size ); |
1129 | | } |
1130 | | libcnotify_printf( |
1131 | | "\n" ); |
1132 | | } |
1133 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
1134 | | |
1135 | 7.86k | internal_list->current_element_index = element_index; |
1136 | | |
1137 | 7.86k | return( 1 ); |
1138 | 7.86k | } |
1139 | | |
1140 | | /* Prepends an element data range |
1141 | | * Returns 1 if successful or -1 on error |
1142 | | */ |
1143 | | int libfdata_list_prepend_element( |
1144 | | libfdata_list_t *list, |
1145 | | int element_file_index, |
1146 | | off64_t element_offset, |
1147 | | size64_t element_size, |
1148 | | uint32_t element_flags, |
1149 | | libcerror_error_t **error ) |
1150 | 0 | { |
1151 | 0 | libfdata_internal_list_t *internal_list = NULL; |
1152 | 0 | libfdata_list_element_t *list_element = NULL; |
1153 | 0 | libfdata_mapped_range_t *mapped_range = NULL; |
1154 | 0 | static char *function = "libfdata_list_prepend_element"; |
1155 | 0 | off64_t mapped_offset = 0; |
1156 | 0 | int element_index = 0; |
1157 | 0 | int mapped_range_index = -1; |
1158 | 0 | int number_of_elements = 0; |
1159 | |
|
1160 | 0 | if( list == NULL ) |
1161 | 0 | { |
1162 | 0 | libcerror_error_set( |
1163 | 0 | error, |
1164 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1165 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1166 | 0 | "%s: invalid list.", |
1167 | 0 | function ); |
1168 | |
|
1169 | 0 | return( -1 ); |
1170 | 0 | } |
1171 | 0 | internal_list = (libfdata_internal_list_t *) list; |
1172 | |
|
1173 | 0 | if( libfdata_mapped_range_initialize( |
1174 | 0 | &mapped_range, |
1175 | 0 | error ) != 1 ) |
1176 | 0 | { |
1177 | 0 | libcerror_error_set( |
1178 | 0 | error, |
1179 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1180 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1181 | 0 | "%s: unable to create mapped range.", |
1182 | 0 | function ); |
1183 | |
|
1184 | 0 | goto on_error; |
1185 | 0 | } |
1186 | 0 | mapped_offset = internal_list->mapped_offset + (off64_t) internal_list->size; |
1187 | |
|
1188 | 0 | if( libfdata_mapped_range_set( |
1189 | 0 | mapped_range, |
1190 | 0 | mapped_offset, |
1191 | 0 | element_size, |
1192 | 0 | error ) != 1 ) |
1193 | 0 | { |
1194 | 0 | libcerror_error_set( |
1195 | 0 | error, |
1196 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1197 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1198 | 0 | "%s: unable to set mapped range values.", |
1199 | 0 | function ); |
1200 | |
|
1201 | 0 | goto on_error; |
1202 | 0 | } |
1203 | 0 | if( libcdata_array_append_entry( |
1204 | 0 | internal_list->mapped_ranges_array, |
1205 | 0 | &mapped_range_index, |
1206 | 0 | (intptr_t *) mapped_range, |
1207 | 0 | error ) != 1 ) |
1208 | 0 | { |
1209 | 0 | libcerror_error_set( |
1210 | 0 | error, |
1211 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1212 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
1213 | 0 | "%s: unable to append mapped range to array.", |
1214 | 0 | function ); |
1215 | |
|
1216 | 0 | goto on_error; |
1217 | 0 | } |
1218 | 0 | if( libfdata_list_element_initialize( |
1219 | 0 | &list_element, |
1220 | 0 | list, |
1221 | 0 | 0, |
1222 | 0 | error ) != 1 ) |
1223 | 0 | { |
1224 | 0 | libcerror_error_set( |
1225 | 0 | error, |
1226 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1227 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1228 | 0 | "%s: unable to create list element.", |
1229 | 0 | function ); |
1230 | |
|
1231 | 0 | goto on_error; |
1232 | 0 | } |
1233 | 0 | if( libfdata_list_element_set_data_range( |
1234 | 0 | list_element, |
1235 | 0 | element_file_index, |
1236 | 0 | element_offset, |
1237 | 0 | element_size, |
1238 | 0 | element_flags, |
1239 | 0 | error ) != 1 ) |
1240 | 0 | { |
1241 | 0 | libcerror_error_set( |
1242 | 0 | error, |
1243 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1244 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1245 | 0 | "%s: unable to set data range of list element.", |
1246 | 0 | function ); |
1247 | |
|
1248 | 0 | goto on_error; |
1249 | 0 | } |
1250 | 0 | if( libcdata_array_prepend_entry( |
1251 | 0 | internal_list->elements_array, |
1252 | 0 | (intptr_t *) list_element, |
1253 | 0 | error ) != 1 ) |
1254 | 0 | { |
1255 | 0 | libcerror_error_set( |
1256 | 0 | error, |
1257 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1258 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
1259 | 0 | "%s: unable to prepend list element to elements array.", |
1260 | 0 | function ); |
1261 | |
|
1262 | 0 | goto on_error; |
1263 | 0 | } |
1264 | 0 | mapped_range_index = -1; |
1265 | 0 | mapped_range = NULL; |
1266 | |
|
1267 | 0 | if( libcdata_array_get_number_of_entries( |
1268 | 0 | internal_list->elements_array, |
1269 | 0 | &number_of_elements, |
1270 | 0 | error ) != 1 ) |
1271 | 0 | { |
1272 | 0 | libcerror_error_set( |
1273 | 0 | error, |
1274 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1275 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1276 | 0 | "%s: unable to retrieve number of entries from elements array.", |
1277 | 0 | function ); |
1278 | |
|
1279 | 0 | goto on_error; |
1280 | 0 | } |
1281 | 0 | for( element_index = 0; |
1282 | 0 | element_index < number_of_elements; |
1283 | 0 | element_index++ ) |
1284 | 0 | { |
1285 | 0 | if( libcdata_array_get_entry_by_index( |
1286 | 0 | internal_list->elements_array, |
1287 | 0 | element_index, |
1288 | 0 | (intptr_t **) &list_element, |
1289 | 0 | error ) != 1 ) |
1290 | 0 | { |
1291 | 0 | libcerror_error_set( |
1292 | 0 | error, |
1293 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1294 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1295 | 0 | "%s: unable to retrieve entry: %d from elements array.", |
1296 | 0 | function, |
1297 | 0 | element_index ); |
1298 | |
|
1299 | 0 | list_element = NULL; |
1300 | |
|
1301 | 0 | goto on_error; |
1302 | 0 | } |
1303 | 0 | if( libfdata_list_element_set_element_index( |
1304 | 0 | list_element, |
1305 | 0 | element_index, |
1306 | 0 | error ) != 1 ) |
1307 | 0 | { |
1308 | 0 | libcerror_error_set( |
1309 | 0 | error, |
1310 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1311 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1312 | 0 | "%s: unable to set list element: %d index.", |
1313 | 0 | function, |
1314 | 0 | element_index ); |
1315 | |
|
1316 | 0 | list_element = NULL; |
1317 | |
|
1318 | 0 | goto on_error; |
1319 | 0 | } |
1320 | 0 | } |
1321 | 0 | internal_list->current_element_index = 0; |
1322 | 0 | internal_list->size += element_size; |
1323 | 0 | internal_list->flags |= LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES; |
1324 | |
|
1325 | 0 | return( 1 ); |
1326 | | |
1327 | 0 | on_error: |
1328 | 0 | if( list_element != NULL ) |
1329 | 0 | { |
1330 | 0 | libfdata_list_element_free( |
1331 | 0 | &list_element, |
1332 | 0 | NULL ); |
1333 | 0 | } |
1334 | 0 | if( mapped_range_index != -1 ) |
1335 | 0 | { |
1336 | 0 | libcdata_array_set_entry_by_index( |
1337 | 0 | internal_list->mapped_ranges_array, |
1338 | 0 | mapped_range_index, |
1339 | 0 | NULL, |
1340 | 0 | NULL ); |
1341 | 0 | } |
1342 | 0 | if( mapped_range != NULL ) |
1343 | 0 | { |
1344 | 0 | libfdata_mapped_range_free( |
1345 | 0 | &mapped_range, |
1346 | 0 | NULL ); |
1347 | 0 | } |
1348 | 0 | return( -1 ); |
1349 | 0 | } |
1350 | | |
1351 | | /* Appends an element data range |
1352 | | * Returns 1 if successful or -1 on error |
1353 | | */ |
1354 | | int libfdata_list_append_element( |
1355 | | libfdata_list_t *list, |
1356 | | int *element_index, |
1357 | | int element_file_index, |
1358 | | off64_t element_offset, |
1359 | | size64_t element_size, |
1360 | | uint32_t element_flags, |
1361 | | libcerror_error_t **error ) |
1362 | 5.22M | { |
1363 | 5.22M | libfdata_internal_list_t *internal_list = NULL; |
1364 | 5.22M | libfdata_list_element_t *list_element = NULL; |
1365 | 5.22M | libfdata_mapped_range_t *mapped_range = NULL; |
1366 | 5.22M | static char *function = "libfdata_list_append_element"; |
1367 | 5.22M | off64_t mapped_offset = 0; |
1368 | 5.22M | int mapped_range_index = -1; |
1369 | | |
1370 | 5.22M | if( list == NULL ) |
1371 | 0 | { |
1372 | 0 | libcerror_error_set( |
1373 | 0 | error, |
1374 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1375 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1376 | 0 | "%s: invalid list.", |
1377 | 0 | function ); |
1378 | |
|
1379 | 0 | return( -1 ); |
1380 | 0 | } |
1381 | 5.22M | internal_list = (libfdata_internal_list_t *) list; |
1382 | | |
1383 | 5.22M | if( element_index == NULL ) |
1384 | 0 | { |
1385 | 0 | libcerror_error_set( |
1386 | 0 | error, |
1387 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1388 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1389 | 0 | "%s: invalid element index.", |
1390 | 0 | function ); |
1391 | |
|
1392 | 0 | return( -1 ); |
1393 | 0 | } |
1394 | 5.22M | if( libfdata_mapped_range_initialize( |
1395 | 5.22M | &mapped_range, |
1396 | 5.22M | error ) != 1 ) |
1397 | 0 | { |
1398 | 0 | libcerror_error_set( |
1399 | 0 | error, |
1400 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1401 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1402 | 0 | "%s: unable to create mapped range.", |
1403 | 0 | function ); |
1404 | |
|
1405 | 0 | goto on_error; |
1406 | 0 | } |
1407 | 5.22M | mapped_offset = internal_list->mapped_offset + (off64_t) internal_list->size; |
1408 | | |
1409 | 5.22M | if( libfdata_mapped_range_set( |
1410 | 5.22M | mapped_range, |
1411 | 5.22M | mapped_offset, |
1412 | 5.22M | element_size, |
1413 | 5.22M | error ) != 1 ) |
1414 | 0 | { |
1415 | 0 | libcerror_error_set( |
1416 | 0 | error, |
1417 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1418 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1419 | 0 | "%s: unable to set mapped range values.", |
1420 | 0 | function ); |
1421 | |
|
1422 | 0 | goto on_error; |
1423 | 0 | } |
1424 | 5.22M | if( libcdata_array_append_entry( |
1425 | 5.22M | internal_list->mapped_ranges_array, |
1426 | 5.22M | &mapped_range_index, |
1427 | 5.22M | (intptr_t *) mapped_range, |
1428 | 5.22M | error ) != 1 ) |
1429 | 0 | { |
1430 | 0 | libcerror_error_set( |
1431 | 0 | error, |
1432 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1433 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
1434 | 0 | "%s: unable to append mapped range to array.", |
1435 | 0 | function ); |
1436 | |
|
1437 | 0 | goto on_error; |
1438 | 0 | } |
1439 | 5.22M | if( libfdata_list_element_initialize( |
1440 | 5.22M | &list_element, |
1441 | 5.22M | list, |
1442 | 5.22M | 0, |
1443 | 5.22M | error ) != 1 ) |
1444 | 0 | { |
1445 | 0 | libcerror_error_set( |
1446 | 0 | error, |
1447 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1448 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1449 | 0 | "%s: unable to create list element.", |
1450 | 0 | function ); |
1451 | |
|
1452 | 0 | goto on_error; |
1453 | 0 | } |
1454 | 5.22M | if( libfdata_list_element_set_data_range( |
1455 | 5.22M | list_element, |
1456 | 5.22M | element_file_index, |
1457 | 5.22M | element_offset, |
1458 | 5.22M | element_size, |
1459 | 5.22M | element_flags, |
1460 | 5.22M | error ) != 1 ) |
1461 | 0 | { |
1462 | 0 | libcerror_error_set( |
1463 | 0 | error, |
1464 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1465 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1466 | 0 | "%s: unable to set data range of list element.", |
1467 | 0 | function ); |
1468 | |
|
1469 | 0 | goto on_error; |
1470 | 0 | } |
1471 | 5.22M | if( libcdata_array_append_entry( |
1472 | 5.22M | internal_list->elements_array, |
1473 | 5.22M | element_index, |
1474 | 5.22M | (intptr_t *) list_element, |
1475 | 5.22M | error ) != 1 ) |
1476 | 0 | { |
1477 | 0 | libcerror_error_set( |
1478 | 0 | error, |
1479 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1480 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
1481 | 0 | "%s: unable to append list element to elements array.", |
1482 | 0 | function ); |
1483 | |
|
1484 | 0 | goto on_error; |
1485 | 0 | } |
1486 | 5.22M | mapped_range_index = -1; |
1487 | 5.22M | mapped_range = NULL; |
1488 | | |
1489 | 5.22M | if( libfdata_list_element_set_element_index( |
1490 | 5.22M | list_element, |
1491 | 5.22M | *element_index, |
1492 | 5.22M | error ) != 1 ) |
1493 | 0 | { |
1494 | 0 | libcerror_error_set( |
1495 | 0 | error, |
1496 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1497 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1498 | 0 | "%s: unable to set list element index.", |
1499 | 0 | function ); |
1500 | |
|
1501 | 0 | list_element = NULL; |
1502 | |
|
1503 | 0 | goto on_error; |
1504 | 0 | } |
1505 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1506 | | if( libcnotify_verbose != 0 ) |
1507 | | { |
1508 | | libcnotify_printf( |
1509 | | "%s: element: %03d\tfile index: %03d offset: %" PRIi64 " - %" PRIi64 " (0x%08" PRIx64 " - 0x%08" PRIx64 ") (size: %" PRIu64 ")\n", |
1510 | | function, |
1511 | | *element_index, |
1512 | | element_file_index, |
1513 | | element_offset, |
1514 | | element_offset + element_size, |
1515 | | element_offset, |
1516 | | element_offset + element_size, |
1517 | | element_size ); |
1518 | | |
1519 | | libcnotify_printf( |
1520 | | "%s: element: %03d\tmapped range: %" PRIi64 " - %" PRIi64 " (0x%08" PRIx64 " - 0x%08" PRIx64 ") (size: %" PRIu64 ")\n", |
1521 | | function, |
1522 | | *element_index, |
1523 | | mapped_offset, |
1524 | | mapped_offset + element_size, |
1525 | | mapped_offset, |
1526 | | mapped_offset + element_size, |
1527 | | element_size ); |
1528 | | |
1529 | | libcnotify_printf( |
1530 | | "\n" ); |
1531 | | } |
1532 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
1533 | | |
1534 | 5.22M | internal_list->current_element_index = *element_index; |
1535 | 5.22M | internal_list->size += element_size; |
1536 | | |
1537 | 5.22M | return( 1 ); |
1538 | | |
1539 | 0 | on_error: |
1540 | 0 | if( list_element != NULL ) |
1541 | 0 | { |
1542 | 0 | libfdata_list_element_free( |
1543 | 0 | &list_element, |
1544 | 0 | NULL ); |
1545 | 0 | } |
1546 | 0 | if( mapped_range_index != -1 ) |
1547 | 0 | { |
1548 | 0 | libcdata_array_set_entry_by_index( |
1549 | 0 | internal_list->mapped_ranges_array, |
1550 | 0 | mapped_range_index, |
1551 | 0 | NULL, |
1552 | 0 | NULL ); |
1553 | 0 | } |
1554 | 0 | if( mapped_range != NULL ) |
1555 | 0 | { |
1556 | 0 | libfdata_mapped_range_free( |
1557 | 0 | &mapped_range, |
1558 | 0 | NULL ); |
1559 | 0 | } |
1560 | 0 | return( -1 ); |
1561 | 5.22M | } |
1562 | | |
1563 | | /* Appends the element of the source list to the list |
1564 | | * The source list is emptied if successful |
1565 | | * Returns 1 if successful or -1 on error |
1566 | | */ |
1567 | | int libfdata_list_append_list( |
1568 | | libfdata_list_t *list, |
1569 | | libfdata_list_t *source_list, |
1570 | | libcerror_error_t **error ) |
1571 | 0 | { |
1572 | 0 | libfdata_internal_list_t *internal_list = NULL; |
1573 | 0 | libfdata_internal_list_t *internal_source_list = NULL; |
1574 | 0 | libfdata_list_element_t *list_element = NULL; |
1575 | 0 | libfdata_mapped_range_t *mapped_range = NULL; |
1576 | 0 | static char *function = "libfdata_list_append_list"; |
1577 | 0 | off64_t mapped_range_offset = 0; |
1578 | 0 | size64_t mapped_range_size = 0; |
1579 | 0 | int element_index = 0; |
1580 | 0 | int new_number_of_elements = 0; |
1581 | 0 | int number_of_elements = 0; |
1582 | 0 | int result = 1; |
1583 | 0 | int source_element_index = 0; |
1584 | 0 | int source_number_of_elements = 0; |
1585 | |
|
1586 | 0 | if( list == NULL ) |
1587 | 0 | { |
1588 | 0 | libcerror_error_set( |
1589 | 0 | error, |
1590 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1591 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1592 | 0 | "%s: invalid list.", |
1593 | 0 | function ); |
1594 | |
|
1595 | 0 | return( -1 ); |
1596 | 0 | } |
1597 | 0 | internal_list = (libfdata_internal_list_t *) list; |
1598 | |
|
1599 | 0 | if( source_list == NULL ) |
1600 | 0 | { |
1601 | 0 | libcerror_error_set( |
1602 | 0 | error, |
1603 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1604 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1605 | 0 | "%s: invalid source list.", |
1606 | 0 | function ); |
1607 | |
|
1608 | 0 | return( -1 ); |
1609 | 0 | } |
1610 | 0 | internal_source_list = (libfdata_internal_list_t *) source_list; |
1611 | |
|
1612 | 0 | if( ( internal_list->flags & LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES ) != 0 ) |
1613 | 0 | { |
1614 | 0 | if( libfdata_list_calculate_mapped_ranges( |
1615 | 0 | internal_list, |
1616 | 0 | error ) != 1 ) |
1617 | 0 | { |
1618 | 0 | libcerror_error_set( |
1619 | 0 | error, |
1620 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1621 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1622 | 0 | "%s: unable to calculate mapped ranges.", |
1623 | 0 | function ); |
1624 | |
|
1625 | 0 | goto on_error; |
1626 | 0 | } |
1627 | 0 | } |
1628 | 0 | if( ( internal_source_list->flags & LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES ) != 0 ) |
1629 | 0 | { |
1630 | 0 | if( libfdata_list_calculate_mapped_ranges( |
1631 | 0 | internal_source_list, |
1632 | 0 | error ) != 1 ) |
1633 | 0 | { |
1634 | 0 | libcerror_error_set( |
1635 | 0 | error, |
1636 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1637 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1638 | 0 | "%s: unable to calculate mapped ranges of source list.", |
1639 | 0 | function ); |
1640 | |
|
1641 | 0 | goto on_error; |
1642 | 0 | } |
1643 | 0 | } |
1644 | 0 | if( ( internal_list->mapped_offset != 0 ) |
1645 | 0 | || ( internal_source_list->mapped_offset != 0 ) ) |
1646 | 0 | { |
1647 | 0 | if( ( (size64_t) internal_list->mapped_offset + internal_list->size ) != (size64_t) internal_source_list->mapped_offset ) |
1648 | 0 | { |
1649 | 0 | libcerror_error_set( |
1650 | 0 | error, |
1651 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1652 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1653 | 0 | "%s: invalid source mapped offset value out of bounds.", |
1654 | 0 | function ); |
1655 | |
|
1656 | 0 | goto on_error; |
1657 | 0 | } |
1658 | 0 | } |
1659 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1660 | | if( libcnotify_verbose != 0 ) |
1661 | | { |
1662 | | libcnotify_printf( |
1663 | | "%s: appending source list with mapped offset: %" PRIi64 " (0x%08" PRIx64 ") and size: %" PRIu64 " to list with mapped offset: %" PRIi64 " (0x%08" PRIx64 ") and size: %" PRIu64 "\n", |
1664 | | function, |
1665 | | internal_source_list->mapped_offset, |
1666 | | internal_source_list->mapped_offset, |
1667 | | internal_source_list->size, |
1668 | | internal_list->mapped_offset, |
1669 | | internal_list->mapped_offset, |
1670 | | internal_list->size ); |
1671 | | } |
1672 | | #endif |
1673 | 0 | if( libcdata_array_get_number_of_entries( |
1674 | 0 | internal_list->elements_array, |
1675 | 0 | &number_of_elements, |
1676 | 0 | error ) != 1 ) |
1677 | 0 | { |
1678 | 0 | libcerror_error_set( |
1679 | 0 | error, |
1680 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1681 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1682 | 0 | "%s: unable to retrieve number of elements from elements array.", |
1683 | 0 | function ); |
1684 | |
|
1685 | 0 | goto on_error; |
1686 | 0 | } |
1687 | 0 | if( libcdata_array_get_number_of_entries( |
1688 | 0 | internal_source_list->elements_array, |
1689 | 0 | &source_number_of_elements, |
1690 | 0 | error ) != 1 ) |
1691 | 0 | { |
1692 | 0 | libcerror_error_set( |
1693 | 0 | error, |
1694 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1695 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1696 | 0 | "%s: unable to retrieve number of elements from source list elements array.", |
1697 | 0 | function ); |
1698 | |
|
1699 | 0 | goto on_error; |
1700 | 0 | } |
1701 | 0 | element_index = number_of_elements; |
1702 | 0 | new_number_of_elements = number_of_elements + source_number_of_elements; |
1703 | |
|
1704 | 0 | if( libcdata_array_resize( |
1705 | 0 | internal_list->elements_array, |
1706 | 0 | new_number_of_elements, |
1707 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_list_element_free, |
1708 | 0 | error ) != 1 ) |
1709 | 0 | { |
1710 | 0 | libcerror_error_set( |
1711 | 0 | error, |
1712 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1713 | 0 | LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED, |
1714 | 0 | "%s: unable to resize elements array.", |
1715 | 0 | function ); |
1716 | |
|
1717 | 0 | goto on_error; |
1718 | 0 | } |
1719 | 0 | if( libcdata_array_resize( |
1720 | 0 | internal_list->mapped_ranges_array, |
1721 | 0 | new_number_of_elements, |
1722 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_mapped_range_free, |
1723 | 0 | error ) != 1 ) |
1724 | 0 | { |
1725 | 0 | libcerror_error_set( |
1726 | 0 | error, |
1727 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1728 | 0 | LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED, |
1729 | 0 | "%s: unable to resize mapped ranges array.", |
1730 | 0 | function ); |
1731 | |
|
1732 | 0 | goto on_error; |
1733 | 0 | } |
1734 | 0 | for( source_element_index = 0; |
1735 | 0 | source_element_index < source_number_of_elements; |
1736 | 0 | source_element_index++ ) |
1737 | 0 | { |
1738 | 0 | if( libcdata_array_get_entry_by_index( |
1739 | 0 | internal_source_list->elements_array, |
1740 | 0 | source_element_index, |
1741 | 0 | (intptr_t **) &list_element, |
1742 | 0 | error ) != 1 ) |
1743 | 0 | { |
1744 | 0 | libcerror_error_set( |
1745 | 0 | error, |
1746 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1747 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1748 | 0 | "%s: unable to retrieve entry: %d from source list elements array.", |
1749 | 0 | function, |
1750 | 0 | source_element_index ); |
1751 | |
|
1752 | 0 | goto on_error; |
1753 | 0 | } |
1754 | 0 | if( libcdata_array_set_entry_by_index( |
1755 | 0 | internal_list->elements_array, |
1756 | 0 | element_index, |
1757 | 0 | (intptr_t *) list_element, |
1758 | 0 | error ) != 1 ) |
1759 | 0 | { |
1760 | 0 | libcerror_error_set( |
1761 | 0 | error, |
1762 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1763 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1764 | 0 | "%s: unable to set entry: %d in elements array.", |
1765 | 0 | function, |
1766 | 0 | element_index ); |
1767 | |
|
1768 | 0 | goto on_error; |
1769 | 0 | } |
1770 | 0 | if( libcdata_array_get_entry_by_index( |
1771 | 0 | internal_source_list->mapped_ranges_array, |
1772 | 0 | source_element_index, |
1773 | 0 | (intptr_t **) &mapped_range, |
1774 | 0 | error ) != 1 ) |
1775 | 0 | { |
1776 | 0 | libcerror_error_set( |
1777 | 0 | error, |
1778 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1779 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1780 | 0 | "%s: unable to retrieve entry: %d from source list mapped ranges array.", |
1781 | 0 | function, |
1782 | 0 | source_element_index ); |
1783 | |
|
1784 | 0 | goto on_error; |
1785 | 0 | } |
1786 | 0 | if( libcdata_array_set_entry_by_index( |
1787 | 0 | internal_list->mapped_ranges_array, |
1788 | 0 | element_index, |
1789 | 0 | (intptr_t *) mapped_range, |
1790 | 0 | error ) != 1 ) |
1791 | 0 | { |
1792 | 0 | libcerror_error_set( |
1793 | 0 | error, |
1794 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1795 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1796 | 0 | "%s: unable to set entry: %d in mapped ranges array.", |
1797 | 0 | function, |
1798 | 0 | element_index ); |
1799 | |
|
1800 | 0 | goto on_error; |
1801 | 0 | } |
1802 | 0 | element_index++; |
1803 | 0 | } |
1804 | 0 | element_index = number_of_elements; |
1805 | 0 | number_of_elements = new_number_of_elements; |
1806 | 0 | new_number_of_elements = 0; |
1807 | |
|
1808 | 0 | if( libcdata_array_empty( |
1809 | 0 | internal_source_list->elements_array, |
1810 | 0 | NULL, |
1811 | 0 | error ) != 1 ) |
1812 | 0 | { |
1813 | 0 | libcerror_error_set( |
1814 | 0 | error, |
1815 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1816 | 0 | LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED, |
1817 | 0 | "%s: unable to empty source list elements array.", |
1818 | 0 | function ); |
1819 | |
|
1820 | 0 | result = -1; |
1821 | 0 | } |
1822 | 0 | if( libcdata_array_empty( |
1823 | 0 | internal_source_list->mapped_ranges_array, |
1824 | 0 | NULL, |
1825 | 0 | error ) != 1 ) |
1826 | 0 | { |
1827 | 0 | libcerror_error_set( |
1828 | 0 | error, |
1829 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1830 | 0 | LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED, |
1831 | 0 | "%s: unable to empty source list mapped ranges array.", |
1832 | 0 | function ); |
1833 | |
|
1834 | 0 | result = -1; |
1835 | 0 | } |
1836 | 0 | internal_source_list->size = 0; |
1837 | |
|
1838 | 0 | while( element_index < number_of_elements ) |
1839 | 0 | { |
1840 | 0 | if( libcdata_array_get_entry_by_index( |
1841 | 0 | internal_list->elements_array, |
1842 | 0 | element_index, |
1843 | 0 | (intptr_t **) &list_element, |
1844 | 0 | error ) != 1 ) |
1845 | 0 | { |
1846 | 0 | libcerror_error_set( |
1847 | 0 | error, |
1848 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1849 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1850 | 0 | "%s: unable to retrieve entry: %d from elements array.", |
1851 | 0 | function, |
1852 | 0 | element_index ); |
1853 | |
|
1854 | 0 | goto on_error; |
1855 | 0 | } |
1856 | 0 | ( (libfdata_internal_list_element_t *) list_element )->list = list; |
1857 | 0 | ( (libfdata_internal_list_element_t *) list_element )->element_index = element_index; |
1858 | |
|
1859 | 0 | if( libcdata_array_get_entry_by_index( |
1860 | 0 | internal_list->mapped_ranges_array, |
1861 | 0 | element_index, |
1862 | 0 | (intptr_t **) &mapped_range, |
1863 | 0 | error ) != 1 ) |
1864 | 0 | { |
1865 | 0 | libcerror_error_set( |
1866 | 0 | error, |
1867 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1868 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1869 | 0 | "%s: unable to retrieve entry: %d from mapped ranges array.", |
1870 | 0 | function, |
1871 | 0 | element_index ); |
1872 | |
|
1873 | 0 | goto on_error; |
1874 | 0 | } |
1875 | 0 | if( libfdata_mapped_range_get( |
1876 | 0 | mapped_range, |
1877 | 0 | &mapped_range_offset, |
1878 | 0 | &mapped_range_size, |
1879 | 0 | error ) != 1 ) |
1880 | 0 | { |
1881 | 0 | libcerror_error_set( |
1882 | 0 | error, |
1883 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1884 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1885 | 0 | "%s: unable to retrieve values from mapped range: %d.", |
1886 | 0 | function, |
1887 | 0 | element_index ); |
1888 | |
|
1889 | 0 | goto on_error; |
1890 | 0 | } |
1891 | 0 | if( libfdata_mapped_range_set( |
1892 | 0 | mapped_range, |
1893 | 0 | internal_list->size, |
1894 | 0 | mapped_range_size, |
1895 | 0 | error ) != 1 ) |
1896 | 0 | { |
1897 | 0 | libcerror_error_set( |
1898 | 0 | error, |
1899 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1900 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1901 | 0 | "%s: unable to set values of mapped range: %d.", |
1902 | 0 | function, |
1903 | 0 | element_index ); |
1904 | |
|
1905 | 0 | goto on_error; |
1906 | 0 | } |
1907 | 0 | internal_list->size += mapped_range_size; |
1908 | |
|
1909 | 0 | element_index++; |
1910 | 0 | } |
1911 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1912 | | if( libcnotify_verbose != 0 ) |
1913 | | { |
1914 | | libcnotify_printf( |
1915 | | "\n" ); |
1916 | | } |
1917 | | #endif |
1918 | 0 | return( result ); |
1919 | | |
1920 | 0 | on_error: |
1921 | 0 | if( new_number_of_elements != 0 ) |
1922 | 0 | { |
1923 | 0 | libcdata_array_resize( |
1924 | 0 | internal_list->mapped_ranges_array, |
1925 | 0 | number_of_elements, |
1926 | 0 | NULL, |
1927 | 0 | NULL ); |
1928 | |
|
1929 | 0 | libcdata_array_resize( |
1930 | 0 | internal_list->elements_array, |
1931 | 0 | number_of_elements, |
1932 | 0 | NULL, |
1933 | 0 | NULL ); |
1934 | 0 | } |
1935 | 0 | return( -1 ); |
1936 | 0 | } |
1937 | | |
1938 | | /* Determines if a specific element is set |
1939 | | * Returns 1 if element is set, 0 if not or -1 on error |
1940 | | */ |
1941 | | int libfdata_list_is_element_set( |
1942 | | libfdata_list_t *list, |
1943 | | int element_index, |
1944 | | libcerror_error_t **error ) |
1945 | 0 | { |
1946 | 0 | libfdata_internal_list_t *internal_list = NULL; |
1947 | 0 | libfdata_list_element_t *list_element = NULL; |
1948 | 0 | static char *function = "libfdata_list_is_element_set"; |
1949 | |
|
1950 | 0 | if( list == NULL ) |
1951 | 0 | { |
1952 | 0 | libcerror_error_set( |
1953 | 0 | error, |
1954 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1955 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1956 | 0 | "%s: invalid list.", |
1957 | 0 | function ); |
1958 | |
|
1959 | 0 | return( -1 ); |
1960 | 0 | } |
1961 | 0 | internal_list = (libfdata_internal_list_t *) list; |
1962 | |
|
1963 | 0 | if( libcdata_array_get_entry_by_index( |
1964 | 0 | internal_list->elements_array, |
1965 | 0 | element_index, |
1966 | 0 | (intptr_t **) &list_element, |
1967 | 0 | error ) != 1 ) |
1968 | 0 | { |
1969 | 0 | libcerror_error_set( |
1970 | 0 | error, |
1971 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1972 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1973 | 0 | "%s: unable to retrieve entry: %d from elements array.", |
1974 | 0 | function, |
1975 | 0 | element_index ); |
1976 | |
|
1977 | 0 | return( -1 ); |
1978 | 0 | } |
1979 | 0 | if( list_element == NULL ) |
1980 | 0 | { |
1981 | 0 | return( 0 ); |
1982 | 0 | } |
1983 | 0 | internal_list->current_element_index = element_index; |
1984 | |
|
1985 | 0 | return( 1 ); |
1986 | 0 | } |
1987 | | |
1988 | | /* Mapped range functions |
1989 | | */ |
1990 | | |
1991 | | /* Retrieves the mapped range of a specific element |
1992 | | * Returns 1 if successful or -1 on error |
1993 | | */ |
1994 | | int libfdata_list_get_element_mapped_range( |
1995 | | libfdata_list_t *list, |
1996 | | int element_index, |
1997 | | off64_t *mapped_range_offset, |
1998 | | size64_t *mapped_range_size, |
1999 | | libcerror_error_t **error ) |
2000 | 5.74k | { |
2001 | 5.74k | libfdata_internal_list_t *internal_list = NULL; |
2002 | 5.74k | libfdata_mapped_range_t *mapped_range = NULL; |
2003 | 5.74k | static char *function = "libfdata_list_get_element_mapped_range"; |
2004 | | |
2005 | 5.74k | if( list == NULL ) |
2006 | 0 | { |
2007 | 0 | libcerror_error_set( |
2008 | 0 | error, |
2009 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2010 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2011 | 0 | "%s: invalid list.", |
2012 | 0 | function ); |
2013 | |
|
2014 | 0 | return( -1 ); |
2015 | 0 | } |
2016 | 5.74k | internal_list = (libfdata_internal_list_t *) list; |
2017 | | |
2018 | 5.74k | if( ( internal_list->flags & LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES ) != 0 ) |
2019 | 2.87k | { |
2020 | 2.87k | if( libfdata_list_calculate_mapped_ranges( |
2021 | 2.87k | internal_list, |
2022 | 2.87k | error ) != 1 ) |
2023 | 0 | { |
2024 | 0 | libcerror_error_set( |
2025 | 0 | error, |
2026 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2027 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2028 | 0 | "%s: unable to calculate mapped ranges.", |
2029 | 0 | function ); |
2030 | |
|
2031 | 0 | return( -1 ); |
2032 | 0 | } |
2033 | 2.87k | } |
2034 | 5.74k | if( libcdata_array_get_entry_by_index( |
2035 | 5.74k | internal_list->mapped_ranges_array, |
2036 | 5.74k | element_index, |
2037 | 5.74k | (intptr_t **) &mapped_range, |
2038 | 5.74k | error ) != 1 ) |
2039 | 0 | { |
2040 | 0 | libcerror_error_set( |
2041 | 0 | error, |
2042 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2043 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2044 | 0 | "%s: unable to retrieve entry: %d from mapped ranges array.", |
2045 | 0 | function, |
2046 | 0 | element_index ); |
2047 | |
|
2048 | 0 | return( -1 ); |
2049 | 0 | } |
2050 | 5.74k | if( libfdata_mapped_range_get( |
2051 | 5.74k | mapped_range, |
2052 | 5.74k | mapped_range_offset, |
2053 | 5.74k | mapped_range_size, |
2054 | 5.74k | error ) != 1 ) |
2055 | 0 | { |
2056 | 0 | libcerror_error_set( |
2057 | 0 | error, |
2058 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2059 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2060 | 0 | "%s: unable to retrieve values from mapped range: %d.", |
2061 | 0 | function, |
2062 | 0 | element_index ); |
2063 | |
|
2064 | 0 | return( -1 ); |
2065 | 0 | } |
2066 | 5.74k | return( 1 ); |
2067 | 5.74k | } |
2068 | | |
2069 | | /* Retrieves the mapped offset |
2070 | | * Returns 1 if successful, 0 if not set or -1 on error |
2071 | | */ |
2072 | | int libfdata_list_get_mapped_offset( |
2073 | | libfdata_list_t *list, |
2074 | | off64_t *mapped_offset, |
2075 | | libcerror_error_t **error ) |
2076 | 0 | { |
2077 | 0 | libfdata_internal_list_t *internal_list = NULL; |
2078 | 0 | static char *function = "libfdata_list_get_mapped_offset"; |
2079 | |
|
2080 | 0 | if( list == NULL ) |
2081 | 0 | { |
2082 | 0 | libcerror_error_set( |
2083 | 0 | error, |
2084 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2085 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2086 | 0 | "%s: invalid list.", |
2087 | 0 | function ); |
2088 | |
|
2089 | 0 | return( -1 ); |
2090 | 0 | } |
2091 | 0 | internal_list = (libfdata_internal_list_t *) list; |
2092 | |
|
2093 | 0 | if( mapped_offset == NULL ) |
2094 | 0 | { |
2095 | 0 | libcerror_error_set( |
2096 | 0 | error, |
2097 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2098 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2099 | 0 | "%s: invalid mapped offset.", |
2100 | 0 | function ); |
2101 | |
|
2102 | 0 | return( -1 ); |
2103 | 0 | } |
2104 | 0 | if( ( internal_list->flags & LIBFDATA_LIST_FLAG_HAS_MAPPED_OFFSET ) == 0 ) |
2105 | 0 | { |
2106 | 0 | return( 0 ); |
2107 | 0 | } |
2108 | 0 | *mapped_offset = internal_list->mapped_offset; |
2109 | |
|
2110 | 0 | return( 1 ); |
2111 | 0 | } |
2112 | | |
2113 | | /* Sets the mapped offset |
2114 | | * Returns 1 if successful or -1 on error |
2115 | | */ |
2116 | | int libfdata_list_set_mapped_offset( |
2117 | | libfdata_list_t *list, |
2118 | | off64_t mapped_offset, |
2119 | | libcerror_error_t **error ) |
2120 | 0 | { |
2121 | 0 | libfdata_internal_list_t *internal_list = NULL; |
2122 | 0 | static char *function = "libfdata_list_set_mapped_offset"; |
2123 | |
|
2124 | 0 | if( list == NULL ) |
2125 | 0 | { |
2126 | 0 | libcerror_error_set( |
2127 | 0 | error, |
2128 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2129 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2130 | 0 | "%s: invalid list.", |
2131 | 0 | function ); |
2132 | |
|
2133 | 0 | return( -1 ); |
2134 | 0 | } |
2135 | 0 | internal_list = (libfdata_internal_list_t *) list; |
2136 | |
|
2137 | 0 | if( mapped_offset < 0 ) |
2138 | 0 | { |
2139 | 0 | libcerror_error_set( |
2140 | 0 | error, |
2141 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2142 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
2143 | 0 | "%s: invalid offset value out of bounds.", |
2144 | 0 | function ); |
2145 | |
|
2146 | 0 | return( -1 ); |
2147 | 0 | } |
2148 | | #if defined( HAVE_DEBUG_OUTPUT ) |
2149 | | if( libcnotify_verbose != 0 ) |
2150 | | { |
2151 | | libcnotify_printf( |
2152 | | "%s: mapped offset: %" PRIi64 " (0x%08" PRIx64 ")\n", |
2153 | | function, |
2154 | | mapped_offset, |
2155 | | mapped_offset ); |
2156 | | |
2157 | | libcnotify_printf( |
2158 | | "\n" ); |
2159 | | } |
2160 | | #endif |
2161 | 0 | internal_list->mapped_offset = mapped_offset; |
2162 | 0 | internal_list->flags |= LIBFDATA_LIST_FLAG_HAS_MAPPED_OFFSET | LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES; |
2163 | |
|
2164 | 0 | return( 1 ); |
2165 | 0 | } |
2166 | | |
2167 | | /* Retrieves the mapped size of a specific element |
2168 | | * Returns 1 if successful, 0 if not set or -1 on error |
2169 | | */ |
2170 | | int libfdata_list_get_mapped_size_by_index( |
2171 | | libfdata_list_t *list, |
2172 | | int element_index, |
2173 | | size64_t *mapped_size, |
2174 | | libcerror_error_t **error ) |
2175 | 1.04M | { |
2176 | 1.04M | libfdata_internal_list_t *internal_list = NULL; |
2177 | 1.04M | libfdata_list_element_t *list_element = NULL; |
2178 | 1.04M | static char *function = "libfdata_list_get_mapped_size_by_index"; |
2179 | 1.04M | int result = 0; |
2180 | | |
2181 | 1.04M | if( list == NULL ) |
2182 | 0 | { |
2183 | 0 | libcerror_error_set( |
2184 | 0 | error, |
2185 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2186 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2187 | 0 | "%s: invalid list.", |
2188 | 0 | function ); |
2189 | |
|
2190 | 0 | return( -1 ); |
2191 | 0 | } |
2192 | 1.04M | internal_list = (libfdata_internal_list_t *) list; |
2193 | | |
2194 | 1.04M | if( libcdata_array_get_entry_by_index( |
2195 | 1.04M | internal_list->elements_array, |
2196 | 1.04M | element_index, |
2197 | 1.04M | (intptr_t **) &list_element, |
2198 | 1.04M | error ) != 1 ) |
2199 | 1 | { |
2200 | 1 | libcerror_error_set( |
2201 | 1 | error, |
2202 | 1 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2203 | 1 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2204 | 1 | "%s: unable to retrieve entry: %d from elements array.", |
2205 | 1 | function, |
2206 | 1 | element_index ); |
2207 | | |
2208 | 1 | return( -1 ); |
2209 | 1 | } |
2210 | 1.04M | result = libfdata_list_element_get_mapped_size( |
2211 | 1.04M | list_element, |
2212 | 1.04M | mapped_size, |
2213 | 1.04M | error ); |
2214 | | |
2215 | 1.04M | if( result == -1 ) |
2216 | 0 | { |
2217 | 0 | libcerror_error_set( |
2218 | 0 | error, |
2219 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2220 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2221 | 0 | "%s: unable to retrieve mapped size of element: %d.", |
2222 | 0 | function, |
2223 | 0 | element_index ); |
2224 | |
|
2225 | 0 | return( -1 ); |
2226 | 0 | } |
2227 | 1.04M | internal_list->current_element_index = element_index; |
2228 | | |
2229 | 1.04M | return( result ); |
2230 | 1.04M | } |
2231 | | |
2232 | | /* Sets the mapped size of a specific element |
2233 | | * Returns 1 if successful or -1 on error |
2234 | | */ |
2235 | | int libfdata_list_set_mapped_size_by_index( |
2236 | | libfdata_list_t *list, |
2237 | | int element_index, |
2238 | | size64_t mapped_size, |
2239 | | libcerror_error_t **error ) |
2240 | 5.43k | { |
2241 | 5.43k | libfdata_internal_list_t *internal_list = NULL; |
2242 | 5.43k | libfdata_list_element_t *list_element = NULL; |
2243 | 5.43k | static char *function = "libfdata_list_set_mapped_size_by_index"; |
2244 | | |
2245 | 5.43k | if( list == NULL ) |
2246 | 0 | { |
2247 | 0 | libcerror_error_set( |
2248 | 0 | error, |
2249 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2250 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2251 | 0 | "%s: invalid list.", |
2252 | 0 | function ); |
2253 | |
|
2254 | 0 | return( -1 ); |
2255 | 0 | } |
2256 | 5.43k | internal_list = (libfdata_internal_list_t *) list; |
2257 | | |
2258 | 5.43k | if( libcdata_array_get_entry_by_index( |
2259 | 5.43k | internal_list->elements_array, |
2260 | 5.43k | element_index, |
2261 | 5.43k | (intptr_t **) &list_element, |
2262 | 5.43k | error ) != 1 ) |
2263 | 0 | { |
2264 | 0 | libcerror_error_set( |
2265 | 0 | error, |
2266 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2267 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2268 | 0 | "%s: unable to retrieve entry: %d from elements array.", |
2269 | 0 | function, |
2270 | 0 | element_index ); |
2271 | |
|
2272 | 0 | return( -1 ); |
2273 | 0 | } |
2274 | 5.43k | if( libfdata_list_element_set_mapped_size( |
2275 | 5.43k | list_element, |
2276 | 5.43k | mapped_size, |
2277 | 5.43k | error ) != 1 ) |
2278 | 0 | { |
2279 | 0 | libcerror_error_set( |
2280 | 0 | error, |
2281 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2282 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2283 | 0 | "%s: unable to set mapped size of element: %d.", |
2284 | 0 | function, |
2285 | 0 | element_index ); |
2286 | |
|
2287 | 0 | return( -1 ); |
2288 | 0 | } |
2289 | 5.43k | internal_list->current_element_index = element_index; |
2290 | | |
2291 | 5.43k | return( 1 ); |
2292 | 5.43k | } |
2293 | | |
2294 | | /* Retrieves the data range with its mapped size of a specific element |
2295 | | * Returns 1 if successful, 0 if the element has no mapped size or -1 on error |
2296 | | */ |
2297 | | int libfdata_list_get_element_by_index_with_mapped_size( |
2298 | | libfdata_list_t *list, |
2299 | | int element_index, |
2300 | | int *element_file_index, |
2301 | | off64_t *element_offset, |
2302 | | size64_t *element_size, |
2303 | | uint32_t *element_flags, |
2304 | | size64_t *mapped_size, |
2305 | | libcerror_error_t **error ) |
2306 | 92 | { |
2307 | 92 | libfdata_internal_list_t *internal_list = NULL; |
2308 | 92 | libfdata_list_element_t *list_element = NULL; |
2309 | 92 | static char *function = "libfdata_list_get_element_by_index_with_mapped_size"; |
2310 | 92 | int result = 0; |
2311 | | |
2312 | 92 | if( list == NULL ) |
2313 | 0 | { |
2314 | 0 | libcerror_error_set( |
2315 | 0 | error, |
2316 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2317 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2318 | 0 | "%s: invalid list.", |
2319 | 0 | function ); |
2320 | |
|
2321 | 0 | return( -1 ); |
2322 | 0 | } |
2323 | 92 | internal_list = (libfdata_internal_list_t *) list; |
2324 | | |
2325 | 92 | if( libcdata_array_get_entry_by_index( |
2326 | 92 | internal_list->elements_array, |
2327 | 92 | element_index, |
2328 | 92 | (intptr_t **) &list_element, |
2329 | 92 | error ) != 1 ) |
2330 | 0 | { |
2331 | 0 | libcerror_error_set( |
2332 | 0 | error, |
2333 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2334 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2335 | 0 | "%s: unable to retrieve entry: %d from elements array.", |
2336 | 0 | function, |
2337 | 0 | element_index ); |
2338 | |
|
2339 | 0 | return( -1 ); |
2340 | 0 | } |
2341 | 92 | if( libfdata_list_element_get_data_range( |
2342 | 92 | list_element, |
2343 | 92 | element_file_index, |
2344 | 92 | element_offset, |
2345 | 92 | element_size, |
2346 | 92 | element_flags, |
2347 | 92 | error ) != 1 ) |
2348 | 0 | { |
2349 | 0 | libcerror_error_set( |
2350 | 0 | error, |
2351 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2352 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2353 | 0 | "%s: unable to retrieve data range from list element: %d.", |
2354 | 0 | function, |
2355 | 0 | element_index ); |
2356 | |
|
2357 | 0 | return( -1 ); |
2358 | 0 | } |
2359 | 92 | result = libfdata_list_element_get_mapped_size( |
2360 | 92 | list_element, |
2361 | 92 | mapped_size, |
2362 | 92 | error ); |
2363 | | |
2364 | 92 | if( result == -1 ) |
2365 | 0 | { |
2366 | 0 | libcerror_error_set( |
2367 | 0 | error, |
2368 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2369 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2370 | 0 | "%s: unable to retrieve mapped size of list element: %d.", |
2371 | 0 | function, |
2372 | 0 | element_index ); |
2373 | |
|
2374 | 0 | return( -1 ); |
2375 | 0 | } |
2376 | 92 | internal_list->current_element_index = element_index; |
2377 | | |
2378 | 92 | return( result ); |
2379 | 92 | } |
2380 | | |
2381 | | /* Sets the data range of a specific element with its mapped size |
2382 | | * Returns 1 if successful or -1 on error |
2383 | | */ |
2384 | | int libfdata_list_set_element_by_index_with_mapped_size( |
2385 | | libfdata_list_t *list, |
2386 | | int element_index, |
2387 | | int element_file_index, |
2388 | | off64_t element_offset, |
2389 | | size64_t element_size, |
2390 | | uint32_t element_flags, |
2391 | | size64_t mapped_size, |
2392 | | libcerror_error_t **error ) |
2393 | 0 | { |
2394 | 0 | libfdata_internal_list_t *internal_list = NULL; |
2395 | 0 | libfdata_list_element_t *list_element = NULL; |
2396 | 0 | libfdata_mapped_range_t *mapped_range = NULL; |
2397 | 0 | static char *function = "libfdata_list_set_element_by_index_with_mapped_size"; |
2398 | 0 | off64_t previous_element_offset = 0; |
2399 | 0 | size64_t previous_element_size = 0; |
2400 | 0 | size64_t previous_mapped_size = 0; |
2401 | 0 | uint32_t previous_element_flags = 0; |
2402 | 0 | int previous_element_file_index = 0; |
2403 | 0 | int result = 0; |
2404 | |
|
2405 | | #if defined( HAVE_DEBUG_OUTPUT ) |
2406 | | off64_t mapped_range_offset = 0; |
2407 | | size64_t mapped_range_size = 0; |
2408 | | #endif |
2409 | |
|
2410 | 0 | if( list == NULL ) |
2411 | 0 | { |
2412 | 0 | libcerror_error_set( |
2413 | 0 | error, |
2414 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2415 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2416 | 0 | "%s: invalid list.", |
2417 | 0 | function ); |
2418 | |
|
2419 | 0 | return( -1 ); |
2420 | 0 | } |
2421 | 0 | internal_list = (libfdata_internal_list_t *) list; |
2422 | |
|
2423 | 0 | if( libcdata_array_get_entry_by_index( |
2424 | 0 | internal_list->elements_array, |
2425 | 0 | element_index, |
2426 | 0 | (intptr_t **) &list_element, |
2427 | 0 | error ) != 1 ) |
2428 | 0 | { |
2429 | 0 | libcerror_error_set( |
2430 | 0 | error, |
2431 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2432 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2433 | 0 | "%s: unable to retrieve entry: %d from elements array.", |
2434 | 0 | function, |
2435 | 0 | element_index ); |
2436 | |
|
2437 | 0 | return( -1 ); |
2438 | 0 | } |
2439 | 0 | if( list_element == NULL ) |
2440 | 0 | { |
2441 | 0 | if( libfdata_list_element_initialize( |
2442 | 0 | &list_element, |
2443 | 0 | list, |
2444 | 0 | element_index, |
2445 | 0 | error ) != 1 ) |
2446 | 0 | { |
2447 | 0 | libcerror_error_set( |
2448 | 0 | error, |
2449 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2450 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2451 | 0 | "%s: unable to create list element.", |
2452 | 0 | function ); |
2453 | |
|
2454 | 0 | return( -1 ); |
2455 | 0 | } |
2456 | 0 | if( libcdata_array_set_entry_by_index( |
2457 | 0 | internal_list->elements_array, |
2458 | 0 | element_index, |
2459 | 0 | (intptr_t *) list_element, |
2460 | 0 | error ) != 1 ) |
2461 | 0 | { |
2462 | 0 | libcerror_error_set( |
2463 | 0 | error, |
2464 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2465 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2466 | 0 | "%s: unable to set entry: %d in elements array.", |
2467 | 0 | function, |
2468 | 0 | element_index ); |
2469 | |
|
2470 | 0 | libfdata_list_element_free( |
2471 | 0 | &list_element, |
2472 | 0 | NULL ); |
2473 | |
|
2474 | 0 | return( -1 ); |
2475 | 0 | } |
2476 | 0 | } |
2477 | 0 | else |
2478 | 0 | { |
2479 | 0 | result = libfdata_list_element_get_mapped_size( |
2480 | 0 | list_element, |
2481 | 0 | &previous_mapped_size, |
2482 | 0 | error ); |
2483 | |
|
2484 | 0 | if( result == -1 ) |
2485 | 0 | { |
2486 | 0 | libcerror_error_set( |
2487 | 0 | error, |
2488 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2489 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2490 | 0 | "%s: unable to retrieve mapped size of list element: %d.", |
2491 | 0 | function, |
2492 | 0 | element_index ); |
2493 | |
|
2494 | 0 | return( -1 ); |
2495 | 0 | } |
2496 | 0 | else if( result == 0 ) |
2497 | 0 | { |
2498 | 0 | if( libfdata_list_element_get_data_range( |
2499 | 0 | list_element, |
2500 | 0 | &previous_element_file_index, |
2501 | 0 | &previous_element_offset, |
2502 | 0 | &previous_element_size, |
2503 | 0 | &previous_element_flags, |
2504 | 0 | error ) != 1 ) |
2505 | 0 | { |
2506 | 0 | libcerror_error_set( |
2507 | 0 | error, |
2508 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2509 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2510 | 0 | "%s: unable to retrieve data range of list element: %d.", |
2511 | 0 | function, |
2512 | 0 | element_index ); |
2513 | |
|
2514 | 0 | return( -1 ); |
2515 | 0 | } |
2516 | 0 | } |
2517 | 0 | } |
2518 | 0 | if( libfdata_list_element_set_data_range( |
2519 | 0 | list_element, |
2520 | 0 | element_file_index, |
2521 | 0 | element_offset, |
2522 | 0 | element_size, |
2523 | 0 | element_flags, |
2524 | 0 | error ) != 1 ) |
2525 | 0 | { |
2526 | 0 | libcerror_error_set( |
2527 | 0 | error, |
2528 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2529 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2530 | 0 | "%s: unable to set data range of list element: %d.", |
2531 | 0 | function, |
2532 | 0 | element_index ); |
2533 | |
|
2534 | 0 | return( -1 ); |
2535 | 0 | } |
2536 | 0 | if( libfdata_list_element_set_mapped_size( |
2537 | 0 | list_element, |
2538 | 0 | mapped_size, |
2539 | 0 | error ) != 1 ) |
2540 | 0 | { |
2541 | 0 | libcerror_error_set( |
2542 | 0 | error, |
2543 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2544 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2545 | 0 | "%s: unable to set mapped size of list element.", |
2546 | 0 | function ); |
2547 | |
|
2548 | 0 | return( -1 ); |
2549 | 0 | } |
2550 | | /* Make sure the list has a mapped range entry for every element |
2551 | | */ |
2552 | 0 | if( libcdata_array_get_entry_by_index( |
2553 | 0 | internal_list->mapped_ranges_array, |
2554 | 0 | element_index, |
2555 | 0 | (intptr_t **) &mapped_range, |
2556 | 0 | error ) != 1 ) |
2557 | 0 | { |
2558 | 0 | libcerror_error_set( |
2559 | 0 | error, |
2560 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2561 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2562 | 0 | "%s: unable to retrieve entry: %d from mapped ranges array.", |
2563 | 0 | function, |
2564 | 0 | element_index ); |
2565 | |
|
2566 | 0 | return( -1 ); |
2567 | 0 | } |
2568 | 0 | if( mapped_range == NULL ) |
2569 | 0 | { |
2570 | 0 | if( libfdata_mapped_range_initialize( |
2571 | 0 | &mapped_range, |
2572 | 0 | error ) != 1 ) |
2573 | 0 | { |
2574 | 0 | libcerror_error_set( |
2575 | 0 | error, |
2576 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2577 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2578 | 0 | "%s: unable to create mapped range.", |
2579 | 0 | function ); |
2580 | |
|
2581 | 0 | return( -1 ); |
2582 | 0 | } |
2583 | 0 | if( libcdata_array_set_entry_by_index( |
2584 | 0 | internal_list->mapped_ranges_array, |
2585 | 0 | element_index, |
2586 | 0 | (intptr_t *) mapped_range, |
2587 | 0 | error ) != 1 ) |
2588 | 0 | { |
2589 | 0 | libcerror_error_set( |
2590 | 0 | error, |
2591 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2592 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2593 | 0 | "%s: unable to set entry: %d in mapped ranges array.", |
2594 | 0 | function, |
2595 | 0 | element_index ); |
2596 | |
|
2597 | 0 | libfdata_mapped_range_free( |
2598 | 0 | &mapped_range, |
2599 | 0 | NULL ); |
2600 | |
|
2601 | 0 | return( -1 ); |
2602 | 0 | } |
2603 | 0 | internal_list->size += mapped_size; |
2604 | 0 | internal_list->flags |= LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES; |
2605 | 0 | } |
2606 | 0 | else if( previous_mapped_size != mapped_size ) |
2607 | 0 | { |
2608 | 0 | if( previous_mapped_size != 0 ) |
2609 | 0 | { |
2610 | 0 | internal_list->size -= previous_mapped_size; |
2611 | 0 | } |
2612 | 0 | else |
2613 | 0 | { |
2614 | 0 | internal_list->size -= previous_element_size; |
2615 | 0 | } |
2616 | 0 | if( mapped_size != 0 ) |
2617 | 0 | { |
2618 | 0 | internal_list->size += mapped_size; |
2619 | 0 | } |
2620 | 0 | else |
2621 | 0 | { |
2622 | 0 | internal_list->size += element_size; |
2623 | 0 | } |
2624 | 0 | internal_list->flags |= LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES; |
2625 | 0 | } |
2626 | | #if defined( HAVE_DEBUG_OUTPUT ) |
2627 | | if( libcnotify_verbose != 0 ) |
2628 | | { |
2629 | | libcnotify_printf( |
2630 | | "%s: element: %03d\tfile index: %03d offset: %" PRIi64 " - %" PRIi64 " (0x%08" PRIx64 " - 0x%08" PRIx64 ") (size: %" PRIu64 ")\n", |
2631 | | function, |
2632 | | element_index, |
2633 | | element_file_index, |
2634 | | element_offset, |
2635 | | element_offset + element_size, |
2636 | | element_offset, |
2637 | | element_offset + element_size, |
2638 | | element_size ); |
2639 | | |
2640 | | if( ( internal_list->flags & LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES ) == 0 ) |
2641 | | { |
2642 | | if( libfdata_mapped_range_get( |
2643 | | mapped_range, |
2644 | | &mapped_range_offset, |
2645 | | &mapped_range_size, |
2646 | | error ) != 1 ) |
2647 | | { |
2648 | | libcerror_error_set( |
2649 | | error, |
2650 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2651 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2652 | | "%s: unable to retrieve values from mapped range: %d.", |
2653 | | function, |
2654 | | element_index ); |
2655 | | |
2656 | | return( -1 ); |
2657 | | } |
2658 | | libcnotify_printf( |
2659 | | "%s: element: %03d\tmapped range: %" PRIi64 " - %" PRIi64 " (0x%08" PRIx64 " - 0x%08" PRIx64 ") (size: %" PRIu64 ")\n", |
2660 | | function, |
2661 | | element_index, |
2662 | | mapped_range_offset, |
2663 | | mapped_range_offset + mapped_range_size, |
2664 | | mapped_range_offset, |
2665 | | mapped_range_offset + mapped_range_size, |
2666 | | mapped_range_size ); |
2667 | | } |
2668 | | libcnotify_printf( |
2669 | | "\n" ); |
2670 | | } |
2671 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
2672 | | |
2673 | 0 | internal_list->current_element_index = element_index; |
2674 | |
|
2675 | 0 | return( 1 ); |
2676 | 0 | } |
2677 | | |
2678 | | /* Appends an element data range with its mapped size |
2679 | | * Returns 1 if successful or -1 on error |
2680 | | */ |
2681 | | int libfdata_list_append_element_with_mapped_size( |
2682 | | libfdata_list_t *list, |
2683 | | int *element_index, |
2684 | | int element_file_index, |
2685 | | off64_t element_offset, |
2686 | | size64_t element_size, |
2687 | | uint32_t element_flags, |
2688 | | size64_t mapped_size, |
2689 | | libcerror_error_t **error ) |
2690 | 1.28M | { |
2691 | 1.28M | libfdata_internal_list_t *internal_list = NULL; |
2692 | 1.28M | libfdata_list_element_t *list_element = NULL; |
2693 | 1.28M | libfdata_mapped_range_t *mapped_range = NULL; |
2694 | 1.28M | static char *function = "libfdata_list_append_element_with_mapped_size"; |
2695 | 1.28M | off64_t mapped_offset = 0; |
2696 | 1.28M | int mapped_range_index = -1; |
2697 | 1.28M | uint8_t list_flags = 0; |
2698 | | |
2699 | 1.28M | if( list == NULL ) |
2700 | 0 | { |
2701 | 0 | libcerror_error_set( |
2702 | 0 | error, |
2703 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2704 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2705 | 0 | "%s: invalid list.", |
2706 | 0 | function ); |
2707 | |
|
2708 | 0 | return( -1 ); |
2709 | 0 | } |
2710 | 1.28M | internal_list = (libfdata_internal_list_t *) list; |
2711 | | |
2712 | 1.28M | if( element_index == NULL ) |
2713 | 0 | { |
2714 | 0 | libcerror_error_set( |
2715 | 0 | error, |
2716 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2717 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2718 | 0 | "%s: invalid element index.", |
2719 | 0 | function ); |
2720 | |
|
2721 | 0 | return( -1 ); |
2722 | 0 | } |
2723 | 1.28M | if( libfdata_mapped_range_initialize( |
2724 | 1.28M | &mapped_range, |
2725 | 1.28M | error ) != 1 ) |
2726 | 0 | { |
2727 | 0 | libcerror_error_set( |
2728 | 0 | error, |
2729 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2730 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2731 | 0 | "%s: unable to create mapped range.", |
2732 | 0 | function ); |
2733 | |
|
2734 | 0 | goto on_error; |
2735 | 0 | } |
2736 | 1.28M | mapped_offset = internal_list->mapped_offset + (off64_t) internal_list->size; |
2737 | | |
2738 | 1.28M | if( libfdata_mapped_range_set( |
2739 | 1.28M | mapped_range, |
2740 | 1.28M | mapped_offset, |
2741 | 1.28M | mapped_size, |
2742 | 1.28M | error ) != 1 ) |
2743 | 0 | { |
2744 | 0 | libcerror_error_set( |
2745 | 0 | error, |
2746 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2747 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2748 | 0 | "%s: unable to set mapped range values.", |
2749 | 0 | function ); |
2750 | |
|
2751 | 0 | goto on_error; |
2752 | 0 | } |
2753 | 1.28M | if( libcdata_array_append_entry( |
2754 | 1.28M | internal_list->mapped_ranges_array, |
2755 | 1.28M | &mapped_range_index, |
2756 | 1.28M | (intptr_t *) mapped_range, |
2757 | 1.28M | error ) != 1 ) |
2758 | 0 | { |
2759 | 0 | libcerror_error_set( |
2760 | 0 | error, |
2761 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2762 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
2763 | 0 | "%s: unable to append mapped range to array.", |
2764 | 0 | function ); |
2765 | |
|
2766 | 0 | goto on_error; |
2767 | 0 | } |
2768 | 1.28M | if( libfdata_list_element_initialize( |
2769 | 1.28M | &list_element, |
2770 | 1.28M | list, |
2771 | 1.28M | 0, |
2772 | 1.28M | error ) != 1 ) |
2773 | 0 | { |
2774 | 0 | libcerror_error_set( |
2775 | 0 | error, |
2776 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2777 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2778 | 0 | "%s: unable to create list element.", |
2779 | 0 | function ); |
2780 | |
|
2781 | 0 | goto on_error; |
2782 | 0 | } |
2783 | 1.28M | if( libfdata_list_element_set_data_range( |
2784 | 1.28M | list_element, |
2785 | 1.28M | element_file_index, |
2786 | 1.28M | element_offset, |
2787 | 1.28M | element_size, |
2788 | 1.28M | element_flags, |
2789 | 1.28M | error ) != 1 ) |
2790 | 43 | { |
2791 | 43 | libcerror_error_set( |
2792 | 43 | error, |
2793 | 43 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2794 | 43 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2795 | 43 | "%s: unable to set data range of list element.", |
2796 | 43 | function ); |
2797 | | |
2798 | 43 | goto on_error; |
2799 | 43 | } |
2800 | 1.28M | list_flags = internal_list->flags; |
2801 | | |
2802 | 1.28M | if( libfdata_list_element_set_mapped_size( |
2803 | 1.28M | list_element, |
2804 | 1.28M | mapped_size, |
2805 | 1.28M | error ) != 1 ) |
2806 | 0 | { |
2807 | 0 | libcerror_error_set( |
2808 | 0 | error, |
2809 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2810 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2811 | 0 | "%s: unable to set mapped size of list element.", |
2812 | 0 | function ); |
2813 | |
|
2814 | 0 | goto on_error; |
2815 | 0 | } |
2816 | | /* Setting the mapped size in the list element will set the calculate mapped ranges flag in the list |
2817 | | * Reset the flag if it was not set before setting the mapped size in the list element |
2818 | | */ |
2819 | 1.28M | if( ( list_flags & LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES ) == 0 ) |
2820 | 1.28M | { |
2821 | 1.28M | internal_list->flags &= ~( LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES ); |
2822 | 1.28M | } |
2823 | 1.28M | if( libcdata_array_append_entry( |
2824 | 1.28M | internal_list->elements_array, |
2825 | 1.28M | element_index, |
2826 | 1.28M | (intptr_t *) list_element, |
2827 | 1.28M | error ) != 1 ) |
2828 | 0 | { |
2829 | 0 | libcerror_error_set( |
2830 | 0 | error, |
2831 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2832 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
2833 | 0 | "%s: unable to append list element to elements array.", |
2834 | 0 | function ); |
2835 | |
|
2836 | 0 | goto on_error; |
2837 | 0 | } |
2838 | 1.28M | mapped_range_index = -1; |
2839 | 1.28M | mapped_range = NULL; |
2840 | | |
2841 | 1.28M | if( libfdata_list_element_set_element_index( |
2842 | 1.28M | list_element, |
2843 | 1.28M | *element_index, |
2844 | 1.28M | error ) != 1 ) |
2845 | 0 | { |
2846 | 0 | libcerror_error_set( |
2847 | 0 | error, |
2848 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2849 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2850 | 0 | "%s: unable to set list element index.", |
2851 | 0 | function ); |
2852 | |
|
2853 | 0 | list_element = NULL; |
2854 | |
|
2855 | 0 | goto on_error; |
2856 | 0 | } |
2857 | | #if defined( HAVE_DEBUG_OUTPUT ) |
2858 | | if( libcnotify_verbose != 0 ) |
2859 | | { |
2860 | | libcnotify_printf( |
2861 | | "%s: element: %03d\tfile index: %03d offset: %" PRIi64 " - %" PRIi64 " (0x%08" PRIx64 " - 0x%08" PRIx64 ") (size: %" PRIu64 ")\n", |
2862 | | function, |
2863 | | *element_index, |
2864 | | element_file_index, |
2865 | | element_offset, |
2866 | | element_offset + element_size, |
2867 | | element_offset, |
2868 | | element_offset + element_size, |
2869 | | element_size ); |
2870 | | |
2871 | | libcnotify_printf( |
2872 | | "%s: element: %03d\tmapped range: %" PRIi64 " - %" PRIi64 " (0x%08" PRIx64 " - 0x%08" PRIx64 ") (size: %" PRIu64 ")\n", |
2873 | | function, |
2874 | | *element_index, |
2875 | | mapped_offset, |
2876 | | mapped_offset + mapped_size, |
2877 | | mapped_offset, |
2878 | | mapped_offset + mapped_size, |
2879 | | mapped_size ); |
2880 | | |
2881 | | libcnotify_printf( |
2882 | | "\n" ); |
2883 | | } |
2884 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
2885 | | |
2886 | 1.28M | internal_list->current_element_index = *element_index; |
2887 | 1.28M | internal_list->size += mapped_size; |
2888 | | |
2889 | 1.28M | return( 1 ); |
2890 | | |
2891 | 43 | on_error: |
2892 | 43 | if( list_element != NULL ) |
2893 | 43 | { |
2894 | 43 | libfdata_list_element_free( |
2895 | 43 | &list_element, |
2896 | 43 | NULL ); |
2897 | 43 | } |
2898 | 43 | if( mapped_range_index != -1 ) |
2899 | 43 | { |
2900 | 43 | libcdata_array_set_entry_by_index( |
2901 | 43 | internal_list->mapped_ranges_array, |
2902 | 43 | mapped_range_index, |
2903 | 43 | NULL, |
2904 | 43 | NULL ); |
2905 | 43 | } |
2906 | 43 | if( mapped_range != NULL ) |
2907 | 43 | { |
2908 | 43 | libfdata_mapped_range_free( |
2909 | 43 | &mapped_range, |
2910 | 43 | NULL ); |
2911 | 43 | } |
2912 | 43 | return( -1 ); |
2913 | 1.28M | } |
2914 | | |
2915 | | /* Calculates the mapped ranges |
2916 | | * Returns 1 if successful or -1 on error |
2917 | | */ |
2918 | | int libfdata_list_calculate_mapped_ranges( |
2919 | | libfdata_internal_list_t *internal_list, |
2920 | | libcerror_error_t **error ) |
2921 | 3.21k | { |
2922 | 3.21k | libfdata_list_element_t *list_element = NULL; |
2923 | 3.21k | libfdata_mapped_range_t *mapped_range = NULL; |
2924 | 3.21k | static char *function = "libfdata_list_calculate_mapped_ranges"; |
2925 | 3.21k | off64_t mapped_offset = 0; |
2926 | 3.21k | off64_t element_offset = 0; |
2927 | 3.21k | size64_t element_size = 0; |
2928 | 3.21k | size64_t mapped_size = 0; |
2929 | 3.21k | uint32_t element_flags = 0; |
2930 | 3.21k | int element_file_index = -1; |
2931 | 3.21k | int element_index = -1; |
2932 | 3.21k | int number_of_elements = 0; |
2933 | 3.21k | int result = 0; |
2934 | | |
2935 | 3.21k | if( internal_list == NULL ) |
2936 | 0 | { |
2937 | 0 | libcerror_error_set( |
2938 | 0 | error, |
2939 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2940 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2941 | 0 | "%s: invalid list.", |
2942 | 0 | function ); |
2943 | |
|
2944 | 0 | return( -1 ); |
2945 | 0 | } |
2946 | 3.21k | if( libcdata_array_get_number_of_entries( |
2947 | 3.21k | internal_list->elements_array, |
2948 | 3.21k | &number_of_elements, |
2949 | 3.21k | error ) != 1 ) |
2950 | 0 | { |
2951 | 0 | libcerror_error_set( |
2952 | 0 | error, |
2953 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2954 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2955 | 0 | "%s: unable to retrieve number of elements from elements array.", |
2956 | 0 | function ); |
2957 | |
|
2958 | 0 | return( -1 ); |
2959 | 0 | } |
2960 | 3.21k | mapped_offset = internal_list->mapped_offset; |
2961 | | |
2962 | 3.21k | for( element_index = 0; |
2963 | 6.52k | element_index < number_of_elements; |
2964 | 3.31k | element_index++ ) |
2965 | 3.31k | { |
2966 | 3.31k | if( libcdata_array_get_entry_by_index( |
2967 | 3.31k | internal_list->elements_array, |
2968 | 3.31k | element_index, |
2969 | 3.31k | (intptr_t **) &list_element, |
2970 | 3.31k | error ) != 1 ) |
2971 | 0 | { |
2972 | 0 | libcerror_error_set( |
2973 | 0 | error, |
2974 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2975 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2976 | 0 | "%s: unable to retrieve entry: %d from elements array.", |
2977 | 0 | function, |
2978 | 0 | element_index ); |
2979 | |
|
2980 | 0 | return( -1 ); |
2981 | 0 | } |
2982 | 3.31k | if( libcdata_array_get_entry_by_index( |
2983 | 3.31k | internal_list->mapped_ranges_array, |
2984 | 3.31k | element_index, |
2985 | 3.31k | (intptr_t **) &mapped_range, |
2986 | 3.31k | error ) != 1 ) |
2987 | 0 | { |
2988 | 0 | libcerror_error_set( |
2989 | 0 | error, |
2990 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2991 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2992 | 0 | "%s: unable to retrieve entry: %d from mapped ranges array.", |
2993 | 0 | function, |
2994 | 0 | element_index ); |
2995 | |
|
2996 | 0 | return( -1 ); |
2997 | 0 | } |
2998 | 3.31k | if( libfdata_list_element_get_data_range( |
2999 | 3.31k | list_element, |
3000 | 3.31k | &element_file_index, |
3001 | 3.31k | &element_offset, |
3002 | 3.31k | &element_size, |
3003 | 3.31k | &element_flags, |
3004 | 3.31k | error ) != 1 ) |
3005 | 0 | { |
3006 | 0 | libcerror_error_set( |
3007 | 0 | error, |
3008 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3009 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3010 | 0 | "%s: unable to retrieve data range of list element: %d.", |
3011 | 0 | function, |
3012 | 0 | element_index ); |
3013 | |
|
3014 | 0 | return( -1 ); |
3015 | 0 | } |
3016 | 3.31k | result = libfdata_list_element_get_mapped_size( |
3017 | 3.31k | list_element, |
3018 | 3.31k | &mapped_size, |
3019 | 3.31k | error ); |
3020 | | |
3021 | 3.31k | if( result == -1 ) |
3022 | 0 | { |
3023 | 0 | libcerror_error_set( |
3024 | 0 | error, |
3025 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3026 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3027 | 0 | "%s: unable to retrieve mapped size of list element: %d.", |
3028 | 0 | function, |
3029 | 0 | element_index ); |
3030 | |
|
3031 | 0 | return( -1 ); |
3032 | 0 | } |
3033 | 3.31k | else if( result == 0 ) |
3034 | 2.87k | { |
3035 | 2.87k | mapped_size = element_size; |
3036 | 2.87k | } |
3037 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3038 | | if( libcnotify_verbose != 0 ) |
3039 | | { |
3040 | | libcnotify_printf( |
3041 | | "%s: element: %03d\tfile index: %03d offset: %" PRIi64 " - %" PRIi64 " (0x%08" PRIx64 " - 0x%08" PRIx64 ") (size: %" PRIu64 ")\n", |
3042 | | function, |
3043 | | element_index, |
3044 | | element_file_index, |
3045 | | element_offset, |
3046 | | element_offset + element_size, |
3047 | | element_offset, |
3048 | | element_offset + element_size, |
3049 | | element_size ); |
3050 | | |
3051 | | libcnotify_printf( |
3052 | | "%s: element: %03d\tmapped range: %" PRIi64 " - %" PRIi64 " (0x%08" PRIx64 " - 0x%08" PRIx64 ") (size: %" PRIu64 ")\n", |
3053 | | function, |
3054 | | element_index, |
3055 | | mapped_offset, |
3056 | | mapped_offset + mapped_size, |
3057 | | mapped_offset, |
3058 | | mapped_offset + mapped_size, |
3059 | | mapped_size ); |
3060 | | } |
3061 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
3062 | | |
3063 | 3.31k | if( libfdata_mapped_range_set( |
3064 | 3.31k | mapped_range, |
3065 | 3.31k | mapped_offset, |
3066 | 3.31k | mapped_size, |
3067 | 3.31k | error ) != 1 ) |
3068 | 0 | { |
3069 | 0 | libcerror_error_set( |
3070 | 0 | error, |
3071 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3072 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
3073 | 0 | "%s: unable to set mapped range: %d values.", |
3074 | 0 | function, |
3075 | 0 | element_index ); |
3076 | |
|
3077 | 0 | return( -1 ); |
3078 | 0 | } |
3079 | 3.31k | mapped_offset += (off64_t) mapped_size; |
3080 | 3.31k | } |
3081 | 3.21k | internal_list->size = (size64_t) mapped_offset - internal_list->mapped_offset; |
3082 | 3.21k | internal_list->flags &= ~( LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES ); |
3083 | | |
3084 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3085 | | if( libcnotify_verbose != 0 ) |
3086 | | { |
3087 | | libcnotify_printf( |
3088 | | "\n" ); |
3089 | | } |
3090 | | #endif |
3091 | 3.21k | return( 1 ); |
3092 | 3.21k | } |
3093 | | |
3094 | | /* Retrieves the element index for a specific offset |
3095 | | * The element_data_offset value is set to the offset relative to the start of the element |
3096 | | * Returns 1 if successful, 0 if not or -1 on error |
3097 | | */ |
3098 | | int libfdata_list_get_element_index_at_offset( |
3099 | | libfdata_list_t *list, |
3100 | | off64_t offset, |
3101 | | int *element_index, |
3102 | | off64_t *element_data_offset, |
3103 | | libcerror_error_t **error ) |
3104 | 658k | { |
3105 | 658k | libfdata_internal_list_t *internal_list = NULL; |
3106 | 658k | libfdata_mapped_range_t *mapped_range = NULL; |
3107 | 658k | static char *function = "libfdata_list_get_element_index_at_offset"; |
3108 | 658k | off64_t list_offset = 0; |
3109 | 658k | off64_t mapped_range_end_offset = 0; |
3110 | 658k | off64_t mapped_range_start_offset = 0; |
3111 | 658k | size64_t mapped_range_size = 0; |
3112 | 658k | int initial_element_index = 0; |
3113 | 658k | int number_of_elements = 0; |
3114 | 658k | int result = 0; |
3115 | 658k | int search_element_index = 0; |
3116 | | |
3117 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3118 | | libfdata_list_element_t *element = NULL; |
3119 | | off64_t element_offset = 0; |
3120 | | size64_t element_size = 0; |
3121 | | uint32_t element_flags = 0; |
3122 | | int element_file_index = -1; |
3123 | | #endif |
3124 | | |
3125 | 658k | if( list == NULL ) |
3126 | 0 | { |
3127 | 0 | libcerror_error_set( |
3128 | 0 | error, |
3129 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3130 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3131 | 0 | "%s: invalid list.", |
3132 | 0 | function ); |
3133 | |
|
3134 | 0 | return( -1 ); |
3135 | 0 | } |
3136 | 658k | internal_list = (libfdata_internal_list_t *) list; |
3137 | | |
3138 | 658k | if( offset < 0 ) |
3139 | 0 | { |
3140 | 0 | libcerror_error_set( |
3141 | 0 | error, |
3142 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3143 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_LESS_THAN_ZERO, |
3144 | 0 | "%s: invalid offset value less than zero.", |
3145 | 0 | function ); |
3146 | |
|
3147 | 0 | return( -1 ); |
3148 | 0 | } |
3149 | 658k | if( element_index == NULL ) |
3150 | 0 | { |
3151 | 0 | libcerror_error_set( |
3152 | 0 | error, |
3153 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3154 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3155 | 0 | "%s: invalid element index.", |
3156 | 0 | function ); |
3157 | |
|
3158 | 0 | return( -1 ); |
3159 | 0 | } |
3160 | 658k | if( element_data_offset == NULL ) |
3161 | 0 | { |
3162 | 0 | libcerror_error_set( |
3163 | 0 | error, |
3164 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3165 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3166 | 0 | "%s: invalid element data offset.", |
3167 | 0 | function ); |
3168 | |
|
3169 | 0 | return( -1 ); |
3170 | 0 | } |
3171 | 658k | if( ( internal_list->flags & LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES ) != 0 ) |
3172 | 345 | { |
3173 | 345 | if( libfdata_list_calculate_mapped_ranges( |
3174 | 345 | internal_list, |
3175 | 345 | error ) != 1 ) |
3176 | 0 | { |
3177 | 0 | libcerror_error_set( |
3178 | 0 | error, |
3179 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3180 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3181 | 0 | "%s: unable to calculate mapped ranges.", |
3182 | 0 | function ); |
3183 | |
|
3184 | 0 | return( -1 ); |
3185 | 0 | } |
3186 | 345 | } |
3187 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3188 | | if( libcnotify_verbose != 0 ) |
3189 | | { |
3190 | | libcnotify_printf( |
3191 | | "%s: requested offset: %" PRIi64 " (0x%08" PRIx64 ")\n", |
3192 | | function, |
3193 | | offset, |
3194 | | offset ); |
3195 | | } |
3196 | | #endif |
3197 | 658k | if( internal_list->size == 0 ) |
3198 | 90 | { |
3199 | 90 | return( 0 ); |
3200 | 90 | } |
3201 | 658k | if( offset < internal_list->mapped_offset ) |
3202 | 0 | { |
3203 | 0 | return( 0 ); |
3204 | 0 | } |
3205 | 658k | list_offset = offset - internal_list->mapped_offset; |
3206 | | |
3207 | 658k | if( (size64_t) list_offset >= internal_list->size ) |
3208 | 16.7k | { |
3209 | 16.7k | return( 0 ); |
3210 | 16.7k | } |
3211 | 642k | if( libcdata_array_get_number_of_entries( |
3212 | 642k | internal_list->mapped_ranges_array, |
3213 | 642k | &number_of_elements, |
3214 | 642k | error ) != 1 ) |
3215 | 0 | { |
3216 | 0 | libcerror_error_set( |
3217 | 0 | error, |
3218 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3219 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3220 | 0 | "%s: unable to retrieve number of entries from mapped ranges array.", |
3221 | 0 | function ); |
3222 | |
|
3223 | 0 | return( -1 ); |
3224 | 0 | } |
3225 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3226 | | if( libcnotify_verbose != 0 ) |
3227 | | { |
3228 | | libcnotify_printf( |
3229 | | "%s: number of elements: %d\n", |
3230 | | function, |
3231 | | number_of_elements ); |
3232 | | } |
3233 | | #endif |
3234 | | /* This assumes a fairly even distribution of the sizes of the elements |
3235 | | */ |
3236 | 642k | initial_element_index = (int) ( ( number_of_elements * list_offset ) / internal_list->size ); |
3237 | | |
3238 | | /* Look for the corresponding element upwards in the array |
3239 | | */ |
3240 | 642k | for( search_element_index = initial_element_index; |
3241 | 1.78M | search_element_index < number_of_elements; |
3242 | 1.14M | search_element_index++ ) |
3243 | 1.78M | { |
3244 | 1.78M | if( libcdata_array_get_entry_by_index( |
3245 | 1.78M | internal_list->mapped_ranges_array, |
3246 | 1.78M | search_element_index, |
3247 | 1.78M | (intptr_t **) &mapped_range, |
3248 | 1.78M | error ) != 1 ) |
3249 | 0 | { |
3250 | 0 | libcerror_error_set( |
3251 | 0 | error, |
3252 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3253 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3254 | 0 | "%s: unable to retrieve entry: %d from mapped ranges array.", |
3255 | 0 | function, |
3256 | 0 | search_element_index ); |
3257 | |
|
3258 | 0 | return( -1 ); |
3259 | 0 | } |
3260 | 1.78M | if( libfdata_mapped_range_get( |
3261 | 1.78M | mapped_range, |
3262 | 1.78M | &mapped_range_start_offset, |
3263 | 1.78M | &mapped_range_size, |
3264 | 1.78M | error ) != 1 ) |
3265 | 0 | { |
3266 | 0 | libcerror_error_set( |
3267 | 0 | error, |
3268 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3269 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
3270 | 0 | "%s: unable to retrieve values from mapped range: %d.", |
3271 | 0 | function, |
3272 | 0 | search_element_index ); |
3273 | |
|
3274 | 0 | return( -1 ); |
3275 | 0 | } |
3276 | 1.78M | mapped_range_end_offset = mapped_range_start_offset + (off64_t) mapped_range_size; |
3277 | | |
3278 | 1.78M | if( mapped_range_end_offset < mapped_range_start_offset ) |
3279 | 0 | { |
3280 | 0 | libcerror_error_set( |
3281 | 0 | error, |
3282 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3283 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
3284 | 0 | "%s: invalid element: %d - mapped range value out of bounds.", |
3285 | 0 | function, |
3286 | 0 | search_element_index ); |
3287 | |
|
3288 | 0 | return( -1 ); |
3289 | 0 | } |
3290 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3291 | | if( libcnotify_verbose != 0 ) |
3292 | | { |
3293 | | libcnotify_printf( |
3294 | | "%s: element: %03d\tmapped range: %" PRIi64 " - %" PRIi64 " (0x%08" PRIx64 " - 0x%08" PRIx64 ") (size: %" PRIu64 ")\n", |
3295 | | function, |
3296 | | search_element_index, |
3297 | | mapped_range_start_offset, |
3298 | | mapped_range_end_offset, |
3299 | | mapped_range_start_offset, |
3300 | | mapped_range_end_offset, |
3301 | | mapped_range_size ); |
3302 | | } |
3303 | | #endif |
3304 | | /* Check if the offset is in the mapped range |
3305 | | */ |
3306 | 1.78M | if( ( offset >= mapped_range_start_offset ) |
3307 | 1.78M | && ( offset < mapped_range_end_offset ) ) |
3308 | 629k | { |
3309 | 629k | offset -= mapped_range_start_offset; |
3310 | | |
3311 | 629k | break; |
3312 | 629k | } |
3313 | | /* Check if the offset is out of bounds |
3314 | | */ |
3315 | 1.16M | if( offset < mapped_range_start_offset ) |
3316 | 12.9k | { |
3317 | 12.9k | search_element_index = number_of_elements; |
3318 | | |
3319 | 12.9k | break; |
3320 | 12.9k | } |
3321 | 1.16M | } |
3322 | 642k | if( search_element_index >= number_of_elements ) |
3323 | 12.9k | { |
3324 | | /* Look for the corresponding element downwards in the array |
3325 | | */ |
3326 | 12.9k | for( search_element_index = initial_element_index; |
3327 | 213k | search_element_index >= 0; |
3328 | 200k | search_element_index-- ) |
3329 | 213k | { |
3330 | 213k | if( libcdata_array_get_entry_by_index( |
3331 | 213k | internal_list->mapped_ranges_array, |
3332 | 213k | search_element_index, |
3333 | 213k | (intptr_t **) &mapped_range, |
3334 | 213k | error ) != 1 ) |
3335 | 0 | { |
3336 | 0 | libcerror_error_set( |
3337 | 0 | error, |
3338 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3339 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3340 | 0 | "%s: unable to retrieve entry: %d from mapped ranges array.", |
3341 | 0 | function, |
3342 | 0 | search_element_index ); |
3343 | |
|
3344 | 0 | return( -1 ); |
3345 | 0 | } |
3346 | 213k | if( libfdata_mapped_range_get( |
3347 | 213k | mapped_range, |
3348 | 213k | &mapped_range_start_offset, |
3349 | 213k | &mapped_range_size, |
3350 | 213k | error ) != 1 ) |
3351 | 0 | { |
3352 | 0 | libcerror_error_set( |
3353 | 0 | error, |
3354 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3355 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
3356 | 0 | "%s: unable to retrieve values from mapped range: %d.", |
3357 | 0 | function, |
3358 | 0 | search_element_index ); |
3359 | |
|
3360 | 0 | return( -1 ); |
3361 | 0 | } |
3362 | 213k | mapped_range_end_offset = mapped_range_start_offset + (off64_t) mapped_range_size; |
3363 | | |
3364 | 213k | if( mapped_range_end_offset < mapped_range_start_offset ) |
3365 | 0 | { |
3366 | 0 | libcerror_error_set( |
3367 | 0 | error, |
3368 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3369 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
3370 | 0 | "%s: invalid element: %d - mapped range value out of bounds.", |
3371 | 0 | function, |
3372 | 0 | search_element_index ); |
3373 | |
|
3374 | 0 | return( -1 ); |
3375 | 0 | } |
3376 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3377 | | if( libcnotify_verbose != 0 ) |
3378 | | { |
3379 | | libcnotify_printf( |
3380 | | "%s: element: %03d\tmapped range: %" PRIi64 " - %" PRIi64 " (0x%08" PRIx64 " - 0x%08" PRIx64 ") (size: %" PRIu64 ")\n", |
3381 | | function, |
3382 | | search_element_index, |
3383 | | mapped_range_start_offset, |
3384 | | mapped_range_end_offset, |
3385 | | mapped_range_start_offset, |
3386 | | mapped_range_end_offset, |
3387 | | mapped_range_size ); |
3388 | | } |
3389 | | #endif |
3390 | | /* Check if the offset is in the mapped range |
3391 | | */ |
3392 | 213k | if( ( offset >= mapped_range_start_offset ) |
3393 | 213k | && ( offset < mapped_range_end_offset ) ) |
3394 | 12.9k | { |
3395 | 12.9k | offset -= mapped_range_start_offset; |
3396 | | |
3397 | 12.9k | break; |
3398 | 12.9k | } |
3399 | | /* Check if the offset is out of bounds |
3400 | | */ |
3401 | 200k | if( offset > mapped_range_start_offset ) |
3402 | 0 | { |
3403 | 0 | search_element_index--; |
3404 | |
|
3405 | 0 | break; |
3406 | 0 | } |
3407 | 200k | } |
3408 | 12.9k | } |
3409 | 642k | if( ( search_element_index >= 0 ) |
3410 | 642k | && ( search_element_index < number_of_elements ) ) |
3411 | 642k | { |
3412 | 642k | if( offset < 0 ) |
3413 | 0 | { |
3414 | 0 | libcerror_error_set( |
3415 | 0 | error, |
3416 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3417 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
3418 | 0 | "%s: invalid offset value out of bounds.", |
3419 | 0 | function ); |
3420 | |
|
3421 | 0 | return( -1 ); |
3422 | 0 | } |
3423 | 642k | *element_data_offset = offset; |
3424 | | |
3425 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3426 | | if( libcnotify_verbose != 0 ) |
3427 | | { |
3428 | | if( libcdata_array_get_entry_by_index( |
3429 | | internal_list->elements_array, |
3430 | | search_element_index, |
3431 | | (intptr_t **) &element, |
3432 | | error ) != 1 ) |
3433 | | { |
3434 | | libcerror_error_set( |
3435 | | error, |
3436 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3437 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3438 | | "%s: unable to retrieve entry: %d from elements array.", |
3439 | | function, |
3440 | | search_element_index ); |
3441 | | |
3442 | | return( -1 ); |
3443 | | } |
3444 | | if( libfdata_list_element_get_data_range( |
3445 | | element, |
3446 | | &element_file_index, |
3447 | | &element_offset, |
3448 | | &element_size, |
3449 | | &element_flags, |
3450 | | error ) != 1 ) |
3451 | | { |
3452 | | libcerror_error_set( |
3453 | | error, |
3454 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3455 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3456 | | "%s: unable to retrieve data range of list element: %d.", |
3457 | | function, |
3458 | | search_element_index ); |
3459 | | |
3460 | | return( -1 ); |
3461 | | } |
3462 | | libcnotify_printf( |
3463 | | "%s: element: %03d\tfile index: %03d offset: %" PRIi64 " - %" PRIi64 " (0x%08" PRIx64 " - 0x%08" PRIx64 ") (size: %" PRIu64 ")\n", |
3464 | | function, |
3465 | | search_element_index, |
3466 | | element_file_index, |
3467 | | element_offset, |
3468 | | element_offset + element_size, |
3469 | | element_offset, |
3470 | | element_offset + element_size, |
3471 | | element_size ); |
3472 | | } |
3473 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
3474 | | |
3475 | 642k | internal_list->current_element_index = search_element_index; |
3476 | | |
3477 | 642k | result = 1; |
3478 | 642k | } |
3479 | 642k | if( result == 1 ) |
3480 | 642k | { |
3481 | 642k | *element_index = search_element_index; |
3482 | 642k | } |
3483 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3484 | | if( libcnotify_verbose != 0 ) |
3485 | | { |
3486 | | libcnotify_printf( |
3487 | | "\n" ); |
3488 | | } |
3489 | | #endif |
3490 | 642k | return( result ); |
3491 | 642k | } |
3492 | | |
3493 | | /* Retrieves the list element for a specific offset |
3494 | | * The element_data_offset value is set to the offset relative to the start of the element |
3495 | | * Returns 1 if successful, 0 if not or -1 on error |
3496 | | */ |
3497 | | int libfdata_list_get_list_element_at_offset( |
3498 | | libfdata_list_t *list, |
3499 | | off64_t offset, |
3500 | | int *element_index, |
3501 | | off64_t *element_data_offset, |
3502 | | libfdata_list_element_t **element, |
3503 | | libcerror_error_t **error ) |
3504 | 621k | { |
3505 | 621k | libfdata_internal_list_t *internal_list = NULL; |
3506 | 621k | static char *function = "libfdata_list_get_list_element_at_offset"; |
3507 | 621k | int result = 0; |
3508 | | |
3509 | 621k | if( list == NULL ) |
3510 | 0 | { |
3511 | 0 | libcerror_error_set( |
3512 | 0 | error, |
3513 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3514 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3515 | 0 | "%s: invalid list.", |
3516 | 0 | function ); |
3517 | |
|
3518 | 0 | return( -1 ); |
3519 | 0 | } |
3520 | 621k | internal_list = (libfdata_internal_list_t *) list; |
3521 | | |
3522 | 621k | if( offset < 0 ) |
3523 | 0 | { |
3524 | 0 | libcerror_error_set( |
3525 | 0 | error, |
3526 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3527 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_LESS_THAN_ZERO, |
3528 | 0 | "%s: invalid offset value less than zero.", |
3529 | 0 | function ); |
3530 | |
|
3531 | 0 | return( -1 ); |
3532 | 0 | } |
3533 | 621k | if( element_index == NULL ) |
3534 | 0 | { |
3535 | 0 | libcerror_error_set( |
3536 | 0 | error, |
3537 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3538 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3539 | 0 | "%s: invalid element index.", |
3540 | 0 | function ); |
3541 | |
|
3542 | 0 | return( -1 ); |
3543 | 0 | } |
3544 | 621k | if( element == NULL ) |
3545 | 0 | { |
3546 | 0 | libcerror_error_set( |
3547 | 0 | error, |
3548 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3549 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3550 | 0 | "%s: invalid element.", |
3551 | 0 | function ); |
3552 | |
|
3553 | 0 | return( -1 ); |
3554 | 0 | } |
3555 | 621k | result = libfdata_list_get_element_index_at_offset( |
3556 | 621k | list, |
3557 | 621k | offset, |
3558 | 621k | element_index, |
3559 | 621k | element_data_offset, |
3560 | 621k | error ); |
3561 | | |
3562 | 621k | if( result == -1 ) |
3563 | 0 | { |
3564 | 0 | libcerror_error_set( |
3565 | 0 | error, |
3566 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3567 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3568 | 0 | "%s: unable to retrieve element index at offset: %" PRIi64 " (0x%08" PRIx64 ").", |
3569 | 0 | function, |
3570 | 0 | offset, |
3571 | 0 | offset ); |
3572 | |
|
3573 | 0 | return( -1 ); |
3574 | 0 | } |
3575 | 621k | else if( result != 0 ) |
3576 | 620k | { |
3577 | 620k | if( libcdata_array_get_entry_by_index( |
3578 | 620k | internal_list->elements_array, |
3579 | 620k | *element_index, |
3580 | 620k | (intptr_t **) element, |
3581 | 620k | error ) != 1 ) |
3582 | 0 | { |
3583 | 0 | libcerror_error_set( |
3584 | 0 | error, |
3585 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3586 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3587 | 0 | "%s: unable to retrieve entry: %d from elements array.", |
3588 | 0 | function, |
3589 | 0 | *element_index ); |
3590 | |
|
3591 | 0 | return( -1 ); |
3592 | 0 | } |
3593 | 620k | } |
3594 | 621k | return( result ); |
3595 | 621k | } |
3596 | | |
3597 | | /* Retrieves the data range of an element at a specific offset |
3598 | | * Returns 1 if successful, 0 if not or -1 on error |
3599 | | */ |
3600 | | int libfdata_list_get_element_at_offset( |
3601 | | libfdata_list_t *list, |
3602 | | off64_t offset, |
3603 | | int *element_index, |
3604 | | off64_t *element_data_offset, |
3605 | | int *element_file_index, |
3606 | | off64_t *element_offset, |
3607 | | size64_t *element_size, |
3608 | | uint32_t *element_flags, |
3609 | | libcerror_error_t **error ) |
3610 | 0 | { |
3611 | 0 | libfdata_internal_list_t *internal_list = NULL; |
3612 | 0 | libfdata_list_element_t *list_element = NULL; |
3613 | 0 | static char *function = "libfdata_list_get_element_at_offset"; |
3614 | 0 | int result = 0; |
3615 | |
|
3616 | 0 | if( list == NULL ) |
3617 | 0 | { |
3618 | 0 | libcerror_error_set( |
3619 | 0 | error, |
3620 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3621 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3622 | 0 | "%s: invalid list.", |
3623 | 0 | function ); |
3624 | |
|
3625 | 0 | return( -1 ); |
3626 | 0 | } |
3627 | 0 | internal_list = (libfdata_internal_list_t *) list; |
3628 | |
|
3629 | 0 | if( element_index == NULL ) |
3630 | 0 | { |
3631 | 0 | libcerror_error_set( |
3632 | 0 | error, |
3633 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3634 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3635 | 0 | "%s: invalid element index.", |
3636 | 0 | function ); |
3637 | |
|
3638 | 0 | return( -1 ); |
3639 | 0 | } |
3640 | 0 | result = libfdata_list_get_element_index_at_offset( |
3641 | 0 | list, |
3642 | 0 | offset, |
3643 | 0 | element_index, |
3644 | 0 | element_data_offset, |
3645 | 0 | error ); |
3646 | |
|
3647 | 0 | if( result == -1 ) |
3648 | 0 | { |
3649 | 0 | libcerror_error_set( |
3650 | 0 | error, |
3651 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3652 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3653 | 0 | "%s: unable to retrieve element index at offset: %" PRIi64 " (0x%08" PRIx64 ").", |
3654 | 0 | function, |
3655 | 0 | offset, |
3656 | 0 | offset ); |
3657 | |
|
3658 | 0 | return( -1 ); |
3659 | 0 | } |
3660 | 0 | else if( result != 0 ) |
3661 | 0 | { |
3662 | 0 | if( libcdata_array_get_entry_by_index( |
3663 | 0 | internal_list->elements_array, |
3664 | 0 | *element_index, |
3665 | 0 | (intptr_t **) &list_element, |
3666 | 0 | error ) != 1 ) |
3667 | 0 | { |
3668 | 0 | libcerror_error_set( |
3669 | 0 | error, |
3670 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3671 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3672 | 0 | "%s: unable to retrieve entry: %d from elements array.", |
3673 | 0 | function, |
3674 | 0 | *element_index ); |
3675 | |
|
3676 | 0 | return( -1 ); |
3677 | 0 | } |
3678 | 0 | if( libfdata_list_element_get_data_range( |
3679 | 0 | list_element, |
3680 | 0 | element_file_index, |
3681 | 0 | element_offset, |
3682 | 0 | element_size, |
3683 | 0 | element_flags, |
3684 | 0 | error ) != 1 ) |
3685 | 0 | { |
3686 | 0 | libcerror_error_set( |
3687 | 0 | error, |
3688 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3689 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3690 | 0 | "%s: unable to retrieve data range of list element: %d.", |
3691 | 0 | function, |
3692 | 0 | *element_index ); |
3693 | |
|
3694 | 0 | return( -1 ); |
3695 | 0 | } |
3696 | 0 | } |
3697 | 0 | return( result ); |
3698 | 0 | } |
3699 | | |
3700 | | /* List element value functions |
3701 | | */ |
3702 | | |
3703 | | /* Caches the element value |
3704 | | * Returns 1 if successful or -1 on error |
3705 | | */ |
3706 | | int libfdata_list_cache_element_value( |
3707 | | libfdata_list_t *list, |
3708 | | libfdata_cache_t *cache, |
3709 | | int element_index LIBFDATA_ATTRIBUTE_UNUSED, |
3710 | | int element_file_index, |
3711 | | off64_t element_data_offset, |
3712 | | size64_t element_data_size LIBFDATA_ATTRIBUTE_UNUSED, |
3713 | | uint32_t element_data_flags LIBFDATA_ATTRIBUTE_UNUSED, |
3714 | | int64_t element_timestamp, |
3715 | | intptr_t *element_value, |
3716 | | int (*free_element_value)( |
3717 | | intptr_t **element_value, |
3718 | | libcerror_error_t **error ), |
3719 | | uint8_t write_flags, |
3720 | | libcerror_error_t **error ) |
3721 | 0 | { |
3722 | 0 | static char *function = "libfdata_list_cache_element_value"; |
3723 | |
|
3724 | 0 | LIBFDATA_UNREFERENCED_PARAMETER( element_index ) |
3725 | 0 | LIBFDATA_UNREFERENCED_PARAMETER( element_data_size ) |
3726 | 0 | LIBFDATA_UNREFERENCED_PARAMETER( element_data_flags ) |
3727 | |
|
3728 | 0 | if( list == NULL ) |
3729 | 0 | { |
3730 | 0 | libcerror_error_set( |
3731 | 0 | error, |
3732 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3733 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3734 | 0 | "%s: invalid list.", |
3735 | 0 | function ); |
3736 | |
|
3737 | 0 | return( -1 ); |
3738 | 0 | } |
3739 | 0 | if( libfcache_cache_set_value_by_identifier( |
3740 | 0 | (libfcache_cache_t *) cache, |
3741 | 0 | element_file_index, |
3742 | 0 | element_data_offset, |
3743 | 0 | element_timestamp, |
3744 | 0 | element_value, |
3745 | 0 | free_element_value, |
3746 | 0 | write_flags, |
3747 | 0 | error ) != 1 ) |
3748 | 0 | { |
3749 | 0 | libcerror_error_set( |
3750 | 0 | error, |
3751 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3752 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
3753 | 0 | "%s: unable to set value in cache.", |
3754 | 0 | function ); |
3755 | |
|
3756 | 0 | return( -1 ); |
3757 | 0 | } |
3758 | 0 | return( 1 ); |
3759 | 0 | } |
3760 | | |
3761 | | /* Retrieves the element value |
3762 | | * Returns 1 if successful or -1 on error |
3763 | | */ |
3764 | | int libfdata_list_get_element_value( |
3765 | | libfdata_list_t *list, |
3766 | | intptr_t *file_io_handle, |
3767 | | libfdata_cache_t *cache, |
3768 | | libfdata_list_element_t *element, |
3769 | | intptr_t **element_value, |
3770 | | uint8_t read_flags, |
3771 | | libcerror_error_t **error ) |
3772 | 753k | { |
3773 | 753k | libfcache_cache_value_t *cache_value = NULL; |
3774 | 753k | libfdata_internal_list_t *internal_list = NULL; |
3775 | 753k | static char *function = "libfdata_list_get_element_value"; |
3776 | 753k | size64_t element_data_size = 0; |
3777 | 753k | off64_t cache_value_offset = (off64_t) -1; |
3778 | 753k | off64_t element_data_offset = 0; |
3779 | 753k | int64_t cache_value_timestamp = 0; |
3780 | 753k | int64_t element_timestamp = 0; |
3781 | 753k | uint32_t element_data_flags = 0; |
3782 | 753k | int cache_value_file_index = -1; |
3783 | 753k | int element_file_index = -1; |
3784 | 753k | int result = 0; |
3785 | | |
3786 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3787 | | const char *hit_or_miss = NULL; |
3788 | | #endif |
3789 | | |
3790 | 753k | if( list == NULL ) |
3791 | 0 | { |
3792 | 0 | libcerror_error_set( |
3793 | 0 | error, |
3794 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3795 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3796 | 0 | "%s: invalid list.", |
3797 | 0 | function ); |
3798 | |
|
3799 | 0 | return( -1 ); |
3800 | 0 | } |
3801 | 753k | internal_list = (libfdata_internal_list_t *) list; |
3802 | | |
3803 | 753k | if( internal_list->read_element_data == NULL ) |
3804 | 0 | { |
3805 | 0 | libcerror_error_set( |
3806 | 0 | error, |
3807 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3808 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3809 | 0 | "%s: invalid list - missing read element data function.", |
3810 | 0 | function ); |
3811 | |
|
3812 | 0 | return( -1 ); |
3813 | 0 | } |
3814 | 753k | if( libfdata_list_element_get_data_range( |
3815 | 753k | element, |
3816 | 753k | &element_file_index, |
3817 | 753k | &element_data_offset, |
3818 | 753k | &element_data_size, |
3819 | 753k | &element_data_flags, |
3820 | 753k | error ) != 1 ) |
3821 | 69 | { |
3822 | 69 | libcerror_error_set( |
3823 | 69 | error, |
3824 | 69 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3825 | 69 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3826 | 69 | "%s: unable to retrieve data range from list element.", |
3827 | 69 | function ); |
3828 | | |
3829 | 69 | return( -1 ); |
3830 | 69 | } |
3831 | 753k | if( libfdata_list_element_get_timestamp( |
3832 | 753k | element, |
3833 | 753k | &element_timestamp, |
3834 | 753k | error ) != 1 ) |
3835 | 0 | { |
3836 | 0 | libcerror_error_set( |
3837 | 0 | error, |
3838 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3839 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3840 | 0 | "%s: unable to retrieve time stamp from list element.", |
3841 | 0 | function ); |
3842 | |
|
3843 | 0 | return( -1 ); |
3844 | 0 | } |
3845 | 753k | if( ( read_flags & LIBFDATA_READ_FLAG_IGNORE_CACHE ) == 0 ) |
3846 | 753k | { |
3847 | 753k | result = libfcache_cache_get_value_by_identifier( |
3848 | 753k | (libfcache_cache_t *) cache, |
3849 | 753k | element_file_index, |
3850 | 753k | element_data_offset, |
3851 | 753k | element_timestamp, |
3852 | 753k | &cache_value, |
3853 | 753k | error ); |
3854 | | |
3855 | 753k | if( result == -1 ) |
3856 | 0 | { |
3857 | 0 | libcerror_error_set( |
3858 | 0 | error, |
3859 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3860 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3861 | 0 | "%s: unable to retrieve value from cache.", |
3862 | 0 | function ); |
3863 | |
|
3864 | 0 | return( -1 ); |
3865 | 0 | } |
3866 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3867 | | if( libcnotify_verbose != 0 ) |
3868 | | { |
3869 | | if( result == 0 ) |
3870 | | { |
3871 | | hit_or_miss = "miss"; |
3872 | | } |
3873 | | else |
3874 | | { |
3875 | | hit_or_miss = "hit"; |
3876 | | } |
3877 | | libcnotify_printf( |
3878 | | "%s: cache: 0x%08" PRIjx " %s\n", |
3879 | | function, |
3880 | | (intptr_t) cache, |
3881 | | hit_or_miss ); |
3882 | | } |
3883 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
3884 | 753k | } |
3885 | 753k | if( result == 0 ) |
3886 | 21.7k | { |
3887 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3888 | | if( libcnotify_verbose != 0 ) |
3889 | | { |
3890 | | libcnotify_printf( |
3891 | | "%s: reading element data at offset: %" PRIi64 " (0x%08" PRIx64 ") of size: %" PRIu64 "\n", |
3892 | | function, |
3893 | | element_data_offset, |
3894 | | element_data_offset, |
3895 | | element_data_size ); |
3896 | | } |
3897 | | #endif |
3898 | 21.7k | if( internal_list->read_element_data( |
3899 | 21.7k | internal_list->data_handle, |
3900 | 21.7k | file_io_handle, |
3901 | 21.7k | element, |
3902 | 21.7k | cache, |
3903 | 21.7k | element_file_index, |
3904 | 21.7k | element_data_offset, |
3905 | 21.7k | element_data_size, |
3906 | 21.7k | element_data_flags, |
3907 | 21.7k | read_flags, |
3908 | 21.7k | error ) != 1 ) |
3909 | 3.85k | { |
3910 | 3.85k | libcerror_error_set( |
3911 | 3.85k | error, |
3912 | 3.85k | LIBCERROR_ERROR_DOMAIN_IO, |
3913 | 3.85k | LIBCERROR_IO_ERROR_READ_FAILED, |
3914 | 3.85k | "%s: unable to read element data at offset: %" PRIi64 " (0x%08" PRIx64 ").", |
3915 | 3.85k | function, |
3916 | 3.85k | element_data_offset, |
3917 | 3.85k | element_data_offset ); |
3918 | | |
3919 | 3.85k | return( -1 ); |
3920 | 3.85k | } |
3921 | 17.9k | if( libfcache_cache_get_value_by_identifier( |
3922 | 17.9k | (libfcache_cache_t *) cache, |
3923 | 17.9k | element_file_index, |
3924 | 17.9k | element_data_offset, |
3925 | 17.9k | element_timestamp, |
3926 | 17.9k | &cache_value, |
3927 | 17.9k | error ) != 1 ) |
3928 | 0 | { |
3929 | 0 | libcerror_error_set( |
3930 | 0 | error, |
3931 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3932 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3933 | 0 | "%s: unable to retrieve value from cache.", |
3934 | 0 | function ); |
3935 | |
|
3936 | 0 | return( -1 ); |
3937 | 0 | } |
3938 | 17.9k | if( libfcache_cache_value_get_identifier( |
3939 | 17.9k | cache_value, |
3940 | 17.9k | &cache_value_file_index, |
3941 | 17.9k | &cache_value_offset, |
3942 | 17.9k | &cache_value_timestamp, |
3943 | 17.9k | error ) != 1 ) |
3944 | 0 | { |
3945 | 0 | libcerror_error_set( |
3946 | 0 | error, |
3947 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3948 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3949 | 0 | "%s: unable to retrieve cache value identifier.", |
3950 | 0 | function ); |
3951 | |
|
3952 | 0 | return( -1 ); |
3953 | 0 | } |
3954 | 17.9k | if( ( element_file_index != cache_value_file_index ) |
3955 | 17.9k | || ( element_data_offset != cache_value_offset ) |
3956 | 17.9k | || ( element_timestamp != cache_value_timestamp ) ) |
3957 | 0 | { |
3958 | 0 | libcerror_error_set( |
3959 | 0 | error, |
3960 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3961 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3962 | 0 | "%s: missing cache value.", |
3963 | 0 | function ); |
3964 | |
|
3965 | 0 | return( -1 ); |
3966 | 0 | } |
3967 | 17.9k | } |
3968 | 749k | if( libfcache_cache_value_get_value( |
3969 | 749k | cache_value, |
3970 | 749k | element_value, |
3971 | 749k | error ) != 1 ) |
3972 | 0 | { |
3973 | 0 | libcerror_error_set( |
3974 | 0 | error, |
3975 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3976 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3977 | 0 | "%s: unable to retrieve element value.", |
3978 | 0 | function ); |
3979 | |
|
3980 | 0 | return( -1 ); |
3981 | 0 | } |
3982 | 749k | return( 1 ); |
3983 | 749k | } |
3984 | | |
3985 | | /* Retrieves the value of a specific element |
3986 | | * Returns 1 if successful or -1 on error |
3987 | | */ |
3988 | | int libfdata_list_get_element_value_by_index( |
3989 | | libfdata_list_t *list, |
3990 | | intptr_t *file_io_handle, |
3991 | | libfdata_cache_t *cache, |
3992 | | int element_index, |
3993 | | intptr_t **element_value, |
3994 | | uint8_t read_flags, |
3995 | | libcerror_error_t **error ) |
3996 | 132k | { |
3997 | 132k | libfdata_internal_list_t *internal_list = NULL; |
3998 | 132k | libfdata_list_element_t *list_element = NULL; |
3999 | 132k | static char *function = "libfdata_list_get_element_value_by_index"; |
4000 | | |
4001 | 132k | if( list == NULL ) |
4002 | 0 | { |
4003 | 0 | libcerror_error_set( |
4004 | 0 | error, |
4005 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4006 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4007 | 0 | "%s: invalid list.", |
4008 | 0 | function ); |
4009 | |
|
4010 | 0 | return( -1 ); |
4011 | 0 | } |
4012 | 132k | internal_list = (libfdata_internal_list_t *) list; |
4013 | | |
4014 | 132k | if( libcdata_array_get_entry_by_index( |
4015 | 132k | internal_list->elements_array, |
4016 | 132k | element_index, |
4017 | 132k | (intptr_t **) &list_element, |
4018 | 132k | error ) != 1 ) |
4019 | 98 | { |
4020 | 98 | libcerror_error_set( |
4021 | 98 | error, |
4022 | 98 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4023 | 98 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4024 | 98 | "%s: unable to retrieve entry: %d from elements array.", |
4025 | 98 | function, |
4026 | 98 | element_index ); |
4027 | | |
4028 | 98 | return( -1 ); |
4029 | 98 | } |
4030 | 132k | if( libfdata_list_get_element_value( |
4031 | 132k | list, |
4032 | 132k | file_io_handle, |
4033 | 132k | cache, |
4034 | 132k | list_element, |
4035 | 132k | element_value, |
4036 | 132k | read_flags, |
4037 | 132k | error ) != 1 ) |
4038 | 2.50k | { |
4039 | 2.50k | libcerror_error_set( |
4040 | 2.50k | error, |
4041 | 2.50k | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4042 | 2.50k | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4043 | 2.50k | "%s: unable to retrieve element value.", |
4044 | 2.50k | function ); |
4045 | | |
4046 | 2.50k | return( -1 ); |
4047 | 2.50k | } |
4048 | 130k | internal_list->current_element_index = element_index; |
4049 | | |
4050 | 130k | return( 1 ); |
4051 | 132k | } |
4052 | | |
4053 | | /* Retrieves the value an element at a specific offset |
4054 | | * Returns 1 if successful, 0 if not or -1 on error |
4055 | | */ |
4056 | | int libfdata_list_get_element_value_at_offset( |
4057 | | libfdata_list_t *list, |
4058 | | intptr_t *file_io_handle, |
4059 | | libfdata_cache_t *cache, |
4060 | | off64_t offset, |
4061 | | int *element_index, |
4062 | | off64_t *element_data_offset, |
4063 | | intptr_t **element_value, |
4064 | | uint8_t read_flags, |
4065 | | libcerror_error_t **error ) |
4066 | 621k | { |
4067 | 621k | libfdata_list_element_t *list_element = NULL; |
4068 | 621k | static char *function = "libfdata_list_get_element_value_at_offset"; |
4069 | 621k | int result = 0; |
4070 | | |
4071 | 621k | if( element_index == NULL ) |
4072 | 0 | { |
4073 | 0 | libcerror_error_set( |
4074 | 0 | error, |
4075 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4076 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4077 | 0 | "%s: invalid element index.", |
4078 | 0 | function ); |
4079 | |
|
4080 | 0 | return( -1 ); |
4081 | 0 | } |
4082 | 621k | result = libfdata_list_get_list_element_at_offset( |
4083 | 621k | list, |
4084 | 621k | offset, |
4085 | 621k | element_index, |
4086 | 621k | element_data_offset, |
4087 | 621k | &list_element, |
4088 | 621k | error ); |
4089 | | |
4090 | 621k | if( result == -1 ) |
4091 | 0 | { |
4092 | 0 | libcerror_error_set( |
4093 | 0 | error, |
4094 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4095 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4096 | 0 | "%s: unable to retrieve element at offset: %" PRIi64 " (0x%08" PRIx64 ").", |
4097 | 0 | function, |
4098 | 0 | offset, |
4099 | 0 | offset ); |
4100 | |
|
4101 | 0 | return( -1 ); |
4102 | 0 | } |
4103 | 621k | else if( result != 0 ) |
4104 | 620k | { |
4105 | 620k | if( libfdata_list_get_element_value( |
4106 | 620k | list, |
4107 | 620k | file_io_handle, |
4108 | 620k | cache, |
4109 | 620k | list_element, |
4110 | 620k | element_value, |
4111 | 620k | read_flags, |
4112 | 620k | error ) != 1 ) |
4113 | 1.24k | { |
4114 | 1.24k | libcerror_error_set( |
4115 | 1.24k | error, |
4116 | 1.24k | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4117 | 1.24k | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4118 | 1.24k | "%s: unable to retrieve element: %d value.", |
4119 | 1.24k | function, |
4120 | 1.24k | *element_index ); |
4121 | | |
4122 | 1.24k | return( -1 ); |
4123 | 1.24k | } |
4124 | 620k | } |
4125 | 619k | return( result ); |
4126 | 621k | } |
4127 | | |
4128 | | /* Sets the value of a specific element |
4129 | | * |
4130 | | * If the flag LIBFDATA_LIST_ELEMENT_VALUE_FLAG_MANAGED is set the list |
4131 | | * takes over management of the value and the value is freed when |
4132 | | * no longer needed. |
4133 | | * |
4134 | | * Returns 1 if successful or -1 on error |
4135 | | */ |
4136 | | int libfdata_list_set_element_value( |
4137 | | libfdata_list_t *list, |
4138 | | intptr_t *file_io_handle LIBFDATA_ATTRIBUTE_UNUSED, |
4139 | | libfdata_cache_t *cache, |
4140 | | libfdata_list_element_t *element, |
4141 | | intptr_t *element_value, |
4142 | | int (*free_element_value)( |
4143 | | intptr_t **element_value, |
4144 | | libcerror_error_t **error ), |
4145 | | uint8_t write_flags, |
4146 | | libcerror_error_t **error ) |
4147 | 23.9k | { |
4148 | 23.9k | static char *function = "libfdata_list_set_element_value"; |
4149 | 23.9k | size64_t element_data_size = 0; |
4150 | 23.9k | off64_t element_data_offset = 0; |
4151 | 23.9k | int64_t element_timestamp = 0; |
4152 | 23.9k | uint32_t element_data_flags = 0; |
4153 | 23.9k | int element_file_index = -1; |
4154 | | |
4155 | 23.9k | LIBFDATA_UNREFERENCED_PARAMETER( file_io_handle ) |
4156 | | |
4157 | 23.9k | if( list == NULL ) |
4158 | 0 | { |
4159 | 0 | libcerror_error_set( |
4160 | 0 | error, |
4161 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4162 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4163 | 0 | "%s: invalid list.", |
4164 | 0 | function ); |
4165 | |
|
4166 | 0 | return( -1 ); |
4167 | 0 | } |
4168 | 23.9k | if( libfdata_list_element_get_data_range( |
4169 | 23.9k | element, |
4170 | 23.9k | &element_file_index, |
4171 | 23.9k | &element_data_offset, |
4172 | 23.9k | &element_data_size, |
4173 | 23.9k | &element_data_flags, |
4174 | 23.9k | error ) != 1 ) |
4175 | 0 | { |
4176 | 0 | libcerror_error_set( |
4177 | 0 | error, |
4178 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4179 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4180 | 0 | "%s: unable to retrieve data range from list element.", |
4181 | 0 | function ); |
4182 | |
|
4183 | 0 | return( -1 ); |
4184 | 0 | } |
4185 | 23.9k | if( libfdata_list_element_get_timestamp( |
4186 | 23.9k | element, |
4187 | 23.9k | &element_timestamp, |
4188 | 23.9k | error ) != 1 ) |
4189 | 0 | { |
4190 | 0 | libcerror_error_set( |
4191 | 0 | error, |
4192 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4193 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4194 | 0 | "%s: unable to retrieve time stamp from list element.", |
4195 | 0 | function ); |
4196 | |
|
4197 | 0 | return( -1 ); |
4198 | 0 | } |
4199 | 23.9k | if( libfcache_cache_set_value_by_identifier( |
4200 | 23.9k | (libfcache_cache_t *) cache, |
4201 | 23.9k | element_file_index, |
4202 | 23.9k | element_data_offset, |
4203 | 23.9k | element_timestamp, |
4204 | 23.9k | element_value, |
4205 | 23.9k | free_element_value, |
4206 | 23.9k | write_flags, |
4207 | 23.9k | error ) != 1 ) |
4208 | 0 | { |
4209 | 0 | libcerror_error_set( |
4210 | 0 | error, |
4211 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4212 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
4213 | 0 | "%s: unable to set value in cache.", |
4214 | 0 | function ); |
4215 | |
|
4216 | 0 | return( -1 ); |
4217 | 0 | } |
4218 | 23.9k | return( 1 ); |
4219 | 23.9k | } |
4220 | | |
4221 | | /* Sets the value of a specific element |
4222 | | * |
4223 | | * If the flag LIBFDATA_LIST_ELEMENT_VALUE_FLAG_MANAGED is set the list |
4224 | | * takes over management of the value and the value is freed when |
4225 | | * no longer needed. |
4226 | | * |
4227 | | * Returns 1 if successful or -1 on error |
4228 | | */ |
4229 | | int libfdata_list_set_element_value_by_index( |
4230 | | libfdata_list_t *list, |
4231 | | intptr_t *file_io_handle, |
4232 | | libfdata_cache_t *cache, |
4233 | | int element_index, |
4234 | | intptr_t *element_value, |
4235 | | int (*free_element_value)( |
4236 | | intptr_t **element_value, |
4237 | | libcerror_error_t **error ), |
4238 | | uint8_t write_flags, |
4239 | | libcerror_error_t **error ) |
4240 | 5.93k | { |
4241 | 5.93k | libfdata_internal_list_t *internal_list = NULL; |
4242 | 5.93k | libfdata_list_element_t *list_element = NULL; |
4243 | 5.93k | static char *function = "libfdata_list_set_element_value_by_index"; |
4244 | | |
4245 | 5.93k | if( list == NULL ) |
4246 | 0 | { |
4247 | 0 | libcerror_error_set( |
4248 | 0 | error, |
4249 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4250 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4251 | 0 | "%s: invalid list.", |
4252 | 0 | function ); |
4253 | |
|
4254 | 0 | return( -1 ); |
4255 | 0 | } |
4256 | 5.93k | internal_list = (libfdata_internal_list_t *) list; |
4257 | | |
4258 | 5.93k | if( libcdata_array_get_entry_by_index( |
4259 | 5.93k | internal_list->elements_array, |
4260 | 5.93k | element_index, |
4261 | 5.93k | (intptr_t **) &list_element, |
4262 | 5.93k | error ) != 1 ) |
4263 | 0 | { |
4264 | 0 | libcerror_error_set( |
4265 | 0 | error, |
4266 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4267 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4268 | 0 | "%s: unable to retrieve entry: %d from elements array.", |
4269 | 0 | function, |
4270 | 0 | element_index ); |
4271 | |
|
4272 | 0 | return( -1 ); |
4273 | 0 | } |
4274 | 5.93k | if( libfdata_list_set_element_value( |
4275 | 5.93k | list, |
4276 | 5.93k | file_io_handle, |
4277 | 5.93k | cache, |
4278 | 5.93k | list_element, |
4279 | 5.93k | element_value, |
4280 | 5.93k | free_element_value, |
4281 | 5.93k | write_flags, |
4282 | 5.93k | error ) != 1 ) |
4283 | 0 | { |
4284 | 0 | libcerror_error_set( |
4285 | 0 | error, |
4286 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4287 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
4288 | 0 | "%s: unable to set element value.", |
4289 | 0 | function ); |
4290 | |
|
4291 | 0 | return( -1 ); |
4292 | 0 | } |
4293 | 5.93k | internal_list->current_element_index = element_index; |
4294 | | |
4295 | 5.93k | return( 1 ); |
4296 | 5.93k | } |
4297 | | |
4298 | | /* Sets the value of an element at a specific offset |
4299 | | * |
4300 | | * If the flag LIBFDATA_LIST_ELEMENT_VALUE_FLAG_MANAGED is set the list |
4301 | | * takes over management of the value and the value is freed when |
4302 | | * no longer needed. |
4303 | | * |
4304 | | * Returns 1 if successful, 0 if not or -1 on error |
4305 | | */ |
4306 | | int libfdata_list_set_element_value_at_offset( |
4307 | | libfdata_list_t *list, |
4308 | | intptr_t *file_io_handle, |
4309 | | libfdata_cache_t *cache, |
4310 | | off64_t offset, |
4311 | | intptr_t *element_value, |
4312 | | int (*free_element_value)( |
4313 | | intptr_t **element_value, |
4314 | | libcerror_error_t **error ), |
4315 | | uint8_t write_flags, |
4316 | | libcerror_error_t **error ) |
4317 | 0 | { |
4318 | 0 | libfdata_list_element_t *list_element = NULL; |
4319 | 0 | static char *function = "libfdata_list_set_element_value_at_offset"; |
4320 | 0 | off64_t element_data_offset = 0; |
4321 | 0 | int element_index = 0; |
4322 | 0 | int result = 0; |
4323 | |
|
4324 | 0 | result = libfdata_list_get_list_element_at_offset( |
4325 | 0 | list, |
4326 | 0 | offset, |
4327 | 0 | &element_index, |
4328 | 0 | &element_data_offset, |
4329 | 0 | &list_element, |
4330 | 0 | error ); |
4331 | |
|
4332 | 0 | if( result == -1 ) |
4333 | 0 | { |
4334 | 0 | libcerror_error_set( |
4335 | 0 | error, |
4336 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4337 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4338 | 0 | "%s: unable to retrieve element at offset: %" PRIi64 " (0x%08" PRIx64 ").", |
4339 | 0 | function, |
4340 | 0 | offset, |
4341 | 0 | offset ); |
4342 | |
|
4343 | 0 | return( -1 ); |
4344 | 0 | } |
4345 | 0 | else if( result != 0 ) |
4346 | 0 | { |
4347 | 0 | if( libfdata_list_set_element_value( |
4348 | 0 | list, |
4349 | 0 | file_io_handle, |
4350 | 0 | cache, |
4351 | 0 | list_element, |
4352 | 0 | element_value, |
4353 | 0 | free_element_value, |
4354 | 0 | write_flags, |
4355 | 0 | error ) != 1 ) |
4356 | 0 | { |
4357 | 0 | libcerror_error_set( |
4358 | 0 | error, |
4359 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4360 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
4361 | 0 | "%s: unable to set value of element: %d.", |
4362 | 0 | function, |
4363 | 0 | element_index ); |
4364 | |
|
4365 | 0 | return( -1 ); |
4366 | 0 | } |
4367 | 0 | } |
4368 | 0 | return( result ); |
4369 | 0 | } |
4370 | | |
4371 | | /* Retrieves the size of the list |
4372 | | * Returns 1 if successful or -1 on error |
4373 | | */ |
4374 | | int libfdata_list_get_size( |
4375 | | libfdata_list_t *list, |
4376 | | size64_t *size, |
4377 | | libcerror_error_t **error ) |
4378 | 0 | { |
4379 | 0 | libfdata_internal_list_t *internal_list = NULL; |
4380 | 0 | static char *function = "libfdata_list_get_size"; |
4381 | |
|
4382 | 0 | if( list == NULL ) |
4383 | 0 | { |
4384 | 0 | libcerror_error_set( |
4385 | 0 | error, |
4386 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4387 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4388 | 0 | "%s: invalid list.", |
4389 | 0 | function ); |
4390 | |
|
4391 | 0 | return( -1 ); |
4392 | 0 | } |
4393 | 0 | internal_list = (libfdata_internal_list_t *) list; |
4394 | |
|
4395 | 0 | if( size == NULL ) |
4396 | 0 | { |
4397 | 0 | libcerror_error_set( |
4398 | 0 | error, |
4399 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4400 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4401 | 0 | "%s: invalid size.", |
4402 | 0 | function ); |
4403 | |
|
4404 | 0 | return( -1 ); |
4405 | 0 | } |
4406 | 0 | if( ( internal_list->flags & LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES ) != 0 ) |
4407 | 0 | { |
4408 | 0 | if( libfdata_list_calculate_mapped_ranges( |
4409 | 0 | internal_list, |
4410 | 0 | error ) != 1 ) |
4411 | 0 | { |
4412 | 0 | libcerror_error_set( |
4413 | 0 | error, |
4414 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4415 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4416 | 0 | "%s: unable to calculate mapped ranges.", |
4417 | 0 | function ); |
4418 | |
|
4419 | 0 | return( -1 ); |
4420 | 0 | } |
4421 | 0 | } |
4422 | 0 | *size = internal_list->size; |
4423 | |
|
4424 | 0 | return( 1 ); |
4425 | 0 | } |
4426 | | |