]> err.no Git - util-linux/commitdiff
blkid: add DEBUG_LOWPROBE, cleanup a little debug stuff
authorKarel Zak <kzak@redhat.com>
Tue, 13 Jan 2009 22:39:15 +0000 (23:39 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 11 Feb 2009 22:21:50 +0000 (23:21 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libs/blkid/src/blkidP.h
libs/blkid/src/cache.c
libs/blkid/src/dev.c
libs/blkid/src/devname.c
libs/blkid/src/devno.c
libs/blkid/src/probe.c
libs/blkid/src/read.c
libs/blkid/src/resolve.c
libs/blkid/src/save.c
libs/blkid/src/tag.c
libs/blkid/src/verify.c

index 2f41d1d13b4512294993aa1de537c943cd200c52..774f6c4d7be941598e16ea59b9cd76c59241ec71 100644 (file)
@@ -13,6 +13,9 @@
 #ifndef _BLKID_BLKIDP_H
 #define _BLKID_BLKIDP_H
 
+
+#define CONFIG_BLKID_DEBUG 1
+
 #include <sys/types.h>
 #include <stdio.h>
 
@@ -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 <stdio.h>
-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 {
index 7c95726d273a801cc32e121de2db8674974a8151..0769027bc2f3f10ff33343e046b94d7a15446050 100644 (file)
@@ -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);
index fb8d85274c1c48324193d36e9334a40054f864ce..a1dc567ec8bc4fe583a22d3dcd2471391b9fde76 100644 (file)
@@ -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]);
                }
index 101055d859ea5c412b5cbeb368d30d090762749f..5f877fcc7815413ef68adff73fd959afc31d5cc8 100644 (file)
@@ -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]);
index 0a16d9be1b6183d2115d1eaf07f39427888e73ef..aaaca1ba0c5d93abb267240b03cd6dd8135c6dde 100644 (file)
@@ -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",
index 12ea210756671825527aa43e356315dcaa7a2172..764d82fd614d4cc269b9a4cc10b97d628c818411 100644 (file)
@@ -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;
                }
        }
index ca2798f052f867f45c95e7815f3e980a3c453374..09980d76d3bf953db94574c05b6dd1c54dabf173 100644 (file)
@@ -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]);
index 678f34e7a3997e0bd048d48ad39cc1f88e2da2e1..86fa9fe8865ae48415042f296ea9e56cd243055a 100644 (file)
@@ -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"
index 656bb0bb632ed6b922e8e9ea29e7987c0a097ae4..994b65c0a5eb6cb78c9e453e4484770176200392 100644 (file)
@@ -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]);
index b305ab48e0a0b1c052908fab0951e657582a99d9..3de6bfa2ac23f96ef98f46325a138a30f126a375 100644 (file)
@@ -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]);
                }
index dd03ab7d60e201afb30be00125349cec4e9d4c9a..8892820d38e359cae3e6adb66dde67c2b2be03a0 100644 (file)
@@ -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);