OSDN Git Service

maint: update copyright year ranges to include 2011
[android-x86/external-parted.git] / tests / t2100-mkswap.sh
1 #!/bin/sh
2 # create linux-swap partitions
3
4 # Copyright (C) 2007, 2009-2011 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_512_byte_sector_size_
21
22 ######################################################################
23 # When creating a partition of type linux-swap(v1) in a DOS partition
24 # table, ensure that the proper file system type (0x82) is used.
25 # Some releases, e.g. parted-1.8.8 would mistakenly use 0x83.
26 ######################################################################
27 N=2M
28 dev=loop-file
29 dev2=loop-file-2
30 # create a file to simulate the underlying device
31 dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null || fail=1
32
33 # label the test disk
34 parted -s $dev mklabel msdos > out 2>&1 || fail=1
35 compare out /dev/null || fail=1
36
37 # create a partition
38 parted -s $dev mkpart primary 2048s 4095s > out 2>&1 || fail=1
39 compare out /dev/null || fail=1
40
41 # create a linux-swap file system
42 parted -s $dev mkfs 1 "linux-swap(v1)" > out 2>&1 || fail=1
43 compare out /dev/null || fail=1
44
45 # Extract the byte at offset 451.  It must be 0x82, not 0x83.
46 # extract byte 451 (fs-type)
47 od -t x1 -An -j450 -N1 $dev > out && echo " 82" > exp || fail=1
48
49 # expect it to be 82, not 83
50 compare out exp || fail=1
51
52 # create another file to simulate the underlying device
53 dd if=/dev/null of=$dev2 bs=1 seek=$N 2> /dev/null || fail=1
54
55 # label another test disk
56 parted -s $dev2 mklabel msdos > out 2>&1 || fail=1
57 compare out /dev/null || fail=1
58
59 # create another partition
60 parted -s $dev2 mkpart primary 2048s 4095s > out 2>&1 || fail=1
61 compare out /dev/null || fail=1
62
63 # create another linux-swap file system
64 parted -s $dev2 mkfs 1 "linux-swap(v1)" > out 2>&1 || fail=1
65 compare out /dev/null || fail=1
66
67 # partition starts at offset 1048576; swap UUID is 1036 bytes in
68 # extract UUID 1
69 od -t x1 -An -j1049612 -N16 $dev > uuid1 || fail=1
70 # extract UUID 2
71 od -t x1 -An -j1049612 -N16 $dev2 > uuid2 || fail=1
72 # two linux-swap file systems must have different UUIDs
73 cmp uuid1 uuid2 && fail=1
74
75 # check linux-swap file system
76 parted -s $dev2 check 1 > out 2>&1 || fail=1
77 compare out /dev/null || fail=1
78
79 # extract new UUID 2
80 od -t x1 -An -j1049612 -N16 $dev2 > uuid2-new || fail=1
81 # check preserves linux-swap UUID
82 compare uuid2 uuid2-new || fail=1
83
84 # create a linux-swap file system via alias
85 parted -s $dev mkfs 1 linux-swap > out 2>&1 || fail=1
86 compare out /dev/null || fail=1
87
88 Exit $fail