diff options
author | Karel Zak | 2014-08-13 21:21:46 +0200 |
---|---|---|
committer | Karel Zak | 2014-08-13 21:21:46 +0200 |
commit | 14620822c031f17823b546d2e59e60c3cd247748 (patch) | |
tree | 2b95e5abeb3612ba8dbe627485c39c72e3f79c91 /disk-utils/cfdisk.c | |
parent | tests: add debug tests (diff) | |
download | kernel-qcow2-util-linux-14620822c031f17823b546d2e59e60c3cd247748.tar.gz kernel-qcow2-util-linux-14620822c031f17823b546d2e59e60c3cd247748.tar.xz kernel-qcow2-util-linux-14620822c031f17823b546d2e59e60c3cd247748.zip |
cfdisk: add libfdisk independent debug stuff
Now it's possible to use
CFDISK_DEBUG=0xffff ./cfdisk
to debug only cfdisk UI.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/cfdisk.c')
-rw-r--r-- | disk-utils/cfdisk.c | 88 |
1 files changed, 55 insertions, 33 deletions
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index 93331ebd7..144479857 100644 --- a/disk-utils/cfdisk.c +++ b/disk-utils/cfdisk.c @@ -179,6 +179,28 @@ struct cfdisk { zero_start :1; /* ignore existing partition table */ }; + +/* + * let's use include/debug.h stuff for cfdisk too + */ +UL_DEBUG_DEFINE_MASK(cfdisk); +UL_DEBUG_DEFINE_MASKANEMS(cfdisk) = UL_DEBUG_EMPTY_MASKNAMES; + +#define CFDISK_DEBUG_INIT (1 << 1) +#define CFDISK_DEBUG_UI (1 << 2) +#define CFDISK_DEBUG_MENU (1 << 3) +#define CFDISK_DEBUG_MISC (1 << 4) +#define CFDISK_DEBUG_TABLE (1 << 5) +#define CFDISK_DEBUG_ALL 0xFFFF + +#undef DBG /* temporary to avoid collision with fdiskP.h */ +#define DBG(m, x) __UL_DBG(cfdisk, CFDISK_DEBUG_, m, x) + +static void cfdisk_init_debug(void) +{ + __UL_INIT_DEBUG(cfdisk, CFDISK_DEBUG_, 0, CFDISK_DEBUG); +} + /* Initialize output columns -- we follow libfdisk fields (usually specific * to the label type. */ @@ -208,7 +230,7 @@ static void resize(void) } touchwin(stdscr); - DBG(FRONTEND, ul_debug("ui: resize refresh COLS=%d, LINES=%d", COLS, LINES)); + DBG(UI, ul_debug("ui: resize refresh COLS=%d, LINES=%d", COLS, LINES)); ui_resize = 0; } @@ -247,7 +269,7 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb) int tree = 0; struct libscols_line *ln, *ln_cont = NULL; - DBG(FRONTEND, ul_debug("table: convert to string")); + DBG(TABLE, ul_debug("convert to string")); assert(cf); assert(cf->cxt); @@ -264,7 +286,7 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb) /* get container (e.g. extended partition) */ while (fdisk_table_next_partition(tb, itr, &pa) == 0) { if (fdisk_partition_is_nested(pa)) { - DBG(FRONTEND, ul_debug("table: nested detected, using tree")); + DBG(TABLE, ul_debug("nested detected, using tree")); tree = SCOLS_FL_TREE; break; } @@ -365,7 +387,7 @@ static int lines_refresh(struct cfdisk *cf) assert(cf); - DBG(FRONTEND, ul_debug("refreshing buffer")); + DBG(TABLE, ul_debug("refreshing buffer")); free(cf->linesbuf); free(cf->lines); @@ -664,14 +686,14 @@ static void ui_clean_hint(void) static void die_on_signal(int dummy __attribute__((__unused__))) { - DBG(FRONTEND, ul_debug("die on signal.")); + DBG(MISC, ul_debug("die on signal.")); ui_end(); exit(EXIT_FAILURE); } static void resize_on_signal(int dummy __attribute__((__unused__))) { - DBG(FRONTEND, ul_debug("resize on signal.")); + DBG(MISC, ul_debug("resize on signal.")); ui_resize = 1; } @@ -696,7 +718,7 @@ static void menu_update_ignore(struct cfdisk *cf) m = cf->menu; org = menu_get_menuitem(cf, m->idx); - DBG(FRONTEND, ul_debug("menu: update menu ignored keys")); + DBG(MENU, ul_debug("update menu ignored keys")); i = m->ignore_cb(cf, ignore, sizeof(ignore)); ignore[i] = '\0'; @@ -735,7 +757,7 @@ static struct cfdisk_menu *menu_push( assert(cf); - DBG(FRONTEND, ul_debug("menu: new menu")); + DBG(MENU, ul_debug("new menu")); m->prev = cf->menu; m->items = items; @@ -759,7 +781,7 @@ static struct cfdisk_menu *menu_pop(struct cfdisk *cf) assert(cf); - DBG(FRONTEND, ul_debug("menu: rem menu")); + DBG(MENU, ul_debug("pop menu")); if (cf->menu) { m = cf->menu->prev; @@ -789,7 +811,7 @@ static int ui_init(struct cfdisk *cf __attribute__((__unused__))) { struct sigaction sa; - DBG(FRONTEND, ul_debug("ui: init")); + DBG(UI, ul_debug("init")); /* setup SIGCHLD handler */ sigemptyset(&sa.sa_mask); @@ -930,7 +952,7 @@ static void ui_draw_menuitem(struct cfdisk *cf, vert ? MBS_ALIGN_LEFT : MBS_ALIGN_CENTER, 0); - DBG(FRONTEND, ul_debug("ui: menuitem: cl=%d, ln=%d, item='%s'", + DBG(MENU, ul_debug("menuitem: cl=%d, ln=%d, item='%s'", cl, ln, buf)); if (vert) { @@ -982,7 +1004,7 @@ static void ui_draw_menu(struct cfdisk *cf) assert(cf); assert(cf->menu); - DBG(FRONTEND, ul_debug("ui: menu: draw start")); + DBG(MENU, ul_debug("draw start")); ui_clean_menu(cf); m = cf->menu; @@ -1033,7 +1055,7 @@ static void ui_draw_menu(struct cfdisk *cf) mvaddch(ln + nlines, cl + m->width + 3, ACS_DARROW); } - DBG(FRONTEND, ul_debug("ui: menu: draw end.")); + DBG(MENU, ul_debug("draw end.")); } static void ui_menu_goto(struct cfdisk *cf, int where) @@ -1086,7 +1108,7 @@ static int ui_menu_move(struct cfdisk *cf, int key) m = cf->menu; - DBG(FRONTEND, ul_debug("ui: menu move key >%c<.", key)); + DBG(MENU, ul_debug("menu move key >%c<.", key)); if (m->vertical) { @@ -1170,8 +1192,8 @@ static void ui_draw_partition(struct cfdisk *cf, size_t i) curpg = cf->lines_idx / cf->page_sz; } - DBG(FRONTEND, ul_debug( - "ui: draw partition %zu [page_sz=%zu, " + DBG(UI, ul_debug( + "draw partition %zu [page_sz=%zu, " "line=%d, idx=%zu]", i, cf->page_sz, ln, cf->lines_idx)); @@ -1210,7 +1232,7 @@ static int ui_draw_table(struct cfdisk *cf) size_t i, nparts = fdisk_table_get_nents(cf->table); size_t curpg = cf->page_sz ? cf->lines_idx / cf->page_sz : 0; - DBG(FRONTEND, ul_debug("ui: draw table")); + DBG(UI, ul_debug("draw table")); for (i = TABLE_START_LINE; i <= TABLE_START_LINE + cf->page_sz; i++) { move(i, 0); @@ -1245,7 +1267,7 @@ static int ui_table_goto(struct cfdisk *cf, int where) size_t old; size_t nparts = fdisk_table_get_nents(cf->table); - DBG(FRONTEND, ul_debug("ui: goto table %d", where)); + DBG(UI, ul_debug("goto table %d", where)); if (where < 0) where = 0; @@ -1423,7 +1445,7 @@ static int ui_get_size(struct cfdisk *cf, const char *prompt, uintmax_t *res, ssize_t rc; char *dflt = size_to_human_string(0, *res); - DBG(FRONTEND, ul_debug("ui: get_size (default=%ju)", *res)); + DBG(UI, ul_debug("get_size (default=%ju)", *res)); ui_clean_info(); @@ -1453,7 +1475,7 @@ static int ui_get_size(struct cfdisk *cf, const char *prompt, uintmax_t *res, } if (rc == 0) { - DBG(FRONTEND, ul_debug("ui: get_size user=%ju, power=%d, sectors=%s", + DBG(UI, ul_debug("get_size user=%ju, power=%d, sectors=%s", user, pwr, insec ? "yes" : "no")); if (insec) user *= cf->cxt->sector_size; @@ -1478,7 +1500,7 @@ static int ui_get_size(struct cfdisk *cf, const char *prompt, uintmax_t *res, *res = user; free(dflt); - DBG(FRONTEND, ul_debug("ui: get_size (result=%ju, rc=%zd)", *res, rc)); + DBG(UI, ul_debug("get_size (result=%ju, rc=%zd)", *res, rc)); return rc; } @@ -1490,7 +1512,7 @@ static struct fdisk_parttype *ui_get_parttype(struct cfdisk *cf, struct fdisk_parttype *t = NULL; int has_typestr = 0; - DBG(FRONTEND, ul_debug("ui: asking for parttype.")); + DBG(UI, ul_debug("asking for parttype.")); /* create cfdisk menu according to label types, note that the * last cm[] item has to be empty -- so nitems + 1 */ @@ -1560,7 +1582,7 @@ done: free((char *) cm[i].name); } free(cm); - DBG(FRONTEND, ul_debug("ui: get parrtype done [type=%s] ", t ? t->name : NULL)); + DBG(UI, ul_debug("get parrtype done [type=%s] ", t ? t->name : NULL)); return t; } @@ -1574,7 +1596,7 @@ static int ui_create_label(struct cfdisk *cf) assert(cf); - DBG(FRONTEND, ul_debug("ui: asking for new disklabe.")); + DBG(UI, ul_debug("asking for new disklabe.")); /* create cfdisk menu according to libfdisk labels, note that the * last cm[] item has to be empty -- so nitems + 1 */ @@ -1625,7 +1647,7 @@ static int ui_create_label(struct cfdisk *cf) done: menu_pop(cf); free(cm); - DBG(FRONTEND, ul_debug("ui: create label done [rc=%d] ", rc)); + DBG(UI, ul_debug("create label done [rc=%d] ", rc)); return rc; } @@ -1726,17 +1748,17 @@ static int main_menu_action(struct cfdisk *cf, int key) } else if (key != 'w' && key != 'W') key = tolower(key); /* case insensitive except 'W'rite */ - DBG(FRONTEND, ul_debug("ui: main menu action: key=%c", key)); + DBG(MENU, ul_debug("main menu action: key=%c", key)); if (cf->menu->ignore && strchr(cf->menu->ignore, key)) { - DBG(FRONTEND, ul_debug(" ignore '%c'", key)); + DBG(MENU, ul_debug(" ignore '%c'", key)); return 0; } pa = get_current_partition(cf); n = fdisk_partition_get_partno(pa); - DBG(FRONTEND, ul_debug("menu action on %p", pa)); + DBG(MENU, ul_debug("menu action on %p", pa)); ui_clean_hint(); ui_clean_info(); @@ -1886,7 +1908,7 @@ static int ui_run(struct cfdisk *cf) { int rc = 0; - DBG(FRONTEND, ul_debug("ui: start COLS=%d, LINES=%d", COLS, LINES)); + DBG(UI, ul_debug("start COLS=%d, LINES=%d", COLS, LINES)); if (!fdisk_dev_has_disklabel(cf->cxt) || cf->zero_start) { rc = ui_create_label(cf); @@ -1924,7 +1946,7 @@ static int ui_run(struct cfdisk *cf) if (ui_menu_move(cf, key) == 0) continue; - DBG(FRONTEND, ul_debug("ui: main action key >%c<.", key)); + DBG(UI, ul_debug("main action key >%c<.", key)); switch (key) { case KEY_DOWN: @@ -1971,7 +1993,7 @@ static int ui_run(struct cfdisk *cf) menu_pop(cf); - DBG(FRONTEND, ul_debug("ui: end")); + DBG(UI, ul_debug("end")); return 0; } @@ -2039,7 +2061,7 @@ int main(int argc, char *argv[]) fdisk_init_debug(0); scols_init_debug(0); - + cfdisk_init_debug(); cf->cxt = fdisk_new_context(); if (!cf->cxt) err(EXIT_FAILURE, _("failed to allocate libfdisk context")); @@ -2070,6 +2092,6 @@ int main(int argc, char *argv[]) rc = fdisk_context_deassign_device(cf->cxt, cf->nwrites == 0); fdisk_free_context(cf->cxt); - DBG(FRONTEND, ul_debug("bye! [rc=%d]", rc)); + DBG(MISC, ul_debug("bye! [rc=%d]", rc)); return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } |