/src/libfsfat/libfsfat/libfsfat_extent.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Extent functions |
3 | | * |
4 | | * Copyright (C) 2021-2024, Joachim Metz <joachim.metz@gmail.com> |
5 | | * |
6 | | * Refer to AUTHORS for acknowledgements. |
7 | | * |
8 | | * This program is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include <common.h> |
23 | | #include <memory.h> |
24 | | #include <types.h> |
25 | | |
26 | | #include "libfsfat_extent.h" |
27 | | #include "libfsfat_libcerror.h" |
28 | | |
29 | | /* Creates an extent |
30 | | * Make sure the value extent is referencing, is set to NULL |
31 | | * Returns 1 if successful or -1 on error |
32 | | */ |
33 | | int libfsfat_extent_initialize( |
34 | | libfsfat_extent_t **extent, |
35 | | libcerror_error_t **error ) |
36 | 0 | { |
37 | 0 | static char *function = "libfsfat_extent_initialize"; |
38 | |
|
39 | 0 | if( extent == NULL ) |
40 | 0 | { |
41 | 0 | libcerror_error_set( |
42 | 0 | error, |
43 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
44 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
45 | 0 | "%s: invalid extent.", |
46 | 0 | function ); |
47 | |
|
48 | 0 | return( -1 ); |
49 | 0 | } |
50 | 0 | if( *extent != NULL ) |
51 | 0 | { |
52 | 0 | libcerror_error_set( |
53 | 0 | error, |
54 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
55 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
56 | 0 | "%s: invalid extent value already set.", |
57 | 0 | function ); |
58 | |
|
59 | 0 | return( -1 ); |
60 | 0 | } |
61 | 0 | *extent = memory_allocate_structure( |
62 | 0 | libfsfat_extent_t ); |
63 | |
|
64 | 0 | if( *extent == NULL ) |
65 | 0 | { |
66 | 0 | libcerror_error_set( |
67 | 0 | error, |
68 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
69 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
70 | 0 | "%s: unable to create extent.", |
71 | 0 | function ); |
72 | |
|
73 | 0 | goto on_error; |
74 | 0 | } |
75 | 0 | if( memory_set( |
76 | 0 | *extent, |
77 | 0 | 0, |
78 | 0 | sizeof( libfsfat_extent_t ) ) == NULL ) |
79 | 0 | { |
80 | 0 | libcerror_error_set( |
81 | 0 | error, |
82 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
83 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
84 | 0 | "%s: unable to clear extent.", |
85 | 0 | function ); |
86 | |
|
87 | 0 | goto on_error; |
88 | 0 | } |
89 | 0 | return( 1 ); |
90 | | |
91 | 0 | on_error: |
92 | 0 | if( *extent != NULL ) |
93 | 0 | { |
94 | 0 | memory_free( |
95 | 0 | *extent ); |
96 | |
|
97 | 0 | *extent = NULL; |
98 | 0 | } |
99 | 0 | return( -1 ); |
100 | 0 | } |
101 | | |
102 | | /* Frees an extent |
103 | | * Returns 1 if successful or -1 on error |
104 | | */ |
105 | | int libfsfat_extent_free( |
106 | | libfsfat_extent_t **extent, |
107 | | libcerror_error_t **error ) |
108 | 0 | { |
109 | 0 | static char *function = "libfsfat_extent_free"; |
110 | |
|
111 | 0 | if( extent == NULL ) |
112 | 0 | { |
113 | 0 | libcerror_error_set( |
114 | 0 | error, |
115 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
116 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
117 | 0 | "%s: invalid extent.", |
118 | 0 | function ); |
119 | |
|
120 | 0 | return( -1 ); |
121 | 0 | } |
122 | 0 | if( *extent != NULL ) |
123 | 0 | { |
124 | 0 | memory_free( |
125 | 0 | *extent ); |
126 | |
|
127 | 0 | *extent = NULL; |
128 | 0 | } |
129 | 0 | return( 1 ); |
130 | 0 | } |
131 | | |
132 | | /* Retrieves the extents values |
133 | | * Returns 1 if successful or -1 on error |
134 | | */ |
135 | | int libfsfat_extent_get_values( |
136 | | libfsfat_extent_t *extent, |
137 | | off64_t *extent_offset, |
138 | | size64_t *extent_size, |
139 | | uint32_t *extent_flags, |
140 | | libcerror_error_t **error ) |
141 | 0 | { |
142 | 0 | static char *function = "libfsfat_extent_get_values"; |
143 | |
|
144 | 0 | if( extent == NULL ) |
145 | 0 | { |
146 | 0 | libcerror_error_set( |
147 | 0 | error, |
148 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
149 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
150 | 0 | "%s: invalid extent.", |
151 | 0 | function ); |
152 | |
|
153 | 0 | return( -1 ); |
154 | 0 | } |
155 | 0 | if( extent_offset == NULL ) |
156 | 0 | { |
157 | 0 | libcerror_error_set( |
158 | 0 | error, |
159 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
160 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
161 | 0 | "%s: invalid extent offset.", |
162 | 0 | function ); |
163 | |
|
164 | 0 | return( -1 ); |
165 | 0 | } |
166 | 0 | if( extent_size == NULL ) |
167 | 0 | { |
168 | 0 | libcerror_error_set( |
169 | 0 | error, |
170 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
171 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
172 | 0 | "%s: invalid extent size.", |
173 | 0 | function ); |
174 | |
|
175 | 0 | return( -1 ); |
176 | 0 | } |
177 | 0 | if( extent_flags == NULL ) |
178 | 0 | { |
179 | 0 | libcerror_error_set( |
180 | 0 | error, |
181 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
182 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
183 | 0 | "%s: invalid extent flags.", |
184 | 0 | function ); |
185 | |
|
186 | 0 | return( -1 ); |
187 | 0 | } |
188 | 0 | *extent_offset = extent->offset; |
189 | 0 | *extent_size = extent->size; |
190 | 0 | *extent_flags = 0; |
191 | |
|
192 | 0 | return( 1 ); |
193 | 0 | } |
194 | | |