diff --git a/tools/args.h b/tools/args.h index 15d473499..23c0cbde5 100644 --- a/tools/args.h +++ b/tools/args.h @@ -41,6 +41,7 @@ arg(file_ARG, 'f', "file", string_arg) arg(force_ARG, 'f', "force", NULL) arg(full_ARG, 'f', "full", NULL) arg(help_ARG, 'h', "help", NULL) +arg(help2_ARG, '?', "", NULL) arg(stripesize_ARG, 'I', "stripesize", size_arg) arg(stripes_ARG, 'i', "stripes", int_arg) arg(iop_version_ARG, 'i', "iop_version", NULL) diff --git a/tools/commands.h b/tools/commands.h index cddc11b0d..5e984b422 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -41,41 +41,40 @@ xx(help, xx(lvactivate, "Activate logical volume on given partition(s)", "lvactivate " - "\t[-d/--debug]\n" - "\t[-h/--help]\n" - "\t[-v/--verbose]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" + "\t[-v|--verbose]\n" "Logical Volume(s)\n") ***********/ xx(lvchange, "Change the attributes of logical volume(s)", "lvchange\n" - "\t[-A/--autobackup y/n]\n" - "\t[-a/--available y/n]\n" - "\t[-C/--contiguous y/n]\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" + "\t[-A|--autobackup y|n]\n" + "\t[-a|--available y|n]\n" + "\t[-C|--contiguous y|n]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" "\t[--ignorelockingfailure]\n" - "\t[-M/--persistent y/n] [--minor minor]\n" - "\t[-P/--partial] " "\n" - "\t[-p/--permission r/rw]\n" - "\t[-r/--readahead ReadAheadSectors]\n" - "\t[-t/--test]\n" - "\t[-v/--verbose]\n" + "\t[-M|--persistent y|n] [--minor minor]\n" + "\t[-P|--partial] " "\n" + "\t[-p|--permission r|rw]\n" + "\t[-r|--readahead ReadAheadSectors]\n" + "\t[-t|--test]\n" + "\t[-v|--verbose]\n" "\tLogicalVolume[Path] [LogicalVolume[Path]...]\n", autobackup_ARG, available_ARG, contiguous_ARG, - ignorelockingfailure_ARG, minor_ARG, persistent_ARG, partial_ARG, - permission_ARG, readahead_ARG, test_ARG) + ignorelockingfailure_ARG, minor_ARG, partial_ARG, permission_ARG, + persistent_ARG, readahead_ARG, test_ARG) xx(lvcreate, "Create a logical volume", - "Original logical volume synopsis:\n\n" "lvcreate " "\n" "\t[-A|--autobackup {y|n}]\n" "\t[-C|--contiguous {y|n}]\n" "\t[-d|--debug]\n" - "\t[-h|--help]\n" + "\t[-h|-?|--help]\n" "\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n" "\t{-l|--extents LogicalExtentsNumber |\n" "\t -L|--size LogicalVolumeSize[kKmMgGtT]}\n" @@ -87,16 +86,14 @@ xx(lvcreate, "\t[-v|--verbose]\n" "\t[-Z|--zero {y|n}]\n" "\t[--version]\n" - "\tVolumeGroupName [PhysicalVolumePath...]\n\n\n" + "\tVolumeGroupName [PhysicalVolumePath...]\n\n" - "Snapshot logical volume synopsis:\n\n" - "lvcreate " "\n" - "\t-s|--snapshot\n" + "lvcreate -s|--snapshot\n" "\t[-c|--chunksize]\n" "\t[-A|--autobackup {y|n}]\n" "\t[-C|--contiguous {y|n}]\n" "\t[-d|--debug]\n" - "\t[-h|--help]\n" + "\t[-h|-?|--help]\n" "\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n" "\t{-l|--extents LogicalExtentsNumber |\n" "\t -L|--size LogicalVolumeSize[kKmMgGtT]}\n" @@ -116,13 +113,13 @@ xx(lvcreate, xx(lvdisplay, "Display information about a logical volume", "lvdisplay\n" - "\t[-c/--colon]\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" + "\t[-c|--colon]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" "\t[--ignorelockingfailure]\n" - "\t[-m/--maps]\n" - "\t[-P/--partial] " "\n" - "\t[-v/--verbose]\n" + "\t[-m|--maps]\n" + "\t[-P|--partial] " "\n" + "\t[-v|--verbose]\n" "\tLogicalVolume[Path] [LogicalVolume[Path]...]\n", colon_ARG, disk_ARG, ignorelockingfailure_ARG, maps_ARG, partial_ARG) @@ -130,14 +127,14 @@ xx(lvdisplay, xx(lvextend, "Add space to a logical volume", "lvextend\n" - "\t[-A/--autobackup y/n]\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" + "\t[-A|--autobackup y|n]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" "\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n" - "\t{-l/--extents [+]LogicalExtentsNumber |\n" - "\t -L/--size [+]LogicalVolumeSize[kKmMgGtT]}\n" - "\t[-t/--test]\n" - "\t[-v/--verbose]\n" + "\t{-l|--extents [+]LogicalExtentsNumber |\n" + "\t -L|--size [+]LogicalVolumeSize[kKmMgGtT]}\n" + "\t[-t|--test]\n" + "\t[-v|--verbose]\n" "\tLogicalVolume[Path] [ PhysicalVolumePath... ]\n", autobackup_ARG, extents_ARG, size_ARG, stripes_ARG, @@ -146,38 +143,38 @@ xx(lvextend, xx(lvmchange, "With the device mapper, this is obsolete and does nothing.", "lvmchange\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" - "\t[-R/--reset]\n" - "\t[-v/--verbose]\n", + "\t[-d|--debug]\n" + "\t[-h|--help]\n" + "\t[-R|--reset]\n" + "\t[-v|--verbose]\n", reset_ARG) xx(lvmdiskscan, "List devices that may be used as physical volumes", "lvmdiskscan\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" - "\t[-l/--lvmpartition]\n", + "\t[-d|--debug]\n" + "\t[-h|--help]\n" + "\t[-l|--lvmpartition]\n", lvmpartition_ARG) xx(lvmsadc, "Collect activity data", "lvmsadc\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" - "\t[-v/--verbose]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" + "\t[-v|--verbose]\n" "\t[LogFilePath]\n" ) xx(lvmsar, "Create activity report", "lvmsar\n" - "\t[-d/--debug]\n" - "\t[-f/--full]\n" - "\t[-h/--help]\n" - "\t[-s/--stdin]\n" - "\t[-v/--verbose]\n" + "\t[-d|--debug]\n" + "\t[-f|--full]\n" + "\t[-h|--help]\n" + "\t[-s|--stdin]\n" + "\t[-v|--verbose]\n" "\tLogFilePath\n", full_ARG, stdin_ARG) @@ -185,14 +182,14 @@ xx(lvmsar, xx(lvreduce, "Reduce the size of a logical volume", "lvreduce\n" - "\t[-A/--autobackup y/n]\n" - "\t[-d/--debug]\n" - "\t[-f/--force]\n" - "\t[-h/--help]\n" - "\t{-l/--extents [-]LogicalExtentsNumber |\n" - "\t -L/--size [-]LogicalVolumeSize[kKmMgGtT]}\n" - "\t[-t/--test]\n" - "\t[-v/--verbose]\n" + "\t[-A|--autobackup y|n]\n" + "\t[-d|--debug]\n" + "\t[-f|--force]\n" + "\t[-h|--help]\n" + "\t{-l|--extents [-]LogicalExtentsNumber |\n" + "\t -L|--size [-]LogicalVolumeSize[kKmMgGtT]}\n" + "\t[-t|--test]\n" + "\t[-v|--verbose]\n" "\tLogicalVolume[Path]\n", autobackup_ARG, force_ARG, extents_ARG, @@ -201,12 +198,12 @@ xx(lvreduce, xx(lvremove, "Remove logical volume(s) from the system", "lvremove\n" - "\t[-A/--autobackup y/n]\n" - "\t[-d/--debug]\n" - "\t[-f/--force]\n" - "\t[-h/--help]\n" - "\t[-t/--test]\n" - "\t[-v/--verbose]\n" + "\t[-A|--autobackup y|n]\n" + "\t[-d|--debug]\n" + "\t[-f|--force]\n" + "\t[-h|--help]\n" + "\t[-t|--test]\n" + "\t[-v|--verbose]\n" "\tLogicalVolume[Path] [LogicalVolume[Path]...]\n", autobackup_ARG, force_ARG, test_ARG) @@ -216,7 +213,7 @@ xx(lvrename, "lvrename " "\t[-A|--autobackup {y|n}] " "\n" "\t[-d|--debug] " "\n" - "\t[-h|--help] " "\n" + "\t[-h|-?|--help] " "\n" "\t[-t|--test] " "\n" "\t[-v|--verbose]" "\n" "\t[--version] " "\n" @@ -228,14 +225,14 @@ xx(lvrename, xx(lvresize, "Resize a logical volume", "lvresize\n" - "\t[-A/--autobackup y/n]\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" + "\t[-A|--autobackup y|n]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" "\t[-i|--stripes Stripes [-I|--stripesize StripeSize]]\n" - "\t{-l/--extents [+/-]LogicalExtentsNumber |\n" - "\t -L/--size [+/-]LogicalVolumeSize[kKmMgGtT]}\n" + "\t{-l|--extents [+|-]LogicalExtentsNumber |\n" + "\t -L|--size [+|-]LogicalVolumeSize[kKmMgGtT]}\n" "\t[-t|--test]\n" - "\t[-v/--verbose]\n" + "\t[-v|--verbose]\n" "\tLogicalVolume[Path] [ PhysicalVolumePath... ]\n", autobackup_ARG, extents_ARG, size_ARG, stripes_ARG, stripesize_ARG, @@ -246,7 +243,7 @@ xx(lvscan, "lvscan " "\n" "\t[-b|--blockdevice] " "\n" "\t[-d|--debug] " "\n" - "\t[-h|--help] " "\n" + "\t[-h|-?|--help] " "\n" "\t[--ignorelockingfailure]\n" "\t[-P|--partial] " "\n" "\t[-v|--verbose] " "\n" @@ -257,13 +254,13 @@ xx(lvscan, xx(pvchange, "Change attributes of physical volume(s)", "pvchange\n" - "\t[-A/--autobackup y/n]\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" - "\t[-v/--verbose]\n" - "\t[-a/--all]\n" + "\t[-A|--autobackup y|n]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" + "\t[-v|--verbose]\n" + "\t[-a|--all]\n" "\t[-t|--test]\n" - "\t[-x/--allocatable y/n]\n" + "\t[-x|--allocatable y|n]\n" "\t[PhysicalVolumePath...]\n", all_ARG, allocatable_ARG, allocation_ARG, autobackup_ARG, test_ARG) @@ -274,7 +271,7 @@ xx(pvcreate, "\t[--restorefile file]\n" "\t[-d|--debug]" "\n" "\t[-f[f]|--force [--force]] " "\n" - "\t[-h|--help] " "\n" + "\t[-h|-?|--help] " "\n" "\t[--labelsector sector] " "\n" "\t[-M|--metadatatype 1|2]" "\n" "\t[--metadatacopies #copies]" "\n" @@ -297,7 +294,7 @@ xx(pvdata, "\t[-a|--all] " "\n" "\t[-d|--debug] " "\n" "\t[-E|--physicalextent] " "\n" - "\t[-h|--help]" "\n" + "\t[-h|-?|--help]" "\n" "\t[-L|--logicalvolume] " "\n" "\t[-P[P]|--physicalvolume [--physicalvolume]]" "\n" "\t[-U|--uuidlist] " "\n" @@ -312,13 +309,13 @@ xx(pvdata, xx(pvdisplay, "Display various attributes of logical volume(s)", "pvdisplay\n" - "\t[-c/--colon]\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" + "\t[-c|--colon]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" "\t[--ignorelockingfailure]\n" - "\t[-m/--maps]\n" - "\t[-s/--short]\n" - "\t[-v/--verbose]\n" + "\t[-m|--maps]\n" + "\t[-s|--short]\n" + "\t[-v|--verbose]\n" "\tPhysicalVolumePath [PhysicalVolumePath...]\n", colon_ARG, ignorelockingfailure_ARG, maps_ARG, short_ARG) @@ -329,7 +326,7 @@ xx(pvmove, "[-A|--autobackup {y|n}] " "[-d|--debug] " "[-f|--force]" - "[-h|--help]\n\t" + "[-h|-?|--help]\n\t" "[-t|--test] " "[-v|--verbose] " "[--version]\n\t" @@ -344,7 +341,7 @@ xx(pvremove, "pvremove " "\n" "\t[-d|--debug]" "\n" "\t[-f[f]|--force [--force]] " "\n" - "\t[-h|--help] " "\n" + "\t[-h|-?|--help] " "\n" "\t[-y|--yes]" "\n" "\t[-t|--test] " "\n" "\t[-v|--verbose] " "\n" @@ -361,7 +358,7 @@ xx(pvresize, "pvresize " "[-A|--autobackup {y|n}] " "[-d|--debug] " - "[-h|--help]\n\t" + "[-h|-?|--help]\n\t" "[-s|--size PhysicalVolumeSize[kKmMgGtT]" "\n" "[-v|--verbose] " "[--version]\n\t" @@ -373,8 +370,8 @@ xx(pvscan, "List all physical volumes", "pvscan " "\n" "\t[-d|--debug] " "\n" - "\t{-e|--exported | -n/--novolumegroup} " "\n" - "\t[-h|--help]" "\n" + "\t{-e|--exported | -n|--novolumegroup} " "\n" + "\t[-h|-?|--help]" "\n" "\t[--ignorelockingfailure]\n" "\t[-P|--partial] " "\n" "\t[-s|--short] " "\n" @@ -390,7 +387,7 @@ xx(vgcfgbackup, "vgcfgbackup " "\n" "\t[-d|--debug] " "\n" "\t[-f|--file filename] " "\n" - "\t[-h|--help] " "\n" + "\t[-h|-?|--help] " "\n" "\t[--ignorelockingfailure]\n" "\t[-P|--partial] " "\n" "\t[-v|--verbose]" "\n" @@ -431,15 +428,15 @@ xx(vgchange, "\t -l|--logicalvolume MaxLogicalVolumes}" "\n" "\t[VolumeGroupName...]\n", - autobackup_ARG, available_ARG, ignorelockingfailure_ARG, logicalvolume_ARG, - partial_ARG, resizeable_ARG, resizable_ARG, allocation_ARG, test_ARG) + allocation_ARG, autobackup_ARG, available_ARG, ignorelockingfailure_ARG, + logicalvolume_ARG, partial_ARG, resizeable_ARG, resizable_ARG, test_ARG) xx(vgck, "Check the consistency of volume group(s)", "vgck " - "\t[-d/--debug]\n" - "\t[-h/--help]\n" - "\t[-v/--verbose]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" + "\t[-v|--verbose]\n" "\t[VolumeGroupName...]\n" ) xx(vgconvert, @@ -507,11 +504,11 @@ xx(vgexport, xx(vgextend, "Add physical volumes to a volume group", "vgextend\n" - "\t[-A/--autobackup y/n]\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" - "\t[-t/--test]\n" - "\t[-v/--verbose]\n" + "\t[-A|--autobackup y|n]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" + "\t[-t|--test]\n" + "\t[-v|--verbose]\n" "\tVolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]\n", autobackup_ARG, test_ARG) @@ -519,7 +516,7 @@ xx(vgextend, xx(vgimport, "Register exported volume group with system", "vgimport " "\n" - "\t[-a/--all]\n" + "\t[-a|--all]\n" "\t[-d|--debug] " "\n" "\t[-f|--force] " "\n" "\t[-h|--help] " "\n" @@ -532,12 +529,12 @@ xx(vgimport, xx(vgmerge, "Merge volume groups", "vgmerge\n" - "\t[-A/--autobackup y/n]\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" - "\t[-l/--list]\n" - "\t[-t/--test]\n" - "\t[-v/--verbose]\n" + "\t[-A|--autobackup y|n]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" + "\t[-l|--list]\n" + "\t[-t|--test]\n" + "\t[-v|--verbose]\n" "\tDestinationVolumeGroupName SourceVolumeGroupName\n", autobackup_ARG, list_ARG, test_ARG) @@ -545,20 +542,20 @@ xx(vgmerge, xx(vgmknodes, "Create the special files for volume group devices in /dev", "vgmknodes\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" - "\t[-v/--verbose]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" + "\t[-v|--verbose]\n" "\t[VolumeGroupName...]\n" ) xx(vgreduce, "Remove physical volume(s) from a volume group", "vgreduce\n" - "\t[-a/--all]\n" - "\t[-A/--autobackup y/n]\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" - "\t[-t/--test]\n" - "\t[-v/--verbose]\n" + "\t[-a|--all]\n" + "\t[-A|--autobackup y|n]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" + "\t[-t|--test]\n" + "\t[-v|--verbose]\n" "\tVolumeGroupName\n" "\t[PhysicalVolumePath...]\n", @@ -567,10 +564,10 @@ xx(vgreduce, xx(vgremove, "Remove volume group(s)", "vgremove\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" - "\t[-t/--test]\n" - "\t[-v/--verbose]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" + "\t[-t|--test]\n" + "\t[-v|--verbose]\n" "\tVolumeGroupName [VolumeGroupName...]\n", test_ARG) @@ -578,11 +575,11 @@ xx(vgremove, xx(vgrename, "Rename a volume group", "vgrename\n" - "\t[-A/--autobackup y/n]\n" - "\t[-d/--debug]\n" - "\t[-h/--help]\n" - "\t[-t/--test]\n" - "\t[-v/--verbose]\n" + "\t[-A|--autobackup y|n]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" + "\t[-t|--test]\n" + "\t[-v|--verbose]\n" "\tOldVolumeGroupPath NewVolumeGroupPath |\n" "\tOldVolumeGroupName NewVolumeGroupName\n", @@ -591,11 +588,11 @@ xx(vgrename, xx(vgscan, "Search for all volume groups", "vgscan " - "\t[-d/--debug]\n" - "\t[-h/--help]\n" + "\t[-d|--debug]\n" + "\t[-h|--help]\n" "\t[--ignorelockingfailure]\n" - "\t[-P/--partial] " "\n" - "\t[-v/--verbose]\n" , + "\t[-P|--partial] " "\n" + "\t[-v|--verbose]\n" , ignorelockingfailure_ARG, partial_ARG) diff --git a/tools/lvm.c b/tools/lvm.c index 526c1847a..baa7c9795 100644 --- a/tools/lvm.c +++ b/tools/lvm.c @@ -305,7 +305,7 @@ static void _register_commands() { #define xx(a, b, c...) _register_command(# a, a, b, ## c, \ driverloaded_ARG, \ - debug_ARG, help_ARG, \ + debug_ARG, help_ARG, help2_ARG, \ version_ARG, verbose_ARG, \ quiet_ARG, -1); #include "commands.h" @@ -543,7 +543,7 @@ static int _get_settings(struct cmd_context *cmd) static int _process_common_commands(struct cmd_context *cmd) { - if (arg_count(cmd, help_ARG)) { + if (arg_count(cmd, help_ARG) || arg_count(cmd, help2_ARG)) { usage(cmd->command->name); return ECMD_PROCESSED; } @@ -959,7 +959,7 @@ static char *_list_args(const char *text, int state) char *l; l = (the_args + com->valid_args[match_no++ - com->num_args])->long_arg; - if (!strncmp(text, l, len)) + if (*(l + 2) && !strncmp(text, l, len)) return strdup(l); } diff --git a/tools/lvmdiskscan.c b/tools/lvmdiskscan.c index adc122e18..a6edfa6bf 100644 --- a/tools/lvmdiskscan.c +++ b/tools/lvmdiskscan.c @@ -13,17 +13,81 @@ #include "tools.h" -int _get_max_dev_name_len(struct dev_filter *filter); -void _count(struct device *, int *, int *); -void _print(struct device *, uint64_t, char *); -int _check_device(struct device *); - int disks_found = 0; int parts_found = 0; int pv_disks_found = 0; int pv_parts_found = 0; int max_len; +static int _get_max_dev_name_len(struct dev_filter *filter) +{ + int len = 0; + int max_len = 0; + struct dev_iter *iter; + struct device *dev; + + if (!(iter = dev_iter_create(filter))) { + log_error("dev_iter_create failed"); + return 0; + } + + /* Do scan */ + for (dev = dev_iter_get(iter); dev; dev = dev_iter_get(iter)) { + len = strlen(dev_name(dev)); + if (len > max_len) + max_len = len; + } + dev_iter_destroy(iter); + + return max_len; +} + +static void _count(struct device *dev, int *disks, int *parts) +{ + int c = dev_name(dev)[strlen(dev_name(dev)) - 1]; + + if (!isdigit(c)) + (*disks)++; + else + (*parts)++; +} + +static void _print(struct device *dev, uint64_t size, char *what) +{ + char *dummy = display_size(size / 2, SIZE_SHORT); + const char *name = dev_name(dev); + + if (!what) + what = ""; + + log_print("%-*s [%15s] %s", max_len, name, dummy, what); + dbg_free(dummy); +} + +static int _check_device(struct device *dev) +{ + char buffer; + uint64_t size; + + if (!dev_open(dev, 0)) { + return 0; + } + if (dev_read(dev, 0, 1, &buffer) != 1) { + dev_close(dev); + return 0; + } + if (!dev_get_size(dev, &size)) { + log_error("Couldn't get size of \"%s\"", dev_name(dev)); + } + _print(dev, size, NULL); + _count(dev, &disks_found, &parts_found); + if (!dev_close(dev)) { + log_error("dev_close on \"%s\" failed", dev_name(dev)); + return 0; + } + return 1; +} + int lvmdiskscan(struct cmd_context *cmd, int argc, char **argv) { uint64_t size; @@ -78,72 +142,3 @@ int lvmdiskscan(struct cmd_context *cmd, int argc, char **argv) return 0; } - -int _check_device(struct device *dev) -{ - char buffer; - uint64_t size; - - if (!dev_open(dev, 0)) { - return 0; - } - if (dev_read(dev, 0, 1, &buffer) != 1) { - dev_close(dev); - return 0; - } - if (!dev_get_size(dev, &size)) { - log_error("Couldn't get size of \"%s\"", dev_name(dev)); - } - _print(dev, size, NULL); - _count(dev, &disks_found, &parts_found); - if (!dev_close(dev)) { - log_error("dev_close on \"%s\" failed", dev_name(dev)); - return 0; - } - return 1; -} - -int _get_max_dev_name_len(struct dev_filter *filter) -{ - int len = 0; - int max_len = 0; - struct dev_iter *iter; - struct device *dev; - - if (!(iter = dev_iter_create(filter))) { - log_error("dev_iter_create failed"); - return 0; - } - - /* Do scan */ - for (dev = dev_iter_get(iter); dev; dev = dev_iter_get(iter)) { - len = strlen(dev_name(dev)); - if (len > max_len) - max_len = len; - } - dev_iter_destroy(iter); - - return max_len; -} - -void _count(struct device *dev, int *disks, int *parts) -{ - int c = dev_name(dev)[strlen(dev_name(dev)) - 1]; - - if (!isdigit(c)) - (*disks)++; - else - (*parts)++; -} - -void _print(struct device *dev, uint64_t size, char *what) -{ - char *dummy = display_size(size / 2, SIZE_SHORT); - const char *name = dev_name(dev); - - if (!what) - what = ""; - - log_print("%-*s [%15s] %s", max_len, name, dummy, what); - dbg_free(dummy); -}