Skip to main content
typo
Source Link
clst
  • 211
  • 1
  • 3
  • 8
  1. The ExternalStorageFormatter calls then uses IMountService to call formatVolume(extStoragePath)
  1. The ExternalStorageFormatter calls then uses IMountService to formatVolume(extStoragePath)
  1. The ExternalStorageFormatter then uses IMountService to call formatVolume(extStoragePath)
Source Link
clst
  • 211
  • 1
  • 3
  • 8

TL;DR: Every Android uses FAT32. The Cluster size depends on the release. Existing partitions will be preserved. It will always use quick format.

Long Answer: After some more research here is the process as it was coded in the Android source code:

  1. The Setting App displays a few confirmations then uses the Intent: Intent(ExternalStorageFormatter.FORMAT_ONLY)

in 4.4 KitKat: https://android.googlesource.com/platform/packages/apps/Settings/+/kitkat-release/src/com/android/settings/MediaFormat.java
in 5 Lollipop: https://android.googlesource.com/platform/packages/apps/Settings/+/lollipop-release/src/com/android/settings/MediaFormat.java
in 6 they changed this. I will have to look more into it.

  1. The ExternalStorageFormatter calls then uses IMountService to formatVolume(extStoragePath)

in 4.4 KitKat: https://android.googlesource.com/platform/frameworks/base.git/+/kitkat-release/core/java/com/android/internal/os/storage/ExternalStorageFormatter.java
in 5 Lollipop: https://android.googlesource.com/platform/frameworks/base.git/+/lollipop-release/core/java/com/android/internal/os/storage/ExternalStorageFormatter.java

  1. This function calls
    mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25); mConnector.execute("volume", "format", path);

in 4.4 KitKat: https://android.googlesource.com/platform/frameworks/base/+/kitkat-release/services/java/com/android/server/MountService.java
in 5 Lollipop: https://android.googlesource.com/platform/frameworks/base/+/lollipop-release/services/core/java/com/android/server/MountService.java
more info about vold: https://source.android.com/devices/storage/config.html

  1. NativeDaemonConnector finally calls the native function to format the partition: Volume::formatVol() This call is without a Volume Label and does not wipe the partition.

see Volume.cpp, VolumeManager.cpp, CommandListener.cpp
in 4.4 KitKat: https://android.googlesource.com/platform/system/vold/+/kitkat-release in 5 Lollipop: https://android.googlesource.com/platform/system/vold/+/lollipop-release

  1. formatVol decides wether to format the partition (if one already exists) or the whole device (see int Volume::formatVol(bool wipe)). When the latter is the case a new MBR is written. Then Fat::format(devicePath, 0, wipe) is called. (Interesting sidenote: when mounting a volume Android is deleting autorun.inf if it exists: see Volume::protectFromAutorunStupidity())
  2. in Fat::format (in Marshmallow it is named Vfat) the actual formatting is done with: /system/bin/newfs_msdos. The parameters are different depending on the Android release, number of sectors is always omitted, wipe is always false:

Appendix: /system/bin/newfs_msdos syntax from https://android.googlesource.com/platform/system/core/+/lollipop-release/toolbox/newfs_msdos.c :

usage: newfs_msdos [ -options ] special [disktype]
where the options are:
    -@ create file system at specified offset
    -A Attempt to cluster align root directory
    -B get bootstrap from file
    -C create image file with specified size
    -F FAT type (12, 16, or 32)
    -I volume ID
    -L volume label
    -N don't create file system: just print out parameters
    -O OEM string
    -S bytes/sector
    -a sectors/FAT
    -b block size
    -c sectors/cluster
    -e root directory entries
    -f standard format
    -h drive heads
    -i file system info sector
    -k backup boot sector
    -m media descriptor
    -n number of FATs
    -o hidden sectors
    -r reserved sectors
    -s file system size (sectors)
    -u sectors/track