#!/bin/bash # Copyright (C) 2019 Karel Zak TS_TOPDIR="${0%/*}/../.." TS_DESC="all (fstab)" . "$TS_TOPDIR"/functions.sh ts_init "$*" ts_check_test_command "$TS_CMD_MOUNT" ts_check_test_command "$TS_CMD_UMOUNT" ts_check_test_command "$TS_CMD_FDISK" ts_skip_nonroot ts_check_prog "mkfs.ext2" ts_check_prog "mkfs.ext4" # set global variable TS_DEVICE ts_scsi_debug_init dev_size_mb=50 ts_log "Create partitions" $TS_CMD_FDISK --noauto-pt ${TS_DEVICE} &> /dev/null < /dev/null ts_log "Create filesystem B" mkfs.ext2 ${TS_DEVICE}2 &> /dev/null ts_log "Create filesystem C" mkfs.ext2 ${TS_DEVICE}3 &> /dev/null ts_log "Create filesystem D" mkfs.ext4 ${TS_DEVICE}4 &> /dev/null udevadm settle # use the same top-level mountpoint for all sub-tests MOUNTPOINT=$TS_MOUNTPOINT [ -d "${MOUNTPOINT}A" ] || mkdir -p ${MOUNTPOINT}A [ -d "${MOUNTPOINT}B" ] || mkdir -p ${MOUNTPOINT}B [ -d "${MOUNTPOINT}C" ] || mkdir -p ${MOUNTPOINT}C [ -d "${MOUNTPOINT}D" ] || mkdir -p ${MOUNTPOINT}D # generic fstab rm -rf "${TS_FSTAB}" echo "${TS_DEVICE}1 ${MOUNTPOINT}A ext2 rw,defaults 0 0" >> "${TS_FSTAB}" echo "${TS_DEVICE}2 ${MOUNTPOINT}B ext2 rw,defaults 0 0" >> "${TS_FSTAB}" echo "${TS_DEVICE}3 ${MOUNTPOINT}C ext2 ro,defaults 0 0" >> "${TS_FSTAB}" echo "${TS_DEVICE}4 ${MOUNTPOINT}D ext4 rw,defaults 0 0" >> "${TS_FSTAB}" ts_init_subtest "basic" $TS_CMD_MOUNT --all --fstab "${TS_FSTAB}" >> $TS_OUTPUT 2>> $TS_ERRLOG [ $? == 0 ] || ts_log "mount failed" udevadm settle $TS_CMD_UMOUNT ${MOUNTPOINT}{A,B,C,D} [ $? == 0 ] || ts_log "umount failed" ts_finalize_subtest ts_init_subtest "filter-type" $TS_CMD_MOUNT --all --fstab "${TS_FSTAB}" -t ext4 >> $TS_OUTPUT 2>> $TS_ERRLOG [ $? == 0 ] || ts_log "mount failed" udevadm settle $TS_CMD_UMOUNT ${MOUNTPOINT}D [ $? == 0 ] || ts_log "umount failed" ts_finalize_subtest ts_init_subtest "filter-notype" $TS_CMD_MOUNT --all --fstab "${TS_FSTAB}" -t noext4 >> $TS_OUTPUT 2>> $TS_ERRLOG [ $? == 0 ] || ts_log "mount failed" udevadm settle $TS_CMD_UMOUNT ${MOUNTPOINT}{A,B,C} [ $? == 0 ] || ts_log "umount failed" ts_finalize_subtest ts_init_subtest "filter-option" $TS_CMD_MOUNT --all --fstab "${TS_FSTAB}" -O ro >> $TS_OUTPUT 2>> $TS_ERRLOG [ $? == 0 ] || ts_log "mount failed" udevadm settle $TS_CMD_UMOUNT ${MOUNTPOINT}C [ $? == 0 ] || ts_log "umount failed" ts_finalize_subtest ts_init_subtest "override-option" $TS_CMD_MOUNT --all --fstab "${TS_FSTAB}" -o ro >> $TS_OUTPUT 2>> $TS_ERRLOG [ $? == 0 ] || ts_log "mount failed" udevadm settle $TS_CMD_UMOUNT ${MOUNTPOINT}{A,B,C,D} [ $? == 0 ] || ts_log "umount failed" ts_finalize_subtest ts_init_subtest "relative-path" cd "$TS_OUTDIR" > /dev/null $TS_CMD_MOUNT --all --fstab $(basename "${TS_FSTAB}") >> $TS_OUTPUT 2>> $TS_ERRLOG [ $? == 0 ] || ts_log "mount failed" udevadm settle $TS_CMD_UMOUNT ${MOUNTPOINT}{A,B,C,D} [ $? == 0 ] || ts_log "umount failed" cd - > /dev/null ts_finalize_subtest ts_init_subtest "prefix" MY_ROOT="$TS_OUTDIR/${TS_TESTNAME}-rootdir" [ -d "${MY_ROOT}" ] || mkdir -p ${MY_ROOT} rm -rf "${TS_FSTAB}" echo "${TS_DEVICE}1 /foo/A ext2 rw,defaults 0 0" >> "${TS_FSTAB}" echo "${TS_DEVICE}2 /foo/B ext2 rw,defaults 0 0" >> "${TS_FSTAB}" echo "${TS_DEVICE}3 /foo/C ext2 rw,defaults 0 0" >> "${TS_FSTAB}" echo "${TS_DEVICE}4 /foo/D ext4 rw,defaults 0 0" >> "${TS_FSTAB}" # mount all to prefix $TS_CMD_MOUNT --all \ --fstab "${TS_FSTAB}" \ --target-prefix $MY_ROOT \ -o X-mount.mkdir >> $TS_OUTPUT 2>> $TS_ERRLOG [ $? == 0 ] || ts_log "mount failed" udevadm settle $TS_CMD_UMOUNT $MY_ROOT/foo/{A,B,C,D} [ $? == 0 ] || ts_log "umount failed" ts_finalize_subtest ts_finalize