@ -246,28 +246,53 @@ status_t PublicVolume::doUnmount() {
}
}
status_t PublicVolume : : doFormat ( const std : : string & fsType ) {
status_t PublicVolume : : doFormat ( const std : : string & fsType ) {
if ( ( fsType = = " vfat " | | fsType = = " auto " ) & & vfat : : IsSupported ( ) ) {
bool useVfat = vfat : : IsSupported ( ) ;
if ( WipeBlockDevice ( mDevPath ) ! = OK ) {
bool useExfat = exfat : : IsSupported ( ) ;
LOG ( WARNING ) < < getId ( ) < < " failed to wipe " ;
status_t res = OK ;
// Resolve the target filesystem type
if ( fsType = = " auto " & & useVfat & & useExfat ) {
uint64_t size = 0 ;
res = GetBlockDevSize ( mDevPath , & size ) ;
if ( res ! = OK ) {
LOG ( ERROR ) < < " Couldn't get device size " < < mDevPath ;
return res ;
}
}
if ( vfat : : Format ( mDevPath , 0 ) ) {
LOG ( ERROR ) < < getId ( ) < < " failed to format " ;
// If both vfat & exfat are supported use exfat for SDXC (>~32GiB) cards
return - errno ;
if ( size > 32896LL * 1024 * 1024 ) {
useVfat = false ;
} else {
useExfat = false ;
}
} else if ( fsType = = " vfat " ) {
useExfat = false ;
} else if ( fsType = = " exfat " ) {
useVfat = false ;
}
}
} else if ( ( fsType = = " exfat " | | fsType = = " auto " ) & & exfat : : IsSupported ( ) ) {
if ( ! useVfat & & ! useExfat ) {
LOG ( ERROR ) < < " Unsupported filesystem " < < fsType ;
return - EINVAL ;
}
if ( WipeBlockDevice ( mDevPath ) ! = OK ) {
if ( WipeBlockDevice ( mDevPath ) ! = OK ) {
LOG ( WARNING ) < < getId ( ) < < " failed to wipe " ;
LOG ( WARNING ) < < getId ( ) < < " failed to wipe " ;
}
}
if ( exfat : : Format ( mDevPath ) ) {
LOG ( ERROR ) < < getId ( ) < < " failed to format " ;
if ( useVfat ) {
return - errno ;
res = vfat : : Format ( mDevPath , 0 ) ;
} else if ( useExfat ) {
res = exfat : : Format ( mDevPath ) ;
}
}
} else {
LOG ( ERROR ) < < " Unsupported filesystem " < < fsType ;
if ( res ! = OK ) {
return - EINVAL ;
LOG ( ERROR ) < < getId ( ) < < " failed to format " ;
res = - errno ;
}
}
return OK ;
return res ;
}
}
} // namespace vold
} // namespace vold