bectl.c (9b1662e67b54e3a4ae04050beacc38645a003a8c) bectl.c (96c5db5854191eb7ff464c74ea677ee8016b3a9e)
1/*
2 * be.c
3 *
4 * Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 60 unchanged lines hidden (view full) ---

69static int bectl_cmd_create(int argc, char *argv[]);
70static int bectl_cmd_destroy(int argc, char *argv[]);
71static int bectl_cmd_export(int argc, char *argv[]);
72static int bectl_cmd_import(int argc, char *argv[]);
73static int bectl_cmd_add(int argc, char *argv[]);
74static int bectl_cmd_jail(int argc, char *argv[]);
75static const char *get_origin_props(nvlist_t *dsprops, nvlist_t **originprops);
76static void print_padding(const char *fval, int colsz, struct printc *pc);
1/*
2 * be.c
3 *
4 * Copyright (c) 2017 Kyle J. Kneitinger <kyle@kneit.in>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 60 unchanged lines hidden (view full) ---

69static int bectl_cmd_create(int argc, char *argv[]);
70static int bectl_cmd_destroy(int argc, char *argv[]);
71static int bectl_cmd_export(int argc, char *argv[]);
72static int bectl_cmd_import(int argc, char *argv[]);
73static int bectl_cmd_add(int argc, char *argv[]);
74static int bectl_cmd_jail(int argc, char *argv[]);
75static const char *get_origin_props(nvlist_t *dsprops, nvlist_t **originprops);
76static void print_padding(const char *fval, int colsz, struct printc *pc);
77static int print_snapshots(const char *dsname, struct printc *pc);
77static void print_info(const char *name, nvlist_t *dsprops, struct printc *pc);
78static void print_headers(nvlist_t *props, struct printc *pc);
79static int bectl_cmd_list(int argc, char *argv[]);
80static int bectl_cmd_mount(int argc, char *argv[]);
81static int bectl_cmd_rename(int argc, char *argv[]);
82static int bectl_search_jail_paths(const char *mnt);
83static int bectl_locate_jail(const char *ident);
84static int bectl_cmd_unjail(int argc, char *argv[]);

--- 415 unchanged lines hidden (view full) ---

500 if (nvlist_lookup_string(dsprops, "used", &propstr) == 0)
501 space = strtoull(propstr, NULL, 10);
502
503 nvlist_free(dsprops);
504 free(dsname);
505 return (space);
506}
507
78static void print_info(const char *name, nvlist_t *dsprops, struct printc *pc);
79static void print_headers(nvlist_t *props, struct printc *pc);
80static int bectl_cmd_list(int argc, char *argv[]);
81static int bectl_cmd_mount(int argc, char *argv[]);
82static int bectl_cmd_rename(int argc, char *argv[]);
83static int bectl_search_jail_paths(const char *mnt);
84static int bectl_locate_jail(const char *ident);
85static int bectl_cmd_unjail(int argc, char *argv[]);

--- 415 unchanged lines hidden (view full) ---

501 if (nvlist_lookup_string(dsprops, "used", &propstr) == 0)
502 space = strtoull(propstr, NULL, 10);
503
504 nvlist_free(dsprops);
505 free(dsname);
506 return (space);
507}
508
509static int
510print_snapshots(const char *dsname, struct printc *pc)
511{
512 nvpair_t *cur;
513 nvlist_t *props, *sprops;
514
515 if (be_prop_list_alloc(&props) != 0) {
516 fprintf(stderr, "bectl list: failed to allocate snapshot nvlist\n");
517 return (1);
518 }
519 if (be_get_dataset_snapshots(be, dsname, props) != 0) {
520 fprintf(stderr, "bectl list: failed to fetch boot ds snapshots\n");
521 return (1);
522 }
523 for (cur = nvlist_next_nvpair(props, NULL); cur != NULL;
524 cur = nvlist_next_nvpair(props, cur)) {
525 nvpair_value_nvlist(cur, &sprops);
526 print_info(nvpair_name(cur), sprops, pc);
527 }
528 return (0);
529}
530
508static void
509print_info(const char *name, nvlist_t *dsprops, struct printc *pc)
510{
511#define BUFSZ 64
512 char buf[BUFSZ];
513 unsigned long long ctimenum, space;
514 nvlist_t *originprops;
515 const char *oname;
531static void
532print_info(const char *name, nvlist_t *dsprops, struct printc *pc)
533{
534#define BUFSZ 64
535 char buf[BUFSZ];
536 unsigned long long ctimenum, space;
537 nvlist_t *originprops;
538 const char *oname;
516 char *propstr;
539 char *dsname, *propstr;
517 int active_colsz;
518 boolean_t active_now, active_reboot;
519
540 int active_colsz;
541 boolean_t active_now, active_reboot;
542
543 dsname = NULL;
520 originprops = NULL;
521 printf("%*s%s", pc->current_indent, "", name);
544 originprops = NULL;
545 printf("%*s%s", pc->current_indent, "", name);
546 nvlist_lookup_string(dsprops, "dataset", &dsname);
522
523 /* Recurse at the base level if we're breaking info down */
524 if (pc->current_indent == 0 && (pc->show_all_datasets ||
525 pc->show_snaps)) {
526 printf("\n");
547
548 /* Recurse at the base level if we're breaking info down */
549 if (pc->current_indent == 0 && (pc->show_all_datasets ||
550 pc->show_snaps)) {
551 printf("\n");
527 if (nvlist_lookup_string(dsprops, "dataset", &propstr) != 0)
552 if (dsname == NULL)
528 /* XXX TODO: Error? */
529 return;
530 pc->current_indent += INDENT_INCREMENT;
553 /* XXX TODO: Error? */
554 return;
555 pc->current_indent += INDENT_INCREMENT;
531 print_info(propstr, dsprops, pc);
556 print_info(dsname, dsprops, pc);
532 pc->current_indent += INDENT_INCREMENT;
533 if ((oname = get_origin_props(dsprops, &originprops)) != NULL) {
534 print_info(oname, originprops, pc);
535 nvlist_free(originprops);
536 }
557 pc->current_indent += INDENT_INCREMENT;
558 if ((oname = get_origin_props(dsprops, &originprops)) != NULL) {
559 print_info(oname, originprops, pc);
560 nvlist_free(originprops);
561 }
562
563 /* Back up a level; snapshots at the same level as dataset */
564 pc->current_indent -= INDENT_INCREMENT;
565 if (pc->show_snaps)
566 print_snapshots(dsname, pc);
537 pc->current_indent = 0;
538 return;
539 } else
540 print_padding(name, pc->be_colsz - pc->current_indent, pc);
541
542 active_colsz = pc->active_colsz_def;
543 if (nvlist_lookup_boolean_value(dsprops, "active",
544 &active_now) == 0 && active_now) {

--- 43 unchanged lines hidden (view full) ---

588 if (nvlist_lookup_string(dsprops, "creation", &propstr) == 0) {
589 ctimenum = strtoull(propstr, NULL, 10);
590 strftime(buf, BUFSZ, "%Y-%m-%d %H:%M",
591 localtime((time_t *)&ctimenum));
592 printf("%s", buf);
593 }
594
595 printf("\n");
567 pc->current_indent = 0;
568 return;
569 } else
570 print_padding(name, pc->be_colsz - pc->current_indent, pc);
571
572 active_colsz = pc->active_colsz_def;
573 if (nvlist_lookup_boolean_value(dsprops, "active",
574 &active_now) == 0 && active_now) {

--- 43 unchanged lines hidden (view full) ---

618 if (nvlist_lookup_string(dsprops, "creation", &propstr) == 0) {
619 ctimenum = strtoull(propstr, NULL, 10);
620 strftime(buf, BUFSZ, "%Y-%m-%d %H:%M",
621 localtime((time_t *)&ctimenum));
622 printf("%s", buf);
623 }
624
625 printf("\n");
596 if (originprops != NULL) {
597 /*if (pc->show_all_datasets) {
598 }*/
626 if (originprops != NULL)
599 be_prop_list_free(originprops);
627 be_prop_list_free(originprops);
600 }
601#undef BUFSZ
602}
603
604static void
605print_headers(nvlist_t *props, struct printc *pc)
606{
607 const char *chosen_be_header;
608 nvpair_t *cur;

--- 384 unchanged lines hidden ---
628#undef BUFSZ
629}
630
631static void
632print_headers(nvlist_t *props, struct printc *pc)
633{
634 const char *chosen_be_header;
635 nvpair_t *cur;

--- 384 unchanged lines hidden ---