Index: sbin/nvmecontrol/devlist.c =================================================================== --- sbin/nvmecontrol/devlist.c +++ sbin/nvmecontrol/devlist.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include #include @@ -51,10 +53,27 @@ static cmd_fn_t devlist; +static struct options { + bool human; +} opt = { + .human = false, +}; + +static const struct opts devlist_opts[] = { +#define OPT(l, s, t, opt, addr, desc) { l, s, t, &opt.addr, desc } + OPT("human", 'h', arg_none, opt, human, + "Show human readable disk size"), + { NULL, 0, arg_none, NULL, NULL } +}; +#undef OPT + static struct cmd devlist_cmd = { .name = "devlist", .fn = devlist, - .descr = "List NVMe controllers and namespaces" + .descr = "List NVMe controllers and namespaces", + .ctx_size = sizeof(opt), + .opts = devlist_opts, + .args = NULL, }; CMD_COMMAND(devlist_cmd); @@ -81,7 +100,9 @@ struct nvme_namespace_data nsdata; char name[64]; uint8_t mn[64]; + uint8_t buf[6]; uint32_t i; + uint64_t size; int ctrlr, fd, found, ret; if (arg_parse(argc, argv, f)) @@ -115,11 +136,15 @@ continue; sprintf(name, "%s%d%s%d", NVME_CTRLR_PREFIX, ctrlr, NVME_NS_PREFIX, i + 1); - printf(" %10s (%lldMB)\n", - name, - nsdata.nsze * - (long long)ns_get_sector_size(&nsdata) / - 1024 / 1024); + size = nsdata.nsze * (uint64_t)ns_get_sector_size(&nsdata); + if (opt.human) { + humanize_number(buf, sizeof(buf), size, "", + HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); + printf(" %10s (%s)\n", name, buf); + + } else { + printf(" %10s (%luMB)\n", name, size / 1024 / 1024); + } } close(fd); Index: sbin/nvmecontrol/nvmecontrol.8 =================================================================== --- sbin/nvmecontrol/nvmecontrol.8 +++ sbin/nvmecontrol/nvmecontrol.8 @@ -44,6 +44,7 @@ .Sh SYNOPSIS .Nm .Ic devlist +.Op Fl h .Nm .Ic identify .Op Fl v @@ -209,6 +210,13 @@ .Sh DESCRIPTION NVM Express (NVMe) is a storage protocol standard, for SSDs and other high-speed storage devices over PCI Express. +.Ss devlist +List all NVMe controllers and namespaces along with their device nodes. +With the +.Fl h +argument, use unit suffixes: Byte, Kibibyte, Mebibyte, Gibibyte, Tebibyte +and Pebibyte (based on powers of 1024) when showing the disk space. +By default, uses Mebibyte. .Ss identify The identify commands reports information from the drive's .Dv IDENTIFY_CONTROLLER