~youscribe/parted/3.1

« back to all changes in this revision

Viewing changes to tests/t3200-type-change.sh

  • Committer: Guilhem Lettron
  • Date: 2012-10-22 14:37:59 UTC
  • Revision ID: guilhem+ubuntu@lettron.fr-20121022143759-m403kecgz13sknvp
3.1 from tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# Ensure parted doesn't change the type of a partition to match its FS.
 
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
 
 
21
require_root_
 
22
require_scsi_debug_module_
 
23
 
 
24
grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
 
25
  skip_ 'this system lacks a new-enough libblkid'
 
26
 
 
27
# create memory-backed device
 
28
scsi_debug_setup_ dev_size_mb=550 > dev-name ||
 
29
  skip_ 'failed to create scsi_debug device'
 
30
scsi_dev=$(cat dev-name)
 
31
 
 
32
# Create an empty partition of "type fat32", and then create an actual
 
33
# ext2 partition in it.  Then "unset" the already unset LVM flag on that
 
34
# partition and ensure that parted doesn't "helpfully" change the partition
 
35
# type to match the newly-detected FS type.
 
36
 
 
37
parted -s $scsi_dev mklabel msdos mkpart primary fat32 64s 80000s || fail=1
 
38
 
 
39
parted -s $scsi_dev u s p
 
40
 
 
41
p1=${scsi_dev}1
 
42
wait_for_dev_to_appear_ $p1 || fail=1
 
43
mkfs.ext2 $p1 || fail=1
 
44
 
 
45
# print as hex, the type of the first partition
 
46
msdos_p1_type() { od -An --skip=450 -N1 -tx1 "$1"; }
 
47
 
 
48
# Initially, it is 0x0c (FAT32).
 
49
type=$(msdos_p1_type $scsi_dev) || fail=1
 
50
type=${type# } # remove leading space
 
51
case $type in
 
52
  0c) ;;
 
53
  *) fail_ "expected initial type of 0c (FAT32)";;
 
54
esac
 
55
 
 
56
parted -s $scsi_dev u s p
 
57
parted -s $scsi_dev set 1 lvm off || fail=1
 
58
 
 
59
# Before parted-2.1, the above would mistakenly change it to 0x83,
 
60
# to match the file system now residing in that partition.
 
61
type=$(msdos_p1_type $scsi_dev) || fail=1
 
62
type=${type# } # remove leading space
 
63
case $type in
 
64
  0c) ;;
 
65
  *) fail_ "parted changed the type of partition 1 from 0c to $type";;
 
66
esac
 
67
 
 
68
# Ensure that setting the "lvm" flag still works.
 
69
parted -s $scsi_dev set 1 lvm on || fail=1
 
70
parted -s $scsi_dev u s p > out || fail=1
 
71
grep lvm out || { fail=1; cat out; }
 
72
 
 
73
Exit $fail