/src/libfsfat/libfsfat/libfsfat_directory_entry.c
Line | Count | Source |
1 | | /* |
2 | | * The directory entry functions |
3 | | * |
4 | | * Copyright (C) 2021-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 "libfsfat_date_time.h" |
28 | | #include "libfsfat_debug.h" |
29 | | #include "libfsfat_definitions.h" |
30 | | #include "libfsfat_directory_entry.h" |
31 | | #include "libfsfat_libbfio.h" |
32 | | #include "libfsfat_libcdata.h" |
33 | | #include "libfsfat_libcerror.h" |
34 | | #include "libfsfat_libcnotify.h" |
35 | | #include "libfsfat_libfdatetime.h" |
36 | | #include "libfsfat_libuna.h" |
37 | | #include "libfsfat_name.h" |
38 | | |
39 | | #include "fsfat_directory_entry.h" |
40 | | |
41 | | const uint8_t libfsfat_directory_entry_empty[ 32 ] = { |
42 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
43 | | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
44 | | |
45 | | /* Creates a directory entry |
46 | | * Make sure the value directory_entry is referencing, is set to NULL |
47 | | * Returns 1 if successful or -1 on error |
48 | | */ |
49 | | int libfsfat_directory_entry_initialize( |
50 | | libfsfat_directory_entry_t **directory_entry, |
51 | | libcerror_error_t **error ) |
52 | 701k | { |
53 | 701k | static char *function = "libfsfat_directory_entry_initialize"; |
54 | | |
55 | 701k | if( directory_entry == NULL ) |
56 | 0 | { |
57 | 0 | libcerror_error_set( |
58 | 0 | error, |
59 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
60 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
61 | 0 | "%s: invalid directory entry.", |
62 | 0 | function ); |
63 | |
|
64 | 0 | return( -1 ); |
65 | 0 | } |
66 | 701k | if( *directory_entry != NULL ) |
67 | 0 | { |
68 | 0 | libcerror_error_set( |
69 | 0 | error, |
70 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
71 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
72 | 0 | "%s: invalid directory entry value already set.", |
73 | 0 | function ); |
74 | |
|
75 | 0 | return( -1 ); |
76 | 0 | } |
77 | 701k | *directory_entry = memory_allocate_structure( |
78 | 701k | libfsfat_directory_entry_t ); |
79 | | |
80 | 701k | if( *directory_entry == NULL ) |
81 | 0 | { |
82 | 0 | libcerror_error_set( |
83 | 0 | error, |
84 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
85 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
86 | 0 | "%s: unable to create directory entry.", |
87 | 0 | function ); |
88 | |
|
89 | 0 | goto on_error; |
90 | 0 | } |
91 | 701k | if( memory_set( |
92 | 701k | *directory_entry, |
93 | 701k | 0, |
94 | 701k | sizeof( libfsfat_directory_entry_t ) ) == NULL ) |
95 | 0 | { |
96 | 0 | libcerror_error_set( |
97 | 0 | error, |
98 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
99 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
100 | 0 | "%s: unable to clear directory entry.", |
101 | 0 | function ); |
102 | |
|
103 | 0 | memory_free( |
104 | 0 | *directory_entry ); |
105 | |
|
106 | 0 | *directory_entry = NULL; |
107 | |
|
108 | 0 | return( -1 ); |
109 | 0 | } |
110 | 701k | ( *directory_entry )->entry_type = LIBFSFAT_DIRECTORY_ENTRY_TYPE_TERMINATOR; |
111 | | |
112 | 701k | return( 1 ); |
113 | | |
114 | 0 | on_error: |
115 | 0 | if( *directory_entry != NULL ) |
116 | 0 | { |
117 | 0 | memory_free( |
118 | 0 | *directory_entry ); |
119 | |
|
120 | 0 | *directory_entry = NULL; |
121 | 0 | } |
122 | 0 | return( -1 ); |
123 | 701k | } |
124 | | |
125 | | /* Frees a directory entry |
126 | | * Returns 1 if successful or -1 on error |
127 | | */ |
128 | | int libfsfat_directory_entry_free( |
129 | | libfsfat_directory_entry_t **directory_entry, |
130 | | libcerror_error_t **error ) |
131 | 701k | { |
132 | 701k | static char *function = "libfsfat_directory_entry_free"; |
133 | 701k | int result = 1; |
134 | | |
135 | 701k | if( directory_entry == NULL ) |
136 | 0 | { |
137 | 0 | libcerror_error_set( |
138 | 0 | error, |
139 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
140 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
141 | 0 | "%s: invalid directory entry.", |
142 | 0 | function ); |
143 | |
|
144 | 0 | return( -1 ); |
145 | 0 | } |
146 | 701k | if( *directory_entry != NULL ) |
147 | 701k | { |
148 | 701k | if( ( *directory_entry )->name_entries_array != NULL ) |
149 | 2.45k | { |
150 | 2.45k | if( libcdata_array_free( |
151 | 2.45k | &( ( *directory_entry )->name_entries_array ), |
152 | 2.45k | NULL, |
153 | 2.45k | error ) != 1 ) |
154 | 0 | { |
155 | 0 | libcerror_error_set( |
156 | 0 | error, |
157 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
158 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
159 | 0 | "%s: unable to free name entries array.", |
160 | 0 | function ); |
161 | |
|
162 | 0 | result = -1; |
163 | 0 | } |
164 | 2.45k | } |
165 | 701k | if( ( *directory_entry )->name != NULL ) |
166 | 76.5k | { |
167 | 76.5k | memory_free( |
168 | 76.5k | ( *directory_entry )->name ); |
169 | 76.5k | } |
170 | 701k | memory_free( |
171 | 701k | *directory_entry ); |
172 | | |
173 | 701k | *directory_entry = NULL; |
174 | 701k | } |
175 | 701k | return( result ); |
176 | 701k | } |
177 | | |
178 | | /* Clones a directory entry |
179 | | * Returns 1 if successful or -1 on error |
180 | | */ |
181 | | int libfsfat_directory_entry_clone( |
182 | | libfsfat_directory_entry_t **destination_directory_entry, |
183 | | libfsfat_directory_entry_t *source_directory_entry, |
184 | | libcerror_error_t **error ) |
185 | 60 | { |
186 | 60 | static char *function = "libfsfat_directory_entry_clone"; |
187 | | |
188 | 60 | if( destination_directory_entry == 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 directory entry.", |
195 | 0 | function ); |
196 | |
|
197 | 0 | return( -1 ); |
198 | 0 | } |
199 | 60 | if( *destination_directory_entry != 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 destination directory entry value already set.", |
206 | 0 | function ); |
207 | |
|
208 | 0 | return( -1 ); |
209 | 0 | } |
210 | 60 | if( source_directory_entry == NULL ) |
211 | 0 | { |
212 | 0 | *destination_directory_entry = source_directory_entry; |
213 | |
|
214 | 0 | return( 1 ); |
215 | 0 | } |
216 | 60 | if( source_directory_entry->name == NULL ) |
217 | 0 | { |
218 | 0 | if( libfsfat_directory_entry_get_name( |
219 | 0 | source_directory_entry, |
220 | 0 | error ) != 1 ) |
221 | 0 | { |
222 | 0 | libcerror_error_set( |
223 | 0 | error, |
224 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
225 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
226 | 0 | "%s: unable to determine name of source directory entry.", |
227 | 0 | function ); |
228 | |
|
229 | 0 | return( -1 ); |
230 | 0 | } |
231 | 0 | } |
232 | 60 | *destination_directory_entry = memory_allocate_structure( |
233 | 60 | libfsfat_directory_entry_t ); |
234 | | |
235 | 60 | if( *destination_directory_entry == NULL ) |
236 | 0 | { |
237 | 0 | libcerror_error_set( |
238 | 0 | error, |
239 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
240 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
241 | 0 | "%s: unable to create destination directory entry.", |
242 | 0 | function ); |
243 | |
|
244 | 0 | goto on_error; |
245 | 0 | } |
246 | 60 | if( memory_copy( |
247 | 60 | *destination_directory_entry, |
248 | 60 | source_directory_entry, |
249 | 60 | sizeof( libfsfat_directory_entry_t ) ) == NULL ) |
250 | 0 | { |
251 | 0 | libcerror_error_set( |
252 | 0 | error, |
253 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
254 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
255 | 0 | "%s: unable to copy directory entry.", |
256 | 0 | function ); |
257 | |
|
258 | 0 | ( *destination_directory_entry )->name = NULL; |
259 | |
|
260 | 0 | goto on_error; |
261 | 0 | } |
262 | 60 | ( *destination_directory_entry )->name = NULL; |
263 | 60 | ( *destination_directory_entry )->name_entries_array = NULL; |
264 | | |
265 | 60 | if( source_directory_entry->name != NULL ) |
266 | 60 | { |
267 | 60 | ( *destination_directory_entry )->name = (uint8_t *) memory_allocate( |
268 | 60 | sizeof( uint8_t ) * source_directory_entry->name_size ); |
269 | | |
270 | 60 | if( ( *destination_directory_entry )->name == NULL ) |
271 | 0 | { |
272 | 0 | libcerror_error_set( |
273 | 0 | error, |
274 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
275 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
276 | 0 | "%s: unable to create name.", |
277 | 0 | function ); |
278 | |
|
279 | 0 | goto on_error; |
280 | 0 | } |
281 | 60 | if( memory_copy( |
282 | 60 | ( *destination_directory_entry )->name, |
283 | 60 | source_directory_entry->name, |
284 | 60 | source_directory_entry->name_size ) == NULL ) |
285 | 0 | { |
286 | 0 | libcerror_error_set( |
287 | 0 | error, |
288 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
289 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
290 | 0 | "%s: unable to copy name.", |
291 | 0 | function ); |
292 | |
|
293 | 0 | goto on_error; |
294 | 0 | } |
295 | 60 | } |
296 | 60 | return( 1 ); |
297 | | |
298 | 0 | on_error: |
299 | 0 | if( *destination_directory_entry != NULL ) |
300 | 0 | { |
301 | 0 | if( ( *destination_directory_entry )->name != NULL ) |
302 | 0 | { |
303 | 0 | memory_free( |
304 | 0 | ( *destination_directory_entry )->name ); |
305 | 0 | } |
306 | 0 | memory_free( |
307 | 0 | *destination_directory_entry ); |
308 | |
|
309 | 0 | *destination_directory_entry = NULL; |
310 | 0 | } |
311 | 0 | return( -1 ); |
312 | 60 | } |
313 | | |
314 | | /* Reads a directory entry |
315 | | * Returns 1 if successful, 0 if empty or -1 on error |
316 | | */ |
317 | | int libfsfat_directory_entry_read_data( |
318 | | libfsfat_directory_entry_t *directory_entry, |
319 | | const uint8_t *data, |
320 | | size_t data_size, |
321 | | uint8_t file_system_format, |
322 | | libcerror_error_t **error ) |
323 | 701k | { |
324 | 701k | static char *function = "libfsfat_directory_entry_read_data"; |
325 | 701k | uint16_t data_start_cluster_upper = 0; |
326 | | |
327 | | #if defined( HAVE_DEBUG_OUTPUT ) |
328 | | uint64_t value_64bit = 0; |
329 | | uint32_t value_32bit = 0; |
330 | | uint16_t value_16bit = 0; |
331 | | #endif |
332 | | |
333 | 701k | if( directory_entry == NULL ) |
334 | 0 | { |
335 | 0 | libcerror_error_set( |
336 | 0 | error, |
337 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
338 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
339 | 0 | "%s: invalid directory entry.", |
340 | 0 | function ); |
341 | |
|
342 | 0 | return( -1 ); |
343 | 0 | } |
344 | 701k | if( data == NULL ) |
345 | 0 | { |
346 | 0 | libcerror_error_set( |
347 | 0 | error, |
348 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
349 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
350 | 0 | "%s: invalid data.", |
351 | 0 | function ); |
352 | |
|
353 | 0 | return( -1 ); |
354 | 0 | } |
355 | 701k | if( data_size != sizeof( fsfat_directory_entry_t ) ) |
356 | 0 | { |
357 | 0 | libcerror_error_set( |
358 | 0 | error, |
359 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
360 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
361 | 0 | "%s: invalid data size value out of bounds.", |
362 | 0 | function ); |
363 | |
|
364 | 0 | return( -1 ); |
365 | 0 | } |
366 | | #if defined( HAVE_DEBUG_OUTPUT ) |
367 | | if( libcnotify_verbose != 0 ) |
368 | | { |
369 | | libcnotify_printf( |
370 | | "%s: directory entry data:\n", |
371 | | function ); |
372 | | libcnotify_print_data( |
373 | | data, |
374 | | sizeof( fsfat_directory_entry_t ), |
375 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
376 | | } |
377 | | #endif |
378 | 701k | if( file_system_format == LIBFSFAT_FILE_SYSTEM_FORMAT_EXFAT ) |
379 | 323k | { |
380 | 323k | switch( data[ 0 ] ) |
381 | 323k | { |
382 | 143 | case 0: |
383 | 143 | directory_entry->entry_type = LIBFSFAT_DIRECTORY_ENTRY_TYPE_TERMINATOR; |
384 | 143 | break; |
385 | | |
386 | 646 | case 0x81: |
387 | 646 | directory_entry->entry_type = LIBFSFAT_DIRECTORY_ENTRY_TYPE_EXFAT_ALLOCATION_BITMAP; |
388 | 646 | break; |
389 | | |
390 | 2.72k | case 0x82: |
391 | 2.72k | directory_entry->entry_type = LIBFSFAT_DIRECTORY_ENTRY_TYPE_EXFAT_UPCASE_TABLE; |
392 | 2.72k | break; |
393 | | |
394 | 103 | case 0x83: |
395 | 103 | directory_entry->entry_type = LIBFSFAT_DIRECTORY_ENTRY_TYPE_EXFAT_VOLUME_LABEL; |
396 | 103 | break; |
397 | | |
398 | 2.45k | case 0x85: |
399 | 2.45k | directory_entry->entry_type = LIBFSFAT_DIRECTORY_ENTRY_TYPE_EXFAT_FILE_ENTRY; |
400 | 2.45k | break; |
401 | | |
402 | 483 | case 0xc0: |
403 | 483 | directory_entry->entry_type = LIBFSFAT_DIRECTORY_ENTRY_TYPE_EXFAT_DATA_STREAM; |
404 | 483 | break; |
405 | | |
406 | 4.20k | case 0xc1: |
407 | 4.20k | directory_entry->entry_type = LIBFSFAT_DIRECTORY_ENTRY_TYPE_EXFAT_FILE_ENTRY_NAME; |
408 | 4.20k | break; |
409 | | |
410 | 313k | default: |
411 | 313k | directory_entry->entry_type = LIBFSFAT_DIRECTORY_ENTRY_TYPE_EXFAT_UNKNOWN; |
412 | 313k | break; |
413 | 323k | } |
414 | 323k | } |
415 | 377k | else if( memory_compare( |
416 | 377k | data, |
417 | 377k | libfsfat_directory_entry_empty, |
418 | 377k | sizeof( fsfat_directory_entry_t ) ) == 0 ) |
419 | 164 | { |
420 | 164 | directory_entry->entry_type = LIBFSFAT_DIRECTORY_ENTRY_TYPE_TERMINATOR; |
421 | 164 | } |
422 | 377k | else |
423 | 377k | { |
424 | 377k | directory_entry->entry_type = LIBFSFAT_DIRECTORY_ENTRY_TYPE_SHORT_NAME; |
425 | | |
426 | 377k | if( ( ( data[ 0 ] >= 0x01 ) |
427 | 369k | && ( data[ 0 ] <= 0x13 ) ) |
428 | 373k | || ( ( data[ 0 ] >= 0x41 ) |
429 | 326k | && ( data[ 0 ] <= 0x54 ) ) ) |
430 | 140k | { |
431 | 140k | if( ( data[ 11 ] == 0x0f ) |
432 | 7.11k | && ( data[ 12 ] == 0x00 ) |
433 | 7.08k | && ( data[ 26 ] == 0x00 ) |
434 | 7.03k | && ( data[ 27 ] == 0x00 ) ) |
435 | 7.00k | { |
436 | 7.00k | directory_entry->entry_type = LIBFSFAT_DIRECTORY_ENTRY_TYPE_VFAT_LONG_NAME; |
437 | 7.00k | } |
438 | 140k | } |
439 | 236k | else if( data[ 0 ] == 0xe5 ) |
440 | 3.16k | { |
441 | 3.16k | directory_entry->entry_type = LIBFSFAT_DIRECTORY_ENTRY_TYPE_UNALLOCATED; |
442 | 3.16k | } |
443 | 377k | } |
444 | 701k | if( directory_entry->entry_type == LIBFSFAT_DIRECTORY_ENTRY_TYPE_TERMINATOR ) |
445 | 307 | { |
446 | 307 | return( 0 ); |
447 | 307 | } |
448 | 700k | else if( directory_entry->entry_type == LIBFSFAT_DIRECTORY_ENTRY_TYPE_SHORT_NAME ) |
449 | 366k | { |
450 | 366k | if( memory_copy( |
451 | 366k | directory_entry->name_data, |
452 | 366k | ( (fsfat_directory_entry_t *) data )->name, |
453 | 366k | 8 ) == NULL ) |
454 | 0 | { |
455 | 0 | libcerror_error_set( |
456 | 0 | error, |
457 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
458 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
459 | 0 | "%s: unable to copy name.", |
460 | 0 | function ); |
461 | |
|
462 | 0 | return( -1 ); |
463 | 0 | } |
464 | 366k | if( memory_copy( |
465 | 366k | &( directory_entry->name_data[ 8 ] ), |
466 | 366k | ( (fsfat_directory_entry_t *) data )->extension, |
467 | 366k | 3 ) == NULL ) |
468 | 0 | { |
469 | 0 | libcerror_error_set( |
470 | 0 | error, |
471 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
472 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
473 | 0 | "%s: unable to copy extension.", |
474 | 0 | function ); |
475 | |
|
476 | 0 | return( -1 ); |
477 | 0 | } |
478 | 366k | directory_entry->file_attribute_flags = ( (fsfat_directory_entry_t *) data )->file_attribute_flags; |
479 | 366k | directory_entry->flags = ( (fsfat_directory_entry_t *) data )->flags; |
480 | 366k | directory_entry->creation_time_fraction = ( (fsfat_directory_entry_t *) data )->creation_time_fraction; |
481 | | |
482 | 366k | byte_stream_copy_to_uint16_little_endian( |
483 | 366k | ( (fsfat_directory_entry_t *) data )->creation_date, |
484 | 366k | directory_entry->creation_date ); |
485 | | |
486 | 366k | byte_stream_copy_to_uint16_little_endian( |
487 | 366k | ( (fsfat_directory_entry_t *) data )->creation_time, |
488 | 366k | directory_entry->creation_time ); |
489 | | |
490 | 366k | byte_stream_copy_to_uint16_little_endian( |
491 | 366k | ( (fsfat_directory_entry_t *) data )->access_date, |
492 | 366k | directory_entry->access_date ); |
493 | | |
494 | 366k | byte_stream_copy_to_uint16_little_endian( |
495 | 366k | ( (fsfat_directory_entry_t *) data )->modification_date, |
496 | 366k | directory_entry->modification_date ); |
497 | | |
498 | 366k | byte_stream_copy_to_uint16_little_endian( |
499 | 366k | ( (fsfat_directory_entry_t *) data )->modification_time, |
500 | 366k | directory_entry->modification_time ); |
501 | | |
502 | 366k | byte_stream_copy_to_uint16_little_endian( |
503 | 366k | ( (fsfat_directory_entry_t *) data )->data_start_cluster_lower, |
504 | 366k | directory_entry->data_start_cluster ); |
505 | | |
506 | 366k | if( file_system_format == LIBFSFAT_FILE_SYSTEM_FORMAT_FAT32 ) |
507 | 141k | { |
508 | 141k | byte_stream_copy_to_uint16_little_endian( |
509 | 141k | ( (fsfat_directory_entry_t *) data )->data_start_cluster_upper, |
510 | 141k | data_start_cluster_upper ); |
511 | | |
512 | 141k | directory_entry->data_start_cluster |= (uint32_t) data_start_cluster_upper << 16; |
513 | 141k | } |
514 | 366k | byte_stream_copy_to_uint32_little_endian( |
515 | 366k | ( (fsfat_directory_entry_t *) data )->data_size, |
516 | 366k | directory_entry->data_size ); |
517 | | |
518 | | #if defined( HAVE_DEBUG_OUTPUT ) |
519 | | if( libcnotify_verbose != 0 ) |
520 | | { |
521 | | libcnotify_printf( |
522 | | "%s: name\t\t\t\t: %c%c%c%c%c%c%c%c\n", |
523 | | function, |
524 | | ( (fsfat_directory_entry_t *) data )->name[ 0 ], |
525 | | ( (fsfat_directory_entry_t *) data )->name[ 1 ], |
526 | | ( (fsfat_directory_entry_t *) data )->name[ 2 ], |
527 | | ( (fsfat_directory_entry_t *) data )->name[ 3 ], |
528 | | ( (fsfat_directory_entry_t *) data )->name[ 4 ], |
529 | | ( (fsfat_directory_entry_t *) data )->name[ 5 ], |
530 | | ( (fsfat_directory_entry_t *) data )->name[ 6 ], |
531 | | ( (fsfat_directory_entry_t *) data )->name[ 7 ] ); |
532 | | |
533 | | libcnotify_printf( |
534 | | "%s: extension\t\t\t\t: %c%c%c\n", |
535 | | function, |
536 | | ( (fsfat_directory_entry_t *) data )->extension[ 0 ], |
537 | | ( (fsfat_directory_entry_t *) data )->extension[ 1 ], |
538 | | ( (fsfat_directory_entry_t *) data )->extension[ 2 ] ); |
539 | | |
540 | | libcnotify_printf( |
541 | | "%s: file attribute flags\t\t: 0x%02" PRIx16 "\n", |
542 | | function, |
543 | | directory_entry->file_attribute_flags ); |
544 | | libfsfat_debug_print_file_attribute_flags( |
545 | | directory_entry->file_attribute_flags ); |
546 | | libcnotify_printf( |
547 | | "\n" ); |
548 | | |
549 | | libcnotify_printf( |
550 | | "%s: flags\t\t\t\t: 0x%02" PRIx8 "\n", |
551 | | function, |
552 | | ( (fsfat_directory_entry_t *) data )->flags ); |
553 | | |
554 | | if( libfsfat_debug_print_fat_date_time_value( |
555 | | function, |
556 | | "creation time\t\t\t", |
557 | | directory_entry->creation_date, |
558 | | directory_entry->creation_time, |
559 | | directory_entry->creation_time_fraction, |
560 | | 0, |
561 | | LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, |
562 | | error ) != 1 ) |
563 | | { |
564 | | libcerror_error_set( |
565 | | error, |
566 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
567 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
568 | | "%s: unable to print FAT date time value.", |
569 | | function ); |
570 | | |
571 | | return( -1 ); |
572 | | } |
573 | | if( libfsfat_debug_print_fat_date_time_value( |
574 | | function, |
575 | | "access time\t\t\t\t", |
576 | | directory_entry->access_date, |
577 | | 0, |
578 | | 0, |
579 | | 0, |
580 | | LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, |
581 | | error ) != 1 ) |
582 | | { |
583 | | libcerror_error_set( |
584 | | error, |
585 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
586 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
587 | | "%s: unable to print FAT date time value.", |
588 | | function ); |
589 | | |
590 | | return( -1 ); |
591 | | } |
592 | | byte_stream_copy_to_uint16_little_endian( |
593 | | ( (fsfat_directory_entry_t *) data )->data_start_cluster_upper, |
594 | | value_16bit ); |
595 | | |
596 | | if( file_system_format == LIBFSFAT_FILE_SYSTEM_FORMAT_FAT32 ) |
597 | | { |
598 | | libcnotify_printf( |
599 | | "%s: data start cluster (upper)\t\t: %" PRIu16 "\n", |
600 | | function, |
601 | | value_16bit ); |
602 | | } |
603 | | else |
604 | | { |
605 | | libcnotify_printf( |
606 | | "%s: unknown3\t\t\t\t: 0x%04" PRIx16 "\n", |
607 | | function, |
608 | | value_16bit ); |
609 | | } |
610 | | if( libfsfat_debug_print_fat_date_time_value( |
611 | | function, |
612 | | "modification time\t\t\t", |
613 | | directory_entry->modification_date, |
614 | | directory_entry->modification_time, |
615 | | 0, |
616 | | 0, |
617 | | LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, |
618 | | error ) != 1 ) |
619 | | { |
620 | | libcerror_error_set( |
621 | | error, |
622 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
623 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
624 | | "%s: unable to print FAT date time value.", |
625 | | function ); |
626 | | |
627 | | return( -1 ); |
628 | | } |
629 | | byte_stream_copy_to_uint16_little_endian( |
630 | | ( (fsfat_directory_entry_t *) data )->data_start_cluster_lower, |
631 | | value_16bit ); |
632 | | |
633 | | if( file_system_format == LIBFSFAT_FILE_SYSTEM_FORMAT_FAT32 ) |
634 | | { |
635 | | libcnotify_printf( |
636 | | "%s: data start cluster (lower)\t\t: %" PRIu16 "\n", |
637 | | function, |
638 | | value_16bit ); |
639 | | } |
640 | | else |
641 | | { |
642 | | libcnotify_printf( |
643 | | "%s: data start cluster\t\t\t: %" PRIu16 "\n", |
644 | | function, |
645 | | value_16bit ); |
646 | | } |
647 | | libcnotify_printf( |
648 | | "%s: data size\t\t\t\t: %" PRIu64 "\n", |
649 | | function, |
650 | | directory_entry->data_size ); |
651 | | |
652 | | libcnotify_printf( |
653 | | "\n" ); |
654 | | } |
655 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
656 | 366k | } |
657 | 333k | else if( directory_entry->entry_type == LIBFSFAT_DIRECTORY_ENTRY_TYPE_VFAT_LONG_NAME ) |
658 | 7.00k | { |
659 | 7.00k | directory_entry->vfat_sequence_number = ( (fsfat_directory_entry_vfat_t *) data )->sequence_number; |
660 | | |
661 | 7.00k | if( memory_copy( |
662 | 7.00k | directory_entry->name_data, |
663 | 7.00k | ( (fsfat_directory_entry_vfat_t *) data )->first_name_segment, |
664 | 7.00k | 10 ) == NULL ) |
665 | 0 | { |
666 | 0 | libcerror_error_set( |
667 | 0 | error, |
668 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
669 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
670 | 0 | "%s: unable to copy first name segment.", |
671 | 0 | function ); |
672 | |
|
673 | 0 | return( -1 ); |
674 | 0 | } |
675 | 7.00k | if( memory_copy( |
676 | 7.00k | &( directory_entry->name_data[ 10 ] ), |
677 | 7.00k | ( (fsfat_directory_entry_vfat_t *) data )->second_name_segment, |
678 | 7.00k | 12 ) == NULL ) |
679 | 0 | { |
680 | 0 | libcerror_error_set( |
681 | 0 | error, |
682 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
683 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
684 | 0 | "%s: unable to copy second name segment.", |
685 | 0 | function ); |
686 | |
|
687 | 0 | return( -1 ); |
688 | 0 | } |
689 | 7.00k | if( memory_copy( |
690 | 7.00k | &( directory_entry->name_data[ 10 + 12 ] ), |
691 | 7.00k | ( (fsfat_directory_entry_vfat_t *) data )->third_name_segment, |
692 | 7.00k | 4 ) == NULL ) |
693 | 0 | { |
694 | 0 | libcerror_error_set( |
695 | 0 | error, |
696 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
697 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
698 | 0 | "%s: unable to copy third name segment.", |
699 | 0 | function ); |
700 | |
|
701 | 0 | return( -1 ); |
702 | 0 | } |
703 | | #if defined( HAVE_DEBUG_OUTPUT ) |
704 | | if( libcnotify_verbose != 0 ) |
705 | | { |
706 | | libcnotify_printf( |
707 | | "%s: VFAT sequence number\t\t: 0x%02" PRIx8 " (%" PRIu8 ")\n", |
708 | | function, |
709 | | ( (fsfat_directory_entry_vfat_t *) data )->sequence_number, |
710 | | ( (fsfat_directory_entry_vfat_t *) data )->sequence_number & 0x1f ); |
711 | | |
712 | | libcnotify_printf( |
713 | | "%s: first name segment:\n", |
714 | | function ); |
715 | | libcnotify_print_data( |
716 | | ( (fsfat_directory_entry_vfat_t *) data )->first_name_segment, |
717 | | 10, |
718 | | 0 ); |
719 | | |
720 | | libcnotify_printf( |
721 | | "%s: unknown1\t\t\t\t: 0x%02" PRIx8 "\n", |
722 | | function, |
723 | | ( (fsfat_directory_entry_vfat_t *) data )->unknown1 ); |
724 | | |
725 | | libcnotify_printf( |
726 | | "%s: unknown2\t\t\t\t: 0x%02" PRIx8 "\n", |
727 | | function, |
728 | | ( (fsfat_directory_entry_vfat_t *) data )->unknown2 ); |
729 | | |
730 | | libcnotify_printf( |
731 | | "%s: name checksum\t\t\t: 0x%02" PRIx8 "\n", |
732 | | function, |
733 | | ( (fsfat_directory_entry_vfat_t *) data )->name_checksum ); |
734 | | |
735 | | libcnotify_printf( |
736 | | "%s: second name segment:\n", |
737 | | function ); |
738 | | libcnotify_print_data( |
739 | | ( (fsfat_directory_entry_vfat_t *) data )->second_name_segment, |
740 | | 12, |
741 | | 0 ); |
742 | | |
743 | | byte_stream_copy_to_uint16_little_endian( |
744 | | ( (fsfat_directory_entry_vfat_t *) data )->unknown3, |
745 | | value_16bit ); |
746 | | libcnotify_printf( |
747 | | "%s: unknown3\t\t\t\t: 0x%04" PRIx16 "\n", |
748 | | function, |
749 | | value_16bit ); |
750 | | |
751 | | libcnotify_printf( |
752 | | "%s: third name segment:\n", |
753 | | function ); |
754 | | libcnotify_print_data( |
755 | | ( (fsfat_directory_entry_vfat_t *) data )->third_name_segment, |
756 | | 4, |
757 | | 0 ); |
758 | | } |
759 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
760 | 7.00k | } |
761 | 326k | else if( directory_entry->entry_type == LIBFSFAT_DIRECTORY_ENTRY_TYPE_EXFAT_ALLOCATION_BITMAP ) |
762 | 646 | { |
763 | | #if defined( HAVE_DEBUG_OUTPUT ) |
764 | | if( libcnotify_verbose != 0 ) |
765 | | { |
766 | | libcnotify_printf( |
767 | | "%s: entry type\t\t\t\t: 0x%02" PRIx8 " (%s)\n", |
768 | | function, |
769 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->entry_type, |
770 | | libfsfat_debug_print_exfat_directory_entry_type( |
771 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->entry_type ) ); |
772 | | |
773 | | libcnotify_printf( |
774 | | "%s: bitmap flags\t\t\t: 0x%02" PRIx8 "\n", |
775 | | function, |
776 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->bitmap_flags ); |
777 | | |
778 | | libcnotify_printf( |
779 | | "%s: unknown1:\n", |
780 | | function ); |
781 | | libcnotify_print_data( |
782 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->unknown1, |
783 | | 18, |
784 | | 0 ); |
785 | | |
786 | | byte_stream_copy_to_uint32_little_endian( |
787 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->data_start_cluster, |
788 | | value_32bit ); |
789 | | libcnotify_printf( |
790 | | "%s: data start cluster\t\t\t: %" PRIu32 "\n", |
791 | | function, |
792 | | value_32bit ); |
793 | | |
794 | | byte_stream_copy_to_uint64_little_endian( |
795 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->data_size, |
796 | | value_64bit ); |
797 | | libcnotify_printf( |
798 | | "%s: data size\t\t\t\t: %" PRIu64 "\n", |
799 | | function, |
800 | | value_64bit ); |
801 | | |
802 | | libcnotify_printf( |
803 | | "\n" ); |
804 | | } |
805 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
806 | 646 | } |
807 | 326k | else if( directory_entry->entry_type == LIBFSFAT_DIRECTORY_ENTRY_TYPE_EXFAT_DATA_STREAM ) |
808 | 483 | { |
809 | 483 | directory_entry->name_size = ( (fsfat_directory_entry_exfat_volume_label_t *) data )->name_size; |
810 | | |
811 | 483 | byte_stream_copy_to_uint64_little_endian( |
812 | 483 | ( (fsfat_directory_entry_exfat_data_stream_t *) data )->valid_data_size, |
813 | 483 | directory_entry->valid_data_size ); |
814 | | |
815 | 483 | directory_entry->data_stream_flags = ( (fsfat_directory_entry_exfat_data_stream_t *) data )->entry_flags; |
816 | | |
817 | 483 | byte_stream_copy_to_uint32_little_endian( |
818 | 483 | ( (fsfat_directory_entry_exfat_data_stream_t *) data )->data_start_cluster, |
819 | 483 | directory_entry->data_start_cluster ); |
820 | | |
821 | 483 | byte_stream_copy_to_uint64_little_endian( |
822 | 483 | ( (fsfat_directory_entry_exfat_data_stream_t *) data )->data_size, |
823 | 483 | directory_entry->data_size ); |
824 | | |
825 | | #if defined( HAVE_DEBUG_OUTPUT ) |
826 | | if( libcnotify_verbose != 0 ) |
827 | | { |
828 | | libcnotify_printf( |
829 | | "%s: entry type\t\t\t\t: 0x%02" PRIx8 " (%s)\n", |
830 | | function, |
831 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->entry_type, |
832 | | libfsfat_debug_print_exfat_directory_entry_type( |
833 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->entry_type ) ); |
834 | | |
835 | | libcnotify_printf( |
836 | | "%s: entry flags\t\t\t\t: 0x%02" PRIx8 "\n", |
837 | | function, |
838 | | ( (fsfat_directory_entry_exfat_data_stream_t *) data )->entry_flags ); |
839 | | |
840 | | libcnotify_printf( |
841 | | "%s: unknown2\t\t\t\t: 0x%02" PRIx8 "\n", |
842 | | function, |
843 | | ( (fsfat_directory_entry_exfat_data_stream_t *) data )->unknown2 ); |
844 | | |
845 | | libcnotify_printf( |
846 | | "%s: name size\t\t\t\t: %" PRIu16 " (%" PRIu8 " characters)\n", |
847 | | function, |
848 | | (uint16_t) ( (fsfat_directory_entry_exfat_data_stream_t *) data )->name_size * 2, |
849 | | ( (fsfat_directory_entry_exfat_data_stream_t *) data )->name_size ); |
850 | | |
851 | | byte_stream_copy_to_uint16_little_endian( |
852 | | ( (fsfat_directory_entry_exfat_data_stream_t *) data )->name_hash, |
853 | | value_16bit ); |
854 | | libcnotify_printf( |
855 | | "%s: name hash\t\t\t\t: 0x%04" PRIx16 "\n", |
856 | | function, |
857 | | value_16bit ); |
858 | | |
859 | | byte_stream_copy_to_uint16_little_endian( |
860 | | ( (fsfat_directory_entry_exfat_data_stream_t *) data )->unknown3, |
861 | | value_16bit ); |
862 | | libcnotify_printf( |
863 | | "%s: unknown3\t\t\t\t: 0x%04" PRIx16 "\n", |
864 | | function, |
865 | | value_16bit ); |
866 | | |
867 | | libcnotify_printf( |
868 | | "%s: valid data size\t\t\t: %" PRIu64 "\n", |
869 | | function, |
870 | | directory_entry->valid_data_size ); |
871 | | |
872 | | byte_stream_copy_to_uint32_little_endian( |
873 | | ( (fsfat_directory_entry_exfat_data_stream_t *) data )->unknown4, |
874 | | value_32bit ); |
875 | | libcnotify_printf( |
876 | | "%s: unknown4\t\t\t\t: 0x%08" PRIx32 "\n", |
877 | | function, |
878 | | value_32bit ); |
879 | | |
880 | | libcnotify_printf( |
881 | | "%s: data start cluster\t\t\t: %" PRIu32 "\n", |
882 | | function, |
883 | | directory_entry->data_start_cluster ); |
884 | | |
885 | | libcnotify_printf( |
886 | | "%s: data size\t\t\t\t: %" PRIu64 "\n", |
887 | | function, |
888 | | directory_entry->data_size ); |
889 | | |
890 | | libcnotify_printf( |
891 | | "\n" ); |
892 | | } |
893 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
894 | | |
895 | 483 | directory_entry->name_size *= 2; |
896 | 483 | } |
897 | 325k | else if( directory_entry->entry_type == LIBFSFAT_DIRECTORY_ENTRY_TYPE_EXFAT_FILE_ENTRY ) |
898 | 2.45k | { |
899 | 2.45k | byte_stream_copy_to_uint16_little_endian( |
900 | 2.45k | ( (fsfat_directory_entry_exfat_file_entry_t *) data )->file_attribute_flags, |
901 | 2.45k | directory_entry->file_attribute_flags ); |
902 | | |
903 | 2.45k | byte_stream_copy_to_uint16_little_endian( |
904 | 2.45k | ( (fsfat_directory_entry_exfat_file_entry_t *) data )->creation_date, |
905 | 2.45k | directory_entry->creation_date ); |
906 | | |
907 | 2.45k | byte_stream_copy_to_uint16_little_endian( |
908 | 2.45k | ( (fsfat_directory_entry_exfat_file_entry_t *) data )->creation_time, |
909 | 2.45k | directory_entry->creation_time ); |
910 | | |
911 | 2.45k | byte_stream_copy_to_uint16_little_endian( |
912 | 2.45k | ( (fsfat_directory_entry_exfat_file_entry_t *) data )->modification_date, |
913 | 2.45k | directory_entry->modification_date ); |
914 | | |
915 | 2.45k | byte_stream_copy_to_uint16_little_endian( |
916 | 2.45k | ( (fsfat_directory_entry_exfat_file_entry_t *) data )->modification_time, |
917 | 2.45k | directory_entry->modification_time ); |
918 | | |
919 | 2.45k | byte_stream_copy_to_uint16_little_endian( |
920 | 2.45k | ( (fsfat_directory_entry_exfat_file_entry_t *) data )->access_date, |
921 | 2.45k | directory_entry->access_date ); |
922 | | |
923 | 2.45k | byte_stream_copy_to_uint16_little_endian( |
924 | 2.45k | ( (fsfat_directory_entry_exfat_file_entry_t *) data )->access_time, |
925 | 2.45k | directory_entry->access_time ); |
926 | | |
927 | 2.45k | directory_entry->creation_time_fraction = ( (fsfat_directory_entry_exfat_file_entry_t *) data )->creation_time_fraction; |
928 | | |
929 | 2.45k | directory_entry->modification_time_fraction = ( (fsfat_directory_entry_exfat_file_entry_t *) data )->modification_time_fraction; |
930 | | |
931 | 2.45k | directory_entry->creation_time_utc_offset = ( (fsfat_directory_entry_exfat_file_entry_t *) data )->creation_time_utc_offset; |
932 | | |
933 | 2.45k | directory_entry->access_time_utc_offset = ( (fsfat_directory_entry_exfat_file_entry_t *) data )->access_time_utc_offset; |
934 | | |
935 | 2.45k | directory_entry->modification_time_utc_offset = ( (fsfat_directory_entry_exfat_file_entry_t *) data )->modification_time_utc_offset; |
936 | | |
937 | | #if defined( HAVE_DEBUG_OUTPUT ) |
938 | | if( libcnotify_verbose != 0 ) |
939 | | { |
940 | | libcnotify_printf( |
941 | | "%s: entry type\t\t\t\t: 0x%02" PRIx8 " (%s)\n", |
942 | | function, |
943 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->entry_type, |
944 | | libfsfat_debug_print_exfat_directory_entry_type( |
945 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->entry_type ) ); |
946 | | |
947 | | libcnotify_printf( |
948 | | "%s: unknown1\t\t\t\t: 0x%02" PRIx8 "\n", |
949 | | function, |
950 | | ( (fsfat_directory_entry_exfat_file_entry_t *) data )->unknown1 ); |
951 | | |
952 | | byte_stream_copy_to_uint16_little_endian( |
953 | | ( (fsfat_directory_entry_exfat_file_entry_t *) data )->unknown2, |
954 | | value_16bit ); |
955 | | libcnotify_printf( |
956 | | "%s: unknown2\t\t\t\t: 0x%04" PRIx16 "\n", |
957 | | function, |
958 | | value_16bit ); |
959 | | |
960 | | libcnotify_printf( |
961 | | "%s: file attribute flags\t\t: 0x%02" PRIx16 "\n", |
962 | | function, |
963 | | directory_entry->file_attribute_flags ); |
964 | | libfsfat_debug_print_file_attribute_flags( |
965 | | directory_entry->file_attribute_flags ); |
966 | | libcnotify_printf( |
967 | | "\n" ); |
968 | | |
969 | | if( libfsfat_debug_print_fat_date_time_value( |
970 | | function, |
971 | | "creation time\t\t\t", |
972 | | directory_entry->creation_date, |
973 | | directory_entry->creation_time, |
974 | | directory_entry->creation_time_fraction, |
975 | | directory_entry->creation_time_utc_offset, |
976 | | LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, |
977 | | error ) != 1 ) |
978 | | { |
979 | | libcerror_error_set( |
980 | | error, |
981 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
982 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
983 | | "%s: unable to print FAT date time value.", |
984 | | function ); |
985 | | |
986 | | return( -1 ); |
987 | | } |
988 | | if( libfsfat_debug_print_fat_date_time_value( |
989 | | function, |
990 | | "modification time\t\t\t", |
991 | | directory_entry->modification_date, |
992 | | directory_entry->modification_time, |
993 | | directory_entry->modification_time_fraction, |
994 | | directory_entry->modification_time_utc_offset, |
995 | | LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, |
996 | | error ) != 1 ) |
997 | | { |
998 | | libcerror_error_set( |
999 | | error, |
1000 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1001 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
1002 | | "%s: unable to print FAT date time value.", |
1003 | | function ); |
1004 | | |
1005 | | return( -1 ); |
1006 | | } |
1007 | | if( libfsfat_debug_print_fat_date_time_value( |
1008 | | function, |
1009 | | "access time\t\t\t\t", |
1010 | | directory_entry->access_date, |
1011 | | directory_entry->access_time, |
1012 | | 0, |
1013 | | directory_entry->access_time_utc_offset, |
1014 | | LIBFDATETIME_STRING_FORMAT_TYPE_CTIME | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME, |
1015 | | error ) != 1 ) |
1016 | | { |
1017 | | libcerror_error_set( |
1018 | | error, |
1019 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1020 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
1021 | | "%s: unable to print FAT date time value.", |
1022 | | function ); |
1023 | | |
1024 | | return( -1 ); |
1025 | | } |
1026 | | libcnotify_printf( |
1027 | | "%s: unknown4:\n", |
1028 | | function ); |
1029 | | libcnotify_print_data( |
1030 | | ( (fsfat_directory_entry_exfat_file_entry_t *) data )->unknown4, |
1031 | | 7, |
1032 | | 0 ); |
1033 | | } |
1034 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
1035 | 2.45k | } |
1036 | 323k | else if( directory_entry->entry_type == LIBFSFAT_DIRECTORY_ENTRY_TYPE_EXFAT_FILE_ENTRY_NAME ) |
1037 | 4.20k | { |
1038 | 4.20k | if( memory_copy( |
1039 | 4.20k | directory_entry->name_data, |
1040 | 4.20k | ( (fsfat_directory_entry_exfat_file_entry_name_t *) data )->name, |
1041 | 4.20k | 30 ) == NULL ) |
1042 | 0 | { |
1043 | 0 | libcerror_error_set( |
1044 | 0 | error, |
1045 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1046 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
1047 | 0 | "%s: unable to copy exFAT file entry name.", |
1048 | 0 | function ); |
1049 | |
|
1050 | 0 | return( -1 ); |
1051 | 0 | } |
1052 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1053 | | if( libcnotify_verbose != 0 ) |
1054 | | { |
1055 | | libcnotify_printf( |
1056 | | "%s: entry type\t\t\t\t: 0x%02" PRIx8 " (%s)\n", |
1057 | | function, |
1058 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->entry_type, |
1059 | | libfsfat_debug_print_exfat_directory_entry_type( |
1060 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->entry_type ) ); |
1061 | | |
1062 | | libcnotify_printf( |
1063 | | "%s: unknown1\t\t\t\t: 0x%02" PRIx8 "\n", |
1064 | | function, |
1065 | | ( (fsfat_directory_entry_exfat_file_entry_name_t *) data )->unknown1 ); |
1066 | | |
1067 | | libcnotify_printf( |
1068 | | "%s: name data:\n", |
1069 | | function ); |
1070 | | libcnotify_print_data( |
1071 | | ( (fsfat_directory_entry_exfat_file_entry_name_t *) data )->name, |
1072 | | 30, |
1073 | | 0 ); |
1074 | | } |
1075 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
1076 | 4.20k | } |
1077 | 318k | else if( directory_entry->entry_type == LIBFSFAT_DIRECTORY_ENTRY_TYPE_EXFAT_VOLUME_LABEL ) |
1078 | 103 | { |
1079 | 103 | if( memory_copy( |
1080 | 103 | directory_entry->name_data, |
1081 | 103 | ( (fsfat_directory_entry_exfat_volume_label_t *) data )->name, |
1082 | 103 | 22 ) == NULL ) |
1083 | 0 | { |
1084 | 0 | libcerror_error_set( |
1085 | 0 | error, |
1086 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1087 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
1088 | 0 | "%s: unable to copy exFAT volume label name.", |
1089 | 0 | function ); |
1090 | |
|
1091 | 0 | return( -1 ); |
1092 | 0 | } |
1093 | 103 | directory_entry->name_size = ( (fsfat_directory_entry_exfat_volume_label_t *) data )->name_size; |
1094 | | |
1095 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1096 | | if( libcnotify_verbose != 0 ) |
1097 | | { |
1098 | | libcnotify_printf( |
1099 | | "%s: entry type\t\t\t\t: 0x%02" PRIx8 " (%s)\n", |
1100 | | function, |
1101 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->entry_type, |
1102 | | libfsfat_debug_print_exfat_directory_entry_type( |
1103 | | ( (fsfat_directory_entry_exfat_allocation_bitmap_t *) data )->entry_type ) ); |
1104 | | |
1105 | | libcnotify_printf( |
1106 | | "%s: name size\t\t\t\t: %" PRIu16 " (%" PRIu8 " characters)\n", |
1107 | | function, |
1108 | | (uint16_t) ( (fsfat_directory_entry_exfat_volume_label_t *) data )->name_size * 2, |
1109 | | ( (fsfat_directory_entry_exfat_volume_label_t *) data )->name_size ); |
1110 | | |
1111 | | libcnotify_printf( |
1112 | | "%s: name data:\n", |
1113 | | function ); |
1114 | | libcnotify_print_data( |
1115 | | ( (fsfat_directory_entry_exfat_volume_label_t *) data )->name, |
1116 | | 22, |
1117 | | 0 ); |
1118 | | |
1119 | | libcnotify_printf( |
1120 | | "%s: unknown1:\n", |
1121 | | function ); |
1122 | | libcnotify_print_data( |
1123 | | ( (fsfat_directory_entry_exfat_volume_label_t *) data )->unknown1, |
1124 | | 8, |
1125 | | 0 ); |
1126 | | } |
1127 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
1128 | | |
1129 | 103 | if( directory_entry->name_size > 11 ) |
1130 | 12 | { |
1131 | 12 | libcerror_error_set( |
1132 | 12 | error, |
1133 | 12 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1134 | 12 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
1135 | 12 | "%s: invalid exFAT volume label name size value out of bounds.", |
1136 | 12 | function ); |
1137 | | |
1138 | 12 | return( -1 ); |
1139 | 12 | } |
1140 | 91 | directory_entry->name_size *= 2; |
1141 | 91 | } |
1142 | 700k | return( 1 ); |
1143 | 701k | } |
1144 | | |
1145 | | /* Reads a directory entry |
1146 | | * Returns 1 if successful, 0 if empty or -1 on error |
1147 | | */ |
1148 | | int libfsfat_directory_entry_read_file_io_handle( |
1149 | | libfsfat_directory_entry_t *directory_entry, |
1150 | | libbfio_handle_t *file_io_handle, |
1151 | | off64_t file_offset, |
1152 | | uint8_t file_system_format, |
1153 | | libcerror_error_t **error ) |
1154 | 701k | { |
1155 | 701k | uint8_t directory_entry_data[ sizeof( fsfat_directory_entry_t ) ]; |
1156 | | |
1157 | 701k | static char *function = "libfsfat_directory_entry_read_file_io_handle"; |
1158 | 701k | ssize_t read_count = 0; |
1159 | 701k | int result = 0; |
1160 | | |
1161 | 701k | if( directory_entry == NULL ) |
1162 | 0 | { |
1163 | 0 | libcerror_error_set( |
1164 | 0 | error, |
1165 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1166 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1167 | 0 | "%s: invalid directory entry.", |
1168 | 0 | function ); |
1169 | |
|
1170 | 0 | return( -1 ); |
1171 | 0 | } |
1172 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1173 | | if( libcnotify_verbose != 0 ) |
1174 | | { |
1175 | | libcnotify_printf( |
1176 | | "%s: reading directory entry at offset: %" PRIi64 " (0x%08" PRIx64 ").\n", |
1177 | | function, |
1178 | | file_offset, |
1179 | | file_offset ); |
1180 | | } |
1181 | | #endif |
1182 | 701k | read_count = libbfio_handle_read_buffer_at_offset( |
1183 | 701k | file_io_handle, |
1184 | 701k | directory_entry_data, |
1185 | 701k | sizeof( fsfat_directory_entry_t ), |
1186 | 701k | file_offset, |
1187 | 701k | error ); |
1188 | | |
1189 | 701k | if( read_count != (ssize_t) sizeof( fsfat_directory_entry_t ) ) |
1190 | 666 | { |
1191 | 666 | libcerror_error_set( |
1192 | 666 | error, |
1193 | 666 | LIBCERROR_ERROR_DOMAIN_IO, |
1194 | 666 | LIBCERROR_IO_ERROR_READ_FAILED, |
1195 | 666 | "%s: unable to read directory entry data at offset: %" PRIi64 " (0x%08" PRIx64 ").", |
1196 | 666 | function, |
1197 | 666 | file_offset, |
1198 | 666 | file_offset ); |
1199 | | |
1200 | 666 | return( -1 ); |
1201 | 666 | } |
1202 | 701k | result = libfsfat_directory_entry_read_data( |
1203 | 701k | directory_entry, |
1204 | 701k | directory_entry_data, |
1205 | 701k | sizeof( fsfat_directory_entry_t ), |
1206 | 701k | file_system_format, |
1207 | 701k | error ); |
1208 | | |
1209 | 701k | if( result == -1 ) |
1210 | 12 | { |
1211 | 12 | libcerror_error_set( |
1212 | 12 | error, |
1213 | 12 | LIBCERROR_ERROR_DOMAIN_IO, |
1214 | 12 | LIBCERROR_IO_ERROR_READ_FAILED, |
1215 | 12 | "%s: unable to read directory entry.", |
1216 | 12 | function ); |
1217 | | |
1218 | 12 | return( -1 ); |
1219 | 12 | } |
1220 | 701k | return( result ); |
1221 | 701k | } |
1222 | | |
1223 | | /* Retrieves the identifier |
1224 | | * The identifier is the offset of the short name directory entry |
1225 | | * Returns 1 if successful or -1 on error |
1226 | | */ |
1227 | | int libfsfat_directory_entry_get_identifier( |
1228 | | libfsfat_directory_entry_t *directory_entry, |
1229 | | uint64_t *identifier, |
1230 | | libcerror_error_t **error ) |
1231 | 60 | { |
1232 | 60 | static char *function = "libfsfat_directory_entry_get_identifier"; |
1233 | | |
1234 | 60 | if( directory_entry == NULL ) |
1235 | 0 | { |
1236 | 0 | libcerror_error_set( |
1237 | 0 | error, |
1238 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1239 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1240 | 0 | "%s: invalid directory entry.", |
1241 | 0 | function ); |
1242 | |
|
1243 | 0 | return( -1 ); |
1244 | 0 | } |
1245 | 60 | if( identifier == NULL ) |
1246 | 0 | { |
1247 | 0 | libcerror_error_set( |
1248 | 0 | error, |
1249 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1250 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1251 | 0 | "%s: invalid identifier.", |
1252 | 0 | function ); |
1253 | |
|
1254 | 0 | return( -1 ); |
1255 | 0 | } |
1256 | 60 | *identifier = directory_entry->identifier; |
1257 | | |
1258 | 60 | return( 1 ); |
1259 | 60 | } |
1260 | | |
1261 | | /* Retrieves the access date and time |
1262 | | * The timestamp is an unsigned 64-bit integer containing the 10 milli seconds intervals since January 1, 1980 |
1263 | | * Returns 1 if successful or -1 on error |
1264 | | */ |
1265 | | int libfsfat_directory_entry_get_access_time( |
1266 | | libfsfat_directory_entry_t *directory_entry, |
1267 | | uint64_t *fat_timestamp, |
1268 | | libcerror_error_t **error ) |
1269 | 0 | { |
1270 | 0 | static char *function = "libfsfat_directory_entry_get_access_time"; |
1271 | |
|
1272 | 0 | if( directory_entry == NULL ) |
1273 | 0 | { |
1274 | 0 | libcerror_error_set( |
1275 | 0 | error, |
1276 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1277 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1278 | 0 | "%s: invalid directory entry.", |
1279 | 0 | function ); |
1280 | |
|
1281 | 0 | return( -1 ); |
1282 | 0 | } |
1283 | 0 | if( libfsfat_date_time_get_timestamp( |
1284 | 0 | directory_entry->access_date, |
1285 | 0 | directory_entry->access_time, |
1286 | 0 | 0, |
1287 | 0 | directory_entry->access_time_utc_offset, |
1288 | 0 | fat_timestamp, |
1289 | 0 | error ) != 1 ) |
1290 | 0 | { |
1291 | 0 | libcerror_error_set( |
1292 | 0 | error, |
1293 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1294 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1295 | 0 | "%s: unable to retrieve access timestamp.", |
1296 | 0 | function ); |
1297 | |
|
1298 | 0 | return( -1 ); |
1299 | 0 | } |
1300 | 0 | return( 1 ); |
1301 | 0 | } |
1302 | | |
1303 | | /* Retrieves the creation date and time |
1304 | | * The timestamp is an unsigned 64-bit integer containing the 10 milli seconds intervals since January 1, 1980 |
1305 | | * Returns 1 if successful or -1 on error |
1306 | | */ |
1307 | | int libfsfat_directory_entry_get_creation_time( |
1308 | | libfsfat_directory_entry_t *directory_entry, |
1309 | | uint64_t *fat_timestamp, |
1310 | | libcerror_error_t **error ) |
1311 | 0 | { |
1312 | 0 | static char *function = "libfsfat_directory_entry_get_creation_time"; |
1313 | |
|
1314 | 0 | if( directory_entry == NULL ) |
1315 | 0 | { |
1316 | 0 | libcerror_error_set( |
1317 | 0 | error, |
1318 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1319 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1320 | 0 | "%s: invalid directory entry.", |
1321 | 0 | function ); |
1322 | |
|
1323 | 0 | return( -1 ); |
1324 | 0 | } |
1325 | 0 | if( libfsfat_date_time_get_timestamp( |
1326 | 0 | directory_entry->creation_date, |
1327 | 0 | directory_entry->creation_time, |
1328 | 0 | directory_entry->creation_time_fraction, |
1329 | 0 | directory_entry->creation_time_utc_offset, |
1330 | 0 | fat_timestamp, |
1331 | 0 | error ) != 1 ) |
1332 | 0 | { |
1333 | 0 | libcerror_error_set( |
1334 | 0 | error, |
1335 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1336 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1337 | 0 | "%s: unable to retrieve creation timestamp.", |
1338 | 0 | function ); |
1339 | |
|
1340 | 0 | return( -1 ); |
1341 | 0 | } |
1342 | 0 | return( 1 ); |
1343 | 0 | } |
1344 | | |
1345 | | /* Retrieves the modification date and time |
1346 | | * The timestamp is an unsigned 64-bit integer containing the 10 milli seconds intervals since January 1, 1980 |
1347 | | * Returns 1 if successful or -1 on error |
1348 | | */ |
1349 | | int libfsfat_directory_entry_get_modification_time( |
1350 | | libfsfat_directory_entry_t *directory_entry, |
1351 | | uint64_t *fat_timestamp, |
1352 | | libcerror_error_t **error ) |
1353 | 0 | { |
1354 | 0 | static char *function = "libfsfat_directory_entry_get_modification_time"; |
1355 | |
|
1356 | 0 | if( directory_entry == NULL ) |
1357 | 0 | { |
1358 | 0 | libcerror_error_set( |
1359 | 0 | error, |
1360 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1361 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1362 | 0 | "%s: invalid directory entry.", |
1363 | 0 | function ); |
1364 | |
|
1365 | 0 | return( -1 ); |
1366 | 0 | } |
1367 | 0 | if( libfsfat_date_time_get_timestamp( |
1368 | 0 | directory_entry->modification_date, |
1369 | 0 | directory_entry->modification_time, |
1370 | 0 | directory_entry->modification_time_fraction, |
1371 | 0 | directory_entry->modification_time_utc_offset, |
1372 | 0 | fat_timestamp, |
1373 | 0 | error ) != 1 ) |
1374 | 0 | { |
1375 | 0 | libcerror_error_set( |
1376 | 0 | error, |
1377 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1378 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1379 | 0 | "%s: unable to retrieve modification timestamp.", |
1380 | 0 | function ); |
1381 | |
|
1382 | 0 | return( -1 ); |
1383 | 0 | } |
1384 | 0 | return( 1 ); |
1385 | 0 | } |
1386 | | |
1387 | | /* Retrieves the file attribute flags |
1388 | | * Returns 1 if successful or -1 on error |
1389 | | */ |
1390 | | int libfsfat_directory_entry_get_file_attribute_flags( |
1391 | | libfsfat_directory_entry_t *directory_entry, |
1392 | | uint16_t *file_attribute_flags, |
1393 | | libcerror_error_t **error ) |
1394 | 60 | { |
1395 | 60 | static char *function = "libfsfat_directory_entry_get_file_attribute_flags"; |
1396 | | |
1397 | 60 | if( directory_entry == NULL ) |
1398 | 0 | { |
1399 | 0 | libcerror_error_set( |
1400 | 0 | error, |
1401 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1402 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1403 | 0 | "%s: invalid directory entry.", |
1404 | 0 | function ); |
1405 | |
|
1406 | 0 | return( -1 ); |
1407 | 0 | } |
1408 | 60 | if( file_attribute_flags == NULL ) |
1409 | 0 | { |
1410 | 0 | libcerror_error_set( |
1411 | 0 | error, |
1412 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1413 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1414 | 0 | "%s: invalid file attribute flags.", |
1415 | 0 | function ); |
1416 | |
|
1417 | 0 | return( -1 ); |
1418 | 0 | } |
1419 | 60 | *file_attribute_flags = directory_entry->file_attribute_flags; |
1420 | | |
1421 | 60 | return( 1 ); |
1422 | 60 | } |
1423 | | |
1424 | | /* Determines the name |
1425 | | * Returns 1 if successful or -1 on error |
1426 | | */ |
1427 | | int libfsfat_directory_entry_get_name( |
1428 | | libfsfat_directory_entry_t *directory_entry, |
1429 | | libcerror_error_t **error ) |
1430 | 74.0k | { |
1431 | 74.0k | static char *function = "libfsfat_directory_entry_get_name"; |
1432 | 74.0k | size_t name_data_offset = 0; |
1433 | 74.0k | size_t name_data_size = 0; |
1434 | 74.0k | size_t name_offset = 0; |
1435 | 74.0k | size_t name_size = 0; |
1436 | 74.0k | uint8_t byte_value = 0; |
1437 | | |
1438 | 74.0k | if( directory_entry == NULL ) |
1439 | 0 | { |
1440 | 0 | libcerror_error_set( |
1441 | 0 | error, |
1442 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1443 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1444 | 0 | "%s: invalid directory entry.", |
1445 | 0 | function ); |
1446 | |
|
1447 | 0 | return( -1 ); |
1448 | 0 | } |
1449 | 74.0k | if( directory_entry->name != NULL ) |
1450 | 0 | { |
1451 | 0 | libcerror_error_set( |
1452 | 0 | error, |
1453 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1454 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1455 | 0 | "%s: invalid directory entry - name value already set.", |
1456 | 0 | function ); |
1457 | |
|
1458 | 0 | return( -1 ); |
1459 | 0 | } |
1460 | 74.0k | if( directory_entry->name_entries_array != NULL ) |
1461 | 508 | { |
1462 | 508 | if( libfsfat_directory_entry_get_name_from_exfat_file_name_entries( |
1463 | 508 | directory_entry, |
1464 | 508 | directory_entry->name_entries_array, |
1465 | 508 | error ) != 1 ) |
1466 | 51 | { |
1467 | 51 | libcerror_error_set( |
1468 | 51 | error, |
1469 | 51 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1470 | 51 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1471 | 51 | "%s: unable to determine name from exFAT file name entries.", |
1472 | 51 | function ); |
1473 | | |
1474 | 51 | goto on_error; |
1475 | 51 | } |
1476 | 508 | } |
1477 | 73.4k | else if( directory_entry->entry_type == LIBFSFAT_DIRECTORY_ENTRY_TYPE_SHORT_NAME ) |
1478 | 73.4k | { |
1479 | 73.4k | name_size = 8 + 3 + 1; |
1480 | | |
1481 | 73.4k | if( ( directory_entry->file_attribute_flags & LIBFSFAT_FILE_ATTRIBUTE_FLAG_VOLUME_LABEL ) == 0 ) |
1482 | 28.0k | { |
1483 | 28.0k | name_size += 1; |
1484 | 28.0k | } |
1485 | 73.4k | directory_entry->name = (uint8_t *) memory_allocate( |
1486 | 73.4k | sizeof( uint8_t ) * name_size ); |
1487 | | |
1488 | 73.4k | if( directory_entry->name == NULL ) |
1489 | 0 | { |
1490 | 0 | libcerror_error_set( |
1491 | 0 | error, |
1492 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1493 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
1494 | 0 | "%s: unable to create name.", |
1495 | 0 | function ); |
1496 | |
|
1497 | 0 | goto on_error; |
1498 | 0 | } |
1499 | 73.4k | directory_entry->name_size = name_size; |
1500 | | |
1501 | 73.4k | name_data_size = 8; |
1502 | | |
1503 | 73.4k | do |
1504 | 91.6k | { |
1505 | 91.6k | if( directory_entry->name_data[ name_data_size - 1 ] != ' ' ) |
1506 | 72.8k | { |
1507 | 72.8k | break; |
1508 | 72.8k | } |
1509 | 18.7k | name_data_size--; |
1510 | 18.7k | } |
1511 | 73.4k | while( name_data_size > 0 ); |
1512 | | |
1513 | 73.4k | name_offset = 0; |
1514 | | |
1515 | 73.4k | for( name_data_offset = 0; |
1516 | 642k | name_data_offset < name_data_size; |
1517 | 568k | name_data_offset++ ) |
1518 | 568k | { |
1519 | 568k | byte_value = directory_entry->name_data[ name_data_offset ]; |
1520 | | |
1521 | 568k | if( ( ( directory_entry->flags & 0x08 ) != 0 ) |
1522 | 369k | && ( ( byte_value >= 'A' ) && ( byte_value <= 'Z' ) ) ) |
1523 | 5.73k | { |
1524 | 5.73k | byte_value += 0x20; |
1525 | 5.73k | } |
1526 | 568k | directory_entry->name[ name_offset++ ] = byte_value; |
1527 | 568k | } |
1528 | 73.4k | name_data_size = 8 + 3; |
1529 | | |
1530 | 73.4k | do |
1531 | 78.5k | { |
1532 | 78.5k | if( directory_entry->name_data[ name_data_size - 1 ] != ' ' ) |
1533 | 71.9k | { |
1534 | 71.9k | break; |
1535 | 71.9k | } |
1536 | 6.60k | name_data_size--; |
1537 | 6.60k | } |
1538 | 73.4k | while( name_data_size > 8 ); |
1539 | | |
1540 | 73.4k | for( name_data_offset = 8; |
1541 | 287k | name_data_offset < name_data_size; |
1542 | 213k | name_data_offset++ ) |
1543 | 213k | { |
1544 | 213k | if( ( name_data_offset == 8 ) |
1545 | 71.9k | && ( ( directory_entry->file_attribute_flags & LIBFSFAT_FILE_ATTRIBUTE_FLAG_VOLUME_LABEL ) == 0 ) ) |
1546 | 26.7k | { |
1547 | 26.7k | directory_entry->name[ name_offset++ ] = '.'; |
1548 | 26.7k | } |
1549 | 213k | byte_value = directory_entry->name_data[ name_data_offset ]; |
1550 | | |
1551 | 213k | if( ( ( directory_entry->flags & 0x10 ) != 0 ) |
1552 | 185k | && ( ( byte_value >= 'A' ) && ( byte_value <= 'Z' ) ) ) |
1553 | 2.88k | { |
1554 | 2.88k | byte_value += 0x20; |
1555 | 2.88k | } |
1556 | 213k | directory_entry->name[ name_offset++ ] = byte_value; |
1557 | 213k | } |
1558 | 73.4k | directory_entry->name[ name_offset++ ] = 0; |
1559 | 73.4k | directory_entry->name_size = name_offset; |
1560 | 73.4k | directory_entry->is_unicode = 0; |
1561 | | |
1562 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1563 | | if( libcnotify_verbose != 0 ) |
1564 | | { |
1565 | | libcnotify_printf( |
1566 | | "%s: name data:\n", |
1567 | | function ); |
1568 | | libcnotify_print_data( |
1569 | | directory_entry->name, |
1570 | | directory_entry->name_size, |
1571 | | 0 ); |
1572 | | } |
1573 | | #endif |
1574 | 73.4k | } |
1575 | 74 | else if( directory_entry->entry_type == LIBFSFAT_DIRECTORY_ENTRY_TYPE_EXFAT_VOLUME_LABEL ) |
1576 | 74 | { |
1577 | 74 | name_offset = directory_entry->name_size; |
1578 | 74 | name_size = directory_entry->name_size + 2; |
1579 | | |
1580 | 74 | directory_entry->name = (uint8_t *) memory_allocate( |
1581 | 74 | sizeof( uint8_t ) * name_size ); |
1582 | | |
1583 | 74 | if( directory_entry->name == NULL ) |
1584 | 0 | { |
1585 | 0 | libcerror_error_set( |
1586 | 0 | error, |
1587 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1588 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
1589 | 0 | "%s: unable to create name.", |
1590 | 0 | function ); |
1591 | |
|
1592 | 0 | goto on_error; |
1593 | 0 | } |
1594 | 74 | if( memory_copy( |
1595 | 74 | directory_entry->name, |
1596 | 74 | directory_entry->name_data, |
1597 | 74 | directory_entry->name_size ) == NULL ) |
1598 | 0 | { |
1599 | 0 | libcerror_error_set( |
1600 | 0 | error, |
1601 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1602 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
1603 | 0 | "%s: unable to volume label name: %d.", |
1604 | 0 | function ); |
1605 | |
|
1606 | 0 | goto on_error; |
1607 | 0 | } |
1608 | 74 | directory_entry->name[ name_offset ] = 0; |
1609 | 74 | directory_entry->name[ name_offset + 1 ] = 0; |
1610 | 74 | directory_entry->name_size = name_size; |
1611 | 74 | directory_entry->is_unicode = 1; |
1612 | | |
1613 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1614 | | if( libcnotify_verbose != 0 ) |
1615 | | { |
1616 | | libcnotify_printf( |
1617 | | "%s: name data:\n", |
1618 | | function ); |
1619 | | libcnotify_print_data( |
1620 | | directory_entry->name, |
1621 | | directory_entry->name_size, |
1622 | | 0 ); |
1623 | | } |
1624 | | #endif |
1625 | 74 | } |
1626 | 73.9k | return( 1 ); |
1627 | | |
1628 | 51 | on_error: |
1629 | 51 | if( directory_entry->name != NULL ) |
1630 | 0 | { |
1631 | 0 | memory_free( |
1632 | 0 | directory_entry->name ); |
1633 | |
|
1634 | 0 | directory_entry->name = NULL; |
1635 | 0 | } |
1636 | 51 | directory_entry->name_size = 0; |
1637 | | |
1638 | 51 | return( -1 ); |
1639 | 74.0k | } |
1640 | | |
1641 | | /* Determines the name from exFAT file name entries |
1642 | | * Returns 1 if successful or -1 on error |
1643 | | */ |
1644 | | int libfsfat_directory_entry_get_name_from_exfat_file_name_entries( |
1645 | | libfsfat_directory_entry_t *directory_entry, |
1646 | | libcdata_array_t *name_entries_array, |
1647 | | libcerror_error_t **error ) |
1648 | 508 | { |
1649 | 508 | libfsfat_directory_entry_t *name_directory_entry = NULL; |
1650 | 508 | static char *function = "libfsfat_directory_entry_get_name_from_exfat_file_name_entries"; |
1651 | 508 | size_t name_offset = 0; |
1652 | 508 | size_t name_size = 0; |
1653 | 508 | int entry_index = 0; |
1654 | 508 | int number_of_entries = 0; |
1655 | | |
1656 | 508 | if( directory_entry == NULL ) |
1657 | 0 | { |
1658 | 0 | libcerror_error_set( |
1659 | 0 | error, |
1660 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1661 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1662 | 0 | "%s: invalid directory entry.", |
1663 | 0 | function ); |
1664 | |
|
1665 | 0 | return( -1 ); |
1666 | 0 | } |
1667 | 508 | if( directory_entry->name != NULL ) |
1668 | 0 | { |
1669 | 0 | libcerror_error_set( |
1670 | 0 | error, |
1671 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1672 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1673 | 0 | "%s: invalid directory entry - name value already set.", |
1674 | 0 | function ); |
1675 | |
|
1676 | 0 | return( -1 ); |
1677 | 0 | } |
1678 | 508 | if( libcdata_array_get_number_of_entries( |
1679 | 508 | name_entries_array, |
1680 | 508 | &number_of_entries, |
1681 | 508 | error ) != 1 ) |
1682 | 0 | { |
1683 | 0 | libcerror_error_set( |
1684 | 0 | error, |
1685 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1686 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1687 | 0 | "%s: unable to retrieve number of name entries.", |
1688 | 0 | function ); |
1689 | |
|
1690 | 0 | goto on_error; |
1691 | 0 | } |
1692 | 508 | if( ( number_of_entries == 0 ) |
1693 | 467 | || ( number_of_entries > 9 ) ) |
1694 | 51 | { |
1695 | 51 | libcerror_error_set( |
1696 | 51 | error, |
1697 | 51 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1698 | 51 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
1699 | 51 | "%s: invalid number of name entries value out of bounds.", |
1700 | 51 | function ); |
1701 | | |
1702 | 51 | goto on_error; |
1703 | 51 | } |
1704 | 457 | name_size = ( (size_t) 30 * number_of_entries ) + 2; |
1705 | | |
1706 | 457 | directory_entry->name = (uint8_t *) memory_allocate( |
1707 | 457 | sizeof( uint8_t ) * name_size ); |
1708 | | |
1709 | 457 | if( directory_entry->name == NULL ) |
1710 | 0 | { |
1711 | 0 | libcerror_error_set( |
1712 | 0 | error, |
1713 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1714 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
1715 | 0 | "%s: unable to create name.", |
1716 | 0 | function ); |
1717 | |
|
1718 | 0 | goto on_error; |
1719 | 0 | } |
1720 | 457 | directory_entry->name_size = name_size; |
1721 | | |
1722 | 457 | for( entry_index = 0; |
1723 | 2.49k | entry_index < number_of_entries; |
1724 | 2.04k | entry_index++ ) |
1725 | 2.04k | { |
1726 | 2.04k | if( libcdata_array_get_entry_by_index( |
1727 | 2.04k | name_entries_array, |
1728 | 2.04k | entry_index, |
1729 | 2.04k | (intptr_t **) &name_directory_entry, |
1730 | 2.04k | error ) != 1 ) |
1731 | 0 | { |
1732 | 0 | libcerror_error_set( |
1733 | 0 | error, |
1734 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1735 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1736 | 0 | "%s: unable to retrieve directory entry: %d from name entries array.", |
1737 | 0 | function, |
1738 | 0 | entry_index ); |
1739 | |
|
1740 | 0 | goto on_error; |
1741 | 0 | } |
1742 | 2.04k | if( name_directory_entry == NULL ) |
1743 | 0 | { |
1744 | 0 | libcerror_error_set( |
1745 | 0 | error, |
1746 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1747 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1748 | 0 | "%s: invalid name directory entry: %d.", |
1749 | 0 | function, |
1750 | 0 | entry_index ); |
1751 | |
|
1752 | 0 | goto on_error; |
1753 | 0 | } |
1754 | 2.04k | if( memory_copy( |
1755 | 2.04k | &( directory_entry->name[ name_offset ] ), |
1756 | 2.04k | name_directory_entry->name_data, |
1757 | 2.04k | 30 ) == NULL ) |
1758 | 0 | { |
1759 | 0 | libcerror_error_set( |
1760 | 0 | error, |
1761 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1762 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
1763 | 0 | "%s: unable to copy name segment: %d.", |
1764 | 0 | function ); |
1765 | |
|
1766 | 0 | goto on_error; |
1767 | 0 | } |
1768 | 2.04k | name_offset += 30; |
1769 | 2.04k | } |
1770 | 457 | directory_entry->name[ name_offset++ ] = 0; |
1771 | 457 | directory_entry->name[ name_offset++ ] = 0; |
1772 | | |
1773 | 457 | for( name_offset = 0; |
1774 | 20.5k | ( name_offset + 1 ) < directory_entry->name_size; |
1775 | 20.0k | name_offset += 2 ) |
1776 | 20.5k | { |
1777 | 20.5k | if( ( directory_entry->name[ name_offset ] == 0 ) |
1778 | 1.02k | && ( directory_entry->name[ name_offset + 1 ] == 0 ) ) |
1779 | 457 | { |
1780 | 457 | name_offset += 2; |
1781 | 457 | break; |
1782 | 457 | } |
1783 | 20.5k | } |
1784 | 457 | directory_entry->name_size = name_offset; |
1785 | 457 | directory_entry->is_unicode = 1; |
1786 | | |
1787 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1788 | | if( libcnotify_verbose != 0 ) |
1789 | | { |
1790 | | libcnotify_printf( |
1791 | | "%s: name data:\n", |
1792 | | function ); |
1793 | | libcnotify_print_data( |
1794 | | directory_entry->name, |
1795 | | directory_entry->name_size, |
1796 | | 0 ); |
1797 | | } |
1798 | | #endif |
1799 | 457 | return( 1 ); |
1800 | | |
1801 | 51 | on_error: |
1802 | 51 | if( directory_entry->name != NULL ) |
1803 | 0 | { |
1804 | 0 | memory_free( |
1805 | 0 | directory_entry->name ); |
1806 | |
|
1807 | 0 | directory_entry->name = NULL; |
1808 | 0 | } |
1809 | 51 | directory_entry->name_size = 0; |
1810 | | |
1811 | 51 | return( -1 ); |
1812 | 457 | } |
1813 | | |
1814 | | /* Determines the name from VFAT long file name entries |
1815 | | * Returns 1 if successful or -1 on error |
1816 | | */ |
1817 | | int libfsfat_directory_entry_get_name_from_vfat_long_file_name_entries( |
1818 | | libfsfat_directory_entry_t *directory_entry, |
1819 | | libcdata_array_t *name_entries_array, |
1820 | | libcerror_error_t **error ) |
1821 | 2.58k | { |
1822 | 2.58k | libfsfat_directory_entry_t *name_directory_entry = NULL; |
1823 | 2.58k | static char *function = "libfsfat_directory_entry_get_name_from_vfat_long_file_name_entries"; |
1824 | 2.58k | size_t name_offset = 0; |
1825 | 2.58k | size_t name_size = 0; |
1826 | 2.58k | int entry_index = 0; |
1827 | 2.58k | int number_of_entries = 0; |
1828 | | |
1829 | 2.58k | if( directory_entry == NULL ) |
1830 | 0 | { |
1831 | 0 | libcerror_error_set( |
1832 | 0 | error, |
1833 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1834 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1835 | 0 | "%s: invalid directory entry.", |
1836 | 0 | function ); |
1837 | |
|
1838 | 0 | return( -1 ); |
1839 | 0 | } |
1840 | 2.58k | if( directory_entry->name != NULL ) |
1841 | 0 | { |
1842 | 0 | libcerror_error_set( |
1843 | 0 | error, |
1844 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1845 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1846 | 0 | "%s: invalid directory entry - name value already set.", |
1847 | 0 | function ); |
1848 | |
|
1849 | 0 | return( -1 ); |
1850 | 0 | } |
1851 | 2.58k | if( libcdata_array_get_number_of_entries( |
1852 | 2.58k | name_entries_array, |
1853 | 2.58k | &number_of_entries, |
1854 | 2.58k | error ) != 1 ) |
1855 | 0 | { |
1856 | 0 | libcerror_error_set( |
1857 | 0 | error, |
1858 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1859 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1860 | 0 | "%s: unable to retrieve number of long file name entries.", |
1861 | 0 | function ); |
1862 | |
|
1863 | 0 | goto on_error; |
1864 | 0 | } |
1865 | 2.58k | if( ( number_of_entries == 0 ) |
1866 | 2.58k | || ( number_of_entries > 20 ) ) |
1867 | 0 | { |
1868 | 0 | libcerror_error_set( |
1869 | 0 | error, |
1870 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1871 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
1872 | 0 | "%s: invalid number of long file name entries value out of bounds.", |
1873 | 0 | function ); |
1874 | |
|
1875 | 0 | goto on_error; |
1876 | 0 | } |
1877 | 2.58k | name_size = ( (size_t) ( 10 + 12 + 4 ) * number_of_entries ) + 2; |
1878 | | |
1879 | 2.58k | directory_entry->name = (uint8_t *) memory_allocate( |
1880 | 2.58k | sizeof( uint8_t ) * name_size ); |
1881 | | |
1882 | 2.58k | if( directory_entry->name == NULL ) |
1883 | 0 | { |
1884 | 0 | libcerror_error_set( |
1885 | 0 | error, |
1886 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1887 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
1888 | 0 | "%s: unable to create name.", |
1889 | 0 | function ); |
1890 | |
|
1891 | 0 | goto on_error; |
1892 | 0 | } |
1893 | 2.58k | directory_entry->name_size = name_size; |
1894 | | |
1895 | 2.58k | for( entry_index = number_of_entries - 1; |
1896 | 6.48k | entry_index >= 0; |
1897 | 3.90k | entry_index-- ) |
1898 | 3.90k | { |
1899 | 3.90k | if( libcdata_array_get_entry_by_index( |
1900 | 3.90k | name_entries_array, |
1901 | 3.90k | entry_index, |
1902 | 3.90k | (intptr_t **) &name_directory_entry, |
1903 | 3.90k | error ) != 1 ) |
1904 | 0 | { |
1905 | 0 | libcerror_error_set( |
1906 | 0 | error, |
1907 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1908 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1909 | 0 | "%s: unable to retrieve directory entry: %d from long file name entries array.", |
1910 | 0 | function, |
1911 | 0 | entry_index ); |
1912 | |
|
1913 | 0 | goto on_error; |
1914 | 0 | } |
1915 | 3.90k | if( name_directory_entry == NULL ) |
1916 | 0 | { |
1917 | 0 | libcerror_error_set( |
1918 | 0 | error, |
1919 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1920 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1921 | 0 | "%s: invalid long file name directory entry: %d.", |
1922 | 0 | function, |
1923 | 0 | entry_index ); |
1924 | |
|
1925 | 0 | goto on_error; |
1926 | 0 | } |
1927 | 3.90k | if( memory_copy( |
1928 | 3.90k | &( directory_entry->name[ name_offset ] ), |
1929 | 3.90k | name_directory_entry->name_data, |
1930 | 3.90k | 10 + 12 + 4 ) == NULL ) |
1931 | 0 | { |
1932 | 0 | libcerror_error_set( |
1933 | 0 | error, |
1934 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1935 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
1936 | 0 | "%s: unable to copy long file name segment: %d.", |
1937 | 0 | function ); |
1938 | |
|
1939 | 0 | goto on_error; |
1940 | 0 | } |
1941 | 3.90k | name_offset += 10 + 12 + 4; |
1942 | 3.90k | } |
1943 | 2.58k | directory_entry->name[ name_offset++ ] = 0; |
1944 | 2.58k | directory_entry->name[ name_offset++ ] = 0; |
1945 | | |
1946 | | /* TODO determine if name is UCS-2 or ASCII */ |
1947 | | |
1948 | 2.58k | for( name_offset = 0; |
1949 | 13.7k | ( name_offset + 1 ) < directory_entry->name_size; |
1950 | 11.1k | name_offset += 2 ) |
1951 | 13.7k | { |
1952 | 13.7k | if( ( directory_entry->name[ name_offset ] == 0 ) |
1953 | 5.66k | && ( directory_entry->name[ name_offset + 1 ] == 0 ) ) |
1954 | 2.58k | { |
1955 | 2.58k | name_offset += 2; |
1956 | 2.58k | break; |
1957 | 2.58k | } |
1958 | 13.7k | } |
1959 | 2.58k | directory_entry->name_size = name_offset; |
1960 | 2.58k | directory_entry->is_unicode = 1; |
1961 | | |
1962 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1963 | | if( libcnotify_verbose != 0 ) |
1964 | | { |
1965 | | libcnotify_printf( |
1966 | | "%s: name data:\n", |
1967 | | function ); |
1968 | | libcnotify_print_data( |
1969 | | directory_entry->name, |
1970 | | directory_entry->name_size, |
1971 | | 0 ); |
1972 | | } |
1973 | | #endif |
1974 | 2.58k | return( 1 ); |
1975 | | |
1976 | 0 | on_error: |
1977 | 0 | if( directory_entry->name != NULL ) |
1978 | 0 | { |
1979 | 0 | memory_free( |
1980 | 0 | directory_entry->name ); |
1981 | |
|
1982 | 0 | directory_entry->name = NULL; |
1983 | 0 | } |
1984 | 0 | directory_entry->name_size = 0; |
1985 | |
|
1986 | 0 | return( -1 ); |
1987 | 2.58k | } |
1988 | | |
1989 | | /* Retrieves the size of the UTF-8 encoded name |
1990 | | * The returned size includes the end of string character |
1991 | | * Returns 1 if successful, 0 if not available or -1 on error |
1992 | | */ |
1993 | | int libfsfat_directory_entry_get_utf8_name_size( |
1994 | | libfsfat_directory_entry_t *directory_entry, |
1995 | | size_t *utf8_string_size, |
1996 | | libcerror_error_t **error ) |
1997 | 153 | { |
1998 | 153 | static char *function = "libfsfat_directory_entry_get_utf8_name_size"; |
1999 | 153 | int result = 0; |
2000 | | |
2001 | 153 | if( directory_entry == NULL ) |
2002 | 0 | { |
2003 | 0 | libcerror_error_set( |
2004 | 0 | error, |
2005 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2006 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2007 | 0 | "%s: invalid directory entry.", |
2008 | 0 | function ); |
2009 | |
|
2010 | 0 | return( -1 ); |
2011 | 0 | } |
2012 | 153 | if( directory_entry->name == NULL ) |
2013 | 153 | { |
2014 | 153 | if( libfsfat_directory_entry_get_name( |
2015 | 153 | directory_entry, |
2016 | 153 | error ) != 1 ) |
2017 | 0 | { |
2018 | 0 | libcerror_error_set( |
2019 | 0 | error, |
2020 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2021 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2022 | 0 | "%s: unable to determine name.", |
2023 | 0 | function ); |
2024 | |
|
2025 | 0 | return( -1 ); |
2026 | 0 | } |
2027 | 153 | } |
2028 | 153 | if( directory_entry->is_unicode != 0 ) |
2029 | 74 | { |
2030 | 74 | result = libuna_utf8_string_size_from_utf16_stream( |
2031 | 74 | directory_entry->name, |
2032 | 74 | directory_entry->name_size, |
2033 | 74 | LIBUNA_ENDIAN_LITTLE, |
2034 | 74 | utf8_string_size, |
2035 | 74 | error ); |
2036 | 74 | } |
2037 | 79 | else |
2038 | 79 | { |
2039 | | /* TODO add codepage support */ |
2040 | 79 | result = libuna_utf8_string_size_from_byte_stream( |
2041 | 79 | directory_entry->name, |
2042 | 79 | directory_entry->name_size, |
2043 | 79 | LIBUNA_CODEPAGE_ASCII, |
2044 | 79 | utf8_string_size, |
2045 | 79 | error ); |
2046 | 79 | } |
2047 | 153 | if( result != 1 ) |
2048 | 17 | { |
2049 | 17 | libcerror_error_set( |
2050 | 17 | error, |
2051 | 17 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2052 | 17 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2053 | 17 | "%s: unable to retrieve UTF-8 string size.", |
2054 | 17 | function ); |
2055 | | |
2056 | 17 | return( -1 ); |
2057 | 17 | } |
2058 | 136 | return( 1 ); |
2059 | 153 | } |
2060 | | |
2061 | | /* Retrieves the UTF-8 encoded name |
2062 | | * The size should include the end of string character |
2063 | | * Returns 1 if successful, 0 if not available or -1 on error |
2064 | | */ |
2065 | | int libfsfat_directory_entry_get_utf8_name( |
2066 | | libfsfat_directory_entry_t *directory_entry, |
2067 | | uint8_t *utf8_string, |
2068 | | size_t utf8_string_size, |
2069 | | libcerror_error_t **error ) |
2070 | 136 | { |
2071 | 136 | static char *function = "libfsfat_directory_entry_get_utf8_name"; |
2072 | 136 | int result = 0; |
2073 | | |
2074 | 136 | if( directory_entry == NULL ) |
2075 | 0 | { |
2076 | 0 | libcerror_error_set( |
2077 | 0 | error, |
2078 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2079 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2080 | 0 | "%s: invalid directory entry.", |
2081 | 0 | function ); |
2082 | |
|
2083 | 0 | return( -1 ); |
2084 | 0 | } |
2085 | 136 | if( directory_entry->name == NULL ) |
2086 | 0 | { |
2087 | 0 | if( libfsfat_directory_entry_get_name( |
2088 | 0 | directory_entry, |
2089 | 0 | error ) != 1 ) |
2090 | 0 | { |
2091 | 0 | libcerror_error_set( |
2092 | 0 | error, |
2093 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2094 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2095 | 0 | "%s: unable to determine name.", |
2096 | 0 | function ); |
2097 | |
|
2098 | 0 | return( -1 ); |
2099 | 0 | } |
2100 | 0 | } |
2101 | 136 | if( directory_entry->is_unicode != 0 ) |
2102 | 57 | { |
2103 | 57 | result = libuna_utf8_string_copy_from_utf16_stream( |
2104 | 57 | utf8_string, |
2105 | 57 | utf8_string_size, |
2106 | 57 | directory_entry->name, |
2107 | 57 | directory_entry->name_size, |
2108 | 57 | LIBUNA_ENDIAN_LITTLE, |
2109 | 57 | error ); |
2110 | 57 | } |
2111 | 79 | else |
2112 | 79 | { |
2113 | | /* TODO add codepage support */ |
2114 | 79 | result = libuna_utf8_string_copy_from_byte_stream( |
2115 | 79 | utf8_string, |
2116 | 79 | utf8_string_size, |
2117 | 79 | directory_entry->name, |
2118 | 79 | directory_entry->name_size, |
2119 | 79 | LIBUNA_CODEPAGE_ASCII, |
2120 | 79 | error ); |
2121 | 79 | } |
2122 | 136 | if( result != 1 ) |
2123 | 0 | { |
2124 | 0 | libcerror_error_set( |
2125 | 0 | error, |
2126 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2127 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2128 | 0 | "%s: unable to retrieve UTF-8 string.", |
2129 | 0 | function ); |
2130 | |
|
2131 | 0 | return( -1 ); |
2132 | 0 | } |
2133 | 136 | return( 1 ); |
2134 | 136 | } |
2135 | | |
2136 | | /* Compares an UTF-8 string with the name of the directory entry |
2137 | | * Returns LIBUNA_COMPARE_LESS, LIBUNA_COMPARE_EQUAL, LIBUNA_COMPARE_GREATER if successful or -1 on error |
2138 | | */ |
2139 | | int libfsfat_directory_entry_compare_with_utf8_string( |
2140 | | libfsfat_directory_entry_t *directory_entry, |
2141 | | const uint8_t *utf8_string, |
2142 | | size_t utf8_string_length, |
2143 | | libcerror_error_t **error ) |
2144 | 74.2k | { |
2145 | 74.2k | static char *function = "libfsfat_directory_entry_compare_with_utf8_string"; |
2146 | 74.2k | int result = 0; |
2147 | | |
2148 | 74.2k | if( directory_entry == NULL ) |
2149 | 0 | { |
2150 | 0 | libcerror_error_set( |
2151 | 0 | error, |
2152 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2153 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2154 | 0 | "%s: invalid directory entry.", |
2155 | 0 | function ); |
2156 | |
|
2157 | 0 | return( -1 ); |
2158 | 0 | } |
2159 | 74.2k | if( directory_entry->name == NULL ) |
2160 | 73.8k | { |
2161 | 73.8k | if( libfsfat_directory_entry_get_name( |
2162 | 73.8k | directory_entry, |
2163 | 73.8k | error ) != 1 ) |
2164 | 51 | { |
2165 | 51 | libcerror_error_set( |
2166 | 51 | error, |
2167 | 51 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2168 | 51 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2169 | 51 | "%s: unable to determine name.", |
2170 | 51 | function ); |
2171 | | |
2172 | 51 | return( -1 ); |
2173 | 51 | } |
2174 | 73.8k | } |
2175 | | /* TODO add compare of both long and short name */ |
2176 | | /* TODO add codepage support */ |
2177 | 74.2k | result = libfsfat_name_compare_with_utf8_string( |
2178 | 74.2k | directory_entry->name, |
2179 | 74.2k | directory_entry->name_size, |
2180 | 74.2k | directory_entry->is_unicode, |
2181 | 74.2k | utf8_string, |
2182 | 74.2k | utf8_string_length, |
2183 | 74.2k | 1, |
2184 | 74.2k | error ); |
2185 | | |
2186 | 74.2k | if( result == -1 ) |
2187 | 18 | { |
2188 | 18 | libcerror_error_set( |
2189 | 18 | error, |
2190 | 18 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2191 | 18 | LIBCERROR_RUNTIME_ERROR_GENERIC, |
2192 | 18 | "%s: unable to compare UTF-8 string with directory entry name.", |
2193 | 18 | function ); |
2194 | | |
2195 | 18 | return( -1 ); |
2196 | 18 | } |
2197 | 74.2k | return( result ); |
2198 | 74.2k | } |
2199 | | |
2200 | | /* Retrieves the size of the UTF-16 encoded name |
2201 | | * The returned size includes the end of string character |
2202 | | * Returns 1 if successful, 0 if not available or -1 on error |
2203 | | */ |
2204 | | int libfsfat_directory_entry_get_utf16_name_size( |
2205 | | libfsfat_directory_entry_t *directory_entry, |
2206 | | size_t *utf16_string_size, |
2207 | | libcerror_error_t **error ) |
2208 | 136 | { |
2209 | 136 | static char *function = "libfsfat_directory_entry_get_utf16_name_size"; |
2210 | 136 | int result = 0; |
2211 | | |
2212 | 136 | if( directory_entry == NULL ) |
2213 | 0 | { |
2214 | 0 | libcerror_error_set( |
2215 | 0 | error, |
2216 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2217 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2218 | 0 | "%s: invalid directory entry.", |
2219 | 0 | function ); |
2220 | |
|
2221 | 0 | return( -1 ); |
2222 | 0 | } |
2223 | 136 | if( directory_entry->name == NULL ) |
2224 | 0 | { |
2225 | 0 | if( libfsfat_directory_entry_get_name( |
2226 | 0 | directory_entry, |
2227 | 0 | error ) != 1 ) |
2228 | 0 | { |
2229 | 0 | libcerror_error_set( |
2230 | 0 | error, |
2231 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2232 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2233 | 0 | "%s: unable to determine name.", |
2234 | 0 | function ); |
2235 | |
|
2236 | 0 | return( -1 ); |
2237 | 0 | } |
2238 | 0 | } |
2239 | 136 | if( directory_entry->is_unicode != 0 ) |
2240 | 57 | { |
2241 | 57 | result = libuna_utf16_string_size_from_utf16_stream( |
2242 | 57 | directory_entry->name, |
2243 | 57 | directory_entry->name_size, |
2244 | 57 | LIBUNA_ENDIAN_LITTLE, |
2245 | 57 | utf16_string_size, |
2246 | 57 | error ); |
2247 | 57 | } |
2248 | 79 | else |
2249 | 79 | { |
2250 | | /* TODO add codepage support */ |
2251 | 79 | result = libuna_utf16_string_size_from_byte_stream( |
2252 | 79 | directory_entry->name, |
2253 | 79 | directory_entry->name_size, |
2254 | 79 | LIBUNA_CODEPAGE_ASCII, |
2255 | 79 | utf16_string_size, |
2256 | 79 | error ); |
2257 | 79 | } |
2258 | 136 | if( result != 1 ) |
2259 | 0 | { |
2260 | 0 | libcerror_error_set( |
2261 | 0 | error, |
2262 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2263 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2264 | 0 | "%s: unable to retrieve UTF-16 string size.", |
2265 | 0 | function ); |
2266 | |
|
2267 | 0 | return( -1 ); |
2268 | 0 | } |
2269 | 136 | return( 1 ); |
2270 | 136 | } |
2271 | | |
2272 | | /* Retrieves the UTF-16 encoded name |
2273 | | * The size should include the end of string character |
2274 | | * Returns 1 if successful, 0 if not available or -1 on error |
2275 | | */ |
2276 | | int libfsfat_directory_entry_get_utf16_name( |
2277 | | libfsfat_directory_entry_t *directory_entry, |
2278 | | uint16_t *utf16_string, |
2279 | | size_t utf16_string_size, |
2280 | | libcerror_error_t **error ) |
2281 | 136 | { |
2282 | 136 | static char *function = "libfsfat_directory_entry_get_utf16_name"; |
2283 | 136 | int result = 0; |
2284 | | |
2285 | 136 | if( directory_entry == NULL ) |
2286 | 0 | { |
2287 | 0 | libcerror_error_set( |
2288 | 0 | error, |
2289 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2290 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2291 | 0 | "%s: invalid directory entry.", |
2292 | 0 | function ); |
2293 | |
|
2294 | 0 | return( -1 ); |
2295 | 0 | } |
2296 | 136 | if( directory_entry->name == NULL ) |
2297 | 0 | { |
2298 | 0 | if( libfsfat_directory_entry_get_name( |
2299 | 0 | directory_entry, |
2300 | 0 | error ) != 1 ) |
2301 | 0 | { |
2302 | 0 | libcerror_error_set( |
2303 | 0 | error, |
2304 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2305 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2306 | 0 | "%s: unable to determine name.", |
2307 | 0 | function ); |
2308 | |
|
2309 | 0 | return( -1 ); |
2310 | 0 | } |
2311 | 0 | } |
2312 | 136 | if( directory_entry->is_unicode != 0 ) |
2313 | 57 | { |
2314 | 57 | result = libuna_utf16_string_copy_from_utf16_stream( |
2315 | 57 | utf16_string, |
2316 | 57 | utf16_string_size, |
2317 | 57 | directory_entry->name, |
2318 | 57 | directory_entry->name_size, |
2319 | 57 | LIBUNA_ENDIAN_LITTLE, |
2320 | 57 | error ); |
2321 | 57 | } |
2322 | 79 | else |
2323 | 79 | { |
2324 | | /* TODO add codepage support */ |
2325 | 79 | result = libuna_utf16_string_copy_from_byte_stream( |
2326 | 79 | utf16_string, |
2327 | 79 | utf16_string_size, |
2328 | 79 | directory_entry->name, |
2329 | 79 | directory_entry->name_size, |
2330 | 79 | LIBUNA_CODEPAGE_ASCII, |
2331 | 79 | error ); |
2332 | 79 | } |
2333 | 136 | if( result != 1 ) |
2334 | 0 | { |
2335 | 0 | libcerror_error_set( |
2336 | 0 | error, |
2337 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2338 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2339 | 0 | "%s: unable to retrieve UTF-16 string.", |
2340 | 0 | function ); |
2341 | |
|
2342 | 0 | return( -1 ); |
2343 | 0 | } |
2344 | 136 | return( 1 ); |
2345 | 136 | } |
2346 | | |
2347 | | /* Compares an UTF-16 string with the name of the directory entry |
2348 | | * Returns LIBUNA_COMPARE_LESS, LIBUNA_COMPARE_EQUAL, LIBUNA_COMPARE_GREATER if successful or -1 on error |
2349 | | */ |
2350 | | int libfsfat_directory_entry_compare_with_utf16_string( |
2351 | | libfsfat_directory_entry_t *directory_entry, |
2352 | | const uint16_t *utf16_string, |
2353 | | size_t utf16_string_length, |
2354 | | libcerror_error_t **error ) |
2355 | 73.9k | { |
2356 | 73.9k | static char *function = "libfsfat_directory_entry_compare_with_utf16_string"; |
2357 | 73.9k | int result = 0; |
2358 | | |
2359 | 73.9k | if( directory_entry == NULL ) |
2360 | 0 | { |
2361 | 0 | libcerror_error_set( |
2362 | 0 | error, |
2363 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2364 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2365 | 0 | "%s: invalid directory entry.", |
2366 | 0 | function ); |
2367 | |
|
2368 | 0 | return( -1 ); |
2369 | 0 | } |
2370 | 73.9k | if( directory_entry->name == NULL ) |
2371 | 0 | { |
2372 | 0 | if( libfsfat_directory_entry_get_name( |
2373 | 0 | directory_entry, |
2374 | 0 | error ) != 1 ) |
2375 | 0 | { |
2376 | 0 | libcerror_error_set( |
2377 | 0 | error, |
2378 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2379 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2380 | 0 | "%s: unable to determine name.", |
2381 | 0 | function ); |
2382 | |
|
2383 | 0 | return( -1 ); |
2384 | 0 | } |
2385 | 0 | } |
2386 | | /* TODO add compare of both long and short name */ |
2387 | | /* TODO add codepage support */ |
2388 | 73.9k | result = libfsfat_name_compare_with_utf16_string( |
2389 | 73.9k | directory_entry->name, |
2390 | 73.9k | directory_entry->name_size, |
2391 | 73.9k | directory_entry->is_unicode, |
2392 | 73.9k | utf16_string, |
2393 | 73.9k | utf16_string_length, |
2394 | 73.9k | 1, |
2395 | 73.9k | error ); |
2396 | | |
2397 | 73.9k | if( result == -1 ) |
2398 | 0 | { |
2399 | 0 | libcerror_error_set( |
2400 | 0 | error, |
2401 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2402 | 0 | LIBCERROR_RUNTIME_ERROR_GENERIC, |
2403 | 0 | "%s: unable to compare UTF-16 string with directory entry name.", |
2404 | 0 | function ); |
2405 | |
|
2406 | 0 | return( -1 ); |
2407 | 0 | } |
2408 | 73.9k | return( result ); |
2409 | 73.9k | } |
2410 | | |
2411 | | /* Retrieves the data start cluster |
2412 | | * Returns 1 if successful or -1 on error |
2413 | | */ |
2414 | | int libfsfat_directory_entry_get_data_start_cluster( |
2415 | | libfsfat_directory_entry_t *directory_entry, |
2416 | | uint32_t *data_start_cluster, |
2417 | | libcerror_error_t **error ) |
2418 | 190 | { |
2419 | 190 | static char *function = "libfsfat_directory_entry_get_data_start_cluster"; |
2420 | | |
2421 | 190 | if( directory_entry == NULL ) |
2422 | 0 | { |
2423 | 0 | libcerror_error_set( |
2424 | 0 | error, |
2425 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2426 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2427 | 0 | "%s: invalid directory entry.", |
2428 | 0 | function ); |
2429 | |
|
2430 | 0 | return( -1 ); |
2431 | 0 | } |
2432 | 190 | if( data_start_cluster == NULL ) |
2433 | 0 | { |
2434 | 0 | libcerror_error_set( |
2435 | 0 | error, |
2436 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2437 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2438 | 0 | "%s: invalid data start cluster.", |
2439 | 0 | function ); |
2440 | |
|
2441 | 0 | return( -1 ); |
2442 | 0 | } |
2443 | 190 | *data_start_cluster = directory_entry->data_start_cluster; |
2444 | | |
2445 | 190 | return( 1 ); |
2446 | 190 | } |
2447 | | |
2448 | | /* Retrieves the data size |
2449 | | * Returns 1 if successful or -1 on error |
2450 | | */ |
2451 | | int libfsfat_directory_entry_get_data_size( |
2452 | | libfsfat_directory_entry_t *directory_entry, |
2453 | | uint64_t *data_size, |
2454 | | libcerror_error_t **error ) |
2455 | 60 | { |
2456 | 60 | static char *function = "libfsfat_directory_entry_get_data_size"; |
2457 | | |
2458 | 60 | if( directory_entry == NULL ) |
2459 | 0 | { |
2460 | 0 | libcerror_error_set( |
2461 | 0 | error, |
2462 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2463 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2464 | 0 | "%s: invalid directory entry.", |
2465 | 0 | function ); |
2466 | |
|
2467 | 0 | return( -1 ); |
2468 | 0 | } |
2469 | 60 | if( data_size == NULL ) |
2470 | 0 | { |
2471 | 0 | libcerror_error_set( |
2472 | 0 | error, |
2473 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2474 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2475 | 0 | "%s: invalid data size.", |
2476 | 0 | function ); |
2477 | |
|
2478 | 0 | return( -1 ); |
2479 | 0 | } |
2480 | 60 | *data_size = directory_entry->data_size; |
2481 | | |
2482 | 60 | return( 1 ); |
2483 | 60 | } |
2484 | | |
2485 | | /* Retrieves the valid data size |
2486 | | * Returns 1 if successful or -1 on error |
2487 | | */ |
2488 | | int libfsfat_directory_entry_get_valid_data_size( |
2489 | | libfsfat_directory_entry_t *directory_entry, |
2490 | | uint64_t *valid_data_size, |
2491 | | libcerror_error_t **error ) |
2492 | 60 | { |
2493 | 60 | static char *function = "libfsfat_directory_entry_get_valid_data_size"; |
2494 | | |
2495 | 60 | if( directory_entry == NULL ) |
2496 | 0 | { |
2497 | 0 | libcerror_error_set( |
2498 | 0 | error, |
2499 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2500 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2501 | 0 | "%s: invalid directory entry.", |
2502 | 0 | function ); |
2503 | |
|
2504 | 0 | return( -1 ); |
2505 | 0 | } |
2506 | 60 | if( valid_data_size == NULL ) |
2507 | 0 | { |
2508 | 0 | libcerror_error_set( |
2509 | 0 | error, |
2510 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2511 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2512 | 0 | "%s: invalid valid data size.", |
2513 | 0 | function ); |
2514 | |
|
2515 | 0 | return( -1 ); |
2516 | 0 | } |
2517 | 60 | *valid_data_size = directory_entry->valid_data_size; |
2518 | | |
2519 | 60 | return( 1 ); |
2520 | 60 | } |
2521 | | |