mirror of https://github.com/vitalif/e2fsprogs
Add dynamic debugging capabilities to the blkid library,
controlled by the environment variable BLKID_DEBUG. The debugging code is enabled by a new configuration option, --enable-blkid-debug.bitmap-optimize
parent
98999c399d
commit
f0a22d0fd3
|
@ -1,3 +1,8 @@
|
|||
2003-02-22 Theodore Ts'o <tytso@mit.edu>
|
||||
|
||||
* configure.in, configure: Add new configure option
|
||||
--enable-blkid-debug
|
||||
|
||||
2003-01-23 Theodore Ts'o <tytso@mit.edu>
|
||||
|
||||
* Makefile.in, configure, configure.in: Integrate new blkid library.
|
||||
|
|
15
configure.in
15
configure.in
|
@ -334,6 +334,21 @@ fi
|
|||
echo "Disabling journal debugging by default"
|
||||
)
|
||||
dnl
|
||||
dnl handle --enable-blkid-debug
|
||||
dnl
|
||||
AC_ARG_ENABLE([blkid-debug],
|
||||
[ --enable-blkid-debug enable blkid debugging],
|
||||
if test "$enableval" = "no"
|
||||
then
|
||||
echo "Disabling blkid debugging"
|
||||
else
|
||||
AC_DEFINE(CONFIG_BLKID_DEBUG)
|
||||
echo "Enabling blkid debugging"
|
||||
fi
|
||||
,
|
||||
echo "Disabling blkid debugging by default"
|
||||
)
|
||||
dnl
|
||||
dnl handle --enable-swapfs
|
||||
dnl
|
||||
AC_ARG_ENABLE([swapfs],
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
2003-02-22 Theodore Ts'o <tytso@mit.edu>
|
||||
|
||||
* cache.c, dev.c, devname.c, devno.c, probe.c, read.c, resolve.c,
|
||||
save.c, tag.c, blkidP.h: Add dynamic debugging
|
||||
capabilities, controlled by the environment variable
|
||||
BLKID_DEBUG.
|
||||
|
||||
2003-02-16 Theodore Ts'o <tytso@mit.edu>
|
||||
|
||||
* blkid.h, dev.c, devname.c, probe.c, read.c, resolve.c: Rename
|
||||
|
|
|
@ -104,7 +104,7 @@ tst_save: $(srcdir)/save.c $(DEPLIBS_BLKID)
|
|||
blkid: ../../misc/blkid.o libblkid.a $(LIBUUID)
|
||||
$(CC) -Wall -o blkid ../../misc/blkid.o libblkid.a $(LIBUUID)
|
||||
|
||||
check:: tst_cache tst_devname tst_devno tst_getsize tst_probe \
|
||||
check:: all tst_cache tst_devname tst_devno tst_getsize tst_probe \
|
||||
tst_read tst_resolve tst_save
|
||||
|
||||
installdirs::
|
||||
|
|
|
@ -116,31 +116,37 @@ extern const char *blkid_devdirs[];
|
|||
#define BLKID_PRI_LVM 20
|
||||
#define BLKID_PRI_MD 10
|
||||
|
||||
#if defined(TEST_PROGRAM)
|
||||
#define DEBUG
|
||||
#if defined(TEST_PROGRAM) && !defined(CONFIG_BLKID_DEBUG)
|
||||
#define CONFIG_BLKID_DEBUG
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_CACHE
|
||||
#define DEBUG_DUMP
|
||||
#define DEBUG_DEV
|
||||
#define DEBUG_DEVNAME
|
||||
#define DEBUG_DEVNO
|
||||
#define DEBUG_PROBE
|
||||
#define DEBUG_READ
|
||||
#define DEBUG_RESOLVE
|
||||
#define DEBUG_SAVE
|
||||
#define DEBUG_TAG
|
||||
#define CHECK_TAG
|
||||
#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_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
|
||||
|
||||
#if defined(TEST_PROGRAM) && !defined(DEBUG_DUMP)
|
||||
#define DEBUG_DUMP
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_DUMP
|
||||
static inline void DEB_DUMP_TAG(blkid_tag tag)
|
||||
#ifdef CONFIG_BLKID_DEBUG
|
||||
static inline void DEB_DUMP_TAG(int mask, blkid_tag tag)
|
||||
{
|
||||
if (!(mask & blkid_debug_mask))
|
||||
return;
|
||||
|
||||
if (!tag) {
|
||||
printf(" tag: NULL\n");
|
||||
return;
|
||||
|
@ -149,10 +155,13 @@ static inline void DEB_DUMP_TAG(blkid_tag tag)
|
|||
printf(" tag: %s=\"%s\"\n", tag->bit_name, tag->bit_val);
|
||||
}
|
||||
|
||||
static inline void DEB_DUMP_DEV(blkid_dev dev)
|
||||
static inline void DEB_DUMP_DEV(int mask, blkid_dev dev)
|
||||
{
|
||||
struct list_head *p;
|
||||
|
||||
if (!(mask & blkid_debug_mask))
|
||||
return;
|
||||
|
||||
if (!dev) {
|
||||
printf(" dev: NULL\n");
|
||||
return;
|
||||
|
@ -166,16 +175,16 @@ static inline void DEB_DUMP_DEV(blkid_dev dev)
|
|||
|
||||
list_for_each(p, &dev->bid_tags) {
|
||||
blkid_tag tag = list_entry(p, struct blkid_struct_tag, bit_tags);
|
||||
DEB_DUMP_TAG(tag);
|
||||
DEB_DUMP_TAG(mask, tag);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static inline void DEB_DUMP_CACHE(blkid_cache cache)
|
||||
static inline void DEB_DUMP_CACHE(int mask, blkid_cache cache)
|
||||
{
|
||||
struct list_head *p;
|
||||
|
||||
if (!cache) {
|
||||
if (!cache || !(mask & blkid_debug_mask)) {
|
||||
printf("cache: NULL\n");
|
||||
return;
|
||||
}
|
||||
|
@ -185,13 +194,13 @@ static inline void DEB_DUMP_CACHE(blkid_cache cache)
|
|||
|
||||
list_for_each(p, &cache->bic_devs) {
|
||||
blkid_dev dev = list_entry(p, struct blkid_struct_dev, bid_devs);
|
||||
DEB_DUMP_DEV(dev);
|
||||
DEB_DUMP_DEV(mask, dev);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define DEB_DUMP_TAG(tag) do {} while (0)
|
||||
#define DEB_DUMP_DEV(dev) do {} while (0)
|
||||
#define DEB_DUMP_CACHE(cache) do {} while (0)
|
||||
#define DEB_DUMP_TAG(mask, tag) do {} while (0)
|
||||
#define DEB_DUMP_DEV(mask, dev) do {} while (0)
|
||||
#define DEB_DUMP_CACHE(mask, cache) do {} while (0)
|
||||
#endif
|
||||
|
||||
/* lseek.c */
|
||||
|
|
|
@ -13,17 +13,24 @@
|
|||
#include <stdlib.h>
|
||||
#include "blkidP.h"
|
||||
|
||||
#ifdef DEBUG_CACHE
|
||||
#include <stdio.h>
|
||||
#define DBG(x) x
|
||||
#else
|
||||
#define DBG(x)
|
||||
#endif
|
||||
int blkid_debug_mask;
|
||||
|
||||
blkid_cache blkid_new_cache(void)
|
||||
{
|
||||
blkid_cache cache;
|
||||
|
||||
#ifdef CONFIG_BLKID_DEBUG
|
||||
if (!(blkid_debug_mask & DEBUG_INIT)) {
|
||||
char *dstr = getenv("BLKID_DEBUG");
|
||||
|
||||
if (dstr)
|
||||
blkid_debug_mask = strtoul(dstr, 0, 0);
|
||||
blkid_debug_mask |= DEBUG_INIT;
|
||||
}
|
||||
#endif
|
||||
|
||||
DBG(DEBUG_CACHE, printf("initializing empty cache\n"));
|
||||
|
||||
if (!(cache = (blkid_cache) calloc(1, sizeof(struct blkid_struct_cache))))
|
||||
return NULL;
|
||||
|
||||
|
@ -40,7 +47,7 @@ void blkid_put_cache(blkid_cache cache)
|
|||
|
||||
(void) blkid_flush_cache(cache);
|
||||
|
||||
DBG(printf("freeing cache struct\n"));
|
||||
DBG(DEBUG_CACHE, printf("freeing cache struct\n"));
|
||||
|
||||
/* DEB_DUMP_CACHE(cache); */
|
||||
|
||||
|
@ -61,8 +68,8 @@ void blkid_put_cache(blkid_cache cache)
|
|||
struct blkid_struct_tag,
|
||||
bit_names);
|
||||
|
||||
DBG(printf("warning: unfreed tag %s=%s\n",
|
||||
bad->bit_name, bad->bit_val));
|
||||
DBG(DEBUG_CACHE, printf("warning: unfreed tag %s=%s\n",
|
||||
bad->bit_name, bad->bit_val));
|
||||
blkid_free_tag(bad);
|
||||
}
|
||||
blkid_free_tag(tag);
|
||||
|
@ -79,6 +86,7 @@ int main(int argc, char** argv)
|
|||
blkid_cache cache = NULL;
|
||||
int ret;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if ((argc > 2)) {
|
||||
fprintf(stderr, "Usage: %s [filename] \n", argv[0]);
|
||||
exit(1);
|
||||
|
|
|
@ -15,13 +15,6 @@
|
|||
|
||||
#include "blkidP.h"
|
||||
|
||||
#ifdef DEBUG_DEV
|
||||
#include <stdio.h>
|
||||
#define DBG(x) x
|
||||
#else
|
||||
#define DBG(x)
|
||||
#endif
|
||||
|
||||
blkid_dev blkid_new_dev(void)
|
||||
{
|
||||
blkid_dev dev;
|
||||
|
@ -40,8 +33,9 @@ void blkid_free_dev(blkid_dev dev)
|
|||
if (!dev)
|
||||
return;
|
||||
|
||||
DBG(printf(" freeing dev %s (%s)\n", dev->bid_name, dev->bid_type));
|
||||
DEB_DUMP_DEV(dev);
|
||||
DBG(DEBUG_DEV,
|
||||
printf(" freeing dev %s (%s)\n", dev->bid_name, dev->bid_type));
|
||||
DEB_DUMP_DEV(DEBUG_DEV, dev);
|
||||
|
||||
list_del(&dev->bid_devs);
|
||||
while (!list_empty(&dev->bid_tags)) {
|
||||
|
|
|
@ -35,13 +35,6 @@
|
|||
|
||||
#include "blkidP.h"
|
||||
|
||||
/* #define DEBUG_DEVNAME */
|
||||
#ifdef DEBUG_DEVNAME
|
||||
#define DBG(x) x
|
||||
#else
|
||||
#define DBG(x)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Find a dev struct in the cache by device name, if available.
|
||||
*
|
||||
|
@ -61,7 +54,8 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
|
|||
if (strcmp(tmp->bid_name, devname))
|
||||
continue;
|
||||
|
||||
DBG(printf("found devname %s in cache\n", tmp->bid_name));
|
||||
DBG(DEBUG_DEVNAME,
|
||||
printf("found devname %s in cache\n", tmp->bid_name));
|
||||
dev = tmp;
|
||||
break;
|
||||
}
|
||||
|
@ -157,10 +151,10 @@ static dev_t lvm_get_devno(const char *lvm_device)
|
|||
int ma, mi;
|
||||
dev_t ret = 0;
|
||||
|
||||
DBG(printf("opening %s\n", lvm_device));
|
||||
DBG(DEBUG_DEVNAME, printf("opening %s\n", lvm_device));
|
||||
if ((lvf = fopen(lvm_device, "r")) == NULL) {
|
||||
DBG(printf("%s: (%d) %s\n", lvm_device, errno,
|
||||
strerror(errno)));
|
||||
DBG(DEBUG_DEVNAME, printf("%s: (%d) %s\n", lvm_device, errno,
|
||||
strerror(errno)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -185,7 +179,7 @@ static void lvm_probe_all(blkid_cache cache)
|
|||
if ((vg_list = opendir(VG_DIR)) == NULL)
|
||||
return;
|
||||
|
||||
DBG(printf("probing LVM devices under %s\n", VG_DIR));
|
||||
DBG(DEBUG_DEVNAME, printf("probing LVM devices under %s\n", VG_DIR));
|
||||
|
||||
while ((vg_iter = readdir(vg_list)) != NULL) {
|
||||
DIR *lv_list;
|
||||
|
@ -223,8 +217,9 @@ static void lvm_probe_all(blkid_cache cache)
|
|||
lv_name);
|
||||
dev = lvm_get_devno(lvm_device);
|
||||
sprintf(lvm_device, "%s/%s", vg_name, lv_name);
|
||||
DBG(printf("LVM dev %s: devno 0x%04X\n",
|
||||
lvm_device, dev));
|
||||
DBG(DEBUG_DEVNAME, printf("LVM dev %s: devno 0x%04X\n",
|
||||
lvm_device,
|
||||
(unsigned int) dev));
|
||||
probe_one(cache, lvm_device, dev, BLKID_PRI_LVM);
|
||||
free(lvm_device);
|
||||
}
|
||||
|
@ -253,8 +248,8 @@ evms_probe_all(blkid_cache cache)
|
|||
&ma, &mi, &sz, device) != 4)
|
||||
continue;
|
||||
|
||||
DBG(printf("Checking partition %s (%d, %d)\n",
|
||||
device, ma, mi));
|
||||
DBG(DEBUG_DEVNAME, printf("Checking partition %s (%d, %d)\n",
|
||||
device, ma, mi));
|
||||
|
||||
probe_one(cache, device, makedev(ma, mi), BLKID_PRI_EVMS);
|
||||
num++;
|
||||
|
@ -304,7 +299,7 @@ int blkid_probe_all(blkid_cache cache)
|
|||
continue;
|
||||
devs[which] = makedev(ma, mi);
|
||||
|
||||
DBG(printf("read partition name %s\n", ptname));
|
||||
DBG(DEBUG_DEVNAME, printf("read partition name %s\n", ptname));
|
||||
|
||||
/* Skip whole disk devs unless they have no partitions
|
||||
* If we don't have a partition on this dev, also
|
||||
|
@ -319,8 +314,9 @@ int blkid_probe_all(blkid_cache cache)
|
|||
|
||||
lens[which] = strlen(ptname);
|
||||
if (isdigit(ptname[lens[which] - 1])) {
|
||||
DBG(printf("partition dev %s, devno 0x%04X\n",
|
||||
ptname, devs[which]));
|
||||
DBG(DEBUG_DEVNAME,
|
||||
printf("partition dev %s, devno 0x%04X\n",
|
||||
ptname, (unsigned int) devs[which]));
|
||||
|
||||
if (sz > 1)
|
||||
probe_one(cache, ptname, devs[which], 0);
|
||||
|
@ -328,8 +324,9 @@ int blkid_probe_all(blkid_cache cache)
|
|||
lens[last] = 0;
|
||||
} else if (lens[last] && strncmp(ptnames[last], ptname,
|
||||
lens[last])) {
|
||||
DBG(printf("whole dev %s, devno 0x%04X\n",
|
||||
ptnames[last], devs[last]));
|
||||
DBG(DEBUG_DEVNAME,
|
||||
printf("whole dev %s, devno 0x%04X\n",
|
||||
ptnames[last], (unsigned int) devs[last]));
|
||||
probe_one(cache, ptnames[last], devs[last], 0);
|
||||
lens[last] = 0;
|
||||
}
|
||||
|
@ -351,6 +348,7 @@ int main(int argc, char **argv)
|
|||
{
|
||||
blkid_cache cache = NULL;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if (argc != 1) {
|
||||
fprintf(stderr, "Usage: %s\n"
|
||||
"Probe all devices and exit\n", argv[0]);
|
||||
|
|
|
@ -33,12 +33,6 @@
|
|||
|
||||
#include "blkidP.h"
|
||||
|
||||
#ifdef DEBUG_DEVNO
|
||||
#define DBG(x) x
|
||||
#else
|
||||
#define DBG(x)
|
||||
#endif
|
||||
|
||||
struct dir_list {
|
||||
char *name;
|
||||
struct dir_list *next;
|
||||
|
@ -130,7 +124,8 @@ static void scan_dir(char *dirname, dev_t devno, struct dir_list **list,
|
|||
add_to_dirlist(path, list);
|
||||
else if (S_ISBLK(st.st_mode) && st.st_rdev == devno) {
|
||||
*devname = blkid_strdup(path);
|
||||
DBG(printf("found 0x%Lx at %s (%p)\n", devno,
|
||||
DBG(DEBUG_DEVNO,
|
||||
printf("found 0x%Lx at %s (%p)\n", devno,
|
||||
path, *devname));
|
||||
break;
|
||||
}
|
||||
|
@ -164,7 +159,7 @@ char *blkid_devno_to_devname(dev_t devno)
|
|||
struct dir_list *current = list;
|
||||
|
||||
list = list->next;
|
||||
DBG(printf("directory %s\n", current->name));
|
||||
DBG(DEBUG_DEVNO, printf("directory %s\n", current->name));
|
||||
scan_dir(current->name, devno, &new_list, &devname);
|
||||
free(current->name);
|
||||
free(current);
|
||||
|
@ -182,11 +177,15 @@ char *blkid_devno_to_devname(dev_t devno)
|
|||
free_dirlist(&list);
|
||||
free_dirlist(&new_list);
|
||||
|
||||
if (!devname)
|
||||
DBG(printf("blkid: couldn't find devno 0x%04lx\n",
|
||||
if (!devname) {
|
||||
DBG(DEBUG_DEVNO,
|
||||
printf("blkid: couldn't find devno 0x%04lx\n",
|
||||
(unsigned long) devno));
|
||||
else
|
||||
DBG(printf("found devno 0x%04Lx as %s\n", devno, devname));
|
||||
} else {
|
||||
DBG(DEBUG_DEVNO,
|
||||
printf("found devno 0x%04Lx as %s\n", devno, devname));
|
||||
}
|
||||
|
||||
|
||||
return devname;
|
||||
}
|
||||
|
@ -199,6 +198,7 @@ int main(int argc, char** argv)
|
|||
dev_t devno;
|
||||
const char *errmsg = "Couldn't parse %s: %s\n";
|
||||
|
||||
blkid_debug_mask = 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",
|
||||
|
|
|
@ -31,13 +31,6 @@
|
|||
#include "uuid/uuid.h"
|
||||
#include "probe.h"
|
||||
|
||||
/* #define DEBUG_PROBE */
|
||||
#ifdef DEBUG_PROBE
|
||||
#define DBG(x) x
|
||||
#else
|
||||
#define DBG(x)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is a special case code to check for an MDRAID device. We do
|
||||
* this special since it requires checking for a superblock at the end
|
||||
|
@ -93,7 +86,7 @@ static int probe_ext2(int fd, blkid_cache cache, blkid_dev dev,
|
|||
|
||||
es = (struct ext2_super_block *)buf;
|
||||
|
||||
DBG(printf("ext2_sb.compat = %08X:%08X:%08X\n",
|
||||
DBG(DEBUG_PROBE, printf("ext2_sb.compat = %08X:%08X:%08X\n",
|
||||
blkid_le32(es->s_feature_compat),
|
||||
blkid_le32(es->s_feature_incompat),
|
||||
blkid_le32(es->s_feature_ro_compat)));
|
||||
|
@ -344,7 +337,8 @@ blkid_dev blkid_verify_devname(blkid_cache cache, blkid_dev dev)
|
|||
diff < BLKID_PROBE_INTERVAL))
|
||||
return dev;
|
||||
|
||||
DBG(printf("need to revalidate %s (time since last check %lu)\n",
|
||||
DBG(DEBUG_PROBE,
|
||||
printf("need to revalidate %s (time since last check %lu)\n",
|
||||
dev->bid_name, diff));
|
||||
|
||||
if (((fd = open(dev->bid_name, O_RDONLY)) < 0) ||
|
||||
|
@ -354,7 +348,9 @@ blkid_dev blkid_verify_devname(blkid_cache cache, blkid_dev dev)
|
|||
return NULL;
|
||||
}
|
||||
/* We don't have read permission, just return cache data. */
|
||||
DBG(printf("returning unverified data for %s\n", dev->bid_name));
|
||||
DBG(DEBUG_PROBE,
|
||||
printf("returning unverified data for %s\n",
|
||||
dev->bid_name));
|
||||
return dev;
|
||||
}
|
||||
|
||||
|
@ -436,7 +432,7 @@ found_type:
|
|||
if (sec_type)
|
||||
blkid_set_tag(dev, "TYPE", sec_type, 0, 0);
|
||||
|
||||
DBG(printf("%s: devno 0x%04Lx, type %s\n",
|
||||
DBG(DEBUG_PROBE, printf("%s: devno 0x%04Lx, type %s\n",
|
||||
dev->bid_name, st.st_rdev, type));
|
||||
}
|
||||
|
||||
|
@ -451,6 +447,7 @@ int main(int argc, char **argv)
|
|||
blkid_dev dev;
|
||||
blkid_cache cache;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s device\n"
|
||||
"Probe a single device to determine type\n", argv[0]);
|
||||
|
|
|
@ -23,12 +23,6 @@
|
|||
#include "blkidP.h"
|
||||
#include "uuid/uuid.h"
|
||||
|
||||
#ifdef DEBUG_CACHE
|
||||
#define DBG(x) x
|
||||
#else
|
||||
#define DBG(x)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRTOULL
|
||||
#define __USE_ISOC9X
|
||||
#define STRTOULL strtoull /* defined in stdlib.h if you try hard enough */
|
||||
|
@ -146,7 +140,7 @@ static int parse_start(char **cp)
|
|||
return 0;
|
||||
|
||||
if (!strncmp(p, "<device", 7)) {
|
||||
DBG(printf("found device header: %8s\n", p));
|
||||
DBG(DEBUG_READ, printf("found device header: %8s\n", p));
|
||||
p += 7;
|
||||
|
||||
*cp = p;
|
||||
|
@ -165,7 +159,7 @@ static int parse_end(char **cp)
|
|||
*cp = skip_over_blank(*cp);
|
||||
|
||||
if (!strncmp(*cp, "</device>", 9)) {
|
||||
DBG(printf("found device trailer %9s\n", *cp));
|
||||
DBG(DEBUG_READ, printf("found device trailer %9s\n", *cp));
|
||||
*cp += 9;
|
||||
return 0;
|
||||
}
|
||||
|
@ -189,13 +183,14 @@ static int parse_dev(blkid_cache cache, blkid_dev *dev, char **cp)
|
|||
|
||||
start = tmp = strchr(*cp, '>');
|
||||
if (!start) {
|
||||
DBG(printf("blkid: short line parsing dev: %s\n", *cp));
|
||||
DBG(DEBUG_READ,
|
||||
printf("blkid: short line parsing dev: %s\n", *cp));
|
||||
return -BLKID_ERR_CACHE;
|
||||
}
|
||||
start = skip_over_blank(start + 1);
|
||||
end = skip_over_word(start);
|
||||
|
||||
DBG(printf("device should be %*s\n", end - start, start));
|
||||
DBG(DEBUG_READ, printf("device should be %*s\n", end - start, start));
|
||||
|
||||
if (**cp == '>')
|
||||
*cp = end;
|
||||
|
@ -204,13 +199,14 @@ static int parse_dev(blkid_cache cache, blkid_dev *dev, char **cp)
|
|||
|
||||
*tmp = '\0';
|
||||
|
||||
if (!(tmp = strrchr(end, '<')) || parse_end(&tmp) < 0)
|
||||
DBG(printf("blkid: missing </device> ending: %s\n", end));
|
||||
else if (tmp)
|
||||
if (!(tmp = strrchr(end, '<')) || parse_end(&tmp) < 0) {
|
||||
DBG(DEBUG_READ,
|
||||
printf("blkid: missing </device> ending: %s\n", end));
|
||||
} else if (tmp)
|
||||
*tmp = '\0';
|
||||
|
||||
if (end - start <= 1) {
|
||||
DBG(printf("blkid: empty device name: %s\n", *cp));
|
||||
DBG(DEBUG_READ, printf("blkid: empty device name: %s\n", *cp));
|
||||
return -BLKID_ERR_CACHE;
|
||||
}
|
||||
|
||||
|
@ -218,7 +214,7 @@ static int parse_dev(blkid_cache cache, blkid_dev *dev, char **cp)
|
|||
if (name == NULL)
|
||||
return -BLKID_ERR_MEM;
|
||||
|
||||
DBG(printf("found dev %s\n", name));
|
||||
DBG(DEBUG_READ, printf("found dev %s\n", name));
|
||||
|
||||
if (!(*dev = blkid_get_dev(cache, name, BLKID_DEV_CREATE)))
|
||||
return -BLKID_ERR_MEM;
|
||||
|
@ -247,7 +243,8 @@ static int parse_token(char **name, char **value, char **cp)
|
|||
if (**value == '"') {
|
||||
end = strchr(*value + 1, '"');
|
||||
if (!end) {
|
||||
DBG(printf("unbalanced quotes at: %s\n", *value));
|
||||
DBG(DEBUG_READ,
|
||||
printf("unbalanced quotes at: %s\n", *value));
|
||||
*cp = *value;
|
||||
return -BLKID_ERR_CACHE;
|
||||
}
|
||||
|
@ -317,7 +314,7 @@ static int parse_tag(blkid_cache cache, blkid_dev dev, char **cp)
|
|||
else
|
||||
ret = blkid_set_tag(dev, name, value, strlen(value), 0);
|
||||
|
||||
DBG(printf(" tag: %s=\"%s\"\n", name, value));
|
||||
DBG(DEBUG_READ, printf(" tag: %s=\"%s\"\n", name, value));
|
||||
|
||||
return ret < 0 ? ret : 1;
|
||||
}
|
||||
|
@ -343,7 +340,7 @@ static int blkid_parse_line(blkid_cache cache, blkid_dev *dev_p, char *cp)
|
|||
|
||||
*dev_p = NULL;
|
||||
|
||||
DBG(printf("line: %s\n", cp));
|
||||
DBG(DEBUG_READ, printf("line: %s\n", cp));
|
||||
|
||||
if ((ret = parse_dev(cache, dev_p, &cp)) <= 0)
|
||||
return ret;
|
||||
|
@ -355,11 +352,12 @@ static int blkid_parse_line(blkid_cache cache, blkid_dev *dev_p, char *cp)
|
|||
}
|
||||
|
||||
if (dev->bid_type == NULL) {
|
||||
DBG(printf("blkid: device %s has no TYPE\n",dev->bid_name));
|
||||
DBG(DEBUG_READ,
|
||||
printf("blkid: device %s has no TYPE\n",dev->bid_name));
|
||||
blkid_free_dev(dev);
|
||||
}
|
||||
|
||||
DEB_DUMP_DEV(dev);
|
||||
DEB_DUMP_DEV(DEBUG_READ, dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -386,7 +384,8 @@ int blkid_get_cache(blkid_cache *cache, const char *filename)
|
|||
else
|
||||
(*cache)->bic_filename = blkid_strdup(filename);
|
||||
|
||||
DBG(printf("cache file %s\n", filename));
|
||||
DBG(DEBUG_READ|DEBUG_CACHE, printf("reading cache file %s\n",
|
||||
filename));
|
||||
|
||||
if (!strcmp(filename, "-"))
|
||||
file = stdin;
|
||||
|
@ -417,7 +416,8 @@ int blkid_get_cache(blkid_cache *cache, const char *filename)
|
|||
}
|
||||
|
||||
if (blkid_parse_line(*cache, &dev, buf) < 0) {
|
||||
DBG(printf("blkid: bad format on line %d\n", lineno));
|
||||
DBG(DEBUG_READ,
|
||||
printf("blkid: bad format on line %d\n", lineno));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -438,6 +438,7 @@ int main(int argc, char**argv)
|
|||
blkid_cache cache = NULL;
|
||||
int ret;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if (argc > 2) {
|
||||
fprintf(stderr, "Usage: %s [filename]\n"
|
||||
"Test parsing of the cache (filename)\n", argv[0]);
|
||||
|
|
|
@ -22,13 +22,6 @@
|
|||
#include "blkidP.h"
|
||||
#include "probe.h"
|
||||
|
||||
#ifdef DEBUG_RESOLVE
|
||||
#define DBG(x) x
|
||||
#else
|
||||
#define DBG(x)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Find a tagname (e.g. LABEL or UUID) on a specific device.
|
||||
*/
|
||||
|
@ -39,7 +32,7 @@ char *blkid_get_tagname_devname(blkid_cache cache, const char *tagname,
|
|||
blkid_dev dev;
|
||||
char *ret = NULL;
|
||||
|
||||
DBG(printf("looking for %s on %s\n", tagname, devname));
|
||||
DBG(DEBUG_RESOLVE, printf("looking for %s on %s\n", tagname, devname));
|
||||
|
||||
if (!devname)
|
||||
return NULL;
|
||||
|
@ -71,7 +64,8 @@ char *blkid_get_devname(blkid_cache cache, const char *token,
|
|||
if (!token)
|
||||
return NULL;
|
||||
|
||||
DBG(printf("looking for %s%c%s %s\n", token, value ? '=' : ' ',
|
||||
DBG(DEBUG_RESOLVE,
|
||||
printf("looking for %s%c%s %s\n", token, value ? '=' : ' ',
|
||||
value ? value : "", cache ? "in cache" : "from disk"));
|
||||
|
||||
if (!cache) {
|
||||
|
@ -112,6 +106,7 @@ int main(int argc, char **argv)
|
|||
char *value;
|
||||
blkid_cache cache;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if (argc != 2 && argc != 3) {
|
||||
fprintf(stderr, "Usage:\t%s tagname=value\n"
|
||||
"\t%s tagname devname\n"
|
||||
|
|
|
@ -26,12 +26,6 @@
|
|||
#endif
|
||||
#include "blkidP.h"
|
||||
|
||||
#ifdef DEBUG_SAVE
|
||||
#define DBG(x) x
|
||||
#else
|
||||
#define DBG(x)
|
||||
#endif
|
||||
|
||||
static int save_dev(blkid_dev dev, FILE *file)
|
||||
{
|
||||
struct list_head *p;
|
||||
|
@ -39,7 +33,8 @@ static int save_dev(blkid_dev dev, FILE *file)
|
|||
if (!dev)
|
||||
return 0;
|
||||
|
||||
DBG(printf("device %s, type %s\n", dev->bid_name, dev->bid_type));
|
||||
DBG(DEBUG_SAVE,
|
||||
printf("device %s, type %s\n", dev->bid_name, dev->bid_type));
|
||||
|
||||
fprintf(file,
|
||||
"<device TYPE=\"%s\" DEVNO=\"0x%04lx\" TIME=\"%lu\"",
|
||||
|
@ -73,7 +68,7 @@ int blkid_flush_cache(blkid_cache cache)
|
|||
|
||||
if (list_empty(&cache->bic_devs) ||
|
||||
!(cache->bic_flags & BLKID_BIC_FL_CHANGED)) {
|
||||
DBG(printf("empty cache, not saving\n"));
|
||||
DBG(DEBUG_SAVE, printf("empty cache, not saving\n"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -87,7 +82,8 @@ int blkid_flush_cache(blkid_cache cache)
|
|||
/* 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(printf("can't write to cache file %s\n", filename));
|
||||
DBG(DEBUG_SAVE,
|
||||
printf("can't write to cache file %s\n", filename));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -116,7 +112,8 @@ int blkid_flush_cache(blkid_cache cache)
|
|||
opened = filename;
|
||||
}
|
||||
|
||||
DBG(printf("cache file %s (really %s)\n", filename, opened));
|
||||
DBG(DEBUG_SAVE,
|
||||
printf("cache file %s (really %s)\n", filename, opened));
|
||||
|
||||
if (!file) {
|
||||
ret = errno;
|
||||
|
@ -142,7 +139,8 @@ int blkid_flush_cache(blkid_cache cache)
|
|||
if (opened != filename) {
|
||||
if (ret < 0) {
|
||||
unlink(opened);
|
||||
DBG(printf("unlinked temp cache %s\n", opened));
|
||||
DBG(DEBUG_SAVE,
|
||||
printf("unlinked temp cache %s\n", opened));
|
||||
} else {
|
||||
char *backup;
|
||||
|
||||
|
@ -154,7 +152,8 @@ int blkid_flush_cache(blkid_cache cache)
|
|||
free(backup);
|
||||
}
|
||||
rename(opened, filename);
|
||||
DBG(printf("moved temp cache %s\n", opened));
|
||||
DBG(DEBUG_SAVE,
|
||||
printf("moved temp cache %s\n", opened));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,6 +170,7 @@ int main(int argc, char **argv)
|
|||
blkid_cache cache = NULL;
|
||||
int ret;
|
||||
|
||||
blkid_debug_mask = DEBUG_ALL;
|
||||
if (argc > 2) {
|
||||
fprintf(stderr, "Usage: %s [filename]\n"
|
||||
"Test loading/saving a cache (filename)\n", argv[0]);
|
||||
|
|
|
@ -16,12 +16,6 @@
|
|||
|
||||
#include "blkidP.h"
|
||||
|
||||
#ifdef DEBUG_TAG
|
||||
#define DBG(x) x
|
||||
#else
|
||||
#define DBG(x)
|
||||
#endif
|
||||
|
||||
static blkid_tag blkid_new_tag(void)
|
||||
{
|
||||
blkid_tag tag;
|
||||
|
@ -40,9 +34,9 @@ void blkid_free_tag(blkid_tag tag)
|
|||
if (!tag)
|
||||
return;
|
||||
|
||||
DBG(printf(" freeing tag %s=%s\n", tag->bit_name,
|
||||
DBG(DEBUG_TAG, printf(" freeing tag %s=%s\n", tag->bit_name,
|
||||
tag->bit_val ? tag->bit_val : "(NULL)"));
|
||||
DEB_DUMP_TAG(tag);
|
||||
DEB_DUMP_TAG(DEBUG_TAG, tag);
|
||||
|
||||
list_del(&tag->bit_tags); /* list of tags for this device */
|
||||
list_del(&tag->bit_names); /* list of tags with this type */
|
||||
|
@ -91,7 +85,8 @@ static blkid_tag blkid_find_head_cache(blkid_cache cache, const char *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(printf(" found cache tag head %s\n", type));
|
||||
DBG(DEBUG_TAG,
|
||||
printf(" found cache tag head %s\n", type));
|
||||
head = tmp;
|
||||
break;
|
||||
}
|
||||
|
@ -161,7 +156,8 @@ repeat:
|
|||
if (!head)
|
||||
goto errout;
|
||||
|
||||
DBG(printf(" creating new cache tag head %s\n",
|
||||
DBG(DEBUG_TAG,
|
||||
printf(" creating new cache tag head %s\n",
|
||||
name));
|
||||
head->bit_name = blkid_strdup(name);
|
||||
if (!head->bit_name)
|
||||
|
@ -210,7 +206,7 @@ int blkid_parse_tag_string(const char *token, char **ret_type, char **ret_val)
|
|||
{
|
||||
char *name, *value, *cp;
|
||||
|
||||
DBG(printf("trying to parse '%s' as a tag\n", token));
|
||||
DBG(DEBUG_TAG, printf("trying to parse '%s' as a tag\n", token));
|
||||
|
||||
if (!token || !(cp = strchr(token, '=')))
|
||||
return -1;
|
||||
|
@ -325,11 +321,12 @@ extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
|
|||
if (!cache || !type || !value)
|
||||
return NULL;
|
||||
|
||||
DBG(printf("looking for %s=%s in cache\n", type, value));
|
||||
DBG(DEBUG_TAG, printf("looking for %s=%s in cache\n", type, value));
|
||||
|
||||
try_again:
|
||||
pri = -1;
|
||||
found = 0;
|
||||
dev = 0;
|
||||
head = blkid_find_head_cache(cache, type);
|
||||
|
||||
if (head) {
|
||||
|
@ -349,7 +346,7 @@ try_again:
|
|||
if (dev && strcmp(found->bit_val, value))
|
||||
dev = 0;
|
||||
|
||||
if ((!head || !dev) && !(cache->bic_flags & BLKID_BIC_FL_PROBED)) {
|
||||
if (!dev && !(cache->bic_flags & BLKID_BIC_FL_PROBED)) {
|
||||
blkid_probe_all(cache);
|
||||
goto try_again;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue