diff --git a/.gitignore b/.gitignore index 1a3151b6..bc6e51ab 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,8 @@ cpumf/lspai.bash cpumf/pai.bash cpuplugd/cpuplugd dasdfmt/dasdfmt +dasdfmt/_dasdfmt +dasdfmt/dasdfmt.bash dasdinfo/dasdinfo dasdview/dasdview dump2tar/src/dump2tar diff --git a/dasdfmt/Makefile b/dasdfmt/Makefile index 98d9d3ea..e4f8cefd 100644 --- a/dasdfmt/Makefile +++ b/dasdfmt/Makefile @@ -1,5 +1,10 @@ include ../common.mak +zsh-completions = _dasdfmt +bash-completions = dasdfmt.bash + +include ../common_autocomp.mak + all: dasdfmt libs = $(rootdir)/libdasd/libdasd.a \ diff --git a/dasdfmt/autocompletion_generator_host.c b/dasdfmt/autocompletion_generator_host.c new file mode 100644 index 00000000..9ae5a96d --- /dev/null +++ b/dasdfmt/autocompletion_generator_host.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +/* + * Autocompletion generation - for dasdfmt tool + * + * Copyright IBM Corp. 2025 + * + * s390-tools is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ + +#include "lib/util_autocomp.h" + +#include "dasdfmt_cli.h" + +int main(void) +{ + generate_autocomp(opt_vec, "dasdfmt"); + + return 0; +} diff --git a/dasdfmt/dasdfmt.c b/dasdfmt/dasdfmt.c index a49e41c0..29606a6b 100644 --- a/dasdfmt/dasdfmt.c +++ b/dasdfmt/dasdfmt.c @@ -24,6 +24,7 @@ #include "lib/zt_common.h" #include "dasdfmt.h" +#include "dasdfmt_cli.h" #define BUSIDSIZE 8 #define SEC_PER_DAY (60 * 60 * 24) @@ -81,112 +82,6 @@ static struct dasdfmt_globals { .dasd_info = { 0 }, }; -/* Defines for options with no short command */ -#define OPT_CHECK 128 -#define OPT_NOZERO 129 -#define OPT_NODISCARD 130 - -static struct util_opt opt_vec[] = { - UTIL_OPT_SECTION("FORMAT ACTIONS"), - { - .option = { "mode", required_argument, NULL, 'M' }, - .argument = "MODE", - .desc = "Specify scope of operation using MODE:\n" - " full: Full device (default)\n" - " quick: Only the first two tracks\n" - " expand: Unformatted tracks at device end", - }, - { - .option = { "check", no_argument, NULL, OPT_CHECK }, - .desc = "Perform complete format check on device", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - UTIL_OPT_SECTION("FORMAT OPTIONS"), - { - .option = { "blocksize", required_argument, NULL, 'b' }, - .argument = "SIZE", - .desc = "Format blocks to SIZE bytes (default 4096)", - }, - { - .option = { "disk_layout", required_argument, NULL, 'd' }, - .argument = "LAYOUT", - .desc = "Specify the disk layout:\n" - " cdl: Compatible Disk Layout (default)\n" - " ldl: Linux Disk Layout", - }, - { - .option = { "keep_volser", no_argument, NULL, 'k' }, - .desc = "Do not change the current volume serial", - }, - { - .option = { "label", required_argument, NULL, 'l' }, - .argument = "VOLSER", - .desc = "Specify volume serial number", - }, - { - .option = { "no_label", no_argument, NULL, 'L' }, - .desc = "Don't write a disk label", - }, - { - .option = { "requestsize", required_argument, NULL, 'r' }, - .argument = "NUM", - .desc = "Process NUM cylinders in one formatting step", - }, - { - .option = { "norecordzero", no_argument, NULL, OPT_NOZERO }, - .desc = "Prevent storage server from modifying record 0", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - { - .option = { "no-discard", no_argument, NULL, OPT_NODISCARD }, - .desc = "Do not discard space before formatting", - .flags = UTIL_OPT_FLAG_NOSHORT, - }, - { - .option = { NULL, no_argument, NULL, 'y' }, - .desc = "Start formatting without further user-confirmation", - .flags = UTIL_OPT_FLAG_NOLONG, - }, - UTIL_OPT_SECTION("DISPLAY PROGRESS"), - { - .option = { "hashmarks", required_argument, NULL, 'm' }, - .argument = "NUM", - .desc = "Show a hashmark every NUM cylinders", - }, - { - .option = { "progressbar", no_argument, NULL, 'p' }, - .desc = "Show a progressbar", - }, - { - .option = { "percentage", no_argument, NULL, 'P' }, - .desc = "Show progress in percent", - }, - UTIL_OPT_SECTION("MISC"), - { - .option = { "check_host_count", no_argument, NULL, 'C' }, - .desc = "Check if device is in use by other hosts", - }, - { - .option = { "force", no_argument, NULL, 'F' }, - .desc = "Format without performing sanity checking", - }, - { - .option = { "test", no_argument, NULL, 't' }, - .desc = "Run in dry-run mode without modifying the DASD", - }, - { - .option = { NULL, no_argument, NULL, 'v' }, - .desc = "Print verbose messages when executing", - .flags = UTIL_OPT_FLAG_NOLONG, - }, - UTIL_OPT_HELP, - { - .option = { "version", no_argument, NULL, 'V' }, - .desc = "Print version information, then exit", - }, - UTIL_OPT_END -}; - /* Report error, free memory, and exit */ static void error(const char *format, ...) { diff --git a/dasdfmt/dasdfmt_cli.h b/dasdfmt/dasdfmt_cli.h new file mode 100644 index 00000000..d4565b77 --- /dev/null +++ b/dasdfmt/dasdfmt_cli.h @@ -0,0 +1,123 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Command line utilities - for dasdfmt + * + * Copyright IBM Corp. 2025 + * + * s390-tools is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ + +#ifndef DASDFMT_CLI_H +#define DASDFMT_CLI_H + +#include "lib/util_fmt.h" +#include "lib/util_opt.h" + +/* Defines for options with no short command */ +#define OPT_CHECK 128 +#define OPT_NOZERO 129 +#define OPT_NODISCARD 130 + +static struct util_opt opt_vec[] = { +UTIL_OPT_SECTION("FORMAT ACTIONS"), + { + .option = { "mode", required_argument, NULL, 'M' }, + .argument = "MODE", + .desc = "Specify scope of operation using MODE:\n" + " full: Full device (default)\n" + " quick: Only the first two tracks\n" + " expand: Unformatted tracks at device end", + }, + { + .option = { "check", no_argument, NULL, OPT_CHECK }, + .desc = "Perform complete format check on device", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + UTIL_OPT_SECTION("FORMAT OPTIONS"), + { + .option = { "blocksize", required_argument, NULL, 'b' }, + .argument = "SIZE", + .desc = "Format blocks to SIZE bytes (default 4096)", + }, + { + .option = { "disk_layout", required_argument, NULL, 'd' }, + .argument = "LAYOUT", + .desc = "Specify the disk layout:\n" + " cdl: Compatible Disk Layout (default)\n" + " ldl: Linux Disk Layout", + }, + { + .option = { "keep_volser", no_argument, NULL, 'k' }, + .desc = "Do not change the current volume serial", + }, + { + .option = { "label", required_argument, NULL, 'l' }, + .argument = "VOLSER", + .desc = "Specify volume serial number", + }, + { + .option = { "no_label", no_argument, NULL, 'L' }, + .desc = "Don't write a disk label", + }, + { + .option = { "requestsize", required_argument, NULL, 'r' }, + .argument = "NUM", + .desc = "Process NUM cylinders in one formatting step", + }, + { + .option = { "norecordzero", no_argument, NULL, OPT_NOZERO }, + .desc = "Prevent storage server from modifying record 0", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + { + .option = { "no-discard", no_argument, NULL, OPT_NODISCARD }, + .desc = "Do not discard space before formatting", + .flags = UTIL_OPT_FLAG_NOSHORT, + }, + { + .option = { NULL, no_argument, NULL, 'y' }, + .desc = "Start formatting without further user-confirmation", + .flags = UTIL_OPT_FLAG_NOLONG, + }, + UTIL_OPT_SECTION("DISPLAY PROGRESS"), + { + .option = { "hashmarks", required_argument, NULL, 'm' }, + .argument = "NUM", + .desc = "Show a hashmark every NUM cylinders", + }, + { + .option = { "progressbar", no_argument, NULL, 'p' }, + .desc = "Show a progressbar", + }, + { + .option = { "percentage", no_argument, NULL, 'P' }, + .desc = "Show progress in percent", + }, + UTIL_OPT_SECTION("MISC"), + { + .option = { "check_host_count", no_argument, NULL, 'C' }, + .desc = "Check if device is in use by other hosts", + }, + { + .option = { "force", no_argument, NULL, 'F' }, + .desc = "Format without performing sanity checking", + }, + { + .option = { "test", no_argument, NULL, 't' }, + .desc = "Run in dry-run mode without modifying the DASD", + }, + { + .option = { NULL, no_argument, NULL, 'v' }, + .desc = "Print verbose messages when executing", + .flags = UTIL_OPT_FLAG_NOLONG, + }, + UTIL_OPT_HELP, + { + .option = { "version", no_argument, NULL, 'V' }, + .desc = "Print version information, then exit", + }, + UTIL_OPT_END +}; + +#endif