Coverage Report

Created: 2025-10-14 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvsmbr/libvsmbr/libvsmbr_partition_values.c
Line
Count
Source
1
/*
2
 * The partition values 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 "libvsmbr_libcerror.h"
27
#include "libvsmbr_partition_values.h"
28
29
/* Creates partition values
30
 * Make sure the value partition_values is referencing, is set to NULL
31
 * Returns 1 if successful or -1 on error
32
 */
33
int libvsmbr_partition_values_initialize(
34
     libvsmbr_partition_values_t **partition_values,
35
     libcerror_error_t **error )
36
21.5k
{
37
21.5k
  static char *function = "libvsmbr_partition_values_initialize";
38
39
21.5k
  if( partition_values == 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 partition values.",
46
0
     function );
47
48
0
    return( -1 );
49
0
  }
50
21.5k
  if( *partition_values != 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 partition values value already set.",
57
0
     function );
58
59
0
    return( -1 );
60
0
  }
61
21.5k
  *partition_values = memory_allocate_structure(
62
21.5k
                       libvsmbr_partition_values_t );
63
64
21.5k
  if( *partition_values == 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 partition values.",
71
0
     function );
72
73
0
    goto on_error;
74
0
  }
75
21.5k
  if( memory_set(
76
21.5k
       *partition_values,
77
21.5k
       0,
78
21.5k
       sizeof( libvsmbr_partition_values_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 partition values.",
85
0
     function );
86
87
0
    goto on_error;
88
0
  }
89
21.5k
  return( 1 );
90
91
0
on_error:
92
0
  if( *partition_values != NULL )
93
0
  {
94
0
    memory_free(
95
0
     *partition_values );
96
97
0
    *partition_values = NULL;
98
0
  }
99
0
  return( -1 );
100
21.5k
}
101
102
/* Frees partition values
103
 * Returns 1 if successful or -1 on error
104
 */
105
int libvsmbr_partition_values_free(
106
     libvsmbr_partition_values_t **partition_values,
107
     libcerror_error_t **error )
108
21.5k
{
109
21.5k
  static char *function = "libvsmbr_partition_values_free";
110
111
21.5k
  if( partition_values == 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 partition values.",
118
0
     function );
119
120
0
    return( -1 );
121
0
  }
122
21.5k
  if( *partition_values != NULL )
123
21.5k
  {
124
21.5k
    memory_free(
125
21.5k
     *partition_values );
126
127
21.5k
    *partition_values = NULL;
128
21.5k
  }
129
21.5k
  return( 1 );
130
21.5k
}
131
132
/* Retrieves the partition type
133
 * Returns 1 if successful or -1 on error
134
 */
135
int libvsmbr_partition_values_get_type(
136
     libvsmbr_partition_values_t *partition_values,
137
     uint8_t *type,
138
     libcerror_error_t **error )
139
0
{
140
0
  static char *function = "libvsmbr_partition_values_get_type";
141
142
0
  if( partition_values == NULL )
143
0
  {
144
0
    libcerror_error_set(
145
0
     error,
146
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
147
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
148
0
     "%s: invalid partition values.",
149
0
     function );
150
151
0
    return( -1 );
152
0
  }
153
0
  if( type == NULL )
154
0
  {
155
0
    libcerror_error_set(
156
0
     error,
157
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
158
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
159
0
     "%s: invalid type.",
160
0
     function );
161
162
0
    return( -1 );
163
0
  }
164
0
  *type = partition_values->type;
165
166
0
  return( 1 );
167
0
}
168
169
/* Retrieves the partition sector number
170
 * Returns 1 if successful or -1 on error
171
 */
172
int libvsmbr_partition_values_get_sector_number(
173
     libvsmbr_partition_values_t *partition_values,
174
     uint32_t *sector_number,
175
     libcerror_error_t **error )
176
70
{
177
70
  static char *function = "libvsmbr_partition_values_get_sector_number";
178
179
70
  if( partition_values == NULL )
180
0
  {
181
0
    libcerror_error_set(
182
0
     error,
183
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
184
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
185
0
     "%s: invalid partition values.",
186
0
     function );
187
188
0
    return( -1 );
189
0
  }
190
70
  if( sector_number == NULL )
191
0
  {
192
0
    libcerror_error_set(
193
0
     error,
194
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
195
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
196
0
     "%s: invalid sector number.",
197
0
     function );
198
199
0
    return( -1 );
200
0
  }
201
70
  *sector_number = partition_values->sector_number;
202
203
70
  return( 1 );
204
70
}
205
206
/* Retrieves the partition number of sectors
207
 * Returns 1 if successful or -1 on error
208
 */
209
int libvsmbr_partition_values_get_number_of_sectors(
210
     libvsmbr_partition_values_t *partition_values,
211
     uint32_t *number_of_sectors,
212
     libcerror_error_t **error )
213
70
{
214
70
  static char *function = "libvsmbr_partition_values_get_number_of_sectors";
215
216
70
  if( partition_values == NULL )
217
0
  {
218
0
    libcerror_error_set(
219
0
     error,
220
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
221
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
222
0
     "%s: invalid partition values.",
223
0
     function );
224
225
0
    return( -1 );
226
0
  }
227
70
  if( number_of_sectors == NULL )
228
0
  {
229
0
    libcerror_error_set(
230
0
     error,
231
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
232
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
233
0
     "%s: invalid number of sectors.",
234
0
     function );
235
236
0
    return( -1 );
237
0
  }
238
70
  *number_of_sectors = partition_values->number_of_sectors;
239
240
70
  return( 1 );
241
70
}
242