From e4c291a1ee7a0fe7660173e93777686900b2cc40 Mon Sep 17 00:00:00 2001 From: Daniel Rosenberg Date: Wed, 20 Apr 2016 14:07:32 -0700 Subject: [PATCH] Fix resizeAsec to determine correct size This fixes an eror where resizeAsec would attempt to read from the superblock struct before initializing it. Bug: 28292918 Change-Id: Ic6804e97e7c83bcedfb682a187b8d5e0e1bc51f9 --- VolumeManager.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/VolumeManager.cpp b/VolumeManager.cpp index 24acbd3..ec68164 100644 --- a/VolumeManager.cpp +++ b/VolumeManager.cpp @@ -1007,24 +1007,6 @@ int VolumeManager::resizeAsec(const char *id, unsigned long numSectors, const ch oldNumSec = info.st_size / 512; - unsigned long numImgSectors; - if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) - numImgSectors = adjustSectorNumExt4(numSectors); - else - numImgSectors = adjustSectorNumFAT(numSectors); - /* - * add one block for the superblock - */ - SLOGD("Resizing from %lu sectors to %lu sectors", oldNumSec, numImgSectors + 1); - if (oldNumSec == numImgSectors + 1) { - SLOGW("Size unchanged; ignoring resize request"); - return 0; - } else if (oldNumSec > numImgSectors + 1) { - SLOGE("Only growing is currently supported."); - close(fd); - return -1; - } - /* * Try to read superblock. */ @@ -1050,10 +1032,26 @@ int VolumeManager::resizeAsec(const char *id, unsigned long numSectors, const ch return -1; } + unsigned long numImgSectors; if (!(sb.c_opts & ASEC_SB_C_OPTS_EXT4)) { SLOGE("Only ext4 partitions are supported for resize"); errno = EINVAL; return -1; + } else { + numImgSectors = adjustSectorNumExt4(numSectors); + } + + /* + * add one block for the superblock + */ + SLOGD("Resizing from %lu sectors to %lu sectors", oldNumSec, numImgSectors + 1); + if (oldNumSec == numImgSectors + 1) { + SLOGW("Size unchanged; ignoring resize request"); + return 0; + } else if (oldNumSec > numImgSectors + 1) { + SLOGE("Only growing is currently supported."); + close(fd); + return -1; } if (Loop::resizeImageFile(asecFileName, numImgSectors + 1)) {