vold: correct counting of partitions when NPARTS is not available.

This only effects devices using older kernels (before 2.6.32) which don't implement NPARTS/PARTN uevents.

If an sdcard has multiple paritions and NPARTS/PARTN are not implemented in the kernel vold will only attempt to
mount the last partition on the card, rather than attempt to mount each until it finds a FAT partition.
This is a problem as when there are multiple partitions present the last is usually not FAT.
With this patch vold correctly attempts to mount each partition.

Change-Id: If6fc4f5bbca1839f7a8d97b22bcb555e0e26797d
Also handle usb_connected (like usb_configuration) states
coming up from the USB driver in the kernel (e.g. Samsung SGS2),
that also notify the framework that UMS is available.

Change-Id: Ib91997e6bb994e9336ac3671059cd3a93d526b4f
Vold: support stacking of storage mounts.

Any stacked mounts must appear in vold.fstab with deepest mount
points listed last. When mounting a volume, vold will scan for mounts
that prefix the desired mount point, and attempt to mount them first.
When unmounting a volume, it will scan for other volumes to which the
current mount point is a prefix, and unmount them first. System is
also permitted to browse (but not read/write) storage mount points,
as otherwise Settings->Storage can not report free/used space due to
access failure.

Change-Id: Id3fd8f9bab5d31084da0c82a478cf9c3bcd6eda3
Use a list of possible lun paths instead of a hardcoded one.

This will easily play nice with kernels that use gadget drivers and
function drivers (ex: tethering support doesn't require a new vold).

Change-Id: I71796114501cf2d64dea5fd077ac5baf54873af4
Vold: sort volume list by mountpoint length on load.

In VolumeManager::addVolume, scan the existing list of volumes and
insert before the first one with greater or equal mountpoint path
length. This will ensure that deeper mounts are always after more
shallow ones in sets of stacked mounts, an assumption that vold
already makes in stacked mount handling, and which was previously
enforced by the author of the vold.fstab file.

Change-Id: I3f4a8045801863101e7b4f6b98b03acd9bd68a23
vold: Allow pre-configured device pairs to switch mountpoints

The use-case for this are devices with internal extended storage
(pseudo-SDCard emmc) and an actual microSD card reader.
In CM, we choose to use the microSD as primary storage, and leave
the internal partition mostly unused; some users usually come up with
imaginative and data-destroying ways of working around that.

This allows us to specify a pair of mountpoints which can be
switched from a user preference. For this vold.fstab:

-----
dev_mount sdcard /mnt/sdcard ...<path-to-microSD-sysfs>
dev_mount emmc /mnt/emmc ...<path-to-emmc-partition>
-----

We can add to build.prop:
"ro.vold.switchablepair=/mnt/sdcard,/mnt/emmc"

A persistent toggle (persist.sys.vold.switchexternal), controllable
through CMParts, can be presented to the user to allow choosing
something other than our default as primary storage.

Change-Id: I58aa56f49dbf45bf0510b05dcf88567a2c229fa2
vold: add class AutoVolume to support auto-mount and fake sdcard
vold: extend the syntax of vold.fstab

Now vold.fstab can accept the following:

dev_mount sdcard /mnt/sdcard auto <devpath>       // use normal DirectVolume
dev_mount sdcard /mnt/sdcard auto SDCARD=dev_node // use AutoVolume for specified device node
dev_mount sdcard /mnt/sdcard auto                 // use AutoVolume to mount USB/MMC/SD automatically

Change-Id: I5c74fcce9cee552d0e3d51898865bb4e11c461dc
vold: Add (read-only) automounting support for NTFS.

With USB host mode it can be useful to also automount NTFS volumes so I
cherry picked and adjusted the ntfs additions from this source:
http://forum.xda-developers.com/showthread.php?t=897075

Basicly it tries NTFS if FAT (or EXT4) detection fails.

It does, of course, only work if NTFS is supported by the kernel.

Tested mounting both FAT32 (usb disk and hard drive) and NTFS (usb stick)
and it works fine for me.

Should also work with NTFS formatted sd-cards but with it being read-only I do
not see any practical use for that scenario.

Change-Id: I4caefeeb6bfb0820805b1742d88064a6d916c221
vold: add ro.vold.umsdirtyratio property

This allows control of what /proc/sys/vm/dirty_ratio is used when USB mounting.
Some platforms like the HTC Desire (bravo) get a _HUGE_ performance boost when
writing to the sdcard when USB mounting if this is set to 20 (which is the default)
on the HTC Desire.

This addresses this issue: http://code.google.com/p/cyanogenmod/issues/detail?id=2949

Basicly it makes it possible to undo or control the effect of this commit:
https://github.com/CyanogenMod/android_system_vold/commit/a28056b38275003895ff5d9576681aca01544822

Change-Id: I86b7bbd02695fb0c19f39448714a219257bf806f
Add custom second lun number support

like u8800 have different second lun number
use TARGET_USE_CUSTOM_SECOND_LUN_NUM options to custom lun number

Change-Id: I36f8c92f1f8041efeaa0304795a11eb1cc49e5e1
fix buffer overflow while reading /proc/cmdline

char line[255] was used to store each line in vold.fstab. but, by AutoVolume changes, it is also (ab)used to store each arg in /proc/cmdline.
length of /proc/cmdline is architecture dependent. it should be 1024 on arm. so each arg can be longer than 255.

this change fixes vold crash (stack corruption detected: aborted) with longer arg.

this issue is found by ^BatVanko^ on forum.xda-developers.com. thank you!

Change-Id: I7a4a9dd00a9a0b291429df9a85fbe097fd22c1ba
Use new usb mass storage switch compatible with newer kernels

Change-Id: Ic59f4b454e01bc4b72fd3632adba158bfac6e130