From: Masatake YAMATO Date: Wed, 8 Dec 2021 13:30:57 +0000 (+0900) Subject: tests: (lsfd) add a factory for opening a block device to the helper command X-Git-Tag: v2.38-rc1~96^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb16b318d3726d3d839aa66a7a8e2c4b36ab5c04;p=thirdparty%2Futil-linux.git tests: (lsfd) add a factory for opening a block device to the helper command Signed-off-by: Masatake YAMATO --- diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c index db6e92fdb6..bb4fe882a3 100644 --- a/tests/helpers/test_mkfds.c +++ b/tests/helpers/test_mkfds.c @@ -17,6 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include #include #include @@ -456,6 +457,22 @@ static void open_with_opath(const struct factory *factory, struct fdesc fdescs[] }; } +static void open_ro_blkdev(const struct factory *factory, struct fdesc fdescs[], pid_t * child _U_, + int argc, char ** argv) +{ + struct arg blkdev = decode_arg("blkdev", factory->params, argc, argv); + int fd = open(ARG_STRING(blkdev), O_RDONLY); + if (fd < 0) + err(EXIT_FAILURE, "failed to open: %s", ARG_STRING(blkdev)); + free_arg(&blkdev); + + fdescs[0] = (struct fdesc){ + .fd = fd, + .close = close_fdesc, + .data = NULL, + }; +} + #define PARAM_END { .name = NULL, } static const struct factory factories[] = { { @@ -572,6 +589,23 @@ static const struct factory factories[] = { PARAM_END }, }, + { + .name = "ro-block-device", + .desc = "block device with O_RDONLY flag", + .priv = true, + .N = 1, + .fork = false, + .make = open_ro_blkdev, + .params = (struct parameter []) { + { + .name = "blkdev", + .type = PTYPE_STRING, + .desc = "block device node to be opened", + .defv.string = "/dev/nullb0", + }, + PARAM_END + }, + }, }; static int count_parameters(const struct factory *factory)