summaryrefslogtreecommitdiff
path: root/tests/t3000-resize-fs.sh
blob: f9a24017330dd4f5b0ee2cc4942f21659e62ef37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh
# exercise the resize sub-command; FAT and HFS only

# Copyright (C) 2009-2010 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

if test "$VERBOSE" = yes; then
  set -x
  parted --version
fi

: ${srcdir=.}
. $srcdir/t-lib.sh
require_hfs_

require_root_
require_scsi_debug_module_
require_512_byte_sector_size_

cat <<EOF > exp-warning || framework_failure
WARNING: you are attempting to use parted to operate on (resize) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs.  We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
EOF

ss=$sector_size_

start=63s
default_end=546147s
    new_end=530144s

# create memory-backed device
scsi_debug_setup_ dev_size_mb=550 > dev-name ||
  skip_ 'failed to create scsi_debug device'
dev=$(cat dev-name)

fail=0

parted -s $dev mklabel gpt > out 2>&1 || fail=1
# expect no output
compare out /dev/null || fail=1

# ensure that the disk is large enough
dev_n_sectors=$(parted -s $dev u s p|sed -n '2s/.* \([0-9]*\)s$/\1/p')
device_sectors_required=$(echo $default_end | sed 's/s$//')
# Ensure that $dev is large enough for this test
test $device_sectors_required -le $dev_n_sectors || fail=1

for fs_type in hfs+ fat32; do

  # create an empty $fs_type partition, cylinder aligned, size > 256 MB
  parted -s $dev mkpart primary $fs_type $start $default_end > out 2>&1 || fail=1
  echo "Warning: The resulting partition is not properly" \
      "aligned for best performance." > exp
  compare out exp || fail=1

  # print partition table
  parted -m -s $dev u s p > out 2>&1 || fail=1

  # FIXME: check expected output

  # There's a race condition here: on udev-based systems, the partition#1
  # device, ${dev}1 (i.e., /dev/sde1) is not created immediately, and
  # without some delay, this mount command would fail.  Using a flash card
  # as $dev, the loop below typically iterates 7-20 times.

  # wait for new partition device to appear
  wait_for_dev_to_appear_ ${dev}1 || { warn_ "${dev}1 did not appear"  fail=1; }
  sleep 1

  case $fs_type in
    fat32) mkfs_cmd='mkfs.vfat -F 32';;
    hfs*) mkfs_cmd='mkfs.hfs';;
    *) error "internal error: unhandled fs type: $fs_type";;
  esac

  # create the file system
  $mkfs_cmd ${dev}1 || fail=1

  # NOTE: shrinking is the only type of resizing that works.
  # resize that file system to be one cylinder (8MiB) smaller
  parted -s $dev resize 1 $start $new_end > out 2> err || fail=1
  # expect no output
  compare out /dev/null || fail=1
  compare err exp-warning || fail=1

  # print partition table
  parted -m -s $dev u s p > out 2>&1 || fail=1

  # compare against expected output
  sed -n 3p out > k && mv k out || fail=1
  printf "1:$start:$new_end:530082s:$fs_type:primary:$ms;\n" > exp || fail=1
  compare out exp || fail=1

  # Remove the partition explicitly, so that mklabel doesn't evoke a warning.
  parted -s $dev rm 1 || fail=1

  # Create a clean partition table for the next iteration.
  parted -s $dev mklabel gpt > out 2>&1 || fail=1
  # expect no output
  compare out /dev/null || fail=1

done

Exit $fail