| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# Copyright (C) 2021 Masatake YAMATO <[email protected]> |
| 4 |
# |
| 5 |
# This file is part of util-linux. |
| 6 |
# |
| 7 |
# This file is free software; you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 2 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# This file is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
TS_TOPDIR="${0%/*}/../.." |
| 18 |
TS_DESC="block device with O_RDONLY" |
| 19 |
|
| 20 |
. "$TS_TOPDIR"/functions.sh |
| 21 |
ts_init "$*" |
| 22 |
ts_skip_nonroot |
| 23 |
ts_skip_docker |
| 24 |
|
| 25 |
# losetup cannot find an unused loop device. |
| 26 |
ts_skip_qemu_user |
| 27 |
|
| 28 |
. "$TS_SELF"/lsfd-functions.bash |
| 29 |
|
| 30 |
ts_check_test_command "$TS_CMD_LSFD" |
| 31 |
|
| 32 |
ts_check_test_command "$TS_CMD_LOSETUP" |
| 33 |
ts_check_test_command "$TS_HELPER_MKFDS" |
| 34 |
|
| 35 |
ts_cd "$TS_OUTDIR" |
| 36 |
|
| 37 |
ts_device_init |
| 38 |
LSFD_LOOP_BDEV=$TS_LODEV |
| 39 |
LSFD_LOOP_BDEV_BASENAME=${LSFD_LOOP_BDEV##*/} |
| 40 |
LSFD_LOOP_BDEV_NUM=${LSFD_LOOP_BDEV_BASENAME#loop} |
| 41 |
|
| 42 |
PID= |
| 43 |
FD=3 |
| 44 |
EXPR= |
| 45 |
|
| 46 |
{ |
| 47 |
coproc MKFDS { "$TS_HELPER_MKFDS" ro-block-device $FD blkdev=${LSFD_LOOP_BDEV}; } |
| 48 |
if read -u ${MKFDS[0]} PID; then |
| 49 |
EXPR='(PID == '"${PID}"') and (FD == '"$FD"')' |
| 50 |
${TS_CMD_LSFD} -n -o ASSOC,MODE,TYPE,POS,BLKDRV,DEVTYPE -Q "${EXPR}" |
| 51 |
echo 'ASSOC,MODE,TYPE,,POS,,BLKDRV,DEVTYPE': $? |
| 52 |
|
| 53 |
LSFD_NAME=$(${TS_CMD_LSFD} --raw -n -o NAME -Q "${EXPR}") |
| 54 |
echo 'NAME[RUN]:' $? |
| 55 |
[ "${LSFD_NAME}" == "${LSFD_LOOP_BDEV}" ] |
| 56 |
echo 'NAME[STR]:' $? |
| 57 |
|
| 58 |
LSFD_SOURCE=$(${TS_CMD_LSFD} --raw -n -o SOURCE -Q "${EXPR}") |
| 59 |
echo 'SOURCE[RUN]:' $? |
| 60 |
[ "${LSFD_SOURCE}" == "${LSFD_LOOP_BDEV_BASENAME}" ] |
| 61 |
echo 'SOURCE[STR]:' $? |
| 62 |
|
| 63 |
LSFD_MAJ_MIN=$(${TS_CMD_LSFD} --raw -n -o MAJ:MIN -Q "${EXPR}") |
| 64 |
echo 'MAJ_MIN[RUN]:' $? |
| 65 |
[ "${LSFD_MAJ_MIN}" == 7:"${LSFD_LOOP_BDEV_NUM}" ] |
| 66 |
echo 'MAJ_MIN[STR]:' $? |
| 67 |
|
| 68 |
LSFD_RDEV=$(${TS_CMD_LSFD} --raw -n -o RDEV -Q "${EXPR}") |
| 69 |
echo 'RDEV[RUN]:' $? |
| 70 |
[ "${LSFD_RDEV}" == 7:"${LSFD_LOOP_BDEV_NUM}" ] |
| 71 |
echo 'RDEV[STR]:' $? |
| 72 |
|
| 73 |
lsfd_compare_dev "${TS_CMD_LSFD}" "${LSFD_LOOP_BDEV}" "${EXPR}" |
| 74 |
|
| 75 |
echo DONE >&"${MKFDS[1]}" |
| 76 |
fi |
| 77 |
wait ${MKFDS_PID} |
| 78 |
} > $TS_OUTPUT 2>&1 |
| 79 |
|
| 80 |
ts_finalize |