/src/libcreg/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  | 51.0k  | { | 
82  | 51.0k  |   libfdata_internal_list_t *internal_list = NULL;  | 
83  | 51.0k  |   static char *function                   = "libfdata_list_initialize";  | 
84  |  |  | 
85  | 51.0k  |   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  | 51.0k  |   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  | 51.0k  |   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  | 51.0k  |   internal_list = memory_allocate_structure(  | 
119  | 51.0k  |                    libfdata_internal_list_t );  | 
120  |  |  | 
121  | 51.0k  |   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  | 51.0k  |   if( memory_set(  | 
133  | 51.0k  |        internal_list,  | 
134  | 51.0k  |        0,  | 
135  | 51.0k  |        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  | 51.0k  |   if( libcdata_array_initialize(  | 
150  | 51.0k  |        &( internal_list->elements_array ),  | 
151  | 51.0k  |        0,  | 
152  | 51.0k  |        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  | 51.0k  |   if( libcdata_array_initialize(  | 
164  | 51.0k  |        &( internal_list->mapped_ranges_array ),  | 
165  | 51.0k  |        0,  | 
166  | 51.0k  |        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  | 51.0k  |   internal_list->flags             |= flags;  | 
178  | 51.0k  |   internal_list->data_handle        = data_handle;  | 
179  | 51.0k  |   internal_list->free_data_handle   = free_data_handle;  | 
180  | 51.0k  |   internal_list->clone_data_handle  = clone_data_handle;  | 
181  | 51.0k  |   internal_list->read_element_data  = read_element_data;  | 
182  | 51.0k  |   internal_list->write_element_data = write_element_data;  | 
183  |  |  | 
184  | 51.0k  |   *list = (libfdata_list_t *) internal_list;  | 
185  |  |  | 
186  | 51.0k  |   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  | 51.0k  | }  | 
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  | 51.0k  | { | 
211  | 51.0k  |   libfdata_internal_list_t *internal_list = NULL;  | 
212  | 51.0k  |   static char *function                   = "libfdata_list_free";  | 
213  | 51.0k  |   int result                              = 1;  | 
214  |  |  | 
215  | 51.0k  |   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  | 51.0k  |   if( *list != NULL )  | 
227  | 51.0k  |   { | 
228  | 51.0k  |     internal_list = (libfdata_internal_list_t *) *list;  | 
229  | 51.0k  |     *list         = NULL;  | 
230  |  |  | 
231  | 51.0k  |     if( libcdata_array_free(  | 
232  | 51.0k  |          &( internal_list->elements_array ),  | 
233  | 51.0k  |          (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_list_element_free,  | 
234  | 51.0k  |          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  | 51.0k  |     if( libcdata_array_free(  | 
246  | 51.0k  |          &( internal_list->mapped_ranges_array ),  | 
247  | 51.0k  |          (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_mapped_range_free,  | 
248  | 51.0k  |          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  | 51.0k  |     if( ( internal_list->flags & LIBFDATA_DATA_HANDLE_FLAG_MANAGED ) != 0 )  | 
260  | 14.0k  |     { | 
261  | 14.0k  |       if( internal_list->data_handle != NULL )  | 
262  | 14.0k  |       { | 
263  | 14.0k  |         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  | 14.0k  |         else if( internal_list->free_data_handle(  | 
275  | 14.0k  |                   &( internal_list->data_handle ),  | 
276  | 14.0k  |                   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  | 14.0k  |       }  | 
288  | 14.0k  |     }  | 
289  | 51.0k  |     memory_free(  | 
290  | 51.0k  |      internal_list );  | 
291  | 51.0k  |   }  | 
292  | 51.0k  |   return( result );  | 
293  | 51.0k  | }  | 
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.55M  | { | 
480  | 1.55M  |   libfdata_internal_list_t *internal_list = NULL;  | 
481  | 1.55M  |   static char *function                   = "libfdata_list_set_calculate_mapped_ranges_flag";  | 
482  |  |  | 
483  | 1.55M  |   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.55M  |   internal_list = (libfdata_internal_list_t *) list;  | 
495  |  |  | 
496  | 1.55M  |   internal_list->flags |= LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES;  | 
497  |  |  | 
498  | 1.55M  |   return( 1 );  | 
499  | 1.55M  | }  | 
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.5k  | { | 
511  | 11.5k  |   libfdata_internal_list_t *internal_list = NULL;  | 
512  | 11.5k  |   static char *function                   = "libfdata_list_empty";  | 
513  |  |  | 
514  | 11.5k  |   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.5k  |   internal_list = (libfdata_internal_list_t *) list;  | 
526  |  |  | 
527  | 11.5k  |   if( libcdata_array_empty(  | 
528  | 11.5k  |        internal_list->elements_array,  | 
529  | 11.5k  |        (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_list_element_free,  | 
530  | 11.5k  |        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.5k  |   if( libcdata_array_empty(  | 
542  | 11.5k  |        internal_list->mapped_ranges_array,  | 
543  | 11.5k  |        (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_mapped_range_free,  | 
544  | 11.5k  |        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.5k  |   internal_list->size = 0;  | 
556  |  |  | 
557  | 11.5k  |   return( 1 );  | 
558  | 11.5k  | }  | 
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.23k  | { | 
568  | 7.23k  |   libfdata_internal_list_t *internal_list = NULL;  | 
569  | 7.23k  |   static char *function                   = "libfdata_list_resize";  | 
570  |  |  | 
571  | 7.23k  |   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.23k  |   internal_list = (libfdata_internal_list_t *) list;  | 
583  |  |  | 
584  | 7.23k  |   if( libcdata_array_resize(  | 
585  | 7.23k  |        internal_list->elements_array,  | 
586  | 7.23k  |        number_of_elements,  | 
587  | 7.23k  |        (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_list_element_free,  | 
588  | 7.23k  |        error ) != 1 )  | 
589  | 38  |   { | 
590  | 38  |     libcerror_error_set(  | 
591  | 38  |      error,  | 
592  | 38  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
593  | 38  |      LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED,  | 
594  | 38  |      "%s: unable to resize elements array.",  | 
595  | 38  |      function );  | 
596  |  |  | 
597  | 38  |     return( -1 );  | 
598  | 38  |   }  | 
599  | 7.19k  |   if( libcdata_array_resize(  | 
600  | 7.19k  |        internal_list->mapped_ranges_array,  | 
601  | 7.19k  |        number_of_elements,  | 
602  | 7.19k  |        (int (*)(intptr_t **, libcerror_error_t **)) &libfdata_mapped_range_free,  | 
603  | 7.19k  |        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.19k  |   internal_list->flags |= LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES;  | 
615  |  |  | 
616  | 7.19k  |   return( 1 );  | 
617  | 7.19k  | }  | 
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  | 170  | { | 
626  | 170  |   libfdata_internal_list_t *internal_list = NULL;  | 
627  | 170  |   libfdata_list_element_t *list_element   = NULL;  | 
628  | 170  |   static char *function                   = "libfdata_list_reverse";  | 
629  | 170  |   int element_index                       = 0;  | 
630  | 170  |   int number_of_elements                  = 0;  | 
631  |  |  | 
632  | 170  |   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  | 170  |   internal_list = (libfdata_internal_list_t *) list;  | 
644  |  |  | 
645  | 170  |   if( libcdata_array_reverse(  | 
646  | 170  |        internal_list->elements_array,  | 
647  | 170  |        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  | 170  |   if( libcdata_array_get_number_of_entries(  | 
659  | 170  |        internal_list->elements_array,  | 
660  | 170  |        &number_of_elements,  | 
661  | 170  |        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  | 170  |   for( element_index = 0;  | 
673  | 170  |        element_index < number_of_elements;  | 
674  | 170  |        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  | 170  |   internal_list->flags |= LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES;  | 
709  |  |  | 
710  | 170  |   return( 1 );  | 
711  | 170  | }  | 
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  | 17.4k  | { | 
721  | 17.4k  |   libfdata_internal_list_t *internal_list = NULL;  | 
722  | 17.4k  |   static char *function                   = "libfdata_list_get_number_of_elements";  | 
723  |  |  | 
724  | 17.4k  |   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  | 17.4k  |   internal_list = (libfdata_internal_list_t *) list;  | 
736  |  |  | 
737  | 17.4k  |   if( libcdata_array_get_number_of_entries(  | 
738  | 17.4k  |        internal_list->elements_array,  | 
739  | 17.4k  |        number_of_elements,  | 
740  | 17.4k  |        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  | 17.4k  |   return( 1 );  | 
752  | 17.4k  | }  | 
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  | 546  | { | 
763  | 546  |   libfdata_internal_list_t *internal_list = NULL;  | 
764  | 546  |   static char *function                   = "libfdata_list_get_list_element_by_index";  | 
765  |  |  | 
766  | 546  |   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  | 546  |   internal_list = (libfdata_internal_list_t *) list;  | 
778  |  |  | 
779  | 546  |   if( libcdata_array_get_entry_by_index(  | 
780  | 546  |        internal_list->elements_array,  | 
781  | 546  |        element_index,  | 
782  | 546  |        (intptr_t **) element,  | 
783  | 546  |        error ) != 1 )  | 
784  | 10  |   { | 
785  | 10  |     libcerror_error_set(  | 
786  | 10  |      error,  | 
787  | 10  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
788  | 10  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
789  | 10  |      "%s: unable to retrieve entry: %d from elements array.",  | 
790  | 10  |      function,  | 
791  | 10  |      element_index );  | 
792  |  |  | 
793  | 10  |     return( -1 );  | 
794  | 10  |   }  | 
795  | 536  |   internal_list->current_element_index = element_index;  | 
796  |  |  | 
797  | 536  |   return( 1 );  | 
798  | 546  | }  | 
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.40k  | { | 
812  | 3.40k  |   libfdata_internal_list_t *internal_list = NULL;  | 
813  | 3.40k  |   libfdata_list_element_t *list_element   = NULL;  | 
814  | 3.40k  |   static char *function                   = "libfdata_list_get_element_by_index";  | 
815  |  |  | 
816  | 3.40k  |   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.40k  |   internal_list = (libfdata_internal_list_t *) list;  | 
828  |  |  | 
829  | 3.40k  |   if( libcdata_array_get_entry_by_index(  | 
830  | 3.40k  |        internal_list->elements_array,  | 
831  | 3.40k  |        element_index,  | 
832  | 3.40k  |        (intptr_t **) &list_element,  | 
833  | 3.40k  |        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.40k  |   if( libfdata_list_element_get_data_range(  | 
846  | 3.40k  |        list_element,  | 
847  | 3.40k  |        element_file_index,  | 
848  | 3.40k  |        element_offset,  | 
849  | 3.40k  |        element_size,  | 
850  | 3.40k  |        element_flags,  | 
851  | 3.40k  |        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.40k  |   internal_list->current_element_index = element_index;  | 
864  |  |  | 
865  | 3.40k  |   return( 1 );  | 
866  | 3.40k  | }  | 
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  | 9.15k  | { | 
880  | 9.15k  |   libfdata_internal_list_t *internal_list = NULL;  | 
881  | 9.15k  |   libfdata_list_element_t *list_element   = NULL;  | 
882  | 9.15k  |   libfdata_mapped_range_t *mapped_range   = NULL;  | 
883  | 9.15k  |   static char *function                   = "libfdata_list_set_element_by_index";  | 
884  | 9.15k  |   off64_t previous_element_offset         = 0;  | 
885  | 9.15k  |   size64_t mapped_size                    = 0;  | 
886  | 9.15k  |   size64_t previous_element_size          = 0;  | 
887  | 9.15k  |   uint32_t previous_element_flags         = 0;  | 
888  | 9.15k  |   int previous_element_file_index         = 0;  | 
889  | 9.15k  |   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  | 9.15k  |   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  | 9.15k  |   internal_list = (libfdata_internal_list_t *) list;  | 
908  |  |  | 
909  | 9.15k  |   if( libcdata_array_get_entry_by_index(  | 
910  | 9.15k  |        internal_list->elements_array,  | 
911  | 9.15k  |        element_index,  | 
912  | 9.15k  |        (intptr_t **) &list_element,  | 
913  | 9.15k  |        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  | 9.15k  |   if( list_element == NULL )  | 
926  | 8.53k  |   { | 
927  | 8.53k  |     if( libfdata_list_element_initialize(  | 
928  | 8.53k  |          &list_element,  | 
929  | 8.53k  |          list,  | 
930  | 8.53k  |          element_index,  | 
931  | 8.53k  |          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  | 8.53k  |     if( libcdata_array_set_entry_by_index(  | 
943  | 8.53k  |          internal_list->elements_array,  | 
944  | 8.53k  |          element_index,  | 
945  | 8.53k  |          (intptr_t *) list_element,  | 
946  | 8.53k  |          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  | 8.53k  |   }  | 
963  | 617  |   else  | 
964  | 617  |   { | 
965  | 617  |     result = libfdata_list_element_get_mapped_size(  | 
966  | 617  |               list_element,  | 
967  | 617  |               &mapped_size,  | 
968  | 617  |               error );  | 
969  |  |  | 
970  | 617  |     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  | 617  |     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  | 617  |   }  | 
1004  | 9.15k  |   if( libfdata_list_element_set_data_range(  | 
1005  | 9.15k  |        list_element,  | 
1006  | 9.15k  |        element_file_index,  | 
1007  | 9.15k  |        element_offset,  | 
1008  | 9.15k  |        element_size,  | 
1009  | 9.15k  |        element_flags,  | 
1010  | 9.15k  |        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  | 9.15k  |   if( libcdata_array_get_entry_by_index(  | 
1025  | 9.15k  |        internal_list->mapped_ranges_array,  | 
1026  | 9.15k  |        element_index,  | 
1027  | 9.15k  |        (intptr_t **) &mapped_range,  | 
1028  | 9.15k  |        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  | 9.15k  |   if( mapped_range == NULL )  | 
1041  | 8.53k  |   { | 
1042  | 8.53k  |     if( libfdata_mapped_range_initialize(  | 
1043  | 8.53k  |          &mapped_range,  | 
1044  | 8.53k  |          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  | 8.53k  |     if( libcdata_array_set_entry_by_index(  | 
1056  | 8.53k  |          internal_list->mapped_ranges_array,  | 
1057  | 8.53k  |          element_index,  | 
1058  | 8.53k  |          (intptr_t *) mapped_range,  | 
1059  | 8.53k  |          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  | 8.53k  |     internal_list->size  += element_size;  | 
1076  | 8.53k  |     internal_list->flags |= LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES;  | 
1077  | 8.53k  |   }  | 
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  | 617  |   else if( ( mapped_size == 0 )  | 
1082  | 617  |         && ( 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  | 9.15k  |   internal_list->current_element_index = element_index;  | 
1136  |  |  | 
1137  | 9.15k  |   return( 1 );  | 
1138  | 9.15k  | }  | 
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  | 4.87M  | { | 
1363  | 4.87M  |   libfdata_internal_list_t *internal_list = NULL;  | 
1364  | 4.87M  |   libfdata_list_element_t *list_element   = NULL;  | 
1365  | 4.87M  |   libfdata_mapped_range_t *mapped_range   = NULL;  | 
1366  | 4.87M  |   static char *function                   = "libfdata_list_append_element";  | 
1367  | 4.87M  |   off64_t mapped_offset                   = 0;  | 
1368  | 4.87M  |   int mapped_range_index                  = -1;  | 
1369  |  |  | 
1370  | 4.87M  |   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  | 4.87M  |   internal_list = (libfdata_internal_list_t *) list;  | 
1382  |  |  | 
1383  | 4.87M  |   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  | 4.87M  |   if( libfdata_mapped_range_initialize(  | 
1395  | 4.87M  |        &mapped_range,  | 
1396  | 4.87M  |        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  | 4.87M  |   mapped_offset = internal_list->mapped_offset + (off64_t) internal_list->size;  | 
1408  |  |  | 
1409  | 4.87M  |   if( libfdata_mapped_range_set(  | 
1410  | 4.87M  |        mapped_range,  | 
1411  | 4.87M  |        mapped_offset,  | 
1412  | 4.87M  |        element_size,  | 
1413  | 4.87M  |        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  | 4.87M  |   if( libcdata_array_append_entry(  | 
1425  | 4.87M  |        internal_list->mapped_ranges_array,  | 
1426  | 4.87M  |        &mapped_range_index,  | 
1427  | 4.87M  |        (intptr_t *) mapped_range,  | 
1428  | 4.87M  |        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  | 4.87M  |   if( libfdata_list_element_initialize(  | 
1440  | 4.87M  |        &list_element,  | 
1441  | 4.87M  |        list,  | 
1442  | 4.87M  |        0,  | 
1443  | 4.87M  |        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  | 4.87M  |   if( libfdata_list_element_set_data_range(  | 
1455  | 4.87M  |        list_element,  | 
1456  | 4.87M  |        element_file_index,  | 
1457  | 4.87M  |        element_offset,  | 
1458  | 4.87M  |        element_size,  | 
1459  | 4.87M  |        element_flags,  | 
1460  | 4.87M  |        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  | 4.87M  |   if( libcdata_array_append_entry(  | 
1472  | 4.87M  |        internal_list->elements_array,  | 
1473  | 4.87M  |        element_index,  | 
1474  | 4.87M  |        (intptr_t *) list_element,  | 
1475  | 4.87M  |        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  | 4.87M  |   mapped_range_index = -1;  | 
1487  | 4.87M  |   mapped_range       = NULL;  | 
1488  |  |  | 
1489  | 4.87M  |   if( libfdata_list_element_set_element_index(  | 
1490  | 4.87M  |        list_element,  | 
1491  | 4.87M  |        *element_index,  | 
1492  | 4.87M  |        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  | 4.87M  |   internal_list->current_element_index = *element_index;  | 
1535  | 4.87M  |   internal_list->size                 += element_size;  | 
1536  |  |  | 
1537  | 4.87M  |   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  | 4.87M  | }  | 
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.89k  | { | 
2001  | 5.89k  |   libfdata_internal_list_t *internal_list = NULL;  | 
2002  | 5.89k  |   libfdata_mapped_range_t *mapped_range   = NULL;  | 
2003  | 5.89k  |   static char *function                   = "libfdata_list_get_element_mapped_range";  | 
2004  |  |  | 
2005  | 5.89k  |   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.89k  |   internal_list = (libfdata_internal_list_t *) list;  | 
2017  |  |  | 
2018  | 5.89k  |   if( ( internal_list->flags & LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES ) != 0 )  | 
2019  | 2.94k  |   { | 
2020  | 2.94k  |     if( libfdata_list_calculate_mapped_ranges(  | 
2021  | 2.94k  |          internal_list,  | 
2022  | 2.94k  |          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.94k  |   }  | 
2034  | 5.89k  |   if( libcdata_array_get_entry_by_index(  | 
2035  | 5.89k  |        internal_list->mapped_ranges_array,  | 
2036  | 5.89k  |        element_index,  | 
2037  | 5.89k  |        (intptr_t **) &mapped_range,  | 
2038  | 5.89k  |        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.89k  |   if( libfdata_mapped_range_get(  | 
2051  | 5.89k  |        mapped_range,  | 
2052  | 5.89k  |        mapped_range_offset,  | 
2053  | 5.89k  |        mapped_range_size,  | 
2054  | 5.89k  |        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.89k  |   return( 1 );  | 
2067  | 5.89k  | }  | 
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.30M  | { | 
2176  | 1.30M  |   libfdata_internal_list_t *internal_list = NULL;  | 
2177  | 1.30M  |   libfdata_list_element_t *list_element   = NULL;  | 
2178  | 1.30M  |   static char *function                   = "libfdata_list_get_mapped_size_by_index";  | 
2179  | 1.30M  |   int result                              = 0;  | 
2180  |  |  | 
2181  | 1.30M  |   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.30M  |   internal_list = (libfdata_internal_list_t *) list;  | 
2193  |  |  | 
2194  | 1.30M  |   if( libcdata_array_get_entry_by_index(  | 
2195  | 1.30M  |        internal_list->elements_array,  | 
2196  | 1.30M  |        element_index,  | 
2197  | 1.30M  |        (intptr_t **) &list_element,  | 
2198  | 1.30M  |        error ) != 1 )  | 
2199  | 3  |   { | 
2200  | 3  |     libcerror_error_set(  | 
2201  | 3  |      error,  | 
2202  | 3  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2203  | 3  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
2204  | 3  |      "%s: unable to retrieve entry: %d from elements array.",  | 
2205  | 3  |      function,  | 
2206  | 3  |      element_index );  | 
2207  |  |  | 
2208  | 3  |     return( -1 );  | 
2209  | 3  |   }  | 
2210  | 1.30M  |   result = libfdata_list_element_get_mapped_size(  | 
2211  | 1.30M  |             list_element,  | 
2212  | 1.30M  |             mapped_size,  | 
2213  | 1.30M  |             error );  | 
2214  |  |  | 
2215  | 1.30M  |   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.30M  |   internal_list->current_element_index = element_index;  | 
2228  |  |  | 
2229  | 1.30M  |   return( result );  | 
2230  | 1.30M  | }  | 
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  | 6.67k  | { | 
2241  | 6.67k  |   libfdata_internal_list_t *internal_list = NULL;  | 
2242  | 6.67k  |   libfdata_list_element_t *list_element   = NULL;  | 
2243  | 6.67k  |   static char *function                   = "libfdata_list_set_mapped_size_by_index";  | 
2244  |  |  | 
2245  | 6.67k  |   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  | 6.67k  |   internal_list = (libfdata_internal_list_t *) list;  | 
2257  |  |  | 
2258  | 6.67k  |   if( libcdata_array_get_entry_by_index(  | 
2259  | 6.67k  |        internal_list->elements_array,  | 
2260  | 6.67k  |        element_index,  | 
2261  | 6.67k  |        (intptr_t **) &list_element,  | 
2262  | 6.67k  |        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  | 6.67k  |   if( libfdata_list_element_set_mapped_size(  | 
2275  | 6.67k  |        list_element,  | 
2276  | 6.67k  |        mapped_size,  | 
2277  | 6.67k  |        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  | 6.67k  |   internal_list->current_element_index = element_index;  | 
2290  |  |  | 
2291  | 6.67k  |   return( 1 );  | 
2292  | 6.67k  | }  | 
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  | 109  | { | 
2307  | 109  |   libfdata_internal_list_t *internal_list = NULL;  | 
2308  | 109  |   libfdata_list_element_t *list_element   = NULL;  | 
2309  | 109  |   static char *function                   = "libfdata_list_get_element_by_index_with_mapped_size";  | 
2310  | 109  |   int result                              = 0;  | 
2311  |  |  | 
2312  | 109  |   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  | 109  |   internal_list = (libfdata_internal_list_t *) list;  | 
2324  |  |  | 
2325  | 109  |   if( libcdata_array_get_entry_by_index(  | 
2326  | 109  |        internal_list->elements_array,  | 
2327  | 109  |        element_index,  | 
2328  | 109  |        (intptr_t **) &list_element,  | 
2329  | 109  |        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  | 109  |   if( libfdata_list_element_get_data_range(  | 
2342  | 109  |        list_element,  | 
2343  | 109  |        element_file_index,  | 
2344  | 109  |        element_offset,  | 
2345  | 109  |        element_size,  | 
2346  | 109  |        element_flags,  | 
2347  | 109  |        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  | 109  |   result = libfdata_list_element_get_mapped_size(  | 
2360  | 109  |             list_element,  | 
2361  | 109  |             mapped_size,  | 
2362  | 109  |             error );  | 
2363  |  |  | 
2364  | 109  |   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  | 109  |   internal_list->current_element_index = element_index;  | 
2377  |  |  | 
2378  | 109  |   return( result );  | 
2379  | 109  | }  | 
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.55M  | { | 
2691  | 1.55M  |   libfdata_internal_list_t *internal_list = NULL;  | 
2692  | 1.55M  |   libfdata_list_element_t *list_element   = NULL;  | 
2693  | 1.55M  |   libfdata_mapped_range_t *mapped_range   = NULL;  | 
2694  | 1.55M  |   static char *function                   = "libfdata_list_append_element_with_mapped_size";  | 
2695  | 1.55M  |   off64_t mapped_offset                   = 0;  | 
2696  | 1.55M  |   int mapped_range_index                  = -1;  | 
2697  | 1.55M  |   uint8_t list_flags                      = 0;  | 
2698  |  |  | 
2699  | 1.55M  |   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.55M  |   internal_list = (libfdata_internal_list_t *) list;  | 
2711  |  |  | 
2712  | 1.55M  |   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.55M  |   if( libfdata_mapped_range_initialize(  | 
2724  | 1.55M  |        &mapped_range,  | 
2725  | 1.55M  |        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.55M  |   mapped_offset = internal_list->mapped_offset + (off64_t) internal_list->size;  | 
2737  |  |  | 
2738  | 1.55M  |   if( libfdata_mapped_range_set(  | 
2739  | 1.55M  |        mapped_range,  | 
2740  | 1.55M  |        mapped_offset,  | 
2741  | 1.55M  |        mapped_size,  | 
2742  | 1.55M  |        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.55M  |   if( libcdata_array_append_entry(  | 
2754  | 1.55M  |        internal_list->mapped_ranges_array,  | 
2755  | 1.55M  |        &mapped_range_index,  | 
2756  | 1.55M  |        (intptr_t *) mapped_range,  | 
2757  | 1.55M  |        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.55M  |   if( libfdata_list_element_initialize(  | 
2769  | 1.55M  |        &list_element,  | 
2770  | 1.55M  |        list,  | 
2771  | 1.55M  |        0,  | 
2772  | 1.55M  |        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.55M  |   if( libfdata_list_element_set_data_range(  | 
2784  | 1.55M  |        list_element,  | 
2785  | 1.55M  |        element_file_index,  | 
2786  | 1.55M  |        element_offset,  | 
2787  | 1.55M  |        element_size,  | 
2788  | 1.55M  |        element_flags,  | 
2789  | 1.55M  |        error ) != 1 )  | 
2790  | 46  |   { | 
2791  | 46  |     libcerror_error_set(  | 
2792  | 46  |      error,  | 
2793  | 46  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
2794  | 46  |      LIBCERROR_RUNTIME_ERROR_SET_FAILED,  | 
2795  | 46  |      "%s: unable to set data range of list element.",  | 
2796  | 46  |      function );  | 
2797  |  |  | 
2798  | 46  |     goto on_error;  | 
2799  | 46  |   }  | 
2800  | 1.55M  |   list_flags = internal_list->flags;  | 
2801  |  |  | 
2802  | 1.55M  |   if( libfdata_list_element_set_mapped_size(  | 
2803  | 1.55M  |        list_element,  | 
2804  | 1.55M  |        mapped_size,  | 
2805  | 1.55M  |        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.55M  |   if( ( list_flags & LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES ) == 0 )  | 
2820  | 1.55M  |   { | 
2821  | 1.55M  |     internal_list->flags &= ~( LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES );  | 
2822  | 1.55M  |   }  | 
2823  | 1.55M  |   if( libcdata_array_append_entry(  | 
2824  | 1.55M  |        internal_list->elements_array,  | 
2825  | 1.55M  |        element_index,  | 
2826  | 1.55M  |        (intptr_t *) list_element,  | 
2827  | 1.55M  |        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.55M  |   mapped_range_index = -1;  | 
2839  | 1.55M  |   mapped_range       = NULL;  | 
2840  |  |  | 
2841  | 1.55M  |   if( libfdata_list_element_set_element_index(  | 
2842  | 1.55M  |        list_element,  | 
2843  | 1.55M  |        *element_index,  | 
2844  | 1.55M  |        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.55M  |   internal_list->current_element_index = *element_index;  | 
2887  | 1.55M  |   internal_list->size                 += mapped_size;  | 
2888  |  |  | 
2889  | 1.55M  |   return( 1 );  | 
2890  |  |  | 
2891  | 46  | on_error:  | 
2892  | 46  |   if( list_element != NULL )  | 
2893  | 46  |   { | 
2894  | 46  |     libfdata_list_element_free(  | 
2895  | 46  |      &list_element,  | 
2896  | 46  |      NULL );  | 
2897  | 46  |   }  | 
2898  | 46  |   if( mapped_range_index != -1 )  | 
2899  | 46  |   { | 
2900  | 46  |     libcdata_array_set_entry_by_index(  | 
2901  | 46  |      internal_list->mapped_ranges_array,  | 
2902  | 46  |      mapped_range_index,  | 
2903  | 46  |      NULL,  | 
2904  | 46  |      NULL );  | 
2905  | 46  |   }  | 
2906  | 46  |   if( mapped_range != NULL )  | 
2907  | 46  |   { | 
2908  | 46  |     libfdata_mapped_range_free(  | 
2909  | 46  |      &mapped_range,  | 
2910  | 46  |      NULL );  | 
2911  | 46  |   }  | 
2912  | 46  |   return( -1 );  | 
2913  | 1.55M  | }  | 
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.78k  | { | 
2922  | 3.78k  |   libfdata_list_element_t *list_element = NULL;  | 
2923  | 3.78k  |   libfdata_mapped_range_t *mapped_range = NULL;  | 
2924  | 3.78k  |   static char *function                 = "libfdata_list_calculate_mapped_ranges";  | 
2925  | 3.78k  |   off64_t mapped_offset                 = 0;  | 
2926  | 3.78k  |   off64_t element_offset                = 0;  | 
2927  | 3.78k  |   size64_t element_size                 = 0;  | 
2928  | 3.78k  |   size64_t mapped_size                  = 0;  | 
2929  | 3.78k  |   uint32_t element_flags                = 0;  | 
2930  | 3.78k  |   int element_file_index                = -1;  | 
2931  | 3.78k  |   int element_index                     = -1;  | 
2932  | 3.78k  |   int number_of_elements                = 0;  | 
2933  | 3.78k  |   int result                            = 0;  | 
2934  |  |  | 
2935  | 3.78k  |   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.78k  |   if( libcdata_array_get_number_of_entries(  | 
2947  | 3.78k  |        internal_list->elements_array,  | 
2948  | 3.78k  |        &number_of_elements,  | 
2949  | 3.78k  |        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.78k  |   mapped_offset = internal_list->mapped_offset;  | 
2961  |  |  | 
2962  | 3.78k  |   for( element_index = 0;  | 
2963  | 7.90k  |        element_index < number_of_elements;  | 
2964  | 4.11k  |        element_index++ )  | 
2965  | 4.11k  |   { | 
2966  | 4.11k  |     if( libcdata_array_get_entry_by_index(  | 
2967  | 4.11k  |          internal_list->elements_array,  | 
2968  | 4.11k  |          element_index,  | 
2969  | 4.11k  |          (intptr_t **) &list_element,  | 
2970  | 4.11k  |          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  | 4.11k  |     if( libcdata_array_get_entry_by_index(  | 
2983  | 4.11k  |          internal_list->mapped_ranges_array,  | 
2984  | 4.11k  |          element_index,  | 
2985  | 4.11k  |          (intptr_t **) &mapped_range,  | 
2986  | 4.11k  |          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  | 4.11k  |     if( libfdata_list_element_get_data_range(  | 
2999  | 4.11k  |          list_element,  | 
3000  | 4.11k  |          &element_file_index,  | 
3001  | 4.11k  |          &element_offset,  | 
3002  | 4.11k  |          &element_size,  | 
3003  | 4.11k  |          &element_flags,  | 
3004  | 4.11k  |          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  | 4.11k  |     result = libfdata_list_element_get_mapped_size(  | 
3017  | 4.11k  |               list_element,  | 
3018  | 4.11k  |               &mapped_size,  | 
3019  | 4.11k  |               error );  | 
3020  |  |  | 
3021  | 4.11k  |     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  | 4.11k  |     else if( result == 0 )  | 
3034  | 2.94k  |     { | 
3035  | 2.94k  |       mapped_size = element_size;  | 
3036  | 2.94k  |     }  | 
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  | 4.11k  |     if( libfdata_mapped_range_set(  | 
3064  | 4.11k  |          mapped_range,  | 
3065  | 4.11k  |          mapped_offset,  | 
3066  | 4.11k  |          mapped_size,  | 
3067  | 4.11k  |          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  | 4.11k  |     mapped_offset += (off64_t) mapped_size;  | 
3080  | 4.11k  |   }  | 
3081  | 3.78k  |   internal_list->size   = (size64_t) mapped_offset - internal_list->mapped_offset;  | 
3082  | 3.78k  |   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.78k  |   return( 1 );  | 
3092  | 3.78k  | }  | 
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  | 563k  | { | 
3105  | 563k  |   libfdata_internal_list_t *internal_list = NULL;  | 
3106  | 563k  |   libfdata_mapped_range_t *mapped_range   = NULL;  | 
3107  | 563k  |   static char *function                   = "libfdata_list_get_element_index_at_offset";  | 
3108  | 563k  |   off64_t list_offset                     = 0;  | 
3109  | 563k  |   off64_t mapped_range_end_offset         = 0;  | 
3110  | 563k  |   off64_t mapped_range_start_offset       = 0;  | 
3111  | 563k  |   size64_t mapped_range_size              = 0;  | 
3112  | 563k  |   int initial_element_index               = 0;  | 
3113  | 563k  |   int number_of_elements                  = 0;  | 
3114  | 563k  |   int result                              = 0;  | 
3115  | 563k  |   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  | 563k  |   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  | 563k  |   internal_list = (libfdata_internal_list_t *) list;  | 
3137  |  |  | 
3138  | 563k  |   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  | 563k  |   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  | 563k  |   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  | 563k  |   if( ( internal_list->flags & LIBFDATA_FLAG_CALCULATE_MAPPED_RANGES ) != 0 )  | 
3172  | 837  |   { | 
3173  | 837  |     if( libfdata_list_calculate_mapped_ranges(  | 
3174  | 837  |          internal_list,  | 
3175  | 837  |          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  | 837  |   }  | 
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  | 563k  |   if( internal_list->size == 0 )  | 
3198  | 90  |   { | 
3199  | 90  |     return( 0 );  | 
3200  | 90  |   }  | 
3201  | 563k  |   if( offset < internal_list->mapped_offset )  | 
3202  | 0  |   { | 
3203  | 0  |     return( 0 );  | 
3204  | 0  |   }  | 
3205  | 563k  |   list_offset = offset - internal_list->mapped_offset;  | 
3206  |  |  | 
3207  | 563k  |   if( (size64_t) list_offset >= internal_list->size )  | 
3208  | 18.4k  |   { | 
3209  | 18.4k  |     return( 0 );  | 
3210  | 18.4k  |   }  | 
3211  | 545k  |   if( libcdata_array_get_number_of_entries(  | 
3212  | 545k  |        internal_list->mapped_ranges_array,  | 
3213  | 545k  |        &number_of_elements,  | 
3214  | 545k  |        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  | 545k  |   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  | 545k  |   for( search_element_index = initial_element_index;  | 
3241  | 1.11M  |        search_element_index < number_of_elements;  | 
3242  | 572k  |        search_element_index++ )  | 
3243  | 1.11M  |   { | 
3244  | 1.11M  |     if( libcdata_array_get_entry_by_index(  | 
3245  | 1.11M  |          internal_list->mapped_ranges_array,  | 
3246  | 1.11M  |          search_element_index,  | 
3247  | 1.11M  |          (intptr_t **) &mapped_range,  | 
3248  | 1.11M  |          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.11M  |     if( libfdata_mapped_range_get(  | 
3261  | 1.11M  |          mapped_range,  | 
3262  | 1.11M  |          &mapped_range_start_offset,  | 
3263  | 1.11M  |          &mapped_range_size,  | 
3264  | 1.11M  |          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.11M  |     mapped_range_end_offset = mapped_range_start_offset + (off64_t) mapped_range_size;  | 
3277  |  |  | 
3278  | 1.11M  |     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.11M  |     if( ( offset >= mapped_range_start_offset )  | 
3307  | 1.11M  |      && ( offset < mapped_range_end_offset ) )  | 
3308  | 535k  |     { | 
3309  | 535k  |       offset -= mapped_range_start_offset;  | 
3310  |  |  | 
3311  | 535k  |       break;  | 
3312  | 535k  |     }  | 
3313  |  |     /* Check if the offset is out of bounds  | 
3314  |  |      */  | 
3315  | 582k  |     if( offset < mapped_range_start_offset )  | 
3316  | 9.71k  |     { | 
3317  | 9.71k  |       search_element_index = number_of_elements;  | 
3318  |  |  | 
3319  | 9.71k  |       break;  | 
3320  | 9.71k  |     }  | 
3321  | 582k  |   }  | 
3322  | 545k  |   if( search_element_index >= number_of_elements )  | 
3323  | 9.71k  |   { | 
3324  |  |     /* Look for the corresponding element downwards in the array  | 
3325  |  |      */  | 
3326  | 9.71k  |     for( search_element_index = initial_element_index;  | 
3327  | 142k  |          search_element_index >= 0;  | 
3328  | 133k  |          search_element_index-- )  | 
3329  | 142k  |     { | 
3330  | 142k  |       if( libcdata_array_get_entry_by_index(  | 
3331  | 142k  |            internal_list->mapped_ranges_array,  | 
3332  | 142k  |            search_element_index,  | 
3333  | 142k  |            (intptr_t **) &mapped_range,  | 
3334  | 142k  |            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  | 142k  |       if( libfdata_mapped_range_get(  | 
3347  | 142k  |            mapped_range,  | 
3348  | 142k  |            &mapped_range_start_offset,  | 
3349  | 142k  |            &mapped_range_size,  | 
3350  | 142k  |            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  | 142k  |       mapped_range_end_offset = mapped_range_start_offset + (off64_t) mapped_range_size;  | 
3363  |  |  | 
3364  | 142k  |       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  | 142k  |       if( ( offset >= mapped_range_start_offset )  | 
3393  | 142k  |        && ( offset < mapped_range_end_offset ) )  | 
3394  | 9.71k  |       { | 
3395  | 9.71k  |         offset -= mapped_range_start_offset;  | 
3396  |  |  | 
3397  | 9.71k  |         break;  | 
3398  | 9.71k  |       }  | 
3399  |  |       /* Check if the offset is out of bounds  | 
3400  |  |        */  | 
3401  | 133k  |       if( offset > mapped_range_start_offset )  | 
3402  | 0  |       { | 
3403  | 0  |         search_element_index--;  | 
3404  |  | 
  | 
3405  | 0  |         break;  | 
3406  | 0  |       }  | 
3407  | 133k  |     }  | 
3408  | 9.71k  |   }  | 
3409  | 545k  |   if( ( search_element_index >= 0 )  | 
3410  | 545k  |    && ( search_element_index < number_of_elements ) )  | 
3411  | 545k  |   { | 
3412  | 545k  |     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  | 545k  |     *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  | 545k  |     internal_list->current_element_index = search_element_index;  | 
3476  |  |  | 
3477  | 545k  |     result = 1;  | 
3478  | 545k  |   }  | 
3479  | 545k  |   if( result == 1 )  | 
3480  | 545k  |   { | 
3481  | 545k  |     *element_index = search_element_index;  | 
3482  | 545k  |   }  | 
3483  |  | #if defined( HAVE_DEBUG_OUTPUT )  | 
3484  |  |   if( libcnotify_verbose != 0 )  | 
3485  |  |   { | 
3486  |  |     libcnotify_printf(  | 
3487  |  |      "\n" );  | 
3488  |  |   }  | 
3489  |  | #endif  | 
3490  | 545k  |   return( result );  | 
3491  | 545k  | }  | 
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  | 513k  | { | 
3505  | 513k  |   libfdata_internal_list_t *internal_list = NULL;  | 
3506  | 513k  |   static char *function                   = "libfdata_list_get_list_element_at_offset";  | 
3507  | 513k  |   int result                              = 0;  | 
3508  |  |  | 
3509  | 513k  |   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  | 513k  |   internal_list = (libfdata_internal_list_t *) list;  | 
3521  |  |  | 
3522  | 513k  |   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  | 513k  |   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  | 513k  |   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  | 513k  |   result = libfdata_list_get_element_index_at_offset(  | 
3556  | 513k  |             list,  | 
3557  | 513k  |             offset,  | 
3558  | 513k  |             element_index,  | 
3559  | 513k  |             element_data_offset,  | 
3560  | 513k  |             error );  | 
3561  |  |  | 
3562  | 513k  |   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  | 513k  |   else if( result != 0 )  | 
3576  | 513k  |   { | 
3577  | 513k  |     if( libcdata_array_get_entry_by_index(  | 
3578  | 513k  |          internal_list->elements_array,  | 
3579  | 513k  |          *element_index,  | 
3580  | 513k  |          (intptr_t **) element,  | 
3581  | 513k  |          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  | 513k  |   }  | 
3594  | 513k  |   return( result );  | 
3595  | 513k  | }  | 
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  | 771k  | { | 
3773  | 771k  |   libfcache_cache_value_t *cache_value    = NULL;  | 
3774  | 771k  |   libfdata_internal_list_t *internal_list = NULL;  | 
3775  | 771k  |   static char *function                   = "libfdata_list_get_element_value";  | 
3776  | 771k  |   size64_t element_data_size              = 0;  | 
3777  | 771k  |         off64_t cache_value_offset              = (off64_t) -1;  | 
3778  | 771k  |   off64_t element_data_offset             = 0;  | 
3779  | 771k  |   int64_t cache_value_timestamp           = 0;  | 
3780  | 771k  |   int64_t element_timestamp               = 0;  | 
3781  | 771k  |   uint32_t element_data_flags             = 0;  | 
3782  | 771k  |   int cache_value_file_index              = -1;  | 
3783  | 771k  |   int element_file_index                  = -1;  | 
3784  | 771k  |   int result                              = 0;  | 
3785  |  |  | 
3786  |  | #if defined( HAVE_DEBUG_OUTPUT )  | 
3787  |  |   const char *hit_or_miss                 = NULL;  | 
3788  |  | #endif  | 
3789  |  |  | 
3790  | 771k  |   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  | 771k  |   internal_list = (libfdata_internal_list_t *) list;  | 
3802  |  |  | 
3803  | 771k  |   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  | 771k  |   if( libfdata_list_element_get_data_range(  | 
3815  | 771k  |        element,  | 
3816  | 771k  |        &element_file_index,  | 
3817  | 771k  |        &element_data_offset,  | 
3818  | 771k  |        &element_data_size,  | 
3819  | 771k  |        &element_data_flags,  | 
3820  | 771k  |        error ) != 1 )  | 
3821  | 68  |   { | 
3822  | 68  |     libcerror_error_set(  | 
3823  | 68  |      error,  | 
3824  | 68  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
3825  | 68  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
3826  | 68  |      "%s: unable to retrieve data range from list element.",  | 
3827  | 68  |      function );  | 
3828  |  |  | 
3829  | 68  |     return( -1 );  | 
3830  | 68  |   }  | 
3831  | 771k  |   if( libfdata_list_element_get_timestamp(  | 
3832  | 771k  |        element,  | 
3833  | 771k  |        &element_timestamp,  | 
3834  | 771k  |        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  | 771k  |   if( ( read_flags & LIBFDATA_READ_FLAG_IGNORE_CACHE ) == 0 )  | 
3846  | 771k  |   { | 
3847  | 771k  |     result = libfcache_cache_get_value_by_identifier(  | 
3848  | 771k  |               (libfcache_cache_t *) cache,  | 
3849  | 771k  |               element_file_index,  | 
3850  | 771k  |               element_data_offset,  | 
3851  | 771k  |               element_timestamp,  | 
3852  | 771k  |               &cache_value,  | 
3853  | 771k  |               error );  | 
3854  |  |  | 
3855  | 771k  |     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  | 771k  |   }  | 
3885  | 771k  |   if( result == 0 )  | 
3886  | 22.0k  |   { | 
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  | 22.0k  |     if( internal_list->read_element_data(  | 
3899  | 22.0k  |          internal_list->data_handle,  | 
3900  | 22.0k  |          file_io_handle,  | 
3901  | 22.0k  |          element,  | 
3902  | 22.0k  |          cache,  | 
3903  | 22.0k  |          element_file_index,  | 
3904  | 22.0k  |          element_data_offset,  | 
3905  | 22.0k  |          element_data_size,  | 
3906  | 22.0k  |          element_data_flags,  | 
3907  | 22.0k  |          read_flags,  | 
3908  | 22.0k  |          error ) != 1 )  | 
3909  | 3.81k  |     { | 
3910  | 3.81k  |       libcerror_error_set(  | 
3911  | 3.81k  |        error,  | 
3912  | 3.81k  |        LIBCERROR_ERROR_DOMAIN_IO,  | 
3913  | 3.81k  |        LIBCERROR_IO_ERROR_READ_FAILED,  | 
3914  | 3.81k  |        "%s: unable to read element data at offset: %" PRIi64 " (0x%08" PRIx64 ").",  | 
3915  | 3.81k  |        function,  | 
3916  | 3.81k  |        element_data_offset,  | 
3917  | 3.81k  |        element_data_offset );  | 
3918  |  |  | 
3919  | 3.81k  |       return( -1 );  | 
3920  | 3.81k  |     }  | 
3921  | 18.2k  |     if( libfcache_cache_get_value_by_identifier(  | 
3922  | 18.2k  |          (libfcache_cache_t *) cache,  | 
3923  | 18.2k  |          element_file_index,  | 
3924  | 18.2k  |          element_data_offset,  | 
3925  | 18.2k  |          element_timestamp,  | 
3926  | 18.2k  |          &cache_value,  | 
3927  | 18.2k  |          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  | 18.2k  |     if( libfcache_cache_value_get_identifier(  | 
3939  | 18.2k  |          cache_value,  | 
3940  | 18.2k  |          &cache_value_file_index,  | 
3941  | 18.2k  |          &cache_value_offset,  | 
3942  | 18.2k  |          &cache_value_timestamp,  | 
3943  | 18.2k  |          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  | 18.2k  |     if( ( element_file_index != cache_value_file_index )  | 
3955  | 18.2k  |      || ( element_data_offset != cache_value_offset )  | 
3956  | 18.2k  |      || ( 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  | 18.2k  |   }  | 
3968  | 767k  |   if( libfcache_cache_value_get_value(  | 
3969  | 767k  |        cache_value,  | 
3970  | 767k  |        element_value,  | 
3971  | 767k  |        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  | 767k  |   return( 1 );  | 
3983  | 767k  | }  | 
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  | 258k  | { | 
3997  | 258k  |   libfdata_internal_list_t *internal_list = NULL;  | 
3998  | 258k  |   libfdata_list_element_t *list_element   = NULL;  | 
3999  | 258k  |   static char *function                   = "libfdata_list_get_element_value_by_index";  | 
4000  |  |  | 
4001  | 258k  |   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  | 258k  |   internal_list = (libfdata_internal_list_t *) list;  | 
4013  |  |  | 
4014  | 258k  |   if( libcdata_array_get_entry_by_index(  | 
4015  | 258k  |        internal_list->elements_array,  | 
4016  | 258k  |        element_index,  | 
4017  | 258k  |        (intptr_t **) &list_element,  | 
4018  | 258k  |        error ) != 1 )  | 
4019  | 93  |   { | 
4020  | 93  |     libcerror_error_set(  | 
4021  | 93  |      error,  | 
4022  | 93  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
4023  | 93  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
4024  | 93  |      "%s: unable to retrieve entry: %d from elements array.",  | 
4025  | 93  |      function,  | 
4026  | 93  |      element_index );  | 
4027  |  |  | 
4028  | 93  |     return( -1 );  | 
4029  | 93  |   }  | 
4030  | 257k  |   if( libfdata_list_get_element_value(  | 
4031  | 257k  |        list,  | 
4032  | 257k  |        file_io_handle,  | 
4033  | 257k  |        cache,  | 
4034  | 257k  |        list_element,  | 
4035  | 257k  |        element_value,  | 
4036  | 257k  |        read_flags,  | 
4037  | 257k  |        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  | 255k  |   internal_list->current_element_index = element_index;  | 
4049  |  |  | 
4050  | 255k  |   return( 1 );  | 
4051  | 257k  | }  | 
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  | 513k  | { | 
4067  | 513k  |   libfdata_list_element_t *list_element = NULL;  | 
4068  | 513k  |   static char *function                 = "libfdata_list_get_element_value_at_offset";  | 
4069  | 513k  |   int result                            = 0;  | 
4070  |  |  | 
4071  | 513k  |   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  | 513k  |   result = libfdata_list_get_list_element_at_offset(  | 
4083  | 513k  |             list,  | 
4084  | 513k  |             offset,  | 
4085  | 513k  |             element_index,  | 
4086  | 513k  |             element_data_offset,  | 
4087  | 513k  |             &list_element,  | 
4088  | 513k  |             error );  | 
4089  |  |  | 
4090  | 513k  |   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  | 513k  |   else if( result != 0 )  | 
4104  | 513k  |   { | 
4105  | 513k  |     if( libfdata_list_get_element_value(  | 
4106  | 513k  |          list,  | 
4107  | 513k  |          file_io_handle,  | 
4108  | 513k  |          cache,  | 
4109  | 513k  |          list_element,  | 
4110  | 513k  |          element_value,  | 
4111  | 513k  |          read_flags,  | 
4112  | 513k  |          error ) != 1 )  | 
4113  | 1.21k  |     { | 
4114  | 1.21k  |       libcerror_error_set(  | 
4115  | 1.21k  |        error,  | 
4116  | 1.21k  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
4117  | 1.21k  |        LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
4118  | 1.21k  |        "%s: unable to retrieve element: %d value.",  | 
4119  | 1.21k  |        function,  | 
4120  | 1.21k  |        *element_index );  | 
4121  |  |  | 
4122  | 1.21k  |       return( -1 );  | 
4123  | 1.21k  |     }  | 
4124  | 513k  |   }  | 
4125  | 512k  |   return( result );  | 
4126  | 513k  | }  | 
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  | 24.6k  | { | 
4148  | 24.6k  |   static char *function       = "libfdata_list_set_element_value";  | 
4149  | 24.6k  |   size64_t element_data_size  = 0;  | 
4150  | 24.6k  |   off64_t element_data_offset = 0;  | 
4151  | 24.6k  |   int64_t element_timestamp   = 0;  | 
4152  | 24.6k  |   uint32_t element_data_flags = 0;  | 
4153  | 24.6k  |   int element_file_index      = -1;  | 
4154  |  |  | 
4155  | 24.6k  |   LIBFDATA_UNREFERENCED_PARAMETER( file_io_handle )  | 
4156  |  |  | 
4157  | 24.6k  |   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  | 24.6k  |   if( libfdata_list_element_get_data_range(  | 
4169  | 24.6k  |        element,  | 
4170  | 24.6k  |        &element_file_index,  | 
4171  | 24.6k  |        &element_data_offset,  | 
4172  | 24.6k  |        &element_data_size,  | 
4173  | 24.6k  |        &element_data_flags,  | 
4174  | 24.6k  |        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  | 24.6k  |   if( libfdata_list_element_get_timestamp(  | 
4186  | 24.6k  |        element,  | 
4187  | 24.6k  |        &element_timestamp,  | 
4188  | 24.6k  |        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  | 24.6k  |   if( libfcache_cache_set_value_by_identifier(  | 
4200  | 24.6k  |        (libfcache_cache_t *) cache,  | 
4201  | 24.6k  |        element_file_index,  | 
4202  | 24.6k  |        element_data_offset,  | 
4203  | 24.6k  |        element_timestamp,  | 
4204  | 24.6k  |        element_value,  | 
4205  | 24.6k  |        free_element_value,  | 
4206  | 24.6k  |        write_flags,  | 
4207  | 24.6k  |        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  | 24.6k  |   return( 1 );  | 
4219  | 24.6k  | }  | 
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  | 6.26k  | { | 
4241  | 6.26k  |   libfdata_internal_list_t *internal_list = NULL;  | 
4242  | 6.26k  |   libfdata_list_element_t *list_element   = NULL;  | 
4243  | 6.26k  |   static char *function                   = "libfdata_list_set_element_value_by_index";  | 
4244  |  |  | 
4245  | 6.26k  |   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  | 6.26k  |   internal_list = (libfdata_internal_list_t *) list;  | 
4257  |  |  | 
4258  | 6.26k  |   if( libcdata_array_get_entry_by_index(  | 
4259  | 6.26k  |        internal_list->elements_array,  | 
4260  | 6.26k  |        element_index,  | 
4261  | 6.26k  |        (intptr_t **) &list_element,  | 
4262  | 6.26k  |        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  | 6.26k  |   if( libfdata_list_set_element_value(  | 
4275  | 6.26k  |        list,  | 
4276  | 6.26k  |        file_io_handle,  | 
4277  | 6.26k  |        cache,  | 
4278  | 6.26k  |        list_element,  | 
4279  | 6.26k  |        element_value,  | 
4280  | 6.26k  |        free_element_value,  | 
4281  | 6.26k  |        write_flags,  | 
4282  | 6.26k  |        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  | 6.26k  |   internal_list->current_element_index = element_index;  | 
4294  |  |  | 
4295  | 6.26k  |   return( 1 );  | 
4296  | 6.26k  | }  | 
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  |  |  |