summaryrefslogtreecommitdiff
path: root/tests/t8001-loop-blkpg.sh
blob: 5b7b8919672efec2daacc9d28d6bea1c9acc1269 (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
#!/bin/sh
# Test support for partitions on loop devices

# Copyright (C) 2008-2014, 2019-2023 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

require_root_
require_udevadm_settle_
lvm_init_root_dir_

cleanup_fn_()
{
  test -n "$loopdev" \
    && { udevadm settle --timeout=3; losetup -d "$loopdev"; }
}

# Create backing file
dd if=/dev/zero of=backing_file bs=1M count=4 >/dev/null 2>&1 || fail=1

# Set up loop device on top of backing file
loopdev=$(loop_setup_ backing_file)
test -z "$loopdev" && fail=1

# Skip this test if loop devices are not partitionable.
require_partitionable_loop_device_ $loopdev

# Expect this to succeed
parted -s "$loopdev" mklabel msdos > err 2>&1 || fail=1
compare /dev/null err || fail=1     # expect no output

# Create a partition
parted -s "$loopdev" mkpart primary 1M 2M > err 2>&1 || fail=1
compare /dev/null err || fail=1     # expect no output
udevadm settle --timeout=5 || fail=1

# Verify that the partition appeared in /proc/partitions
entry=$(basename "$loopdev"p1)
grep "$entry" /proc/partitions || { cat /proc/partitions; fail=1; }

# Remove the partition
parted -s "$loopdev" rm 1 > err 2>&1 || fail=1
compare /dev/null err || fail=1     # expect no output
udevadm settle --timeout=5 || fail=1

# Verify that the partition got removed from /proc/partitions
grep "$entry" /proc/partitions && fail=1

Exit $fail