#!/sbin/sh DEV=$(echo "$@" | tr ' ' '\n' | grep '/dev') OPTIONS="-f -O quota -w 4096 -R 0:0" echo "Executing /sbin/__mkfs.f2fs $OPTIONS $DEV" /sbin/__mkfs.f2fs $OPTIONS $DEV echo "Optimizing f2fs" mkdir -p /mnt mount $DEV /mnt find /sys/fs/f2fs* -name extension_list | while read list; do echo "Updating extensions list for $list" echo "Removing previous extensions list" HOT=$(cat $list | grep -n 'hot file extension' | cut -d : -f 1) COLD=$(($(cat $list | wc -l) - $HOT)) COLDLIST=$(head -n$(($HOT - 1)) $list | grep -v ':') HOTLIST=$(tail -n$COLD $list) echo $COLDLIST | tr ' ' '\n' | while read cold; do echo "[c]!$cold" echo "[c]!$cold" > $list done echo $HOTLIST | tr ' ' '\n' | while read hot; do echo "[h]!$hot" echo "[h]!$hot" > $list done echo "Writing new extensions list" cat /sbin/f2fs-cold.list | grep -v '#' | while read cold; do if [ ! -z $cold ]; then echo "[c]$cold" echo "[c]$cold" > $list fi done cat /sbin/f2fs-hot.list | while read hot; do if [ ! -z $hot ]; then echo "[h]$hot" echo "[h]$hot" > $list fi done done umount /mnt