diff options
Diffstat (limited to 'src/btrfs-utils/btrfs-shrink')
-rwxr-xr-x | src/btrfs-utils/btrfs-shrink | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/btrfs-utils/btrfs-shrink b/src/btrfs-utils/btrfs-shrink index 229b478..4c4e40d 100755 --- a/src/btrfs-utils/btrfs-shrink +++ b/src/btrfs-utils/btrfs-shrink | |||
@@ -6,7 +6,7 @@ die() { printf "%s: Error: %s\n" "$0" "$*" >&2; exit 1; } | |||
6 | 6 | ||
7 | shrink() | 7 | shrink() |
8 | { | 8 | { |
9 | shrinkmegs=100 | 9 | local shrinkmegs=100 mountpoint="$1" |
10 | while true; do | 10 | while true; do |
11 | while ! btrfs filesystem resize -${shrinkmegs}M "$mountpoint"/; do | 11 | while ! btrfs filesystem resize -${shrinkmegs}M "$mountpoint"/; do |
12 | shrinkmegs=$((shrinkmegs - 10 )) | 12 | shrinkmegs=$((shrinkmegs - 10 )) |
@@ -30,18 +30,20 @@ btrfs_truncate() | |||
30 | main() | 30 | main() |
31 | { | 31 | { |
32 | if [ -d "$1" ]; then | 32 | if [ -d "$1" ]; then |
33 | mountpoint -q "$1" || die "not a mountpoint: $1" | 33 | mountpoint=$1 |
34 | shrink "$1" | 34 | mountpoint -q "$mountpoint" || die "not a mountpoint: $1" |
35 | shrink "$mountpoint" | ||
35 | elif [ -f "$1" ]; then | 36 | elif [ -f "$1" ]; then |
36 | mkdir "$1".mnt.tmp | 37 | mountpoint="$1".mnt.tmp |
37 | mount -t btrfs "$1" "$1".mnt.tmp | 38 | mkdir "$mountpoint" |
39 | mount -t btrfs "$1" "$mountpoint" | ||
38 | result=$? | 40 | result=$? |
39 | if [ $result = 0 ]; then | 41 | if [ $result = 0 ]; then |
40 | shrink "$1".mnt.tmp | 42 | shrink "$mountpoint" |
41 | result=$? | 43 | result=$? |
44 | umount "$mountpoint" | ||
42 | fi | 45 | fi |
43 | umount "$1".mnt.tmp | 46 | rmdir "$mountpoint" |
44 | rmdir "$1".mnt.tmp | ||
45 | btrfs_truncate "$1" | 47 | btrfs_truncate "$1" |
46 | return $result | 48 | return $result |
47 | else | 49 | else |