Coverage Report

Created: 2023-06-07 06:53

/src/libfsntfs/libfsntfs/libfsntfs_volume_name_attribute.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Volume name attribute ($VOLUME_NAME) functions
3
 *
4
 * Copyright (C) 2010-2023, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <common.h>
23
#include <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_name_attribute.h"
32
#include "libfsntfs_volume_name_values.h"
33
34
/* Retrieves the size of the UTF-8 encoded name
35
 * The returned size includes the end of string character
36
 * Returns 1 if successful or -1 on error
37
 */
38
int libfsntfs_volume_name_attribute_get_utf8_name_size(
39
     libfsntfs_attribute_t *attribute,
40
     size_t *utf8_string_size,
41
     libcerror_error_t **error )
42
0
{
43
0
  libfsntfs_internal_attribute_t *internal_attribute = NULL;
44
0
  static char *function                              = "libfsntfs_volume_name_attribute_get_utf8_name_size";
45
0
  uint32_t attribute_type                            = 0;
46
47
0
  if( attribute == NULL )
48
0
  {
49
0
    libcerror_error_set(
50
0
     error,
51
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
52
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
53
0
     "%s: invalid attribute.",
54
0
     function );
55
56
0
    return( -1 );
57
0
  }
58
0
  internal_attribute = (libfsntfs_internal_attribute_t *) attribute;
59
60
0
  if( libfsntfs_internal_attribute_get_type(
61
0
       internal_attribute,
62
0
       &attribute_type,
63
0
       error ) != 1 )
64
0
  {
65
0
    libcerror_error_set(
66
0
     error,
67
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
68
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
69
0
     "%s: unable to retrieve attribute type.",
70
0
     function );
71
72
0
    return( -1 );
73
0
  }
74
0
  if( attribute_type != LIBFSNTFS_ATTRIBUTE_TYPE_VOLUME_NAME )
75
0
  {
76
0
    libcerror_error_set(
77
0
     error,
78
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
79
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
80
0
     "%s: unsupported attribute type.",
81
0
     function );
82
83
0
    return( -1 );
84
0
  }
85
0
  if( libfsntfs_volume_name_values_get_utf8_name_size(
86
0
       (libfsntfs_volume_name_values_t *) internal_attribute->value,
87
0
       utf8_string_size,
88
0
       error ) != 1 )
89
0
  {
90
0
    libcerror_error_set(
91
0
     error,
92
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
93
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
94
0
     "%s: unable to retrieve size of UTF-8 name.",
95
0
     function );
96
97
0
    return( -1 );
98
0
  }
99
0
  return( 1 );
100
0
}
101
102
/* Retrieves the UTF-8 encoded name
103
 * The size should include the end of string character
104
 * Returns 1 if successful or -1 on error
105
 */
106
int libfsntfs_volume_name_attribute_get_utf8_name(
107
     libfsntfs_attribute_t *attribute,
108
     uint8_t *utf8_string,
109
     size_t utf8_string_size,
110
     libcerror_error_t **error )
111
0
{
112
0
  libfsntfs_internal_attribute_t *internal_attribute = NULL;
113
0
  static char *function                              = "libfsntfs_volume_name_attribute_get_utf8_name";
114
0
  uint32_t attribute_type                            = 0;
115
116
0
  if( attribute == 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 attribute.",
123
0
     function );
124
125
0
    return( -1 );
126
0
  }
127
0
  internal_attribute = (libfsntfs_internal_attribute_t *) attribute;
128
129
0
  if( libfsntfs_internal_attribute_get_type(
130
0
       internal_attribute,
131
0
       &attribute_type,
132
0
       error ) != 1 )
133
0
  {
134
0
    libcerror_error_set(
135
0
     error,
136
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
137
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
138
0
     "%s: unable to retrieve attribute type.",
139
0
     function );
140
141
0
    return( -1 );
142
0
  }
143
0
  if( attribute_type != LIBFSNTFS_ATTRIBUTE_TYPE_VOLUME_NAME )
144
0
  {
145
0
    libcerror_error_set(
146
0
     error,
147
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
148
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
149
0
     "%s: unsupported attribute type.",
150
0
     function );
151
152
0
    return( -1 );
153
0
  }
154
0
  if( libfsntfs_volume_name_values_get_utf8_name(
155
0
       (libfsntfs_volume_name_values_t *) internal_attribute->value,
156
0
       utf8_string,
157
0
       utf8_string_size,
158
0
       error ) != 1 )
159
0
  {
160
0
    libcerror_error_set(
161
0
     error,
162
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
163
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
164
0
     "%s: unable to retrieve UTF-8 name.",
165
0
     function );
166
167
0
    return( -1 );
168
0
  }
169
0
  return( 1 );
170
0
}
171
172
/* Retrieves the size of the UTF-16 encoded name
173
 * The returned size includes the end of string character
174
 * Returns 1 if successful or -1 on error
175
 */
176
int libfsntfs_volume_name_attribute_get_utf16_name_size(
177
     libfsntfs_attribute_t *attribute,
178
     size_t *utf16_string_size,
179
     libcerror_error_t **error )
180
0
{
181
0
  libfsntfs_internal_attribute_t *internal_attribute = NULL;
182
0
  static char *function                              = "libfsntfs_volume_name_attribute_get_utf16_name_size";
183
0
  uint32_t attribute_type                            = 0;
184
185
0
  if( attribute == NULL )
186
0
  {
187
0
    libcerror_error_set(
188
0
     error,
189
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
190
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
191
0
     "%s: invalid attribute.",
192
0
     function );
193
194
0
    return( -1 );
195
0
  }
196
0
  internal_attribute = (libfsntfs_internal_attribute_t *) attribute;
197
198
0
  if( libfsntfs_internal_attribute_get_type(
199
0
       internal_attribute,
200
0
       &attribute_type,
201
0
       error ) != 1 )
202
0
  {
203
0
    libcerror_error_set(
204
0
     error,
205
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
206
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
207
0
     "%s: unable to retrieve attribute type.",
208
0
     function );
209
210
0
    return( -1 );
211
0
  }
212
0
  if( attribute_type != LIBFSNTFS_ATTRIBUTE_TYPE_VOLUME_NAME )
213
0
  {
214
0
    libcerror_error_set(
215
0
     error,
216
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
217
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
218
0
     "%s: unsupported attribute type.",
219
0
     function );
220
221
0
    return( -1 );
222
0
  }
223
0
  if( libfsntfs_volume_name_values_get_utf16_name_size(
224
0
       (libfsntfs_volume_name_values_t *) internal_attribute->value,
225
0
       utf16_string_size,
226
0
       error ) != 1 )
227
0
  {
228
0
    libcerror_error_set(
229
0
     error,
230
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
231
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
232
0
     "%s: unable to retrieve size of UTF-16 name.",
233
0
     function );
234
235
0
    return( -1 );
236
0
  }
237
0
  return( 1 );
238
0
}
239
240
/* Retrieves the UTF-16 encoded name
241
 * The size should include the end of string character
242
 * Returns 1 if successful or -1 on error
243
 */
244
int libfsntfs_volume_name_attribute_get_utf16_name(
245
     libfsntfs_attribute_t *attribute,
246
     uint16_t *utf16_string,
247
     size_t utf16_string_size,
248
     libcerror_error_t **error )
249
0
{
250
0
  libfsntfs_internal_attribute_t *internal_attribute = NULL;
251
0
  static char *function                              = "libfsntfs_volume_name_attribute_get_utf16_name";
252
0
  uint32_t attribute_type                            = 0;
253
254
0
  if( attribute == NULL )
255
0
  {
256
0
    libcerror_error_set(
257
0
     error,
258
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
259
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
260
0
     "%s: invalid attribute.",
261
0
     function );
262
263
0
    return( -1 );
264
0
  }
265
0
  internal_attribute = (libfsntfs_internal_attribute_t *) attribute;
266
267
0
  if( libfsntfs_internal_attribute_get_type(
268
0
       internal_attribute,
269
0
       &attribute_type,
270
0
       error ) != 1 )
271
0
  {
272
0
    libcerror_error_set(
273
0
     error,
274
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
275
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
276
0
     "%s: unable to retrieve attribute type.",
277
0
     function );
278
279
0
    return( -1 );
280
0
  }
281
0
  if( attribute_type != LIBFSNTFS_ATTRIBUTE_TYPE_VOLUME_NAME )
282
0
  {
283
0
    libcerror_error_set(
284
0
     error,
285
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
286
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
287
0
     "%s: unsupported attribute type.",
288
0
     function );
289
290
0
    return( -1 );
291
0
  }
292
0
  if( libfsntfs_volume_name_values_get_utf16_name(
293
0
       (libfsntfs_volume_name_values_t *) internal_attribute->value,
294
0
       utf16_string,
295
0
       utf16_string_size,
296
0
       error ) != 1 )
297
0
  {
298
0
    libcerror_error_set(
299
0
     error,
300
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
301
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
302
0
     "%s: unable to retrieve UTF-16 name.",
303
0
     function );
304
305
0
    return( -1 );
306
0
  }
307
0
  return( 1 );
308
0
}
309