San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER |
| 18 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 19 | #include <errno.h> |
| 20 | #include <fcntl.h> |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 21 | #include <stdio.h> |
Olivier Bailly | 37dcda6 | 2010-11-16 10:41:53 -0800 | [diff] [blame] | 22 | #include <stdlib.h> |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 23 | #include <string.h> |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 24 | #include <unistd.h> |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 25 | |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 26 | #include <sys/ioctl.h> |
| 27 | #include <sys/stat.h> |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 28 | #include <sys/types.h> |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 29 | |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 30 | #include <linux/kdev_t.h> |
| 31 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 32 | #include <android-base/logging.h> |
| 33 | #include <android-base/stringprintf.h> |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 34 | #include <android-base/strings.h> |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 35 | #include <utils/Trace.h> |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 36 | |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 37 | #include "Devmapper.h" |
| 38 | |
Peter Bohm | 092aa1c | 2011-04-01 12:35:25 +0200 | [diff] [blame] | 39 | #define DEVMAPPER_BUFFER_SIZE 4096 |
| 40 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 41 | using android::base::StringPrintf; |
| 42 | |
| 43 | static const char* kVoldPrefix = "vold:"; |
| 44 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 45 | void Devmapper::ioctlInit(struct dm_ioctl* io, size_t dataSize, const char* name, unsigned flags) { |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 46 | memset(io, 0, dataSize); |
| 47 | io->data_size = dataSize; |
| 48 | io->data_start = sizeof(struct dm_ioctl); |
| 49 | io->version[0] = 4; |
| 50 | io->version[1] = 0; |
| 51 | io->version[2] = 0; |
| 52 | io->flags = flags; |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 53 | if (name) { |
Chih-Wei Huang | 7929deb | 2013-02-10 22:57:14 +0800 | [diff] [blame] | 54 | size_t ret = strlcpy(io->name, name, sizeof(io->name)); |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 55 | if (ret >= sizeof(io->name)) abort(); |
San Mehat | d9a4e35 | 2010-03-12 13:32:47 -0800 | [diff] [blame] | 56 | } |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 59 | int Devmapper::create(const char* name_raw, const char* loopFile, const char* key, |
| 60 | unsigned long numSectors, char* ubuffer, size_t len) { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 61 | auto name_string = StringPrintf("%s%s", kVoldPrefix, name_raw); |
| 62 | const char* name = name_string.c_str(); |
| 63 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 64 | char* buffer = (char*)malloc(DEVMAPPER_BUFFER_SIZE); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 65 | if (!buffer) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 66 | PLOG(ERROR) << "Failed malloc"; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 67 | return -1; |
| 68 | } |
| 69 | |
| 70 | int fd; |
Jeff Sharkey | ce6a913 | 2015-04-08 21:07:21 -0700 | [diff] [blame] | 71 | if ((fd = open("/dev/device-mapper", O_RDWR | O_CLOEXEC)) < 0) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 72 | PLOG(ERROR) << "Failed open"; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 73 | free(buffer); |
| 74 | return -1; |
| 75 | } |
| 76 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 77 | struct dm_ioctl* io = (struct dm_ioctl*)buffer; |
| 78 | |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 79 | // Create the DM device |
Peter Bohm | 092aa1c | 2011-04-01 12:35:25 +0200 | [diff] [blame] | 80 | ioctlInit(io, DEVMAPPER_BUFFER_SIZE, name, 0); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 81 | |
| 82 | if (ioctl(fd, DM_DEV_CREATE, io)) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 83 | PLOG(ERROR) << "Failed DM_DEV_CREATE"; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 84 | free(buffer); |
| 85 | close(fd); |
| 86 | return -1; |
| 87 | } |
| 88 | |
| 89 | // Set the legacy geometry |
Peter Bohm | 092aa1c | 2011-04-01 12:35:25 +0200 | [diff] [blame] | 90 | ioctlInit(io, DEVMAPPER_BUFFER_SIZE, name, 0); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 91 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 92 | char* geoParams = buffer + sizeof(struct dm_ioctl); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 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 |
Jeff Sharkey | 32ebb73 | 2017-03-27 16:18:50 -0600 | [diff] [blame] | 94 | strlcpy(geoParams, "0 64 63 0", DEVMAPPER_BUFFER_SIZE - sizeof(struct dm_ioctl)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 95 | geoParams += strlen(geoParams) + 1; |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 96 | geoParams = (char*)_align(geoParams, 8); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 97 | if (ioctl(fd, DM_DEV_SET_GEOMETRY, io)) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 98 | PLOG(ERROR) << "Failed DM_DEV_SET_GEOMETRY"; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 99 | free(buffer); |
| 100 | close(fd); |
| 101 | return -1; |
| 102 | } |
| 103 | |
| 104 | // Retrieve the device number we were allocated |
Peter Bohm | 092aa1c | 2011-04-01 12:35:25 +0200 | [diff] [blame] | 105 | ioctlInit(io, DEVMAPPER_BUFFER_SIZE, name, 0); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 106 | if (ioctl(fd, DM_DEV_STATUS, io)) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 107 | PLOG(ERROR) << "Failed DM_DEV_STATUS"; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 108 | free(buffer); |
| 109 | close(fd); |
| 110 | return -1; |
| 111 | } |
| 112 | |
| 113 | unsigned minor = (io->dev & 0xff) | ((io->dev >> 12) & 0xfff00); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 114 | snprintf(ubuffer, len, "/dev/block/dm-%u", minor); |
| 115 | |
| 116 | // Load the table |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 117 | struct dm_target_spec* tgt; |
| 118 | tgt = (struct dm_target_spec*)&buffer[sizeof(struct dm_ioctl)]; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 119 | |
Peter Bohm | 092aa1c | 2011-04-01 12:35:25 +0200 | [diff] [blame] | 120 | ioctlInit(io, DEVMAPPER_BUFFER_SIZE, name, DM_STATUS_TABLE_FLAG); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 121 | io->target_count = 1; |
| 122 | tgt->status = 0; |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 123 | |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 124 | tgt->sector_start = 0; |
San Mehat | 8b8f71b | 2010-01-11 09:17:25 -0800 | [diff] [blame] | 125 | tgt->length = numSectors; |
San Mehat | fcf24fe | 2010-03-03 12:37:32 -0800 | [diff] [blame] | 126 | |
Peter Bohm | 092aa1c | 2011-04-01 12:35:25 +0200 | [diff] [blame] | 127 | strlcpy(tgt->target_type, "crypt", sizeof(tgt->target_type)); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 128 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 129 | char* cryptParams = buffer + sizeof(struct dm_ioctl) + sizeof(struct dm_target_spec); |
Peter Bohm | 092aa1c | 2011-04-01 12:35:25 +0200 | [diff] [blame] | 130 | snprintf(cryptParams, |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 131 | DEVMAPPER_BUFFER_SIZE - (sizeof(struct dm_ioctl) + sizeof(struct dm_target_spec)), |
| 132 | "twofish %s 0 %s 0", key, loopFile); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 133 | cryptParams += strlen(cryptParams) + 1; |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 134 | cryptParams = (char*)_align(cryptParams, 8); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 135 | tgt->next = cryptParams - buffer; |
| 136 | |
| 137 | if (ioctl(fd, DM_TABLE_LOAD, io)) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 138 | PLOG(ERROR) << "Failed DM_TABLE_LOAD"; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 139 | free(buffer); |
| 140 | close(fd); |
| 141 | return -1; |
| 142 | } |
| 143 | |
| 144 | // Resume the new table |
Peter Bohm | 092aa1c | 2011-04-01 12:35:25 +0200 | [diff] [blame] | 145 | ioctlInit(io, DEVMAPPER_BUFFER_SIZE, name, 0); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 146 | |
| 147 | if (ioctl(fd, DM_DEV_SUSPEND, io)) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 148 | PLOG(ERROR) << "Failed DM_DEV_SUSPEND"; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 149 | free(buffer); |
| 150 | close(fd); |
| 151 | return -1; |
| 152 | } |
| 153 | |
| 154 | free(buffer); |
| 155 | |
San Mehat | 8c940ef | 2010-02-13 14:19:53 -0800 | [diff] [blame] | 156 | close(fd); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 160 | int Devmapper::destroy(const char* name_raw) { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 161 | auto name_string = StringPrintf("%s%s", kVoldPrefix, name_raw); |
| 162 | const char* name = name_string.c_str(); |
| 163 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 164 | char* buffer = (char*)malloc(DEVMAPPER_BUFFER_SIZE); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 165 | if (!buffer) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 166 | PLOG(ERROR) << "Failed malloc"; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 167 | return -1; |
| 168 | } |
| 169 | |
| 170 | int fd; |
Jeff Sharkey | ce6a913 | 2015-04-08 21:07:21 -0700 | [diff] [blame] | 171 | if ((fd = open("/dev/device-mapper", O_RDWR | O_CLOEXEC)) < 0) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 172 | PLOG(ERROR) << "Failed open"; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 173 | free(buffer); |
| 174 | return -1; |
| 175 | } |
| 176 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 177 | struct dm_ioctl* io = (struct dm_ioctl*)buffer; |
| 178 | |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 179 | // Create the DM device |
Peter Bohm | 092aa1c | 2011-04-01 12:35:25 +0200 | [diff] [blame] | 180 | ioctlInit(io, DEVMAPPER_BUFFER_SIZE, name, 0); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 181 | |
| 182 | if (ioctl(fd, DM_DEV_REMOVE, io)) { |
San Mehat | 0586d54 | 2010-01-12 15:38:59 -0800 | [diff] [blame] | 183 | if (errno != ENXIO) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 184 | PLOG(ERROR) << "Failed DM_DEV_REMOVE"; |
San Mehat | 0586d54 | 2010-01-12 15:38:59 -0800 | [diff] [blame] | 185 | } |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 186 | free(buffer); |
| 187 | close(fd); |
| 188 | return -1; |
| 189 | } |
| 190 | |
| 191 | free(buffer); |
| 192 | close(fd); |
| 193 | return 0; |
| 194 | } |
| 195 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 196 | int Devmapper::destroyAll() { |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 197 | ATRACE_NAME("Devmapper::destroyAll"); |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 198 | char* buffer = (char*)malloc(1024 * 64); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 199 | if (!buffer) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 200 | PLOG(ERROR) << "Failed malloc"; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 201 | return -1; |
| 202 | } |
| 203 | memset(buffer, 0, (1024 * 64)); |
| 204 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 205 | char* buffer2 = (char*)malloc(DEVMAPPER_BUFFER_SIZE); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 206 | if (!buffer2) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 207 | PLOG(ERROR) << "Failed malloc"; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 208 | free(buffer); |
| 209 | return -1; |
| 210 | } |
| 211 | |
| 212 | int fd; |
| 213 | if ((fd = open("/dev/device-mapper", O_RDWR | O_CLOEXEC)) < 0) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 214 | PLOG(ERROR) << "Failed open"; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 215 | free(buffer); |
| 216 | free(buffer2); |
| 217 | return -1; |
| 218 | } |
| 219 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 220 | struct dm_ioctl* io = (struct dm_ioctl*)buffer; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 221 | ioctlInit(io, (1024 * 64), NULL, 0); |
| 222 | |
| 223 | if (ioctl(fd, DM_LIST_DEVICES, io)) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 224 | PLOG(ERROR) << "Failed DM_LIST_DEVICES"; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 225 | free(buffer); |
| 226 | free(buffer2); |
| 227 | close(fd); |
| 228 | return -1; |
| 229 | } |
| 230 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 231 | struct dm_name_list* n = (struct dm_name_list*)(((char*)buffer) + io->data_start); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 232 | if (!n->dev) { |
| 233 | free(buffer); |
| 234 | free(buffer2); |
| 235 | close(fd); |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | unsigned nxt = 0; |
| 240 | do { |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 241 | n = (struct dm_name_list*)(((char*)n) + nxt); |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 242 | auto name = std::string(n->name); |
| 243 | if (android::base::StartsWith(name, kVoldPrefix)) { |
| 244 | LOG(DEBUG) << "Tearing down stale dm device named " << name; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 245 | |
| 246 | memset(buffer2, 0, DEVMAPPER_BUFFER_SIZE); |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 247 | struct dm_ioctl* io2 = (struct dm_ioctl*)buffer2; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 248 | ioctlInit(io2, DEVMAPPER_BUFFER_SIZE, n->name, 0); |
| 249 | if (ioctl(fd, DM_DEV_REMOVE, io2)) { |
| 250 | if (errno != ENXIO) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 251 | PLOG(WARNING) << "Failed to destroy dm device named " << name; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | } else { |
Sudheer Shanka | 4b6ca4e | 2018-09-21 10:54:54 -0700 | [diff] [blame] | 255 | LOG(DEBUG) << "Found unmanaged dm device named " << name; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 256 | } |
| 257 | nxt = n->next; |
| 258 | } while (nxt); |
| 259 | |
| 260 | free(buffer); |
| 261 | free(buffer2); |
| 262 | close(fd); |
| 263 | return 0; |
| 264 | } |
| 265 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 266 | void* Devmapper::_align(void* ptr, unsigned int a) { |
| 267 | unsigned long agn = --a; |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 268 | |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 269 | return (void*)(((unsigned long)ptr + agn) & ~agn); |
San Mehat | b78a32c | 2010-01-10 13:02:12 -0800 | [diff] [blame] | 270 | } |