home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / lib / partman / resize.sh < prev   
Encoding:
Text File  |  2006-05-23  |  4.6 KB  |  187 lines

  1. # Sets $virtual; used by other functions here.
  2. check_virtual () {
  3.     open_dialog VIRTUAL $oldid
  4.     read_line virtual
  5.     close_dialog
  6. }
  7.  
  8. get_ntfs_resize_range () {
  9.     local backupdev num bdev size
  10.     open_dialog GET_VIRTUAL_RESIZE_RANGE $oldid
  11.     read_line minsize cursize maxsize
  12.     close_dialog
  13.     # A weird way to get the real device path.  The partition numbers
  14.     # in parted_server may be changed and the partition table is still
  15.     # not commited to the disk
  16.     backupdev=/var/lib/partman/backup/${dev#/var/lib/partman/devices/}
  17.     if [ -f $backupdev/$oldid/view -a -f $backupdev/device ]; then
  18.     num=$(sed 's/^[^0-9]*\([0-9]*\)[^0-9].*/\1/' $backupdev/$oldid/view)
  19.     bdev=$(cat $backupdev/device)
  20.     case $bdev in
  21.         */disc)
  22.         bdev=${bdev%/disc}/part$num
  23.         ;;
  24.         /dev/[hs]d[a-z])
  25.         bdev=$bdev$num
  26.         ;;
  27.         *)
  28.         log "get_ntfs_resize_range: strange device name $bdev"
  29.         return
  30.         ;;
  31.     esac
  32.     if [ -b $bdev ]; then
  33.         size=$(ntfsresize -f -i $bdev \
  34.         | grep '^You might resize at' \
  35.         | sed 's/^You might resize at \([0-9]*\) bytes.*/\1/' \
  36.         | grep '^[0-9]*$')
  37.         if [ "$size" ]; then
  38.         minsize=$size
  39.         fi
  40.     fi
  41.     fi
  42. }
  43.  
  44. get_resize_range () {
  45.     open_dialog GET_RESIZE_RANGE $oldid
  46.     read_line minsize cursize maxsize
  47.     close_dialog
  48. }
  49.  
  50. human_resize_range () {
  51.     hminsize=$(longint2human $minsize)
  52.     hcursize=$(longint2human $cursize)
  53.     hmaxsize=$(longint2human $maxsize)
  54.     minpercent=$((100 * $minsize / $maxsize))
  55. }
  56.  
  57. ask_for_size () {
  58.     local noninteractive digits minmb
  59.     noninteractive=true
  60.     while true; do
  61.     newsize=''
  62.     while [ ! "$newsize" ]; do
  63.         db_set partman-partitioning/new_size "$hcursize"
  64.         db_subst partman-partitioning/new_size MINSIZE "$hminsize"
  65.         db_subst partman-partitioning/new_size MAXSIZE "$hmaxsize"
  66.         db_subst partman-partitioning/new_size PERCENT "$minpercent%"
  67.         db_input critical partman-partitioning/new_size || $noninteractive
  68.         noninteractive="return 1"
  69.         db_go || return 1
  70.         db_get partman-partitioning/new_size
  71.         case "$RET" in
  72.         max)
  73.             newsize=$maxsize
  74.             ;;
  75.         *%)
  76.             digits=$(expr "$RET" : '\([1-9][0-9]*\) *%$')
  77.             if [ "$digits" ]; then
  78.             maxmb=$(expr 0000000"$maxsize" : '0*\(..*\)......$')
  79.             newsize=$(($digits * $maxmb / 100))000000
  80.             fi
  81.             ;;
  82.         *)
  83.             if valid_human "$RET"; then
  84.             newsize=$(human2longint "$RET")
  85.             fi
  86.             ;;
  87.         esac
  88.         if [ -z "$newsize" ]; then
  89.         db_input high partman-partitioning/bad_new_size || true
  90.         db_go || true
  91.         elif ! longint_le "$newsize" "$maxsize"; then
  92.         db_input high partman-partitioning/big_new_size || true
  93.         db_go || true
  94.         newsize=''
  95.         elif ! longint_le "$minsize" "$newsize"; then
  96.         db_input high partman-partitioning/small_new_size || true
  97.         db_go || true
  98.         newsize=''
  99.         fi
  100.     done
  101.     if perform_resizing; then break; fi
  102.     done
  103.     return 0
  104. }
  105.  
  106. perform_resizing () {
  107.     if [ "$virtual" = no ]; then
  108.     for s in /lib/partman/commit.d/*; do
  109.         if [ -x $s ]; then
  110.         $s || {
  111.             db_input high partman-partitioning/new_size_commit_failed || true
  112.             db_go || true
  113.             for s in /lib/partman/init.d/*; do
  114.             if [ -x $s ]; then
  115.                 $s || exit 100
  116.             fi
  117.             done
  118.             exit 100
  119.         }
  120.         fi
  121.     done
  122.     fi
  123.  
  124.     disable_swap
  125.  
  126.     if \
  127.     [ "$virtual" = no ] \
  128.     && [ -f $oldid/detected_filesystem ] \
  129.     && [ "$(cat $oldid/detected_filesystem)" = ntfs ]
  130.     then
  131.     # resize NTFS
  132.     if longint_le "$cursize" "$newsize"; then
  133.         open_dialog VIRTUAL_RESIZE_PARTITION $oldid $newsize
  134.         read_line newid
  135.         close_dialog
  136.         open_dialog COMMIT
  137.         close_dialog
  138.         open_dialog PARTITION_INFO $newid
  139.         read_line x1 x2 x3 x4 x5 path x7
  140.         close_dialog
  141.         echo y | ntfsresize -f $path
  142.     else
  143.         open_dialog COMMIT
  144.         close_dialog
  145.         open_dialog PARTITION_INFO $oldid
  146.         read_line x1 x2 x3 x4 x5 path x7
  147.         close_dialog
  148.         if echo y | ntfsresize -f --size "$newsize" $path; then
  149.         open_dialog VIRTUAL_RESIZE_PARTITION $oldid $newsize
  150.         read_line newid
  151.         close_dialog
  152.         echo y | ntfsresize -f $path
  153.         fi
  154.     fi
  155.     else
  156.     # resize virtual partitions, ext2, ext3, swap, fat16, fat32
  157.     # and probably reiserfs 
  158.     name_progress_bar partman-partitioning/progress_resizing
  159.     open_dialog RESIZE_PARTITION $oldid $newsize
  160.     read_line newid
  161.     close_dialog
  162.     fi
  163.  
  164.     if [ -n "$newid" -a "$newid" != "$oldid" ]; then
  165.     [ ! -e "$newid" ] || rm -rf $newid
  166.     mkdir $newid
  167.     cp -r $oldid/* $newid/
  168.     fi
  169.     if [ "$virtual" = no ]; then
  170.     for s in /lib/partman/init.d/*; do
  171.         if [ -x $s ]; then
  172.         $s || exit 100
  173.         fi
  174.     done
  175.     else 
  176.     partitions=''
  177.     open_dialog PARTITIONS
  178.     while { read_line num part size type fs path name; [ "$part" ]; }; do
  179.         partitions="$partitions $part"
  180.     done
  181.     close_dialog
  182.     for part in $partitions; do
  183.         update_partition $dev $part
  184.     done
  185.     fi
  186. }
  187.