SD-Card and storage

Hello friends,

We got some bad reviews recently because many people experienced problems using their SD-Card in Magic DOSBox. People couldn’t pick their DOS applications from the storage card.  Let me explain why this can happen.

Magic DOSBox can run on Android  version 2.2 and above.  Android is a very quickly evolving system and not all updates are very user-friendly. The first Android devices did not support SD-Card. Later on,  some manufacturers made phones with SD-Card support. Unfortunately, support from Google was less than stellar and it was hard to decipher the  rules regarding how to  mount this storage.

More than likely your device  has an “emmc” card which is installed on the android system. This folder is reserved for your photos, movies and videos. Here you have normal access, but you normally don’t  have access outside this folder unless you have a rooted device. This is the reason why you can use only 11GB of storage although your tablet has 16GB in its specification (for example).

Path to this storage is usually : /mnt/sdcard

Don’t be surprised with the “sdcard” name at the end of the path. This path is set by the manufacturer and it is different per device. If you add a sdcard to your device then it’s mounted like an additional storage directory.  Manufacturers should specify  how it will be mounted.  Most likely it will be something like :  “/mnt/sdcard2”.

Here is small list of other possible paths  :

“/mnt/shell/emulated/0”
“/storage/emulated/0”
“/HWUserData”
“/mnt/sdcard0”
“/mnt/sdcard1”
“/storage/sdcard0”
“/storage/sdcard1”
“/storage/extSdCard”

There are some additional algorithms inherited from linux which can detect some additional possible storage paths. So by using the above paths with the algorithm, we can anticipate almost all storage path variations. Google does not have an API which can return the list of all user storage devices (unfortunately for me!).

This approach worked very well until Google released Android 4.4 Kitkat. On one hand, they added a new API for storage detection which works good(of course not 100%). On the other hand they absolutely BRICKED sdcard use for our purposes. Google changed the way SD-Card cab be accessed by 3rd party applications. Google made the SD-Card read-only and allowed only one specific directory to be writable. Unfortunately this directory is completely deleted when you uninstall an application — including all your settings, games and saves.

 Magic dosbox version 17 added a partial fix for this debacle. Users with android Kitkat can store files like *.iso or pictures on the sdcard which can be loaded with Magic Dosbox. Unfortunately DOS applications cannot be executed from read-only storage, so you have to store them on internal storage which is still writable.

Android 5 introduced a new storage API. This time they fixed the Kitkat sdcard debacle. If users want to make the sdcard accessible for 3rd party applications, they must manually set the path where this application can have access.

UPDATE 22.09.2015

Magic Dosbox has implemented workaround for devices with Android 5 and is able load and save games onto sdcard. Android developers know that the solution provided by Google can be hardly called solution. It works fine for apps what are speed independent, but not for emulator.  Many games work fine with this solution, some may produce small sound crackling if the game writes to disk. It’s because :

1. sdcard is slower then internal storage
2. magic dosbox can’t write directly to sdcard, instead is routed through additional security layer
3. google doesn’t provide replacement for all blocked IO functions, so custom solutions have been added

So for devices with Android v4.4 and above stays:

Place iso, bin, cue files on sdcard. These don’t need write access. Already installed games, or installation itself must be directed to internal storage.

People with Android 5 can use new feature what will be released in version 32 (if tests will be fine) and can use workaround written above.

It’s strongly recommended to not place permissions on whole sdcard, but only on folder with stored games