Debian Codegraph @

vhditools/mount_file_system.c

raw symbols SCIP
1 /*
2 * Mount file system
3 *
4 * Copyright (C) 2012-2025, Joachim Metz <[email protected]>
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 <narrow_string.h>
25 #include <system_string.h>
26 #include <types.h>
27 #include <wide_string.h>
28
29 #if defined( HAVE_SYS_STAT_H )
30 #include <sys/stat.h>
31 #endif
32
33 #if defined( HAVE_SYS_TIME_H )
34 #include <sys/time.h>
35 #endif
36
37 #include <time.h>
38
39 #include "mount_file_system.h"
40 #include "vhditools_libcdata.h"
41 #include "vhditools_libcerror.h"
42 #include "vhditools_libvhdi.h"
43
44 /* Creates a file system
45 * Make sure the value file_system is referencing, is set to NULL
46 * Returns 1 if successful or -1 on error
47 */
48 int mount_file_system_initialize(
49 mount_file_system_t **file_system,
50 libcerror_error_t **error )
51 {
52 #if defined( WINAPI )
53 FILETIME filetime;
54 SYSTEMTIME systemtime;
55
56 #elif defined( HAVE_CLOCK_GETTIME )
57 struct timespec time_structure;
58 #endif
59
60 static char *function = "mount_file_system_initialize";
61
62 #if defined( WINAPI )
63 DWORD error_code = 0;
64 #else
65 int64_t timestamp = 0;
66 #endif
67
68 if( file_system == NULL )
69 {
70 libcerror_error_set(
71 error,
72 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
73 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
74 "%s: invalid file system.",
75 function );
76
77 return( -1 );
78 }
79 if( *file_system != NULL )
80 {
81 libcerror_error_set(
82 error,
83 LIBCERROR_ERROR_DOMAIN_RUNTIME,
84 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
85 "%s: invalid file system value already set.",
86 function );
87
88 return( -1 );
89 }
90 *file_system = memory_allocate_structure(
91 mount_file_system_t );
92
93 if( *file_system == NULL )
94 {
95 libcerror_error_set(
96 error,
97 LIBCERROR_ERROR_DOMAIN_MEMORY,
98 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
99 "%s: unable to create file system.",
100 function );
101
102 goto on_error;
103 }
104 if( memory_set(
105 *file_system,
106 0,
107 sizeof( mount_file_system_t ) ) == NULL )
108 {
109 libcerror_error_set(
110 error,
111 LIBCERROR_ERROR_DOMAIN_MEMORY,
112 LIBCERROR_MEMORY_ERROR_SET_FAILED,
113 "%s: unable to clear file system.",
114 function );
115
116 memory_free(
117 *file_system );
118
119 *file_system = NULL;
120
121 return( -1 );
122 }
123 if( libcdata_array_initialize(
124 &( ( *file_system )->files_array ),
125 0,
126 error ) != 1 )
127 {
128 libcerror_error_set(
129 error,
130 LIBCERROR_ERROR_DOMAIN_RUNTIME,
131 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
132 "%s: unable to initialize files array.",
133 function );
134
135 goto on_error;
136 }
137 #if defined( WINAPI )
138 if( memory_set(
139 &systemtime,
140 0,
141 sizeof( SYSTEMTIME ) ) == NULL )
142 {
143 libcerror_error_set(
144 error,
145 LIBCERROR_ERROR_DOMAIN_MEMORY,
146 LIBCERROR_MEMORY_ERROR_SET_FAILED,
147 "%s: unable to clear systemtime.",
148 function );
149
150 goto on_error;
151 }
152 GetSystemTime(
153 &systemtime );
154
155 if( SystemTimeToFileTime(
156 &systemtime,
157 &filetime ) == 0 )
158 {
159 error_code = GetLastError();
160
161 libcerror_system_set_error(
162 error,
163 LIBCERROR_ERROR_DOMAIN_RUNTIME,
164 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
165 error_code,
166 "%s: unable to retrieve FILETIME of current time.",
167 function );
168
169 goto on_error;
170 }
171 ( *file_system )->mounted_timestamp = ( (uint64_t) filetime.dwHighDateTime << 32 ) | filetime.dwLowDateTime;
172
173 #elif defined( HAVE_CLOCK_GETTIME )
174 if( clock_gettime(
175 CLOCK_REALTIME,
176 &time_structure ) != 0 )
177 {
178 libcerror_error_set(
179 error,
180 LIBCERROR_ERROR_DOMAIN_RUNTIME,
181 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
182 "%s: unable to retrieve current time structure.",
183 function );
184
185 goto on_error;
186 }
187 timestamp = ( (int64_t) time_structure.tv_sec * 1000000000 ) + time_structure.tv_nsec;
188
189 ( *file_system )->mounted_timestamp = (uint64_t) timestamp;
190
191 #else
192 timestamp = (int64_t) time( NULL );
193
194 if( timestamp == -1 )
195 {
196 libcerror_error_set(
197 error,
198 LIBCERROR_ERROR_DOMAIN_RUNTIME,
199 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
200 "%s: unable to retrieve current time.",
201 function );
202
203 goto on_error;
204 }
205 timestamp *= 1000000000;
206
207 ( *file_system )->mounted_timestamp = (uint64_t) timestamp;
208
209 #endif /* defined( HAVE_CLOCK_GETTIME ) */
210
211 return( 1 );
212
213 on_error:
214 if( *file_system != NULL )
215 {
216 memory_free(
217 *file_system );
218
219 *file_system = NULL;
220 }
221 return( -1 );
222 }
223
224 /* Frees a file system
225 * Returns 1 if successful or -1 on error
226 */
227 int mount_file_system_free(
228 mount_file_system_t **file_system,
229 libcerror_error_t **error )
230 {
231 static char *function = "mount_file_system_free";
232 int result = 1;
233
234 if( file_system == NULL )
235 {
236 libcerror_error_set(
237 error,
238 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
239 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
240 "%s: invalid file system.",
241 function );
242
243 return( -1 );
244 }
245 if( *file_system != NULL )
246 {
247 if( ( *file_system )->path_prefix != NULL )
248 {
249 memory_free(
250 ( *file_system )->path_prefix );
251 }
252 if( libcdata_array_free(
253 &( ( *file_system )->files_array ),
254 NULL,
255 error ) != 1 )
256 {
257 libcerror_error_set(
258 error,
259 LIBCERROR_ERROR_DOMAIN_RUNTIME,
260 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
261 "%s: unable to free files array.",
262 function );
263
264 result = -1;
265 }
266 memory_free(
267 *file_system );
268
269 *file_system = NULL;
270 }
271 return( result );
272 }
273
274 /* Signals the file system to abort
275 * Returns 1 if successful or -1 on error
276 */
277 int mount_file_system_signal_abort(
278 mount_file_system_t *file_system,
279 libcerror_error_t **error )
280 {
281 libvhdi_file_t *vhdi_file = NULL;
282 static char *function = "mount_file_system_signal_abort";
283 int file_index = 0;
284 int number_of_files = 0;
285
286 if( file_system == NULL )
287 {
288 libcerror_error_set(
289 error,
290 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
291 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
292 "%s: invalid file system.",
293 function );
294
295 return( -1 );
296 }
297 if( libcdata_array_get_number_of_entries(
298 file_system->files_array,
299 &number_of_files,
300 error ) != 1 )
301 {
302 libcerror_error_set(
303 error,
304 LIBCERROR_ERROR_DOMAIN_RUNTIME,
305 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
306 "%s: unable to retrieve number of files.",
307 function );
308
309 return( -1 );
310 }
311 for( file_index = number_of_files - 1;
312 file_index > 0;
313 file_index-- )
314 {
315 if( libcdata_array_get_entry_by_index(
316 file_system->files_array,
317 file_index,
318 (intptr_t **) &vhdi_file,
319 error ) != 1 )
320 {
321 libcerror_error_set(
322 error,
323 LIBCERROR_ERROR_DOMAIN_RUNTIME,
324 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
325 "%s: unable to retrieve file: %d.",
326 function,
327 file_index );
328
329 return( -1 );
330 }
331 if( libvhdi_file_signal_abort(
332 vhdi_file,
333 error ) != 1 )
334 {
335 libcerror_error_set(
336 error,
337 LIBCERROR_ERROR_DOMAIN_RUNTIME,
338 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
339 "%s: unable to signal file: %d to abort.",
340 function,
341 file_index );
342
343 return( -1 );
344 }
345 }
346 return( 1 );
347 }
348
349 /* Sets the path prefix
350 * Returns 1 if successful or -1 on error
351 */
352 int mount_file_system_set_path_prefix(
353 mount_file_system_t *file_system,
354 const system_character_t *path_prefix,
355 size_t path_prefix_size,
356 libcerror_error_t **error )
357 {
358 static char *function = "mount_file_system_set_path_prefix";
359
360 if( file_system == NULL )
361 {
362 libcerror_error_set(
363 error,
364 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
365 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
366 "%s: invalid file system.",
367 function );
368
369 return( -1 );
370 }
371 if( file_system->path_prefix != NULL )
372 {
373 libcerror_error_set(
374 error,
375 LIBCERROR_ERROR_DOMAIN_RUNTIME,
376 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
377 "%s: invalid file system - path prefix value already set.",
378 function );
379
380 return( -1 );
381 }
382 if( path_prefix == NULL )
383 {
384 libcerror_error_set(
385 error,
386 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
387 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
388 "%s: invalid path prefix.",
389 function );
390
391 return( -1 );
392 }
393 if( path_prefix_size == 0 )
394 {
395 libcerror_error_set(
396 error,
397 LIBCERROR_ERROR_DOMAIN_RUNTIME,
398 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
399 "%s: missing path prefix.",
400 function );
401
402 goto on_error;
403 }
404 if( path_prefix_size > (size_t) ( SSIZE_MAX / sizeof( system_character_t ) ) )
405 {
406 libcerror_error_set(
407 error,
408 LIBCERROR_ERROR_DOMAIN_RUNTIME,
409 LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
410 "%s: invalid path prefix size value exceeds maximum.",
411 function );
412
413 goto on_error;
414 }
415 file_system->path_prefix = system_string_allocate(
416 path_prefix_size );
417
418 if( file_system->path_prefix == NULL )
419 {
420 libcerror_error_set(
421 error,
422 LIBCERROR_ERROR_DOMAIN_MEMORY,
423 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
424 "%s: unable to create path prefix string.",
425 function );
426
427 goto on_error;
428 }
429 if( system_string_copy(
430 file_system->path_prefix,
431 path_prefix,
432 path_prefix_size ) == NULL )
433 {
434 libcerror_error_set(
435 error,
436 LIBCERROR_ERROR_DOMAIN_RUNTIME,
437 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
438 "%s: unable to copy path prefix.",
439 function );
440
441 goto on_error;
442 }
443 file_system->path_prefix[ path_prefix_size - 1 ] = 0;
444
445 file_system->path_prefix_size = path_prefix_size;
446
447 return( 1 );
448
449 on_error:
450 if( file_system->path_prefix != NULL )
451 {
452 memory_free(
453 file_system->path_prefix );
454
455 file_system->path_prefix = NULL;
456 }
457 file_system->path_prefix_size = 0;
458
459 return( -1 );
460 }
461
462 /* Retrieves the mounted timestamp
463 * On Windows the timestamp is an unsigned 64-bit FILETIME timestamp
464 * otherwise the timestamp is a signed 64-bit POSIX date and time value in number of nanoseconds
465 * Returns 1 if successful or -1 on error
466 */
467 int mount_file_system_get_mounted_timestamp(
468 mount_file_system_t *file_system,
469 uint64_t *mounted_timestamp,
470 libcerror_error_t **error )
471 {
472 static char *function = "mount_file_system_get_mounted_timestamp";
473
474 if( file_system == NULL )
475 {
476 libcerror_error_set(
477 error,
478 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
479 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
480 "%s: invalid file system.",
481 function );
482
483 return( -1 );
484 }
485 if( mounted_timestamp == NULL )
486 {
487 libcerror_error_set(
488 error,
489 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
490 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
491 "%s: invalid mounted timestamp.",
492 function );
493
494 return( -1 );
495 }
496 *mounted_timestamp = file_system->mounted_timestamp;
497
498 return( 1 );
499 }
500
501 /* Retrieves the number of files
502 * Returns 1 if successful or -1 on error
503 */
504 int mount_file_system_get_number_of_files(
505 mount_file_system_t *file_system,
506 int *number_of_files,
507 libcerror_error_t **error )
508 {
509 static char *function = "mount_file_system_get_number_of_files";
510
511 if( file_system == NULL )
512 {
513 libcerror_error_set(
514 error,
515 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
516 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
517 "%s: invalid file system.",
518 function );
519
520 return( -1 );
521 }
522 if( libcdata_array_get_number_of_entries(
523 file_system->files_array,
524 number_of_files,
525 error ) != 1 )
526 {
527 libcerror_error_set(
528 error,
529 LIBCERROR_ERROR_DOMAIN_RUNTIME,
530 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
531 "%s: unable to retrieve number of files.",
532 function );
533
534 return( -1 );
535 }
536 return( 1 );
537 }
538
539 /* Retrieves a specific file
540 * Returns 1 if successful or -1 on error
541 */
542 int mount_file_system_get_file_by_index(
543 mount_file_system_t *file_system,
544 int file_index,
545 libvhdi_file_t **vhdi_file,
546 libcerror_error_t **error )
547 {
548 static char *function = "mount_file_system_get_file_by_index";
549
550 if( file_system == NULL )
551 {
552 libcerror_error_set(
553 error,
554 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
555 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
556 "%s: invalid file system.",
557 function );
558
559 return( -1 );
560 }
561 if( libcdata_array_get_entry_by_index(
562 file_system->files_array,
563 file_index,
564 (intptr_t **) vhdi_file,
565 error ) != 1 )
566 {
567 libcerror_error_set(
568 error,
569 LIBCERROR_ERROR_DOMAIN_RUNTIME,
570 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
571 "%s: unable to retrieve file: %d.",
572 function,
573 file_index );
574
575 return( -1 );
576 }
577 return( 1 );
578 }
579
580 /* Retrieves the file for a specific path
581 * Returns 1 if successful, 0 if no such file or -1 on error
582 */
583 int mount_file_system_get_file_by_path(
584 mount_file_system_t *file_system,
585 const system_character_t *path,
586 size_t path_length,
587 libvhdi_file_t **vhdi_file,
588 libcerror_error_t **error )
589 {
590 static char *function = "mount_file_system_get_file_by_path";
591 system_character_t character = 0;
592 size_t path_index = 0;
593 int file_index = 0;
594 int result = 0;
595
596 if( file_system == NULL )
597 {
598 libcerror_error_set(
599 error,
600 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
601 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
602 "%s: invalid file system.",
603 function );
604
605 return( -1 );
606 }
607 if( file_system->path_prefix == NULL )
608 {
609 libcerror_error_set(
610 error,
611 LIBCERROR_ERROR_DOMAIN_RUNTIME,
612 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
613 "%s: invalid file system - missing path prefix.",
614 function );
615
616 return( -1 );
617 }
618 if( path == NULL )
619 {
620 libcerror_error_set(
621 error,
622 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
623 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
624 "%s: invalid path.",
625 function );
626
627 return( -1 );
628 }
629 if( path_length > (size_t) ( SSIZE_MAX - 1 ) )
630 {
631 libcerror_error_set(
632 error,
633 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
634 LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
635 "%s: invalid path length value exceeds maximum.",
636 function );
637
638 return( -1 );
639 }
640 if( vhdi_file == NULL )
641 {
642 libcerror_error_set(
643 error,
644 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
645 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
646 "%s: invalid file.",
647 function );
648
649 return( -1 );
650 }
651 path_length = system_string_length(
652 path );
653
654 if( ( path_length == 1 )
655 && ( path[ 0 ] == file_system->path_prefix[ 0 ] ) )
656 {
657 *vhdi_file = NULL;
658
659 return( 1 );
660 }
661 if( ( path_length < file_system->path_prefix_size )
662 || ( path_length > ( file_system->path_prefix_size + 3 ) ) )
663 {
664 return( 0 );
665 }
666 #if defined( WINAPI )
667 result = system_string_compare_no_case(
668 path,
669 file_system->path_prefix,
670 file_system->path_prefix_size - 1 );
671 #else
672 result = system_string_compare(
673 path,
674 file_system->path_prefix,
675 file_system->path_prefix_size - 1 );
676 #endif
677 if( result != 0 )
678 {
679 return( 0 );
680 }
681 file_index = 0;
682
683 path_index = file_system->path_prefix_size - 1;
684
685 while( path_index < path_length )
686 {
687 character = path[ path_index++ ];
688
689 if( ( character < (system_character_t) '0' )
690 || ( character > (system_character_t) '9' ) )
691 {
692 return( 0 );
693 }
694 file_index *= 10;
695 file_index += character - (system_character_t) '0';
696 }
697 file_index -= 1;
698
699 if( libcdata_array_get_entry_by_index(
700 file_system->files_array,
701 file_index,
702 (intptr_t **) vhdi_file,
703 error ) != 1 )
704 {
705 libcerror_error_set(
706 error,
707 LIBCERROR_ERROR_DOMAIN_RUNTIME,
708 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
709 "%s: unable to retrieve file: %d.",
710 function,
711 file_index );
712
713 return( -1 );
714 }
715 return( 1 );
716 }
717
718 /* Appends a file to the file system
719 * Returns 1 if successful or -1 on error
720 */
721 int mount_file_system_append_file(
722 mount_file_system_t *file_system,
723 libvhdi_file_t *vhdi_file,
724 libcerror_error_t **error )
725 {
726 static char *function = "mount_file_system_append_file";
727 int entry_index = 0;
728
729 if( file_system == NULL )
730 {
731 libcerror_error_set(
732 error,
733 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
734 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
735 "%s: invalid file system.",
736 function );
737
738 return( -1 );
739 }
740 if( libcdata_array_append_entry(
741 file_system->files_array,
742 &entry_index,
743 (intptr_t *) vhdi_file,
744 error ) != 1 )
745 {
746 libcerror_error_set(
747 error,
748 LIBCERROR_ERROR_DOMAIN_RUNTIME,
749 LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
750 "%s: unable to append file to array.",
751 function );
752
753 return( -1 );
754 }
755 return( 1 );
756 }
757
758 /* Retrieves the path from a file index.
759 * Returns 1 if successful or -1 on error
760 */
761 int mount_file_system_get_path_from_file_index(
762 mount_file_system_t *file_system,
763 int file_index,
764 system_character_t *path,
765 size_t path_size,
766 libcerror_error_t **error )
767 {
768 static char *function = "mount_file_system_get_path_from_file_index";
769 size_t path_index = 0;
770 size_t required_path_size = 0;
771 int file_number = 0;
772
773 if( file_system == NULL )
774 {
775 libcerror_error_set(
776 error,
777 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
778 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
779 "%s: invalid file system.",
780 function );
781
782 return( -1 );
783 }
784 if( file_system->path_prefix == NULL )
785 {
786 libcerror_error_set(
787 error,
788 LIBCERROR_ERROR_DOMAIN_RUNTIME,
789 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
790 "%s: invalid file system - missing path prefix.",
791 function );
792
793 return( -1 );
794 }
795 if( path == NULL )
796 {
797 libcerror_error_set(
798 error,
799 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
800 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
801 "%s: invalid path.",
802 function );
803
804 return( -1 );
805 }
806 if( path_size > (size_t) SSIZE_MAX )
807 {
808 libcerror_error_set(
809 error,
810 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
811 LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
812 "%s: invalid path length value exceeds maximum.",
813 function );
814
815 return( -1 );
816 }
817 required_path_size = file_system->path_prefix_size;
818
819 file_number = file_index + 1;
820
821 while( file_number > 0 )
822 {
823 required_path_size++;
824
825 file_number /= 10;
826 }
827 if( path_size <= required_path_size )
828 {
829 libcerror_error_set(
830 error,
831 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
832 LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
833 "%s: invalid path size value too small.",
834 function );
835
836 return( -1 );
837 }
838 if( system_string_copy(
839 path,
840 file_system->path_prefix,
841 file_system->path_prefix_size ) == NULL )
842 {
843 libcerror_error_set(
844 error,
845 LIBCERROR_ERROR_DOMAIN_RUNTIME,
846 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
847 "%s: unable to copy path prefix.",
848 function );
849
850 return( -1 );
851 }
852 path_index = required_path_size - 1;
853
854 file_number = file_index + 1;
855
856 path[ path_index-- ] = 0;
857
858 while( file_number > 0 )
859 {
860 path[ path_index-- ] = (system_character_t) '0' + ( file_number % 10 );
861
862 file_number /= 10;
863 }
864 return( 1 );
865 }
866