blob: eae70d1130388b3c3ddcc797bd2cb0dc9b780c91 [file] [log] [blame]
San Mehatf1b736b2009-10-10 17:22:08 -07001/*
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
San Mehat49e2bce2009-10-12 16:29:01 -070017#include <stdlib.h>
San Mehatf1b736b2009-10-10 17:22:08 -070018#include <string.h>
San Mehat49e2bce2009-10-12 16:29:01 -070019#include <dirent.h>
20#include <errno.h>
21#include <fcntl.h>
22
23#include <sys/types.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26#include <sys/mman.h>
San Mehata2677e42009-12-13 10:40:18 -080027#include <sys/mount.h>
28
29#include <linux/kdev_t.h>
30
31#include <cutils/properties.h>
32
San Mehat2a5b8ce2010-03-10 12:48:57 -080033#include <diskconfig/diskconfig.h>
San Mehatf1b736b2009-10-10 17:22:08 -070034
35#define LOG_TAG "Vold"
36
37#include <cutils/log.h>
38
39#include "Volume.h"
San Mehata2677e42009-12-13 10:40:18 -080040#include "VolumeManager.h"
41#include "ResponseCode.h"
San Mehatbf041852010-01-04 10:09:16 -080042#include "Fat.h"
San Mehat586536c2010-02-16 17:12:00 -080043#include "Process.h"
San Mehatf1b736b2009-10-10 17:22:08 -070044
San Mehata2677e42009-12-13 10:40:18 -080045extern "C" void dos_partition_dec(void const *pp, struct dos_partition *d);
46extern "C" void dos_partition_enc(void *pp, struct dos_partition *d);
San Mehat49e2bce2009-10-12 16:29:01 -070047
San Mehat3bb60202010-02-19 18:14:36 -080048
49/*
50 * Secure directory - stuff that only root can see
51 */
52const char *Volume::SECDIR = "/mnt/secure";
53
54/*
55 * Secure staging directory - where media is mounted for preparation
56 */
57const char *Volume::SEC_STGDIR = "/mnt/secure/staging";
58
59/*
60 * Path to the directory on the media which contains publicly accessable
61 * asec imagefiles. This path will be obscured before the mount is
62 * exposed to non priviledged users.
63 */
San Mehat52c2ccb2010-02-23 18:26:13 -080064const char *Volume::SEC_STG_SECIMGDIR = "/mnt/secure/staging/.android_secure";
San Mehat3bb60202010-02-19 18:14:36 -080065
66/*
67 * Path to where *only* root can access asec imagefiles
68 */
69const char *Volume::SEC_ASECDIR = "/mnt/secure/asec";
70
71/*
72 * Path to where secure containers are mounted
73 */
74const char *Volume::ASECDIR = "/mnt/asec";
75
San Mehata2677e42009-12-13 10:40:18 -080076static const char *stateToStr(int state) {
77 if (state == Volume::State_Init)
78 return "Initializing";
79 else if (state == Volume::State_NoMedia)
80 return "No-Media";
81 else if (state == Volume::State_Idle)
82 return "Idle-Unmounted";
83 else if (state == Volume::State_Pending)
84 return "Pending";
85 else if (state == Volume::State_Mounted)
86 return "Mounted";
87 else if (state == Volume::State_Unmounting)
88 return "Unmounting";
89 else if (state == Volume::State_Checking)
90 return "Checking";
91 else if (state == Volume::State_Formatting)
92 return "Formatting";
93 else if (state == Volume::State_Shared)
94 return "Shared-Unmounted";
95 else if (state == Volume::State_SharedMnt)
96 return "Shared-Mounted";
97 else
98 return "Unknown-Error";
99}
100
101Volume::Volume(VolumeManager *vm, const char *label, const char *mount_point) {
102 mVm = vm;
San Mehatd9a4e352010-03-12 13:32:47 -0800103 mDebug = false;
San Mehatf1b736b2009-10-10 17:22:08 -0700104 mLabel = strdup(label);
105 mMountpoint = strdup(mount_point);
106 mState = Volume::State_Init;
San Mehata2677e42009-12-13 10:40:18 -0800107 mCurrentlyMountedKdev = -1;
San Mehatf1b736b2009-10-10 17:22:08 -0700108}
109
110Volume::~Volume() {
111 free(mLabel);
112 free(mMountpoint);
113}
114
San Mehatcb4dac82010-03-14 13:41:54 -0700115void Volume::protectFromAutorunStupidity() {
116 char filename[255];
117
118 snprintf(filename, sizeof(filename), "%s/autorun.inf", SEC_STGDIR);
119 if (!access(filename, F_OK)) {
120 LOGW("Volume contains an autorun.inf! - removing");
121 /*
122 * Ensure the filename is all lower-case so
123 * the process killer can find the inode.
124 * Probably being paranoid here but meh.
125 */
126 rename(filename, filename);
127 Process::killProcessesWithOpenFiles(filename, 2);
128 if (unlink(filename)) {
129 LOGE("Failed to remove %s (%s)", filename, strerror(errno));
130 }
131 }
132}
133
San Mehatd9a4e352010-03-12 13:32:47 -0800134void Volume::setDebug(bool enable) {
135 mDebug = enable;
136}
137
San Mehata2677e42009-12-13 10:40:18 -0800138dev_t Volume::getDiskDevice() {
139 return MKDEV(0, 0);
140};
141
142void Volume::handleVolumeShared() {
143}
144
145void Volume::handleVolumeUnshared() {
146}
147
San Mehatfd7f5872009-10-12 11:32:47 -0700148int Volume::handleBlockEvent(NetlinkEvent *evt) {
San Mehatf1b736b2009-10-10 17:22:08 -0700149 errno = ENOSYS;
150 return -1;
151}
152
153void Volume::setState(int state) {
San Mehata2677e42009-12-13 10:40:18 -0800154 char msg[255];
155 int oldState = mState;
156
157 if (oldState == state) {
158 LOGW("Duplicate state (%d)\n", state);
159 return;
160 }
161
San Mehatf1b736b2009-10-10 17:22:08 -0700162 mState = state;
San Mehata2677e42009-12-13 10:40:18 -0800163
164 LOGD("Volume %s state changing %d (%s) -> %d (%s)", mLabel,
165 oldState, stateToStr(oldState), mState, stateToStr(mState));
166 snprintf(msg, sizeof(msg),
167 "Volume %s %s state changed from %d (%s) to %d (%s)", getLabel(),
168 getMountpoint(), oldState, stateToStr(oldState), mState,
169 stateToStr(mState));
170
171 mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeStateChange,
172 msg, false);
San Mehatf1b736b2009-10-10 17:22:08 -0700173}
San Mehat49e2bce2009-10-12 16:29:01 -0700174
San Mehatdd9b8e92009-10-21 11:06:52 -0700175int Volume::createDeviceNode(const char *path, int major, int minor) {
176 mode_t mode = 0660 | S_IFBLK;
177 dev_t dev = (major << 8) | minor;
178 if (mknod(path, mode, dev) < 0) {
179 if (errno != EEXIST) {
180 return -1;
181 }
182 }
183 return 0;
184}
185
San Mehata2677e42009-12-13 10:40:18 -0800186int Volume::formatVol() {
San Mehat49e2bce2009-10-12 16:29:01 -0700187
San Mehata2677e42009-12-13 10:40:18 -0800188 if (getState() == Volume::State_NoMedia) {
189 errno = ENODEV;
190 return -1;
191 } else if (getState() != Volume::State_Idle) {
192 errno = EBUSY;
San Mehat49e2bce2009-10-12 16:29:01 -0700193 return -1;
194 }
195
San Mehata2677e42009-12-13 10:40:18 -0800196 if (isMountpointMounted(getMountpoint())) {
197 LOGW("Volume is idle but appears to be mounted - fixing");
198 setState(Volume::State_Mounted);
199 // mCurrentlyMountedKdev = XXX
200 errno = EBUSY;
San Mehat49e2bce2009-10-12 16:29:01 -0700201 return -1;
202 }
203
San Mehata2677e42009-12-13 10:40:18 -0800204 char devicePath[255];
205 dev_t diskNode = getDiskDevice();
206 dev_t partNode = MKDEV(MAJOR(diskNode), 1); // XXX: Hmmm
207
208 sprintf(devicePath, "/dev/block/vold/%d:%d",
209 MAJOR(diskNode), MINOR(diskNode));
210
San Mehatd9a4e352010-03-12 13:32:47 -0800211 if (mDebug) {
212 LOGI("Formatting volume %s (%s)", getLabel(), devicePath);
213 }
San Mehat2a5b8ce2010-03-10 12:48:57 -0800214 setState(Volume::State_Formatting);
San Mehata2677e42009-12-13 10:40:18 -0800215
216 if (initializeMbr(devicePath)) {
217 LOGE("Failed to initialize MBR (%s)", strerror(errno));
218 goto err;
San Mehat49e2bce2009-10-12 16:29:01 -0700219 }
220
San Mehata2677e42009-12-13 10:40:18 -0800221 sprintf(devicePath, "/dev/block/vold/%d:%d",
222 MAJOR(partNode), MINOR(partNode));
San Mehatdd9b8e92009-10-21 11:06:52 -0700223
San Mehatfcf24fe2010-03-03 12:37:32 -0800224 if (Fat::format(devicePath, 0)) {
San Mehata2677e42009-12-13 10:40:18 -0800225 LOGE("Failed to format (%s)", strerror(errno));
226 goto err;
227 }
228
San Mehat2a5b8ce2010-03-10 12:48:57 -0800229 setState(Volume::State_Idle);
San Mehat49e2bce2009-10-12 16:29:01 -0700230 return 0;
San Mehata2677e42009-12-13 10:40:18 -0800231err:
232 return -1;
233}
234
235bool Volume::isMountpointMounted(const char *path) {
236 char device[256];
237 char mount_path[256];
238 char rest[256];
239 FILE *fp;
240 char line[1024];
241
242 if (!(fp = fopen("/proc/mounts", "r"))) {
243 LOGE("Error opening /proc/mounts (%s)", strerror(errno));
244 return false;
245 }
246
247 while(fgets(line, sizeof(line), fp)) {
248 line[strlen(line)-1] = '\0';
249 sscanf(line, "%255s %255s %255s\n", device, mount_path, rest);
250 if (!strcmp(mount_path, path)) {
251 fclose(fp);
252 return true;
253 }
254
255 }
256
257 fclose(fp);
258 return false;
259}
260
261int Volume::mountVol() {
262 dev_t deviceNodes[4];
263 int n, i, rc = 0;
264 char errmsg[255];
265
266 if (getState() == Volume::State_NoMedia) {
267 snprintf(errmsg, sizeof(errmsg),
268 "Volume %s %s mount failed - no media",
269 getLabel(), getMountpoint());
270 mVm->getBroadcaster()->sendBroadcast(
271 ResponseCode::VolumeMountFailedNoMedia,
272 errmsg, false);
273 errno = ENODEV;
274 return -1;
275 } else if (getState() != Volume::State_Idle) {
276 errno = EBUSY;
277 return -1;
278 }
279
280 if (isMountpointMounted(getMountpoint())) {
281 LOGW("Volume is idle but appears to be mounted - fixing");
282 setState(Volume::State_Mounted);
283 // mCurrentlyMountedKdev = XXX
284 return 0;
285 }
286
287 n = getDeviceNodes((dev_t *) &deviceNodes, 4);
288 if (!n) {
289 LOGE("Failed to get device nodes (%s)\n", strerror(errno));
290 return -1;
291 }
292
293 for (i = 0; i < n; i++) {
294 char devicePath[255];
295
296 sprintf(devicePath, "/dev/block/vold/%d:%d", MAJOR(deviceNodes[i]),
297 MINOR(deviceNodes[i]));
298
299 LOGI("%s being considered for volume %s\n", devicePath, getLabel());
300
301 errno = 0;
San Mehatbf041852010-01-04 10:09:16 -0800302 setState(Volume::State_Checking);
303
San Mehat3bb60202010-02-19 18:14:36 -0800304 if (Fat::check(devicePath)) {
San Mehata2677e42009-12-13 10:40:18 -0800305 if (errno == ENODATA) {
306 LOGW("%s does not contain a FAT filesystem\n", devicePath);
307 continue;
San Mehata2677e42009-12-13 10:40:18 -0800308 }
San Mehateba65e92010-01-29 05:15:16 -0800309 errno = EIO;
310 /* Badness - abort the mount */
311 LOGE("%s failed FS checks (%s)", devicePath, strerror(errno));
312 setState(Volume::State_Idle);
313 return -1;
San Mehata2677e42009-12-13 10:40:18 -0800314 }
315
San Mehat3bb60202010-02-19 18:14:36 -0800316 /*
317 * Mount the device on our internal staging mountpoint so we can
318 * muck with it before exposing it to non priviledged users.
319 */
San Mehata2677e42009-12-13 10:40:18 -0800320 errno = 0;
San Mehat3bb60202010-02-19 18:14:36 -0800321 if (Fat::doMount(devicePath, "/mnt/secure/staging", false, false, 1000, 1015, 0702, true)) {
322 LOGE("%s failed to mount via VFAT (%s)\n", devicePath, strerror(errno));
323 continue;
San Mehata2677e42009-12-13 10:40:18 -0800324 }
325
San Mehat3bb60202010-02-19 18:14:36 -0800326 LOGI("Device %s, target %s mounted @ /mnt/secure/staging", devicePath, getMountpoint());
327
San Mehatcb4dac82010-03-14 13:41:54 -0700328 protectFromAutorunStupidity();
329
San Mehat3bb60202010-02-19 18:14:36 -0800330 if (createBindMounts()) {
331 LOGE("Failed to create bindmounts (%s)", strerror(errno));
332 umount("/mnt/secure/staging");
333 setState(Volume::State_Idle);
334 return -1;
335 }
336
337 /*
338 * Now that the bindmount trickery is done, atomically move the
339 * whole subtree to expose it to non priviledged users.
340 */
341 if (doMoveMount("/mnt/secure/staging", getMountpoint(), false)) {
342 LOGE("Failed to move mount (%s)", strerror(errno));
343 umount("/mnt/secure/staging");
344 setState(Volume::State_Idle);
345 return -1;
346 }
347 setState(Volume::State_Mounted);
348 mCurrentlyMountedKdev = deviceNodes[i];
349 return 0;
San Mehata2677e42009-12-13 10:40:18 -0800350 }
351
San Mehata2677e42009-12-13 10:40:18 -0800352 LOGE("Volume %s found no suitable devices for mounting :(\n", getLabel());
353 setState(Volume::State_Idle);
354
San Mehateba65e92010-01-29 05:15:16 -0800355 return -1;
San Mehata2677e42009-12-13 10:40:18 -0800356}
357
San Mehat3bb60202010-02-19 18:14:36 -0800358int Volume::createBindMounts() {
359 unsigned long flags;
360
361 /*
San Mehat52c2ccb2010-02-23 18:26:13 -0800362 * Rename old /android_secure -> /.android_secure
363 */
364 if (!access("/mnt/secure/staging/android_secure", R_OK | X_OK) &&
365 access(SEC_STG_SECIMGDIR, R_OK | X_OK)) {
366 if (rename("/mnt/secure/staging/android_secure", SEC_STG_SECIMGDIR)) {
367 LOGE("Failed to rename legacy asec dir (%s)", strerror(errno));
368 }
369 }
370
371 /*
San Mehat3bb60202010-02-19 18:14:36 -0800372 * Ensure that /android_secure exists and is a directory
373 */
374 if (access(SEC_STG_SECIMGDIR, R_OK | X_OK)) {
375 if (errno == ENOENT) {
376 if (mkdir(SEC_STG_SECIMGDIR, 0777)) {
377 LOGE("Failed to create %s (%s)", SEC_STG_SECIMGDIR, strerror(errno));
378 return -1;
379 }
380 } else {
381 LOGE("Failed to access %s (%s)", SEC_STG_SECIMGDIR, strerror(errno));
382 return -1;
383 }
384 } else {
385 struct stat sbuf;
386
387 if (stat(SEC_STG_SECIMGDIR, &sbuf)) {
388 LOGE("Failed to stat %s (%s)", SEC_STG_SECIMGDIR, strerror(errno));
389 return -1;
390 }
391 if (!S_ISDIR(sbuf.st_mode)) {
392 LOGE("%s is not a directory", SEC_STG_SECIMGDIR);
393 errno = ENOTDIR;
394 return -1;
395 }
396 }
397
398 /*
399 * Bind mount /mnt/secure/staging/android_secure -> /mnt/secure/asec so we'll
400 * have a root only accessable mountpoint for it.
401 */
402 if (mount(SEC_STG_SECIMGDIR, SEC_ASECDIR, "", MS_BIND, NULL)) {
403 LOGE("Failed to bind mount points %s -> %s (%s)",
404 SEC_STG_SECIMGDIR, SEC_ASECDIR, strerror(errno));
405 return -1;
406 }
407
408 /*
409 * Mount a read-only, zero-sized tmpfs on <mountpoint>/android_secure to
410 * obscure the underlying directory from everybody - sneaky eh? ;)
411 */
412 if (mount("tmpfs", SEC_STG_SECIMGDIR, "tmpfs", MS_RDONLY, "size=0,mode=000,uid=0,gid=0")) {
413 LOGE("Failed to obscure %s (%s)", SEC_STG_SECIMGDIR, strerror(errno));
414 umount("/mnt/asec_secure");
415 return -1;
416 }
417
418 return 0;
419}
420
421int Volume::doMoveMount(const char *src, const char *dst, bool force) {
422 unsigned int flags = MS_MOVE;
423 int retries = 5;
424
425 while(retries--) {
426 if (!mount(src, dst, "", flags, NULL)) {
San Mehatd9a4e352010-03-12 13:32:47 -0800427 if (mDebug) {
428 LOGD("Moved mount %s -> %s sucessfully", src, dst);
429 }
San Mehat3bb60202010-02-19 18:14:36 -0800430 return 0;
431 } else if (errno != EBUSY) {
432 LOGE("Failed to move mount %s -> %s (%s)", src, dst, strerror(errno));
433 return -1;
434 }
435 int action = 0;
436
437 if (force) {
438 if (retries == 1) {
439 action = 2; // SIGKILL
440 } else if (retries == 2) {
441 action = 1; // SIGHUP
442 }
443 }
444 LOGW("Failed to move %s -> %s (%s, retries %d, action %d)",
445 src, dst, strerror(errno), retries, action);
446 Process::killProcessesWithOpenFiles(src, action);
447 usleep(1000*250);
448 }
449
450 errno = EBUSY;
451 LOGE("Giving up on move %s -> %s (%s)", src, dst, strerror(errno));
452 return -1;
453}
454
455int Volume::doUnmount(const char *path, bool force) {
456 int retries = 10;
457
San Mehatd9a4e352010-03-12 13:32:47 -0800458 if (mDebug) {
459 LOGD("Unmounting {%s}, force = %d", path, force);
460 }
461
San Mehat3bb60202010-02-19 18:14:36 -0800462 while (retries--) {
463 if (!umount(path) || errno == EINVAL || errno == ENOENT) {
464 LOGI("%s sucessfully unmounted", path);
465 return 0;
466 }
467
468 int action = 0;
469
470 if (force) {
471 if (retries == 1) {
472 action = 2; // SIGKILL
473 } else if (retries == 2) {
474 action = 1; // SIGHUP
475 }
476 }
477
478 LOGW("Failed to unmount %s (%s, retries %d, action %d)",
479 path, strerror(errno), retries, action);
480
481 Process::killProcessesWithOpenFiles(path, action);
482 usleep(1000*1000);
483 }
484 errno = EBUSY;
485 LOGE("Giving up on unmount %s (%s)", path, strerror(errno));
486 return -1;
487}
488
San Mehat4ba89482010-02-18 09:00:18 -0800489int Volume::unmountVol(bool force) {
San Mehata2677e42009-12-13 10:40:18 -0800490 int i, rc;
491
492 if (getState() != Volume::State_Mounted) {
493 LOGE("Volume %s unmount request when not mounted", getLabel());
494 errno = EINVAL;
495 return -1;
496 }
497
498 setState(Volume::State_Unmounting);
San Mehat4ba89482010-02-18 09:00:18 -0800499 usleep(1000 * 1000); // Give the framework some time to react
San Mehata2677e42009-12-13 10:40:18 -0800500
San Mehat3bb60202010-02-19 18:14:36 -0800501 /*
502 * First move the mountpoint back to our internal staging point
503 * so nobody else can muck with it while we work.
504 */
505 if (doMoveMount(getMountpoint(), SEC_STGDIR, force)) {
506 LOGE("Failed to move mount %s => %s (%s)", getMountpoint(), SEC_STGDIR, strerror(errno));
507 setState(Volume::State_Mounted);
508 return -1;
San Mehata2677e42009-12-13 10:40:18 -0800509 }
510
San Mehatcb4dac82010-03-14 13:41:54 -0700511 protectFromAutorunStupidity();
512
San Mehat3bb60202010-02-19 18:14:36 -0800513 /*
514 * Unmount the tmpfs which was obscuring the asec image directory
515 * from non root users
516 */
517
518 if (doUnmount(Volume::SEC_STG_SECIMGDIR, force)) {
519 LOGE("Failed to unmount tmpfs on %s (%s)", SEC_STG_SECIMGDIR, strerror(errno));
520 goto fail_republish;
San Mehata2677e42009-12-13 10:40:18 -0800521 }
522
San Mehat3bb60202010-02-19 18:14:36 -0800523 /*
524 * Remove the bindmount we were using to keep a reference to
525 * the previously obscured directory.
526 */
527
528 if (doUnmount(Volume::SEC_ASECDIR, force)) {
529 LOGE("Failed to remove bindmount on %s (%s)", SEC_ASECDIR, strerror(errno));
530 goto fail_remount_tmpfs;
531 }
532
533 /*
534 * Finally, unmount the actual block device from the staging dir
535 */
536 if (doUnmount(Volume::SEC_STGDIR, force)) {
537 LOGE("Failed to unmount %s (%s)", SEC_STGDIR, strerror(errno));
538 goto fail_recreate_bindmount;
539 }
540
541 LOGI("%s unmounted sucessfully", getMountpoint());
542
543 setState(Volume::State_Idle);
544 mCurrentlyMountedKdev = -1;
545 return 0;
546
547 /*
548 * Failure handling - try to restore everything back the way it was
549 */
550fail_recreate_bindmount:
551 if (mount(SEC_STG_SECIMGDIR, SEC_ASECDIR, "", MS_BIND, NULL)) {
552 LOGE("Failed to restore bindmount after failure! - Storage will appear offline!");
553 goto out_nomedia;
554 }
555fail_remount_tmpfs:
556 if (mount("tmpfs", SEC_STG_SECIMGDIR, "tmpfs", MS_RDONLY, "size=0,mode=0,uid=0,gid=0")) {
557 LOGE("Failed to restore tmpfs after failure! - Storage will appear offline!");
558 goto out_nomedia;
559 }
560fail_republish:
561 if (doMoveMount(SEC_STGDIR, getMountpoint(), force)) {
562 LOGE("Failed to republish mount after failure! - Storage will appear offline!");
563 goto out_nomedia;
564 }
565
San Mehata2677e42009-12-13 10:40:18 -0800566 setState(Volume::State_Mounted);
567 return -1;
San Mehat3bb60202010-02-19 18:14:36 -0800568
569out_nomedia:
570 setState(Volume::State_NoMedia);
571 return -1;
San Mehata2677e42009-12-13 10:40:18 -0800572}
573
574int Volume::initializeMbr(const char *deviceNode) {
San Mehat2a5b8ce2010-03-10 12:48:57 -0800575 struct disk_info dinfo;
San Mehata2677e42009-12-13 10:40:18 -0800576
San Mehat2a5b8ce2010-03-10 12:48:57 -0800577 memset(&dinfo, 0, sizeof(dinfo));
578
579 if (!(dinfo.part_lst = (struct part_info *) malloc(MAX_NUM_PARTS * sizeof(struct part_info)))) {
580 LOGE("Failed to malloc prt_lst");
San Mehata2677e42009-12-13 10:40:18 -0800581 return -1;
582 }
583
San Mehat2a5b8ce2010-03-10 12:48:57 -0800584 memset(dinfo.part_lst, 0, MAX_NUM_PARTS * sizeof(struct part_info));
585 dinfo.device = strdup(deviceNode);
586 dinfo.scheme = PART_SCHEME_MBR;
587 dinfo.sect_size = 512;
588 dinfo.skip_lba = 2048;
589 dinfo.num_lba = 0;
590 dinfo.num_parts = 1;
591
592 struct part_info *pinfo = &dinfo.part_lst[0];
593
594 pinfo->name = strdup("android_sdcard");
595 pinfo->flags |= PART_ACTIVE_FLAG;
596 pinfo->type = PC_PART_TYPE_FAT32;
597 pinfo->len_kb = -1;
598
599 int rc = apply_disk_config(&dinfo, 0);
600
601 if (rc) {
602 LOGE("Failed to apply disk configuration (%d)", rc);
603 goto out;
San Mehata2677e42009-12-13 10:40:18 -0800604 }
605
San Mehat2a5b8ce2010-03-10 12:48:57 -0800606 out:
607 free(pinfo->name);
608 free(dinfo.device);
609 free(dinfo.part_lst);
San Mehata2677e42009-12-13 10:40:18 -0800610
San Mehat2a5b8ce2010-03-10 12:48:57 -0800611 return rc;
San Mehata2677e42009-12-13 10:40:18 -0800612}