diff --git a/DirectVolume.h b/DirectVolume.h index bf50891..4bf14ff 100644 --- a/DirectVolume.h +++ b/DirectVolume.h @@ -30,7 +30,6 @@ public: static const int MAX_PARTITIONS = 4; protected: PathCollection *mPaths; - int mPartIdx; int mDiskMajor; int mDiskMinor; int mPartMinors[MAX_PARTITIONS]; diff --git a/Volume.cpp b/Volume.cpp index 1577ba9..d2b87b6 100644 --- a/Volume.cpp +++ b/Volume.cpp @@ -110,6 +110,7 @@ Volume::Volume(VolumeManager *vm, const char *label, const char *mount_point) { mMountpoint = strdup(mount_point); mState = Volume::State_Init; mCurrentlyMountedKdev = -1; + mPartIdx = -1; } Volume::~Volume() { @@ -210,28 +211,31 @@ int Volume::formatVol() { return -1; } + bool formatEntireDevice = (mPartIdx == -1); char devicePath[255]; dev_t diskNode = getDiskDevice(); - dev_t partNode = MKDEV(MAJOR(diskNode), 1); // XXX: Hmmm + dev_t partNode = MKDEV(MAJOR(diskNode), (formatEntireDevice ? 1 : mPartIdx)); - sprintf(devicePath, "/dev/block/vold/%d:%d", - MAJOR(diskNode), MINOR(diskNode)); - - if (mDebug) { - SLOGI("Formatting volume %s (%s)", getLabel(), devicePath); - } setState(Volume::State_Formatting); - if (initializeMbr(devicePath)) { - SLOGE("Failed to initialize MBR (%s)", strerror(errno)); -// goto err; -// don't treat this as a fatal error -// lets continue on and format the partition + // Only initialize the MBR if we are formatting the entire device + if (formatEntireDevice) { + sprintf(devicePath, "/dev/block/vold/%d:%d", + MAJOR(diskNode), MINOR(diskNode)); + + if (initializeMbr(devicePath)) { + SLOGE("Failed to initialize MBR (%s)", strerror(errno)); + goto err; + } } sprintf(devicePath, "/dev/block/vold/%d:%d", MAJOR(partNode), MINOR(partNode)); + if (mDebug) { + SLOGI("Formatting volume %s (%s)", getLabel(), devicePath); + } + if (Fat::format(devicePath, 0)) { SLOGE("Failed to format (%s)", strerror(errno)); goto err; @@ -582,7 +586,6 @@ out_nomedia: setState(Volume::State_NoMedia); return -1; } - int Volume::initializeMbr(const char *deviceNode) { struct disk_info dinfo; diff --git a/Volume.h b/Volume.h index f81afff..64cd7cb 100644 --- a/Volume.h +++ b/Volume.h @@ -51,6 +51,7 @@ protected: char *mMountpoint; VolumeManager *mVm; bool mDebug; + int mPartIdx; /* * The major/minor tuple of the currently mounted filesystem.