/src/libfsntfs/libfsntfs/libfsntfs_extent.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Extent functions |
3 | | * |
4 | | * Copyright (C) 2010-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 "libfsntfs_extent.h" |
27 | | #include "libfsntfs_libcerror.h" |
28 | | |
29 | | /* Creates a 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 libfsntfs_extent_initialize( |
34 | | libfsntfs_extent_t **extent, |
35 | | libcerror_error_t **error ) |
36 | 5.94k | { |
37 | 5.94k | static char *function = "libfsntfs_extent_initialize"; |
38 | | |
39 | 5.94k | 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 | 5.94k | 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 | 5.94k | *extent = memory_allocate_structure( |
62 | 5.94k | libfsntfs_extent_t ); |
63 | | |
64 | 5.94k | 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 | 5.94k | if( memory_set( |
76 | 5.94k | *extent, |
77 | 5.94k | 0, |
78 | 5.94k | sizeof( libfsntfs_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 | memory_free( |
88 | 0 | *extent ); |
89 | |
|
90 | 0 | *extent = NULL; |
91 | |
|
92 | 0 | return( -1 ); |
93 | 0 | } |
94 | 5.94k | return( 1 ); |
95 | | |
96 | 0 | on_error: |
97 | 0 | if( *extent != NULL ) |
98 | 0 | { |
99 | 0 | memory_free( |
100 | 0 | *extent ); |
101 | |
|
102 | 0 | *extent = NULL; |
103 | 0 | } |
104 | 0 | return( -1 ); |
105 | 5.94k | } |
106 | | |
107 | | /* Frees a extent |
108 | | * Returns 1 if successful or -1 on error |
109 | | */ |
110 | | int libfsntfs_extent_free( |
111 | | libfsntfs_extent_t **extent, |
112 | | libcerror_error_t **error ) |
113 | 5.94k | { |
114 | 5.94k | static char *function = "libfsntfs_extent_free"; |
115 | | |
116 | 5.94k | if( extent == NULL ) |
117 | 0 | { |
118 | 0 | libcerror_error_set( |
119 | 0 | error, |
120 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
121 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
122 | 0 | "%s: invalid extent.", |
123 | 0 | function ); |
124 | |
|
125 | 0 | return( -1 ); |
126 | 0 | } |
127 | 5.94k | if( *extent != NULL ) |
128 | 5.94k | { |
129 | 5.94k | memory_free( |
130 | 5.94k | *extent ); |
131 | | |
132 | 5.94k | *extent = NULL; |
133 | 5.94k | } |
134 | 5.94k | return( 1 ); |
135 | 5.94k | } |
136 | | |
137 | | /* Retrieves the extent values |
138 | | * Returns 1 if successful or -1 on error |
139 | | */ |
140 | | int libfsntfs_extent_get_values( |
141 | | libfsntfs_extent_t *extent, |
142 | | off64_t *extent_offset, |
143 | | size64_t *extent_size, |
144 | | uint32_t *extent_flags, |
145 | | libcerror_error_t **error ) |
146 | 0 | { |
147 | 0 | static char *function = "libfsntfs_extent_get_values"; |
148 | |
|
149 | 0 | if( extent == NULL ) |
150 | 0 | { |
151 | 0 | libcerror_error_set( |
152 | 0 | error, |
153 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
154 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
155 | 0 | "%s: invalid extent.", |
156 | 0 | function ); |
157 | |
|
158 | 0 | return( -1 ); |
159 | 0 | } |
160 | 0 | if( extent_offset == NULL ) |
161 | 0 | { |
162 | 0 | libcerror_error_set( |
163 | 0 | error, |
164 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
165 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
166 | 0 | "%s: invalid extent offset.", |
167 | 0 | function ); |
168 | |
|
169 | 0 | return( -1 ); |
170 | 0 | } |
171 | 0 | if( extent_size == NULL ) |
172 | 0 | { |
173 | 0 | libcerror_error_set( |
174 | 0 | error, |
175 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
176 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
177 | 0 | "%s: invalid extent size.", |
178 | 0 | function ); |
179 | |
|
180 | 0 | return( -1 ); |
181 | 0 | } |
182 | 0 | if( extent_flags == NULL ) |
183 | 0 | { |
184 | 0 | libcerror_error_set( |
185 | 0 | error, |
186 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
187 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
188 | 0 | "%s: invalid extent flags.", |
189 | 0 | function ); |
190 | |
|
191 | 0 | return( -1 ); |
192 | 0 | } |
193 | 0 | *extent_offset = extent->start_offset; |
194 | 0 | *extent_size = extent->size; |
195 | 0 | *extent_flags = extent->range_flags; |
196 | |
|
197 | 0 | return( 1 ); |
198 | 0 | } |
199 | | |