Coverage Report

Created: 2026-10-22 07:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libfsntfs/libfsntfs/libfsntfs_directory_entry.c
Line
Count
Source
1
/*
2
 * Directory entry functions
3
 *
4
 * Copyright (C) 2010-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 "libfsntfs_directory_entry.h"
28
#include "libfsntfs_file_name_values.h"
29
#include "libfsntfs_index_value.h"
30
#include "libfsntfs_libcdata.h"
31
#include "libfsntfs_libcerror.h"
32
#include "libfsntfs_libcnotify.h"
33
34
/* Creates a directory entry
35
 * Make sure the value directory_entry is referencing, is set to NULL
36
 * Returns 1 if successful or -1 on error
37
 */
38
int libfsntfs_directory_entry_initialize(
39
     libfsntfs_directory_entry_t **directory_entry,
40
     libcerror_error_t **error )
41
553
{
42
553
  static char *function = "libfsntfs_directory_entry_initialize";
43
44
553
  if( directory_entry == NULL )
45
0
  {
46
0
    libcerror_error_set(
47
0
     error,
48
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
49
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
50
0
     "%s: invalid directory entry.",
51
0
     function );
52
53
0
    return( -1 );
54
0
  }
55
553
  if( *directory_entry != NULL )
56
0
  {
57
0
    libcerror_error_set(
58
0
     error,
59
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
60
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
61
0
     "%s: invalid directory entry value already set.",
62
0
     function );
63
64
0
    return( -1 );
65
0
  }
66
553
  *directory_entry = memory_allocate_structure(
67
553
                      libfsntfs_directory_entry_t );
68
69
553
  if( *directory_entry == NULL )
70
0
  {
71
0
    libcerror_error_set(
72
0
     error,
73
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
74
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
75
0
     "%s: unable to create directory entry.",
76
0
     function );
77
78
0
    goto on_error;
79
0
  }
80
553
  if( memory_set(
81
553
       *directory_entry,
82
553
       0,
83
553
       sizeof( libfsntfs_directory_entry_t ) ) == NULL )
84
0
  {
85
0
    libcerror_error_set(
86
0
     error,
87
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
88
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
89
0
     "%s: unable to clear directory entry.",
90
0
     function );
91
92
0
    memory_free(
93
0
     *directory_entry );
94
95
0
    *directory_entry = NULL;
96
97
0
    return( -1 );
98
0
  }
99
553
  return( 1 );
100
101
0
on_error:
102
0
  if( *directory_entry != NULL )
103
0
  {
104
0
    memory_free(
105
0
     *directory_entry );
106
107
0
    *directory_entry = NULL;
108
0
  }
109
0
  return( -1 );
110
553
}
111
112
/* Frees a directory entry
113
 * Returns 1 if successful or -1 on error
114
 */
115
int libfsntfs_directory_entry_free(
116
     libfsntfs_directory_entry_t **directory_entry,
117
     libcerror_error_t **error )
118
553
{
119
553
  static char *function = "libfsntfs_directory_entry_free";
120
553
  int result            = 1;
121
122
553
  if( directory_entry == NULL )
123
0
  {
124
0
    libcerror_error_set(
125
0
     error,
126
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
127
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
128
0
     "%s: invalid directory entry.",
129
0
     function );
130
131
0
    return( -1 );
132
0
  }
133
553
  if( *directory_entry != NULL )
134
553
  {
135
553
    if( ( *directory_entry )->file_name_values != NULL )
136
98
    {
137
98
      if( libfsntfs_file_name_values_free(
138
98
           &( ( *directory_entry )->file_name_values ),
139
98
           error ) != 1 )
140
0
      {
141
0
        libcerror_error_set(
142
0
         error,
143
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
144
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
145
0
         "%s: unable to free file name values.",
146
0
         function );
147
148
0
        result = -1;
149
0
      }
150
98
    }
151
553
    if( ( *directory_entry )->short_file_name_values != NULL )
152
457
    {
153
457
      if( libfsntfs_file_name_values_free(
154
457
           &( ( *directory_entry )->short_file_name_values ),
155
457
           error ) != 1 )
156
0
      {
157
0
        libcerror_error_set(
158
0
         error,
159
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
160
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
161
0
         "%s: unable to free short file name values.",
162
0
         function );
163
164
0
        result = -1;
165
0
      }
166
457
    }
167
553
    memory_free(
168
553
     *directory_entry );
169
170
553
    *directory_entry = NULL;
171
553
  }
172
553
  return( result );
173
553
}
174
175
/* Clones a directory entry
176
 * Returns 1 if successful or -1 on error
177
 */
178
int libfsntfs_directory_entry_clone(
179
     libfsntfs_directory_entry_t **destination_directory_entry,
180
     libfsntfs_directory_entry_t *source_directory_entry,
181
     libcerror_error_t **error )
182
49
{
183
49
  static char *function = "libfsntfs_directory_entry_clone";
184
185
49
  if( destination_directory_entry == NULL )
186
0
  {
187
0
    libcerror_error_set(
188
0
     error,
189
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
190
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
191
0
     "%s: invalid directory entry.",
192
0
     function );
193
194
0
    return( -1 );
195
0
  }
196
49
  if( *destination_directory_entry != NULL )
197
0
  {
198
0
    libcerror_error_set(
199
0
     error,
200
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
201
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
202
0
     "%s: invalid destination directory entry value already set.",
203
0
     function );
204
205
0
    return( -1 );
206
0
  }
207
49
  if( source_directory_entry == NULL )
208
0
  {
209
0
    *destination_directory_entry = source_directory_entry;
210
211
0
    return( 1 );
212
0
  }
213
49
  if( libfsntfs_directory_entry_initialize(
214
49
       destination_directory_entry,
215
49
       error ) != 1 )
216
0
  {
217
0
    libcerror_error_set(
218
0
     error,
219
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
220
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
221
0
     "%s: unable to create destination directory entry.",
222
0
     function );
223
224
0
    goto on_error;
225
0
  }
226
49
  if( libfsntfs_file_name_values_clone(
227
49
       &( ( *destination_directory_entry )->file_name_values ),
228
49
       source_directory_entry->file_name_values,
229
49
       error ) != 1 )
230
0
  {
231
0
    libcerror_error_set(
232
0
     error,
233
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
234
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
235
0
     "%s: unable to create destination file name values.",
236
0
     function );
237
238
0
    goto on_error;
239
0
  }
240
49
  if( libfsntfs_file_name_values_clone(
241
49
       &( ( *destination_directory_entry )->short_file_name_values ),
242
49
       source_directory_entry->short_file_name_values,
243
49
       error ) != 1 )
244
0
  {
245
0
    libcerror_error_set(
246
0
     error,
247
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
248
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
249
0
     "%s: unable to create destination short file name values.",
250
0
     function );
251
252
0
    goto on_error;
253
0
  }
254
49
  ( *destination_directory_entry )->file_reference = source_directory_entry->file_reference;
255
256
49
  return( 1 );
257
258
0
on_error:
259
0
  if( *destination_directory_entry != NULL )
260
0
  {
261
0
    libfsntfs_directory_entry_free(
262
0
     destination_directory_entry,
263
0
     NULL );
264
0
  }
265
0
  return( -1 );
266
49
}
267
268
/* Compares 2 directory entries by file reference
269
 * Returns LIBCDATA_COMPARE_LESS, LIBCDATA_COMPARE_EQUAL, LIBCDATA_COMPARE_GREATER if successful or -1 on error
270
 */
271
int libfsntfs_directory_entry_compare_by_file_reference(
272
     libfsntfs_directory_entry_t *first_directory_entry,
273
     libfsntfs_directory_entry_t *second_directory_entry,
274
     libcerror_error_t **error )
275
1.93k
{
276
1.93k
  static char *function           = "libfsntfs_directory_entry_compare_by_file_reference";
277
1.93k
  uint64_t first_mft_entry_index  = 0;
278
1.93k
  uint64_t second_mft_entry_index = 0;
279
1.93k
  uint16_t first_sequence_number  = 0;
280
1.93k
  uint16_t second_sequence_number = 0;
281
282
1.93k
  if( first_directory_entry == NULL )
283
0
  {
284
0
    libcerror_error_set(
285
0
     error,
286
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
287
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
288
0
     "%s: invalid first directory entry.",
289
0
     function );
290
291
0
    return( -1 );
292
0
  }
293
1.93k
  if( second_directory_entry == NULL )
294
0
  {
295
0
    libcerror_error_set(
296
0
     error,
297
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
298
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
299
0
     "%s: invalid second directory entry.",
300
0
     function );
301
302
0
    return( -1 );
303
0
  }
304
1.93k
  first_mft_entry_index  = first_directory_entry->file_reference & 0xffffffffffffUL;
305
1.93k
  second_mft_entry_index = second_directory_entry->file_reference & 0xffffffffffffUL;
306
307
1.93k
  if( first_mft_entry_index < second_mft_entry_index )
308
376
  {
309
376
    return( LIBCDATA_COMPARE_LESS );
310
376
  }
311
1.56k
  else if( first_mft_entry_index > second_mft_entry_index )
312
1.49k
  {
313
1.49k
    return( LIBCDATA_COMPARE_GREATER );
314
1.49k
  }
315
69
  first_sequence_number  = (uint16_t) ( first_directory_entry->file_reference >> 48 );
316
69
  second_sequence_number = (uint16_t) ( second_directory_entry->file_reference >> 48 );
317
318
69
  if( first_sequence_number < second_sequence_number )
319
21
  {
320
21
    return( LIBCDATA_COMPARE_LESS );
321
21
  }
322
48
  else if( first_sequence_number > second_sequence_number )
323
38
  {
324
38
    return( LIBCDATA_COMPARE_GREATER );
325
38
  }
326
10
  return( LIBCDATA_COMPARE_EQUAL );
327
69
}
328
329
/* Retrieves the MFT entry index
330
 * Returns 1 if successful or -1 on error
331
 */
332
int libfsntfs_directory_entry_get_mft_entry_index(
333
     libfsntfs_directory_entry_t *directory_entry,
334
     uint64_t *mft_entry_index,
335
     libcerror_error_t **error )
336
49
{
337
49
  static char *function = "libfsntfs_directory_entry_get_mft_entry_index";
338
339
49
  if( directory_entry == NULL )
340
0
  {
341
0
    libcerror_error_set(
342
0
     error,
343
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
344
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
345
0
     "%s: invalid directory entry.",
346
0
     function );
347
348
0
    return( -1 );
349
0
  }
350
49
  if( mft_entry_index == NULL )
351
0
  {
352
0
    libcerror_error_set(
353
0
     error,
354
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
355
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
356
0
     "%s: invalid MFT entry index.",
357
0
     function );
358
359
0
    return( -1 );
360
0
  }
361
49
  if( ( directory_entry->file_reference & 0xffffffffffffUL ) > (uint64_t) INT_MAX )
362
5
  {
363
5
    libcerror_error_set(
364
5
     error,
365
5
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
366
5
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
367
5
     "%s: invalid MFT entry index value out of bounds.",
368
5
     function );
369
370
5
    return( -1 );
371
5
  }
372
44
  *mft_entry_index = (int) ( directory_entry->file_reference & 0xffffffffffffUL );
373
374
44
  return( 1 );
375
49
}
376
377
/* Retrieves the file reference
378
 * Returns 1 if successful or -1 on error
379
 */
380
int libfsntfs_directory_entry_get_file_reference(
381
     libfsntfs_directory_entry_t *directory_entry,
382
     uint64_t *file_reference,
383
     libcerror_error_t **error )
384
0
{
385
0
  static char *function = "libfsntfs_directory_entry_get_file_reference";
386
387
0
  if( directory_entry == NULL )
388
0
  {
389
0
    libcerror_error_set(
390
0
     error,
391
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
392
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
393
0
     "%s: invalid directory entry.",
394
0
     function );
395
396
0
    return( -1 );
397
0
  }
398
0
  if( file_reference == NULL )
399
0
  {
400
0
    libcerror_error_set(
401
0
     error,
402
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
403
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
404
0
     "%s: invalid file reference.",
405
0
     function );
406
407
0
    return( -1 );
408
0
  }
409
0
  *file_reference = directory_entry->file_reference;
410
411
0
  return( 1 );
412
0
}
413
414
/* Retrieves the parent file reference
415
 * Returns 1 if successful or -1 on error
416
 */
417
int libfsntfs_directory_entry_get_parent_file_reference(
418
     libfsntfs_directory_entry_t *directory_entry,
419
     uint64_t *parent_file_reference,
420
     libcerror_error_t **error )
421
0
{
422
0
  static char *function = "libfsntfs_directory_entry_get_parent_file_reference";
423
424
0
  if( directory_entry == NULL )
425
0
  {
426
0
    libcerror_error_set(
427
0
     error,
428
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
429
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
430
0
     "%s: invalid directory entry.",
431
0
     function );
432
433
0
    return( -1 );
434
0
  }
435
0
  if( libfsntfs_file_name_values_get_parent_file_reference(
436
0
       directory_entry->file_name_values,
437
0
       parent_file_reference,
438
0
       error ) != 1 )
439
0
  {
440
0
    libcerror_error_set(
441
0
     error,
442
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
443
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
444
0
     "%s: unable to retrieve parent reference from file name values.",
445
0
     function );
446
447
0
    return( -1 );
448
0
  }
449
0
  return( 1 );
450
0
}
451
452
/* Retrieves the creation date and time
453
 * Returns 1 if successful or -1 on error
454
 */
455
int libfsntfs_directory_entry_get_creation_time(
456
     libfsntfs_directory_entry_t *directory_entry,
457
     uint64_t *filetime,
458
     libcerror_error_t **error )
459
0
{
460
0
  static char *function = "libfsntfs_directory_entry_get_creation_time";
461
462
0
  if( directory_entry == NULL )
463
0
  {
464
0
    libcerror_error_set(
465
0
     error,
466
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
467
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
468
0
     "%s: invalid directory entry.",
469
0
     function );
470
471
0
    return( -1 );
472
0
  }
473
0
  if( libfsntfs_file_name_values_get_creation_time(
474
0
       directory_entry->file_name_values,
475
0
       filetime,
476
0
       error ) != 1 )
477
0
  {
478
0
    libcerror_error_set(
479
0
     error,
480
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
481
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
482
0
     "%s: unable to retrieve creation time from file name values.",
483
0
     function );
484
485
0
    return( -1 );
486
0
  }
487
0
  return( 1 );
488
0
}
489
490
/* Retrieves the modification date and time
491
 * Returns 1 if successful or -1 on error
492
 */
493
int libfsntfs_directory_entry_get_modification_time(
494
     libfsntfs_directory_entry_t *directory_entry,
495
     uint64_t *filetime,
496
     libcerror_error_t **error )
497
0
{
498
0
  static char *function = "libfsntfs_directory_entry_get_modification_time";
499
500
0
  if( directory_entry == NULL )
501
0
  {
502
0
    libcerror_error_set(
503
0
     error,
504
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
505
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
506
0
     "%s: invalid directory entry.",
507
0
     function );
508
509
0
    return( -1 );
510
0
  }
511
0
  if( libfsntfs_file_name_values_get_modification_time(
512
0
       directory_entry->file_name_values,
513
0
       filetime,
514
0
       error ) != 1 )
515
0
  {
516
0
    libcerror_error_set(
517
0
     error,
518
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
519
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
520
0
     "%s: unable to retrieve modification time from file name values.",
521
0
     function );
522
523
0
    return( -1 );
524
0
  }
525
0
  return( 1 );
526
0
}
527
528
/* Retrieves the access date and time
529
 * Returns 1 if successful or -1 on error
530
 */
531
int libfsntfs_directory_entry_get_access_time(
532
     libfsntfs_directory_entry_t *directory_entry,
533
     uint64_t *filetime,
534
     libcerror_error_t **error )
535
0
{
536
0
  static char *function = "libfsntfs_directory_entry_get_access_time";
537
538
0
  if( directory_entry == NULL )
539
0
  {
540
0
    libcerror_error_set(
541
0
     error,
542
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
543
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
544
0
     "%s: invalid directory entry.",
545
0
     function );
546
547
0
    return( -1 );
548
0
  }
549
0
  if( libfsntfs_file_name_values_get_access_time(
550
0
       directory_entry->file_name_values,
551
0
       filetime,
552
0
       error ) != 1 )
553
0
  {
554
0
    libcerror_error_set(
555
0
     error,
556
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
557
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
558
0
     "%s: unable to retrieve access time from file name values.",
559
0
     function );
560
561
0
    return( -1 );
562
0
  }
563
0
  return( 1 );
564
0
}
565
566
/* Retrieves the entry modification date and time
567
 * Returns 1 if successful or -1 on error
568
 */
569
int libfsntfs_directory_entry_get_entry_modification_time(
570
     libfsntfs_directory_entry_t *directory_entry,
571
     uint64_t *filetime,
572
     libcerror_error_t **error )
573
0
{
574
0
  static char *function = "libfsntfs_directory_entry_get_entry_modification_time";
575
576
0
  if( directory_entry == NULL )
577
0
  {
578
0
    libcerror_error_set(
579
0
     error,
580
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
581
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
582
0
     "%s: invalid directory entry.",
583
0
     function );
584
585
0
    return( -1 );
586
0
  }
587
0
  if( libfsntfs_file_name_values_get_entry_modification_time(
588
0
       directory_entry->file_name_values,
589
0
       filetime,
590
0
       error ) != 1 )
591
0
  {
592
0
    libcerror_error_set(
593
0
     error,
594
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
595
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
596
0
     "%s: unable to retrieve entry modification time from file name values.",
597
0
     function );
598
599
0
    return( -1 );
600
0
  }
601
0
  return( 1 );
602
0
}
603
604
/* Retrieves the size
605
 * Returns 1 if successful or -1 on error
606
 */
607
int libfsntfs_directory_entry_get_size(
608
     libfsntfs_directory_entry_t *directory_entry,
609
     uint64_t *size,
610
     libcerror_error_t **error )
611
0
{
612
0
  static char *function = "libfsntfs_directory_entry_get_entry_size";
613
614
0
  if( directory_entry == NULL )
615
0
  {
616
0
    libcerror_error_set(
617
0
     error,
618
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
619
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
620
0
     "%s: invalid directory entry.",
621
0
     function );
622
623
0
    return( -1 );
624
0
  }
625
0
  if( libfsntfs_file_name_values_get_size(
626
0
       directory_entry->file_name_values,
627
0
       size,
628
0
       error ) != 1 )
629
0
  {
630
0
    libcerror_error_set(
631
0
     error,
632
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
633
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
634
0
     "%s: unable to retrieve size from file name values.",
635
0
     function );
636
637
0
    return( -1 );
638
0
  }
639
0
  return( 1 );
640
0
}
641
642
/* Retrieves the file attribute flags
643
 * Returns 1 if successful or -1 on error
644
 */
645
int libfsntfs_directory_entry_get_file_attribute_flags(
646
     libfsntfs_directory_entry_t *directory_entry,
647
     uint32_t *file_attribute_flags,
648
     libcerror_error_t **error )
649
0
{
650
0
  static char *function = "libfsntfs_directory_entry_get_entry_file_attribute_flags";
651
652
0
  if( directory_entry == NULL )
653
0
  {
654
0
    libcerror_error_set(
655
0
     error,
656
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
657
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
658
0
     "%s: invalid directory entry.",
659
0
     function );
660
661
0
    return( -1 );
662
0
  }
663
0
  if( libfsntfs_file_name_values_get_file_attribute_flags(
664
0
       directory_entry->file_name_values,
665
0
       file_attribute_flags,
666
0
       error ) != 1 )
667
0
  {
668
0
    libcerror_error_set(
669
0
     error,
670
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
671
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
672
0
     "%s: unable to retrieve file attribute flags from file name values.",
673
0
     function );
674
675
0
    return( -1 );
676
0
  }
677
0
  return( 1 );
678
0
}
679
680
/* Retrieves the size of the UTF-8 encoded name
681
 * This function uses UTF-8 RFC 2279 (or 6-byte UTF-8) to support characters outside Unicode
682
 * The returned size includes the end of string character
683
 * Returns 1 if successful or -1 on error
684
 */
685
int libfsntfs_directory_entry_get_utf8_name_size(
686
     libfsntfs_directory_entry_t *directory_entry,
687
     size_t *utf8_string_size,
688
     libcerror_error_t **error )
689
0
{
690
0
  static char *function = "libfsntfs_directory_entry_get_utf8_name_size";
691
692
0
  if( directory_entry == NULL )
693
0
  {
694
0
    libcerror_error_set(
695
0
     error,
696
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
697
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
698
0
     "%s: invalid directory entry.",
699
0
     function );
700
701
0
    return( -1 );
702
0
  }
703
0
  if( libfsntfs_file_name_values_get_utf8_name_size(
704
0
       directory_entry->file_name_values,
705
0
       utf8_string_size,
706
0
       error ) != 1 )
707
0
  {
708
0
    libcerror_error_set(
709
0
     error,
710
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
711
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
712
0
     "%s: unable to retrieve size of UTF-8 name from file name values.",
713
0
     function );
714
715
0
    return( -1 );
716
0
  }
717
0
  return( 1 );
718
0
}
719
720
/* Retrieves the UTF-8 encoded name
721
 * This function uses UTF-8 RFC 2279 (or 6-byte UTF-8) to support characters outside Unicode
722
 * The size should include the end of string character
723
 * Returns 1 if successful or -1 on error
724
 */
725
int libfsntfs_directory_entry_get_utf8_name(
726
     libfsntfs_directory_entry_t *directory_entry,
727
     uint8_t *utf8_string,
728
     size_t utf8_string_size,
729
     libcerror_error_t **error )
730
0
{
731
0
  static char *function = "libfsntfs_directory_entry_get_utf8_name";
732
733
0
  if( directory_entry == NULL )
734
0
  {
735
0
    libcerror_error_set(
736
0
     error,
737
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
738
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
739
0
     "%s: invalid directory entry.",
740
0
     function );
741
742
0
    return( -1 );
743
0
  }
744
0
  if( libfsntfs_file_name_values_get_utf8_name(
745
0
       directory_entry->file_name_values,
746
0
       utf8_string,
747
0
       utf8_string_size,
748
0
       error ) != 1 )
749
0
  {
750
0
    libcerror_error_set(
751
0
     error,
752
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
753
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
754
0
     "%s: unable to retrieve UTF-8 name from file name values.",
755
0
     function );
756
757
0
    return( -1 );
758
0
  }
759
0
  return( 1 );
760
0
}
761
762
/* Retrieves the size of the UTF-16 encoded name
763
 * This function uses UCS-2 (with surrogates) to support characters outside Unicode
764
 * The returned size includes the end of string character
765
 * Returns 1 if successful or -1 on error
766
 */
767
int libfsntfs_directory_entry_get_utf16_name_size(
768
     libfsntfs_directory_entry_t *directory_entry,
769
     size_t *utf16_string_size,
770
     libcerror_error_t **error )
771
0
{
772
0
  static char *function = "libfsntfs_directory_entry_get_utf16_name_size";
773
774
0
  if( directory_entry == NULL )
775
0
  {
776
0
    libcerror_error_set(
777
0
     error,
778
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
779
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
780
0
     "%s: invalid directory entry.",
781
0
     function );
782
783
0
    return( -1 );
784
0
  }
785
0
  if( libfsntfs_file_name_values_get_utf16_name_size(
786
0
       directory_entry->file_name_values,
787
0
       utf16_string_size,
788
0
       error ) != 1 )
789
0
  {
790
0
    libcerror_error_set(
791
0
     error,
792
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
793
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
794
0
     "%s: unable to retrieve size of UTF-16 name from file name values.",
795
0
     function );
796
797
0
    return( -1 );
798
0
  }
799
0
  return( 1 );
800
0
}
801
802
/* Retrieves the UTF-16 encoded name
803
 * This function uses UCS-2 (with surrogates) to support characters outside Unicode
804
 * The size should include the end of string character
805
 * Returns 1 if successful or -1 on error
806
 */
807
int libfsntfs_directory_entry_get_utf16_name(
808
     libfsntfs_directory_entry_t *directory_entry,
809
     uint16_t *utf16_string,
810
     size_t utf16_string_size,
811
     libcerror_error_t **error )
812
0
{
813
0
  static char *function = "libfsntfs_directory_entry_get_utf16_name";
814
815
0
  if( directory_entry == NULL )
816
0
  {
817
0
    libcerror_error_set(
818
0
     error,
819
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
820
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
821
0
     "%s: invalid directory entry.",
822
0
     function );
823
824
0
    return( -1 );
825
0
  }
826
0
  if( libfsntfs_file_name_values_get_utf16_name(
827
0
       directory_entry->file_name_values,
828
0
       utf16_string,
829
0
       utf16_string_size,
830
0
       error ) != 1 )
831
0
  {
832
0
    libcerror_error_set(
833
0
     error,
834
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
835
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
836
0
     "%s: unable to retrieve UTF-16 name from file name values.",
837
0
     function );
838
839
0
    return( -1 );
840
0
  }
841
0
  return( 1 );
842
0
}
843