#!/system/bin/sh
#
# Sets sdcard read cache size and does several other initializations needed by MiniCM
#

if [ -e /system/bin/log ];
then
    LOGI="log -p i -t mountsd --"
    LOGE="log -p e -t mountsd --"
else
    LOGI=echo
    LOGE=echo
fi

FREQ_LIST_FILE2="/data/local/tmp/available_frequencies"
DEFAULT_KB="128KB"
DEFAULT=`/system/xbin/echo $DEFAULT_KB | /system/xbin/sed 's/KB//'`
PROP_KB=`getprop persist.sys.sdcardcachereadsize`
PROP=`/system/xbin/echo $PROP_KB | /system/xbin/sed 's/KB//'`

# Uncomment the following lines to have the overclocking module automatically inserted
#/system/bin/insmod /system/lib/modules/x10minioc.ko 
#/system/bin/sleep 2
#/system/xbin/echo x25 > /proc/x10minioc

/system/xbin/rm -f $FREQ_LIST_FILE2
if [ -e /proc/x10minioc ]
then
	/system/bin/cat /proc/x10minioc | /system/xbin/grep '^     1' | /system/xbin/awk '{print $2}'| /system/xbin/tr '\n' ' ' > $FREQ_LIST_FILE2
else
	/system/xbin/echo "122880 245760 320000 480000 600000" > $FREQ_LIST_FILE2
fi
chown 1000:1000 $FREQ_LIST_FILE2


if [ -f /system/bin/recovery.tar ]; then
	RECVERSION=`/system/xbin/strings /system/bin/recovery.tar | /system/xbin/grep ClockworkMod|/system/xbin/head -n 1`
	setprop ro.recversion "$RECVERSION"
elif [ -f /system/bin/xrecovery.tar ]; then
	RECVERSION=`/system/xbin/strings /system/bin/xrecovery.tar | /system/xbin/grep xRecovery`
	setprop ro.recversion "$RECVERSION"
fi


if [ -n "$PROP_KB" ];
then
	$LOGI "defined sdcard cache read size is $PROP_KB"
	if [ -e /sys/devices/virtual/bdi/179:0/read_ahead_kb ]
	then
		/system/xbin/echo $PROP > /sys/devices/virtual/bdi/179\:0/read_ahead_kb
	fi
else
	$LOGI "no sdcard cache read size defined, using default of $DEFAULT_KB"
	setprop persist.sys.sdcardcachereadsize $DEFAULT_KB
	/system/xbin/echo $DEFAULT > /sys/devices/virtual/bdi/179:0/read_ahead_kb
fi

