/src/libfsntfs/libfsntfs/libfsntfs_volume_information_attribute.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Volume information attribute ($VOLUME_INFORMATION) 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_attribute.h" |
27 | | #include "libfsntfs_definitions.h" |
28 | | #include "libfsntfs_libcerror.h" |
29 | | #include "libfsntfs_libcthreads.h" |
30 | | #include "libfsntfs_types.h" |
31 | | #include "libfsntfs_volume_information_attribute.h" |
32 | | #include "libfsntfs_volume_information_values.h" |
33 | | |
34 | | /* Retrieves the version |
35 | | * Returns 1 if successful or -1 on error |
36 | | */ |
37 | | int libfsntfs_volume_information_attribute_get_version( |
38 | | libfsntfs_attribute_t *attribute, |
39 | | uint8_t *major_version, |
40 | | uint8_t *minor_version, |
41 | | libcerror_error_t **error ) |
42 | 0 | { |
43 | 0 | libfsntfs_internal_attribute_t *internal_attribute = NULL; |
44 | 0 | libfsntfs_volume_information_values_t *volume_information_values = NULL; |
45 | 0 | static char *function = "libfsntfs_volume_information_attribute_get_version"; |
46 | 0 | uint32_t attribute_type = 0; |
47 | |
|
48 | 0 | if( attribute == NULL ) |
49 | 0 | { |
50 | 0 | libcerror_error_set( |
51 | 0 | error, |
52 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
53 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
54 | 0 | "%s: invalid attribute.", |
55 | 0 | function ); |
56 | |
|
57 | 0 | return( -1 ); |
58 | 0 | } |
59 | 0 | internal_attribute = (libfsntfs_internal_attribute_t *) attribute; |
60 | |
|
61 | 0 | if( internal_attribute->value == NULL ) |
62 | 0 | { |
63 | 0 | libcerror_error_set( |
64 | 0 | error, |
65 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
66 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
67 | 0 | "%s: invalid attribute - missing value.", |
68 | 0 | function ); |
69 | |
|
70 | 0 | return( -1 ); |
71 | 0 | } |
72 | 0 | if( libfsntfs_internal_attribute_get_type( |
73 | 0 | internal_attribute, |
74 | 0 | &attribute_type, |
75 | 0 | error ) != 1 ) |
76 | 0 | { |
77 | 0 | libcerror_error_set( |
78 | 0 | error, |
79 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
80 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
81 | 0 | "%s: unable to retrieve attribute type.", |
82 | 0 | function ); |
83 | |
|
84 | 0 | return( -1 ); |
85 | 0 | } |
86 | 0 | if( attribute_type != LIBFSNTFS_ATTRIBUTE_TYPE_VOLUME_INFORMATION ) |
87 | 0 | { |
88 | 0 | libcerror_error_set( |
89 | 0 | error, |
90 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
91 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
92 | 0 | "%s: unsupported attribute type.", |
93 | 0 | function ); |
94 | |
|
95 | 0 | return( -1 ); |
96 | 0 | } |
97 | 0 | volume_information_values = (libfsntfs_volume_information_values_t *) internal_attribute->value; |
98 | |
|
99 | 0 | if( major_version == NULL ) |
100 | 0 | { |
101 | 0 | libcerror_error_set( |
102 | 0 | error, |
103 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
104 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
105 | 0 | "%s: invalid major version.", |
106 | 0 | function ); |
107 | |
|
108 | 0 | return( -1 ); |
109 | 0 | } |
110 | 0 | if( minor_version == NULL ) |
111 | 0 | { |
112 | 0 | libcerror_error_set( |
113 | 0 | error, |
114 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
115 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
116 | 0 | "%s: invalid minor version.", |
117 | 0 | function ); |
118 | |
|
119 | 0 | return( -1 ); |
120 | 0 | } |
121 | 0 | *major_version = volume_information_values->major_version; |
122 | 0 | *minor_version = volume_information_values->minor_version; |
123 | |
|
124 | 0 | return( 1 ); |
125 | 0 | } |
126 | | |
127 | | /* Retrieves the flags |
128 | | * Returns 1 if successful or -1 on error |
129 | | */ |
130 | | int libfsntfs_volume_information_attribute_get_flags( |
131 | | libfsntfs_attribute_t *attribute, |
132 | | uint16_t *flags, |
133 | | libcerror_error_t **error ) |
134 | 0 | { |
135 | 0 | libfsntfs_internal_attribute_t *internal_attribute = NULL; |
136 | 0 | libfsntfs_volume_information_values_t *volume_information_values = NULL; |
137 | 0 | static char *function = "libfsntfs_volume_information_attribute_get_flags"; |
138 | 0 | uint32_t attribute_type = 0; |
139 | |
|
140 | 0 | if( attribute == NULL ) |
141 | 0 | { |
142 | 0 | libcerror_error_set( |
143 | 0 | error, |
144 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
145 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
146 | 0 | "%s: invalid attribute.", |
147 | 0 | function ); |
148 | |
|
149 | 0 | return( -1 ); |
150 | 0 | } |
151 | 0 | internal_attribute = (libfsntfs_internal_attribute_t *) attribute; |
152 | |
|
153 | 0 | if( internal_attribute->value == NULL ) |
154 | 0 | { |
155 | 0 | libcerror_error_set( |
156 | 0 | error, |
157 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
158 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
159 | 0 | "%s: invalid attribute - missing value.", |
160 | 0 | function ); |
161 | |
|
162 | 0 | return( -1 ); |
163 | 0 | } |
164 | 0 | if( libfsntfs_internal_attribute_get_type( |
165 | 0 | internal_attribute, |
166 | 0 | &attribute_type, |
167 | 0 | error ) != 1 ) |
168 | 0 | { |
169 | 0 | libcerror_error_set( |
170 | 0 | error, |
171 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
172 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
173 | 0 | "%s: unable to retrieve attribute type.", |
174 | 0 | function ); |
175 | |
|
176 | 0 | return( -1 ); |
177 | 0 | } |
178 | 0 | if( attribute_type != LIBFSNTFS_ATTRIBUTE_TYPE_VOLUME_INFORMATION ) |
179 | 0 | { |
180 | 0 | libcerror_error_set( |
181 | 0 | error, |
182 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
183 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
184 | 0 | "%s: unsupported attribute type.", |
185 | 0 | function ); |
186 | |
|
187 | 0 | return( -1 ); |
188 | 0 | } |
189 | 0 | volume_information_values = (libfsntfs_volume_information_values_t *) internal_attribute->value; |
190 | |
|
191 | 0 | if( flags == NULL ) |
192 | 0 | { |
193 | 0 | libcerror_error_set( |
194 | 0 | error, |
195 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
196 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
197 | 0 | "%s: invalid flags.", |
198 | 0 | function ); |
199 | |
|
200 | 0 | return( -1 ); |
201 | 0 | } |
202 | 0 | *flags = volume_information_values->flags; |
203 | |
|
204 | 0 | return( 1 ); |
205 | 0 | } |