From 6644688a209d022d2c8c348aabcda99bb5bc71a7 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 13 Jan 2009 23:39:15 +0100 Subject: [PATCH] blkid: add DEBUG_LOWPROBE, cleanup a little debug stuff Signed-off-by: Karel Zak --- libs/blkid/src/blkidP.h | 21 +++++++++++++-------- libs/blkid/src/cache.c | 28 +++++++++++++++++++++------- libs/blkid/src/dev.c | 5 ++++- libs/blkid/src/devname.c | 2 +- libs/blkid/src/devno.c | 2 +- libs/blkid/src/probe.c | 36 ++++++++++++++++++++++++++++++++---- libs/blkid/src/read.c | 2 +- libs/blkid/src/resolve.c | 2 +- libs/blkid/src/save.c | 2 +- libs/blkid/src/tag.c | 5 ++++- libs/blkid/src/verify.c | 2 +- 11 files changed, 80 insertions(+), 27 deletions(-) diff --git a/libs/blkid/src/blkidP.h b/libs/blkid/src/blkidP.h index 2f41d1d1..774f6c4d 100644 --- a/libs/blkid/src/blkidP.h +++ b/libs/blkid/src/blkidP.h @@ -13,6 +13,9 @@ #ifndef _BLKID_BLKIDP_H #define _BLKID_BLKIDP_H + +#define CONFIG_BLKID_DEBUG 1 + #include #include @@ -211,21 +214,23 @@ extern char *blkid_strndup(const char *s, const int length); #define DEBUG_RESOLVE 0x0080 #define DEBUG_SAVE 0x0100 #define DEBUG_TAG 0x0200 +#define DEBUG_LOWPROBE 0x0400 #define DEBUG_INIT 0x8000 #define DEBUG_ALL 0xFFFF #ifdef CONFIG_BLKID_DEBUG #include -extern int blkid_debug_mask; -#define DBG(m,x) if ((m) & blkid_debug_mask) x; -#else -#define DBG(m,x) -#endif - -#ifdef CONFIG_BLKID_DEBUG +extern int blkid_debug_mask; +extern void blkid_debug_init(int mask); extern void blkid_debug_dump_dev(blkid_dev dev); extern void blkid_debug_dump_tag(blkid_tag tag); -#endif + +#define DBG(m,x) if ((m) & blkid_debug_mask) x; + +#else /* !CONFIG_BLKID_DEBUG */ +#define DBG(m,x) +#define blkid_debug_init(x) +#endif /* CONFIG_BLKID_DEBUG */ /* devno.c */ struct dir_list { diff --git a/libs/blkid/src/cache.c b/libs/blkid/src/cache.c index 7c95726d..0769027b 100644 --- a/libs/blkid/src/cache.c +++ b/libs/blkid/src/cache.c @@ -75,20 +75,33 @@ static blkid_debug_dump_cache(int mask, blkid_cache cache) } #endif -int blkid_get_cache(blkid_cache *ret_cache, const char *filename) +#ifdef CONFIG_BLKID_DEBUG +void blkid_debug_init(int mask) { - blkid_cache cache; + if (blkid_debug_mask & DEBUG_INIT) + return; -#ifdef CONFIG_BLKID_DEBUG - if (!(blkid_debug_mask & DEBUG_INIT)) { + if (!mask) + { char *dstr = getenv("BLKID_DEBUG"); if (dstr) blkid_debug_mask = strtoul(dstr, 0, 0); - blkid_debug_mask |= DEBUG_INIT; - } + } else + blkid_debug_mask = mask; + + printf("libblkid: debug mask set to 0x%04x.\n", blkid_debug_mask); + + blkid_debug_mask |= DEBUG_INIT; +} #endif +int blkid_get_cache(blkid_cache *ret_cache, const char *filename) +{ + blkid_cache cache; + + blkid_debug_init(0); + DBG(DEBUG_CACHE, printf("creating blkid cache (using %s)\n", filename ? filename : "default cache")); @@ -183,7 +196,8 @@ int main(int argc, char** argv) blkid_cache cache = NULL; int ret; - blkid_debug_mask = DEBUG_ALL; + blkid_debug_init(DEBUG_ALL); + if ((argc > 2)) { fprintf(stderr, "Usage: %s [filename] \n", argv[0]); exit(1); diff --git a/libs/blkid/src/dev.c b/libs/blkid/src/dev.c index fb8d8527..a1dc567e 100644 --- a/libs/blkid/src/dev.c +++ b/libs/blkid/src/dev.c @@ -218,13 +218,16 @@ int main(int argc, char **argv) file = optarg; break; case 'm': - blkid_debug_mask = strtoul (optarg, &tmp, 0); + { + int mask = strtoul (optarg, &tmp, 0); if (*tmp) { fprintf(stderr, "Invalid debug mask: %s\n", optarg); exit(1); } + blkid_debug_init(mask); break; + } case '?': usage(argv[0]); } diff --git a/libs/blkid/src/devname.c b/libs/blkid/src/devname.c index 101055d8..5f877fcc 100644 --- a/libs/blkid/src/devname.c +++ b/libs/blkid/src/devname.c @@ -477,7 +477,7 @@ int main(int argc, char **argv) blkid_cache cache = NULL; int ret; - blkid_debug_mask = DEBUG_ALL; + blkid_debug_init(DEBUG_ALL); if (argc != 1) { fprintf(stderr, "Usage: %s\n" "Probe all devices and exit\n", argv[0]); diff --git a/libs/blkid/src/devno.c b/libs/blkid/src/devno.c index 0a16d9be..aaaca1ba 100644 --- a/libs/blkid/src/devno.c +++ b/libs/blkid/src/devno.c @@ -194,7 +194,7 @@ int main(int argc, char** argv) dev_t devno; const char *errmsg = "Couldn't parse %s: %s\n"; - blkid_debug_mask = DEBUG_ALL; + blkid_debug_init(DEBUG_ALL); if ((argc != 2) && (argc != 3)) { fprintf(stderr, "Usage:\t%s device_number\n\t%s major minor\n" "Resolve a device number to a device name\n", diff --git a/libs/blkid/src/probe.c b/libs/blkid/src/probe.c index 12ea2107..764d82fd 100644 --- a/libs/blkid/src/probe.c +++ b/libs/blkid/src/probe.c @@ -136,6 +136,7 @@ int blkid_known_fstype(const char *fstype) */ blkid_probe blkid_new_probe(void) { + blkid_debug_init(0); return calloc(1, sizeof(struct blkid_struct_probe)); } @@ -163,6 +164,7 @@ void blkid_reset_probe(blkid_probe pr) { if (!pr) return; + DBG(DEBUG_LOWPROBE, printf("reseting blkid_probe\n")); if (pr->buf) memset(pr->buf, 0, pr->buf_max); pr->buf_off = 0; @@ -261,9 +263,13 @@ int blkid_probe_set_device(blkid_probe pr, int fd, pr->size = size; /* read SB to test if the device is readable */ - if (!blkid_probe_get_buffer(pr, 0, 0x200)) + if (!blkid_probe_get_buffer(pr, 0, 0x200)) { + DBG(DEBUG_LOWPROBE, + printf("failed to prepare a device for low-probing\n")); return -1; + } + DBG(DEBUG_LOWPROBE, printf("a new device prepared for low-probing\n")); pr->idx = 0; return 0; } @@ -326,6 +332,7 @@ int blkid_probe_filter_types(blkid_probe pr, int flag, char *names[]) blkid_bmp_set_item(pr->fltr, i); } } + DBG(DEBUG_LOWPROBE, printf("a new probing type-filter initialized\n")); pr->idx = 0; return 0; } @@ -360,6 +367,7 @@ int blkid_probe_filter_usage(blkid_probe pr, int flag, int usage) } else if (flag & BLKID_FLTR_ONLYIN) blkid_bmp_set_item(pr->fltr, i); } + DBG(DEBUG_LOWPROBE, printf("a new probing usage-filter initialized\n")); pr->idx = 0; return 0; } @@ -374,6 +382,7 @@ int blkid_probe_invert_filter(blkid_probe pr) for (i = 0; i < BLKID_FLTR_SIZE; i++) pr->fltr[i] = ~pr->fltr[i]; + DBG(DEBUG_LOWPROBE, printf("probing filter inverted\n")); pr->idx = 0; return 0; } @@ -424,6 +433,8 @@ int blkid_do_probe(blkid_probe pr) if (pr->idx) i = pr->idx + 1; + DBG(DEBUG_LOWPROBE, printf("*** starting probing loop\n")); + for (i = 0; i < ARRAY_SIZE(idinfos); i++) { const struct blkid_idinfo *id; const struct blkid_idmag *mag; @@ -436,6 +447,8 @@ int blkid_do_probe(blkid_probe pr) id = idinfos[i]; mag = id->magics ? &id->magics[0] : NULL; + DBG(DEBUG_LOWPROBE, printf("%s ", id->name)); + /* try to detect by magic string */ while(mag && mag->magic) { int idx; @@ -445,8 +458,12 @@ int blkid_do_probe(blkid_probe pr) buf = blkid_probe_get_buffer(pr, idx << 10, 1024); if (buf && !memcmp(mag->magic, - buf + (mag->sboff & 0x3ff), mag->len)) + buf + (mag->sboff & 0x3ff), mag->len)) { + DBG(DEBUG_LOWPROBE, printf( + "{ detected magic string sboff=%d, kboff=%d } ", + mag->sboff, mag->kboff)); break; + } mag++; } @@ -455,8 +472,12 @@ int blkid_do_probe(blkid_probe pr) continue; /* final check by probing function */ - if (id->probefunc && id->probefunc(pr, mag) != 0) - continue; + if (id->probefunc) { + DBG(DEBUG_LOWPROBE, printf( + "{ calling probing function } \n")); + if (id->probefunc(pr, mag) != 0) + continue; + } /* all cheks passed */ if (pr->probreq & BLKID_PROBREQ_TYPE) @@ -466,8 +487,10 @@ int blkid_do_probe(blkid_probe pr) if (pr->probreq & BLKID_PROBREQ_USAGE) blkid_probe_set_usage(pr, id->usage); + DBG(DEBUG_LOWPROBE, printf("*** leaving probing loop (success)\n")); return 0; } + DBG(DEBUG_LOWPROBE, printf("*** leaving probing loop (failed)\n")); return 1; } @@ -492,6 +515,8 @@ static struct blkid_prval *blkid_probe_assign_value( v = &pr->vals[pr->nvals]; v->name = name; pr->nvals++; + + DBG(DEBUG_LOWPROBE, printf("assigning %s value\n", name)); return v; } @@ -773,6 +798,8 @@ int blkid_probe_get_value(blkid_probe pr, int num, const char **name, *data = v->data; if (len) *len = v->len; + + DBG(DEBUG_LOWPROBE, printf("returning %s value\n", v->name)); return 0; } @@ -792,6 +819,7 @@ int blkid_probe_lookup_value(blkid_probe pr, const char *name, *data = v->data; if (len) *len = v->len; + DBG(DEBUG_LOWPROBE, printf("returning %s value\n", v->name)); return 0; } } diff --git a/libs/blkid/src/read.c b/libs/blkid/src/read.c index ca2798f0..09980d76 100644 --- a/libs/blkid/src/read.c +++ b/libs/blkid/src/read.c @@ -476,7 +476,7 @@ int main(int argc, char**argv) blkid_cache cache = NULL; int ret; - blkid_debug_mask = DEBUG_ALL; + blkid_debug_init(DEBUG_ALL); if (argc > 2) { fprintf(stderr, "Usage: %s [filename]\n" "Test parsing of the cache (filename)\n", argv[0]); diff --git a/libs/blkid/src/resolve.c b/libs/blkid/src/resolve.c index 678f34e7..86fa9fe8 100644 --- a/libs/blkid/src/resolve.c +++ b/libs/blkid/src/resolve.c @@ -113,7 +113,7 @@ int main(int argc, char **argv) char *value; blkid_cache cache; - blkid_debug_mask = DEBUG_ALL; + blkid_debug_init(DEBUG_ALL); if (argc != 2 && argc != 3) { fprintf(stderr, "Usage:\t%s tagname=value\n" "\t%s tagname devname\n" diff --git a/libs/blkid/src/save.c b/libs/blkid/src/save.c index 656bb0bb..994b65c0 100644 --- a/libs/blkid/src/save.c +++ b/libs/blkid/src/save.c @@ -164,7 +164,7 @@ int main(int argc, char **argv) blkid_cache cache = NULL; int ret; - blkid_debug_mask = DEBUG_ALL; + blkid_debug_init(DEBUG_ALL); if (argc > 2) { fprintf(stderr, "Usage: %s [filename]\n" "Test loading/saving a cache (filename)\n", argv[0]); diff --git a/libs/blkid/src/tag.c b/libs/blkid/src/tag.c index b305ab48..3de6bfa2 100644 --- a/libs/blkid/src/tag.c +++ b/libs/blkid/src/tag.c @@ -421,13 +421,16 @@ int main(int argc, char **argv) file = optarg; break; case 'm': - blkid_debug_mask = strtoul (optarg, &tmp, 0); + { + int mask = strtoul (optarg, &tmp, 0); if (*tmp) { fprintf(stderr, "Invalid debug mask: %s\n", optarg); exit(1); } + blkid_debug_init(mask); break; + } case '?': usage(argv[0]); } diff --git a/libs/blkid/src/verify.c b/libs/blkid/src/verify.c index dd03ab7d..8892820d 100644 --- a/libs/blkid/src/verify.c +++ b/libs/blkid/src/verify.c @@ -157,7 +157,7 @@ found_type: blkid_probe_to_tags(cache->probe, dev); DBG(DEBUG_PROBE, printf("%s: devno 0x%04llx, type %s\n", - dev->bid_name, (long long)st.st_rdev, type)); + dev->bid_name, (long long)st.st_rdev, dev->bid_type)); } blkid_reset_probe(cache->probe); -- 2.39.5