ext4_utils: fix utility build (libmincrypt)

external/libselinux/src/android.c:702: error: undefined reference to 'SHA_hash'
collect2: error: ld returned 1 exit status
make: *** [/opt/jenkins/android/workspace/android/cm-11.0/out/target/product/galaxysmtd/obj/UTILITY_EXECUTABLES/utility_make_ext4fs_intermediates/LINKED/make_ext4fs] Error 1

Change-Id: Ie43cefffae1aae74072abc30eba5d8010619b9d8
make_ext4fs: fix block allocation to be best-fit

The block allocation algorithm was failing to allocate parts of large
files out of partially filled block groups.  Update the allocation
algorithm to be a simpler best fit loop - if the remaining length to
allocate is larger than any single contiguous region, allocate the
largest single contiguous region and continue allocating, otherwise
allocate the smallest contiguous that can hold the length.

Change-Id: Idcc60df91ed0a266d3128ea46e86408a581d3f40
Set s_flags to 2 to prevent a write on first mount.

The s_flags field is used to indicate whether characters are signed
or unsigned, which differs between ARM and x86 targets. Setting
this value to 0 causes the correct value for the target to be
written back to the superblock on first mount, even if the fs is
marked read only.

Since this value is only used to ensure interoperability with 2.4
series kernels (which we don't need) in dirhash (which we don't
use), we'll just set it to 2 to prevent the write.

Change-Id: I92698235909791fb5f423cfd61ff5299307a8f97
ext4_utils: don't leave bad image file in case of error

Bug: 13029951
Change-Id: Ibe50a503c2d3988813b362790b7fba83383fb51e