Coverage Report

Created: 2026-12-01 07:31

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