OSDN Git Service

maint: remove now-unused fat-related functions
[android-x86/external-parted.git] / tests / t3310-flags.sh
1 #!/bin/sh
2 # Exercise the exclusive, single-bit flags.
3
4 # Copyright (C) 2010-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 ss=$sector_size_
21 dev=dev-file
22
23 extract_flags()
24 {
25   perl -nle '/^1:2048s:4095s:2048s::(?:P1)?:(.+);$/ and print $1' "$@"
26 }
27
28 for table_type in msdos gpt; do
29
30   # Extract flag names of type $table_type from the texinfo documentation.
31   case $table_type in
32       msdos) search_term=MS-DOS; pri_or_name=pri;;
33       gpt)   search_term=GPT;    pri_or_name=P1;;
34   esac
35   flags=$(sed -n '/^@node set/,/^@node/p' \
36                     "$abs_top_srcdir/doc/parted.texi" \
37                 | perl -00 -ne \
38                     '/^\@item (\w+).*'"$search_term"'/s and print lc($1), "\n"')
39
40   n_sectors=5000
41   dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1
42
43   parted -s $dev mklabel $table_type \
44     mkpart $pri_or_name ext2 $((1*2048))s $((2*2048-1))s \
45       > out 2> err || fail=1
46   compare /dev/null out || fail=1
47
48   for mode in on_only on_and_off ; do
49     for flag in $flags; do
50
51       # Exclude the supplemental flags.
52       # These are not boolean, like the others.
53       case $flag in boot|lba|hidden) continue;; esac
54
55       # Turn on each flag, one at a time.
56       parted -m -s $dev set 1 $flag on u s print > raw 2> err || fail=1
57       extract_flags raw > out
58       grep -F "$flag" out \
59         || { warn_ "$ME: flag not turned on: $(cat out)"; fail=1; }
60       compare /dev/null err || fail=1
61
62       if test $mode = on_and_off; then
63         # Turn it off
64         parted -m -s $dev set 1 $flag off u s print > raw 2> err || fail=1
65         extract_flags raw > out
66         grep -F "$flag" out \
67           && { warn_ "$ME: flag not turned off: $(cat out)"; fail=1; }
68         compare /dev/null err || fail=1
69       fi
70     done
71   done
72 done
73
74 Exit $fail