blob: 51eeba891b2c4bd930a13a59a865ffa7ce19191a [file] [log] [blame]
Jeff Sharkeydeb24052015-03-02 21:01:40 -08001/*
2 * Copyright (C) 2015 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 Sharkeydeb24052015-03-02 21:01:40 -080017#include "Disk.h"
18#include "PublicVolume.h"
Jeff Sharkey9c484982015-03-31 10:35:33 -070019#include "PrivateVolume.h"
Jeff Sharkeydeb24052015-03-02 21:01:40 -080020#include "Utils.h"
21#include "VolumeBase.h"
Jeff Sharkey36801cc2015-03-13 16:09:20 -070022#include "VolumeManager.h"
23#include "ResponseCode.h"
Jeff Sharkeydeb24052015-03-02 21:01:40 -080024
Dan Albertae9e8902015-03-16 10:35:17 -070025#include <base/file.h>
26#include <base/stringprintf.h>
Jeff Sharkey36801cc2015-03-13 16:09:20 -070027#include <base/logging.h>
Jeff Sharkeydeb24052015-03-02 21:01:40 -080028#include <diskconfig/diskconfig.h>
Jeff Sharkeydeb24052015-03-02 21:01:40 -080029
Jeff Sharkey9c484982015-03-31 10:35:33 -070030#include <vector>
Jeff Sharkeydeb24052015-03-02 21:01:40 -080031#include <fcntl.h>
Jeff Sharkey38cfc022015-03-30 21:22:07 -070032#include <inttypes.h>
Jeff Sharkeydeb24052015-03-02 21:01:40 -080033#include <stdio.h>
34#include <stdlib.h>
35#include <sys/types.h>
36#include <sys/stat.h>
37#include <sys/mount.h>
38
Dan Albertae9e8902015-03-16 10:35:17 -070039using android::base::ReadFileToString;
Jeff Sharkey9c484982015-03-31 10:35:33 -070040using android::base::WriteStringToFile;
Dan Albertae9e8902015-03-16 10:35:17 -070041using android::base::StringPrintf;
42
Jeff Sharkeydeb24052015-03-02 21:01:40 -080043namespace android {
44namespace vold {
45
46static const char* kSgdiskPath = "/system/bin/sgdisk";
47static const char* kSgdiskToken = " \t\n";
48
49static const char* kSysfsMmcMaxMinors = "/sys/module/mmcblk/parameters/perdev_minors";
50
51static const unsigned int kMajorBlockScsi = 8;
52static const unsigned int kMajorBlockMmc = 179;
53
54static const char* kGptBasicData = "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7";
55static const char* kGptAndroidMeta = "19A710A2-B3CA-11E4-B026-10604B889DCF";
Jeff Sharkeyce6a9132015-04-08 21:07:21 -070056static const char* kGptAndroidExpand = "193D1EA4-B3CA-11E4-B075-10604B889DCF";
Jeff Sharkeydeb24052015-03-02 21:01:40 -080057
Jeff Sharkey9c484982015-03-31 10:35:33 -070058static const char* kKeyPath = "/data/misc/vold";
59
Jeff Sharkeydeb24052015-03-02 21:01:40 -080060enum class Table {
61 kUnknown,
62 kMbr,
63 kGpt,
64};
65
Jeff Sharkeyce6a9132015-04-08 21:07:21 -070066Disk::Disk(const std::string& eventPath, dev_t device,
67 const std::string& nickname, int flags) :
68 mDevice(device), mSize(-1), mNickname(nickname), mFlags(flags), mCreated(
69 false), mJustPartitioned(false) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -070070 mId = StringPrintf("disk:%u,%u", major(device), minor(device));
71 mEventPath = eventPath;
Jeff Sharkeydeb24052015-03-02 21:01:40 -080072 mSysPath = StringPrintf("/sys/%s", eventPath.c_str());
Jeff Sharkey36801cc2015-03-13 16:09:20 -070073 mDevPath = StringPrintf("/dev/block/vold/%s", mId.c_str());
Jeff Sharkeydeb24052015-03-02 21:01:40 -080074 CreateDeviceNode(mDevPath, mDevice);
75}
76
77Disk::~Disk() {
Jeff Sharkey36801cc2015-03-13 16:09:20 -070078 CHECK(!mCreated);
Jeff Sharkeydeb24052015-03-02 21:01:40 -080079 DestroyDeviceNode(mDevPath);
80}
81
82std::shared_ptr<VolumeBase> Disk::findVolume(const std::string& id) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -070083 for (auto vol : mVolumes) {
84 if (vol->getId() == id) {
85 return vol;
86 }
87 auto stackedVol = vol->findVolume(id);
88 if (stackedVol != nullptr) {
89 return stackedVol;
Jeff Sharkeydeb24052015-03-02 21:01:40 -080090 }
91 }
92 return nullptr;
93}
94
Jeff Sharkey36801cc2015-03-13 16:09:20 -070095status_t Disk::create() {
96 CHECK(!mCreated);
97 mCreated = true;
Jeff Sharkeyce6a9132015-04-08 21:07:21 -070098 notifyEvent(ResponseCode::DiskCreated, StringPrintf("%d", mFlags));
Jeff Sharkey36801cc2015-03-13 16:09:20 -070099 readMetadata();
100 readPartitions();
101 return OK;
102}
103
104status_t Disk::destroy() {
105 CHECK(mCreated);
106 destroyAllVolumes();
107 mCreated = false;
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700108 notifyEvent(ResponseCode::DiskDestroyed);
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700109 return OK;
110}
111
Jeff Sharkey9c484982015-03-31 10:35:33 -0700112static std::string BuildKeyPath(const std::string& partGuid) {
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700113 return StringPrintf("%s/expand_%s.key", kKeyPath, partGuid.c_str());
Jeff Sharkey9c484982015-03-31 10:35:33 -0700114}
115
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700116void Disk::createPublicVolume(dev_t device) {
Jeff Sharkey9c484982015-03-31 10:35:33 -0700117 auto vol = std::shared_ptr<VolumeBase>(new PublicVolume(device));
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700118 if (mJustPartitioned) {
119 LOG(DEBUG) << "Device just partitioned; silently formatting";
120 vol->setSilent(true);
121 vol->create();
122 vol->format();
123 vol->destroy();
124 vol->setSilent(false);
125 }
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700126
Jeff Sharkey9c484982015-03-31 10:35:33 -0700127 mVolumes.push_back(vol);
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700128 vol->create();
129 notifyEvent(ResponseCode::DiskVolumeCreated, vol->getId());
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700130}
131
Jeff Sharkey9c484982015-03-31 10:35:33 -0700132void Disk::createPrivateVolume(dev_t device, const std::string& partGuid) {
133 std::string tmp;
134 std::string normalizedGuid;
135 if (HexToStr(partGuid, tmp)) {
136 LOG(WARNING) << "Invalid GUID " << partGuid;
137 return;
138 }
139 StrToHex(tmp, normalizedGuid);
140
141 std::string keyRaw;
142 if (!ReadFileToString(BuildKeyPath(normalizedGuid), &keyRaw)) {
143 PLOG(ERROR) << "Failed to load key for GUID " << normalizedGuid;
144 return;
145 }
146
147 LOG(DEBUG) << "Found key for GUID " << normalizedGuid;
148
149 auto vol = std::shared_ptr<VolumeBase>(new PrivateVolume(device, keyRaw));
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700150 if (mJustPartitioned) {
151 LOG(DEBUG) << "Device just partitioned; silently formatting";
152 vol->setSilent(true);
153 vol->create();
154 vol->format();
155 vol->destroy();
156 vol->setSilent(false);
157 }
Jeff Sharkey9c484982015-03-31 10:35:33 -0700158
159 mVolumes.push_back(vol);
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700160 vol->create();
161 notifyEvent(ResponseCode::DiskVolumeCreated, vol->getId());
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700162}
163
164void Disk::destroyAllVolumes() {
165 for (auto vol : mVolumes) {
166 vol->destroy();
Jeff Sharkey502164d2015-04-14 16:45:18 -0700167 notifyEvent(ResponseCode::DiskVolumeDestroyed, vol->getId());
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700168 }
169 mVolumes.clear();
170}
171
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800172status_t Disk::readMetadata() {
173 mSize = -1;
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700174 mLabel.clear();
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800175
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700176 int fd = open(mDevPath.c_str(), O_RDONLY | O_CLOEXEC);
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700177 if (fd != -1) {
178 if (ioctl(fd, BLKGETSIZE64, &mSize)) {
179 mSize = -1;
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800180 }
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700181 close(fd);
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800182 }
183
184 switch (major(mDevice)) {
185 case kMajorBlockScsi: {
186 std::string path(mSysPath + "/device/vendor");
187 std::string tmp;
188 if (!ReadFileToString(path, &tmp)) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700189 PLOG(WARNING) << "Failed to read vendor from " << path;
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800190 return -errno;
191 }
192 mLabel = tmp;
193 break;
194 }
195 case kMajorBlockMmc: {
196 std::string path(mSysPath + "/device/manfid");
197 std::string tmp;
198 if (!ReadFileToString(path, &tmp)) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700199 PLOG(WARNING) << "Failed to read manufacturer from " << path;
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800200 return -errno;
201 }
202 uint64_t manfid = strtoll(tmp.c_str(), nullptr, 16);
203 // Our goal here is to give the user a meaningful label, ideally
204 // matching whatever is silk-screened on the card. To reduce
205 // user confusion, this list doesn't contain white-label manfid.
206 switch (manfid) {
207 case 0x000003: mLabel = "SanDisk"; break;
208 case 0x00001b: mLabel = "Samsung"; break;
209 case 0x000028: mLabel = "Lexar"; break;
210 case 0x000074: mLabel = "Transcend"; break;
211 }
212 break;
213 }
214 default: {
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700215 LOG(WARNING) << "Unsupported block major type" << major(mDevice);
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800216 return -ENOTSUP;
217 }
218 }
219
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700220 notifyEvent(ResponseCode::DiskSizeChanged, StringPrintf("%" PRId64, mSize));
221 notifyEvent(ResponseCode::DiskLabelChanged, mLabel);
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800222 return OK;
223}
224
225status_t Disk::readPartitions() {
Jeff Sharkey7d9d0112015-04-14 23:14:23 -0700226 std::lock_guard<std::mutex> lock(mLock);
227
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800228 int8_t maxMinors = getMaxMinors();
229 if (maxMinors < 0) {
230 return -ENOTSUP;
231 }
232
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700233 destroyAllVolumes();
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800234
235 // Parse partition table
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700236
237 std::vector<std::string> cmd;
238 cmd.push_back(kSgdiskPath);
239 cmd.push_back("--android-dump");
240 cmd.push_back(mDevPath);
241
242 std::vector<std::string> output;
243 status_t res = ForkExecvp(cmd, output);
244 if (res != OK) {
245 LOG(WARNING) << "sgdisk failed to scan " << mDevPath;
246 mJustPartitioned = false;
247 return res;
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800248 }
249
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800250 Table table = Table::kUnknown;
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700251 bool foundParts = false;
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700252 for (auto line : output) {
253 char* cline = (char*) line.c_str();
254 char* token = strtok(cline, kSgdiskToken);
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700255 if (token == nullptr) continue;
256
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800257 if (!strcmp(token, "DISK")) {
258 const char* type = strtok(nullptr, kSgdiskToken);
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800259 if (!strcmp(type, "mbr")) {
260 table = Table::kMbr;
261 } else if (!strcmp(type, "gpt")) {
262 table = Table::kGpt;
263 }
264 } else if (!strcmp(token, "PART")) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700265 foundParts = true;
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800266 int i = strtol(strtok(nullptr, kSgdiskToken), nullptr, 10);
267 if (i <= 0 || i > maxMinors) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700268 LOG(WARNING) << mId << " is ignoring partition " << i
269 << " beyond max supported devices";
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800270 continue;
271 }
272 dev_t partDevice = makedev(major(mDevice), minor(mDevice) + i);
273
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800274 if (table == Table::kMbr) {
275 const char* type = strtok(nullptr, kSgdiskToken);
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800276
277 switch (strtol(type, nullptr, 16)) {
278 case 0x06: // FAT16
279 case 0x0b: // W95 FAT32 (LBA)
280 case 0x0c: // W95 FAT32 (LBA)
281 case 0x0e: // W95 FAT16 (LBA)
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700282 createPublicVolume(partDevice);
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800283 break;
284 }
285 } else if (table == Table::kGpt) {
286 const char* typeGuid = strtok(nullptr, kSgdiskToken);
287 const char* partGuid = strtok(nullptr, kSgdiskToken);
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800288
289 if (!strcasecmp(typeGuid, kGptBasicData)) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700290 createPublicVolume(partDevice);
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700291 } else if (!strcasecmp(typeGuid, kGptAndroidExpand)) {
Jeff Sharkey9c484982015-03-31 10:35:33 -0700292 createPrivateVolume(partDevice, partGuid);
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800293 }
294 }
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800295 }
296 }
297
298 // Ugly last ditch effort, treat entire disk as partition
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700299 if (table == Table::kUnknown || !foundParts) {
300 LOG(WARNING) << mId << " has unknown partition table; trying entire device";
301 createPublicVolume(mDevice);
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800302 }
303
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700304 mJustPartitioned = false;
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800305 return OK;
306}
307
Jeff Sharkey9c484982015-03-31 10:35:33 -0700308status_t Disk::unmountAll() {
309 for (auto vol : mVolumes) {
310 vol->unmount();
311 }
312 return OK;
313}
314
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800315status_t Disk::partitionPublic() {
Jeff Sharkey7d9d0112015-04-14 23:14:23 -0700316 std::lock_guard<std::mutex> lock(mLock);
317
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800318 // TODO: improve this code
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700319 destroyAllVolumes();
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700320 mJustPartitioned = true;
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800321
322 struct disk_info dinfo;
323 memset(&dinfo, 0, sizeof(dinfo));
324
325 if (!(dinfo.part_lst = (struct part_info *) malloc(
326 MAX_NUM_PARTS * sizeof(struct part_info)))) {
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800327 return -1;
328 }
329
330 memset(dinfo.part_lst, 0, MAX_NUM_PARTS * sizeof(struct part_info));
331 dinfo.device = strdup(mDevPath.c_str());
332 dinfo.scheme = PART_SCHEME_MBR;
333 dinfo.sect_size = 512;
334 dinfo.skip_lba = 2048;
335 dinfo.num_lba = 0;
336 dinfo.num_parts = 1;
337
338 struct part_info *pinfo = &dinfo.part_lst[0];
339
340 pinfo->name = strdup("android_sdcard");
341 pinfo->flags |= PART_ACTIVE_FLAG;
342 pinfo->type = PC_PART_TYPE_FAT32;
343 pinfo->len_kb = -1;
344
345 int rc = apply_disk_config(&dinfo, 0);
346 if (rc) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700347 LOG(ERROR) << "Failed to apply disk configuration: " << rc;
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800348 goto out;
349 }
350
351out:
352 free(pinfo->name);
353 free(dinfo.device);
354 free(dinfo.part_lst);
355
356 return rc;
357}
358
359status_t Disk::partitionPrivate() {
Jeff Sharkey9c484982015-03-31 10:35:33 -0700360 return partitionMixed(0);
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800361}
362
363status_t Disk::partitionMixed(int8_t ratio) {
Jeff Sharkey7d9d0112015-04-14 23:14:23 -0700364 std::lock_guard<std::mutex> lock(mLock);
365
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700366 int res;
Jeff Sharkey9c484982015-03-31 10:35:33 -0700367
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700368 destroyAllVolumes();
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700369 mJustPartitioned = true;
Jeff Sharkey9c484982015-03-31 10:35:33 -0700370
371 // First nuke any existing partition table
372 std::vector<std::string> cmd;
373 cmd.push_back(kSgdiskPath);
374 cmd.push_back("--zap-all");
375 cmd.push_back(mDevPath);
376
Jeff Sharkeyffeb0072015-04-14 22:22:34 -0700377 // Zap sometimes returns an error when it actually succeeded, so
378 // just log as warning and keep rolling forward.
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700379 if ((res = ForkExecvp(cmd)) != 0) {
Jeff Sharkeyffeb0072015-04-14 22:22:34 -0700380 LOG(WARNING) << "Failed to zap; status " << res;
Jeff Sharkey9c484982015-03-31 10:35:33 -0700381 }
382
383 // We've had some success above, so generate both the private partition
384 // GUID and encryption key and persist them.
385 std::string partGuidRaw;
386 std::string keyRaw;
387 if (ReadRandomBytes(16, partGuidRaw) || ReadRandomBytes(16, keyRaw)) {
388 LOG(ERROR) << "Failed to generate GUID or key";
389 return -EIO;
390 }
391
392 std::string partGuid;
393 StrToHex(partGuidRaw, partGuid);
394
395 if (!WriteStringToFile(keyRaw, BuildKeyPath(partGuid))) {
396 LOG(ERROR) << "Failed to persist key";
397 return -EIO;
398 } else {
399 LOG(DEBUG) << "Persisted key for GUID " << partGuid;
400 }
401
402 // Now let's build the new GPT table. We heavily rely on sgdisk to
403 // force optimal alignment on the created partitions.
404 cmd.clear();
405 cmd.push_back(kSgdiskPath);
406
407 // If requested, create a public partition first. Mixed-mode partitioning
408 // like this is an experimental feature.
409 if (ratio > 0) {
410 if (ratio < 10 || ratio > 90) {
411 LOG(ERROR) << "Mixed partition ratio must be between 10-90%";
412 return -EINVAL;
413 }
414
415 uint64_t splitMb = ((mSize / 100) * ratio) / 1024 / 1024;
416 cmd.push_back(StringPrintf("--new=0:0:+%" PRId64 "M", splitMb));
417 cmd.push_back(StringPrintf("--typecode=0:%s", kGptBasicData));
418 cmd.push_back("--change-name=0:shared");
419 }
420
421 // Define a metadata partition which is designed for future use; there
422 // should only be one of these per physical device, even if there are
423 // multiple private volumes.
424 cmd.push_back("--new=0:0:+16M");
425 cmd.push_back(StringPrintf("--typecode=0:%s", kGptAndroidMeta));
426 cmd.push_back("--change-name=0:android_meta");
427
428 // Define a single private partition filling the rest of disk.
429 cmd.push_back("--new=0:0:-0");
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700430 cmd.push_back(StringPrintf("--typecode=0:%s", kGptAndroidExpand));
Jeff Sharkey9c484982015-03-31 10:35:33 -0700431 cmd.push_back(StringPrintf("--partition-guid=0:%s", partGuid.c_str()));
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700432 cmd.push_back("--change-name=0:android_expand");
Jeff Sharkey9c484982015-03-31 10:35:33 -0700433
434 cmd.push_back(mDevPath);
435
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700436 if ((res = ForkExecvp(cmd)) != 0) {
437 LOG(ERROR) << "Failed to partition; status " << res;
438 return res;
Jeff Sharkey9c484982015-03-31 10:35:33 -0700439 }
440
441 return OK;
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800442}
443
Jeff Sharkeyce6a9132015-04-08 21:07:21 -0700444void Disk::notifyEvent(int event) {
445 VolumeManager::Instance()->getBroadcaster()->sendBroadcast(event,
446 getId().c_str(), false);
447}
448
449void Disk::notifyEvent(int event, const std::string& value) {
450 VolumeManager::Instance()->getBroadcaster()->sendBroadcast(event,
451 StringPrintf("%s %s", getId().c_str(), value.c_str()).c_str(), false);
452}
453
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800454int Disk::getMaxMinors() {
455 // Figure out maximum partition devices supported
456 switch (major(mDevice)) {
457 case kMajorBlockScsi: {
458 // Per Documentation/devices.txt this is static
459 return 15;
460 }
461 case kMajorBlockMmc: {
462 // Per Documentation/devices.txt this is dynamic
463 std::string tmp;
464 if (!ReadFileToString(kSysfsMmcMaxMinors, &tmp)) {
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700465 LOG(ERROR) << "Failed to read max minors";
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800466 return -errno;
467 }
468 return atoi(tmp.c_str());
469 }
470 }
471
Jeff Sharkey36801cc2015-03-13 16:09:20 -0700472 LOG(ERROR) << "Unsupported block major type " << major(mDevice);
Jeff Sharkeydeb24052015-03-02 21:01:40 -0800473 return -ENOTSUP;
474}
475
476} // namespace vold
477} // namespace android