summaryrefslogtreecommitdiff
path: root/tests/t5000-tags.sh
blob: defe7fad769e954fa8d64672aa5542013429e9cc (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
#!/bin/sh
# test bios_grub flag in gpt labels

# Copyright (C) 2007-2014, 2019-2022 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/>.


. "${srcdir=.}/init.sh"; path_prepend_ ../parted
ss=$sector_size_

dev=loop-file
N=4200 # number of sectors

part_sectors=2048
start_sector=2048
end_sector=$(expr $start_sector + $part_sectors - 1)

# setup: reasonable params
test $end_sector -lt $N || fail=1

# setup: create zeroed device
dd if=/dev/zero of=$dev bs=${ss}c count=$N 2> /dev/null || fail=1

# create gpt label
parted -s $dev mklabel gpt > empty 2>&1 || fail=1

# ensure there was no output
compare /dev/null empty || fail=1

# print the table (before adding a partition)
parted -m -s $dev unit s print > t 2>&1 || fail=1
sed "s,.*/$dev:,$dev:," t > out || fail=1

# check for expected output
printf "BYT;\n$dev:${N}s:file:$ss:$ss:gpt::;\n" > exp || fail=1
compare exp out || fail=1

# add a partition
parted -s $dev u s mkpart name1 ${start_sector} ${end_sector} >out 2>&1 \
  || fail=1

# print the table before modification
parted -m -s $dev unit s print > t 2>&1 || fail=1
sed "s,.*/$dev:,$dev:," t >> out || fail=1

# set the new bios_grub attribute
parted -m -s $dev set 1 bios_grub on || fail=1

# print the table after modification
parted -m -s $dev unit s print > t 2>&1 || fail=1
sed "s,.*/$dev:,$dev:," t >> out || fail=1

gen_exp()
{
  cat <<EOF
BYT;
$dev:${N}s:file:$ss:$ss:gpt::;
1:${start_sector}s:${end_sector}s:${part_sectors}s::name1:;
BYT;
$dev:${N}s:file:$ss:$ss:gpt::;
1:${start_sector}s:${end_sector}s:${part_sectors}s::name1:bios_grub;
EOF
}

# check for expected output
gen_exp > exp || fail=1
compare exp out || fail=1

Exit $fail