Debian Codegraph @

tests/ts/mount/complex

raw
1 #!/bin/bash
2
3 #
4 # Copyright (C) 2022 Karel Zak <[email protected]>
5 #
6 # This file is part of util-linux.
7 #
8 # This file is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 TS_TOPDIR="${0%/*}/../.."
14 TS_DESC="complex"
15
16 . $TS_TOPDIR/functions.sh
17 ts_init "$*"
18
19 ts_skip_nonroot
20 ts_skip_qemu_user
21
22 ts_check_test_command "$TS_CMD_MOUNT"
23 ts_check_losetup
24
25 $TS_CMD_MOUNT --version | grep -q 'fd-based' || ts_skip "no fd-based API"
26
27 ts_device_init
28 DEVICE=$TS_LODEV
29
30 mkfs.ext2 $DEVICE &> /dev/null || ts_die "Cannot make ext2 on $DEVICE"
31 ts_udevadm_settle "$DEVICE"
32
33 ROOT_MOUNTPOINT="$TS_MOUNTPOINT"
34 A_MOUNTPOINT="${ROOT_MOUNTPOINT}/A"
35 B_MOUNTPOINT="${ROOT_MOUNTPOINT}/B"
36
37 [ -d "$ROOT_MOUNTPOINT" ] || mkdir -p $ROOT_MOUNTPOINT
38 [ -d "$A_MOUNTPOINT" ] || mkdir -p $A_MOUNTPOINT
39 [ -d "$B_MOUNTPOINT" ] || mkdir -p $B_MOUNTPOINT
40
41 ## create a private directory
42 ts_init_subtest "init"
43 $TS_CMD_MOUNT --bind --make-private $ROOT_MOUNTPOINT $ROOT_MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
44 $TS_CMD_FINDMNT -nr --mountpoint $ROOT_MOUNTPOINT -o PROPAGATION | grep -q private \
45 || ts_log "Cannot find private $ROOT_MOUNTPOINT"
46 ts_finalize_subtest
47
48
49 ## mount the device
50 ts_init_subtest "rw-mount"
51 $TS_CMD_MOUNT --options rw $DEVICE $A_MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
52 ts_is_mounted $DEVICE || ts_log "Cannot find $DEVICE in /proc/mounts"
53 ts_finalize_subtest
54
55
56 ## move device and set it read-only for VFS (FS is still rw)
57 ts_init_subtest "ro-move"
58 $TS_CMD_MOUNT --move --options ro $A_MOUNTPOINT $B_MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
59 findmnt -nr -o VFS-OPTIONS --mountpoint $B_MOUNTPOINT | grep -q 'ro' \
60 || ts_log "Cannot find ro VFS"
61 findmnt -nr -o FS-OPTIONS --mountpoint $B_MOUNTPOINT | grep -q 'rw' \
62 || ts_log "Cannot find rw FS"
63 ts_finalize_subtest
64
65
66 ## remount to set FS to read-only (VFS is still ro)
67 ts_init_subtest "ro-remount"
68 $TS_CMD_MOUNT --options remount,ro,noexec $B_MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
69 findmnt -nr -o VFS-OPTIONS --mountpoint $B_MOUNTPOINT | grep -q 'ro' \
70 || ts_log "Cannot find ro VFS"
71 findmnt -nr -o FS-OPTIONS --mountpoint $B_MOUNTPOINT | grep -q 'ro' \
72 || ts_log "Cannot find ro FS"
73 ts_finalize_subtest
74
75
76 ## remount to set FS and VFS to read-write
77 ts_init_subtest "rw-remount"
78 $TS_CMD_MOUNT --options remount,rw $B_MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
79 findmnt -nr -o VFS-OPTIONS --mountpoint $B_MOUNTPOINT | grep -q 'rw' \
80 || ts_log "Cannot find rw VFS"
81 findmnt -nr -o FS-OPTIONS --mountpoint $B_MOUNTPOINT | grep -q 'rw' \
82 || ts_log "Cannot find rw FS"
83 ts_finalize_subtest
84
85
86 ## bind as read-only (VFS), set shared propagation,
87 ## and remove noexec (but keep FS rw)
88 ts_init_subtest "ro-shared-bind"
89 $TS_CMD_MOUNT --make-shared --bind --options ro,exec $B_MOUNTPOINT $A_MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
90 findmnt -nr -o VFS-OPTIONS --mountpoint $A_MOUNTPOINT | grep -q 'ro' \
91 || ts_log "Cannot find ro VFS"
92 findmnt -nr -o FS-OPTIONS --mountpoint $A_MOUNTPOINT | grep -q 'rw' \
93 || ts_log "Cannot find rw FS"
94 findmnt -nr -o PROPAGATION --mountpoint $A_MOUNTPOINT | grep -q 'shared' \
95 || ts_log "Cannot find shared flag"
96 findmnt -nr -o VFS-OPTIONS --mountpoint $A_MOUNTPOINT | grep -q 'noexec' \
97 && ts_log "Found noexec flag"
98 ts_finalize_subtest
99
100
101 ## cleanup
102 $TS_CMD_UMOUNT $A_MOUNTPOINT &> /dev/null
103 $TS_CMD_UMOUNT $B_MOUNTPOINT &> /dev/null
104 $TS_CMD_UMOUNT $ROOT_MOUNTPOINT &> /dev/null
105
106 ts_finalize