exFAT/NTFS support for the Cosmo Communicator

Cosmo with exfat formatted micro sd card
Cosmo Communicator with exfat formatted micro sd card

Unfortunately the Cosmo Communicator, like many other Android phones, does not support the exFAT filesystem. Most vendors do so due to exFAT being covered by software patents in the USA, which is a problem for companies selling to the USA. exFAT might not be the most sophisticated filesystem available, but is needed for interoperability with other devices and to get rid of the 4GB file size limit of fat32. This article shows how to enable exFAT support for the Cosmo. Since it is not much effort to also get NTFS support this is done by the way.

Setup the kernel sources

To get exfat support, first of all we need a kernel module providing exfat support. Fortunately some time ago Samsung has released their exfat driver under the GPL license. The derivate of this driver can be found on github¹ This module has to be built against the kernel used on the device. The kernel source for the Cosmo has also been made available on github². The two source trees can be combined, as described in the documentation for the exfat module by editing the relevant Makefile an Kconfig. Furthermore CONFIG_EXFAT_FS for exFAT support CONFIG_NTFS_FS for NTFS have to be enabled as modules in kernel configuration. The resulting kernel source tree with the included exfat submodule has been placed on github.

Setup the build environment

To build the kernel modules on better uses a compiler that is as near as possible to the one that has been originally for building the kernel. We can easily find this out via procfs on the target device.

clang version used for the Cosmos kernel build

When compiling on an arm64 system the build environment can easily be installed. I.e. by executing apt install llvm clang on an Ubuntu arm64 system. When using a different architecture for compiling, the appropriate cross toolchain has to be installed.

Build the kernel modules

Once all is set up the kernel modules can be built.

make O=../KERNEL_OUT -C cosmo-linux-kernel-4.4 ARCH=arm64 k71v1_64_bsp_defconfig

make -j4 O=../KERNEL_OUT ARCH=arm64  CC=clang  CLANG_TRIPLE=aarch64-linux-gnu- CROSS_COMPILE=aarch64-linux-gnu- modules

As result we get the two kernel modules ntfs.ko and exfat.ko

Creating a magisk module

The resulted kernel modules have to get loaded on Android startup. Starting with Android Pie it is not possible any more to mount the system partition for writing. One possibility would be to create an own system image containing the kernel modules and necessary scripts. Since Magisk is the recommended way for rooting the Cosmo Communicator anyways, we can take a different approach. Fortunately Magisk gives the possibility to create on overlay filesystem which gets injected into the android system partition, so we can get the same result with less effort.

To create the Magisk module containing the filesystem support we start with the Magisk Module Template4 and copy the two kernel modules to system/lib/modules/. Furthermore we need some additional binaries for filesystem checking and mounting. So we add the filesystem support binaries and volume daemon built for the Pixel 2 from fsbinaries.zip and Magisk-v18.1-extrafs.zip³. Next we need a service.sh script which loads the kernel modules on startup an restarts vold once the user is present. With an earlier restart the volumes do not get added.

#!/system/bin/sh

# load kernel modules
insmod /system/lib/modules/exfat.ko

# kernel ntfs support is ro
# comment this line to use fuse ntfs (rw)
insmod /system/lib/modules/ntfs.ko

_SLEEP_INTERVAL=2

# wait for startup
while [ "$(getprop sys.boot_completed)" != "1" ]; do
    sleep ${_SLEEP_INTERVAL}
done

# wait user to unlock
while dumpsys trust | grep -c "deviceLocked=1"; do
    sleep ${_SLEEP_INTERVAL}
    echo "device locked"
    echo $(dumpsys trust | grep -c "deviceLocked=1")
done

#kill vold to restart
killall vold
echo "vold restarted"

One can comment the line loading the ntfs module to decide whether ntfs kernel support, which is read only or fuse ntfs, which is read/write shall be used. For this a simple wrapper script replacing mount.ntfs has been added.

#!/system/bin/sh
# call mount for in kernel ntfs and mount.ntfs3g without
if cat /proc/filesystems | grep "ntfs" &> /dev/null ; then
  echo "using kernel ntfs (ro)"
  params=$(echo "$@" | sed 's/,shortname=mixed//')
  params=$(echo "$params" | sed 's/,dirsync//')
  mount $params
  echo no ntfs.ko
  mount.ntfs3g $@
else
  echo "using fuse ntfs (rw)"
  mount.ntfs3g $@
fi

Finally LATESTARTSERVICE=true has to be set config.sh to execute the service.sh script on startup and some Selinux policies have to be added to avoid the need of running in permissive mode.

The final result can be found on github. For those who do not want to perform the procedure or parts of it themselves, the installable Magisk module can be downloaded from here:

cosmo-fs.zip (676 downloads )

It can be installed using the Magisk Manager App. Best for all users would be if Planet Computes could include this in the stock ROM. This would give exFAT/NTFS support also for non-rooted devices. Assuming they are fearing software patents, they might consider joining the Open Invention Network to get access to the relevant Microsoft patents in the future.

Jürgen

References:
1. exfat kernel module
2. cosmo communicator kernel source
3. filesystem support binaries
4. Magisk Module Template
5. Magisk module developers guide

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

siteinfo

Translator