#ifndef _BLKID_BLKIDP_H
#define _BLKID_BLKIDP_H
+
+#define CONFIG_BLKID_DEBUG 1
+
#include <sys/types.h>
#include <stdio.h>
#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 {
}
#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"));
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);
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]);
}
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]);
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",
*/
blkid_probe blkid_new_probe(void)
{
+ blkid_debug_init(0);
return calloc(1, sizeof(struct blkid_struct_probe));
}
{
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;
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;
}
blkid_bmp_set_item(pr->fltr, i);
}
}
+ DBG(DEBUG_LOWPROBE, printf("a new probing type-filter initialized\n"));
pr->idx = 0;
return 0;
}
} 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;
}
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;
}
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;
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;
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++;
}
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)
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;
}
v = &pr->vals[pr->nvals];
v->name = name;
pr->nvals++;
+
+ DBG(DEBUG_LOWPROBE, printf("assigning %s value\n", name));
return v;
}
*data = v->data;
if (len)
*len = v->len;
+
+ DBG(DEBUG_LOWPROBE, printf("returning %s value\n", v->name));
return 0;
}
*data = v->data;
if (len)
*len = v->len;
+ DBG(DEBUG_LOWPROBE, printf("returning %s value\n", v->name));
return 0;
}
}
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]);
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"
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]);
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]);
}
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);