Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/bectl/bectl_list.c
Show First 20 Lines • Show All 286 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
print_headers(nvlist_t *props, struct printc *pc) | print_headers(nvlist_t *props, struct printc *pc) | ||||
{ | { | ||||
const char *chosen_be_header; | const char *chosen_be_header; | ||||
nvpair_t *cur; | nvpair_t *cur; | ||||
nvlist_t *dsprops; | nvlist_t *dsprops; | ||||
char *propstr; | char *propstr; | ||||
size_t be_maxcol; | size_t be_maxcol, mount_colsz; | ||||
if (pc->show_all_datasets || pc->show_snaps) | if (pc->show_all_datasets || pc->show_snaps) | ||||
chosen_be_header = HEADER_BEPLUS; | chosen_be_header = HEADER_BEPLUS; | ||||
else | else | ||||
chosen_be_header = HEADER_BE; | chosen_be_header = HEADER_BE; | ||||
be_maxcol = strlen(chosen_be_header); | be_maxcol = strlen(chosen_be_header); | ||||
mount_colsz = strlen(HEADER_MOUNT); | |||||
for (cur = nvlist_next_nvpair(props, NULL); cur != NULL; | for (cur = nvlist_next_nvpair(props, NULL); cur != NULL; | ||||
cur = nvlist_next_nvpair(props, cur)) { | cur = nvlist_next_nvpair(props, cur)) { | ||||
be_maxcol = MAX(be_maxcol, strlen(nvpair_name(cur))); | be_maxcol = MAX(be_maxcol, strlen(nvpair_name(cur))); | ||||
nvpair_value_nvlist(cur, &dsprops); | |||||
if (nvlist_lookup_string(dsprops, "mounted", &propstr) == 0) | |||||
mount_colsz = MAX(mount_colsz, strlen(propstr)); | |||||
if (!pc->show_all_datasets && !pc->show_snaps) | if (!pc->show_all_datasets && !pc->show_snaps) | ||||
continue; | continue; | ||||
nvpair_value_nvlist(cur, &dsprops); | |||||
if (nvlist_lookup_string(dsprops, "dataset", &propstr) != 0) | if (nvlist_lookup_string(dsprops, "dataset", &propstr) != 0) | ||||
continue; | continue; | ||||
be_maxcol = MAX(be_maxcol, strlen(propstr) + INDENT_INCREMENT); | be_maxcol = MAX(be_maxcol, strlen(propstr) + INDENT_INCREMENT); | ||||
if (nvlist_lookup_string(dsprops, "origin", &propstr) != 0) | if (nvlist_lookup_string(dsprops, "origin", &propstr) != 0) | ||||
continue; | continue; | ||||
be_maxcol = MAX(be_maxcol, | be_maxcol = MAX(be_maxcol, | ||||
strlen(propstr) + INDENT_INCREMENT * 2); | strlen(propstr) + INDENT_INCREMENT * 2); | ||||
} | } | ||||
pc->be_colsz = be_maxcol; | pc->be_colsz = be_maxcol; | ||||
pc->active_colsz_def = strlen(HEADER_ACTIVE); | pc->active_colsz_def = strlen(HEADER_ACTIVE); | ||||
pc->mount_colsz = strlen(HEADER_MOUNT); | pc->mount_colsz = mount_colsz; | ||||
pc->space_colsz = strlen(HEADER_SPACE); | pc->space_colsz = strlen(HEADER_SPACE); | ||||
printf("%*s %s %s %s %s\n", -pc->be_colsz, chosen_be_header, | printf("%*s %s %*s %s %s\n", -pc->be_colsz, chosen_be_header, | ||||
HEADER_ACTIVE, HEADER_MOUNT, HEADER_SPACE, HEADER_CREATED); | HEADER_ACTIVE, -pc->mount_colsz, HEADER_MOUNT, HEADER_SPACE, HEADER_CREATED); | ||||
/* | /* | ||||
* All other invocations in which we aren't using the default header | * All other invocations in which we aren't using the default header | ||||
* will produce quite a bit of input. Throw an extra blank line after | * will produce quite a bit of input. Throw an extra blank line after | ||||
* the header to make it look nicer. | * the header to make it look nicer. | ||||
*/ | */ | ||||
if (strcmp(chosen_be_header, HEADER_BE) != 0) | if (strcmp(chosen_be_header, HEADER_BE) != 0) | ||||
printf("\n"); | printf("\n"); | ||||
▲ Show 20 Lines • Show All 165 Lines • Show Last 20 Lines |