/src/libfsext/libfcache/libfcache_cache.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * The cache 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 "libfcache_cache.h"  | 
27  |  | #include "libfcache_cache_value.h"  | 
28  |  | #include "libfcache_definitions.h"  | 
29  |  | #include "libfcache_libcdata.h"  | 
30  |  | #include "libfcache_libcerror.h"  | 
31  |  | #include "libfcache_types.h"  | 
32  |  |  | 
33  |  | /* Creates a cache  | 
34  |  |  * Make sure the value cache is referencing, is set to NULL  | 
35  |  |  * Returns 1 if successful or -1 on error  | 
36  |  |  */  | 
37  |  | int libfcache_cache_initialize(  | 
38  |  |      libfcache_cache_t **cache,  | 
39  |  |      int maximum_cache_entries,  | 
40  |  |      libcerror_error_t **error )  | 
41  | 270k  | { | 
42  | 270k  |   libfcache_internal_cache_t *internal_cache = NULL;  | 
43  | 270k  |   static char *function                      = "libfcache_cache_initialize";  | 
44  |  |  | 
45  | 270k  |   if( cache == NULL )  | 
46  | 0  |   { | 
47  | 0  |     libcerror_error_set(  | 
48  | 0  |      error,  | 
49  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
50  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
51  | 0  |      "%s: invalid cache.",  | 
52  | 0  |      function );  | 
53  |  | 
  | 
54  | 0  |     return( -1 );  | 
55  | 0  |   }  | 
56  | 270k  |   if( *cache != NULL )  | 
57  | 0  |   { | 
58  | 0  |     libcerror_error_set(  | 
59  | 0  |      error,  | 
60  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
61  | 0  |      LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,  | 
62  | 0  |      "%s: invalid cache value already set.",  | 
63  | 0  |      function );  | 
64  |  | 
  | 
65  | 0  |     return( -1 );  | 
66  | 0  |   }  | 
67  | 270k  |   if( maximum_cache_entries <= 0 )  | 
68  | 0  |   { | 
69  | 0  |     libcerror_error_set(  | 
70  | 0  |      error,  | 
71  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
72  | 0  |      LIBCERROR_ARGUMENT_ERROR_VALUE_ZERO_OR_LESS,  | 
73  | 0  |      "%s: invalid maximum cache entries value zero or less.",  | 
74  | 0  |      function );  | 
75  |  | 
  | 
76  | 0  |     return( -1 );  | 
77  | 0  |   }  | 
78  | 270k  |   internal_cache = memory_allocate_structure(  | 
79  | 270k  |                     libfcache_internal_cache_t );  | 
80  |  |  | 
81  | 270k  |   if( internal_cache == NULL )  | 
82  | 0  |   { | 
83  | 0  |     libcerror_error_set(  | 
84  | 0  |      error,  | 
85  | 0  |      LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
86  | 0  |      LIBCERROR_MEMORY_ERROR_INSUFFICIENT,  | 
87  | 0  |      "%s: unable to create cache.",  | 
88  | 0  |      function );  | 
89  |  | 
  | 
90  | 0  |     goto on_error;  | 
91  | 0  |   }  | 
92  | 270k  |   if( memory_set(  | 
93  | 270k  |        internal_cache,  | 
94  | 270k  |        0,  | 
95  | 270k  |        sizeof( libfcache_internal_cache_t ) ) == NULL )  | 
96  | 0  |   { | 
97  | 0  |     libcerror_error_set(  | 
98  | 0  |      error,  | 
99  | 0  |      LIBCERROR_ERROR_DOMAIN_MEMORY,  | 
100  | 0  |      LIBCERROR_MEMORY_ERROR_SET_FAILED,  | 
101  | 0  |      "%s: unable to clear cache.",  | 
102  | 0  |      function );  | 
103  |  | 
  | 
104  | 0  |     memory_free(  | 
105  | 0  |      internal_cache );  | 
106  |  | 
  | 
107  | 0  |     return( -1 );  | 
108  | 0  |   }  | 
109  | 270k  |   if( libcdata_array_initialize(  | 
110  | 270k  |        &( internal_cache->entries_array ),  | 
111  | 270k  |        maximum_cache_entries,  | 
112  | 270k  |        error ) != 1 )  | 
113  | 0  |   { | 
114  | 0  |     libcerror_error_set(  | 
115  | 0  |      error,  | 
116  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
117  | 0  |      LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,  | 
118  | 0  |      "%s: unable to create entries array.",  | 
119  | 0  |      function );  | 
120  |  | 
  | 
121  | 0  |     goto on_error;  | 
122  | 0  |   }  | 
123  | 270k  |   if( libcdata_list_initialize(  | 
124  | 270k  |        &( internal_cache->entries_list ),  | 
125  | 270k  |        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 entries list.",  | 
132  | 0  |      function );  | 
133  |  | 
  | 
134  | 0  |     goto on_error;  | 
135  | 0  |   }  | 
136  | 270k  |   *cache = (libfcache_cache_t *) internal_cache;  | 
137  |  |  | 
138  | 270k  |   return( 1 );  | 
139  |  |  | 
140  | 0  | on_error:  | 
141  | 0  |   if( internal_cache != NULL )  | 
142  | 0  |   { | 
143  | 0  |     if( internal_cache->entries_array != NULL )  | 
144  | 0  |     { | 
145  | 0  |       libcdata_array_free(  | 
146  | 0  |        &( internal_cache->entries_array ),  | 
147  | 0  |        NULL,  | 
148  | 0  |        NULL );  | 
149  | 0  |     }  | 
150  | 0  |     memory_free(  | 
151  | 0  |      internal_cache );  | 
152  | 0  |   }  | 
153  | 0  |   return( -1 );  | 
154  | 270k  | }  | 
155  |  |  | 
156  |  | /* Frees a cache  | 
157  |  |  * Returns 1 if successful or -1 on error  | 
158  |  |  */  | 
159  |  | int libfcache_cache_free(  | 
160  |  |      libfcache_cache_t **cache,  | 
161  |  |      libcerror_error_t **error )  | 
162  | 270k  | { | 
163  | 270k  |   libfcache_internal_cache_t *internal_cache = NULL;  | 
164  | 270k  |   static char *function                      = "libfcache_cache_free";  | 
165  | 270k  |   int result                                 = 1;  | 
166  |  |  | 
167  | 270k  |   if( cache == NULL )  | 
168  | 0  |   { | 
169  | 0  |     libcerror_error_set(  | 
170  | 0  |      error,  | 
171  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
172  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
173  | 0  |      "%s: invalid cache.",  | 
174  | 0  |      function );  | 
175  |  | 
  | 
176  | 0  |     return( -1 );  | 
177  | 0  |   }  | 
178  | 270k  |   if( *cache != NULL )  | 
179  | 270k  |   { | 
180  | 270k  |     internal_cache = (libfcache_internal_cache_t *) *cache;  | 
181  | 270k  |     *cache         = NULL;  | 
182  |  |  | 
183  | 270k  |     if( libcdata_list_free(  | 
184  | 270k  |          &( internal_cache->entries_list ),  | 
185  | 270k  |          NULL,  | 
186  | 270k  |          error ) != 1 )  | 
187  | 0  |     { | 
188  | 0  |       libcerror_error_set(  | 
189  | 0  |        error,  | 
190  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
191  | 0  |        LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,  | 
192  | 0  |        "%s: unable to free the entries list.",  | 
193  | 0  |        function );  | 
194  |  | 
  | 
195  | 0  |       result = -1;  | 
196  | 0  |     }  | 
197  | 270k  |     if( libcdata_array_free(  | 
198  | 270k  |          &( internal_cache->entries_array ),  | 
199  | 270k  |          (int (*)(intptr_t **, libcerror_error_t **)) &libfcache_cache_value_free,  | 
200  | 270k  |          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 the entries array.",  | 
207  | 0  |        function );  | 
208  |  | 
  | 
209  | 0  |       result = -1;  | 
210  | 0  |     }  | 
211  | 270k  |     memory_free(  | 
212  | 270k  |      internal_cache );  | 
213  | 270k  |   }  | 
214  | 270k  |   return( result );  | 
215  | 270k  | }  | 
216  |  |  | 
217  |  | /* Empties the cache  | 
218  |  |  * Returns 1 if successful or -1 on error  | 
219  |  |  */  | 
220  |  | int libfcache_cache_empty(  | 
221  |  |      libfcache_cache_t *cache,  | 
222  |  |      libcerror_error_t **error )  | 
223  | 7.93k  | { | 
224  | 7.93k  |   libfcache_internal_cache_t *internal_cache = NULL;  | 
225  | 7.93k  |   static char *function                      = "libfcache_cache_empty";  | 
226  |  |  | 
227  | 7.93k  |   if( cache == NULL )  | 
228  | 0  |   { | 
229  | 0  |     libcerror_error_set(  | 
230  | 0  |      error,  | 
231  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
232  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
233  | 0  |      "%s: invalid cache.",  | 
234  | 0  |      function );  | 
235  |  | 
  | 
236  | 0  |     return( -1 );  | 
237  | 0  |   }  | 
238  | 7.93k  |   internal_cache = (libfcache_internal_cache_t *) cache;  | 
239  |  |  | 
240  | 7.93k  |   if( libcdata_list_empty(  | 
241  | 7.93k  |        internal_cache->entries_list,  | 
242  | 7.93k  |        NULL,  | 
243  | 7.93k  |        error ) != 1 )  | 
244  | 0  |   { | 
245  | 0  |     libcerror_error_set(  | 
246  | 0  |      error,  | 
247  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
248  | 0  |      LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,  | 
249  | 0  |      "%s: unable to empty entries list.",  | 
250  | 0  |      function );  | 
251  |  | 
  | 
252  | 0  |     return( -1 );  | 
253  | 0  |   }  | 
254  | 7.93k  |   if( libcdata_array_clear(  | 
255  | 7.93k  |        internal_cache->entries_array,  | 
256  | 7.93k  |        (int (*)(intptr_t **, libcerror_error_t **)) &libfcache_cache_value_free,  | 
257  | 7.93k  |        error ) != 1 )  | 
258  | 0  |   { | 
259  | 0  |     libcerror_error_set(  | 
260  | 0  |      error,  | 
261  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
262  | 0  |      LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,  | 
263  | 0  |      "%s: unable to clear entries array.",  | 
264  | 0  |      function );  | 
265  |  | 
  | 
266  | 0  |     return( -1 );  | 
267  | 0  |   }  | 
268  | 7.93k  |   internal_cache->number_of_cache_values = 0;  | 
269  |  |  | 
270  | 7.93k  |   return( 1 );  | 
271  | 7.93k  | }  | 
272  |  |  | 
273  |  | /* Clones (duplicates) the cache, not the cache values  | 
274  |  |  * Returns 1 if successful or -1 on error  | 
275  |  |  */  | 
276  |  | int libfcache_cache_clone(  | 
277  |  |      libfcache_cache_t **destination_cache,  | 
278  |  |      libfcache_cache_t *source_cache,  | 
279  |  |      libcerror_error_t **error )  | 
280  | 0  | { | 
281  | 0  |   libfcache_internal_cache_t *internal_source_cache = NULL;  | 
282  | 0  |   static char *function                             = "libfcache_cache_clone";  | 
283  | 0  |   int number_of_cache_entries                       = 0;  | 
284  |  | 
  | 
285  | 0  |   if( destination_cache == NULL )  | 
286  | 0  |   { | 
287  | 0  |     libcerror_error_set(  | 
288  | 0  |      error,  | 
289  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
290  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
291  | 0  |      "%s: invalid destination cache.",  | 
292  | 0  |      function );  | 
293  |  | 
  | 
294  | 0  |     return( -1 );  | 
295  | 0  |   }  | 
296  | 0  |   if( *destination_cache != NULL )  | 
297  | 0  |   { | 
298  | 0  |     libcerror_error_set(  | 
299  | 0  |      error,  | 
300  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
301  | 0  |      LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,  | 
302  | 0  |      "%s: destination cache already set.",  | 
303  | 0  |      function );  | 
304  |  | 
  | 
305  | 0  |     return( -1 );  | 
306  | 0  |   }  | 
307  | 0  |   if( source_cache == NULL )  | 
308  | 0  |   { | 
309  | 0  |     *destination_cache = NULL;  | 
310  |  | 
  | 
311  | 0  |     return( 1 );  | 
312  | 0  |   }  | 
313  | 0  |   internal_source_cache = (libfcache_internal_cache_t *) source_cache;  | 
314  |  | 
  | 
315  | 0  |   if( libcdata_array_get_number_of_entries(  | 
316  | 0  |        internal_source_cache->entries_array,  | 
317  | 0  |        &number_of_cache_entries,  | 
318  | 0  |        error ) != 1 )  | 
319  | 0  |   { | 
320  | 0  |     libcerror_error_set(  | 
321  | 0  |      error,  | 
322  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
323  | 0  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
324  | 0  |      "%s: unable to retrieve number of cache entries from source entries array.",  | 
325  | 0  |      function );  | 
326  |  | 
  | 
327  | 0  |     return( -1 );  | 
328  | 0  |   }  | 
329  | 0  |   if( libfcache_cache_initialize(  | 
330  | 0  |        destination_cache,  | 
331  | 0  |        number_of_cache_entries,  | 
332  | 0  |        error ) != 1 )  | 
333  | 0  |   { | 
334  | 0  |     libcerror_error_set(  | 
335  | 0  |      error,  | 
336  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
337  | 0  |      LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,  | 
338  | 0  |      "%s: unable to create destination cache.",  | 
339  | 0  |      function );  | 
340  |  | 
  | 
341  | 0  |     return( -1 );  | 
342  | 0  |   }  | 
343  | 0  |   return( 1 );  | 
344  | 0  | }  | 
345  |  |  | 
346  |  | /* Resizes the cache  | 
347  |  |  * Returns 1 if successful or -1 on error  | 
348  |  |  */  | 
349  |  | int libfcache_cache_resize(  | 
350  |  |      libfcache_cache_t *cache,  | 
351  |  |      int maximum_cache_entries,  | 
352  |  |      libcerror_error_t **error )  | 
353  | 0  | { | 
354  | 0  |   libfcache_internal_cache_t *internal_cache = NULL;  | 
355  | 0  |   static char *function                      = "libfcache_cache_resize";  | 
356  |  | 
  | 
357  | 0  |   if( cache == NULL )  | 
358  | 0  |   { | 
359  | 0  |     libcerror_error_set(  | 
360  | 0  |      error,  | 
361  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
362  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
363  | 0  |      "%s: invalid cache.",  | 
364  | 0  |      function );  | 
365  |  | 
  | 
366  | 0  |     return( -1 );  | 
367  | 0  |   }  | 
368  | 0  |   internal_cache = (libfcache_internal_cache_t *) cache;  | 
369  |  | 
  | 
370  | 0  |   if( libcdata_array_resize(  | 
371  | 0  |        internal_cache->entries_array,  | 
372  | 0  |        maximum_cache_entries,  | 
373  | 0  |        (int (*)(intptr_t **, libcerror_error_t **)) &libfcache_cache_value_free,  | 
374  | 0  |        error ) != 1 )  | 
375  | 0  |   { | 
376  | 0  |     libcerror_error_set(  | 
377  | 0  |      error,  | 
378  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
379  | 0  |      LIBCERROR_RUNTIME_ERROR_RESIZE_FAILED,  | 
380  | 0  |      "%s: unable to resize entries array.",  | 
381  | 0  |      function );  | 
382  |  | 
  | 
383  | 0  |     return( -1 );  | 
384  | 0  |   }  | 
385  | 0  |   return( 1 );  | 
386  | 0  | }  | 
387  |  |  | 
388  |  | /* Retrieves the number of entries of the cache  | 
389  |  |  * Returns 1 if successful or -1 on error  | 
390  |  |  */  | 
391  |  | int libfcache_cache_get_number_of_entries(  | 
392  |  |      libfcache_cache_t *cache,  | 
393  |  |      int *number_of_entries,  | 
394  |  |      libcerror_error_t **error )  | 
395  | 37.7k  | { | 
396  | 37.7k  |   libfcache_internal_cache_t *internal_cache = NULL;  | 
397  | 37.7k  |   static char *function                      = "libfcache_cache_get_number_of_entries";  | 
398  |  |  | 
399  | 37.7k  |   if( cache == NULL )  | 
400  | 0  |   { | 
401  | 0  |     libcerror_error_set(  | 
402  | 0  |      error,  | 
403  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
404  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
405  | 0  |      "%s: invalid cache.",  | 
406  | 0  |      function );  | 
407  |  | 
  | 
408  | 0  |     return( -1 );  | 
409  | 0  |   }  | 
410  | 37.7k  |   internal_cache = (libfcache_internal_cache_t *) cache;  | 
411  |  |  | 
412  | 37.7k  |   if( libcdata_array_get_number_of_entries(  | 
413  | 37.7k  |        internal_cache->entries_array,  | 
414  | 37.7k  |        number_of_entries,  | 
415  | 37.7k  |        error ) != 1 )  | 
416  | 0  |   { | 
417  | 0  |     libcerror_error_set(  | 
418  | 0  |      error,  | 
419  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
420  | 0  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
421  | 0  |      "%s: unable to retrieve number of entries from entries array.",  | 
422  | 0  |      function );  | 
423  |  | 
  | 
424  | 0  |     return( -1 );  | 
425  | 0  |   }  | 
426  | 37.7k  |   return( 1 );  | 
427  | 37.7k  | }  | 
428  |  |  | 
429  |  | /* Retrieves the number of cache values  | 
430  |  |  * Returns 1 if successful or -1 on error  | 
431  |  |  */  | 
432  |  | int libfcache_cache_get_number_of_cache_values(  | 
433  |  |      libfcache_cache_t *cache,  | 
434  |  |      int *number_of_cache_values,  | 
435  |  |      libcerror_error_t **error )  | 
436  | 0  | { | 
437  | 0  |   libfcache_internal_cache_t *internal_cache = NULL;  | 
438  | 0  |   static char *function                      = "libfcache_cache_get_number_of_cache_values";  | 
439  |  | 
  | 
440  | 0  |   if( cache == NULL )  | 
441  | 0  |   { | 
442  | 0  |     libcerror_error_set(  | 
443  | 0  |      error,  | 
444  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
445  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
446  | 0  |      "%s: invalid cache.",  | 
447  | 0  |      function );  | 
448  |  | 
  | 
449  | 0  |     return( -1 );  | 
450  | 0  |   }  | 
451  | 0  |   internal_cache = (libfcache_internal_cache_t *) cache;  | 
452  |  | 
  | 
453  | 0  |   if( libcdata_list_get_number_of_elements(  | 
454  | 0  |        internal_cache->entries_list,  | 
455  | 0  |        number_of_cache_values,  | 
456  | 0  |        error ) != 1 )  | 
457  | 0  |   { | 
458  | 0  |     libcerror_error_set(  | 
459  | 0  |      error,  | 
460  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
461  | 0  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
462  | 0  |      "%s: unable to retrieve number of elements from entries list.",  | 
463  | 0  |      function );  | 
464  |  | 
  | 
465  | 0  |     return( -1 );  | 
466  | 0  |   }  | 
467  | 0  |   return( 1 );  | 
468  | 0  | }  | 
469  |  |  | 
470  |  | /* Clears the cache value for the specific index  | 
471  |  |  * Returns 1 if successful or -1 on error  | 
472  |  |  */  | 
473  |  | int libfcache_cache_clear_value_by_index(  | 
474  |  |      libfcache_cache_t *cache,  | 
475  |  |      int cache_entry_index,  | 
476  |  |      libcerror_error_t **error )  | 
477  | 2.01k  | { | 
478  | 2.01k  |   libfcache_cache_value_t *cache_value       = NULL;  | 
479  | 2.01k  |   libfcache_internal_cache_t *internal_cache = NULL;  | 
480  | 2.01k  |   static char *function                      = "libfcache_cache_clear_value_by_index";  | 
481  |  |  | 
482  | 2.01k  |   if( cache == NULL )  | 
483  | 0  |   { | 
484  | 0  |     libcerror_error_set(  | 
485  | 0  |      error,  | 
486  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
487  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
488  | 0  |      "%s: invalid cache.",  | 
489  | 0  |      function );  | 
490  |  | 
  | 
491  | 0  |     return( -1 );  | 
492  | 0  |   }  | 
493  | 2.01k  |   internal_cache = (libfcache_internal_cache_t *) cache;  | 
494  |  |  | 
495  | 2.01k  |   if( libcdata_array_get_entry_by_index(  | 
496  | 2.01k  |        internal_cache->entries_array,  | 
497  | 2.01k  |        cache_entry_index,  | 
498  | 2.01k  |        (intptr_t **) &cache_value,  | 
499  | 2.01k  |        error ) != 1 )  | 
500  | 0  |   { | 
501  | 0  |     libcerror_error_set(  | 
502  | 0  |      error,  | 
503  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
504  | 0  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
505  | 0  |      "%s: unable to retrieve cache value: %d from entries array.",  | 
506  | 0  |      function,  | 
507  | 0  |      cache_entry_index );  | 
508  |  | 
  | 
509  | 0  |     return( -1 );  | 
510  | 0  |   }  | 
511  | 2.01k  |   if( libfcache_cache_value_clear(  | 
512  | 2.01k  |        cache_value,  | 
513  | 2.01k  |        error ) != 1 )  | 
514  | 0  |   { | 
515  | 0  |     libcerror_error_set(  | 
516  | 0  |      error,  | 
517  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
518  | 0  |      LIBCERROR_RUNTIME_ERROR_SET_FAILED,  | 
519  | 0  |      "%s: unable to clear cache value.",  | 
520  | 0  |      function );  | 
521  |  | 
  | 
522  | 0  |     return( -1 );  | 
523  | 0  |   }  | 
524  | 2.01k  |   return( 1 );  | 
525  | 2.01k  | }  | 
526  |  |  | 
527  |  | /* Retrieves the cache value that matches the file index, offset and timestamp  | 
528  |  |  * Returns 1 if successful, 0 if no such value or -1 on error  | 
529  |  |  */  | 
530  |  | int libfcache_cache_get_value_by_identifier(  | 
531  |  |      libfcache_cache_t *cache,  | 
532  |  |      int file_index,  | 
533  |  |      off64_t offset,  | 
534  |  |      int64_t timestamp,  | 
535  |  |      libfcache_cache_value_t **cache_value,  | 
536  |  |      libcerror_error_t **error )  | 
537  | 1.33M  | { | 
538  | 1.33M  |   libcdata_list_element_t *list_element      = NULL;  | 
539  | 1.33M  |   libfcache_cache_value_t *safe_cache_value  = NULL;  | 
540  | 1.33M  |   libfcache_internal_cache_t *internal_cache = NULL;  | 
541  | 1.33M  |   static char *function                      = "libfcache_cache_get_value_by_identifier";  | 
542  | 1.33M  |   off64_t cache_value_offset                 = 0;  | 
543  | 1.33M  |   int64_t cache_value_timestamp              = 0;  | 
544  | 1.33M  |   int cache_value_file_index                 = 0;  | 
545  | 1.33M  |   int number_of_cache_values                 = 0;  | 
546  | 1.33M  |   int result                                 = 0;  | 
547  |  |  | 
548  | 1.33M  |   if( cache == NULL )  | 
549  | 0  |   { | 
550  | 0  |     libcerror_error_set(  | 
551  | 0  |      error,  | 
552  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
553  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
554  | 0  |      "%s: invalid cache.",  | 
555  | 0  |      function );  | 
556  |  | 
  | 
557  | 0  |     return( -1 );  | 
558  | 0  |   }  | 
559  | 1.33M  |   internal_cache = (libfcache_internal_cache_t *) cache;  | 
560  |  |  | 
561  | 1.33M  |   if( cache_value == NULL )  | 
562  | 0  |   { | 
563  | 0  |     libcerror_error_set(  | 
564  | 0  |      error,  | 
565  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
566  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
567  | 0  |      "%s: invalid cache value.",  | 
568  | 0  |      function );  | 
569  |  | 
  | 
570  | 0  |     return( -1 );  | 
571  | 0  |   }  | 
572  | 1.33M  |   *cache_value = NULL;  | 
573  |  |  | 
574  | 1.33M  |   if( libcdata_list_get_number_of_elements(  | 
575  | 1.33M  |        internal_cache->entries_list,  | 
576  | 1.33M  |        &number_of_cache_values,  | 
577  | 1.33M  |        error ) != 1 )  | 
578  | 0  |   { | 
579  | 0  |     libcerror_error_set(  | 
580  | 0  |      error,  | 
581  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
582  | 0  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
583  | 0  |      "%s: unable to retrieve number of elements from entries list.",  | 
584  | 0  |      function );  | 
585  |  | 
  | 
586  | 0  |     return( -1 );  | 
587  | 0  |   }  | 
588  | 1.33M  |   if( libcdata_list_get_first_element(  | 
589  | 1.33M  |        internal_cache->entries_list,  | 
590  | 1.33M  |        &list_element,  | 
591  | 1.33M  |        error ) != 1 )  | 
592  | 0  |   { | 
593  | 0  |     libcerror_error_set(  | 
594  | 0  |      error,  | 
595  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
596  | 0  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
597  | 0  |      "%s: unable to retrieve first list element.",  | 
598  | 0  |      function );  | 
599  |  | 
  | 
600  | 0  |     return( -1 );  | 
601  | 0  |   }  | 
602  | 2.74M  |   while( list_element != NULL )  | 
603  | 2.55M  |   { | 
604  | 2.55M  |     if( libcdata_list_element_get_value(  | 
605  | 2.55M  |          list_element,  | 
606  | 2.55M  |          (intptr_t **) &safe_cache_value,  | 
607  | 2.55M  |          error ) != 1 )  | 
608  | 0  |     { | 
609  | 0  |       libcerror_error_set(  | 
610  | 0  |        error,  | 
611  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
612  | 0  |        LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
613  | 0  |        "%s: unable to retrieve cache value from list element.",  | 
614  | 0  |        function );  | 
615  |  | 
  | 
616  | 0  |       return( -1 );  | 
617  | 0  |     }  | 
618  | 2.55M  |     if( libfcache_cache_value_get_identifier(  | 
619  | 2.55M  |          safe_cache_value,  | 
620  | 2.55M  |          &cache_value_file_index,  | 
621  | 2.55M  |          &cache_value_offset,  | 
622  | 2.55M  |          &cache_value_timestamp,  | 
623  | 2.55M  |          error ) != 1 )  | 
624  | 0  |     { | 
625  | 0  |       libcerror_error_set(  | 
626  | 0  |        error,  | 
627  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
628  | 0  |        LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
629  | 0  |        "%s: unable to retrieve cache value identifier.",  | 
630  | 0  |        function );  | 
631  |  | 
  | 
632  | 0  |       return( -1 );  | 
633  | 0  |     }  | 
634  | 2.55M  |     if( ( cache_value_file_index == file_index )  | 
635  | 2.55M  |      && ( cache_value_offset == offset )  | 
636  | 2.55M  |      && ( cache_value_timestamp == timestamp ) )  | 
637  | 1.14M  |     { | 
638  | 1.14M  |       result = 1;  | 
639  |  |  | 
640  | 1.14M  |       break;  | 
641  | 1.14M  |     }  | 
642  | 1.41M  |     if( libcdata_list_element_get_next_element(  | 
643  | 1.41M  |          list_element,  | 
644  | 1.41M  |          &list_element,  | 
645  | 1.41M  |          error ) != 1 )  | 
646  | 0  |     { | 
647  | 0  |       libcerror_error_set(  | 
648  | 0  |        error,  | 
649  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
650  | 0  |        LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
651  | 0  |        "%s: unable to retrieve next list element.",  | 
652  | 0  |        function );  | 
653  |  | 
  | 
654  | 0  |       return( -1 );  | 
655  | 0  |     }  | 
656  | 1.41M  |   }  | 
657  | 1.33M  |   if( ( result != 0 )  | 
658  | 1.33M  |    && ( number_of_cache_values > 0 ) )  | 
659  | 1.14M  |   { | 
660  | 1.14M  |     if( libcdata_list_remove_element(  | 
661  | 1.14M  |          internal_cache->entries_list,  | 
662  | 1.14M  |          list_element,  | 
663  | 1.14M  |          error ) != 1 )  | 
664  | 0  |     { | 
665  | 0  |       libcerror_error_set(  | 
666  | 0  |        error,  | 
667  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
668  | 0  |        LIBCERROR_RUNTIME_ERROR_REMOVE_FAILED,  | 
669  | 0  |        "%s: unable to remove list element.",  | 
670  | 0  |        function );  | 
671  |  | 
  | 
672  | 0  |       return( -1 );  | 
673  | 0  |     }  | 
674  | 1.14M  |     if( libcdata_list_prepend_element(  | 
675  | 1.14M  |          internal_cache->entries_list,  | 
676  | 1.14M  |          list_element,  | 
677  | 1.14M  |          error ) != 1 )  | 
678  | 0  |     { | 
679  | 0  |       libcerror_error_set(  | 
680  | 0  |        error,  | 
681  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
682  | 0  |        LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,  | 
683  | 0  |        "%s: unable to prepend list element.",  | 
684  | 0  |        function );  | 
685  |  | 
  | 
686  | 0  |       return( -1 );  | 
687  | 0  |     }  | 
688  | 1.14M  |     *cache_value = safe_cache_value;  | 
689  | 1.14M  |   }  | 
690  | 1.33M  |   return( result );  | 
691  | 1.33M  | }  | 
692  |  |  | 
693  |  | /* Retrieves the cache value for the specific index  | 
694  |  |  * Returns 1 if successful or -1 on error  | 
695  |  |  */  | 
696  |  | int libfcache_cache_get_value_by_index(  | 
697  |  |      libfcache_cache_t *cache,  | 
698  |  |      int cache_entry_index,  | 
699  |  |      libfcache_cache_value_t **cache_value,  | 
700  |  |      libcerror_error_t **error )  | 
701  | 37.7k  | { | 
702  | 37.7k  |   libfcache_internal_cache_t *internal_cache = NULL;  | 
703  | 37.7k  |   static char *function                      = "libfcache_cache_get_value_by_index";  | 
704  |  |  | 
705  | 37.7k  |   if( cache == NULL )  | 
706  | 0  |   { | 
707  | 0  |     libcerror_error_set(  | 
708  | 0  |      error,  | 
709  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
710  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
711  | 0  |      "%s: invalid cache.",  | 
712  | 0  |      function );  | 
713  |  | 
  | 
714  | 0  |     return( -1 );  | 
715  | 0  |   }  | 
716  | 37.7k  |   internal_cache = (libfcache_internal_cache_t *) cache;  | 
717  |  |  | 
718  | 37.7k  |   if( libcdata_array_get_entry_by_index(  | 
719  | 37.7k  |        internal_cache->entries_array,  | 
720  | 37.7k  |        cache_entry_index,  | 
721  | 37.7k  |        (intptr_t **) cache_value,  | 
722  | 37.7k  |        error ) != 1 )  | 
723  | 0  |   { | 
724  | 0  |     libcerror_error_set(  | 
725  | 0  |      error,  | 
726  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
727  | 0  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
728  | 0  |      "%s: unable to retrieve cache value: %d from entries array.",  | 
729  | 0  |      function,  | 
730  | 0  |      cache_entry_index );  | 
731  |  | 
  | 
732  | 0  |     return( -1 );  | 
733  | 0  |   }  | 
734  | 37.7k  |   return( 1 );  | 
735  | 37.7k  | }  | 
736  |  |  | 
737  |  | /* Sets the cache value for the file index, offset and timestamp  | 
738  |  |  * Returns 1 if successful or -1 on error  | 
739  |  |  */  | 
740  |  | int libfcache_cache_set_value_by_identifier(  | 
741  |  |      libfcache_cache_t *cache,  | 
742  |  |      int file_index,  | 
743  |  |      off64_t offset,  | 
744  |  |      int64_t timestamp,  | 
745  |  |      intptr_t *value,  | 
746  |  |      int (*value_free_function)(  | 
747  |  |             intptr_t **value,  | 
748  |  |             libcerror_error_t **error ),  | 
749  |  |      uint8_t flags,  | 
750  |  |      libcerror_error_t **error )  | 
751  | 187k  | { | 
752  | 187k  |   libcdata_list_element_t *list_element      = NULL;  | 
753  | 187k  |   libfcache_cache_value_t *cache_value       = NULL;  | 
754  | 187k  |   libfcache_internal_cache_t *internal_cache = NULL;  | 
755  | 187k  |   static char *function                      = "libfcache_cache_set_value_by_identifier";  | 
756  | 187k  |   int cache_entry_index                      = 0;  | 
757  | 187k  |   int number_of_cache_entries                = 0;  | 
758  | 187k  |   int number_of_cache_values                 = 0;  | 
759  |  |  | 
760  | 187k  |   if( cache == NULL )  | 
761  | 0  |   { | 
762  | 0  |     libcerror_error_set(  | 
763  | 0  |      error,  | 
764  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
765  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
766  | 0  |      "%s: invalid cache.",  | 
767  | 0  |      function );  | 
768  |  | 
  | 
769  | 0  |     return( -1 );  | 
770  | 0  |   }  | 
771  | 187k  |   internal_cache = (libfcache_internal_cache_t *) cache;  | 
772  |  |  | 
773  | 187k  |   if( libcdata_array_get_number_of_entries(  | 
774  | 187k  |        internal_cache->entries_array,  | 
775  | 187k  |        &number_of_cache_entries,  | 
776  | 187k  |        error ) != 1 )  | 
777  | 0  |   { | 
778  | 0  |     libcerror_error_set(  | 
779  | 0  |      error,  | 
780  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
781  | 0  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
782  | 0  |      "%s: unable to retrieve number of cache entries from entries array.",  | 
783  | 0  |      function );  | 
784  |  | 
  | 
785  | 0  |     return( -1 );  | 
786  | 0  |   }  | 
787  | 187k  |   if( libcdata_list_get_number_of_elements(  | 
788  | 187k  |        internal_cache->entries_list,  | 
789  | 187k  |        &number_of_cache_values,  | 
790  | 187k  |        error ) != 1 )  | 
791  | 0  |   { | 
792  | 0  |     libcerror_error_set(  | 
793  | 0  |      error,  | 
794  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
795  | 0  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
796  | 0  |      "%s: unable to retrieve number of elements from entries list.",  | 
797  | 0  |      function );  | 
798  |  | 
  | 
799  | 0  |     return( -1 );  | 
800  | 0  |   }  | 
801  | 187k  |   if( number_of_cache_values < number_of_cache_entries )  | 
802  | 111k  |   { | 
803  | 111k  |     cache_entry_index = number_of_cache_values;  | 
804  |  |  | 
805  | 111k  |     if( libfcache_cache_value_initialize(  | 
806  | 111k  |          &cache_value,  | 
807  | 111k  |          error ) != 1 )  | 
808  | 0  |     { | 
809  | 0  |       libcerror_error_set(  | 
810  | 0  |        error,  | 
811  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
812  | 0  |        LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,  | 
813  | 0  |        "%s: unable to create cache value.",  | 
814  | 0  |        function );  | 
815  |  | 
  | 
816  | 0  |       return( -1 );  | 
817  | 0  |     }  | 
818  | 111k  |     if( libfcache_cache_value_set_cache_index(  | 
819  | 111k  |          cache_value,  | 
820  | 111k  |          cache_entry_index,  | 
821  | 111k  |          error ) != 1 )  | 
822  | 0  |     { | 
823  | 0  |       libcerror_error_set(  | 
824  | 0  |        error,  | 
825  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
826  | 0  |        LIBCERROR_RUNTIME_ERROR_SET_FAILED,  | 
827  | 0  |        "%s: unable to set cache index in cache value.",  | 
828  | 0  |        function );  | 
829  |  | 
  | 
830  | 0  |       libfcache_cache_value_free(  | 
831  | 0  |        &cache_value,  | 
832  | 0  |        NULL );  | 
833  |  | 
  | 
834  | 0  |       return( -1 );  | 
835  | 0  |     }  | 
836  | 111k  |     if( libcdata_array_set_entry_by_index(  | 
837  | 111k  |          internal_cache->entries_array,  | 
838  | 111k  |          cache_entry_index,  | 
839  | 111k  |          (intptr_t *) cache_value,  | 
840  | 111k  |          error ) != 1 )  | 
841  | 0  |     { | 
842  | 0  |       libcerror_error_set(  | 
843  | 0  |        error,  | 
844  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
845  | 0  |        LIBCERROR_RUNTIME_ERROR_SET_FAILED,  | 
846  | 0  |        "%s: unable to set cache value: %d in entries array.",  | 
847  | 0  |        function,  | 
848  | 0  |        cache_entry_index );  | 
849  |  | 
  | 
850  | 0  |       libfcache_cache_value_free(  | 
851  | 0  |        &cache_value,  | 
852  | 0  |        NULL );  | 
853  |  | 
  | 
854  | 0  |       return( -1 );  | 
855  | 0  |     }  | 
856  | 111k  |     if( libcdata_list_prepend_value(  | 
857  | 111k  |          internal_cache->entries_list,  | 
858  | 111k  |          (intptr_t *) cache_value,  | 
859  | 111k  |          error ) != 1 )  | 
860  | 0  |     { | 
861  | 0  |       libcerror_error_set(  | 
862  | 0  |        error,  | 
863  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
864  | 0  |        LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,  | 
865  | 0  |        "%s: unable to prepend cache value: %d to entries list.",  | 
866  | 0  |        function );  | 
867  |  | 
  | 
868  | 0  |       return( -1 );  | 
869  | 0  |     }  | 
870  | 111k  |   }  | 
871  | 76.1k  |   else  | 
872  | 76.1k  |   { | 
873  | 76.1k  |     if( libcdata_list_get_last_element(  | 
874  | 76.1k  |          internal_cache->entries_list,  | 
875  | 76.1k  |          &list_element,  | 
876  | 76.1k  |          error ) != 1 )  | 
877  | 0  |     { | 
878  | 0  |       libcerror_error_set(  | 
879  | 0  |        error,  | 
880  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
881  | 0  |        LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
882  | 0  |        "%s: unable to retrieve last list element.",  | 
883  | 0  |        function );  | 
884  |  | 
  | 
885  | 0  |       return( -1 );  | 
886  | 0  |     }  | 
887  | 76.1k  |     if( libcdata_list_element_get_value(  | 
888  | 76.1k  |          list_element,  | 
889  | 76.1k  |          (intptr_t **) &cache_value,  | 
890  | 76.1k  |          error ) != 1 )  | 
891  | 0  |     { | 
892  | 0  |       libcerror_error_set(  | 
893  | 0  |        error,  | 
894  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
895  | 0  |        LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
896  | 0  |        "%s: unable to retrieve cache value from list element.",  | 
897  | 0  |        function );  | 
898  |  | 
  | 
899  | 0  |       return( -1 );  | 
900  | 0  |     }  | 
901  | 76.1k  |     if( libfcache_cache_value_get_cache_index(  | 
902  | 76.1k  |          cache_value,  | 
903  | 76.1k  |          &cache_entry_index,  | 
904  | 76.1k  |          error ) != 1 )  | 
905  | 0  |     { | 
906  | 0  |       libcerror_error_set(  | 
907  | 0  |        error,  | 
908  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
909  | 0  |        LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
910  | 0  |        "%s: unable to retrieve cache index from cache value.",  | 
911  | 0  |        function );  | 
912  |  | 
  | 
913  | 0  |       return( -1 );  | 
914  | 0  |     }  | 
915  | 76.1k  |     if( libcdata_array_get_entry_by_index(  | 
916  | 76.1k  |          internal_cache->entries_array,  | 
917  | 76.1k  |          cache_entry_index,  | 
918  | 76.1k  |          (intptr_t **) &cache_value,  | 
919  | 76.1k  |          error ) != 1 )  | 
920  | 0  |     { | 
921  | 0  |       libcerror_error_set(  | 
922  | 0  |        error,  | 
923  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
924  | 0  |        LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
925  | 0  |        "%s: unable to retrieve cache value: %d from entries array.",  | 
926  | 0  |        function,  | 
927  | 0  |        cache_entry_index );  | 
928  |  | 
  | 
929  | 0  |       return( -1 );  | 
930  | 0  |     }  | 
931  | 76.1k  |   }  | 
932  | 187k  |   if( libfcache_cache_value_set_identifier(  | 
933  | 187k  |        cache_value,  | 
934  | 187k  |        file_index,  | 
935  | 187k  |        offset,  | 
936  | 187k  |        timestamp,  | 
937  | 187k  |        error ) != 1 )  | 
938  | 0  |   { | 
939  | 0  |     libcerror_error_set(  | 
940  | 0  |      error,  | 
941  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
942  | 0  |      LIBCERROR_RUNTIME_ERROR_SET_FAILED,  | 
943  | 0  |      "%s: unable to set identifier in cache value.",  | 
944  | 0  |      function );  | 
945  |  | 
  | 
946  | 0  |     return( -1 );  | 
947  | 0  |   }  | 
948  | 187k  |   if( libfcache_cache_value_set_value(  | 
949  | 187k  |        cache_value,  | 
950  | 187k  |        value,  | 
951  | 187k  |        value_free_function,  | 
952  | 187k  |        flags,  | 
953  | 187k  |        error ) != 1 )  | 
954  | 0  |   { | 
955  | 0  |     libcerror_error_set(  | 
956  | 0  |      error,  | 
957  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
958  | 0  |      LIBCERROR_RUNTIME_ERROR_SET_FAILED,  | 
959  | 0  |      "%s: unable to set value in cache value.",  | 
960  | 0  |      function );  | 
961  |  | 
  | 
962  | 0  |     return( -1 );  | 
963  | 0  |   }  | 
964  | 187k  |   return( 1 );  | 
965  | 187k  | }  | 
966  |  |  | 
967  |  | /* Sets the cache value for the specific index  | 
968  |  |  * Returns 1 if successful or -1 on error  | 
969  |  |  */  | 
970  |  | int libfcache_cache_set_value_by_index(  | 
971  |  |      libfcache_cache_t *cache,  | 
972  |  |      int cache_entry_index,  | 
973  |  |      int file_index,  | 
974  |  |      off64_t offset,  | 
975  |  |      int64_t timestamp,  | 
976  |  |      intptr_t *value,  | 
977  |  |      int (*value_free_function)(  | 
978  |  |             intptr_t **value,  | 
979  |  |             libcerror_error_t **error ),  | 
980  |  |      uint8_t flags,  | 
981  |  |      libcerror_error_t **error )  | 
982  | 15.3k  | { | 
983  | 15.3k  |   libfcache_cache_value_t *cache_value       = NULL;  | 
984  | 15.3k  |   libfcache_internal_cache_t *internal_cache = NULL;  | 
985  | 15.3k  |   static char *function                      = "libfcache_cache_set_value_by_index";  | 
986  |  |  | 
987  | 15.3k  |   if( cache == NULL )  | 
988  | 0  |   { | 
989  | 0  |     libcerror_error_set(  | 
990  | 0  |      error,  | 
991  | 0  |      LIBCERROR_ERROR_DOMAIN_ARGUMENTS,  | 
992  | 0  |      LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,  | 
993  | 0  |      "%s: invalid cache.",  | 
994  | 0  |      function );  | 
995  |  | 
  | 
996  | 0  |     return( -1 );  | 
997  | 0  |   }  | 
998  | 15.3k  |   internal_cache = (libfcache_internal_cache_t *) cache;  | 
999  |  |  | 
1000  | 15.3k  |   if( libcdata_array_get_entry_by_index(  | 
1001  | 15.3k  |        internal_cache->entries_array,  | 
1002  | 15.3k  |        cache_entry_index,  | 
1003  | 15.3k  |        (intptr_t **) &cache_value,  | 
1004  | 15.3k  |        error ) != 1 )  | 
1005  | 0  |   { | 
1006  | 0  |     libcerror_error_set(  | 
1007  | 0  |      error,  | 
1008  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1009  | 0  |      LIBCERROR_RUNTIME_ERROR_GET_FAILED,  | 
1010  | 0  |      "%s: unable to retrieve cache value: %d from entries array.",  | 
1011  | 0  |      function,  | 
1012  | 0  |      cache_entry_index );  | 
1013  |  | 
  | 
1014  | 0  |     return( -1 );  | 
1015  | 0  |   }  | 
1016  | 15.3k  |   if( cache_value == NULL )  | 
1017  | 15.0k  |   { | 
1018  | 15.0k  |     if( libfcache_cache_value_initialize(  | 
1019  | 15.0k  |          &cache_value,  | 
1020  | 15.0k  |          error ) != 1 )  | 
1021  | 0  |     { | 
1022  | 0  |       libcerror_error_set(  | 
1023  | 0  |        error,  | 
1024  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1025  | 0  |        LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,  | 
1026  | 0  |        "%s: unable to create cache value.",  | 
1027  | 0  |        function );  | 
1028  |  | 
  | 
1029  | 0  |       return( -1 );  | 
1030  | 0  |     }  | 
1031  | 15.0k  |     if( libfcache_cache_value_set_cache_index(  | 
1032  | 15.0k  |          cache_value,  | 
1033  | 15.0k  |          cache_entry_index,  | 
1034  | 15.0k  |          error ) != 1 )  | 
1035  | 0  |     { | 
1036  | 0  |       libcerror_error_set(  | 
1037  | 0  |        error,  | 
1038  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1039  | 0  |        LIBCERROR_RUNTIME_ERROR_SET_FAILED,  | 
1040  | 0  |        "%s: unable to set cache index in cache value.",  | 
1041  | 0  |        function );  | 
1042  |  | 
  | 
1043  | 0  |       libfcache_cache_value_free(  | 
1044  | 0  |        &cache_value,  | 
1045  | 0  |        NULL );  | 
1046  |  | 
  | 
1047  | 0  |       return( -1 );  | 
1048  | 0  |     }  | 
1049  | 15.0k  |     if( libcdata_array_set_entry_by_index(  | 
1050  | 15.0k  |          internal_cache->entries_array,  | 
1051  | 15.0k  |          cache_entry_index,  | 
1052  | 15.0k  |          (intptr_t *) cache_value,  | 
1053  | 15.0k  |          error ) != 1 )  | 
1054  | 0  |     { | 
1055  | 0  |       libcerror_error_set(  | 
1056  | 0  |        error,  | 
1057  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1058  | 0  |        LIBCERROR_RUNTIME_ERROR_SET_FAILED,  | 
1059  | 0  |        "%s: unable to set cache value: %d in entries array.",  | 
1060  | 0  |        function,  | 
1061  | 0  |        cache_entry_index );  | 
1062  |  | 
  | 
1063  | 0  |       libfcache_cache_value_free(  | 
1064  | 0  |        &cache_value,  | 
1065  | 0  |        NULL );  | 
1066  |  | 
  | 
1067  | 0  |       return( -1 );  | 
1068  | 0  |     }  | 
1069  | 15.0k  |     if( libcdata_list_prepend_value(  | 
1070  | 15.0k  |          internal_cache->entries_list,  | 
1071  | 15.0k  |          (intptr_t *) cache_value,  | 
1072  | 15.0k  |          error ) != 1 )  | 
1073  | 0  |     { | 
1074  | 0  |       libcerror_error_set(  | 
1075  | 0  |        error,  | 
1076  | 0  |        LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1077  | 0  |        LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,  | 
1078  | 0  |        "%s: unable to prepend cache value: %d to entries list.",  | 
1079  | 0  |        function );  | 
1080  |  | 
  | 
1081  | 0  |       return( -1 );  | 
1082  | 0  |     }  | 
1083  | 15.0k  |   }  | 
1084  | 15.3k  |   if( libfcache_cache_value_set_value(  | 
1085  | 15.3k  |        cache_value,  | 
1086  | 15.3k  |        value,  | 
1087  | 15.3k  |        value_free_function,  | 
1088  | 15.3k  |        flags,  | 
1089  | 15.3k  |        error ) != 1 )  | 
1090  | 0  |   { | 
1091  | 0  |     libcerror_error_set(  | 
1092  | 0  |      error,  | 
1093  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1094  | 0  |      LIBCERROR_RUNTIME_ERROR_SET_FAILED,  | 
1095  | 0  |      "%s: unable to set value in cache value.",  | 
1096  | 0  |      function );  | 
1097  |  | 
  | 
1098  | 0  |     return( -1 );  | 
1099  | 0  |   }  | 
1100  | 15.3k  |   if( libfcache_cache_value_set_identifier(  | 
1101  | 15.3k  |        cache_value,  | 
1102  | 15.3k  |        file_index,  | 
1103  | 15.3k  |        offset,  | 
1104  | 15.3k  |        timestamp,  | 
1105  | 15.3k  |        error ) != 1 )  | 
1106  | 0  |   { | 
1107  | 0  |     libcerror_error_set(  | 
1108  | 0  |      error,  | 
1109  | 0  |      LIBCERROR_ERROR_DOMAIN_RUNTIME,  | 
1110  | 0  |      LIBCERROR_RUNTIME_ERROR_SET_FAILED,  | 
1111  | 0  |      "%s: unable to set identifier in cache value.",  | 
1112  | 0  |      function );  | 
1113  |  | 
  | 
1114  | 0  |     return( -1 );  | 
1115  | 0  |   }  | 
1116  | 15.3k  |   return( 1 );  | 
1117  | 15.3k  | }  | 
1118  |  |  |