/src/libfsext/libfsext/libfsext_directory_entry.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Directory entry functions |
3 | | * |
4 | | * Copyright (C) 2010-2023, 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 "libfsext_debug.h" |
28 | | #include "libfsext_directory_entry.h" |
29 | | #include "libfsext_libcerror.h" |
30 | | #include "libfsext_libcnotify.h" |
31 | | #include "libfsext_libuna.h" |
32 | | |
33 | | #include "fsext_directory_entry.h" |
34 | | |
35 | | /* Creates a directory entry |
36 | | * Make sure the value directory_entry is referencing, is set to NULL |
37 | | * Returns 1 if successful or -1 on error |
38 | | */ |
39 | | int libfsext_directory_entry_initialize( |
40 | | libfsext_directory_entry_t **directory_entry, |
41 | | libcerror_error_t **error ) |
42 | 51.5k | { |
43 | 51.5k | static char *function = "libfsext_directory_entry_initialize"; |
44 | | |
45 | 51.5k | if( directory_entry == NULL ) |
46 | 0 | { |
47 | 0 | libcerror_error_set( |
48 | 0 | error, |
49 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
50 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
51 | 0 | "%s: invalid directory entry.", |
52 | 0 | function ); |
53 | |
|
54 | 0 | return( -1 ); |
55 | 0 | } |
56 | 51.5k | if( *directory_entry != NULL ) |
57 | 0 | { |
58 | 0 | libcerror_error_set( |
59 | 0 | error, |
60 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
61 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
62 | 0 | "%s: invalid directory entry value already set.", |
63 | 0 | function ); |
64 | |
|
65 | 0 | return( -1 ); |
66 | 0 | } |
67 | 51.5k | *directory_entry = memory_allocate_structure( |
68 | 51.5k | libfsext_directory_entry_t ); |
69 | | |
70 | 51.5k | if( *directory_entry == NULL ) |
71 | 0 | { |
72 | 0 | libcerror_error_set( |
73 | 0 | error, |
74 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
75 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
76 | 0 | "%s: unable to create directory entry.", |
77 | 0 | function ); |
78 | |
|
79 | 0 | goto on_error; |
80 | 0 | } |
81 | 51.5k | if( memory_set( |
82 | 51.5k | *directory_entry, |
83 | 51.5k | 0, |
84 | 51.5k | sizeof( libfsext_directory_entry_t ) ) == NULL ) |
85 | 0 | { |
86 | 0 | libcerror_error_set( |
87 | 0 | error, |
88 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
89 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
90 | 0 | "%s: unable to clear directory entry.", |
91 | 0 | function ); |
92 | |
|
93 | 0 | goto on_error; |
94 | 0 | } |
95 | 51.5k | return( 1 ); |
96 | | |
97 | 0 | on_error: |
98 | 0 | if( *directory_entry != NULL ) |
99 | 0 | { |
100 | 0 | memory_free( |
101 | 0 | *directory_entry ); |
102 | |
|
103 | 0 | *directory_entry = NULL; |
104 | 0 | } |
105 | 0 | return( -1 ); |
106 | 51.5k | } |
107 | | |
108 | | /* Frees a directory entry |
109 | | * Returns 1 if successful or -1 on error |
110 | | */ |
111 | | int libfsext_directory_entry_free( |
112 | | libfsext_directory_entry_t **directory_entry, |
113 | | libcerror_error_t **error ) |
114 | 52.2k | { |
115 | 52.2k | static char *function = "libfsext_directory_entry_free"; |
116 | | |
117 | 52.2k | if( directory_entry == NULL ) |
118 | 0 | { |
119 | 0 | libcerror_error_set( |
120 | 0 | error, |
121 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
122 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
123 | 0 | "%s: invalid directory entry.", |
124 | 0 | function ); |
125 | |
|
126 | 0 | return( -1 ); |
127 | 0 | } |
128 | 52.2k | if( *directory_entry != NULL ) |
129 | 52.2k | { |
130 | 52.2k | if( ( *directory_entry )->name != NULL ) |
131 | 42.8k | { |
132 | 42.8k | memory_free( |
133 | 42.8k | ( *directory_entry )->name ); |
134 | 42.8k | } |
135 | 52.2k | memory_free( |
136 | 52.2k | *directory_entry ); |
137 | | |
138 | 52.2k | *directory_entry = NULL; |
139 | 52.2k | } |
140 | 52.2k | return( 1 ); |
141 | 52.2k | } |
142 | | |
143 | | /* Clones a directory entry |
144 | | * Returns 1 if successful or -1 on error |
145 | | */ |
146 | | int libfsext_directory_entry_clone( |
147 | | libfsext_directory_entry_t **destination_directory_entry, |
148 | | libfsext_directory_entry_t *source_directory_entry, |
149 | | libcerror_error_t **error ) |
150 | 729 | { |
151 | 729 | static char *function = "libfsext_directory_entry_clone"; |
152 | | |
153 | 729 | if( destination_directory_entry == NULL ) |
154 | 0 | { |
155 | 0 | libcerror_error_set( |
156 | 0 | error, |
157 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
158 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
159 | 0 | "%s: invalid directory entry.", |
160 | 0 | function ); |
161 | |
|
162 | 0 | return( -1 ); |
163 | 0 | } |
164 | 729 | if( *destination_directory_entry != NULL ) |
165 | 0 | { |
166 | 0 | libcerror_error_set( |
167 | 0 | error, |
168 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
169 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
170 | 0 | "%s: invalid destination directory entry value already set.", |
171 | 0 | function ); |
172 | |
|
173 | 0 | return( -1 ); |
174 | 0 | } |
175 | 729 | if( source_directory_entry == NULL ) |
176 | 0 | { |
177 | 0 | *destination_directory_entry = source_directory_entry; |
178 | |
|
179 | 0 | return( 1 ); |
180 | 0 | } |
181 | 729 | *destination_directory_entry = memory_allocate_structure( |
182 | 729 | libfsext_directory_entry_t ); |
183 | | |
184 | 729 | if( *destination_directory_entry == NULL ) |
185 | 0 | { |
186 | 0 | libcerror_error_set( |
187 | 0 | error, |
188 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
189 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
190 | 0 | "%s: unable to create destination directory entry.", |
191 | 0 | function ); |
192 | |
|
193 | 0 | goto on_error; |
194 | 0 | } |
195 | 729 | if( memory_copy( |
196 | 729 | *destination_directory_entry, |
197 | 729 | source_directory_entry, |
198 | 729 | sizeof( libfsext_directory_entry_t ) ) == NULL ) |
199 | 0 | { |
200 | 0 | libcerror_error_set( |
201 | 0 | error, |
202 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
203 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
204 | 0 | "%s: unable to copy directory entry.", |
205 | 0 | function ); |
206 | |
|
207 | 0 | ( *destination_directory_entry )->name = NULL; |
208 | |
|
209 | 0 | goto on_error; |
210 | 0 | } |
211 | 729 | ( *destination_directory_entry )->name = (uint8_t *) memory_allocate( |
212 | 729 | sizeof( uint8_t ) * source_directory_entry->name_size ); |
213 | | |
214 | 729 | if( ( *destination_directory_entry )->name == NULL ) |
215 | 0 | { |
216 | 0 | libcerror_error_set( |
217 | 0 | error, |
218 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
219 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
220 | 0 | "%s: unable to create name.", |
221 | 0 | function ); |
222 | |
|
223 | 0 | goto on_error; |
224 | 0 | } |
225 | 729 | if( memory_copy( |
226 | 729 | ( *destination_directory_entry )->name, |
227 | 729 | source_directory_entry->name, |
228 | 729 | source_directory_entry->name_size ) == NULL ) |
229 | 0 | { |
230 | 0 | libcerror_error_set( |
231 | 0 | error, |
232 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
233 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
234 | 0 | "%s: unable to copy name.", |
235 | 0 | function ); |
236 | |
|
237 | 0 | goto on_error; |
238 | 0 | } |
239 | 729 | return( 1 ); |
240 | | |
241 | 0 | on_error: |
242 | 0 | if( *destination_directory_entry != NULL ) |
243 | 0 | { |
244 | 0 | if( ( *destination_directory_entry )->name != NULL ) |
245 | 0 | { |
246 | 0 | memory_free( |
247 | 0 | ( *destination_directory_entry )->name ); |
248 | 0 | } |
249 | 0 | memory_free( |
250 | 0 | *destination_directory_entry ); |
251 | |
|
252 | 0 | *destination_directory_entry = NULL; |
253 | 0 | } |
254 | 0 | return( -1 ); |
255 | 729 | } |
256 | | |
257 | | /* Reads the directory entry data |
258 | | * Returns 1 if successful or -1 on error |
259 | | */ |
260 | | int libfsext_directory_entry_read_data( |
261 | | libfsext_directory_entry_t *directory_entry, |
262 | | const uint8_t *data, |
263 | | size_t data_size, |
264 | | libcerror_error_t **error ) |
265 | 51.5k | { |
266 | 51.5k | static char *function = "libfsext_directory_entry_read_data"; |
267 | 51.5k | size_t data_offset = 0; |
268 | 51.5k | uint8_t name_size = 0; |
269 | | |
270 | 51.5k | if( directory_entry == NULL ) |
271 | 0 | { |
272 | 0 | libcerror_error_set( |
273 | 0 | error, |
274 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
275 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
276 | 0 | "%s: invalid directory entry.", |
277 | 0 | function ); |
278 | |
|
279 | 0 | return( -1 ); |
280 | 0 | } |
281 | 51.5k | if( directory_entry->name != NULL ) |
282 | 0 | { |
283 | 0 | libcerror_error_set( |
284 | 0 | error, |
285 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
286 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
287 | 0 | "%s: invalid directory entry - name value already set.", |
288 | 0 | function ); |
289 | |
|
290 | 0 | return( -1 ); |
291 | 0 | } |
292 | 51.5k | if( data == NULL ) |
293 | 0 | { |
294 | 0 | libcerror_error_set( |
295 | 0 | error, |
296 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
297 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
298 | 0 | "%s: invalid data.", |
299 | 0 | function ); |
300 | |
|
301 | 0 | return( -1 ); |
302 | 0 | } |
303 | 51.5k | if( ( data_size < sizeof( fsext_directory_entry_t ) ) |
304 | 51.5k | || ( data_size > (size_t) SSIZE_MAX ) ) |
305 | 31 | { |
306 | 31 | libcerror_error_set( |
307 | 31 | error, |
308 | 31 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
309 | 31 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
310 | 31 | "%s: invalid data size value out of bounds.", |
311 | 31 | function ); |
312 | | |
313 | 31 | return( -1 ); |
314 | 31 | } |
315 | 51.4k | byte_stream_copy_to_uint16_little_endian( |
316 | 51.4k | ( (fsext_directory_entry_t *) data )->size, |
317 | 51.4k | directory_entry->size ); |
318 | | |
319 | 51.4k | if( directory_entry->size == 0 ) |
320 | 9.23k | { |
321 | 9.23k | return( 1 ); |
322 | 9.23k | } |
323 | 42.2k | if( ( directory_entry->size < 8 ) |
324 | 42.2k | || ( directory_entry->size > data_size ) ) |
325 | 92 | { |
326 | 92 | libcerror_error_set( |
327 | 92 | error, |
328 | 92 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
329 | 92 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
330 | 92 | "%s: invalid directory entry - data size value out of bounds.", |
331 | 92 | function ); |
332 | | |
333 | 92 | goto on_error; |
334 | 92 | } |
335 | | #if defined( HAVE_DEBUG_OUTPUT ) |
336 | | if( libcnotify_verbose != 0 ) |
337 | | { |
338 | | libcnotify_printf( |
339 | | "%s: directory entry data:\n", |
340 | | function ); |
341 | | libcnotify_print_data( |
342 | | data, |
343 | | directory_entry->size, |
344 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
345 | | } |
346 | | #endif |
347 | 42.1k | byte_stream_copy_to_uint32_little_endian( |
348 | 42.1k | ( (fsext_directory_entry_t *) data )->inode_number, |
349 | 42.1k | directory_entry->inode_number ); |
350 | | |
351 | 42.1k | name_size = ( (fsext_directory_entry_t *) data )->name_size; |
352 | | |
353 | 42.1k | directory_entry->file_type = ( (fsext_directory_entry_t *) data )->file_type; |
354 | | |
355 | | #if defined( HAVE_DEBUG_OUTPUT ) |
356 | | if( libcnotify_verbose != 0 ) |
357 | | { |
358 | | libcnotify_printf( |
359 | | "%s: inode number\t\t\t: %" PRIu32 "\n", |
360 | | function, |
361 | | directory_entry->inode_number ); |
362 | | |
363 | | libcnotify_printf( |
364 | | "%s: size\t\t\t\t: %" PRIu16 "\n", |
365 | | function, |
366 | | directory_entry->size ); |
367 | | |
368 | | libcnotify_printf( |
369 | | "%s: name size\t\t\t\t: %" PRIu8 "\n", |
370 | | function, |
371 | | name_size ); |
372 | | |
373 | | libcnotify_printf( |
374 | | "%s: file type\t\t\t\t: %" PRIu8 " (%s)\n", |
375 | | function, |
376 | | directory_entry->file_type, |
377 | | libfsext_debug_print_file_type( |
378 | | directory_entry->file_type ) ); |
379 | | } |
380 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
381 | | |
382 | 42.1k | data_offset = 8; |
383 | | |
384 | 42.1k | if( name_size > ( directory_entry->size - data_offset ) ) |
385 | 8 | { |
386 | 8 | libcerror_error_set( |
387 | 8 | error, |
388 | 8 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
389 | 8 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
390 | 8 | "%s: invalid directory entry - name size value out of bounds.", |
391 | 8 | function ); |
392 | | |
393 | 8 | goto on_error; |
394 | 8 | } |
395 | | #if defined( HAVE_DEBUG_OUTPUT ) |
396 | | if( libcnotify_verbose != 0 ) |
397 | | { |
398 | | if( libfsext_debug_print_utf8_string_value( |
399 | | function, |
400 | | "name\t\t\t\t", |
401 | | &( data[ data_offset ] ), |
402 | | name_size, |
403 | | error ) != 1 ) |
404 | | { |
405 | | libcerror_error_set( |
406 | | error, |
407 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
408 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
409 | | "%s: unable to print UTF-8 string value.", |
410 | | function ); |
411 | | |
412 | | goto on_error; |
413 | | } |
414 | | } |
415 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
416 | | |
417 | 42.1k | directory_entry->name = (uint8_t *) memory_allocate( |
418 | 42.1k | sizeof( uint8_t ) * ( name_size + 1 ) ); |
419 | | |
420 | 42.1k | if( directory_entry->name == NULL ) |
421 | 0 | { |
422 | 0 | libcerror_error_set( |
423 | 0 | error, |
424 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
425 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
426 | 0 | "%s: unable to create name.", |
427 | 0 | function ); |
428 | |
|
429 | 0 | goto on_error; |
430 | 0 | } |
431 | 42.1k | if( memory_copy( |
432 | 42.1k | directory_entry->name, |
433 | 42.1k | &( data[ data_offset ] ), |
434 | 42.1k | name_size ) == NULL ) |
435 | 0 | { |
436 | 0 | libcerror_error_set( |
437 | 0 | error, |
438 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
439 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
440 | 0 | "%s: unable to copy name.", |
441 | 0 | function ); |
442 | |
|
443 | 0 | goto on_error; |
444 | 0 | } |
445 | 42.1k | ( directory_entry->name )[ name_size ] = 0; |
446 | 42.1k | directory_entry->name_size = name_size + 1; |
447 | | |
448 | 42.1k | data_offset += name_size; |
449 | | |
450 | | #if defined( HAVE_DEBUG_OUTPUT ) |
451 | | if( libcnotify_verbose != 0 ) |
452 | | { |
453 | | if( data_offset < directory_entry->size ) |
454 | | { |
455 | | libcnotify_printf( |
456 | | "%s: trailing data:\n", |
457 | | function ); |
458 | | libcnotify_print_data( |
459 | | &( data[ data_offset ] ), |
460 | | directory_entry->size - data_offset, |
461 | | LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); |
462 | | } |
463 | | } |
464 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
465 | | |
466 | 42.1k | return( 1 ); |
467 | | |
468 | 100 | on_error: |
469 | 100 | if( directory_entry->name != NULL ) |
470 | 0 | { |
471 | 0 | memory_free( |
472 | 0 | directory_entry->name ); |
473 | |
|
474 | 0 | directory_entry->name = NULL; |
475 | 0 | } |
476 | 100 | return( -1 ); |
477 | 42.1k | } |
478 | | |
479 | | /* Retrieves the inode number |
480 | | * Returns 1 if successful or -1 on error |
481 | | */ |
482 | | int libfsext_directory_entry_get_inode_number( |
483 | | libfsext_directory_entry_t *directory_entry, |
484 | | uint32_t *inode_number, |
485 | | libcerror_error_t **error ) |
486 | 787 | { |
487 | 787 | static char *function = "libfsext_directory_entry_get_inode_number"; |
488 | | |
489 | 787 | if( directory_entry == NULL ) |
490 | 0 | { |
491 | 0 | libcerror_error_set( |
492 | 0 | error, |
493 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
494 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
495 | 0 | "%s: invalid directory entry.", |
496 | 0 | function ); |
497 | |
|
498 | 0 | return( -1 ); |
499 | 0 | } |
500 | 787 | if( inode_number == NULL ) |
501 | 0 | { |
502 | 0 | libcerror_error_set( |
503 | 0 | error, |
504 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
505 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
506 | 0 | "%s: invalid inode number.", |
507 | 0 | function ); |
508 | |
|
509 | 0 | return( -1 ); |
510 | 0 | } |
511 | 787 | *inode_number = directory_entry->inode_number; |
512 | | |
513 | 787 | return( 1 ); |
514 | 787 | } |
515 | | |
516 | | /* Retrieves the size of the UTF-8 encoded name |
517 | | * The returned size includes the end of string character |
518 | | * Returns 1 if successful, 0 if not available or -1 on error |
519 | | */ |
520 | | int libfsext_directory_entry_get_utf8_name_size( |
521 | | libfsext_directory_entry_t *directory_entry, |
522 | | size_t *utf8_string_size, |
523 | | libcerror_error_t **error ) |
524 | 498 | { |
525 | 498 | static char *function = "libfsext_directory_entry_get_utf8_name_size"; |
526 | | |
527 | 498 | if( directory_entry == NULL ) |
528 | 0 | { |
529 | 0 | libcerror_error_set( |
530 | 0 | error, |
531 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
532 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
533 | 0 | "%s: invalid directory entry.", |
534 | 0 | function ); |
535 | |
|
536 | 0 | return( -1 ); |
537 | 0 | } |
538 | 498 | if( libuna_utf8_string_size_from_utf8_stream( |
539 | 498 | directory_entry->name, |
540 | 498 | (size_t) directory_entry->name_size, |
541 | 498 | utf8_string_size, |
542 | 498 | error ) != 1 ) |
543 | 262 | { |
544 | 262 | libcerror_error_set( |
545 | 262 | error, |
546 | 262 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
547 | 262 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
548 | 262 | "%s: unable to retrieve UTF-8 string size.", |
549 | 262 | function ); |
550 | | |
551 | 262 | return( -1 ); |
552 | 262 | } |
553 | 236 | return( 1 ); |
554 | 498 | } |
555 | | |
556 | | /* Retrieves the UTF-8 encoded name |
557 | | * The size should include the end of string character |
558 | | * Returns 1 if successful, 0 if not available or -1 on error |
559 | | */ |
560 | | int libfsext_directory_entry_get_utf8_name( |
561 | | libfsext_directory_entry_t *directory_entry, |
562 | | uint8_t *utf8_string, |
563 | | size_t utf8_string_size, |
564 | | libcerror_error_t **error ) |
565 | 498 | { |
566 | 498 | static char *function = "libfsext_directory_entry_get_utf8_name"; |
567 | | |
568 | 498 | if( directory_entry == NULL ) |
569 | 0 | { |
570 | 0 | libcerror_error_set( |
571 | 0 | error, |
572 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
573 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
574 | 0 | "%s: invalid directory entry.", |
575 | 0 | function ); |
576 | |
|
577 | 0 | return( -1 ); |
578 | 0 | } |
579 | 498 | if( libuna_utf8_string_copy_from_utf8_stream( |
580 | 498 | utf8_string, |
581 | 498 | utf8_string_size, |
582 | 498 | directory_entry->name, |
583 | 498 | (size_t) directory_entry->name_size, |
584 | 498 | error ) != 1 ) |
585 | 266 | { |
586 | 266 | libcerror_error_set( |
587 | 266 | error, |
588 | 266 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
589 | 266 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
590 | 266 | "%s: unable to retrieve UTF-8 string.", |
591 | 266 | function ); |
592 | | |
593 | 266 | return( -1 ); |
594 | 266 | } |
595 | 232 | return( 1 ); |
596 | 498 | } |
597 | | |
598 | | /* Compares an UTF-8 string with the name of the directory entry |
599 | | * Returns LIBUNA_COMPARE_LESS, LIBUNA_COMPARE_EQUAL, LIBUNA_COMPARE_GREATER if successful or -1 on error |
600 | | */ |
601 | | int libfsext_directory_entry_compare_with_utf8_string( |
602 | | libfsext_directory_entry_t *directory_entry, |
603 | | const uint8_t *utf8_string, |
604 | | size_t utf8_string_length, |
605 | | libcerror_error_t **error ) |
606 | 8.47k | { |
607 | 8.47k | static char *function = "libfsext_directory_entry_compare_with_utf8_string"; |
608 | 8.47k | int result = 0; |
609 | | |
610 | 8.47k | if( directory_entry == NULL ) |
611 | 0 | { |
612 | 0 | libcerror_error_set( |
613 | 0 | error, |
614 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
615 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
616 | 0 | "%s: invalid directory entry.", |
617 | 0 | function ); |
618 | |
|
619 | 0 | return( -1 ); |
620 | 0 | } |
621 | 8.47k | result = libuna_utf8_string_compare_with_utf8_stream( |
622 | 8.47k | utf8_string, |
623 | 8.47k | utf8_string_length, |
624 | 8.47k | directory_entry->name, |
625 | 8.47k | directory_entry->name_size, |
626 | 8.47k | error ); |
627 | | |
628 | 8.47k | if( result == -1 ) |
629 | 81 | { |
630 | 81 | libcerror_error_set( |
631 | 81 | error, |
632 | 81 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
633 | 81 | LIBCERROR_RUNTIME_ERROR_GENERIC, |
634 | 81 | "%s: unable to compare UTF-8 string with directory entry name.", |
635 | 81 | function ); |
636 | | |
637 | 81 | return( -1 ); |
638 | 81 | } |
639 | 8.39k | return( result ); |
640 | 8.47k | } |
641 | | |
642 | | /* Retrieves the size of the UTF-16 encoded name |
643 | | * The returned size includes the end of string character |
644 | | * Returns 1 if successful, 0 if not available or -1 on error |
645 | | */ |
646 | | int libfsext_directory_entry_get_utf16_name_size( |
647 | | libfsext_directory_entry_t *directory_entry, |
648 | | size_t *utf16_string_size, |
649 | | libcerror_error_t **error ) |
650 | 0 | { |
651 | 0 | static char *function = "libfsext_directory_entry_get_utf16_name_size"; |
652 | |
|
653 | 0 | if( directory_entry == NULL ) |
654 | 0 | { |
655 | 0 | libcerror_error_set( |
656 | 0 | error, |
657 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
658 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
659 | 0 | "%s: invalid directory entry.", |
660 | 0 | function ); |
661 | |
|
662 | 0 | return( -1 ); |
663 | 0 | } |
664 | 0 | if( libuna_utf16_string_size_from_utf8_stream( |
665 | 0 | directory_entry->name, |
666 | 0 | (size_t) directory_entry->name_size, |
667 | 0 | utf16_string_size, |
668 | 0 | error ) != 1 ) |
669 | 0 | { |
670 | 0 | libcerror_error_set( |
671 | 0 | error, |
672 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
673 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
674 | 0 | "%s: unable to retrieve UTF-16 string size.", |
675 | 0 | function ); |
676 | |
|
677 | 0 | return( -1 ); |
678 | 0 | } |
679 | 0 | return( 1 ); |
680 | 0 | } |
681 | | |
682 | | /* Retrieves the UTF-16 encoded name |
683 | | * The size should include the end of string character |
684 | | * Returns 1 if successful, 0 if not available or -1 on error |
685 | | */ |
686 | | int libfsext_directory_entry_get_utf16_name( |
687 | | libfsext_directory_entry_t *directory_entry, |
688 | | uint16_t *utf16_string, |
689 | | size_t utf16_string_size, |
690 | | libcerror_error_t **error ) |
691 | 0 | { |
692 | 0 | static char *function = "libfsext_directory_entry_get_utf16_name"; |
693 | |
|
694 | 0 | if( directory_entry == NULL ) |
695 | 0 | { |
696 | 0 | libcerror_error_set( |
697 | 0 | error, |
698 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
699 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
700 | 0 | "%s: invalid directory entry.", |
701 | 0 | function ); |
702 | |
|
703 | 0 | return( -1 ); |
704 | 0 | } |
705 | 0 | if( libuna_utf16_string_copy_from_utf8_stream( |
706 | 0 | utf16_string, |
707 | 0 | utf16_string_size, |
708 | 0 | directory_entry->name, |
709 | 0 | (size_t) directory_entry->name_size, |
710 | 0 | error ) != 1 ) |
711 | 0 | { |
712 | 0 | libcerror_error_set( |
713 | 0 | error, |
714 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
715 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
716 | 0 | "%s: unable to retrieve UTF-16 string.", |
717 | 0 | function ); |
718 | |
|
719 | 0 | return( -1 ); |
720 | 0 | } |
721 | 0 | return( 1 ); |
722 | 0 | } |
723 | | |
724 | | /* Compares an UTF-16 string with the name of the directory entry |
725 | | * Returns LIBUNA_COMPARE_LESS, LIBUNA_COMPARE_EQUAL, LIBUNA_COMPARE_GREATER if successful or -1 on error |
726 | | */ |
727 | | int libfsext_directory_entry_compare_with_utf16_string( |
728 | | libfsext_directory_entry_t *directory_entry, |
729 | | const uint16_t *utf16_string, |
730 | | size_t utf16_string_length, |
731 | | libcerror_error_t **error ) |
732 | 0 | { |
733 | 0 | static char *function = "libfsext_directory_entry_compare_with_utf16_string"; |
734 | 0 | int result = 0; |
735 | |
|
736 | 0 | if( directory_entry == NULL ) |
737 | 0 | { |
738 | 0 | libcerror_error_set( |
739 | 0 | error, |
740 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
741 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
742 | 0 | "%s: invalid directory entry.", |
743 | 0 | function ); |
744 | |
|
745 | 0 | return( -1 ); |
746 | 0 | } |
747 | 0 | result = libuna_utf16_string_compare_with_utf8_stream( |
748 | 0 | utf16_string, |
749 | 0 | utf16_string_length, |
750 | 0 | directory_entry->name, |
751 | 0 | directory_entry->name_size, |
752 | 0 | error ); |
753 | |
|
754 | 0 | if( result == -1 ) |
755 | 0 | { |
756 | 0 | libcerror_error_set( |
757 | 0 | error, |
758 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
759 | 0 | LIBCERROR_RUNTIME_ERROR_GENERIC, |
760 | 0 | "%s: unable to compare UTF-16 string with directory entry name.", |
761 | 0 | function ); |
762 | |
|
763 | 0 | return( -1 ); |
764 | 0 | } |
765 | 0 | return( result ); |
766 | 0 | } |
767 | | |