genext2fs.sh 849 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/sh
  2. # genext2fs wrapper calculating needed blocks/inodes values if not specified
  3. export LC_ALL=C
  4. CALC_BLOCKS=1
  5. CALC_INODES=1
  6. while getopts x:d:D:b:i:N:m:g:e:zfqUPhVv f
  7. do
  8. case $f in
  9. b) CALC_BLOCKS=0 ;;
  10. N) CALC_INODES=0; INODES=$OPTARG ;;
  11. d) TARGET_DIR=$OPTARG ;;
  12. esac
  13. done
  14. # calculate needed inodes
  15. if [ $CALC_INODES -eq 1 ];
  16. then
  17. INODES=$(find $TARGET_DIR | wc -l)
  18. INODES=$(expr $INODES + 400)
  19. set -- $@ -N $INODES
  20. fi
  21. # calculate needed blocks
  22. if [ $CALC_BLOCKS -eq 1 ];
  23. then
  24. # size ~= superblock, block+inode bitmaps, inodes (8 per block), blocks
  25. # we scale inodes / blocks with 10% to compensate for bitmaps size + slack
  26. BLOCKS=$(du -s -c -k $TARGET_DIR | grep total | sed -e "s/total//")
  27. BLOCKS=$(expr 500 + \( $BLOCKS + $INODES / 8 \) \* 11 / 10)
  28. set -- $@ -b $BLOCKS
  29. fi
  30. exec genext2fs $@