#define CONFIG_BLKID_DEBUG
#endif
-#define DEBUG_CACHE 0x0001
-#define DEBUG_DUMP 0x0002
-#define DEBUG_DEV 0x0004
-#define DEBUG_DEVNAME 0x0008
-#define DEBUG_DEVNO 0x0010
-#define DEBUG_PROBE 0x0020
-#define DEBUG_READ 0x0040
-#define DEBUG_RESOLVE 0x0080
-#define DEBUG_SAVE 0x0100
-#define DEBUG_TAG 0x0200
-#define DEBUG_LOWPROBE 0x0400
-#define DEBUG_CONFIG 0x0800
-#define DEBUG_EVALUATE 0x1000
-#define DEBUG_INIT 0x8000
-#define DEBUG_ALL 0xFFFF
+#define BLKID_DEBUG_CACHE 0x0001
+#define BLKID_DEBUG_DUMP 0x0002
+#define BLKID_DEBUG_DEV 0x0004
+#define BLKID_DEBUG_DEVNAME 0x0008
+#define BLKID_DEBUG_DEVNO 0x0010
+#define BLKID_DEBUG_PROBE 0x0020
+#define BLKID_DEBUG_READ 0x0040
+#define BLKID_DEBUG_RESOLVE 0x0080
+#define BLKID_DEBUG_SAVE 0x0100
+#define BLKID_DEBUG_TAG 0x0200
+#define BLKID_DEBUG_LOWPROBE 0x0400
+#define BLKID_DEBUG_CONFIG 0x0800
+#define BLKID_DEBUG_EVALUATE 0x1000
+#define BLKID_DEBUG_INIT 0x8000
+#define BLKID_DEBUG_ALL 0xFFFF
#ifdef CONFIG_BLKID_DEBUG
extern int blkid_debug_mask;
extern void blkid_debug_dump_dev(blkid_dev dev);
extern void blkid_debug_dump_tag(blkid_tag tag);
-#define DBG(m,x) do { if ((m) & blkid_debug_mask) x; } while (0)
+#define DBG(m,x) do { \
+ if ((BLKID_DEBUG_ ## m) & blkid_debug_mask) \
+ fprintf(stderr, "%d: libblkid: %8s: ", getpid(), # m); \
+ x; \
+ } while (0)
+
+static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
+blkid_debug(const char *mesg, ...)
+{
+ va_list ap;
+ va_start(ap, mesg);
+ vfprintf(stderr, mesg, ap);
+ va_end(ap);
+ fputc('\n', stderr);
+}
#else /* !CONFIG_BLKID_DEBUG */
#define DBG(m,x)
* locate these devices without enumerating only visible devices, so the use of
* the cache file is required in this situation.
*/
-
-#if 0 /* ifdef CONFIG_BLKID_DEBUG */
-static blkid_debug_dump_cache(int mask, blkid_cache cache)
-{
- struct list_head *p;
-
- if (!cache) {
- printf("cache: NULL\n");
- return;
- }
-
- printf("cache: time = %lu\n", cache->bic_time);
- printf("cache: flags = 0x%08X\n", cache->bic_flags);
-
- list_for_each(p, &cache->bic_devs) {
- blkid_dev dev = list_entry(p, struct blkid_struct_dev, bid_devs);
- blkid_debug_dump_dev(dev);
- }
-}
-#endif
-
#ifdef CONFIG_BLKID_DEBUG
void blkid_init_debug(int mask)
{
- if (blkid_debug_mask & DEBUG_INIT)
+ if (blkid_debug_mask & BLKID_DEBUG_INIT)
return;
if (!mask)
blkid_debug_mask = mask;
if (blkid_debug_mask)
- printf("libblkid: debug mask set to 0x%04x.\n", blkid_debug_mask);
+ fprintf(stderr, "libblkid: debug mask set to 0x%04x.\n", blkid_debug_mask);
- blkid_debug_mask |= DEBUG_INIT;
+ blkid_debug_mask |= BLKID_DEBUG_INIT;
}
#endif
blkid_init_debug(0);
- DBG(DEBUG_CACHE, printf("creating blkid cache (using %s)\n",
+ DBG(CACHE, blkid_debug("creating blkid cache (using %s)",
filename ? filename : "default cache"));
if (!(cache = (blkid_cache) calloc(1, sizeof(struct blkid_struct_cache))))
(void) blkid_flush_cache(cache);
- DBG(DEBUG_CACHE, printf("freeing cache struct\n"));
+ DBG(CACHE, blkid_debug("freeing cache struct"));
- /* DBG(DEBUG_CACHE, blkid_debug_dump_cache(cache)); */
+ /* DBG(CACHE, blkid_debug_dump_cache(cache)); */
while (!list_empty(&cache->bic_devs)) {
blkid_dev dev = list_entry(cache->bic_devs.next,
struct blkid_struct_tag,
bit_names);
- DBG(DEBUG_CACHE, printf("warning: unfreed tag %s=%s\n",
+ DBG(CACHE, blkid_debug("warning: unfreed tag %s=%s",
bad->bit_name, bad->bit_val));
blkid_free_tag(bad);
}
list_for_each_safe(p, pnext, &cache->bic_devs) {
blkid_dev dev = list_entry(p, struct blkid_struct_dev, bid_devs);
if (stat(dev->bid_name, &st) < 0) {
- DBG(DEBUG_CACHE,
- printf("freeing %s\n", dev->bid_name));
+ DBG(CACHE, blkid_debug("freeing %s", dev->bid_name));
blkid_free_dev(dev);
cache->bic_flags |= BLKID_BIC_FL_CHANGED;
} else {
- DBG(DEBUG_CACHE,
- printf("Device %s exists\n", dev->bid_name));
+ DBG(CACHE, blkid_debug("Device %s exists", dev->bid_name));
}
}
}
blkid_cache cache = NULL;
int ret;
- blkid_init_debug(DEBUG_ALL);
+ blkid_init_debug(BLKID_DEBUG_ALL);
if ((argc > 2)) {
fprintf(stderr, "Usage: %s [filename] \n", argv[0]);
}
return 0;
err:
- DBG(DEBUG_CONFIG, printf(
- "config file: unknown evaluation method '%s'.\n", s));
+ DBG(CONFIG, blkid_debug(
+ "config file: unknown evaluation method '%s'.", s));
return -1;
}
if (feof(fd))
s = strchr (buf, '\0');
else {
- DBG(DEBUG_CONFIG, fprintf(stderr,
- "libblkid: config file: missing newline at line '%s'.\n",
+ DBG(CONFIG, blkid_debug(
+ "config file: missing newline at line '%s'.",
buf));
return -1;
}
if (*s && parse_evaluate(conf, s) == -1)
return -1;
} else {
- DBG(DEBUG_CONFIG, printf(
- "config file: unknown option '%s'.\n", s));
+ DBG(CONFIG, blkid_debug(
+ "config file: unknown option '%s'.", s));
return -1;
}
return 0;
return NULL;
conf->uevent = -1;
- DBG(DEBUG_CONFIG, fprintf(stderr,
- "reading config file: %s.\n", filename));
+ DBG(CONFIG, blkid_debug("reading config file: %s.", filename));
f = fopen(filename, "r" UL_CLOEXECSTR);
if (!f) {
- DBG(DEBUG_CONFIG, fprintf(stderr,
- "%s: does not exist, using built-in default\n", filename));
+ DBG(CONFIG, blkid_debug("%s: does not exist, using built-in default", filename));
goto dflt;
}
while (!feof(f)) {
if (parse_next(f, conf)) {
- DBG(DEBUG_CONFIG, fprintf(stderr,
- "%s: parse error\n", filename));
+ DBG(CONFIG, blkid_debug("%s: parse error", filename));
goto err;
}
}
struct blkid_config *conf;
char *filename = NULL;
- blkid_init_debug(DEBUG_ALL);
+ blkid_init_debug(BLKID_DEBUG_ALL);
if (argc == 2)
filename = argv[1];
if (!dev)
return;
- DBG(DEBUG_DEV,
- printf(" freeing dev %s (%s)\n", dev->bid_name, dev->bid_type ?
+ DBG(DEV,
+ blkid_debug(" freeing dev %s (%s)", dev->bid_name, dev->bid_type ?
dev->bid_type : "(null)"));
- DBG(DEBUG_DEV, blkid_debug_dump_dev(dev));
+ DBG(DEV, blkid_debug_dump_dev(dev));
list_del(&dev->bid_devs);
while (!list_empty(&dev->bid_tags)) {
return;
}
- printf(" dev: name = %s\n", dev->bid_name);
- printf(" dev: DEVNO=\"0x%0llx\"\n", (long long)dev->bid_devno);
- printf(" dev: TIME=\"%ld.%ld\"\n", (long)dev->bid_time, (long)dev->bid_utime);
- printf(" dev: PRI=\"%d\"\n", dev->bid_pri);
- printf(" dev: flags = 0x%08X\n", dev->bid_flags);
+ fprintf(stderr, " dev: name = %s\n", dev->bid_name);
+ fprintf(stderr, " dev: DEVNO=\"0x%0llx\"\n", (long long)dev->bid_devno);
+ fprintf(stderr, " dev: TIME=\"%ld.%ld\"\n", (long)dev->bid_time, (long)dev->bid_utime);
+ fprintf(stderr, " dev: PRI=\"%d\"\n", dev->bid_pri);
+ fprintf(stderr, " dev: flags = 0x%08X\n", dev->bid_flags);
list_for_each(p, &dev->bid_tags) {
blkid_tag tag = list_entry(p, struct blkid_struct_tag, bit_tags);
if (tag)
- printf(" tag: %s=\"%s\"\n", tag->bit_name,
+ fprintf(stderr, " tag: %s=\"%s\"\n", tag->bit_name,
tag->bit_val);
else
- printf(" tag: NULL\n");
+ fprintf(stderr, " tag: NULL\n");
}
- printf("\n");
}
#endif
if (strcmp(tmp->bid_name, devname))
continue;
- DBG(DEBUG_DEVNAME,
- printf("found devname %s in cache\n", tmp->bid_name));
+ DBG(DEVNAME, blkid_debug("found devname %s in cache", tmp->bid_name));
dev = tmp;
break;
}
int ma, mi;
dev_t ret = 0;
- DBG(DEBUG_DEVNAME, printf("opening %s\n", lvm_device));
+ DBG(DEVNAME, blkid_debug("opening %s", lvm_device));
if ((lvf = fopen(lvm_device, "r" UL_CLOEXECSTR)) == NULL) {
- DBG(DEBUG_DEVNAME, printf("%s: (%d) %m\n", lvm_device, errno));
+ DBG(DEVNAME, blkid_debug("%s: (%d) %m", lvm_device, errno));
return 0;
}
if ((vg_list = opendir(VG_DIR)) == NULL)
return;
- DBG(DEBUG_DEVNAME, printf("probing LVM devices under %s\n", VG_DIR));
+ DBG(DEVNAME, blkid_debug("probing LVM devices under %s", VG_DIR));
while ((vg_iter = readdir(vg_list)) != NULL) {
DIR *lv_list;
lv_name);
dev = lvm_get_devno(lvm_device);
sprintf(lvm_device, "%s/%s", vg_name, lv_name);
- DBG(DEBUG_DEVNAME, printf("LVM dev %s: devno 0x%04X\n",
+ DBG(DEVNAME, blkid_debug("LVM dev %s: devno 0x%04X",
lvm_device,
(unsigned int) dev));
probe_one(cache, lvm_device, dev, BLKID_PRI_LVM,
&ma, &mi, &sz, device) != 4)
continue;
- DBG(DEBUG_DEVNAME, printf("Checking partition %s (%d, %d)\n",
+ DBG(DEVNAME, blkid_debug("Checking partition %s (%d, %d)",
device, ma, mi));
probe_one(cache, device, makedev(ma, mi), BLKID_PRI_EVMS,
const char **dirname;
for (dirname = dirlist; *dirname; dirname++) {
- DBG(DEBUG_DEVNAME, printf("probing UBI volumes under %s\n",
+ DBG(DEVNAME, blkid_debug("probing UBI volumes under %s",
*dirname));
DIR *dir;
if (!S_ISCHR(st.st_mode) || !minor(dev))
continue;
- DBG(DEBUG_DEVNAME, printf("UBI vol %s/%s: devno 0x%04X\n",
+ DBG(DEVNAME, blkid_debug("UBI vol %s/%s: devno 0x%04X",
*dirname, name, (int) dev));
probe_one(cache, name, dev, BLKID_PRI_UBI, only_if_new, 0);
}
continue;
devs[which] = makedev(ma, mi);
- DBG(DEBUG_DEVNAME, printf("read partition name %s\n", ptname));
+ DBG(DEVNAME, blkid_debug("read partition name %s", ptname));
/* Skip whole disk devs unless they have no partitions.
* If base name of device has changed, also
/* ends in a digit, clearly a partition, so check */
if (isdigit(ptname[lens[which] - 1])) {
- DBG(DEBUG_DEVNAME,
- printf("partition dev %s, devno 0x%04X\n",
+ DBG(DEVNAME, blkid_debug("partition dev %s, devno 0x%04X",
ptname, (unsigned int) devs[which]));
if (sz > 1)
tmp = list_entry(p, struct blkid_struct_dev,
bid_devs);
if (tmp->bid_devno == devs[last]) {
- DBG(DEBUG_DEVNAME,
- printf("freeing %s\n",
+ DBG(DEVNAME, blkid_debug("freeing %s",
tmp->bid_name));
blkid_free_dev(tmp);
cache->bic_flags |= BLKID_BIC_FL_CHANGED;
* check last as well.
*/
if (lens[last] && strncmp(ptnames[last], ptname, lens[last])) {
- DBG(DEBUG_DEVNAME,
- printf("whole dev %s, devno 0x%04X\n",
+ DBG(DEVNAME, blkid_debug("whole dev %s, devno 0x%04X",
ptnames[last], (unsigned int) devs[last]));
probe_one(cache, ptnames[last], devs[last], 0,
only_if_new, 0);
{
int ret;
- DBG(DEBUG_PROBE, printf("Begin blkid_probe_all()\n"));
+ DBG(PROBE, blkid_debug("Begin blkid_probe_all()"));
ret = probe_all(cache, 0);
if (ret == 0) {
cache->bic_time = time(0);
cache->bic_flags |= BLKID_BIC_FL_PROBED;
}
- DBG(DEBUG_PROBE, printf("End blkid_probe_all() [rc=%d]\n", ret));
+ DBG(PROBE, blkid_debug("End blkid_probe_all() [rc=%d]", ret));
return ret;
}
{
int ret;
- DBG(DEBUG_PROBE, printf("Begin blkid_probe_all_new()\n"));
+ DBG(PROBE, blkid_debug("Begin blkid_probe_all_new()"));
ret = probe_all(cache, 1);
- DBG(DEBUG_PROBE, printf("End blkid_probe_all_new() [rc=%d]\n", ret));
+ DBG(PROBE, blkid_debug("End blkid_probe_all_new() [rc=%d]", ret));
return ret;
}
{
int ret;
- DBG(DEBUG_PROBE, printf("Begin blkid_probe_all_removable()\n"));
+ DBG(PROBE, blkid_debug("Begin blkid_probe_all_removable()"));
ret = probe_all_removable(cache);
- DBG(DEBUG_PROBE, printf("End blkid_probe_all_removable() [rc=%d]\n", ret));
+ DBG(PROBE, blkid_debug("End blkid_probe_all_removable() [rc=%d]", ret));
return ret;
}
blkid_cache cache = NULL;
int ret;
- blkid_init_debug(DEBUG_ALL);
+ blkid_init_debug(BLKID_DEBUG_ALL);
if (argc != 1) {
fprintf(stderr, "Usage: %s\n"
"Probe all devices and exit\n", argv[0]);
if (S_ISBLK(st.st_mode) && st.st_rdev == devno) {
*devname = blkid_strconcat(dirname, "/", dp->d_name);
- DBG(DEBUG_DEVNO,
- printf("found 0x%llx at %s\n", (long long)devno,
+ DBG(DEVNO, blkid_debug("found 0x%llx at %s", (long long)devno,
*devname));
break;
}
struct dir_list *current = list;
list = list->next;
- DBG(DEBUG_DEVNO, printf("directory %s\n", current->name));
+ DBG(DEVNO, blkid_debug("directory %s", current->name));
blkid__scan_dir(current->name, devno, &new_list, &devname);
free(current->name);
free(current);
path = scandev_devno_to_devpath(devno);
if (!path) {
- DBG(DEBUG_DEVNO,
- printf("blkid: couldn't find devno 0x%04lx\n",
+ DBG(DEVNO, blkid_debug("blkid: couldn't find devno 0x%04lx",
(unsigned long) devno));
} else {
- DBG(DEBUG_DEVNO,
- printf("found devno 0x%04llx as %s\n", (long long)devno, path));
+ DBG(DEVNO, blkid_debug("found devno 0x%04llx as %s", (long long)devno, path));
}
return path;
fclose(f);
- DBG(DEBUG_DEVNO, printf("major %d %s associated with '%s' driver\n",
+ DBG(DEVNO, blkid_debug("major %d %s associated with '%s' driver",
major, match ? "is" : "is NOT", drvname));
return match;
}
dev_t devno, disk_devno;
const char *errmsg = "Couldn't parse %s: %s\n";
- blkid_init_debug(DEBUG_ALL);
+ blkid_init_debug(BLKID_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",
if (!rc)
rc = memcmp(value, data, len);
done:
- DBG(DEBUG_EVALUATE, printf("%s: %s verification %s\n",
+ DBG(EVALUATE, blkid_debug("%s: %s verification %s",
devname, name, rc == 0 ? "PASS" : "FAILED"));
if (fd >= 0)
close(fd);
FILE *f;
int rc = -1;
- DBG(DEBUG_EVALUATE, printf("%s: uevent '%s' requested\n", devname, action));
+ DBG(EVALUATE, blkid_debug("%s: uevent '%s' requested", devname, action));
if (!devname || !action)
return -1;
rc = 0;
fclose(f);
}
- DBG(DEBUG_EVALUATE, printf("%s: send uevent %s\n",
+ DBG(EVALUATE, blkid_debug("%s: send uevent %s",
uevent, rc == 0 ? "SUCCES" : "FAILED"));
return rc;
}
size_t len;
struct stat st;
- DBG(DEBUG_EVALUATE,
- printf("evaluating by udev %s=%s\n", token, value));
+ DBG(EVALUATE, blkid_debug("evaluating by udev %s=%s", token, value));
if (!strcmp(token, "UUID"))
strcpy(dev, _PATH_DEV_BYUUID "/");
else if (!strcmp(token, "PARTUUID"))
strcpy(dev, _PATH_DEV_BYPARTUUID "/");
else {
- DBG(DEBUG_EVALUATE,
- printf("unsupported token %s\n", token));
+ DBG(EVALUATE, blkid_debug("unsupported token %s", token));
return NULL; /* unsupported tag */
}
if (blkid_encode_string(value, &dev[len], sizeof(dev) - len) != 0)
return NULL;
- DBG(DEBUG_EVALUATE,
- printf("expected udev link: %s\n", dev));
+ DBG(EVALUATE, blkid_debug("expected udev link: %s", dev));
if (stat(dev, &st))
goto failed; /* link or device does not exist */
return path;
failed:
- DBG(DEBUG_EVALUATE, printf("failed to evaluate by udev\n"));
+ DBG(EVALUATE, blkid_debug("failed to evaluate by udev"));
if (uevent && path)
blkid_send_uevent(path, "change");
blkid_cache c = cache ? *cache : NULL;
char *res;
- DBG(DEBUG_EVALUATE,
- printf("evaluating by blkid scan %s=%s\n", token, value));
+ DBG(EVALUATE, blkid_debug("evaluating by blkid scan %s=%s", token, value));
if (!c) {
char *cachefile = blkid_get_cache_filename(conf);
if (!cache || !*cache)
blkid_init_debug(0);
- DBG(DEBUG_EVALUATE,
- printf("evaluating %s%s%s\n", token, value ? "=" : "",
+ DBG(EVALUATE, blkid_debug("evaluating %s%s%s", token, value ? "=" : "",
value ? value : ""));
if (!value) {
break;
}
- DBG(DEBUG_EVALUATE,
- printf("%s=%s evaluated as %s\n", token, value, ret));
+ DBG(EVALUATE, blkid_debug("%s=%s evaluated as %s", token, value, ret));
out:
blkid_free_config(conf);
free(t);
name = "openbsd";
break;
default:
- DBG(DEBUG_LOWPROBE, printf(
+ DBG(LOWPROBE, blkid_debug(
"WARNING: BSD label detected on unknown (0x%x) "
- "primary partition\n",
+ "primary partition",
blkid_partition_get_type(parent)));
break;
}
nparts = le16_to_cpu(l->d_npartitions);
else if (le16_to_cpu(l->d_npartitions) > BSD_MAXPARTITIONS)
- DBG(DEBUG_LOWPROBE, printf(
- "WARNING: ignore %d more BSD partitions\n",
+ DBG(LOWPROBE, blkid_debug(
+ "WARNING: ignore %d more BSD partitions",
le16_to_cpu(l->d_npartitions) - BSD_MAXPARTITIONS));
for (i = 0, p = l->d_partitions; i < nparts; i++, p++) {
if (parent && blkid_partition_get_start(parent) == start
&& blkid_partition_get_size(parent) == size) {
- DBG(DEBUG_LOWPROBE, printf(
+ DBG(LOWPROBE, blkid_debug(
"WARNING: BSD partition (%d) same like parent, "
- "ignore\n", i));
+ "ignore", i));
continue;
}
if (parent && !blkid_is_nested_dimension(parent, start, size)) {
- DBG(DEBUG_LOWPROBE, printf(
+ DBG(LOWPROBE, blkid_debug(
"WARNING: BSD partition (%d) overflow "
- "detected, ignore\n", i));
+ "detected, ignore", i));
continue;
}
* partition table.
*/
if (blkid_probe_is_vfat(pr)) {
- DBG(DEBUG_LOWPROBE, printf("probably FAT -- ignore\n"));
+ DBG(LOWPROBE, blkid_debug("probably FAT -- ignore"));
goto nothing;
}
*/
for (p = p0, i = 0; i < 4; i++, p++)
if (p->boot_ind != 0 && p->boot_ind != 0x80) {
- DBG(DEBUG_LOWPROBE, printf("missing boot indicator -- ignore\n"));
+ DBG(LOWPROBE, blkid_debug("missing boot indicator -- ignore"));
goto nothing;
}
*/
for (p = p0, i = 0; i < 4; i++, p++) {
if (p->sys_type == BLKID_GPT_PARTITION) {
- DBG(DEBUG_LOWPROBE, printf("probably GPT -- ignore\n"));
+ DBG(LOWPROBE, blkid_debug("probably GPT -- ignore"));
goto nothing;
}
}
h->header_crc32 = orgcrc;
if (crc != le32_to_cpu(orgcrc)) {
- DBG(DEBUG_LOWPROBE, printf("GPT header corrupted\n"));
+ DBG(LOWPROBE, blkid_debug("GPT header corrupted"));
return NULL;
}
/* Valid header has to be at MyLBA */
if (le64_to_cpu(h->my_lba) != lba) {
- DBG(DEBUG_LOWPROBE, printf(
- "GPT->MyLBA mismatch with real position\n"));
+ DBG(LOWPROBE, blkid_debug(
+ "GPT->MyLBA mismatch with real position"));
return NULL;
}
/* Check if First and Last usable LBA makes sense */
if (lu < fu || fu > lastlba || lu > lastlba) {
- DBG(DEBUG_LOWPROBE, printf(
- "GPT->{First,Last}UsableLBA out of range\n"));
+ DBG(LOWPROBE, blkid_debug(
+ "GPT->{First,Last}UsableLBA out of range"));
return NULL;
}
/* The header has to be outside usable range */
if (fu < lba && lba < lu) {
- DBG(DEBUG_LOWPROBE, printf("GPT header is inside usable area\n"));
+ DBG(LOWPROBE, blkid_debug("GPT header is inside usable area"));
return NULL;
}
esz = le32_to_cpu(h->num_partition_entries) *
le32_to_cpu(h->sizeof_partition_entry);
if (!esz) {
- DBG(DEBUG_LOWPROBE, printf("GPT entries undefined\n"));
+ DBG(LOWPROBE, blkid_debug("GPT entries undefined"));
return NULL;
}
*ents = (struct gpt_entry *) get_lba_buffer(pr,
le64_to_cpu(h->partition_entries_lba), esz);
if (!*ents) {
- DBG(DEBUG_LOWPROBE, printf("GPT entries unreadable\n"));
+ DBG(LOWPROBE, blkid_debug("GPT entries unreadable"));
return NULL;
}
/* Validate entries */
crc = count_crc32((unsigned char *) *ents, esz);
if (crc != le32_to_cpu(h->partition_entry_array_crc32)) {
- DBG(DEBUG_LOWPROBE, printf("GPT entries corrupted\n"));
+ DBG(LOWPROBE, blkid_debug("GPT entries corrupted"));
return NULL;
}
}
/* the partition has to inside usable range */
if (start < fu || start + size - 1 > lu) {
- DBG(DEBUG_LOWPROBE, printf(
- "GPT entry[%d] overflows usable area - ignore\n",
+ DBG(LOWPROBE, blkid_debug(
+ "GPT entry[%d] overflows usable area - ignore",
i));
blkid_partlist_increment_partno(ls);
continue;
goto nothing;
if (be32_to_cpu(p->map_count) != nblks) {
- DBG(DEBUG_LOWPROBE, printf(
+ DBG(LOWPROBE, blkid_debug(
"mac: inconsisten map_count in partition map, "
- "entry[0]: %d, entry[%d]: %d\n",
+ "entry[0]: %d, entry[%d]: %d",
nblks, i - 1,
be32_to_cpu(p->map_count)));
}
size = dos_partition_size(p);
if (parent && !blkid_is_nested_dimension(parent, start, size)) {
- DBG(DEBUG_LOWPROBE, printf(
+ DBG(LOWPROBE, blkid_debug(
"WARNING: minix partition (%d) overflow "
- "detected, ignore\n", i));
+ "detected, ignore", i));
continue;
}
ls->next_partno = 1;
INIT_LIST_HEAD(&ls->l_tabs);
- DBG(DEBUG_LOWPROBE, printf("partlist reset\n"));
+ DBG(LOWPROBE, blkid_debug("partlist reset"));
}
static blkid_partlist partitions_init_data(struct blkid_chain *chn)
reset_partlist(ls);
- DBG(DEBUG_LOWPROBE,
- printf("parts: initialized partitions list (%p, size=%d)\n",
+ DBG(LOWPROBE, blkid_debug("parts: initialized partitions list (%p, size=%d)",
ls, ls->nparts_max));
return ls;
}
INIT_LIST_HEAD(&tab->t_tabs);
list_add_tail(&tab->t_tabs, &ls->l_tabs);
- DBG(DEBUG_LOWPROBE,
- printf("parts: create a new partition table "
- "(%p, type=%s, offset=%"PRId64")\n", tab, type, offset));
+ DBG(LOWPROBE, blkid_debug("parts: create a new partition table "
+ "(%p, type=%s, offset=%"PRId64")", tab, type, offset));
return tab;
}
par->start = start;
par->size = size;
- DBG(DEBUG_LOWPROBE,
- printf("parts: add partition (%p start=%"
- PRId64 ", size=%" PRId64 ", table=%p)\n",
+ DBG(LOWPROBE, blkid_debug("parts: add partition (%p start=%"
+ PRId64 ", size=%" PRId64 ", table=%p)",
par, par->start, par->size, tab));
return par;
}
/* final check by probing function */
if (id->probefunc) {
- DBG(DEBUG_LOWPROBE, printf(
- "%s: ---> call probefunc()\n", id->name));
+ DBG(LOWPROBE, blkid_debug(
+ "%s: ---> call probefunc()", id->name));
rc = id->probefunc(pr, mag);
if (rc == -1) {
/* reset after error */
reset_partlist(blkid_probe_get_partlist(pr));
if (chn && !chn->binary)
blkid_probe_chain_reset_vals(pr, chn);
- DBG(DEBUG_LOWPROBE, printf(
- "%s probefunc failed\n", id->name));
+ DBG(LOWPROBE, blkid_debug("%s probefunc failed", id->name));
}
if (rc == 0 && mag && chn && !chn->binary)
rc = blkid_probe_set_magic(pr, off, mag->len,
(unsigned char *) mag->magic);
- DBG(DEBUG_LOWPROBE, printf(
- "%s: <--- (rc = %d)\n", id->name, rc));
+ DBG(LOWPROBE, blkid_debug("%s: <--- (rc = %d)", id->name, rc));
}
nothing:
if (!pr->wipe_size && (pr->prob_flags & BLKID_PROBE_FL_IGNORE_PT))
goto details_only;
- DBG(DEBUG_LOWPROBE,
- printf("--> starting probing loop [PARTS idx=%d]\n",
+ DBG(LOWPROBE, blkid_debug("--> starting probing loop [PARTS idx=%d]",
chn->idx));
i = chn->idx < 0 ? 0 : chn->idx + 1U;
blkid_probe_set_value(pr, "PTTYPE",
(unsigned char *) name,
strlen(name) + 1);
- DBG(DEBUG_LOWPROBE,
- printf("<-- leaving probing loop (type=%s) [PARTS idx=%d]\n",
+ DBG(LOWPROBE, blkid_debug("<-- leaving probing loop (type=%s) [PARTS idx=%d]",
name, chn->idx));
rc = 0;
break;
}
if (rc == 1) {
- DBG(DEBUG_LOWPROBE,
- printf("<-- leaving probing loop (failed) [PARTS idx=%d]\n",
+ DBG(LOWPROBE, blkid_debug("<-- leaving probing loop (failed) [PARTS idx=%d]",
chn->idx));
}
blkid_partlist ls;
blkid_loff_t sz, off;
- DBG(DEBUG_LOWPROBE, printf(
- "parts: ----> %s subprobe requested (parent=%p)\n",
+ DBG(LOWPROBE, blkid_debug(
+ "parts: ----> %s subprobe requested (parent=%p)",
id->name, parent));
if (!pr || !parent || !parent->size)
off = ((blkid_loff_t) parent->start) << 9;
if (off < pr->off || pr->off + pr->size < off + sz) {
- DBG(DEBUG_LOWPROBE, printf(
- "ERROR: parts: <---- '%s' subprobe: overflow detected.\n",
+ DBG(LOWPROBE, blkid_debug(
+ "ERROR: parts: <---- '%s' subprobe: overflow detected.",
id->name));
return -1;
}
blkid_free_probe(prc); /* free cloned prober */
- DBG(DEBUG_LOWPROBE, printf(
- "parts: <---- %s subprobe done (parent=%p, rc=%d)\n",
+ DBG(LOWPROBE, blkid_debug(
+ "parts: <---- %s subprobe done (parent=%p, rc=%d)",
id->name, parent, rc));
return rc;
blkid_loff_t start, end;
int nparts, i, rc = 0;
- DBG(DEBUG_LOWPROBE, printf(
- "=> checking if off=%jd size=%jd covered by PT\n",
+ DBG(LOWPROBE, blkid_debug(
+ "=> checking if off=%jd size=%jd covered by PT",
offset, size));
prc = blkid_clone_probe(pr);
blkid_partition par = &ls->parts[i];
if (par->start + par->size > (pr->size >> 9)) {
- DBG(DEBUG_LOWPROBE, printf("partition #%d overflows "
- "device (off=%" PRId64 " size=%" PRId64 ")\n",
+ DBG(LOWPROBE, blkid_debug("partition #%d overflows "
+ "device (off=%" PRId64 " size=%" PRId64 ")",
par->partno, par->start, par->size));
goto done;
}
done:
blkid_free_probe(prc);
- DBG(DEBUG_LOWPROBE, printf("<= %s covered by PT\n", rc ? "IS" : "NOT"));
+ DBG(LOWPROBE, blkid_debug("<= %s covered by PT", rc ? "IS" : "NOT"));
return rc;
}
if (!ls)
return NULL;
- DBG(DEBUG_LOWPROBE,
- printf("triyng to convert devno 0x%llx to partition\n",
+ DBG(LOWPROBE, blkid_debug("triyng to convert devno 0x%llx to partition",
(long long) devno));
if (sysfs_init(&sysfs, devno, NULL)) {
- DBG(DEBUG_LOWPROBE, printf("failed t init sysfs context\n"));
+ DBG(LOWPROBE, blkid_debug("failed t init sysfs context"));
return NULL;
}
rc = sysfs_read_u64(&sysfs, "size", &size);
return NULL;
if (partno) {
- DBG(DEBUG_LOWPROBE, printf("mapped by DM, using partno %d\n", partno));
+ DBG(LOWPROBE, blkid_debug("mapped by DM, using partno %d", partno));
/*
* Partition mapped by kpartx does not provide "start" offset
return NULL;
}
- DBG(DEBUG_LOWPROBE, printf("searching by offset/size\n"));
+ DBG(LOWPROBE, blkid_debug("searching by offset/size"));
for (i = 0; i < ls->nparts; i++) {
blkid_partition par = &ls->parts[i];
}
- DBG(DEBUG_LOWPROBE, printf("not found partition for device\n"));
+ DBG(LOWPROBE, blkid_debug("not found partition for device"));
return NULL;
}
goto nothing;
if (count_checksum(l)) {
- DBG(DEBUG_LOWPROBE, printf(
- "detected corrupted sgi disk label -- ignore\n"));
+ DBG(LOWPROBE, blkid_debug(
+ "detected corrupted sgi disk label -- ignore"));
goto nothing;
}
goto nothing;
if (le32_to_cpu(l->v_version) != 1) {
- DBG(DEBUG_LOWPROBE, printf(
- "WARNING: unsupported solaris x86 version %d, ignore\n",
+ DBG(LOWPROBE, blkid_debug(
+ "WARNING: unsupported solaris x86 version %d, ignore",
le32_to_cpu(l->v_version)));
goto nothing;
}
start += blkid_partition_get_start(parent);
if (parent && !blkid_is_nested_dimension(parent, start, size)) {
- DBG(DEBUG_LOWPROBE, printf(
+ DBG(LOWPROBE, blkid_debug(
"WARNING: solaris partition (%d) overflow "
- "detected, ignore\n", i));
+ "detected, ignore", i));
continue;
}
goto nothing;
if (sun_pt_checksum(l)) {
- DBG(DEBUG_LOWPROBE, printf(
- "detected corrupted sun disk label -- ignore\n"));
+ DBG(LOWPROBE, blkid_debug(
+ "detected corrupted sun disk label -- ignore"));
goto nothing;
}
/* sectors per cylinder (partition offset is in cylinders...) */
spc = be16_to_cpu(l->nhead) * be16_to_cpu(l->nsect);
- DBG(DEBUG_LOWPROBE,
- printf("Sun VTOC sanity=%u version=%u nparts=%u\n",
+ DBG(LOWPROBE, blkid_debug("Sun VTOC sanity=%u version=%u nparts=%u",
be32_to_cpu(l->vtoc.sanity),
be32_to_cpu(l->vtoc.version),
be16_to_cpu(l->vtoc.nparts)));
size = le32_to_cpu(p->nr_sects);
if (parent && !blkid_is_nested_dimension(parent, start, size)) {
- DBG(DEBUG_LOWPROBE, printf(
+ DBG(LOWPROBE, blkid_debug(
"WARNING: unixware partition (%d) overflow "
- "detected, ignore\n", i));
+ "detected, ignore", i));
continue;
}
if (!pr)
return NULL;
- DBG(DEBUG_LOWPROBE, printf("allocate a new probe %p\n", pr));
+ DBG(LOWPROBE, blkid_debug("allocate a new probe %p", pr));
/* initialize chains */
for (i = 0; i < BLKID_NCHAINS; i++) {
if (!parent)
return NULL;
- DBG(DEBUG_LOWPROBE, printf("allocate a probe clone\n"));
+ DBG(LOWPROBE, blkid_debug("allocate a probe clone"));
pr = blkid_new_probe();
if (!pr)
blkid_probe_reset_buffer(pr);
blkid_free_probe(pr->disk_probe);
- DBG(DEBUG_LOWPROBE, printf("free probe %p\n", pr));
+ DBG(LOWPROBE, blkid_debug("free probe %p", pr));
free(pr);
}
if (rc != 0)
return NULL;
- DBG(DEBUG_LOWPROBE,
- printf("returning %s binary data\n", chn->driver->name));
+ DBG(LOWPROBE, blkid_debug("returning %s binary data", chn->driver->name));
return chn->data;
}
for (i = 0; i < chn->driver->nidinfos; i++) {
const struct blkid_idinfo *id = chn->driver->idinfos[i];
- DBG(DEBUG_LOWPROBE, printf("%d: %s: %s\n",
+ DBG(LOWPROBE, blkid_debug("%d: %s: %s",
i,
id->name,
blkid_bmp_get_item(chn->fltr, i)
for (i = 0; i < blkid_bmp_nwords(chn->driver->nidinfos); i++)
chn->fltr[i] = ~chn->fltr[i];
- DBG(DEBUG_LOWPROBE, printf("probing filter inverted\n"));
+ DBG(LOWPROBE, blkid_debug("probing filter inverted"));
/* blkid_probe_dump_filter(pr, chain); */
return 0;
}
}
}
- DBG(DEBUG_LOWPROBE,
- printf("%s: a new probing type-filter initialized\n",
+ DBG(LOWPROBE, blkid_debug("%s: a new probing type-filter initialized",
chn->driver->name));
/* blkid_probe_dump_filter(pr, chain); */
return 0;
list_entry(p, struct blkid_bufinfo, bufs);
if (x->off <= off && off + len <= x->off + x->len) {
- DBG(DEBUG_LOWPROBE,
- printf("\treuse buffer: off=%jd len=%jd pr=%p\n",
+ DBG(LOWPROBE, blkid_debug("\treuse buffer: off=%jd len=%jd pr=%p",
x->off, x->len, pr));
bf = x;
break;
bf->off = off;
INIT_LIST_HEAD(&bf->bufs);
- DBG(DEBUG_LOWPROBE,
- printf("\tbuffer read: off=%jd len=%jd pr=%p\n",
+ DBG(LOWPROBE, blkid_debug("\tbuffer read: off=%jd len=%jd pr=%p",
off, len, pr));
ret = read(pr->fd, bf->data, len);
if (!pr || list_empty(&pr->buffers))
return;
- DBG(DEBUG_LOWPROBE, printf("reseting probing buffers pr=%p\n", pr));
+ DBG(LOWPROBE, blkid_debug("reseting probing buffers pr=%p", pr));
while (!list_empty(&pr->buffers)) {
struct blkid_bufinfo *bf = list_entry(pr->buffers.next,
free(bf);
}
- DBG(DEBUG_LOWPROBE,
- printf("buffers summary: %"PRIu64" bytes "
- "by %"PRIu64" read() call(s)\n",
+ DBG(LOWPROBE, blkid_debug("buffers summary: %"PRIu64" bytes "
+ "by %"PRIu64" read() call(s)",
len_ct, read_ct));
INIT_LIST_HEAD(&pr->buffers);
else {
if (S_ISBLK(sb.st_mode)) {
if (blkdev_get_size(fd, (unsigned long long *) &pr->size)) {
- DBG(DEBUG_LOWPROBE, printf(
- "failed to get device size\n"));
+ DBG(LOWPROBE, blkid_debug("failed to get device size"));
goto err;
}
} else if (S_ISCHR(sb.st_mode))
pr->flags |= BLKID_FL_CDROM_DEV;
#endif
- DBG(DEBUG_LOWPROBE, printf("ready for low-probing, offset=%jd, size=%jd\n",
+ DBG(LOWPROBE, blkid_debug("ready for low-probing, offset=%jd, size=%jd",
pr->off, pr->size));
- DBG(DEBUG_LOWPROBE, printf("whole-disk: %s, regfile: %s\n",
+ DBG(LOWPROBE, blkid_debug("whole-disk: %s, regfile: %s",
blkid_probe_is_wholedisk(pr) ?"YES" : "NO",
S_ISREG(pr->mode) ? "YES" : "NO"));
return 0;
err:
- DBG(DEBUG_LOWPROBE,
- printf("failed to prepare a device for low-probing\n"));
+ DBG(LOWPROBE, blkid_debug("failed to prepare a device for low-probing"));
return -1;
}
if (!pr)
return -1;
- DBG(DEBUG_LOWPROBE, printf(
+ DBG(LOWPROBE, blkid_debug(
"changing probing area pr=%p: size=%llu, off=%llu "
- "-to-> size=%llu, off=%llu\n",
+ "-to-> size=%llu, off=%llu",
pr,
(unsigned long long) pr->size,
(unsigned long long) pr->off,
if (buf && !memcmp(mag->magic,
buf + (mag->sboff & 0x3ff), mag->len)) {
- DBG(DEBUG_LOWPROBE, printf(
- "\tmagic sboff=%u, kboff=%ld\n",
+ DBG(LOWPROBE, blkid_debug("\tmagic sboff=%u, kboff=%ld",
mag->sboff, mag->kboff));
if (offset)
*offset = off + (mag->sboff & 0x3ff);
static inline void blkid_probe_start(blkid_probe pr)
{
if (pr) {
- DBG(DEBUG_LOWPROBE, printf("%p: start probe\n", pr));
+ DBG(LOWPROBE, blkid_debug("%p: start probe", pr));
pr->cur_chain = NULL;
pr->prob_flags = 0;
blkid_probe_set_wiper(pr, 0, 0);
static inline void blkid_probe_end(blkid_probe pr)
{
if (pr) {
- DBG(DEBUG_LOWPROBE, printf("%p: end probe\n", pr));
+ DBG(LOWPROBE, blkid_debug("%p: end probe", pr));
pr->cur_chain = NULL;
pr->prob_flags = 0;
blkid_probe_set_wiper(pr, 0, 0);
chn->binary = FALSE; /* for sure... */
- DBG(DEBUG_LOWPROBE, printf("chain probe %s %s (idx=%d)\n",
+ DBG(LOWPROBE, blkid_debug("chain probe %s %s (idx=%d)",
chn->driver->name,
chn->enabled? "ENABLED" : "DISABLED",
chn->idx));
if (len > sizeof(buf))
len = sizeof(buf);
- DBG(DEBUG_LOWPROBE, printf(
+ DBG(LOWPROBE, blkid_debug(
"do_wipe [offset=0x%jx, len=%zd, chain=%s, idx=%d, dryrun=%s]\n",
offset, len, chn->driver->name, chn->idx, dryrun ? "yes" : "not"));
if (chn->idx >= 0) {
chn->idx--;
- DBG(DEBUG_LOWPROBE,
- printf("step back: moving %s chain index to %d\n",
+ DBG(LOWPROBE, blkid_debug("step back: moving %s chain index to %d",
chn->driver->name,
chn->idx));
}
*/
size_t idx = chn->driver->id > 0 ? chn->driver->id - 1 : 0;
- DBG(DEBUG_LOWPROBE, printf("step back: moving to previous chain\n"));
+ DBG(LOWPROBE, blkid_debug("step back: moving to previous chain"));
if (idx > 0)
pr->cur_chain = &pr->chains[idx];
chn = pr->cur_chain = &pr->chains[i];
chn->binary = FALSE; /* for sure... */
- DBG(DEBUG_LOWPROBE, printf("chain safeprobe %s %s\n",
+ DBG(LOWPROBE, blkid_debug("chain safeprobe %s %s",
chn->driver->name,
chn->enabled? "ENABLED" : "DISABLED"));
chn = pr->cur_chain = &pr->chains[i];
chn->binary = FALSE; /* for sure... */
- DBG(DEBUG_LOWPROBE, printf("chain fullprobe %s: %s\n",
+ DBG(LOWPROBE, blkid_debug("chain fullprobe %s: %s",
chn->driver->name,
chn->enabled? "ENABLED" : "DISABLED"));
v->chain = pr->cur_chain;
pr->nvals++;
- DBG(DEBUG_LOWPROBE,
- printf("assigning %s [%s]\n", name, v->chain->driver->name));
+ DBG(LOWPROBE, blkid_debug("assigning %s [%s]", name, v->chain->driver->name));
return v;
}
v = &pr->vals[pr->nvals - 1];
- DBG(DEBUG_LOWPROBE,
- printf("un-assigning %s [%s]\n", v->name, v->chain->driver->name));
+ DBG(LOWPROBE, blkid_debug("un-assigning %s [%s]", v->name, v->chain->driver->name));
memset(v, 0, sizeof(struct blkid_prval));
pr->nvals--;
if (!disk_path)
return NULL;
- DBG(DEBUG_LOWPROBE, printf("allocate a wholedisk probe\n"));
+ DBG(LOWPROBE, blkid_debug("allocate a wholedisk probe"));
pr->disk_probe = blkid_new_probe_from_filename(disk_path);
if (len)
*len = v->len;
- DBG(DEBUG_LOWPROBE, printf("returning %s value\n", v->name));
+ DBG(LOWPROBE, blkid_debug("returning %s value", v->name));
return 0;
}
struct blkid_prval *v = &pr->vals[i];
if (v->name && strcmp(name, v->name) == 0) {
- DBG(DEBUG_LOWPROBE, printf("returning %s value\n", v->name));
+ DBG(LOWPROBE, blkid_debug("returning %s value", v->name));
return v;
}
}
return;
if (!size) {
- DBG(DEBUG_LOWPROBE, printf("zeroize wiper\n"));
+ DBG(LOWPROBE, blkid_debug("zeroize wiper"));
pr->wipe_size = pr->wipe_off = 0;
pr->wipe_chain = NULL;
return;
pr->wipe_off = off;
pr->wipe_chain = chn;
- DBG(DEBUG_LOWPROBE,
- printf("wiper set to %s::%s off=%jd size=%jd\n",
+ DBG(LOWPROBE,
+ blkid_debug("wiper set to %s::%s off=%jd size=%jd",
chn->driver->name,
chn->driver->idinfos[chn->idx]->name,
pr->wipe_off, pr->wipe_size));
struct blkid_chain *chn = NULL;
if (blkid_probe_is_wiped(pr, &chn, off, size) && chn) {
- DBG(DEBUG_LOWPROBE, printf("previously wiped area modified "
- " -- ignore previous results\n"));
+ DBG(LOWPROBE, blkid_debug("previously wiped area modified "
+ " -- ignore previous results"));
blkid_probe_set_wiper(pr, 0, 0);
blkid_probe_chain_reset_vals(pr, chn);
}
return 0;
if (!strncmp(p, "<device", 7)) {
- DBG(DEBUG_READ, printf("found device header: %8s\n", p));
+ DBG(READ, blkid_debug("found device header: %8s", p));
p += 7;
*cp = p;
*cp = skip_over_blank(*cp);
if (!strncmp(*cp, "</device>", 9)) {
- DBG(DEBUG_READ, printf("found device trailer %9s\n", *cp));
+ DBG(READ, blkid_debug("found device trailer %9s", *cp));
*cp += 9;
return 0;
}
start = tmp = strchr(*cp, '>');
if (!start) {
- DBG(DEBUG_READ,
- printf("blkid: short line parsing dev: %s\n", *cp));
+ DBG(READ, blkid_debug("blkid: short line parsing dev: %s", *cp));
return -BLKID_ERR_CACHE;
}
start = skip_over_blank(start + 1);
end = skip_over_word(start);
- DBG(DEBUG_READ, printf("device should be %*s\n",
+ DBG(READ, blkid_debug("device should be %*s",
(int)(end - start), start));
if (**cp == '>')
*tmp = '\0';
if (!(tmp = strrchr(end, '<')) || parse_end(&tmp) < 0) {
- DBG(DEBUG_READ,
- printf("blkid: missing </device> ending: %s\n", end));
+ DBG(READ, blkid_debug("blkid: missing </device> ending: %s", end));
} else if (tmp)
*tmp = '\0';
if (end - start <= 1) {
- DBG(DEBUG_READ, printf("blkid: empty device name: %s\n", *cp));
+ DBG(READ, blkid_debug("blkid: empty device name: %s", *cp));
return -BLKID_ERR_CACHE;
}
if (name == NULL)
return -BLKID_ERR_MEM;
- DBG(DEBUG_READ, printf("found dev %s\n", name));
+ DBG(READ, blkid_debug("found dev %s", name));
if (!(*dev = blkid_get_dev(cache, name, BLKID_DEV_CREATE))) {
free(name);
if (**value == '"') {
end = strchr(*value + 1, '"');
if (!end) {
- DBG(DEBUG_READ,
- printf("unbalanced quotes at: %s\n", *value));
+ DBG(READ, blkid_debug("unbalanced quotes at: %s", *value));
*cp = *value;
return -BLKID_ERR_CACHE;
}
} else
ret = blkid_set_tag(dev, name, value, strlen(value));
- DBG(DEBUG_READ, printf(" tag: %s=\"%s\"\n", name, value));
+ DBG(READ, blkid_debug(" tag: %s=\"%s\"", name, value));
return ret < 0 ? ret : 1;
}
*dev_p = NULL;
- DBG(DEBUG_READ, printf("line: %s\n", cp));
+ DBG(READ, blkid_debug("line: %s", cp));
if ((ret = parse_dev(cache, dev_p, &cp)) <= 0)
return ret;
}
if (dev->bid_type == NULL) {
- DBG(DEBUG_READ,
- printf("blkid: device %s has no TYPE\n",dev->bid_name));
+ DBG(READ, blkid_debug("blkid: device %s has no TYPE",dev->bid_name));
blkid_free_dev(dev);
goto done;
}
- DBG(DEBUG_READ, blkid_debug_dump_dev(dev));
+ DBG(READ, blkid_debug_dump_dev(dev));
done:
return ret;
goto errout;
if ((st.st_mtime == cache->bic_ftime) ||
(cache->bic_flags & BLKID_BIC_FL_CHANGED)) {
- DBG(DEBUG_CACHE, printf("skipping re-read of %s\n",
+ DBG(CACHE, blkid_debug("skipping re-read of %s",
cache->bic_filename));
goto errout;
}
- DBG(DEBUG_CACHE, printf("reading cache file %s\n",
+ DBG(CACHE, blkid_debug("reading cache file %s",
cache->bic_filename));
file = fdopen(fd, "r" UL_CLOEXECSTR);
}
if (blkid_parse_line(cache, &dev, buf) < 0) {
- DBG(DEBUG_READ,
- printf("blkid: bad format on line %d\n", lineno));
+ DBG(READ, blkid_debug("blkid: bad format on line %d", lineno));
continue;
}
}
blkid_cache cache = NULL;
int ret;
- blkid_init_debug(DEBUG_ALL);
+ blkid_init_debug(BLKID_DEBUG_ALL);
if (argc > 2) {
fprintf(stderr, "Usage: %s [filename]\n"
"Test parsing of the cache (filename)\n", argv[0]);
blkid_cache c = cache;
char *ret = NULL;
- DBG(DEBUG_RESOLVE, printf("looking for %s on %s\n", tagname, devname));
+ DBG(RESOLVE, blkid_debug("looking for %s on %s", tagname, devname));
if (!devname)
return NULL;
if (!cache && blkid_get_cache(&c, NULL) < 0)
return NULL;
- DBG(DEBUG_RESOLVE,
- printf("looking for %s%s%s %s\n", token, value ? "=" : "",
+ DBG(RESOLVE, blkid_debug("looking for %s%s%s %s", token, value ? "=" : "",
value ? value : "", cache ? "in cache" : "from disk"));
if (!value) {
char *value;
blkid_cache cache;
- blkid_init_debug(DEBUG_ALL);
+ blkid_init_debug(BLKID_DEBUG_ALL);
if (argc != 2 && argc != 3) {
fprintf(stderr, "Usage:\t%s tagname=value\n"
"\t%s tagname devname\n"
if (!dev || dev->bid_name[0] != '/')
return 0;
- DBG(DEBUG_SAVE,
- printf("device %s, type %s\n", dev->bid_name, dev->bid_type ?
+ DBG(SAVE, blkid_debug("device %s, type %s", dev->bid_name, dev->bid_type ?
dev->bid_type : "(null)"));
fprintf(file, "<device DEVNO=\"0x%04lx\" TIME=\"%ld.%ld\"",
if (list_empty(&cache->bic_devs) ||
!(cache->bic_flags & BLKID_BIC_FL_CHANGED)) {
- DBG(DEBUG_SAVE, printf("skipping cache file write\n"));
+ DBG(SAVE, blkid_debug("skipping cache file write"));
return 0;
}
S_IRUSR|S_IRGRP|S_IROTH|
S_IXUSR|S_IXGRP|S_IXOTH) != 0
&& errno != EEXIST) {
- DBG(DEBUG_SAVE,
- printf("can't create %s directory for cache file\n",
+ DBG(SAVE, blkid_debug("can't create %s directory for cache file",
BLKID_RUNTIME_DIR));
return 0;
}
/* If we can't write to the cache file, then don't even try */
if (((ret = stat(filename, &st)) < 0 && errno != ENOENT) ||
(ret == 0 && access(filename, W_OK) < 0)) {
- DBG(DEBUG_SAVE,
- printf("can't write to cache file %s\n", filename));
+ DBG(SAVE, blkid_debug("can't write to cache file %s", filename));
return 0;
}
fd = mkostemp(tmp, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC);
if (fd >= 0) {
if (fchmod(fd, 0644) != 0)
- DBG(DEBUG_SAVE, printf("%s: fchmod failed\n", filename));
+ DBG(SAVE, blkid_debug("%s: fchmod failed", filename));
else if ((file = fdopen(fd, "w" UL_CLOEXECSTR)))
opened = tmp;
if (!file)
opened = filename;
}
- DBG(DEBUG_SAVE,
- printf("writing cache file %s (really %s)\n",
+ DBG(SAVE, blkid_debug("writing cache file %s (really %s)",
filename, opened));
if (!file) {
if (opened != filename) {
if (ret < 0) {
unlink(opened);
- DBG(DEBUG_SAVE,
- printf("unlinked temp cache %s\n", opened));
+ DBG(SAVE, blkid_debug("unlinked temp cache %s", opened));
} else {
char *backup;
sprintf(backup, "%s.old", filename);
unlink(backup);
if (link(filename, backup)) {
- DBG(DEBUG_SAVE,
- printf("can't link %s to %s\n",
+ DBG(SAVE, blkid_debug("can't link %s to %s",
filename, backup));
}
free(backup);
}
if (rename(opened, filename)) {
ret = errno;
- DBG(DEBUG_SAVE,
- printf("can't rename %s to %s\n",
+ DBG(SAVE, blkid_debug("can't rename %s to %s",
opened, filename));
} else {
- DBG(DEBUG_SAVE,
- printf("moved temp cache %s\n", opened));
+ DBG(SAVE, blkid_debug("moved temp cache %s", opened));
}
}
}
blkid_cache cache = NULL;
int ret;
- blkid_init_debug(DEBUG_ALL);
+ blkid_init_debug(BLKID_DEBUG_ALL);
if (argc > 2) {
fprintf(stderr, "Usage: %s [filename]\n"
"Test loading/saving a cache (filename)\n", argv[0]);
struct btrfs_super_block *bfs;
if (mag->kboff > 64 && blkid_probe_ignore_backup(pr)) {
- DBG(DEBUG_LOWPROBE, printf("btrfs: found backup superblock, ignore\n"));
+ DBG(LOWPROBE, blkid_debug("btrfs: found backup superblock, ignore"));
return 1;
}
{
struct blkid_chain *chn = blkid_probe_get_chain(pr);
- DBG(DEBUG_PROBE, printf("ext2_sb.compat = %08X:%08X:%08X\n",
+ DBG(PROBE, blkid_debug("ext2_sb.compat = %08X:%08X:%08X",
le32_to_cpu(es->s_feature_compat),
le32_to_cpu(es->s_feature_incompat),
le32_to_cpu(es->s_feature_ro_compat)));
if (lvm2_calc_crc(&label->offset_xl, LVM2_LABEL_SIZE -
((char *) &label->offset_xl - (char *) label)) !=
le32_to_cpu(label->crc_xl)) {
- DBG(DEBUG_PROBE,
- printf("LVM2: label checksum incorrect at sector %d\n",
+ DBG(PROBE, blkid_debug("LVM2: label checksum incorrect at sector %d",
sector));
return 1;
}
off = le64_to_cpu(ns->mft_cluster_location) * sector_size *
sectors_per_cluster;
- DBG(DEBUG_LOWPROBE, printf("NTFS: sector_size=%d, mft_record_size=%d, "
+ DBG(LOWPROBE, blkid_debug("NTFS: sector_size=%d, mft_record_size=%d, "
"sectors_per_cluster=%d, nr_clusters=%ju "
- "cluster_offset=%jd\n",
+ "cluster_offset=%jd",
(int) sector_size, mft_record_size,
sectors_per_cluster, nr_clusters,
off));
if (sil->disk_number >= 8)
return -1;
if (!checksum(sil)) {
- DBG(DEBUG_LOWPROBE, printf("silicon raid: incorrect checksum\n"));
+ DBG(LOWPROBE, blkid_debug("silicon raid: incorrect checksum"));
return -1;
}
} else if (flag & BLKID_FLTR_ONLYIN)
blkid_bmp_set_item(chn->fltr, i);
}
- DBG(DEBUG_LOWPROBE, printf("a new probing usage-filter initialized\n"));
+ DBG(LOWPROBE, blkid_debug("a new probing usage-filter initialized"));
return 0;
}
return -1;
blkid_probe_chain_reset_vals(pr, chn);
- DBG(DEBUG_LOWPROBE,
- printf("--> starting probing loop [SUBLKS idx=%d]\n",
+ DBG(LOWPROBE, blkid_debug("--> starting probing loop [SUBLKS idx=%d]",
chn->idx));
if (pr->size <= 0 || (pr->size <= 1024 && !S_ISCHR(pr->mode)))
id = idinfos[i];
if (chn->fltr && blkid_bmp_get_item(chn->fltr, i)) {
- DBG(DEBUG_LOWPROBE, printf("filter out: %s\n", id->name));
+ DBG(LOWPROBE, blkid_debug("filter out: %s", id->name));
continue;
}
if ((id->usage & BLKID_USAGE_RAID) && blkid_probe_is_tiny(pr))
continue;
- DBG(DEBUG_LOWPROBE, printf("[%zd] %s:\n", i, id->name));
+ DBG(LOWPROBE, blkid_debug("[%zd] %s:", i, id->name));
if (blkid_probe_get_idmag(pr, id, &off, &mag))
continue;
/* final check by probing function */
if (id->probefunc) {
- DBG(DEBUG_LOWPROBE, printf("\tcall probefunc()\n"));
+ DBG(LOWPROBE, blkid_debug("\tcall probefunc()"));
if (id->probefunc(pr, mag) != 0) {
blkid_probe_chain_reset_vals(pr, chn);
continue;
(unsigned char *) mag->magic);
if (rc) {
blkid_probe_chain_reset_vals(pr, chn);
- DBG(DEBUG_LOWPROBE, printf("failed to set result -- ingnore\n"));
+ DBG(LOWPROBE, blkid_debug("failed to set result -- ingnore"));
continue;
}
- DBG(DEBUG_LOWPROBE,
- printf("<-- leaving probing loop (type=%s) [SUBLKS idx=%d]\n",
+ DBG(LOWPROBE, blkid_debug("<-- leaving probing loop (type=%s) [SUBLKS idx=%d]",
id->name, chn->idx));
return 0;
}
nothing:
- DBG(DEBUG_LOWPROBE,
- printf("<-- leaving probing loop (failed) [SUBLKS idx=%d]\n",
+ DBG(LOWPROBE, blkid_debug("<-- leaving probing loop (failed) [SUBLKS idx=%d]",
chn->idx));
return 1;
}
return rc; /* error */
if (count > 1 && intol) {
- DBG(DEBUG_LOWPROBE,
- printf("ERROR: superblocks chain: "
- "ambivalent result detected (%d filesystems)!\n",
+ DBG(LOWPROBE, blkid_debug("ERROR: superblocks chain: "
+ "ambivalent result detected (%d filesystems)!",
count));
return -2; /* error, ambivalent result (more FS) */
}
struct vfat_dir_entry *ent, *dir = NULL;
uint32_t i;
- DBG(DEBUG_LOWPROBE,
- printf("\tlook for label in root-dir "
- "(entries: %d, offset: %jd)\n", entries, offset));
+ DBG(LOWPROBE, blkid_debug("\tlook for label in root-dir "
+ "(entries: %d, offset: %jd)", entries, offset));
if (!blkid_probe_is_tiny(pr)) {
/* large disk, read whole root directory */
if ((ent->attr & (FAT_ATTR_VOLUME_ID | FAT_ATTR_DIR)) ==
FAT_ATTR_VOLUME_ID) {
- DBG(DEBUG_LOWPROBE,
- printf("\tfound fs LABEL at entry %d\n", i));
+ DBG(LOWPROBE, blkid_debug("\tfound fs LABEL at entry %d", i));
return ent->name;
}
}
};
#define nvdebug(fmt, ...) do { } while(0)
-/*#define nvdebug(fmt, a...) printf(fmt, ##a)*/
+/*#define nvdebug(fmt, a...) fprintf(stderr, fmt, ##a)*/
static void zfs_extract_guid_name(blkid_probe pr, loff_t offset)
{
}
#define zdebug(fmt, ...) do {} while(0)
-/*#define zdebug(fmt, a...) printf(fmt, ##a)*/
+/*#define zdebug(fmt, a...) fprintf(stderr, fmt, ##a)*/
/* ZFS has 128x1kB host-endian root blocks, stored in 2 areas at the start
* of the disk, and 2 areas at the end of the disk. Check only some of them...
void blkid_debug_dump_tag(blkid_tag tag)
{
if (!tag) {
- printf(" tag: NULL\n");
+ fprintf(stderr, " tag: NULL\n");
return;
}
- printf(" tag: %s=\"%s\"\n", tag->bit_name, tag->bit_val);
+ fprintf(stderr, " tag: %s=\"%s\"\n", tag->bit_name, tag->bit_val);
}
#endif
if (!tag)
return;
- DBG(DEBUG_TAG, printf(" freeing tag %s=%s\n", tag->bit_name,
+ DBG(TAG, blkid_debug(" freeing tag %s=%s", tag->bit_name,
tag->bit_val ? tag->bit_val : "(NULL)"));
- DBG(DEBUG_TAG, blkid_debug_dump_tag(tag));
+ DBG(TAG, blkid_debug_dump_tag(tag));
list_del(&tag->bit_tags); /* list of tags for this device */
list_del(&tag->bit_names); /* list of tags with this type */
list_for_each(p, &cache->bic_tags) {
tmp = list_entry(p, struct blkid_struct_tag, bit_tags);
if (!strcmp(tmp->bit_name, type)) {
- DBG(DEBUG_TAG,
- printf(" found cache tag head %s\n", type));
+ DBG(TAG, blkid_debug(" found cache tag head %s", type));
head = tmp;
break;
}
if (!head)
goto errout;
- DBG(DEBUG_TAG,
- printf(" creating new cache tag head %s\n", name));
+ DBG(TAG, blkid_debug(" creating new cache tag head %s", name));
head->bit_name = name ? strdup(name) : NULL;
if (!head->bit_name)
goto errout;
{
char *name, *value, *cp;
- DBG(DEBUG_TAG, printf("trying to parse '%s' as a tag\n", token));
+ DBG(TAG, blkid_debug("trying to parse '%s' as a tag", token));
if (!token || !(cp = strchr(token, '=')))
return -1;
blkid_read_cache(cache);
- DBG(DEBUG_TAG, printf("looking for %s=%s in cache\n", type, value));
+ DBG(TAG, blkid_debug("looking for %s=%s in cache", type, value));
try_again:
pri = -1;
if (!cmd)
goto nothing;
if (pipe(dmpipe) < 0) {
- DBG(DEBUG_LOWPROBE,
- printf("Failed to open pipe: errno=%d", errno));
+ DBG(LOWPROBE, blkid_debug("Failed to open pipe: errno=%d", errno));
goto nothing;
}
execv(dmargv[0], dmargv);
- DBG(DEBUG_LOWPROBE,
- printf("Failed to execute %s: errno=%d", cmd, errno));
+ DBG(LOWPROBE, blkid_debug("Failed to execute %s: errno=%d", cmd, errno));
exit(1);
}
case -1:
- DBG(DEBUG_LOWPROBE,
- printf("Failed to forking: errno=%d", errno));
+ DBG(LOWPROBE, blkid_debug("Failed to forking: errno=%d", errno));
goto nothing;
default:
break;
goto nothing;
if (pipe(lvpipe) < 0) {
- DBG(DEBUG_LOWPROBE,
- printf("Failed to open pipe: errno=%d", errno));
+ DBG(LOWPROBE, blkid_debug("Failed to open pipe: errno=%d", errno));
goto nothing;
}
execv(lvargv[0], lvargv);
- DBG(DEBUG_LOWPROBE,
- printf("Failed to execute %s: errno=%d", cmd, errno));
+ DBG(LOWPROBE, blkid_debug("Failed to execute %s: errno=%d", cmd, errno));
exit(1);
}
case -1:
- DBG(DEBUG_LOWPROBE,
- printf("Failed to forking: errno=%d", errno));
+ DBG(LOWPROBE, blkid_debug("Failed to forking: errno=%d", errno));
goto nothing;
default:
break;
return -1; /* nothing, works with block devices only */
if (chn->binary) {
- DBG(DEBUG_LOWPROBE, printf("initialize topology binary data\n"));
+ DBG(LOWPROBE, blkid_debug("initialize topology binary data"));
if (chn->data)
/* reset binary data */
blkid_probe_chain_reset_vals(pr, chn);
- DBG(DEBUG_LOWPROBE,
- printf("--> starting probing loop [TOPOLOGY idx=%d]\n",
+ DBG(LOWPROBE, blkid_debug("--> starting probing loop [TOPOLOGY idx=%d]",
chn->idx));
i = chn->idx < 0 ? 0 : chn->idx + 1U;
chn->idx = i;
if (id->probefunc) {
- DBG(DEBUG_LOWPROBE, printf(
- "%s: call probefunc()\n", id->name));
+ DBG(LOWPROBE, blkid_debug("%s: call probefunc()", id->name));
if (id->probefunc(pr, NULL) != 0)
continue;
}
/* generic for all probing drivers */
topology_set_logical_sector_size(pr);
- DBG(DEBUG_LOWPROBE,
- printf("<-- leaving probing loop (type=%s) [TOPOLOGY idx=%d]\n",
+ DBG(LOWPROBE, blkid_debug("<-- leaving probing loop (type=%s) [TOPOLOGY idx=%d]",
id->name, chn->idx));
return 0;
}
- DBG(DEBUG_LOWPROBE,
- printf("<-- leaving probing loop (failed) [TOPOLOGY idx=%d]\n",
+ DBG(LOWPROBE, blkid_debug("<-- leaving probing loop (failed) [TOPOLOGY idx=%d]",
chn->idx));
return 1;
}
diff = now - dev->bid_time;
if (stat(dev->bid_name, &st) < 0) {
- DBG(DEBUG_PROBE,
- printf("blkid_verify: error %m (%d) while "
- "trying to stat %s\n", errno,
+ DBG(PROBE, blkid_debug("blkid_verify: error %m (%d) while "
+ "trying to stat %s", errno,
dev->bid_name));
open_err:
if ((errno == EPERM) || (errno == EACCES) || (errno == ENOENT)) {
/* We don't have read permission, just return cache data. */
- DBG(DEBUG_PROBE, printf("returning unverified data for %s\n",
+ DBG(PROBE, blkid_debug("returning unverified data for %s",
dev->bid_name));
return dev;
}
return dev;
#ifndef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
- DBG(DEBUG_PROBE,
- printf("need to revalidate %s (cache time %lu, stat time %lu,\n\t"
- "time since last check %lu)\n",
+ DBG(PROBE, blkid_debug("need to revalidate %s (cache time %lu, stat time %lu,\t"
+ "time since last check %lu)",
dev->bid_name, (unsigned long)dev->bid_time,
(unsigned long)st.st_mtime, (unsigned long)diff));
#else
- DBG(DEBUG_PROBE,
- printf("need to revalidate %s (cache time %lu.%lu, stat time %lu.%lu,\n\t"
- "time since last check %lu)\n",
+ DBG(PROBE, blkid_debug("need to revalidate %s (cache time %lu.%lu, stat time %lu.%lu,\t"
+ "time since last check %lu)",
dev->bid_name,
(unsigned long)dev->bid_time, (unsigned long)dev->bid_utime,
(unsigned long)st.st_mtime, (unsigned long)st.st_mtim.tv_nsec / 1000,
fd = open(dev->bid_name, O_RDONLY|O_CLOEXEC);
if (fd < 0) {
- DBG(DEBUG_PROBE, printf("blkid_verify: error %m (%d) while "
- "opening %s\n", errno,
+ DBG(PROBE, blkid_debug("blkid_verify: error %m (%d) while "
+ "opening %s", errno,
dev->bid_name));
goto open_err;
}
blkid_probe_to_tags(cache->probe, dev);
- DBG(DEBUG_PROBE, printf("%s: devno 0x%04llx, type %s\n",
+ DBG(PROBE, blkid_debug("%s: devno 0x%04llx, type %s",
dev->bid_name, (long long)st.st_rdev, dev->bid_type));
}