@ -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 ) ) ;
setState ( Volume : : State_Formatting ) ;
// 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 ( 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
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 ;