int fp_charns( void *obj, int bit, int count, char *fmtstr, int size, int arg, int base, int array) { int i; char *p; ASSERT(bitoffs(bit) == 0); ASSERT(size == bitsz(char)); dbprintf("\""); for (i = 0, p = (char *)obj + byteize(bit); i < count && !seenint(); i++, p++) { if (*p == '\\' || *p == '\'' || *p == '"' || *p == '\?') dbprintf("\\%c", *p); else if (isgraph((int)*p) || *p == ' ') dbprintf("%c", *p); else if (*p == '\a' || *p == '\b' || *p == '\f' || *p == '\n' || *p == '\r' || *p == '\t' || *p == '\v') dbprintf("\\%c", *p + ('a' - '\a')); else dbprintf("\\%03o", *p & 0xff); } dbprintf("\""); return 1; }
/*ARGSUSED*/ int fp_uuid( void *obj, int bit, int count, char *fmtstr, int size, int arg, int base, int array) { char bp[40]; /* UUID string is 36 chars + trailing '\0' */ int i; uuid_t *p; ASSERT(bitoffs(bit) == 0); for (p = (uuid_t *)((char *)obj + byteize(bit)), i = 0; i < count && !seenint(); i++, p++) { if (array) dbprintf("%d:", i + base); platform_uuid_unparse(p, bp); dbprintf("%s", bp); if (i < count - 1) dbprintf(" "); } return 1; }
/*ARGSUSED*/ int fp_time( void *obj, int bit, int count, char *fmtstr, int size, int arg, int base, int array) { int bitpos; char *c; int i; time_t t; ASSERT(bitoffs(bit) == 0); for (i = 0, bitpos = bit; i < count && !seenint(); i++, bitpos += size) { if (array) dbprintf("%d:", i + base); t=(time_t)getbitval((char *)obj + byteize(bitpos), 0, sizeof(int32_t)*8, 0); c = ctime(&t); dbprintf("%24.24s", c); if (i < count - 1) dbprintf(" "); } return 1; }
static void print_flist_1( flist_t *flist, char **ppfx, int parentoff) { char buf[16]; const field_t *f; const ftattr_t *fa; flist_t *fl; int low; int neednl; char **pfx; for (fl = flist; fl && !seenint(); fl = fl->sibling) { pfx = copy_strvec(ppfx); if (fl->name[0]) add_strvec(&pfx, fl->name); if (fl->flags & FL_OKLOW) { add_strvec(&pfx, "["); snprintf(buf, sizeof(buf), "%d", fl->low); add_strvec(&pfx, buf); if (fl->low != fl->high) { add_strvec(&pfx, "-"); snprintf(buf, sizeof(buf), "%d", fl->high); add_strvec(&pfx, buf); } add_strvec(&pfx, "]"); } if (fl->child) { if (fl->name[0]) add_strvec(&pfx, "."); print_flist_1(fl->child, pfx, fl->offset); } else { f = fl->fld; fa = &ftattrtab[f->ftyp]; ASSERT(fa->ftyp == f->ftyp); print_strvec(pfx); dbprintf(" = "); if (fl->flags & FL_OKLOW) low = fl->low; else low = 0; if (fa->prfunc) { neednl = fa->prfunc(iocur_top->data, fl->offset, fcount(f, iocur_top->data, parentoff), fa->fmtstr, fsize(f, iocur_top->data, parentoff, 0), fa->arg, low, (f->flags & FLD_ARRAY) != 0); if (neednl) dbprintf("\n"); } else { ASSERT(fa->arg & FTARG_OKEMPTY); dbprintf(_("(empty)\n")); } } free_strvec(pfx); } }
void print_sarray( void *obj, int bit, int count, int size, int base, int array, const field_t *flds, int skipnms) { int bitoff; const field_t *f; const ftattr_t *fa; int first; int i; ASSERT(bitoffs(bit) == 0); if (skipnms == 0) { for (f = flds, first = 1; f->name; f++) { if (f->flags & FLD_SKIPALL) continue; dbprintf("%c%s", first ? '[' : ',', f->name); first = 0; } dbprintf("] "); } for (i = 0, bitoff = bit; i < count && !seenint(); i++, bitoff += size) { if (array) dbprintf("%d:", i + base); for (f = flds, first = 1; f->name; f++) { if (f->flags & FLD_SKIPALL) continue; fa = &ftattrtab[f->ftyp]; ASSERT(fa->ftyp == f->ftyp); dbprintf("%c", first ? '[' : ','); first = 0; if (fa->prfunc) fa->prfunc(obj, bitoff + bitoffset(f, obj, bitoff, i + base), fcount(f, obj, bitoff), fa->fmtstr, fsize(f, obj, bitoff, i + base), fa->arg, (f->flags & FLD_ABASE1) != 0, f->flags & FLD_ARRAY); else { ASSERT(fa->arg & FTARG_OKEMPTY); dbprintf(_("(empty)")); } } dbprintf("]"); if (i < count - 1) dbprintf(" "); } }
/* * CRC is correct is the current buffer it is being pulled out * of is not marked with a EFSCORRUPTED error. */ int fp_crc( void *obj, int bit, int count, char *fmtstr, int size, int arg, int base, int array) { int bitpos; int i; __int64_t val; char *ok; switch (iocur_crc_valid()) { case -1: ok = "unchecked"; break; case 0: ok = "bad"; break; case 1: ok = "correct"; break; default: ok = "unknown state"; break; } for (i = 0, bitpos = bit; i < count && !seenint(); i++, bitpos += size) { if (array) dbprintf("%d:", i + base); val = getbitval(obj, bitpos, size, BVUNSIGNED); if (size > 32) dbprintf(fmtstr, val, ok); else dbprintf(fmtstr, (__int32_t)val, ok); if (i < count - 1) dbprintf(" "); } return 1; }
/*ARGSUSED*/ void print_string( const field_t *fields, int argc, char **argv) { char *cp; if (argc != 0) dbprintf(_("no arguments allowed\n")); dbprintf("\""); for (cp = iocur_top->data; cp < (char *)iocur_top->data + iocur_top->len && *cp && !seenint(); cp++) dbprintf("%c", *cp); dbprintf("\"\n"); }
int fp_num( void *obj, int bit, int count, char *fmtstr, int size, int arg, int base, int array) { int bitpos; int i; int isnull; __int64_t val; for (i = 0, bitpos = bit; i < count && !seenint(); i++, bitpos += size) { val = getbitval(obj, bitpos, size, (arg & FTARG_SIGNED) ? BVSIGNED : BVUNSIGNED); if ((arg & FTARG_SKIPZERO) && val == 0) continue; isnull = (arg & FTARG_SIGNED) || size == 64 ? val == -1LL : val == ((1LL << size) - 1LL); if ((arg & FTARG_SKIPNULL) && isnull) continue; if (array && count > 1) dbprintf("%d:", i + base); if ((arg & FTARG_DONULL) && isnull) dbprintf(_("null")); else if (size > 32) dbprintf(fmtstr, val); else dbprintf(fmtstr, (__int32_t)val); if (i < count - 1) dbprintf(" "); } return 1; }
int dbprintf(const char *fmt, ...) { va_list ap; int i; if (seenint()) return 0; va_start(ap, fmt); blockint(); i = 0; if (dbprefix) i += printf("%s: ", fsdevice); i += vprintf(fmt, ap); unblockint(); va_end(ap); if (log_file) { va_start(ap, fmt); vfprintf(log_file, fmt, ap); va_end(ap); } return i; }
char * fetchline(void) { char buf[1024]; int iscont; size_t len; size_t rlen; char *rval; rval = NULL; for (rlen = iscont = 0; ; ) { if (inputstacksize == 1) { if (iscont) dbprintf("... "); else dbprintf("%s: ", progname); fflush(stdin); } if (seenint() || (!fgets(buf, sizeof(buf), curinput) && ferror(curinput) && seenint())) { clearint(); dbprintf("^C\n"); clearerr(curinput); if (iscont) { iscont = 0; rlen = 0; if (rval) { xfree(rval); rval = NULL; } } continue; } if (ferror(curinput) || feof(curinput) || (len = strlen(buf)) == 0) { popfile(); if (curinput == NULL) { dbprintf("\n"); return NULL; } iscont = 0; rlen = 0; if (rval) { xfree(rval); rval = NULL; } continue; } if (inputstacksize == 1) logprintf("%s", buf); rval = xrealloc(rval, rlen + len + 1); if (rlen == 0) rval[0] = '\0'; rlen += len; strcat(rval, buf); if (buf[len - 1] == '\n') { if (len > 1 && buf[len - 2] == '\\') { rval[rlen - 2] = ' '; rval[rlen - 1] = '\0'; rlen--; iscont = 1; } else { rval[rlen - 1] = '\0'; rlen--; break; } } } return rval; }