aboutsummaryrefslogtreecommitdiff
path: root/ubifs-utils/common
diff options
context:
space:
mode:
Diffstat (limited to 'ubifs-utils/common')
-rw-r--r--ubifs-utils/common/defs.h48
-rw-r--r--ubifs-utils/common/devtable.c26
-rw-r--r--ubifs-utils/common/lpt.c40
3 files changed, 79 insertions, 35 deletions
diff --git a/ubifs-utils/common/defs.h b/ubifs-utils/common/defs.h
index 485c50c..6d99a2f 100644
--- a/ubifs-utils/common/defs.h
+++ b/ubifs-utils/common/defs.h
@@ -8,8 +8,10 @@
#include <stdlib.h>
#include <stdio.h>
+#include <unistd.h>
#include <limits.h>
#include <errno.h>
+#include <execinfo.h>
#include "ubifs.h"
@@ -22,10 +24,52 @@ extern struct ubifs_info info_;
enum { MKFS_PROGRAM_TYPE = 0 };
-#define dbg_msg(lvl, fmt, ...) do {if (info_.debug_level >= lvl) \
- printf("%s: %s: " fmt "\n", PROGRAM_NAME, __FUNCTION__, ##__VA_ARGS__); \
+enum { ERR_LEVEL = 1, WARN_LEVEL, INFO_LEVEL, DEBUG_LEVEL };
+
+#define pr_debug(fmt, ...) do { if (info_.debug_level >= DEBUG_LEVEL) \
+ printf("<DEBUG> %s[%d] (%s): %s: " fmt, PROGRAM_NAME, getpid(), \
+ info_.dev_name, __FUNCTION__, ##__VA_ARGS__); \
+} while(0)
+
+#define pr_notice(fmt, ...) do { if (info_.debug_level >= INFO_LEVEL) \
+ printf("<INFO> %s[%d] (%s): %s: " fmt, PROGRAM_NAME, getpid(), \
+ info_.dev_name, __FUNCTION__, ##__VA_ARGS__); \
+} while(0)
+
+#define pr_warn(fmt, ...) do { if (info_.debug_level >= WARN_LEVEL) \
+ printf("<WARN> %s[%d] (%s): %s: " fmt, PROGRAM_NAME, getpid(), \
+ info_.dev_name, __FUNCTION__, ##__VA_ARGS__); \
+} while(0)
+
+#define pr_err(fmt, ...) do { if (info_.debug_level >= ERR_LEVEL) \
+ printf("<ERROR> %s[%d] (%s): %s: " fmt, PROGRAM_NAME, getpid(), \
+ info_.dev_name, __FUNCTION__, ##__VA_ARGS__); \
} while(0)
+#define pr_cont(fmt, ...) do { if (info_.debug_level >= ERR_LEVEL) \
+ printf(fmt, ##__VA_ARGS__); \
+} while(0)
+
+static inline void dump_stack(void)
+{
+#define STACK_SIZE 512
+ int j, nptrs;
+ void *buffer[STACK_SIZE];
+ char **strings;
+
+ if (info_.debug_level < ERR_LEVEL)
+ return;
+
+ nptrs = backtrace(buffer, STACK_SIZE);
+ strings = backtrace_symbols(buffer, nptrs);
+
+ printf("dump_stack:\n");
+ for (j = 0; j < nptrs; j++)
+ printf("%s\n", strings[j]);
+
+ free(strings);
+}
+
#define unlikely(x) (x)
#define do_div(n,base) ({ \
diff --git a/ubifs-utils/common/devtable.c b/ubifs-utils/common/devtable.c
index 3903264..7347f09 100644
--- a/ubifs-utils/common/devtable.c
+++ b/ubifs-utils/common/devtable.c
@@ -148,10 +148,10 @@ static int interpret_table_entry(const char *line)
&start, &increment, &count) < 0)
return sys_errmsg("sscanf failed");
- dbg_msg(3, "name %s, type %c, mode %o, uid %u, gid %u, major %u, "
- "minor %u, start %u, inc %u, cnt %u",
- buf, type, mode, uid, gid, major, minor, start,
- increment, count);
+ pr_debug("name %s, type %c, mode %o, uid %u, gid %u, major %u, "
+ "minor %u, start %u, inc %u, cnt %u\n",
+ buf, type, mode, uid, gid, major, minor, start,
+ increment, count);
len = strnlen(buf, 1024);
if (len == 0)
@@ -204,7 +204,7 @@ static int interpret_table_entry(const char *line)
*/
ph_elt = hashtable_search(path_htbl, path);
if (!ph_elt) {
- dbg_msg(3, "inserting '%s' into path hash table", path);
+ pr_debug("inserting '%s' into path hash table\n", path);
ph_elt = malloc(sizeof(struct path_htbl_element));
if (!ph_elt) {
errmsg("cannot allocate %zd bytes of memory",
@@ -252,8 +252,8 @@ static int interpret_table_entry(const char *line)
nh_elt->gid = gid;
nh_elt->dev = makedev(major, minor);
- dbg_msg(3, "inserting '%s' into name hash table (major %d, minor %d)",
- name, major(nh_elt->dev), minor(nh_elt->dev));
+ pr_debug("inserting '%s' into name hash table (major %d, minor %d)\n",
+ name, major(nh_elt->dev), minor(nh_elt->dev));
if (hashtable_search(ph_elt->name_htbl, name)) {
errmsg("'%s' is referred twice", buf);
@@ -291,8 +291,8 @@ static int interpret_table_entry(const char *line)
sprintf(nm, "%s%d", name, i);
nh_elt->name = nm;
- dbg_msg(3, "inserting '%s' into name hash table (major %d, minor %d)",
- nm, major(nh_elt->dev), minor(nh_elt->dev));
+ pr_debug("inserting '%s' into name hash table (major %d, minor %d)\n",
+ nm, major(nh_elt->dev), minor(nh_elt->dev));
if (hashtable_search(ph_elt->name_htbl, nm)) {
errmsg("'%s' is referred twice", buf);
@@ -336,7 +336,7 @@ int parse_devtable(const char *tbl_file)
struct stat st;
size_t len;
- dbg_msg(1, "parsing device table file '%s'", tbl_file);
+ pr_debug("parsing device table file '%s'\n", tbl_file);
path_htbl = create_hashtable(128, &r5_hash, &is_equivalent);
if (!path_htbl)
@@ -386,7 +386,7 @@ int parse_devtable(const char *tbl_file)
line = NULL;
}
- dbg_msg(1, "finished parsing");
+ pr_debug("finished parsing\n");
fclose(f);
return 0;
@@ -460,8 +460,8 @@ int override_attributes(struct stat *st, struct path_htbl_element *ph_elt,
"different", strcmp(ph_elt->path, "/") ? ph_elt->path : "",
nh_elt->name);
- dbg_msg(3, "set UID %d, GID %d, mode %o for %s/%s as device table says",
- nh_elt->uid, nh_elt->gid, nh_elt->mode, ph_elt->path, nh_elt->name);
+ pr_debug("set UID %d, GID %d, mode %o for %s/%s as device table says\n",
+ nh_elt->uid, nh_elt->gid, nh_elt->mode, ph_elt->path, nh_elt->name);
st->st_uid = nh_elt->uid;
st->st_gid = nh_elt->gid;
diff --git a/ubifs-utils/common/lpt.c b/ubifs-utils/common/lpt.c
index 3c55f91..0723698 100644
--- a/ubifs-utils/common/lpt.c
+++ b/ubifs-utils/common/lpt.c
@@ -337,7 +337,7 @@ static void pack_lsave(struct ubifs_info *c, void *buf, int *lsave)
*/
static void set_ltab(struct ubifs_info *c, int lnum, int free, int dirty)
{
- dbg_msg(3, "LEB %d free %d dirty %d to %d %d",
+ pr_debug("LEB %d free %d dirty %d to %d %d\n",
lnum, c->ltab[lnum - c->lpt_first].free,
c->ltab[lnum - c->lpt_first].dirty, free, dirty);
c->ltab[lnum - c->lpt_first].free = free;
@@ -566,26 +566,26 @@ int create_lpt(struct ubifs_info *c)
c->nhead_lnum = lnum;
c->nhead_offs = ALIGN(len, c->min_io_size);
- dbg_msg(1, "lpt_sz: %lld", c->lpt_sz);
- dbg_msg(1, "space_bits: %d", c->space_bits);
- dbg_msg(1, "lpt_lnum_bits: %d", c->lpt_lnum_bits);
- dbg_msg(1, "lpt_offs_bits: %d", c->lpt_offs_bits);
- dbg_msg(1, "lpt_spc_bits: %d", c->lpt_spc_bits);
- dbg_msg(1, "pcnt_bits: %d", c->pcnt_bits);
- dbg_msg(1, "lnum_bits: %d", c->lnum_bits);
- dbg_msg(1, "pnode_sz: %d", c->pnode_sz);
- dbg_msg(1, "nnode_sz: %d", c->nnode_sz);
- dbg_msg(1, "ltab_sz: %d", c->ltab_sz);
- dbg_msg(1, "lsave_sz: %d", c->lsave_sz);
- dbg_msg(1, "lsave_cnt: %d", c->lsave_cnt);
- dbg_msg(1, "lpt_hght: %d", c->lpt_hght);
- dbg_msg(1, "big_lpt: %d", c->big_lpt);
- dbg_msg(1, "LPT root is at %d:%d", c->lpt_lnum, c->lpt_offs);
- dbg_msg(1, "LPT head is at %d:%d", c->nhead_lnum, c->nhead_offs);
- dbg_msg(1, "LPT ltab is at %d:%d", c->ltab_lnum, c->ltab_offs);
+ pr_debug("lpt_sz: %lld\n", c->lpt_sz);
+ pr_debug("space_bits: %d\n", c->space_bits);
+ pr_debug("lpt_lnum_bits: %d\n", c->lpt_lnum_bits);
+ pr_debug("lpt_offs_bits: %d\n", c->lpt_offs_bits);
+ pr_debug("lpt_spc_bits: %d\n", c->lpt_spc_bits);
+ pr_debug("pcnt_bits: %d\n", c->pcnt_bits);
+ pr_debug("lnum_bits: %d\n", c->lnum_bits);
+ pr_debug("pnode_sz: %d\n", c->pnode_sz);
+ pr_debug("nnode_sz: %d\n", c->nnode_sz);
+ pr_debug("ltab_sz: %d\n", c->ltab_sz);
+ pr_debug("lsave_sz: %d\n", c->lsave_sz);
+ pr_debug("lsave_cnt: %d\n", c->lsave_cnt);
+ pr_debug("lpt_hght: %d\n", c->lpt_hght);
+ pr_debug("big_lpt: %d\n", c->big_lpt);
+ pr_debug("LPT root is at %d:%d\n", c->lpt_lnum, c->lpt_offs);
+ pr_debug("LPT head is at %d:%d\n", c->nhead_lnum, c->nhead_offs);
+ pr_debug("LPT ltab is at %d:%d\n", c->ltab_lnum, c->ltab_offs);
if (c->big_lpt)
- dbg_msg(1, "LPT lsave is at %d:%d",
- c->lsave_lnum, c->lsave_offs);
+ pr_debug("LPT lsave is at %d:%d\n",
+ c->lsave_lnum, c->lsave_offs);
out:
free(lsave);
free(buf);