#include "closestream.h"
#include "blkdev.h"
-static const char * type_text[] = {
+static const char *type_text[] = {
"RESERVED",
"CONVENTIONAL",
"SEQ_WRITE_REQUIRED",
"SEQ_WRITE_PREFERRED",
};
-#define ARRAY_COUNT(x) (sizeof((x))/sizeof((*x)))
-
-const char * condition_str[] = {
+static const char *condition_str[] = {
"cv", /* conventional zone */
"e0", /* empty */
"Oi", /* open implicit */
"ro", /* read only */
"fu", /* full */
"OL" /* offline */
- };
-
-static const char * zone_condition_str(uint8_t cond)
-{
- return condition_str[cond & 0x0f];
-}
+};
-static void print_zones(struct blk_zone *info, uint32_t count)
+static void print_zones(const struct blk_zone *info, const uint32_t count)
{
uint32_t iter;
printf(_("Zones returned: %u\n"), count);
- for (iter = 0; iter < count; iter++ ) {
- struct blk_zone * entry = &info[iter];
- unsigned int type = entry->type;
+ for (iter = 0; iter < count; iter++) {
+ const struct blk_zone *entry = &info[iter];
+ unsigned int type = entry->type;
uint64_t start = entry->start;
uint64_t wp = entry->wp;
uint8_t cond = entry->cond;
" reset:%u non-seq:%u, zcond:%2u(%s) [type: %u(%s)]\n"),
start, len, wp - start,
entry->reset, entry->non_seq,
- cond, zone_condition_str(cond),
+ cond, condition_str[cond & ARRAY_SIZE(condition_str)],
type, type_text[type]);
}
}
-static int do_report(int fd, uint64_t lba, uint32_t len, int verbose)
+static int do_report(const int fd, const uint64_t lba, uint32_t len, const int verbose)
{
- int rc = -4;
+ int rc;
struct blk_zone_report *zi;
zi = xmalloc(sizeof(struct blk_zone_report) + (len * sizeof(struct blk_zone)));
if (verbose)
printf(_("Found %d zones\n"), zi->nr_zones);
print_zones(zi->zones, zi->nr_zones);
- } else {
- warn(_("ERR: %d -> %s"), errno, strerror(errno));
}
free(zi);
uint64_t offset = 0ul;
uint32_t length = DEF_REPORT_LEN;
static const struct option longopts[] = {
- { "help", 0, 0, 'h' },
- { "version", 0, 0, 'V' },
- { "zone", 1, 0, 'z' }, /* starting LBA */
- { "count", 1, 0, 'c' }, /* max #of zones (entries) for result */
- { "verbose", 0, 0, 'v' },
- { NULL, 0, 0, 0 }
+ { "help", no_argument, NULL, 'h' },
+ { "version", no_argument, NULL, 'V' },
+ { "zone", required_argument, NULL, 'z' }, /* starting LBA */
+ { "count", required_argument, NULL, 'c' }, /* max #of zones (entries) for result */
+ { "verbose", no_argument, NULL, 'v' },
+ { NULL, 0, NULL, 0 }
};
setlocale(LC_ALL, "");
atexit(close_stdout);
while ((c = getopt_long(argc, argv, "hc:z:vV", longopts, NULL)) != -1) {
- switch(c) {
+ switch (c) {
case 'h':
usage(stdout);
break;
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
-
int main(int argc, char **argv)
{
char *path;
struct stat sb;
struct blk_zone_range za;
uint64_t zsector = 0;
- uint64_t zlen = 0;
+ uint64_t zlen;
uint64_t zcount = 1;
unsigned long zsize;
- int rc = 0;
+ int rc;
static const struct option longopts[] = {
- { "help", 0, 0, 'h' },
- { "version", 0, 0, 'V' },
- { "zone", 1, 0, 'z' },
- { "count", 1, 0, 'c' },
- { NULL, 0, 0, 0 }
+ { "help", no_argument, NULL, 'h' },
+ { "version", no_argument, NULL, 'V' },
+ { "zone", required_argument, NULL, 'z' },
+ { "count", required_argument, NULL, 'c' },
+ { NULL, 0, NULL, 0 }
};
setlocale(LC_ALL, "");
atexit(close_stdout);
while ((c = getopt_long(argc, argv, "hVz:c:", longopts, NULL)) != -1) {
- switch(c) {
+ switch (c) {
case 'h':
usage(stdout);
break;