fdisk: add independent debug stuff

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2014-08-15 12:38:02 +02:00
parent 2ae3d038b9
commit e6d0c4c1ac
3 changed files with 46 additions and 22 deletions

View File

@ -334,15 +334,15 @@ static int menu_detect_collisions(struct fdisk_context *cxt)
r = get_fdisk_menu_entry(cxt, e->key, NULL);
if (!r) {
DBG(FRONTEND, ul_debug("warning: not found "
DBG(MENU, ul_debug("warning: not found "
"entry for %c", e->key));
return -1;
}
if (r != e) {
DBG(FRONTEND, ul_debug("warning: duplicate key '%c'",
DBG(MENU, ul_debug("warning: duplicate key '%c'",
e->key));
DBG(FRONTEND, ul_debug(" : %s", e->title));
DBG(FRONTEND, ul_debug(" : %s", r->title));
DBG(MENU, ul_debug(" : %s", e->title));
DBG(MENU, ul_debug(" : %s", r->title));
abort();
}
}
@ -355,7 +355,7 @@ static int print_fdisk_menu(struct fdisk_context *cxt)
struct menu_context mc = MENU_CXT_EMPTY;
const struct menu_entry *e;
ON_DBG(FRONTEND, menu_detect_collisions(cxt));
ON_DBG(MENU, menu_detect_collisions(cxt));
if (fdisk_is_details(cxt))
printf(_("\nHelp (expert commands):\n"));
@ -427,18 +427,18 @@ int process_fdisk_menu(struct fdisk_context **cxt0)
}
rc = 0;
DBG(FRONTEND, ul_debug("selected: key=%c, entry='%s'",
DBG(MENU, ul_debug("selected: key=%c, entry='%s'",
key, ent->title));
/* menu has implemented callback, use it */
if (menu->callback)
rc = menu->callback(cxt0, menu, ent);
else {
DBG(FRONTEND, ul_debug("no callback for key '%c'", key));
DBG(MENU, ul_debug("no callback for key '%c'", key));
rc = -EINVAL;
}
DBG(FRONTEND, ul_debug("process menu done [rc=%d]", rc));
DBG(MENU, ul_debug("process menu done [rc=%d]", rc));
return rc;
}
@ -570,7 +570,7 @@ static int gpt_menu_cb(struct fdisk_context **cxt0,
assert(ent);
assert(fdisk_is_label(cxt, GPT));
DBG(FRONTEND, ul_debug("enter GPT menu"));
DBG(MENU, ul_debug("enter GPT menu"));
if (ent->expert) {
switch (ent->key) {
@ -628,7 +628,7 @@ static int dos_menu_cb(struct fdisk_context **cxt0,
struct fdisk_context *cxt = *cxt0;
int rc = 0;
DBG(FRONTEND, ul_debug("enter DOS menu"));
DBG(MENU, ul_debug("enter DOS menu"));
if (!ent->expert) {
switch (ent->key) {
@ -698,13 +698,13 @@ static int sun_menu_cb(struct fdisk_context **cxt0,
struct fdisk_context *cxt = *cxt0;
int rc = 0;
DBG(FRONTEND, ul_debug("enter SUN menu"));
DBG(MENU, ul_debug("enter SUN menu"));
assert(cxt);
assert(ent);
assert(fdisk_is_label(cxt, SUN));
DBG(FRONTEND, ul_debug("enter SUN menu"));
DBG(MENU, ul_debug("enter SUN menu"));
/* normal mode */
if (!ent->expert) {
@ -753,7 +753,7 @@ static int sgi_menu_cb(struct fdisk_context **cxt0,
int rc = -EINVAL;
size_t n = 0;
DBG(FRONTEND, ul_debug("enter SGI menu"));
DBG(MENU, ul_debug("enter SGI menu"));
assert(cxt);
assert(ent);
@ -799,7 +799,7 @@ static int bsd_menu_cb(struct fdisk_context **cxt0,
assert(ent);
assert(fdisk_is_label(cxt, BSD));
DBG(FRONTEND, ul_debug("enter BSD menu"));
DBG(MENU, ul_debug("enter BSD menu"));
switch(ent->key) {
case 'e':
@ -831,7 +831,7 @@ static int geo_menu_cb(struct fdisk_context **cxt0,
int rc = -EINVAL;
uintmax_t c = 0, h = 0, s = 0;
DBG(FRONTEND, ul_debug("enter GEO menu"));
DBG(MENU, ul_debug("enter GEO menu"));
assert(cxt);
assert(ent);
@ -863,7 +863,7 @@ static int createlabel_menu_cb(struct fdisk_context **cxt0,
struct fdisk_context *cxt = *cxt0;
int rc = -EINVAL;
DBG(FRONTEND, ul_debug("enter Create label menu"));
DBG(MENU, ul_debug("enter Create label menu"));
assert(cxt);
assert(ent);

View File

@ -46,7 +46,16 @@
# include <linux/blkpg.h>
#endif
/*
* fdisk debug stuff (see fdisk.h and include/debug.h)
*/
UL_DEBUG_DEFINE_MASK(fdisk);
UL_DEBUG_DEFINE_MASKANEMS(fdisk) = UL_DEBUG_EMPTY_MASKNAMES;
static void fdiskprog_init_debug(void)
{
__UL_INIT_DEBUG(fdisk, FDISKPROG_DEBUG_, 0, FDISK_DEBUG);
}
int get_user_reply(struct fdisk_context *cxt, const char *prompt,
char *buf, size_t bufsz)
@ -414,7 +423,7 @@ void list_partition_types(struct fdisk_context *cxt)
const struct fdisk_parttype *t = fdisk_label_get_parttype(lb, next);
size_t ret;
if (t->name) {
if (fdisk_parttype_get_name(t)) {
printf("%c%2x ", i ? ' ' : '\n',
fdisk_parttype_get_code(t));
ret = mbsalign(_(fdisk_parttype_get_name(t)),
@ -488,7 +497,7 @@ void change_partition_type(struct fdisk_context *cxt)
}
t = (struct fdisk_parttype *) fdisk_partition_get_type(pa);
old = t ? t->name : _("Unknown");
old = t ? fdisk_parttype_get_name(t) : _("Unknown");
do {
t = ask_partition_type(cxt);
@ -781,7 +790,7 @@ static void print_all_devices_pt(struct fdisk_context *cxt)
return;
}
DBG(FRONTEND, ul_debug("reading "_PATH_PROC_PARTITIONS));
DBG(MISC, ul_debug("reading "_PATH_PROC_PARTITIONS));
while (fgets(line, sizeof(line), f)) {
char buf[PATH_MAX], *cn;
@ -891,6 +900,8 @@ int main(int argc, char **argv)
atexit(close_stdout);
fdisk_init_debug(0);
fdiskprog_init_debug();
cxt = fdisk_new_context();
if (!cxt)
err(EXIT_FAILURE, _("failed to allocate libfdisk context"));

View File

@ -1,17 +1,30 @@
#ifndef UTIL_LINUX_FDISK_H
#define UTIL_LINUX_FDISK_H
/*
fdisk.h
*/
* fdisk.h
*/
#include "c.h"
#include <assert.h>
#include <libfdisk.h>
/* Let's temporary include private libfdisk header file. The final libfdisk.h
* maybe included when fdisk.c and libfdisk code will be completely spit.
*/
#include "fdiskP.h"
#include "blkdev.h"
#include "colors.h"
#include "debug.h"
#include "nls.h"
#define FDISKPROG_DEBUG_INIT (1 << 1)
#define FDISKPROG_DEBUG_MENU (1 << 3)
#define FDISKPROG_DEBUG_MISC (1 << 4)
#define FDISKPROG_DEBUG_ASK (1 << 5)
#define FDISKPROG_DEBUG_ALL 0xFFFF
UL_DEBUG_DECLARE_MASK(fdisk);
#define DBG(m, x) __UL_DBG(fdisk, FDISKPROG_DEBUG_, m, x)
#define ON_DBG(m, x) __UL_DBG_CALL(fdisk, FDISKPROG_DEBUG_, m, x)
extern int get_user_reply(struct fdisk_context *cxt,
const char *prompt,