From Shawn Heo's patch:
Ext4 introduced reserved clusters to prevent costly zeroout, or
unexpected ENOSPC. The size is 2% or 4096 clusters, whichever
is smaller (http://lwn.net/Articles/546473/).
So, we need to allocate additionally this amount of free space
to asecs when vold create asec images. This is required when
Android runs on Linux kernel 3.10 or later.
see: https://android-review.git.corp.google.com/#/c/96160
Change-Id: Iacff16b8cf0314493c355fa741bcfa519f744d6c
Signed-off-by: Daniel Rosenberg <drosen@google.com>
}
static int adjustSectorNumExt4(unsigned numSectors) {
+ // Ext4 started to reserve 2% or 4096 clusters, whichever is smaller for
+ // preventing costly operations or unexpected ENOSPC error.
+ // Ext4::format() uses default block size without clustering.
+ unsigned clusterSectors = 4096 / 512;
+ unsigned reservedSectors = (numSectors * 2)/100 + (numSectors % 50 > 0);
+ numSectors += reservedSectors > (4096 * clusterSectors) ? (4096 * clusterSectors) : reservedSectors;
return ROUND_UP_POWER_OF_2(numSectors, 3);
}