OK, so I have dug up a lot of info and am not sure where to start.
The first thing to understand is that Android system does not use a traditional UNIX rc.d init system where everything is in little scripts. If you have dug into Solaris svcadm or OS X launchd, it is more like that. (Why? it's better because it's more flexible and everything can run in parallel for speed.) Android now has a volume manager daemon called vold.
If you're familiar with the Observer pattern of object-oriented development, then what happens will make sense ... apps register as BroadcastReceivers with the system, and when the system broadcasts ACTION_SHUTDOWN, they can perform system shutdown actions.
So, one possibility is to make a tiny app that does nothing but umount your partition when this system event fires. But that seems like a lot of custom work for such a little thing ... better to try to get vold to do it.
Normally, /sdcard is the only partition managed by vold and the only one umounted before shutdown. All the yaffs2 partitions like /data and /system *aren't* cleanly umounted.
So, what you need to do is, rather than making your fs mount via the mount command (unmanaged by vold), get vold to manage the mount. Then, it *should* be cleanly unmounted automatically before shutdown. That is what I would try first.
How to do this? Well, as of froyo, the mounts are in an fstab-like file, /system/etc/vold.fstab, so hopefully it should just be a matter of adding a line to that file. Here's
some info on that file (it's from Android x86, but still useful). If you look at vold.fstab on your phone, you will see it's pretty barebones. I've been building the froyo system (2.2.1) recently, so here is the friendly fully commented version:
Code:
## Vold 2.0 Generic fstab
## - San Mehat (san@android.com)
##
#######################
## Regular device mount
##
## Format: dev_mount <label> <mount_point> <part> <sysfs_path1...>
## label - Label for the volume
## mount_point - Where the volume will be mounted
## part - Partition # (1 based), or 'auto' for first usable partition.
## <sysfs_path> - List of sysfs paths to source devices
######################
## Example of a standard sdcard mount for the emulator / Dream
# Mounts the first usable partition of the specified device
dev_mount sdcard /mnt/sdcard auto /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1
## Example of a dual card setup
# dev_mount left_sdcard /sdcard1 auto /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1
# dev_mount right_sdcard /sdcard2 auto /devices/platform/goldfish_mmc.1 /devices/platform/msm_sdcc.3/mmc_host/mmc1
## Example of specifying a specific partition for mounts
# dev_mount sdcard /sdcard 2 /devices/platform/goldfish_mmc.0 /devices/platform/msm_sdcc.2/mmc_host/mmc1
There is a command "vdc" which you can use to manage vold mounts at runtime. "vdc volume list" will print a list of mounted volumes. Here's
a thread with a little more info. You can possibly use vdc to make/test your mount syntax before putting it into vold.fstab.
For a totally different, script-based approach, see
this thread. To make it work you would need to do two things, first create an sh script to do your umounts (i.e. /system/bin/shutdown) in their example, and second register the script in one of the .rc files, like init.rc or init.thunderc.rc. (like anything in the root directory, these files live in the rootfs ramdisk which requires unpacking/repacking your boot partition image, so you will have to look that up if you haven't done it before).
vold is the new hotness, I would go with that.
worst-case, I guess you can stick with ext3/4 and let the journal sort it out.