Coverage Report

Created: 2026-12-01 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfsapfs/libfsapfs/libfsapfs_attribute_values.c
Line
Count
Source
1
/*
2
 * (Extended) attribute values functions
3
 *
4
 * Copyright (C) 2018-2026, 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 <byte_stream.h>
24
#include <memory.h>
25
#include <types.h>
26
27
#include "libfsapfs_attribute_values.h"
28
#include "libfsapfs_debug.h"
29
#include "libfsapfs_file_extent.h"
30
#include "libfsapfs_libcdata.h"
31
#include "libfsapfs_libcerror.h"
32
#include "libfsapfs_libcnotify.h"
33
#include "libfsapfs_libuna.h"
34
35
#include "fsapfs_file_system.h"
36
37
/* Creates an attribute_values
38
 * Make sure the value attribute_values is referencing, is set to NULL
39
 * Returns 1 if successful or -1 on error
40
 */
41
int libfsapfs_attribute_values_initialize(
42
     libfsapfs_attribute_values_t **attribute_values,
43
     libcerror_error_t **error )
44
0
{
45
0
  static char *function = "libfsapfs_attribute_values_initialize";
46
47
0
  if( attribute_values == NULL )
48
0
  {
49
0
    libcerror_error_set(
50
0
     error,
51
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
52
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
53
0
     "%s: invalid attribute values.",
54
0
     function );
55
56
0
    return( -1 );
57
0
  }
58
0
  if( *attribute_values != NULL )
59
0
  {
60
0
    libcerror_error_set(
61
0
     error,
62
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
63
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
64
0
     "%s: invalid attribute values value already set.",
65
0
     function );
66
67
0
    return( -1 );
68
0
  }
69
0
  *attribute_values = memory_allocate_structure(
70
0
                       libfsapfs_attribute_values_t );
71
72
0
  if( *attribute_values == NULL )
73
0
  {
74
0
    libcerror_error_set(
75
0
     error,
76
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
77
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
78
0
     "%s: unable to create attribute values.",
79
0
     function );
80
81
0
    goto on_error;
82
0
  }
83
0
  if( memory_set(
84
0
       *attribute_values,
85
0
       0,
86
0
       sizeof( libfsapfs_attribute_values_t ) ) == NULL )
87
0
  {
88
0
    libcerror_error_set(
89
0
     error,
90
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
91
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
92
0
     "%s: unable to clear attribute values.",
93
0
     function );
94
95
0
    memory_free(
96
0
     attribute_values );
97
98
0
    return( -1 );
99
0
  }
100
0
  return( 1 );
101
102
0
on_error:
103
0
  if( *attribute_values != NULL )
104
0
  {
105
0
    memory_free(
106
0
     *attribute_values );
107
108
0
    *attribute_values = NULL;
109
0
  }
110
0
  return( -1 );
111
0
}
112
113
/* Frees an attribute values
114
 * Returns 1 if successful or -1 on error
115
 */
116
int libfsapfs_attribute_values_free(
117
     libfsapfs_attribute_values_t **attribute_values,
118
     libcerror_error_t **error )
119
0
{
120
0
  static char *function = "libfsapfs_attribute_values_free";
121
0
  int result            = 1;
122
123
0
  if( attribute_values == NULL )
124
0
  {
125
0
    libcerror_error_set(
126
0
     error,
127
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
128
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
129
0
     "%s: invalid attribute values.",
130
0
     function );
131
132
0
    return( -1 );
133
0
  }
134
0
  if( *attribute_values != NULL )
135
0
  {
136
0
    if( ( *attribute_values )->value_data_file_extents != NULL )
137
0
    {
138
0
      if( libcdata_array_free(
139
0
           &( ( *attribute_values )->value_data_file_extents ),
140
0
           (int (*)(intptr_t **, libcerror_error_t **)) &libfsapfs_file_extent_free,
141
0
           error ) != 1 )
142
0
      {
143
0
        libcerror_error_set(
144
0
         error,
145
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
146
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
147
0
         "%s: unable to free value data file extents array.",
148
0
         function );
149
150
0
        result = -1;
151
0
      }
152
0
    }
153
0
    if( ( *attribute_values )->value_data != NULL )
154
0
    {
155
0
      memory_free(
156
0
       ( *attribute_values )->value_data );
157
0
    }
158
0
    if( ( *attribute_values )->name != NULL )
159
0
    {
160
0
      memory_free(
161
0
       ( *attribute_values )->name );
162
0
    }
163
0
    memory_free(
164
0
     *attribute_values );
165
166
0
    *attribute_values = NULL;
167
0
  }
168
0
  return( result );
169
0
}
170
171
/* Reads the attribute values key data
172
 * Returns 1 if successful or -1 on error
173
 */
174
int libfsapfs_attribute_values_read_key_data(
175
     libfsapfs_attribute_values_t *attribute_values,
176
     const uint8_t *data,
177
     size_t data_size,
178
     libcerror_error_t **error )
179
0
{
180
0
  static char *function = "libfsapfs_attribute_values_read_key_data";
181
0
  size_t data_offset    = 0;
182
0
  uint16_t name_size    = 0;
183
184
#if defined( HAVE_DEBUG_OUTPUT )
185
  uint64_t value_64bit  = 0;
186
#endif
187
188
0
  if( attribute_values == NULL )
189
0
  {
190
0
    libcerror_error_set(
191
0
     error,
192
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
193
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
194
0
     "%s: invalid attribute values.",
195
0
     function );
196
197
0
    return( -1 );
198
0
  }
199
0
  if( attribute_values->name != NULL )
200
0
  {
201
0
    libcerror_error_set(
202
0
     error,
203
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
204
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
205
0
     "%s: invalid attribute values - name value already set.",
206
0
     function );
207
208
0
    return( -1 );
209
0
  }
210
0
  if( data == NULL )
211
0
  {
212
0
    libcerror_error_set(
213
0
     error,
214
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
215
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
216
0
     "%s: invalid data.",
217
0
     function );
218
219
0
    return( -1 );
220
0
  }
221
0
  if( ( data_size < sizeof( fsapfs_file_system_btree_key_extended_attribute_t ) )
222
0
   || ( data_size > (size_t) SSIZE_MAX ) )
223
0
  {
224
0
    libcerror_error_set(
225
0
     error,
226
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
227
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
228
0
     "%s: invalid data size value out of bounds.",
229
0
     function );
230
231
0
    return( -1 );
232
0
  }
233
#if defined( HAVE_DEBUG_OUTPUT )
234
  if( libcnotify_verbose != 0 )
235
  {
236
    libcnotify_printf(
237
     "%s: attribute values key data:\n",
238
     function );
239
    libcnotify_print_data(
240
     data,
241
     data_size,
242
     LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
243
  }
244
#endif
245
0
  byte_stream_copy_to_uint16_little_endian(
246
0
   ( (fsapfs_file_system_btree_key_extended_attribute_t *) data )->name_size,
247
0
   name_size );
248
249
#if defined( HAVE_DEBUG_OUTPUT )
250
  if( libcnotify_verbose != 0 )
251
  {
252
    byte_stream_copy_to_uint64_little_endian(
253
     ( (fsapfs_file_system_btree_key_extended_attribute_t *) data )->file_system_identifier,
254
     value_64bit );
255
    libcnotify_printf(
256
     "%s: parent identifier\t\t: 0x%08" PRIx64 "\n",
257
     function,
258
     value_64bit );
259
260
    libcnotify_printf(
261
     "%s: name size\t\t\t: %" PRIu16 "\n",
262
     function,
263
     name_size );
264
  }
265
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
266
267
0
  data_offset = sizeof( fsapfs_file_system_btree_key_extended_attribute_t );
268
269
0
  if( ( name_size == 0 )
270
0
   || ( (size_t) name_size > ( data_size - data_offset ) ) )
271
0
  {
272
0
    libcerror_error_set(
273
0
     error,
274
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
275
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
276
0
     "%s: invalid name size value out of bounds.",
277
0
     function );
278
279
0
    goto on_error;
280
0
  }
281
#if defined( HAVE_DEBUG_OUTPUT )
282
  if( libcnotify_verbose != 0 )
283
  {
284
    libcnotify_printf(
285
     "%s: name data:\n",
286
     function );
287
    libcnotify_print_data(
288
     &( data[ data_offset ] ),
289
     (size_t) name_size,
290
     0 );
291
  }
292
#endif
293
0
  attribute_values->name = (uint8_t *) memory_allocate(
294
0
                                        sizeof( uint8_t ) * name_size );
295
296
0
  if( attribute_values->name == NULL )
297
0
  {
298
0
    libcerror_error_set(
299
0
     error,
300
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
301
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
302
0
     "%s: unable to create name.",
303
0
     function );
304
305
0
    goto on_error;
306
0
  }
307
0
  attribute_values->name_size = name_size;
308
309
0
  if( memory_copy(
310
0
       attribute_values->name,
311
0
       &( data[ data_offset ] ),
312
0
       name_size ) == NULL )
313
0
  {
314
0
    libcerror_error_set(
315
0
     error,
316
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
317
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
318
0
     "%s: unable to copy name.",
319
0
     function );
320
321
0
    goto on_error;
322
0
  }
323
0
  return( 1 );
324
325
0
on_error:
326
0
  if( attribute_values->name != NULL )
327
0
  {
328
0
    memory_free(
329
0
     attribute_values->name );
330
331
0
    attribute_values->name = NULL;
332
0
  }
333
0
  attribute_values->name_size = 0;
334
335
0
  return( -1 );
336
0
}
337
338
/* Reads the attribute values value data
339
 * Returns 1 if successful or -1 on error
340
 */
341
int libfsapfs_attribute_values_read_value_data(
342
     libfsapfs_attribute_values_t *attribute_values,
343
     const uint8_t *data,
344
     size_t data_size,
345
     libcerror_error_t **error )
346
0
{
347
0
  const uint8_t *attribute_values_data = NULL;
348
0
  static char *function                = "libfsapfs_attribute_values_read_value_data";
349
0
  size_t data_offset                   = 0;
350
0
  uint16_t attribute_values_data_size  = 0;
351
352
#if defined( HAVE_DEBUG_OUTPUT )
353
  uint64_t value_64bit                 = 0;
354
#endif
355
356
0
  if( attribute_values == NULL )
357
0
  {
358
0
    libcerror_error_set(
359
0
     error,
360
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
361
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
362
0
     "%s: invalid attribute values.",
363
0
     function );
364
365
0
    return( -1 );
366
0
  }
367
0
  if( attribute_values->value_data != NULL )
368
0
  {
369
0
    libcerror_error_set(
370
0
     error,
371
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
372
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
373
0
     "%s: invalid attribute values - value data value already set.",
374
0
     function );
375
376
0
    return( -1 );
377
0
  }
378
0
  if( data == NULL )
379
0
  {
380
0
    libcerror_error_set(
381
0
     error,
382
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
383
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
384
0
     "%s: invalid data.",
385
0
     function );
386
387
0
    return( -1 );
388
0
  }
389
0
  if( ( data_size < sizeof( fsapfs_file_system_btree_value_extended_attribute_t ) )
390
0
   || ( data_size > (size_t) SSIZE_MAX ) )
391
0
  {
392
0
    libcerror_error_set(
393
0
     error,
394
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
395
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
396
0
     "%s: invalid data size value out of bounds.",
397
0
     function );
398
399
0
    return( -1 );
400
0
  }
401
#if defined( HAVE_DEBUG_OUTPUT )
402
  if( libcnotify_verbose != 0 )
403
  {
404
    libcnotify_printf(
405
     "%s: attribute values value data:\n",
406
     function );
407
    libcnotify_print_data(
408
     data,
409
     data_size,
410
     LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
411
  }
412
#endif
413
0
  byte_stream_copy_to_uint16_little_endian(
414
0
   ( (fsapfs_file_system_btree_value_extended_attribute_t *) data )->flags,
415
0
   attribute_values->flags );
416
417
0
  byte_stream_copy_to_uint16_little_endian(
418
0
   ( (fsapfs_file_system_btree_value_extended_attribute_t *) data )->data_size,
419
0
   attribute_values_data_size );
420
421
#if defined( HAVE_DEBUG_OUTPUT )
422
  if( libcnotify_verbose != 0 )
423
  {
424
    libcnotify_printf(
425
     "%s: flags\t\t\t: 0x%04" PRIx16 "\n",
426
     function,
427
     attribute_values->flags );
428
    libfsapfs_debug_print_extended_attribute_flags(
429
     attribute_values->flags );
430
    libcnotify_printf(
431
     "\n" );
432
433
    libcnotify_printf(
434
     "%s: data size\t\t\t: %" PRIu16 "\n",
435
     function,
436
     attribute_values_data_size );
437
438
    libcnotify_printf(
439
     "\n" );
440
  }
441
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
442
443
0
  data_offset = sizeof( fsapfs_file_system_btree_value_extended_attribute_t );
444
445
0
  if( ( attribute_values_data_size != 0 )
446
0
   && ( (size_t) attribute_values_data_size > ( data_size - data_offset ) ) )
447
0
  {
448
0
    libcerror_error_set(
449
0
     error,
450
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
451
0
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
452
0
     "%s: invalid attribute values data size value out of bounds.",
453
0
     function );
454
455
0
    goto on_error;
456
0
  }
457
0
  attribute_values_data = &( data[ data_offset ] );
458
459
#if defined( HAVE_DEBUG_OUTPUT )
460
  if( libcnotify_verbose != 0 )
461
  {
462
    libcnotify_printf(
463
     "%s: attribute values data:\n",
464
     function );
465
    libcnotify_print_data(
466
     attribute_values_data,
467
     (size_t) attribute_values_data_size,
468
     LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
469
  }
470
#endif
471
0
  if( ( attribute_values->flags & 0x0001 ) != 0 )
472
0
  {
473
0
    if( (size_t) attribute_values_data_size != sizeof( fsapfs_file_system_extended_attribute_data_stream_t ) )
474
0
    {
475
0
      libcerror_error_set(
476
0
       error,
477
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
478
0
       LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
479
0
       "%s: unsupported attribute values data size.",
480
0
       function );
481
482
0
      goto on_error;
483
0
    }
484
0
    byte_stream_copy_to_uint64_little_endian(
485
0
     ( (fsapfs_file_system_extended_attribute_data_stream_t *) attribute_values_data )->data_stream_identifier,
486
0
     attribute_values->value_data_stream_identifier );
487
488
0
    byte_stream_copy_to_uint64_little_endian(
489
0
     ( (fsapfs_file_system_extended_attribute_data_stream_t *) attribute_values_data )->used_size,
490
0
     attribute_values->value_data_size );
491
492
#if defined( HAVE_DEBUG_OUTPUT )
493
    if( libcnotify_verbose != 0 )
494
    {
495
      libcnotify_printf(
496
       "%s: data stream indentifier\t: %" PRIu64 "\n",
497
       function,
498
       attribute_values->value_data_stream_identifier );
499
500
      libcnotify_printf(
501
       "%s: used size\t\t\t: %" PRIu64 "\n",
502
       function,
503
       attribute_values->value_data_size );
504
505
      byte_stream_copy_to_uint64_little_endian(
506
       ( (fsapfs_file_system_extended_attribute_data_stream_t *) attribute_values_data )->allocated_size,
507
       value_64bit );
508
      libcnotify_printf(
509
       "%s: allocated size\t\t: %" PRIu64 "\n",
510
       function,
511
       value_64bit );
512
513
      byte_stream_copy_to_uint64_little_endian(
514
       ( (fsapfs_file_system_extended_attribute_data_stream_t *) attribute_values_data )->encryption_identifier,
515
       value_64bit );
516
      libcnotify_printf(
517
       "%s: encryption identifier\t: %" PRIu64 "\n",
518
       function,
519
       value_64bit );
520
521
      byte_stream_copy_to_uint64_little_endian(
522
       ( (fsapfs_file_system_extended_attribute_data_stream_t *) attribute_values_data )->number_of_bytes_written,
523
       value_64bit );
524
      libcnotify_printf(
525
       "%s: number of bytes written\t: %" PRIu64 "\n",
526
       function,
527
       value_64bit );
528
529
      byte_stream_copy_to_uint64_little_endian(
530
       ( (fsapfs_file_system_extended_attribute_data_stream_t *) attribute_values_data )->number_of_bytes_read,
531
       value_64bit );
532
      libcnotify_printf(
533
       "%s: number of bytes read\t: %" PRIu64 "\n",
534
       function,
535
       value_64bit );
536
537
      libcnotify_printf(
538
       "\n" );
539
    }
540
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
541
0
  }
542
0
  else if( ( ( attribute_values->flags & 0x0002 ) != 0 )
543
0
        && ( attribute_values_data_size > 0 ) )
544
0
  {
545
0
    attribute_values->value_data = (uint8_t *) memory_allocate(
546
0
                                                sizeof( uint8_t ) * attribute_values_data_size );
547
548
0
    if( attribute_values->value_data == NULL )
549
0
    {
550
0
      libcerror_error_set(
551
0
       error,
552
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
553
0
       LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
554
0
       "%s: unable to create value data.",
555
0
       function );
556
557
0
      goto on_error;
558
0
    }
559
0
    attribute_values->value_data_size = (size64_t) attribute_values_data_size;
560
561
0
    if( memory_copy(
562
0
         attribute_values->value_data,
563
0
         attribute_values_data,
564
0
         attribute_values_data_size ) == NULL )
565
0
    {
566
0
      libcerror_error_set(
567
0
       error,
568
0
       LIBCERROR_ERROR_DOMAIN_MEMORY,
569
0
       LIBCERROR_MEMORY_ERROR_COPY_FAILED,
570
0
       "%s: unable to copy data.",
571
0
       function );
572
573
0
      goto on_error;
574
0
    }
575
0
  }
576
0
  return( 1 );
577
578
0
on_error:
579
0
  if( attribute_values->value_data != NULL )
580
0
  {
581
0
    memory_free(
582
0
     attribute_values->value_data );
583
584
0
    attribute_values->value_data = NULL;
585
0
  }
586
0
  attribute_values->value_data_size = 0;
587
588
0
  return( -1 );
589
0
}
590
591
/* Compares an UTF-8 string with an attribute name
592
 * Returns LIBUNA_COMPARE_LESS, LIBUNA_COMPARE_EQUAL, LIBUNA_COMPARE_GREATER if successful or -1 on error
593
 */
594
int libfsapfs_attribute_values_compare_name_with_utf8_string(
595
     libfsapfs_attribute_values_t *attribute_values,
596
     const uint8_t *utf8_string,
597
     size_t utf8_string_length,
598
     libcerror_error_t **error )
599
0
{
600
0
  static char *function = "libfsapfs_attribute_values_compare_name_with_utf8_string";
601
0
  int result            = 0;
602
603
0
  if( attribute_values == NULL )
604
0
  {
605
0
    libcerror_error_set(
606
0
     error,
607
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
608
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
609
0
     "%s: invalid attribute values.",
610
0
     function );
611
612
0
    return( -1 );
613
0
  }
614
0
  result = libuna_utf8_string_compare_with_utf8_stream(
615
0
            utf8_string,
616
0
            utf8_string_length,
617
0
            attribute_values->name,
618
0
            attribute_values->name_size,
619
0
            error );
620
621
0
  if( result == -1 )
622
0
  {
623
0
    libcerror_error_set(
624
0
     error,
625
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
626
0
     LIBCERROR_RUNTIME_ERROR_GENERIC,
627
0
     "%s: unable to compare UTF-8 string with name.",
628
0
     function );
629
630
0
    return( -1 );
631
0
  }
632
0
  return( result );
633
0
}
634
635
/* Retrieves the size of the UTF-8 encoded name
636
 * The returned size includes the end of string character
637
 * Returns 1 if successful, 0 if not available or -1 on error
638
 */
639
int libfsapfs_attribute_values_get_utf8_name_size(
640
     libfsapfs_attribute_values_t *attribute_values,
641
     size_t *utf8_string_size,
642
     libcerror_error_t **error )
643
0
{
644
0
  static char *function = "libfsapfs_attribute_values_get_utf8_name_size";
645
646
0
  if( attribute_values == NULL )
647
0
  {
648
0
    libcerror_error_set(
649
0
     error,
650
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
651
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
652
0
     "%s: invalid attribute values.",
653
0
     function );
654
655
0
    return( -1 );
656
0
  }
657
0
  if( libuna_utf8_string_size_from_utf8_stream(
658
0
       attribute_values->name,
659
0
       (size_t) attribute_values->name_size,
660
0
       utf8_string_size,
661
0
       error ) != 1 )
662
0
  {
663
0
    libcerror_error_set(
664
0
     error,
665
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
666
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
667
0
     "%s: unable to retrieve UTF-8 string size.",
668
0
     function );
669
670
0
    return( -1 );
671
0
  }
672
0
  return( 1 );
673
0
}
674
675
/* Retrieves the UTF-8 encoded name
676
 * The size should include the end of string character
677
 * Returns 1 if successful, 0 if not available or -1 on error
678
 */
679
int libfsapfs_attribute_values_get_utf8_name(
680
     libfsapfs_attribute_values_t *attribute_values,
681
     uint8_t *utf8_string,
682
     size_t utf8_string_size,
683
     libcerror_error_t **error )
684
0
{
685
0
  static char *function = "libfsapfs_attribute_values_get_utf8_name";
686
687
0
  if( attribute_values == NULL )
688
0
  {
689
0
    libcerror_error_set(
690
0
     error,
691
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
692
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
693
0
     "%s: invalid attribute values.",
694
0
     function );
695
696
0
    return( -1 );
697
0
  }
698
0
  if( libuna_utf8_string_copy_from_utf8_stream(
699
0
       utf8_string,
700
0
       utf8_string_size,
701
0
       attribute_values->name,
702
0
       (size_t) attribute_values->name_size,
703
0
       error ) != 1 )
704
0
  {
705
0
    libcerror_error_set(
706
0
     error,
707
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
708
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
709
0
     "%s: unable to retrieve UTF-8 string.",
710
0
     function );
711
712
0
    return( -1 );
713
0
  }
714
0
  return( 1 );
715
0
}
716
717
/* Compares an UTF-16 string with an attribute name
718
 * Returns LIBUNA_COMPARE_LESS, LIBUNA_COMPARE_EQUAL, LIBUNA_COMPARE_GREATER if successful or -1 on error
719
 */
720
int libfsapfs_attribute_values_compare_name_with_utf16_string(
721
     libfsapfs_attribute_values_t *attribute_values,
722
     const uint16_t *utf16_string,
723
     size_t utf16_string_length,
724
     libcerror_error_t **error )
725
0
{
726
0
  static char *function = "libfsapfs_attribute_values_compare_name_with_utf16_string";
727
0
  int result            = 0;
728
729
0
  if( attribute_values == NULL )
730
0
  {
731
0
    libcerror_error_set(
732
0
     error,
733
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
734
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
735
0
     "%s: invalid attribute values.",
736
0
     function );
737
738
0
    return( -1 );
739
0
  }
740
0
  result = libuna_utf16_string_compare_with_utf8_stream(
741
0
            utf16_string,
742
0
            utf16_string_length,
743
0
            attribute_values->name,
744
0
            attribute_values->name_size,
745
0
            error );
746
747
0
  if( result == -1 )
748
0
  {
749
0
    libcerror_error_set(
750
0
     error,
751
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
752
0
     LIBCERROR_RUNTIME_ERROR_GENERIC,
753
0
     "%s: unable to compare UTF-16 string with name.",
754
0
     function );
755
756
0
    return( -1 );
757
0
  }
758
0
  return( result );
759
0
}
760
761
/* Retrieves the size of the UTF-16 encoded name
762
 * The returned size includes the end of string character
763
 * Returns 1 if successful, 0 if not available or -1 on error
764
 */
765
int libfsapfs_attribute_values_get_utf16_name_size(
766
     libfsapfs_attribute_values_t *attribute_values,
767
     size_t *utf16_string_size,
768
     libcerror_error_t **error )
769
0
{
770
0
  static char *function = "libfsapfs_attribute_values_get_utf16_name_size";
771
772
0
  if( attribute_values == NULL )
773
0
  {
774
0
    libcerror_error_set(
775
0
     error,
776
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
777
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
778
0
     "%s: invalid attribute values.",
779
0
     function );
780
781
0
    return( -1 );
782
0
  }
783
0
  if( libuna_utf16_string_size_from_utf8_stream(
784
0
       attribute_values->name,
785
0
       (size_t) attribute_values->name_size,
786
0
       utf16_string_size,
787
0
       error ) != 1 )
788
0
  {
789
0
    libcerror_error_set(
790
0
     error,
791
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
792
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
793
0
     "%s: unable to retrieve UTF-16 string size.",
794
0
     function );
795
796
0
    return( -1 );
797
0
  }
798
0
  return( 1 );
799
0
}
800
801
/* Retrieves the UTF-16 encoded name
802
 * The size should include the end of string character
803
 * Returns 1 if successful, 0 if not available or -1 on error
804
 */
805
int libfsapfs_attribute_values_get_utf16_name(
806
     libfsapfs_attribute_values_t *attribute_values,
807
     uint16_t *utf16_string,
808
     size_t utf16_string_size,
809
     libcerror_error_t **error )
810
0
{
811
0
  static char *function = "libfsapfs_attribute_values_get_utf16_name";
812
813
0
  if( attribute_values == NULL )
814
0
  {
815
0
    libcerror_error_set(
816
0
     error,
817
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
818
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
819
0
     "%s: invalid attribute values.",
820
0
     function );
821
822
0
    return( -1 );
823
0
  }
824
0
  if( libuna_utf16_string_copy_from_utf8_stream(
825
0
       utf16_string,
826
0
       utf16_string_size,
827
0
       attribute_values->name,
828
0
       (size_t) attribute_values->name_size,
829
0
       error ) != 1 )
830
0
  {
831
0
    libcerror_error_set(
832
0
     error,
833
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
834
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
835
0
     "%s: unable to retrieve UTF-16 string.",
836
0
     function );
837
838
0
    return( -1 );
839
0
  }
840
0
  return( 1 );
841
0
}
842
843
/* Retrieves the number of extents
844
 * Returns 1 if successful or -1 on error
845
 */
846
int libfsapfs_attribute_values_get_number_of_extents(
847
     libfsapfs_attribute_values_t *attribute_values,
848
     int *number_of_extents,
849
     libcerror_error_t **error )
850
0
{
851
0
  static char *function = "libfsapfs_attribute_values_get_number_of_extents";
852
853
0
  if( attribute_values == NULL )
854
0
  {
855
0
    libcerror_error_set(
856
0
     error,
857
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
858
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
859
0
     "%s: invalid attribute values.",
860
0
     function );
861
862
0
    return( -1 );
863
0
  }
864
0
  if( attribute_values->value_data_file_extents == NULL )
865
0
  {
866
0
    if( number_of_extents == NULL )
867
0
    {
868
0
      libcerror_error_set(
869
0
       error,
870
0
       LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
871
0
       LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
872
0
       "%s: invalid number of extents.",
873
0
       function );
874
875
0
      return( -1 );
876
0
    }
877
0
    *number_of_extents = 0;
878
0
  }
879
0
  else
880
0
  {
881
0
    if( libcdata_array_get_number_of_entries(
882
0
         attribute_values->value_data_file_extents,
883
0
         number_of_extents,
884
0
         error ) != 1 )
885
0
    {
886
0
      libcerror_error_set(
887
0
       error,
888
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
889
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
890
0
       "%s: unable to retrieve number of entries from array.",
891
0
       function );
892
893
0
      return( -1 );
894
0
    }
895
0
  }
896
0
  return( 1 );
897
0
}
898
899
/* Retrieves a specific extent
900
 * Returns 1 if successful or -1 on error
901
 */
902
int libfsapfs_attribute_values_get_extent_by_index(
903
     libfsapfs_attribute_values_t *attribute_values,
904
     int extent_index,
905
     libfsapfs_file_extent_t **file_extent,
906
     libcerror_error_t **error )
907
0
{
908
0
  static char *function = "libfsapfs_attribute_values_get_extent_by_index";
909
910
0
  if( attribute_values == NULL )
911
0
  {
912
0
    libcerror_error_set(
913
0
     error,
914
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
915
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
916
0
     "%s: invalid attribute values.",
917
0
     function );
918
919
0
    return( -1 );
920
0
  }
921
0
  if( libcdata_array_get_entry_by_index(
922
0
       attribute_values->value_data_file_extents,
923
0
       extent_index,
924
0
       (intptr_t **) file_extent,
925
0
       error ) != 1 )
926
0
  {
927
0
    libcerror_error_set(
928
0
     error,
929
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
930
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
931
0
     "%s: unable to retrieve file extent: %d.",
932
0
     function,
933
0
     extent_index );
934
935
0
    return( -1 );
936
0
  }
937
0
  return( 1 );
938
0
}
939