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