| #!/bin/bash |
| |
| SCRIPT=$(readlink -f "$0") |
| SCRIPTDIR=$(dirname "$SCRIPT") |
| MKLFS=$SCRIPTDIR/mklfs |
| |
| # parameters |
| INPUT=$1 |
| OUTPUT=$2 |
| INLINE_SIZE=$3 |
| PAGE_SIZE=$4 |
| BLK_SIZE=$5 |
| CYCLE_SIZE=$6 |
| |
| # config limitation size, 80MB |
| LIMIT_SIZE=`expr 80 \* 1024 \* 1024` |
| |
| nr_dir=`find $INPUT -type d | wc -l` |
| nr_file_s_1k=`find $INPUT -type f -size -${INLINE_SIZE}c | wc -l` |
| nr_file_b_1k_s_blk=`find $INPUT -type f -size +${INLINE_SIZE}c -size -${BLK_SIZE}c | wc -l` |
| nr_file_b_blk=`find $INPUT -type f -size +${BLK_SIZE}c | wc -l` |
| |
| # 2 blocks per dir |
| est_nr_blk=`expr "$nr_dir" \* 2` |
| #est_nr_blk=`expr "$nr_dir" + 2` |
| # other files |
| est_nr_blk=`expr "$est_nr_blk" + "$nr_file_b_1k_s_blk" + "$nr_file_b_blk"` |
| est_img_size=`expr "$est_nr_blk" \* "$BLK_SIZE"` |
| nr_iter=1 |
| |
| echo "MKLFS: $MKLFS" |
| echo "DIR #: $nr_dir" |
| echo "FILE # (0 ~ ${INLINE_SIZE}): $nr_file_s_1k" |
| echo "FILE # (${INLINE_SIZE} ~ ${BLK_SIZE}): $nr_file_b_1k_s_blk" |
| echo "FILE # (> ${BLK_SIZE}): $nr_file_b_blk" |
| echo "Estimated block #: $est_nr_blk" |
| echo "Estimated image size: $est_img_size B" |
| echo "Limited size: $LIMIT_SIZE B" |
| |
| # do iterations |
| while [ "true" ]; do |
| echo "iter $nr_iter: mklfs -c $INPUT -y $CYCLE_SIZE -b $BLK_SIZE -r $PAGE_SIZE -p $PAGE_SIZE -s $est_img_size -i $OUTPUT" |
| # size check |
| if [ "$est_img_size" -gt "$LIMIT_SIZE" ]; then |
| echo "Sorry... image exceeded the limit size $est_img_size > $LIMIT_SIZE B" |
| # error return |
| exit 1 |
| fi |
| |
| rm -f $OUTPUT |
| tmp=`$MKLFS -c $INPUT -y 512 -b $BLK_SIZE -r $PAGE_SIZE -p $PAGE_SIZE -s $est_img_size -i $OUTPUT 2>/dev/null` |
| nofree=`echo "$tmp" | grep "No more free space"` |
| #echo "tmp: $tmp" |
| #echo "nofree: $nofree" |
| if [ "$nofree" != "" ]; then |
| #echo "no free space" |
| # add 1 block per step |
| est_img_size=`expr $est_img_size + $BLK_SIZE` |
| else |
| # okay... all is done |
| break |
| fi |
| nr_iter=`expr $nr_iter + 1` |
| done |
| |
| #est_img_size=`expr $est_img_size / 1024` |
| echo "Final image size: ${est_img_size}B, # iter: $nr_iter" |