/src/libvslvm/libfdata/libfdata_list_element.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * The list element 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_libcerror.h" |
28 | | #include "libfdata_libcnotify.h" |
29 | | #include "libfdata_libfcache.h" |
30 | | #include "libfdata_list.h" |
31 | | #include "libfdata_list_element.h" |
32 | | #include "libfdata_range.h" |
33 | | #include "libfdata_types.h" |
34 | | |
35 | | /* Creates an element |
36 | | * Make sure the value element is referencing, is set to NULL |
37 | | * Returns 1 if successful or -1 on error |
38 | | */ |
39 | | int libfdata_list_element_initialize( |
40 | | libfdata_list_element_t **element, |
41 | | libfdata_list_t *list, |
42 | | int element_index, |
43 | | libcerror_error_t **error ) |
44 | 6.51M | { |
45 | 6.51M | libfdata_internal_list_element_t *internal_element = NULL; |
46 | 6.51M | static char *function = "libfdata_list_element_initialize"; |
47 | | |
48 | 6.51M | if( element == NULL ) |
49 | 0 | { |
50 | 0 | libcerror_error_set( |
51 | 0 | error, |
52 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
53 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
54 | 0 | "%s: invalid element.", |
55 | 0 | function ); |
56 | |
|
57 | 0 | return( -1 ); |
58 | 0 | } |
59 | 6.51M | if( *element != NULL ) |
60 | 0 | { |
61 | 0 | libcerror_error_set( |
62 | 0 | error, |
63 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
64 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
65 | 0 | "%s: invalid element value already set.", |
66 | 0 | function ); |
67 | |
|
68 | 0 | return( -1 ); |
69 | 0 | } |
70 | 6.51M | if( list == NULL ) |
71 | 0 | { |
72 | 0 | libcerror_error_set( |
73 | 0 | error, |
74 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
75 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
76 | 0 | "%s: invalid list.", |
77 | 0 | function ); |
78 | |
|
79 | 0 | return( -1 ); |
80 | 0 | } |
81 | 6.51M | if( element_index < 0 ) |
82 | 0 | { |
83 | 0 | libcerror_error_set( |
84 | 0 | error, |
85 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
86 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_LESS_THAN_ZERO, |
87 | 0 | "%s: invalid element index value less than zero.", |
88 | 0 | function ); |
89 | |
|
90 | 0 | return( -1 ); |
91 | 0 | } |
92 | 6.51M | internal_element = memory_allocate_structure( |
93 | 6.51M | libfdata_internal_list_element_t ); |
94 | | |
95 | 6.51M | if( internal_element == NULL ) |
96 | 0 | { |
97 | 0 | libcerror_error_set( |
98 | 0 | error, |
99 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
100 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
101 | 0 | "%s: unable to create element.", |
102 | 0 | function ); |
103 | |
|
104 | 0 | goto on_error; |
105 | 0 | } |
106 | 6.51M | if( memory_set( |
107 | 6.51M | internal_element, |
108 | 6.51M | 0, |
109 | 6.51M | sizeof( libfdata_internal_list_element_t ) ) == NULL ) |
110 | 0 | { |
111 | 0 | libcerror_error_set( |
112 | 0 | error, |
113 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
114 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
115 | 0 | "%s: unable to clear element.", |
116 | 0 | function ); |
117 | |
|
118 | 0 | memory_free( |
119 | 0 | internal_element ); |
120 | |
|
121 | 0 | return( -1 ); |
122 | 0 | } |
123 | 6.51M | if( libfdata_range_initialize( |
124 | 6.51M | &( internal_element->data_range ), |
125 | 6.51M | error ) != 1 ) |
126 | 0 | { |
127 | 0 | libcerror_error_set( |
128 | 0 | error, |
129 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
130 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
131 | 0 | "%s: unable to create data range.", |
132 | 0 | function ); |
133 | |
|
134 | 0 | goto on_error; |
135 | 0 | } |
136 | 6.51M | if( libfcache_date_time_get_timestamp( |
137 | 6.51M | &( internal_element->timestamp ), |
138 | 6.51M | error ) != 1 ) |
139 | 0 | { |
140 | 0 | libcerror_error_set( |
141 | 0 | error, |
142 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
143 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
144 | 0 | "%s: unable to retrieve cache timestamp.", |
145 | 0 | function ); |
146 | |
|
147 | 0 | goto on_error; |
148 | 0 | } |
149 | 6.51M | internal_element->list = list; |
150 | 6.51M | internal_element->element_index = element_index; |
151 | | |
152 | 6.51M | *element = (libfdata_list_element_t *) internal_element; |
153 | | |
154 | 6.51M | return( 1 ); |
155 | | |
156 | 0 | on_error: |
157 | 0 | if( internal_element != NULL ) |
158 | 0 | { |
159 | 0 | if( internal_element->data_range != NULL ) |
160 | 0 | { |
161 | 0 | libfdata_range_free( |
162 | 0 | &( internal_element->data_range ), |
163 | 0 | NULL ); |
164 | 0 | } |
165 | 0 | memory_free( |
166 | 0 | internal_element ); |
167 | 0 | } |
168 | 0 | return( -1 ); |
169 | 6.51M | } |
170 | | |
171 | | /* Frees an element |
172 | | * Returns 1 if successful or -1 on error |
173 | | */ |
174 | | int libfdata_list_element_free( |
175 | | libfdata_list_element_t **element, |
176 | | libcerror_error_t **error ) |
177 | 6.51M | { |
178 | 6.51M | libfdata_internal_list_element_t *internal_element = NULL; |
179 | 6.51M | static char *function = "libfdata_list_element_free"; |
180 | 6.51M | int result = 1; |
181 | | |
182 | 6.51M | if( element == NULL ) |
183 | 0 | { |
184 | 0 | libcerror_error_set( |
185 | 0 | error, |
186 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
187 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
188 | 0 | "%s: invalid element.", |
189 | 0 | function ); |
190 | |
|
191 | 0 | return( -1 ); |
192 | 0 | } |
193 | 6.51M | if( *element != NULL ) |
194 | 6.51M | { |
195 | 6.51M | internal_element = (libfdata_internal_list_element_t *) *element; |
196 | 6.51M | *element = NULL; |
197 | | |
198 | 6.51M | if( libfdata_range_free( |
199 | 6.51M | &( internal_element->data_range ), |
200 | 6.51M | error ) != 1 ) |
201 | 0 | { |
202 | 0 | libcerror_error_set( |
203 | 0 | error, |
204 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
205 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
206 | 0 | "%s: unable to free data range.", |
207 | 0 | function ); |
208 | |
|
209 | 0 | result = -1; |
210 | 0 | } |
211 | 6.51M | memory_free( |
212 | 6.51M | internal_element ); |
213 | 6.51M | } |
214 | 6.51M | return( result ); |
215 | 6.51M | } |
216 | | |
217 | | /* Clones (duplicates) the element |
218 | | * Returns 1 if successful or -1 on error |
219 | | */ |
220 | | int libfdata_list_element_clone( |
221 | | libfdata_list_element_t **destination_element, |
222 | | libfdata_list_element_t *source_element, |
223 | | libcerror_error_t **error ) |
224 | 0 | { |
225 | 0 | libfdata_internal_list_element_t *internal_destination_element = NULL; |
226 | 0 | libfdata_internal_list_element_t *internal_source_element = NULL; |
227 | 0 | static char *function = "libfdata_list_element_clone"; |
228 | |
|
229 | 0 | if( destination_element == NULL ) |
230 | 0 | { |
231 | 0 | libcerror_error_set( |
232 | 0 | error, |
233 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
234 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
235 | 0 | "%s: invalid destination element.", |
236 | 0 | function ); |
237 | |
|
238 | 0 | return( -1 ); |
239 | 0 | } |
240 | 0 | if( *destination_element != NULL ) |
241 | 0 | { |
242 | 0 | libcerror_error_set( |
243 | 0 | error, |
244 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
245 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
246 | 0 | "%s: destination element already set.", |
247 | 0 | function ); |
248 | |
|
249 | 0 | return( -1 ); |
250 | 0 | } |
251 | 0 | if( source_element == NULL ) |
252 | 0 | { |
253 | 0 | *destination_element = NULL; |
254 | |
|
255 | 0 | return( 1 ); |
256 | 0 | } |
257 | 0 | internal_source_element = (libfdata_internal_list_element_t *) source_element; |
258 | |
|
259 | 0 | internal_destination_element = memory_allocate_structure( |
260 | 0 | libfdata_internal_list_element_t ); |
261 | |
|
262 | 0 | if( internal_destination_element == NULL ) |
263 | 0 | { |
264 | 0 | libcerror_error_set( |
265 | 0 | error, |
266 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
267 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
268 | 0 | "%s: unable to create destination element.", |
269 | 0 | function ); |
270 | |
|
271 | 0 | goto on_error; |
272 | 0 | } |
273 | 0 | if( memory_set( |
274 | 0 | internal_destination_element, |
275 | 0 | 0, |
276 | 0 | sizeof( libfdata_internal_list_element_t ) ) == NULL ) |
277 | 0 | { |
278 | 0 | libcerror_error_set( |
279 | 0 | error, |
280 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
281 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
282 | 0 | "%s: unable to clear destination element.", |
283 | 0 | function ); |
284 | |
|
285 | 0 | memory_free( |
286 | 0 | internal_destination_element ); |
287 | |
|
288 | 0 | return( -1 ); |
289 | 0 | } |
290 | 0 | if( libfdata_range_clone( |
291 | 0 | &( internal_destination_element->data_range ), |
292 | 0 | internal_source_element->data_range, |
293 | 0 | error ) != 1 ) |
294 | 0 | { |
295 | 0 | libcerror_error_set( |
296 | 0 | error, |
297 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
298 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
299 | 0 | "%s: unable to create destination data range.", |
300 | 0 | function ); |
301 | |
|
302 | 0 | goto on_error; |
303 | 0 | } |
304 | 0 | if( libfcache_date_time_get_timestamp( |
305 | 0 | &( internal_destination_element->timestamp ), |
306 | 0 | error ) != 1 ) |
307 | 0 | { |
308 | 0 | libcerror_error_set( |
309 | 0 | error, |
310 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
311 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
312 | 0 | "%s: unable to retrieve destination timestamp.", |
313 | 0 | function ); |
314 | |
|
315 | 0 | goto on_error; |
316 | 0 | } |
317 | 0 | internal_destination_element->list = internal_source_element->list; |
318 | 0 | internal_destination_element->element_index = internal_source_element->element_index; |
319 | 0 | internal_destination_element->mapped_size = internal_source_element->mapped_size; |
320 | |
|
321 | 0 | *destination_element = (libfdata_list_element_t *) internal_destination_element; |
322 | |
|
323 | 0 | return( 1 ); |
324 | | |
325 | 0 | on_error: |
326 | 0 | if( internal_destination_element != NULL ) |
327 | 0 | { |
328 | 0 | if( internal_destination_element->data_range != NULL ) |
329 | 0 | { |
330 | 0 | libfdata_range_free( |
331 | 0 | &( internal_destination_element->data_range ), |
332 | 0 | NULL ); |
333 | 0 | } |
334 | 0 | memory_free( |
335 | 0 | internal_destination_element ); |
336 | 0 | } |
337 | 0 | return( -1 ); |
338 | 0 | } |
339 | | |
340 | | /* Retrieves the element index |
341 | | * Returns 1 if successful or -1 on error |
342 | | */ |
343 | | int libfdata_list_element_get_element_index( |
344 | | libfdata_list_element_t *element, |
345 | | int *element_index, |
346 | | libcerror_error_t **error ) |
347 | 659 | { |
348 | 659 | libfdata_internal_list_element_t *internal_element = NULL; |
349 | 659 | static char *function = "libfdata_list_element_get_element_index"; |
350 | | |
351 | 659 | if( element == NULL ) |
352 | 0 | { |
353 | 0 | libcerror_error_set( |
354 | 0 | error, |
355 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
356 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
357 | 0 | "%s: invalid element.", |
358 | 0 | function ); |
359 | |
|
360 | 0 | return( -1 ); |
361 | 0 | } |
362 | 659 | internal_element = (libfdata_internal_list_element_t *) element; |
363 | | |
364 | 659 | if( element_index == NULL ) |
365 | 0 | { |
366 | 0 | libcerror_error_set( |
367 | 0 | error, |
368 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
369 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
370 | 0 | "%s: invalid element index.", |
371 | 0 | function ); |
372 | |
|
373 | 0 | return( -1 ); |
374 | 0 | } |
375 | 659 | *element_index = internal_element->element_index; |
376 | | |
377 | 659 | return( 1 ); |
378 | 659 | } |
379 | | |
380 | | /* Sets the element index |
381 | | * Returns 1 if successful or -1 on error |
382 | | */ |
383 | | int libfdata_list_element_set_element_index( |
384 | | libfdata_list_element_t *element, |
385 | | int element_index, |
386 | | libcerror_error_t **error ) |
387 | 6.50M | { |
388 | 6.50M | libfdata_internal_list_element_t *internal_element = NULL; |
389 | 6.50M | static char *function = "libfdata_list_element_set_element_index"; |
390 | | |
391 | 6.50M | if( element == NULL ) |
392 | 0 | { |
393 | 0 | libcerror_error_set( |
394 | 0 | error, |
395 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
396 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
397 | 0 | "%s: invalid element.", |
398 | 0 | function ); |
399 | |
|
400 | 0 | return( -1 ); |
401 | 0 | } |
402 | 6.50M | internal_element = (libfdata_internal_list_element_t *) element; |
403 | | |
404 | 6.50M | if( element_index < 0 ) |
405 | 0 | { |
406 | 0 | libcerror_error_set( |
407 | 0 | error, |
408 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
409 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_LESS_THAN_ZERO, |
410 | 0 | "%s: invalid element index value less than zero.", |
411 | 0 | function ); |
412 | |
|
413 | 0 | return( -1 ); |
414 | 0 | } |
415 | 6.50M | internal_element->element_index = element_index; |
416 | | |
417 | 6.50M | return( 1 ); |
418 | 6.50M | } |
419 | | |
420 | | /* Retrieves the time stamp |
421 | | * Returns 1 if successful or -1 on error |
422 | | */ |
423 | | int libfdata_list_element_get_timestamp( |
424 | | libfdata_list_element_t *element, |
425 | | int64_t *timestamp, |
426 | | libcerror_error_t **error ) |
427 | 777k | { |
428 | 777k | libfdata_internal_list_element_t *internal_element = NULL; |
429 | 777k | static char *function = "libfdata_list_element_get_timestamp"; |
430 | | |
431 | 777k | if( element == NULL ) |
432 | 0 | { |
433 | 0 | libcerror_error_set( |
434 | 0 | error, |
435 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
436 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
437 | 0 | "%s: invalid element.", |
438 | 0 | function ); |
439 | |
|
440 | 0 | return( -1 ); |
441 | 0 | } |
442 | 777k | internal_element = (libfdata_internal_list_element_t *) element; |
443 | | |
444 | 777k | if( timestamp == NULL ) |
445 | 0 | { |
446 | 0 | libcerror_error_set( |
447 | 0 | error, |
448 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
449 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
450 | 0 | "%s: invalid time stamp.", |
451 | 0 | function ); |
452 | |
|
453 | 0 | return( -1 ); |
454 | 0 | } |
455 | 777k | *timestamp = internal_element->timestamp; |
456 | | |
457 | 777k | return( 1 ); |
458 | 777k | } |
459 | | |
460 | | /* Data range functions |
461 | | */ |
462 | | |
463 | | /* Retrieves the data range |
464 | | * Returns 1 if successful or -1 on error |
465 | | */ |
466 | | int libfdata_list_element_get_data_range( |
467 | | libfdata_list_element_t *element, |
468 | | int *file_index, |
469 | | off64_t *offset, |
470 | | size64_t *size, |
471 | | uint32_t *flags, |
472 | | libcerror_error_t **error ) |
473 | 784k | { |
474 | 784k | libfdata_internal_list_element_t *internal_element = NULL; |
475 | 784k | static char *function = "libfdata_list_element_get_data_range"; |
476 | | |
477 | 784k | if( element == NULL ) |
478 | 69 | { |
479 | 69 | libcerror_error_set( |
480 | 69 | error, |
481 | 69 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
482 | 69 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
483 | 69 | "%s: invalid element.", |
484 | 69 | function ); |
485 | | |
486 | 69 | return( -1 ); |
487 | 69 | } |
488 | 784k | internal_element = (libfdata_internal_list_element_t *) element; |
489 | | |
490 | 784k | if( libfdata_range_get( |
491 | 784k | internal_element->data_range, |
492 | 784k | file_index, |
493 | 784k | offset, |
494 | 784k | size, |
495 | 784k | flags, |
496 | 784k | error ) != 1 ) |
497 | 0 | { |
498 | 0 | libcerror_error_set( |
499 | 0 | error, |
500 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
501 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
502 | 0 | "%s: unable to retrieve data range.", |
503 | 0 | function ); |
504 | |
|
505 | 0 | return( -1 ); |
506 | 0 | } |
507 | 784k | return( 1 ); |
508 | 784k | } |
509 | | |
510 | | /* Sets the data range |
511 | | * Returns 1 if successful or -1 on error |
512 | | */ |
513 | | int libfdata_list_element_set_data_range( |
514 | | libfdata_list_element_t *element, |
515 | | int file_index, |
516 | | off64_t offset, |
517 | | size64_t size, |
518 | | uint32_t flags, |
519 | | libcerror_error_t **error ) |
520 | 6.51M | { |
521 | 6.51M | libfdata_internal_list_element_t *internal_element = NULL; |
522 | 6.51M | static char *function = "libfdata_list_element_set_data_range"; |
523 | | |
524 | 6.51M | if( element == NULL ) |
525 | 0 | { |
526 | 0 | libcerror_error_set( |
527 | 0 | error, |
528 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
529 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
530 | 0 | "%s: invalid element.", |
531 | 0 | function ); |
532 | |
|
533 | 0 | return( -1 ); |
534 | 0 | } |
535 | 6.51M | internal_element = (libfdata_internal_list_element_t *) element; |
536 | | |
537 | 6.51M | if( file_index < 0 ) |
538 | 0 | { |
539 | 0 | libcerror_error_set( |
540 | 0 | error, |
541 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
542 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_LESS_THAN_ZERO, |
543 | 0 | "%s: invalid file index less than zero.", |
544 | 0 | function ); |
545 | |
|
546 | 0 | return( -1 ); |
547 | 0 | } |
548 | 6.51M | if( offset < 0 ) |
549 | 0 | { |
550 | 0 | libcerror_error_set( |
551 | 0 | error, |
552 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
553 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_LESS_THAN_ZERO, |
554 | 0 | "%s: invalid offset value less than zero.", |
555 | 0 | function ); |
556 | |
|
557 | 0 | return( -1 ); |
558 | 0 | } |
559 | 6.51M | if( size > (size64_t) INT64_MAX ) |
560 | 43 | { |
561 | 43 | libcerror_error_set( |
562 | 43 | error, |
563 | 43 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
564 | 43 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
565 | 43 | "%s: invalid size value exceeds maximum.", |
566 | 43 | function ); |
567 | | |
568 | 43 | return( -1 ); |
569 | 43 | } |
570 | 6.51M | if( libfdata_range_set( |
571 | 6.51M | internal_element->data_range, |
572 | 6.51M | file_index, |
573 | 6.51M | offset, |
574 | 6.51M | size, |
575 | 6.51M | flags, |
576 | 6.51M | error ) != 1 ) |
577 | 0 | { |
578 | 0 | libcerror_error_set( |
579 | 0 | error, |
580 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
581 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
582 | 0 | "%s: unable to set data range.", |
583 | 0 | function ); |
584 | |
|
585 | 0 | return( -1 ); |
586 | 0 | } |
587 | 6.51M | if( libfcache_date_time_get_timestamp( |
588 | 6.51M | &( internal_element->timestamp ), |
589 | 6.51M | error ) != 1 ) |
590 | 0 | { |
591 | 0 | libcerror_error_set( |
592 | 0 | error, |
593 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
594 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
595 | 0 | "%s: unable to retrieve cache timestamp.", |
596 | 0 | function ); |
597 | |
|
598 | 0 | return( -1 ); |
599 | 0 | } |
600 | 6.51M | return( 1 ); |
601 | 6.51M | } |
602 | | |
603 | | /* Mapped range functions |
604 | | */ |
605 | | |
606 | | /* Retrieves the mapped size |
607 | | * Returns 1 if successful, 0 if not set or -1 on error |
608 | | */ |
609 | | int libfdata_list_element_get_mapped_size( |
610 | | libfdata_list_element_t *element, |
611 | | size64_t *mapped_size, |
612 | | libcerror_error_t **error ) |
613 | 1.05M | { |
614 | 1.05M | libfdata_internal_list_element_t *internal_element = NULL; |
615 | 1.05M | static char *function = "libfdata_list_element_get_mapped_size"; |
616 | | |
617 | 1.05M | if( element == NULL ) |
618 | 0 | { |
619 | 0 | libcerror_error_set( |
620 | 0 | error, |
621 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
622 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
623 | 0 | "%s: invalid element.", |
624 | 0 | function ); |
625 | |
|
626 | 0 | return( -1 ); |
627 | 0 | } |
628 | 1.05M | internal_element = (libfdata_internal_list_element_t *) element; |
629 | | |
630 | 1.05M | if( mapped_size == NULL ) |
631 | 0 | { |
632 | 0 | libcerror_error_set( |
633 | 0 | error, |
634 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
635 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
636 | 0 | "%s: invalid mapped size.", |
637 | 0 | function ); |
638 | |
|
639 | 0 | return( -1 ); |
640 | 0 | } |
641 | 1.05M | if( ( internal_element->flags & LIBFDATA_LIST_ELEMENT_FLAG_HAS_MAPPED_SIZE ) == 0 ) |
642 | 2.87k | { |
643 | 2.87k | return( 0 ); |
644 | 2.87k | } |
645 | 1.05M | *mapped_size = internal_element->mapped_size; |
646 | | |
647 | 1.05M | return( 1 ); |
648 | 1.05M | } |
649 | | |
650 | | /* Sets the mapped size |
651 | | * Returns 1 if successful or -1 on error |
652 | | */ |
653 | | int libfdata_list_element_set_mapped_size( |
654 | | libfdata_list_element_t *element, |
655 | | size64_t mapped_size, |
656 | | libcerror_error_t **error ) |
657 | 1.28M | { |
658 | 1.28M | libfdata_internal_list_element_t *internal_element = NULL; |
659 | 1.28M | static char *function = "libfdata_list_element_set_mapped_size"; |
660 | | |
661 | 1.28M | if( element == NULL ) |
662 | 0 | { |
663 | 0 | libcerror_error_set( |
664 | 0 | error, |
665 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
666 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
667 | 0 | "%s: invalid element.", |
668 | 0 | function ); |
669 | |
|
670 | 0 | return( -1 ); |
671 | 0 | } |
672 | 1.28M | internal_element = (libfdata_internal_list_element_t *) element; |
673 | | |
674 | 1.28M | if( mapped_size > (size64_t) INT64_MAX ) |
675 | 0 | { |
676 | 0 | libcerror_error_set( |
677 | 0 | error, |
678 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
679 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
680 | 0 | "%s: invalid mapped size value exceeds maximum.", |
681 | 0 | function ); |
682 | |
|
683 | 0 | return( -1 ); |
684 | 0 | } |
685 | | #if defined( HAVE_DEBUG_OUTPUT ) |
686 | | if( libcnotify_verbose != 0 ) |
687 | | { |
688 | | libcnotify_printf( |
689 | | "%s: element: %03d\tmapped size: %" PRIu64 "\n", |
690 | | function, |
691 | | internal_element->element_index, |
692 | | mapped_size ); |
693 | | |
694 | | libcnotify_printf( |
695 | | "\n" ); |
696 | | } |
697 | | #endif |
698 | 1.28M | internal_element->mapped_size = mapped_size; |
699 | 1.28M | internal_element->flags |= LIBFDATA_LIST_ELEMENT_FLAG_HAS_MAPPED_SIZE; |
700 | | |
701 | 1.28M | if( libfdata_list_set_calculate_mapped_ranges_flag( |
702 | 1.28M | internal_element->list, |
703 | 1.28M | error ) != 1 ) |
704 | 0 | { |
705 | 0 | libcerror_error_set( |
706 | 0 | error, |
707 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
708 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
709 | 0 | "%s: unable to set the calculate mapped ranges flag in list.", |
710 | 0 | function ); |
711 | |
|
712 | 0 | return( -1 ); |
713 | 0 | } |
714 | 1.28M | return( 1 ); |
715 | 1.28M | } |
716 | | |
717 | | /* Element value functions |
718 | | */ |
719 | | |
720 | | /* Retrieves the element value |
721 | | * Returns 1 if successful or -1 on error |
722 | | */ |
723 | | int libfdata_list_element_get_element_value( |
724 | | libfdata_list_element_t *element, |
725 | | intptr_t *file_io_handle, |
726 | | libfdata_cache_t *cache, |
727 | | intptr_t **element_value, |
728 | | uint8_t read_flags, |
729 | | libcerror_error_t **error ) |
730 | 424 | { |
731 | 424 | libfdata_internal_list_element_t *internal_element = NULL; |
732 | 424 | static char *function = "libfdata_list_element_get_element_value"; |
733 | | |
734 | 424 | if( element == NULL ) |
735 | 0 | { |
736 | 0 | libcerror_error_set( |
737 | 0 | error, |
738 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
739 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
740 | 0 | "%s: invalid element.", |
741 | 0 | function ); |
742 | |
|
743 | 0 | return( -1 ); |
744 | 0 | } |
745 | 424 | internal_element = (libfdata_internal_list_element_t *) element; |
746 | | |
747 | 424 | if( libfdata_list_get_element_value( |
748 | 424 | internal_element->list, |
749 | 424 | file_io_handle, |
750 | 424 | cache, |
751 | 424 | element, |
752 | 424 | element_value, |
753 | 424 | read_flags, |
754 | 424 | error ) != 1 ) |
755 | 173 | { |
756 | 173 | libcerror_error_set( |
757 | 173 | error, |
758 | 173 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
759 | 173 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
760 | 173 | "%s: unable to retrieve element value.", |
761 | 173 | function ); |
762 | | |
763 | 173 | return( -1 ); |
764 | 173 | } |
765 | 251 | return( 1 ); |
766 | 424 | } |
767 | | |
768 | | /* Sets the element value |
769 | | * |
770 | | * If the flag LIBFDATA_LIST_ELEMENT_VALUE_FLAG_MANAGED is set the list element |
771 | | * takes over management of the value and the value is freed when |
772 | | * no longer needed. |
773 | | * |
774 | | * Returns 1 if successful or -1 on error |
775 | | */ |
776 | | int libfdata_list_element_set_element_value( |
777 | | libfdata_list_element_t *element, |
778 | | intptr_t *file_io_handle, |
779 | | libfdata_cache_t *cache, |
780 | | intptr_t *element_value, |
781 | | int (*free_element_value)( |
782 | | intptr_t **element_value, |
783 | | libcerror_error_t **error ), |
784 | | uint8_t write_flags, |
785 | | libcerror_error_t **error ) |
786 | 18.0k | { |
787 | 18.0k | libfdata_internal_list_element_t *internal_element = NULL; |
788 | 18.0k | static char *function = "libfdata_list_element_set_element_value"; |
789 | | |
790 | 18.0k | if( element == NULL ) |
791 | 0 | { |
792 | 0 | libcerror_error_set( |
793 | 0 | error, |
794 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
795 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
796 | 0 | "%s: invalid element.", |
797 | 0 | function ); |
798 | |
|
799 | 0 | return( -1 ); |
800 | 0 | } |
801 | 18.0k | internal_element = (libfdata_internal_list_element_t *) element; |
802 | | |
803 | 18.0k | if( libfdata_list_set_element_value( |
804 | 18.0k | internal_element->list, |
805 | 18.0k | file_io_handle, |
806 | 18.0k | cache, |
807 | 18.0k | element, |
808 | 18.0k | element_value, |
809 | 18.0k | free_element_value, |
810 | 18.0k | write_flags, |
811 | 18.0k | error ) != 1 ) |
812 | 0 | { |
813 | 0 | libcerror_error_set( |
814 | 0 | error, |
815 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
816 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
817 | 0 | "%s: unable to set element value.", |
818 | 0 | function ); |
819 | |
|
820 | 0 | return( -1 ); |
821 | 0 | } |
822 | 18.0k | return( 1 ); |
823 | 18.0k | } |
824 | | |