| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2007 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 |
# This file is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
TS_TOPDIR="${0%/*}/../.." |
| 19 |
TS_DESC="broken fstab" |
| 20 |
|
| 21 |
. "$TS_TOPDIR"/functions.sh |
| 22 |
ts_init "$*" |
| 23 |
|
| 24 |
ts_check_test_command "$TS_CMD_MOUNT" |
| 25 |
ts_check_test_command "$TS_CMD_UMOUNT" |
| 26 |
ts_check_test_command "$TS_CMD_FINDMNT" |
| 27 |
|
| 28 |
ts_skip_nonroot |
| 29 |
ts_skip_docker |
| 30 |
|
| 31 |
# Let's use the same mountpoint for all subtests |
| 32 |
MNT=$TS_MOUNTPOINT |
| 33 |
mkdir -p $MNT |
| 34 |
|
| 35 |
ts_fstab_lock |
| 36 |
ts_fstab_open |
| 37 |
echo "tmpd $MNT tmpfs" >> "$TS_FSTAB" |
| 38 |
ts_fstab_close |
| 39 |
|
| 40 |
ts_init_subtest "mount" |
| 41 |
$TS_CMD_MOUNT --fstab "$TS_FSTAB" $MNT &> /dev/null |
| 42 |
[ "$?" = "0" ] || ts_log "error: mount $MNT" |
| 43 |
$TS_CMD_FINDMNT --kernel --mountpoint "$MNT" &> /dev/null |
| 44 |
if [ "$?" != "0" ]; then |
| 45 |
ts_log "Cannot find $MNT in /proc/self/mountinfo" |
| 46 |
else |
| 47 |
ts_log "OK" |
| 48 |
fi |
| 49 |
$TS_CMD_UMOUNT $MNT &> /dev/null |
| 50 |
if [ "$?" = "0" ]; then |
| 51 |
# for old systems with mtab and /sbin/mount.tmpfs |
| 52 |
/bin/umount --fake "$MNT" &> /dev/null |
| 53 |
else |
| 54 |
ts_log "error: umount $MNT" |
| 55 |
fi |
| 56 |
ts_finalize_subtest |
| 57 |
|
| 58 |
|
| 59 |
ts_init_subtest "mount-all" |
| 60 |
$TS_CMD_MOUNT --fstab "$TS_FSTAB" --all &> /dev/null |
| 61 |
[ "$?" = "0" ] || ts_log "error: mount -a" |
| 62 |
$TS_CMD_FINDMNT --kernel --mountpoint "$MNT" &> /dev/null |
| 63 |
if [ "$?" != "0" ]; then |
| 64 |
ts_log "Cannot find $MNT in /proc/self/mountinfo" |
| 65 |
else |
| 66 |
ts_log "OK" |
| 67 |
fi |
| 68 |
$TS_CMD_UMOUNT $MNT &> /dev/null |
| 69 |
if [ "$?" = "0" ]; then |
| 70 |
# for old systems with mtab and /sbin/mount.tmpfs |
| 71 |
/bin/umount --fake $MNT &> /dev/null |
| 72 |
else |
| 73 |
ts_log "error: umount $MNT" |
| 74 |
fi |
| 75 |
ts_finalize_subtest |
| 76 |
|
| 77 |
ts_fstab_clean # this unlocks too |
| 78 |
|
| 79 |
ts_log "Success" |
| 80 |
ts_finalize |
| 81 |
|