]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (lsfd) add a factory for opening a block device to the helper command
authorMasatake YAMATO <yamato@redhat.com>
Wed, 8 Dec 2021 13:30:57 +0000 (22:30 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Thu, 9 Dec 2021 15:49:58 +0000 (00:49 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/helpers/test_mkfds.c

index db6e92fdb61d9d3ad7fd4b8de45d6c8d6e6e6058..bb4fe882a3e99037cceeba9304be1eb151a95734 100644 (file)
@@ -17,6 +17,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include <ctype.h>
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -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)