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