OSDN Git Service

2fd36a56c6130c55e8f95416869ae8d46614628d
[android-x86/external-parted.git] / tests / t3000-resize-fs.sh
1 #!/bin/sh
2 # exercise the resize library; FAT and HFS+ only
3
4 # Copyright (C) 2009-2012 Free Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 . "${srcdir=.}/init.sh"; path_prepend_ ../parted .
20 require_hfs_
21
22 require_root_
23 require_scsi_debug_module_
24 require_512_byte_sector_size_
25
26 ss=$sector_size_
27
28 start=63s
29 default_end=546147s
30     new_end=530144s
31
32 # create memory-backed device
33 scsi_debug_setup_ dev_size_mb=550 > dev-name ||
34   skip_test_ 'failed to create scsi_debug device'
35 dev=$(cat dev-name)
36
37 fail=0
38
39 parted -s $dev mklabel gpt > out 2>&1 || fail=1
40 # expect no output
41 compare /dev/null out || fail=1
42
43 # ensure that the disk is large enough
44 dev_n_sectors=$(parted -s $dev u s p|sed -n '2s/.* \([0-9]*\)s$/\1/p')
45 device_sectors_required=$(echo $default_end | sed 's/s$//')
46 # Ensure that $dev is large enough for this test
47 test $device_sectors_required -le $dev_n_sectors || fail=1
48
49 for fs_type in hfs+ fat32; do
50
51   # create an empty $fs_type partition, cylinder aligned, size > 256 MB
52   parted -a min -s $dev mkpart p1 $start $default_end > out 2>&1 || fail=1
53   compare /dev/null out || fail=1
54
55   # print partition table
56   parted -m -s $dev u s p > out 2>&1 || fail=1
57
58   # wait for new partition device to appear
59   wait_for_dev_to_appear_ ${dev}1
60
61   case $fs_type in
62     fat32) mkfs_cmd='mkfs.vfat -F 32'; fsck='fsck.vfat -v';;
63     hfs*) mkfs_cmd='mkfs.hfs';         fsck=fsck.hfs;;
64     *) error "internal error: unhandled fs type: $fs_type";;
65   esac
66
67   # create the file system
68   $mkfs_cmd ${dev}1 || fail=1
69
70   # NOTE: shrinking is the only type of resizing that works.
71   # resize that file system to be one cylinder (8MiB) smaller
72   fs-resize ${dev}1 0 $new_end > out 2>&1 || fail=1
73   # expect no output
74   compare /dev/null out || fail=1
75
76   # This is known to segfault with fsck.hfs from
77   # Fedora 16's hfsplus-tools-332.14-12.fc15.x86_64.
78   # You can build a working version from
79   # git://cavan.codon.org.uk/hfsplus-tools.git
80
81   # Skip the fsck.hfs test unless it understands the -v option.
82   skip=0
83   case $fs_type in
84     hfs*) $fsck -v || { warn_ skipping $fsck test; skip=1; } ;; esac
85
86   if test $skip = 0; then
87     $fsck ${dev}1 > out || fail=1
88     cat out
89     # Oops.  Currently, fsck.hfs reports this:
90     # Executing fsck_hfs (version 540.1-Linux).
91     # ** Checking non-journaled HFS Plus Volume.
92     #    The volume name is untitled
93     # ** Checking extents overflow file.
94     # ** Checking catalog file.
95     # ** Checking multi-linked files.
96     # ** Checking catalog hierarchy.
97     # ** Checking volume bitmap.
98     #    Volume bitmap needs minor repair for orphaned blocks
99     # ** Checking volume information.
100     #    Invalid volume free block count
101     #    (It should be 67189 instead of 65197)
102     #    Volume header needs minor repair
103     # (2, 0)
104     # FIXME: This means the HFS resizing code is wrong.
105
106     # FIXME: parse "out" for FS size and verify that it's the new, smaller size
107   fi
108
109   # Remove the partition explicitly, so that mklabel doesn't evoke a warning.
110   parted -s $dev rm 1 || fail=1
111
112   # Create a clean partition table for the next iteration.
113   parted -s $dev mklabel gpt > out 2>&1 || fail=1
114   # expect no output
115   compare /dev/null out || fail=1
116
117 done
118
119 Exit $fail