16
16
17
17
#define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER
18
18
19
+ #include < errno.h>
20
+ #include < fcntl.h>
19
21
#include < stdio.h>
20
22
#include < stdlib.h>
21
- #include < fcntl.h>
22
- #include < unistd.h>
23
- #include < errno.h>
24
23
#include < string.h>
25
- #include < stdlib .h>
24
+ #include < unistd .h>
26
25
27
- #include < sys/types.h>
28
26
#include < sys/ioctl.h>
29
27
#include < sys/stat.h>
28
+ #include < sys/types.h>
30
29
31
30
#include < linux/kdev_t.h>
32
31
33
32
#include < android-base/logging.h>
34
- #include < android-base/strings.h>
35
33
#include < android-base/stringprintf.h>
34
+ #include < android-base/strings.h>
36
35
#include < utils/Trace.h>
37
36
38
37
#include " Devmapper.h"
@@ -43,8 +42,7 @@ using android::base::StringPrintf;
43
42
44
43
static const char * kVoldPrefix = " vold:" ;
45
44
46
- void Devmapper::ioctlInit (struct dm_ioctl *io, size_t dataSize,
47
- const char *name, unsigned flags) {
45
+ void Devmapper::ioctlInit (struct dm_ioctl * io, size_t dataSize, const char * name, unsigned flags) {
48
46
memset (io, 0 , dataSize);
49
47
io->data_size = dataSize;
50
48
io->data_start = sizeof (struct dm_ioctl );
@@ -54,17 +52,16 @@ void Devmapper::ioctlInit(struct dm_ioctl *io, size_t dataSize,
54
52
io->flags = flags;
55
53
if (name) {
56
54
size_t ret = strlcpy (io->name , name, sizeof (io->name ));
57
- if (ret >= sizeof (io->name ))
58
- abort ();
55
+ if (ret >= sizeof (io->name )) abort ();
59
56
}
60
57
}
61
58
62
- int Devmapper::create (const char * name_raw, const char * loopFile, const char * key,
63
- unsigned long numSectors, char * ubuffer, size_t len) {
59
+ int Devmapper::create (const char * name_raw, const char * loopFile, const char * key,
60
+ unsigned long numSectors, char * ubuffer, size_t len) {
64
61
auto name_string = StringPrintf (" %s%s" , kVoldPrefix , name_raw);
65
62
const char * name = name_string.c_str ();
66
63
67
- char * buffer = (char *) malloc (DEVMAPPER_BUFFER_SIZE);
64
+ char * buffer = (char *) malloc (DEVMAPPER_BUFFER_SIZE);
68
65
if (!buffer) {
69
66
PLOG (ERROR) << " Failed malloc" ;
70
67
return -1 ;
@@ -77,8 +74,8 @@ int Devmapper::create(const char *name_raw, const char *loopFile, const char *ke
77
74
return -1 ;
78
75
}
79
76
80
- struct dm_ioctl * io = (struct dm_ioctl *) buffer;
81
-
77
+ struct dm_ioctl * io = (struct dm_ioctl *) buffer;
78
+
82
79
// Create the DM device
83
80
ioctlInit (io, DEVMAPPER_BUFFER_SIZE, name, 0 );
84
81
@@ -92,11 +89,11 @@ int Devmapper::create(const char *name_raw, const char *loopFile, const char *ke
92
89
// Set the legacy geometry
93
90
ioctlInit (io, DEVMAPPER_BUFFER_SIZE, name, 0 );
94
91
95
- char * geoParams = buffer + sizeof (struct dm_ioctl );
92
+ char * geoParams = buffer + sizeof (struct dm_ioctl );
96
93
// bps=512 spc=8 res=32 nft=2 sec=8190 mid=0xf0 spt=63 hds=64 hid=0 bspf=8 rdcl=2 infs=1 bkbs=2
97
94
strlcpy (geoParams, " 0 64 63 0" , DEVMAPPER_BUFFER_SIZE - sizeof (struct dm_ioctl ));
98
95
geoParams += strlen (geoParams) + 1 ;
99
- geoParams = (char *) _align (geoParams, 8 );
96
+ geoParams = (char *) _align (geoParams, 8 );
100
97
if (ioctl (fd, DM_DEV_SET_GEOMETRY, io)) {
101
98
PLOG (ERROR) << " Failed DM_DEV_SET_GEOMETRY" ;
102
99
free (buffer);
@@ -117,8 +114,8 @@ int Devmapper::create(const char *name_raw, const char *loopFile, const char *ke
117
114
snprintf (ubuffer, len, " /dev/block/dm-%u" , minor);
118
115
119
116
// Load the table
120
- struct dm_target_spec * tgt;
121
- tgt = (struct dm_target_spec *) &buffer[sizeof (struct dm_ioctl )];
117
+ struct dm_target_spec * tgt;
118
+ tgt = (struct dm_target_spec *) &buffer[sizeof (struct dm_ioctl )];
122
119
123
120
ioctlInit (io, DEVMAPPER_BUFFER_SIZE, name, DM_STATUS_TABLE_FLAG);
124
121
io->target_count = 1 ;
@@ -129,12 +126,12 @@ int Devmapper::create(const char *name_raw, const char *loopFile, const char *ke
129
126
130
127
strlcpy (tgt->target_type , " crypt" , sizeof (tgt->target_type ));
131
128
132
- char * cryptParams = buffer + sizeof (struct dm_ioctl ) + sizeof (struct dm_target_spec );
129
+ char * cryptParams = buffer + sizeof (struct dm_ioctl ) + sizeof (struct dm_target_spec );
133
130
snprintf (cryptParams,
134
- DEVMAPPER_BUFFER_SIZE - (sizeof (struct dm_ioctl ) + sizeof (struct dm_target_spec )),
135
- " twofish %s 0 %s 0" , key, loopFile);
131
+ DEVMAPPER_BUFFER_SIZE - (sizeof (struct dm_ioctl ) + sizeof (struct dm_target_spec )),
132
+ " twofish %s 0 %s 0" , key, loopFile);
136
133
cryptParams += strlen (cryptParams) + 1 ;
137
- cryptParams = (char *) _align (cryptParams, 8 );
134
+ cryptParams = (char *) _align (cryptParams, 8 );
138
135
tgt->next = cryptParams - buffer;
139
136
140
137
if (ioctl (fd, DM_TABLE_LOAD, io)) {
@@ -160,11 +157,11 @@ int Devmapper::create(const char *name_raw, const char *loopFile, const char *ke
160
157
return 0 ;
161
158
}
162
159
163
- int Devmapper::destroy (const char * name_raw) {
160
+ int Devmapper::destroy (const char * name_raw) {
164
161
auto name_string = StringPrintf (" %s%s" , kVoldPrefix , name_raw);
165
162
const char * name = name_string.c_str ();
166
163
167
- char * buffer = (char *) malloc (DEVMAPPER_BUFFER_SIZE);
164
+ char * buffer = (char *) malloc (DEVMAPPER_BUFFER_SIZE);
168
165
if (!buffer) {
169
166
PLOG (ERROR) << " Failed malloc" ;
170
167
return -1 ;
@@ -177,8 +174,8 @@ int Devmapper::destroy(const char *name_raw) {
177
174
return -1 ;
178
175
}
179
176
180
- struct dm_ioctl * io = (struct dm_ioctl *) buffer;
181
-
177
+ struct dm_ioctl * io = (struct dm_ioctl *) buffer;
178
+
182
179
// Create the DM device
183
180
ioctlInit (io, DEVMAPPER_BUFFER_SIZE, name, 0 );
184
181
@@ -198,14 +195,14 @@ int Devmapper::destroy(const char *name_raw) {
198
195
199
196
int Devmapper::destroyAll () {
200
197
ATRACE_NAME (" Devmapper::destroyAll" );
201
- char * buffer = (char *) malloc (1024 * 64 );
198
+ char * buffer = (char *) malloc (1024 * 64 );
202
199
if (!buffer) {
203
200
PLOG (ERROR) << " Failed malloc" ;
204
201
return -1 ;
205
202
}
206
203
memset (buffer, 0 , (1024 * 64 ));
207
204
208
- char * buffer2 = (char *) malloc (DEVMAPPER_BUFFER_SIZE);
205
+ char * buffer2 = (char *) malloc (DEVMAPPER_BUFFER_SIZE);
209
206
if (!buffer2) {
210
207
PLOG (ERROR) << " Failed malloc" ;
211
208
free (buffer);
@@ -220,7 +217,7 @@ int Devmapper::destroyAll() {
220
217
return -1 ;
221
218
}
222
219
223
- struct dm_ioctl * io = (struct dm_ioctl *) buffer;
220
+ struct dm_ioctl * io = (struct dm_ioctl *) buffer;
224
221
ioctlInit (io, (1024 * 64 ), NULL , 0 );
225
222
226
223
if (ioctl (fd, DM_LIST_DEVICES, io)) {
@@ -231,7 +228,7 @@ int Devmapper::destroyAll() {
231
228
return -1 ;
232
229
}
233
230
234
- struct dm_name_list * n = (struct dm_name_list *) (((char *) buffer) + io->data_start );
231
+ struct dm_name_list * n = (struct dm_name_list *) (((char *) buffer) + io->data_start );
235
232
if (!n->dev ) {
236
233
free (buffer);
237
234
free (buffer2);
@@ -241,13 +238,13 @@ int Devmapper::destroyAll() {
241
238
242
239
unsigned nxt = 0 ;
243
240
do {
244
- n = (struct dm_name_list *) (((char *) n) + nxt);
241
+ n = (struct dm_name_list *) (((char *) n) + nxt);
245
242
auto name = std::string (n->name );
246
243
if (android::base::StartsWith (name, kVoldPrefix )) {
247
244
LOG (DEBUG) << " Tearing down stale dm device named " << name;
248
245
249
246
memset (buffer2, 0 , DEVMAPPER_BUFFER_SIZE);
250
- struct dm_ioctl * io2 = (struct dm_ioctl *) buffer2;
247
+ struct dm_ioctl * io2 = (struct dm_ioctl *) buffer2;
251
248
ioctlInit (io2, DEVMAPPER_BUFFER_SIZE, n->name , 0 );
252
249
if (ioctl (fd, DM_DEV_REMOVE, io2)) {
253
250
if (errno != ENXIO) {
@@ -266,9 +263,8 @@ int Devmapper::destroyAll() {
266
263
return 0 ;
267
264
}
268
265
269
- void *Devmapper::_align (void *ptr, unsigned int a)
270
- {
271
- unsigned long agn = --a;
266
+ void * Devmapper::_align (void * ptr, unsigned int a) {
267
+ unsigned long agn = --a;
272
268
273
- return (void *) (((unsigned long ) ptr + agn) & ~agn);
269
+ return (void *) (((unsigned long )ptr + agn) & ~agn);
274
270
}
0 commit comments